From f79c282225dff2ab555d0c6adaaa8b65a125cb7e Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 18 Nov 2015 07:39:00 +0000 Subject: [PATCH] Clan energy warnings implemented. (not tested yet) --- .../src/mineplex/core/updater/UpdateType.java | 4 + .../game/clans/clans/ClanEnergyTracker.java | 142 ++++++++++++++++++ .../game/clans/clans/ClansManager.java | 2 + 3 files changed, 148 insertions(+) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanEnergyTracker.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/updater/UpdateType.java b/Plugins/Mineplex.Core/src/mineplex/core/updater/UpdateType.java index 558312fc0..cc20bb94c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/updater/UpdateType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/updater/UpdateType.java @@ -5,9 +5,13 @@ import mineplex.core.common.util.UtilTime; public enum UpdateType { MIN_64(3840000), + HOUR_01(3600000), MIN_32(1920000), + MIN_30(1800000), MIN_16(960000), + MIN_10(600000), MIN_08(480000), + MIN_05(300000), MIN_04(240000), MIN_02(120000), MIN_01(60000), diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanEnergyTracker.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanEnergyTracker.java new file mode 100644 index 000000000..a938137ac --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanEnergyTracker.java @@ -0,0 +1,142 @@ +package mineplex.game.clans.clans; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class ClanEnergyTracker extends MiniPlugin +{ + private ClansManager _clans; + + public ClanEnergyTracker(JavaPlugin plugin, ClansManager clans) + { + super("Clan Energy Tracker", plugin); + _clans = clans; + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (event.getType() == UpdateType.MIN_05) + { + for (String clanName : _clans.getClanNameSet()) + { + ClanInfo clan = _clans.getClan(clanName); + + if (clan.isOnlineNow()) + { + if (displayFor(clan, event.getType())) + { + for (Player player : clan.getOnlinePlayers()) + { + UtilTextMiddle.display(C.cRed + "Urgent", "Clan Energy is almost depleted"); + UtilPlayer.message(player, F.main("Energy", "To top up your Clan's Energy, head to the shop and go to the Energy Shop!")); + } + } + } + } + } + else if (event.getType() == UpdateType.MIN_10) + { + for (String clanName : _clans.getClanNameSet()) + { + ClanInfo clan = _clans.getClan(clanName); + + if (clan.isOnlineNow()) + { + if (displayFor(clan, event.getType())) + { + for (Player player : clan.getOnlinePlayers()) + { + UtilTextMiddle.display(C.cGold + "Warning", "Clan Energy is almost depleted"); + UtilPlayer.message(player, F.main("Energy", "To top up your Clan's Energy, head to the shop and go to the Energy Shop!")); + } + } + } + } + } + else if (event.getType() == UpdateType.MIN_30) + { + for (String clanName : _clans.getClanNameSet()) + { + ClanInfo clan = _clans.getClan(clanName); + + if (clan.isOnlineNow()) + { + if (displayFor(clan, event.getType())) + { + for (Player player : clan.getOnlinePlayers()) + { + UtilTextMiddle.display(C.cYellow + "Energy", "Clan Energy is running low"); + UtilPlayer.message(player, F.main("Energy", "To top up your Clan's Energy, head to the shop and go to the Energy Shop!")); + } + } + } + } + } + else if (event.getType() == UpdateType.HOUR_01) + { + for (String clanName : _clans.getClanNameSet()) + { + ClanInfo clan = _clans.getClan(clanName); + + if (clan.isOnlineNow()) + { + if (displayFor(clan, event.getType())) + { + for (Player player : clan.getOnlinePlayers()) + { + UtilTextMiddle.display(C.cYellow + "Energy", "Clan Energy is running low"); + UtilPlayer.message(player, F.main("Energy", "To top up your Clan's Energy, head to the shop and go to the Energy Shop!")); + } + } + } + } + } + } + + private boolean displayFor(ClanInfo clan, UpdateType type) + { + double energyRemainingSeconds = ((60000L * clan.getEnergy()) / (clan.getEnergyCostPerMinute())) / 1000.0D; + + switch (type) + { + case MIN_05: + if (energyRemainingSeconds <= (1000 * 60 * 60)) + { + return clan.isOnlineNow(); + } + break; + case MIN_10: + if (energyRemainingSeconds <= (1000 * 60 * 60 * 4)) + { + return clan.isOnlineNow(); + } + break; + case MIN_30: + if (energyRemainingSeconds <= (1000 * 60 * 60 * 24)) + { + return clan.isOnlineNow(); + } + break; + case HOUR_01: + if (energyRemainingSeconds <= (1000 * 60 * 60 * 48)) + { + return clan.isOnlineNow(); + } + break; + + } + + return false; + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 09d6c69ea..ad44cf829 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -235,6 +235,8 @@ public class ClansManager extends MiniClientPlugin implements IRelat new SafeLog(plugin, this); new ObserverManager(plugin, _condition, this); + new ClanEnergyTracker(plugin, this); + new ClansAlphaManager(this, taskManager); new Weapon(plugin, energy);