Formatted WorldEventManager (seperate commit for formatting so that confusion doesn't arise in future commits)

This commit is contained in:
NewGarbo 2015-11-13 21:19:50 +00:00
parent a0ac15dec5
commit 8a972075da

View File

@ -6,20 +6,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import mineplex.core.MiniPlugin;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.util.C;
import mineplex.core.scoreboard.ScoreboardManager;
import mineplex.core.scoreboard.elements.ScoreboardElement;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.worldevent.command.WorldEventCommand;
import mineplex.minecraft.game.core.boss.EventState;
import mineplex.minecraft.game.core.boss.WorldEvent;
import mineplex.minecraft.game.core.damage.DamageManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -31,9 +17,24 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer;
import mineplex.core.scoreboard.ScoreboardManager;
import mineplex.core.scoreboard.elements.ScoreboardElement;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.worldevent.command.WorldEventCommand;
import mineplex.minecraft.game.core.boss.EventState;
import mineplex.minecraft.game.core.boss.WorldEvent;
import mineplex.minecraft.game.core.damage.DamageManager;
public class WorldEventManager extends MiniPlugin implements ScoreboardElement
{
private final List<WorldEvent> _events;
private final List<WorldEvent> _runningEvents;
private Random _random;
private ClansManager _clansManager;
@ -55,7 +56,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
_damageManager = damageManager;
_lootManager = lootManager;
_blockRestore = blockRestore;
_events = new LinkedList<WorldEvent>();
_runningEvents = new LinkedList<WorldEvent>();
_lastEventEnd = System.currentTimeMillis();
updateNextEventTime();
}
@ -63,7 +64,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
@Override
public void disable()
{
for (WorldEvent event : _events)
for (WorldEvent event : _runningEvents)
{
event.cancel();
}
@ -72,12 +73,11 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
@EventHandler
public void removeEvent(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (event.getType() != UpdateType.SEC) return;
boolean removed = false;
Iterator<WorldEvent> iterator = _events.iterator();
Iterator<WorldEvent> iterator = _runningEvents.iterator();
while (iterator.hasNext())
{
WorldEvent worldEvent = iterator.next();
@ -87,38 +87,39 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
iterator.remove();
// If the event was cancelled, we don't need to run a cleanup
if (worldEvent.getState() == EventState.COMPLETE) worldEvent.cleanup();
if (worldEvent.getState() == EventState.COMPLETE)
{
worldEvent.cleanup();
}
removed = true;
_lastEventEnd = System.currentTimeMillis();
}
}
if (removed && _events.size() == 0)
if (removed && _runningEvents.size() == 0)
{
updateNextEventTime();
}
}
// @EventHandler
// public void startEvent(UpdateEvent event)
// {
// if (event.getType() != UpdateType.SEC)
// return;
//
// if (_events.size() == 0 && System.currentTimeMillis() > _nextEventStart)
// {
// if (UtilServer.getPlayers().length > 0)
// {
// Bukkit.broadcastMessage("Starting new event from random...");
// startRandomEvent();
// }
// else
// {
// updateNextEventTime();
// }
// }
// }
@EventHandler
public void startEvent(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC) return;
if (_runningEvents.size() == 0 && System.currentTimeMillis() > _nextEventStart)
{
if (UtilServer.getPlayers().length > 0)
{
startRandomEvent();
}
else
{
updateNextEventTime();
}
}
}
private void startRandomEvent()
{
@ -143,7 +144,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
event.loadMap();
event.start();
getPlugin().getServer().getPluginManager().registerEvents(event, getPlugin());
_events.add(event);
_runningEvents.add(event);
}
public WorldEvent startEventFromName(Location location, String name)
@ -161,7 +162,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
public void clearEvents()
{
Iterator<WorldEvent> iterator = _events.iterator();
Iterator<WorldEvent> iterator = _runningEvents.iterator();
while (iterator.hasNext())
{
WorldEvent event = iterator.next();
@ -211,7 +212,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
{
ArrayList<String> output = new ArrayList<String>();
Iterator<WorldEvent> iterator = _events.iterator();
Iterator<WorldEvent> iterator = _runningEvents.iterator();
while (iterator.hasNext())
{
WorldEvent event = iterator.next();
@ -243,14 +244,13 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
public List<WorldEvent> getEvents()
{
return _events;
return _runningEvents;
}
@EventHandler
public void gear(PlayerCommandPreprocessEvent event)
{
if (!event.getPlayer().isOp())
return;
if (!event.getPlayer().isOp()) return;
// TODO: Remove
if (event.getMessage().equalsIgnoreCase("/dgear"))