Update fountain count every 5 seconds. Display Hologram

This commit is contained in:
Shaun Bennett 2016-04-19 14:30:38 +10:00
parent 6dc2559dd1
commit cb48df6a3d
6 changed files with 36 additions and 4 deletions

View File

@ -31,7 +31,7 @@ public class Fountain
_name = name;
_dataKey = dataKey;
_location = location;
_hologram = new Hologram(hologramManager, location.clone().add(0, 2, 0), name);
_hologram = new Hologram(hologramManager, location.clone().add(0, 2, 0), name).start();
_counter = new Counter(dataKey, goal);
updateHologram();
@ -43,6 +43,17 @@ public class Fountain
_hologram.setText(_name, progressBar);
}
protected void updateCount()
{
// Make sure we only update if it has been 5 seconds since the last update
// Players incrementing the counter will automatically cause it to update
if (System.currentTimeMillis() - _counter.getCacheLastUpdated() > 5000)
{
_counter.updateCount();
updateHologram();
}
}
public void increment(Player player, long amount)
{
_statsManager.incrementStat(player, "Global.Fountain." + getDataKey(), amount);

View File

@ -3,6 +3,8 @@ package mineplex.core.brawl.fountain;
import mineplex.core.MiniPlugin;
import mineplex.core.brawl.fountain.command.FountainCommand;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.hologram.HologramManager;
import mineplex.core.stats.StatsManager;
import mineplex.core.updater.UpdateType;
@ -31,7 +33,7 @@ public class FountainManager extends MiniPlugin
_hologramManager = hologramManager;
_statsManager = statsManager;
_gemFountain = new Fountain(new Location(Bukkit.getWorld("world"), -32.5, 72, -23.5),
_gemFountain = new Fountain(new Location(Bukkit.getWorlds().get(0), -32.5, 72, -23.5),
C.cGreen + "Gem Fountain", "GemFountain", 1000000, _hologramManager, _statsManager);
}
@ -47,7 +49,7 @@ public class FountainManager extends MiniPlugin
if (event.getType() != UpdateType.SLOW)
return;
_gemFountain.updateHologram();
_gemFountain.updateCount();
}
public Fountain getGemFountain()

View File

@ -30,6 +30,7 @@ public class AddCommand extends CommandBase<FountainManager>
{
long amount = Long.parseLong(args[0]);
Plugin.getGemFountain().increment(caller, amount);
UtilPlayer.message(caller, F.main("Fountain", "Added " + F.elem(amount) + " to the fountain!"));
}
catch (NumberFormatException ex)
{

View File

@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
import mineplex.core.brawl.fountain.FountainManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -226,6 +227,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
new SoccerManager(this, _gadgetManager);
new KothManager(this, _gadgetManager);
new FountainManager(plugin, hologramManager, statsManager);
//new TrickOrTreatManager(_plugin, this, taskManager, donationManager, clientManager);
_petManager = petManager;

View File

@ -60,11 +60,16 @@ public class Counter
public double getFillPercent()
{
return Math.min(100, (((double) getCount()) / _goal));
return Math.min(1, (((double) getCount()) / _goal));
}
public String getDataKey()
{
return _dataKey;
}
public long getCacheLastUpdated()
{
return _cacheLastUpdated;
}
}

View File

@ -17,6 +17,8 @@ public class CounterRedisRepository extends RedisRepository
super(Region.ALL);
_dataKey = dataKey;
// setNX();
}
/**
@ -61,4 +63,12 @@ public class CounterRedisRepository extends RedisRepository
{
return getKey(_dataKey);
}
// private void setNX()
// {
// try (Jedis jedis = getResource(true))
// {
// jedis.setnx(getKey(), "0");
// }
// }
}