Use bounds for energy tracker messages aren't displayed multiple times

This commit is contained in:
Shaun Bennett 2015-11-19 14:44:03 -05:00
parent 63e580404c
commit f47a61e38e

View File

@ -1,36 +1,33 @@
package mineplex.game.clans.clans;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.concurrent.TimeUnit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Pair;
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;
private EnumMap<UpdateType, Long> _updateMap;
private EnumMap<UpdateType, Pair<Long, Long>> _updateMap;
public ClanEnergyTracker(JavaPlugin plugin, ClansManager clans)
{
super("Clan Energy Tracker", plugin);
_clans = clans;
_updateMap = new EnumMap<UpdateType, Long>(UpdateType.class);
_updateMap.put(UpdateType.MIN_05, TimeUnit.HOURS.toMillis(1));
_updateMap.put(UpdateType.MIN_10, TimeUnit.HOURS.toMillis(4));
_updateMap.put(UpdateType.MIN_30, TimeUnit.DAYS.toMillis(1));
_updateMap.put(UpdateType.HOUR_01, TimeUnit.DAYS.toMillis(2));
_updateMap = new EnumMap<UpdateType, Pair<Long, Long>>(UpdateType.class);
_updateMap.put(UpdateType.MIN_05, Pair.create(0L, TimeUnit.HOURS.toMillis(1)));
_updateMap.put(UpdateType.MIN_10, Pair.create(TimeUnit.HOURS.toMillis(1), TimeUnit.HOURS.toMillis(4)));
_updateMap.put(UpdateType.MIN_30, Pair.create(TimeUnit.HOURS.toMillis(4), TimeUnit.DAYS.toMillis(1)));
_updateMap.put(UpdateType.HOUR_01, Pair.create(TimeUnit.DAYS.toMillis(1), TimeUnit.DAYS.toMillis(2)));
}
@EventHandler
@ -42,9 +39,7 @@ public class ClanEnergyTracker extends MiniPlugin
if (_updateMap.containsKey(event.getType()))
{
for (ClanInfo clan : _clans.getClanMap().values())
{
display(clan, event.getType());
}
}
}
@ -60,13 +55,12 @@ public class ClanEnergyTracker extends MiniPlugin
// Energy Remaining in milliseconds
long energyRemaining = (clan.getEnergy() / clan.getEnergyCostPerMinute()) * 60000L;
Long energyForDisplay = _updateMap.get(type);
Pair<Long, Long> energyBounds = _updateMap.get(type);
if (energyForDisplay != null && energyRemaining < energyForDisplay.longValue())
if (energyBounds != null && energyRemaining > energyBounds.getLeft() && energyRemaining < energyBounds.getRight())
{
_clans.middleTextClan(clan, C.cRed + "Urgent", "Clan Energy is almost depleted", 20, 200, 80);
_clans.messageClan(clan, F.main("Energy", "To top up your Clan's Energy, head to the shop and go to the Energy Shop!"));
}
}
}