Add BlockProgressBar for Gem Fountain
This commit is contained in:
parent
e8370579c0
commit
cabf4c4c8b
|
@ -0,0 +1,57 @@
|
|||
package mineplex.core.brawl.fountain;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
/**
|
||||
* This class handled filling a vertical area with a specific block based off a percent
|
||||
*
|
||||
* @author Shaun Bennett
|
||||
*/
|
||||
public class BlockProgressBar
|
||||
{
|
||||
// Starting block for the block fill
|
||||
private final Block _startBlock;
|
||||
// Direction the blockfill takes place in
|
||||
private final BlockFace _direction;
|
||||
// Blocks in order from lowest to highes
|
||||
private final Block[] _blocks;
|
||||
// Material used to fill the blocks
|
||||
private final Material _material;
|
||||
|
||||
public BlockProgressBar(Block startBlock, Material material, BlockFace direction)
|
||||
{
|
||||
_startBlock = startBlock;
|
||||
_material = material;
|
||||
_direction = direction;
|
||||
|
||||
// Add blocks to array
|
||||
int i;
|
||||
Block curr;
|
||||
Block[] blocks = new Block[100]; // max of 100 to prevent blocking
|
||||
for (i = 0, curr = startBlock; (curr.getType() == Material.AIR || curr.getType() == material) && i < blocks.length; i++)
|
||||
{
|
||||
blocks[i] = curr;
|
||||
curr = curr.getRelative(direction);
|
||||
}
|
||||
|
||||
_blocks = new Block[i];
|
||||
System.arraycopy(blocks, 0, _blocks, 0, i);
|
||||
}
|
||||
|
||||
// Update the blockfill based on fill percent
|
||||
public void update(double percent)
|
||||
{
|
||||
double percentPerBlock = 1D / _blocks.length;
|
||||
double check = 0;
|
||||
|
||||
for (int i = 0; i < _blocks.length; i++)
|
||||
{
|
||||
_blocks[i].setType(percent > check ? _material : Material.AIR);
|
||||
|
||||
check += percentPerBlock;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,9 +7,10 @@ import mineplex.core.donation.DonationManager;
|
|||
import mineplex.core.hologram.Hologram;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
import mineplex.serverdata.redis.counter.Counter;
|
||||
import mineplex.serverdata.redis.counter.GoalCounter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +28,7 @@ public class Fountain
|
|||
private Location _lavaLocation;
|
||||
private final Hologram _hologram;
|
||||
private final GoalCounter _counter;
|
||||
private final BlockProgressBar _blockProgressBar;
|
||||
|
||||
private final FountainShop _shop;
|
||||
|
||||
|
@ -43,28 +45,27 @@ public class Fountain
|
|||
_lavaLocation = lavaLocation;
|
||||
_hologram = new Hologram(hologramManager, location.clone().add(0, 2, 0), name).start();
|
||||
_counter = new GoalCounter(dataKey, 5000, goal);
|
||||
_blockProgressBar = new BlockProgressBar(_lavaLocation.getBlock(), Material.LAVA, BlockFace.UP);
|
||||
|
||||
_shop = new FountainShop(this, fountainManager, clientManager, donationManager);
|
||||
|
||||
updateHologram();
|
||||
updateVisuals();
|
||||
}
|
||||
|
||||
protected void updateHologram()
|
||||
protected void updateVisuals()
|
||||
{
|
||||
String progressBar = UtilText.getProgress(null, _counter.getFillPercent(), null, false);
|
||||
double percent = _counter.getFillPercent();
|
||||
|
||||
String progressBar = UtilText.getProgress(null, percent, null, false);
|
||||
_hologram.setText(_name, progressBar);
|
||||
}
|
||||
|
||||
protected void updateCount()
|
||||
{
|
||||
updateHologram();
|
||||
_blockProgressBar.update(percent);
|
||||
}
|
||||
|
||||
public void increment(Player player, long amount)
|
||||
{
|
||||
_statsManager.incrementStat(player, "Global.Fountain." + getDataKey(), amount);
|
||||
_counter.addAndGet(amount);
|
||||
updateHologram();
|
||||
updateVisuals();
|
||||
}
|
||||
|
||||
public String getName()
|
||||
|
|
|
@ -53,10 +53,10 @@ public class FountainManager extends MiniPlugin
|
|||
@EventHandler
|
||||
public void updateFountainCount(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SLOW)
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
return;
|
||||
|
||||
_gemFountain.updateCount();
|
||||
_gemFountain.updateVisuals();
|
||||
}
|
||||
|
||||
public Fountain getGemFountain()
|
||||
|
|
|
@ -27,8 +27,6 @@ public class Counter
|
|||
_dataKey = dataKey;
|
||||
_syncTime = syncTime;
|
||||
_redisRepository = new CounterRedisRepository(dataKey);
|
||||
|
||||
updateCount(_redisRepository.getCount());
|
||||
}
|
||||
|
||||
public Counter(String dataKey)
|
||||
|
|
Loading…
Reference in New Issue