Proper display of extra gem fountain rewards
This commit is contained in:
parent
c9d5b91c52
commit
09d2c00f66
@ -1555,12 +1555,12 @@ public class UtilBlock
|
||||
BlockPosition pos = new BlockPosition(x, y, z);
|
||||
IBlockData ibd = net.minecraft.server.v1_8_R3.Block.getById(type).fromLegacyData(data);
|
||||
chunk.a(pos, ibd);
|
||||
// nmsWorld.notify(pos);
|
||||
nmsWorld.notify(pos);
|
||||
|
||||
if(_quickChangeRecorder != null)
|
||||
{
|
||||
_quickChangeRecorder.addBlock(world.getBlockAt(x, y, z));
|
||||
}
|
||||
// if(_quickChangeRecorder != null)
|
||||
// {
|
||||
// _quickChangeRecorder.addBlock(world.getBlockAt(x, y, z));
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -672,18 +672,23 @@ public class UtilText
|
||||
}
|
||||
|
||||
public static String getProgress(String prefix, double amount, String suffix, boolean progressDirectionSwap, int bars)
|
||||
{
|
||||
return getProgress(prefix, amount, suffix, progressDirectionSwap, bars, C.cRed, C.cGreen);
|
||||
}
|
||||
|
||||
public static String getProgress(String prefix, double amount, String suffix, boolean progressDirectionSwap, int bars, String emptyColor, String fillColor)
|
||||
{
|
||||
if (progressDirectionSwap)
|
||||
amount = 1 - amount;
|
||||
|
||||
//Generate Bar
|
||||
String progressBar = C.cGreen + "";
|
||||
String progressBar = fillColor + "";
|
||||
boolean colorChange = false;
|
||||
for (int i=0 ; i<bars ; i++)
|
||||
{
|
||||
if (!colorChange && (float)i/(float)bars >= amount)
|
||||
{
|
||||
progressBar += C.cRed;
|
||||
progressBar += emptyColor;
|
||||
colorChange = true;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.brawl.fountain.gui.FountainShop;
|
||||
import mineplex.core.common.SortedSchematicLoader;
|
||||
import mineplex.core.common.block.schematic.UtilSchematic;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
@ -50,7 +51,7 @@ public class Fountain implements GoalCounterListener
|
||||
_name = name;
|
||||
_dataKey = dataKey;
|
||||
_location = location;
|
||||
_hologram = new Hologram(hologramManager, location.clone().add(0, 2, 0), name).start();
|
||||
_hologram = new Hologram(hologramManager, location.clone().add(4, 3, -3), name).start();
|
||||
_counter = new GoalCounter(dataKey, 5000, goal);
|
||||
_counter.addListener(this);
|
||||
// _blockProgressBar = new BlockProgressBar(_lavaLocation.getBlock(), Material.LAVA, BlockFace.UP);
|
||||
@ -84,10 +85,42 @@ public class Fountain implements GoalCounterListener
|
||||
|
||||
protected void updateVisuals()
|
||||
{
|
||||
double percent = _counter.getFillPercent();
|
||||
double percent = getFillPercent();
|
||||
double flatPercent = percent - (int) percent;
|
||||
|
||||
String progressBar = UtilText.getProgress(null, percent, null, false);
|
||||
_hologram.setText(_name, progressBar);
|
||||
String fillColor;
|
||||
String emptyColor;
|
||||
String goalMessage;
|
||||
|
||||
if (percent < 1)
|
||||
{
|
||||
fillColor = C.cGreen;
|
||||
emptyColor = C.cRed;
|
||||
goalMessage = "100% to Unlock Weekend Brawl";
|
||||
}
|
||||
else if (percent < 2)
|
||||
{
|
||||
fillColor = C.cYellow;
|
||||
emptyColor = C.cGreen;
|
||||
goalMessage = "200% to Unlock 2x XP for Weekend Brawl";
|
||||
}
|
||||
else if (percent < 3)
|
||||
{
|
||||
fillColor = C.cAqua;
|
||||
emptyColor = C.cYellow;
|
||||
goalMessage = "300% to Unlock 3x XP for Weekend Brawl";
|
||||
}
|
||||
else
|
||||
{
|
||||
fillColor = C.cAqua;
|
||||
emptyColor = C.cYellow;
|
||||
goalMessage = "All Rewards Unlocked!";
|
||||
flatPercent = 1;
|
||||
}
|
||||
|
||||
int intPercent = (int) (percent * 100);
|
||||
String progressBar = UtilText.getProgress(null, flatPercent, null, false, 30, emptyColor, fillColor);
|
||||
_hologram.setText(_name + C.Reset + " " + intPercent + "%", goalMessage, progressBar);
|
||||
_schematicLoader.update(percent);
|
||||
}
|
||||
|
||||
@ -125,7 +158,7 @@ public class Fountain implements GoalCounterListener
|
||||
|
||||
public double getFillPercent()
|
||||
{
|
||||
return _counter.getFillPercent();
|
||||
return Math.min(3, _counter.getFillPercent());
|
||||
}
|
||||
|
||||
public long getCount()
|
||||
@ -140,14 +173,19 @@ public class Fountain implements GoalCounterListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGoalComplete(GoalCounter counter)
|
||||
public void onMilestone(GoalCounter counter, int milestone)
|
||||
{
|
||||
Bukkit.broadcastMessage(F.main("Fountain", "The Gem Fountain has reached its goal! Brawl Game unlocked this week"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGoalReset(GoalCounter counter)
|
||||
{
|
||||
Bukkit.broadcastMessage(F.main("Fountain", "The Gem Fountain has reset! Goal this week: " + _counter.getGoal()));
|
||||
switch (milestone)
|
||||
{
|
||||
case 1:
|
||||
Bukkit.broadcastMessage(F.main("Fountain", "The Gem Fountain has reached 100%! Brawl Game unlocked this week"));
|
||||
break;
|
||||
case 2:
|
||||
Bukkit.broadcastMessage(F.main("Fountain", "The Gem Fountain has reached 200%! 2x XP enabled for Brawl!"));
|
||||
break;
|
||||
case 3:
|
||||
Bukkit.broadcastMessage(F.main("Fountain", "The Gem Fountain has reached 300%! 3x XP enabled for Brawl!"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,10 @@ public class FountainPage extends ShopPageBase<FountainManager, FountainShop>
|
||||
{
|
||||
private final MaterialData EMPTY_XP = MaterialData.of(Material.STAINED_GLASS_PANE, (byte) 7);
|
||||
private final MaterialData XP = MaterialData.of(Material.STAINED_GLASS_PANE, (byte) 5);
|
||||
private final MaterialData EMPTY_XP100 = MaterialData.of(Material.STAINED_GLASS_PANE, (byte) 5);
|
||||
private final MaterialData XP100 = MaterialData.of(Material.STAINED_GLASS_PANE, (byte) 4);
|
||||
private final MaterialData EMPTY_XP200 = MaterialData.of(Material.STAINED_GLASS_PANE, (byte) 4);
|
||||
private final MaterialData XP200 = MaterialData.of(Material.STAINED_GLASS_PANE, (byte) 3);
|
||||
private final int[] XP_SLOTS = { 2, 3, 4, 5, 6 };
|
||||
|
||||
private Fountain _fountain;
|
||||
@ -39,20 +43,31 @@ public class FountainPage extends ShopPageBase<FountainManager, FountainShop>
|
||||
// Experience Bar
|
||||
long added = _fountain.getAmountAdded(getPlayer());
|
||||
final double fillPercent = _fountain.getFillPercent();
|
||||
String title = Math.round(fillPercent * 100) + "% Complete";
|
||||
String title = ((int)(fillPercent * 100)) + "% Complete";
|
||||
boolean canAdd = fillPercent < 3;
|
||||
|
||||
String unlockMessage;
|
||||
if (fillPercent < 1) unlockMessage = "Reach 100% to unlock Weekend Brawl Game";
|
||||
else if (fillPercent < 2) unlockMessage = "Reach 200% to unlock 2x XP in Brawl";
|
||||
else if (fillPercent < 3) unlockMessage = "Reach 300% to unlock 3x XP in Brawl";
|
||||
else unlockMessage = "All rewards unlocked!";
|
||||
|
||||
String[] lore = new String[] {
|
||||
" ",
|
||||
C.cWhite + "Reaching the goal for this week will",
|
||||
C.cWhite + "unlock the weekend brawl minigame!",
|
||||
C.cWhite + unlockMessage,
|
||||
" ",
|
||||
C.cWhite + "You have added " + C.cGreen + added + " Gems"};
|
||||
|
||||
final double percentForEach = 1D / XP_SLOTS.length;
|
||||
double check = percentForEach;
|
||||
|
||||
double flatPercent = fillPercent == 3 ? 1 : fillPercent - ((int) fillPercent);
|
||||
for (int i = 0; i < XP_SLOTS.length; i++)
|
||||
{
|
||||
MaterialData data = fillPercent >= check ? XP : EMPTY_XP;
|
||||
MaterialData data;
|
||||
if (fillPercent < 1) data = flatPercent >= check ? XP : EMPTY_XP;
|
||||
else if (fillPercent < 2) data = flatPercent >= check ? XP100 : EMPTY_XP100;
|
||||
else data = flatPercent >= check ? XP200 : EMPTY_XP200;
|
||||
ShopItem shopItem = new ShopItem(data.getMaterial(), data.getData(), title,
|
||||
lore, 1, false, false);
|
||||
|
||||
@ -60,15 +75,18 @@ public class FountainPage extends ShopPageBase<FountainManager, FountainShop>
|
||||
check += percentForEach;
|
||||
}
|
||||
|
||||
int playerGems = getDonationManager().Get(getPlayer()).GetGems();
|
||||
ShopItem add1 = new ShopItem(Material.EMERALD, "Add 100 Gems", new String[] {}, 1, playerGems < 100, false);
|
||||
ShopItem add2 = new ShopItem(Material.EMERALD, "Add 1,000 Gems", new String[] {}, 64, playerGems < 1000, false);
|
||||
ShopItem add3 = new ShopItem(Material.EMERALD, "Add 10,000 Gems", new String[] {}, 1, playerGems < 10000, false);
|
||||
ShopItem add4 = new ShopItem(Material.EMERALD, "Add 100,000 Gems", new String[] {}, 64, playerGems < 100000, false);
|
||||
// Buttons
|
||||
addButton(19, add1, new FountainAddButton(this, 100));
|
||||
addButton(21, add2, new FountainAddButton(this, 1000));
|
||||
addButton(23, add3, new FountainAddButton(this, 10000));
|
||||
addButton(25, add4, new FountainAddButton(this, 100000));
|
||||
if (canAdd)
|
||||
{
|
||||
int playerGems = getDonationManager().Get(getPlayer()).GetGems();
|
||||
ShopItem add1 = new ShopItem(Material.EMERALD, "Add 100 Gems", new String[]{}, 1, playerGems < 100, false);
|
||||
ShopItem add2 = new ShopItem(Material.EMERALD, "Add 1,000 Gems", new String[]{}, 64, playerGems < 1000, false);
|
||||
ShopItem add3 = new ShopItem(Material.EMERALD_BLOCK, "Add 10,000 Gems", new String[]{}, 1, playerGems < 10000, false);
|
||||
ShopItem add4 = new ShopItem(Material.EMERALD_BLOCK, "Add 100,000 Gems", new String[]{}, 64, playerGems < 100000, false);
|
||||
// Buttons
|
||||
addButton(19, add1, new FountainAddButton(this, 100));
|
||||
addButton(21, add2, new FountainAddButton(this, 1000));
|
||||
addButton(23, add3, new FountainAddButton(this, 10000));
|
||||
addButton(25, add4, new FountainAddButton(this, 100000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||
*/
|
||||
public class GoalCounter extends Counter
|
||||
{
|
||||
private int _lastMilestone;
|
||||
// Has the goal been completed?
|
||||
private boolean _completed;
|
||||
// The goal we are trying to reach
|
||||
@ -25,6 +26,7 @@ public class GoalCounter extends Counter
|
||||
_goal = goal;
|
||||
|
||||
_listeners = new ArrayList<>();
|
||||
_lastMilestone = (int) getFillPercent();
|
||||
|
||||
update();
|
||||
}
|
||||
@ -35,7 +37,7 @@ public class GoalCounter extends Counter
|
||||
*/
|
||||
public double getFillPercent()
|
||||
{
|
||||
return Math.min(1, (((double) getCount()) / _goal));
|
||||
return (((double) getCount()) / _goal);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,16 +80,14 @@ public class GoalCounter extends Counter
|
||||
*/
|
||||
private void update()
|
||||
{
|
||||
boolean updatedValue = getCount() >= _goal;
|
||||
int currentMilestone = (int) getFillPercent();
|
||||
|
||||
if (updatedValue != _completed)
|
||||
if (currentMilestone != _lastMilestone && currentMilestone > _lastMilestone)
|
||||
{
|
||||
_completed = updatedValue;
|
||||
_listeners.forEach(listener -> {
|
||||
if (_completed) listener.onGoalComplete(this);
|
||||
else listener.onGoalReset(this);
|
||||
});
|
||||
_listeners.forEach(listener -> listener.onMilestone(this, currentMilestone));
|
||||
}
|
||||
|
||||
_lastMilestone = currentMilestone;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,7 +5,5 @@ package mineplex.serverdata.redis.counter;
|
||||
*/
|
||||
public interface GoalCounterListener
|
||||
{
|
||||
public void onGoalComplete(GoalCounter counter);
|
||||
|
||||
public void onGoalReset(GoalCounter counter);
|
||||
public void onMilestone(GoalCounter counter, int milestone);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user