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,53 +17,67 @@ 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;
private EventTerrainFinder _terrainFinder;
private DamageManager _damageManager;
private LootManager _lootManager;
private BlockRestore _blockRestore;
private long _lastEventEnd;
private long _nextEventStart;
public WorldEventManager(JavaPlugin plugin, ClansManager clansManager, DamageManager damageManager, LootManager lootManager, BlockRestore blockRestore)
{
super("World Event", plugin);
_random = new Random();
_terrainFinder = new EventTerrainFinder(this, clansManager);
_clansManager = clansManager;
_damageManager = damageManager;
_lootManager = lootManager;
_blockRestore = blockRestore;
_events = new LinkedList<WorldEvent>();
_runningEvents = new LinkedList<WorldEvent>();
_lastEventEnd = System.currentTimeMillis();
updateNextEventTime();
}
@Override
public void disable()
{
for (WorldEvent event : _events)
for (WorldEvent event : _runningEvents)
{
event.cancel();
}
}
@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();
@ -85,41 +85,42 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
{
HandlerList.unregisterAll(worldEvent);
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()
{
WorldEventType[] types = WorldEventType.values();
@ -135,17 +136,17 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
_nextEventStart = System.currentTimeMillis() + 300000;
}
}
private void initializeEvent(WorldEvent event)
{
assert(event != null);
event.loadMap();
event.start();
getPlugin().getServer().getPluginManager().registerEvents(event, getPlugin());
_events.add(event);
_runningEvents.add(event);
}
public WorldEvent startEventFromName(Location location, String name)
{
WorldEventType eventType = WorldEventType.valueOf(name);
@ -155,13 +156,13 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
initializeEvent(event);
return event;
}
return null;
}
public void clearEvents()
{
Iterator<WorldEvent> iterator = _events.iterator();
Iterator<WorldEvent> iterator = _runningEvents.iterator();
while (iterator.hasNext())
{
WorldEvent event = iterator.next();
@ -169,89 +170,88 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
HandlerList.unregisterAll(event);
iterator.remove();
}
updateNextEventTime();
}
public ClansManager getClans()
{
return _clansManager;
}
public DamageManager getDamage()
{
return _damageManager;
}
public LootManager getLoot()
{
return _lootManager;
}
public EventTerrainFinder getTerrainFinder()
{
return _terrainFinder;
}
@Override
public void addCommands()
{
addCommand(new WorldEventCommand(this));
}
private void updateNextEventTime()
{
// 45 Minutes + 0 - 15 Minutes
long waitTime = 2700000L + _random.nextInt(900000);
_nextEventStart = System.currentTimeMillis() + waitTime;
}
@Override
public ArrayList<String> getLines(ScoreboardManager manager, Player player, ArrayList<String> out)
{
ArrayList<String> output = new ArrayList<String>();
Iterator<WorldEvent> iterator = _events.iterator();
Iterator<WorldEvent> iterator = _runningEvents.iterator();
while (iterator.hasNext())
{
WorldEvent event = iterator.next();
if (event.getState() == EventState.LIVE)
{
output.add(" ");
output.add(C.cAqua + C.Bold + "Event");
Location eventLocation = event.getCenterLocation();
String locationString = eventLocation.getBlockX() + ", " + eventLocation.getBlockY() + ", " + eventLocation.getBlockZ();
output.add(" " + C.cWhite + event.getName());
output.add(" " + C.cWhite + locationString);
ArrayList<String> scoreboardLines = event.getScoreboardLines();
if (scoreboardLines != null) output.addAll(event.getScoreboardLines());
break;
}
}
return output;
}
public BlockRestore getBlockRestore()
{
return _blockRestore;
}
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"))
{