king of the hill changes. (renamed enum for it for ease of typing)

This commit is contained in:
NewGarbo 2015-11-15 19:57:00 +00:00
parent c247fe9317
commit 22ae67ba81
3 changed files with 62 additions and 14 deletions

View File

@ -0,0 +1,27 @@
package mineplex.core.common.util;
import org.bukkit.scheduler.BukkitRunnable;
public abstract class LimitedBukkitRunnable extends BukkitRunnable
{
private int _timesRun;
private int _maxTimes;
public LimitedBukkitRunnable(int maxTimes)
{
_maxTimes = maxTimes;
}
@Override
public void run()
{
if (_timesRun > _maxTimes){
UtilServer.getServer().getScheduler().cancelTask(getTaskId());
return;
}
onRun(_timesRun);
}
public abstract void onRun(int timesRun);
}

View File

@ -8,8 +8,10 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LimitedBukkitRunnable;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.scoreboard.ScoreboardManager;
@ -25,7 +27,9 @@ public class KingHill extends WorldEvent
{
private static List<HillData> LOADED_HILLS = new ArrayList<HillData>();
private static int GOLD_PER_TICK = 1;
private static int GOLD_PER_TICK = 5;
private ClanInfo _clanOnHill;
static
{
@ -48,6 +52,9 @@ public class KingHill extends WorldEvent
private long _nextLootDrop;
private int _lootDropCount;
private long _lastGoldDrop;
private long _lastOnHillMessage;
public KingHill(WorldEventManager eventManager, Location centerLocation)
{
super(eventManager.getClans().getDisguiseManager(), eventManager.getClans().getProjectile(), eventManager.getDamage(), eventManager.getBlockRestore(), eventManager.getClans().getCondition(), "King of the Hill", centerLocation);
@ -116,6 +123,8 @@ public class KingHill extends WorldEvent
if (clanCount == 1 && lastClan != null)
{
_clanOnHill = lastClan;
CaptureData capData = _scoreMap.get(lastClan);
if (capData == null)
{
@ -124,12 +133,28 @@ public class KingHill extends WorldEvent
}
capData.TicksOnHill++;
if (getTicksRunning() % 40 == 0)
if (System.currentTimeMillis() - _lastGoldDrop > 30000)
{
Bukkit.broadcastMessage(F.desc("Hill", F.elem(lastClan.getName()) + " own the hill (" + F.time(UtilTime.MakeStr(capData.TicksOnHill*50)) + ")"));
UtilServer.getServer().getScheduler().scheduleSyncRepeatingTask(getPlugin(), new LimitedBukkitRunnable(100)
{
public void onRun(int timesRun)
{
GoldManager.getInstance().dropGold(getCenterLocation().clone().add(0, 13, 0), GOLD_PER_TICK);
}
}, 0L, 1L);
_lastGoldDrop = System.currentTimeMillis();
}
GoldManager.getInstance().dropGold(getCenterLocation().clone().add(0, 13, 0), GOLD_PER_TICK);
if (System.currentTimeMillis() - _lastOnHillMessage > 30000)
{
Bukkit.broadcastMessage(F.desc("Hill", F.elem(lastClan.getName()) + " own the hill (" + F.time(UtilTime.MakeStr(capData.TicksOnHill * 50)) + ")"));
_lastOnHillMessage = System.currentTimeMillis();
}
}
else
{
_clanOnHill = null;
}
}
@ -138,11 +163,9 @@ public class KingHill extends WorldEvent
{
ArrayList<String> list = new ArrayList<String>(1);
ClanInfo clan = _clansManager.getClan(player);
if (clan != null)
if (_clanOnHill != null && _scoreMap.containsKey(_clanOnHill))
{
list.add(" Time on hill: " + UtilTime.MakeStr(_scoreMap.get(clan).TicksOnHill * 50));
list.add(" " + _clanOnHill.getName() + " are on the Hill");
}
return list;

View File

@ -54,7 +54,7 @@ public abstract class WorldEvent implements Listener, ScoreboardElement
private Location _cornerLocation;
private EventMap _map;
private Random _random;
private int _ticksRunning;
private long _timeStarted = System.currentTimeMillis();
private long _lastActive;
private Schematic _schematic;
@ -81,7 +81,6 @@ public abstract class WorldEvent implements Listener, ScoreboardElement
_state = EventState.PREPARE;
_cornerLocation = cornerLocation;
_random = new Random();
_ticksRunning = 0;
_creatures = new ArrayList<>();
_blocks = blockRestore.createMap();
@ -218,9 +217,9 @@ public abstract class WorldEvent implements Listener, ScoreboardElement
return _state;
}
public int getTicksRunning()
public long getTimeRunning()
{
return _ticksRunning;
return System.currentTimeMillis() - _timeStarted;
}
public DamageManager getDamageManager()
@ -371,7 +370,6 @@ public abstract class WorldEvent implements Listener, ScoreboardElement
return;
}
_ticksRunning++;
customTick();
}
@ -404,7 +402,7 @@ public abstract class WorldEvent implements Listener, ScoreboardElement
}
// Event was preparing for more than 5 minutes
if (getTicksRunning() > 6000)
if (getTimeRunning() > 1000 * 60 * 5)
{
cancel();
}