From cb48df6a3d3ffa04f456fb46d203ffb4e85f27f0 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Tue, 19 Apr 2016 14:30:38 +1000 Subject: [PATCH] Update fountain count every 5 seconds. Display Hologram --- .../src/mineplex/core/brawl/fountain/Fountain.java | 13 ++++++++++++- .../core/brawl/fountain/FountainManager.java | 6 ++++-- .../core/brawl/fountain/command/AddCommand.java | 1 + .../Mineplex.Hub/src/mineplex/hub/HubManager.java | 3 +++ .../mineplex/serverdata/redis/counter/Counter.java | 7 ++++++- .../redis/counter/CounterRedisRepository.java | 10 ++++++++++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java index 564034ec3..319b37420 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/Fountain.java @@ -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); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java index c0c35e2e0..03697dd76 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java @@ -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() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java index f296c735d..1a6235154 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/command/AddCommand.java @@ -30,6 +30,7 @@ public class AddCommand extends CommandBase { 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) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index da9d102aa..99ada65fe 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -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; @@ -225,6 +226,8 @@ public class HubManager extends MiniClientPlugin new SoccerManager(this, _gadgetManager); new KothManager(this, _gadgetManager); + + new FountainManager(plugin, hologramManager, statsManager); //new TrickOrTreatManager(_plugin, this, taskManager, donationManager, clientManager); diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java index f7dfb9199..a7cad37f2 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/Counter.java @@ -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; + } } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java index eebf35e20..478e2e7f3 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/counter/CounterRedisRepository.java @@ -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"); +// } +// } }