Some cleanup

This commit is contained in:
Shaun Bennett 2015-06-17 21:36:47 -05:00
parent b5f4574b1b
commit 71da87a5ae
5 changed files with 45 additions and 64 deletions

View File

@ -1,8 +0,0 @@
package mineplex.game.clans.clans.worldevent;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
public interface WorldEventListener
{
public void onComplete(WorldEvent event);
}

View File

@ -3,6 +3,8 @@ package mineplex.game.clans.clans.worldevent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
@ -20,16 +22,18 @@ import mineplex.core.MiniPlugin;
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.worldevent.command.WorldEventCommand;
import mineplex.game.clans.clans.worldevent.event.EventState;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.minecraft.game.core.damage.DamageManager;
public class WorldEventManager extends MiniPlugin implements WorldEventListener, ScoreboardElement
public class WorldEventManager extends MiniPlugin implements ScoreboardElement
{
private final WorldEventFactory _factory;
private final Set<WorldEvent> _events;
private final List<WorldEvent> _events;
private ClansManager _clansManager;
private DamageManager _damageManager;
@ -41,7 +45,7 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener,
_clansManager = clansManager;
_damageManager = damageManager;
_factory = new ConcreteWorldEventFactory(this);
_events = new HashSet<WorldEvent>();
_events = new LinkedList<WorldEvent>();
}
@Override
@ -53,12 +57,30 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener,
}
}
@EventHandler
public void removeEvent(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
Iterator<WorldEvent> iterator = _events.iterator();
while (iterator.hasNext())
{
WorldEvent worldEvent = iterator.next();
if (worldEvent.getState() == EventState.END)
{
worldEvent.cleanup();
HandlerList.unregisterAll(worldEvent);
iterator.remove();
}
}
}
private void initializeEvent(WorldEvent event)
{
assert(event != null);
event.start();
event.addListener(this);
getPlugin().getServer().getPluginManager().registerEvents(event, getPlugin());
_events.add(event);
}
@ -92,15 +114,6 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener,
return _damageManager;
}
@Override
public void onComplete(WorldEvent event)
{
// TODO
Bukkit.broadcastMessage("World Event Manager On Complete");
HandlerList.unregisterAll(event);
_events.remove(event);
}
@Override
public void addCommands()
{

View File

@ -51,7 +51,6 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
protected final void spawnEntity()
{
System.out.println("spawn entity");
Location spawnLocation = _entity == null ? _spawnLocation : _entity.getLocation();
T entity = _spawnLocation.getWorld().spawn(spawnLocation, getEntityClass());

View File

@ -12,7 +12,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import mineplex.core.common.schematic.Schematic;
import mineplex.core.common.schematic.SchematicRunnable;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
@ -21,7 +20,6 @@ import mineplex.core.common.data.BlockData;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.EventMap;
import mineplex.game.clans.clans.worldevent.WorldEventListener;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.creature.EventCreature;
import mineplex.minecraft.game.core.damage.DamageManager;
@ -31,19 +29,15 @@ public abstract class WorldEvent implements Listener
private WorldEventManager _eventManager;
private DamageManager _damageManager;
private List<WorldEventListener> _listeners;
private String _name;
private EventState _state;
private Location _cornerLocation;
private EventMap _map;
private Random _random;
private int _ticks;
// Creatures
private List<EventCreature> _creatures;
// Block Restore
private HashMap<Block, BlockData> _blocks;
@ -51,13 +45,16 @@ public abstract class WorldEvent implements Listener
{
_eventManager = eventManager;
_damageManager = damageManager;
_name = name;
_state = EventState.PREPARE;
_cornerLocation = cornerLocation;
_listeners = new ArrayList<WorldEventListener>();
_map = null;
_random = new Random();
_ticks = 0;
_creatures = new ArrayList<EventCreature>();
_blocks = new HashMap<Block, BlockData>();
_state = EventState.PREPARE;
}
public final void start()
@ -71,6 +68,12 @@ public abstract class WorldEvent implements Listener
{
clearCreatures();
restoreBlocks();
customCleanup();
}
public void customCleanup()
{
}
public final void cancel()
@ -80,9 +83,15 @@ public abstract class WorldEvent implements Listener
customCancel();
}
protected abstract void customCancel();
protected void customCancel()
{
protected abstract void customTick();
}
protected void customTick()
{
}
protected void setState(EventState state)
{
@ -94,26 +103,6 @@ public abstract class WorldEvent implements Listener
return _state;
}
public void addListener(WorldEventListener listener)
{
_listeners.add(listener);
}
public void removeListener(WorldEventListener listener)
{
_listeners.remove(listener);
}
protected List<WorldEventListener> getListeners()
{
return _listeners;
}
public void clearListeners()
{
_listeners.clear();
}
public int getTicks()
{
return _ticks;

View File

@ -59,18 +59,6 @@ public class SlimeBoss extends WorldEvent
announceStart();
}
@Override
protected void customCancel()
{
Bukkit.broadcastMessage("Custom Cancel");
}
@Override
protected void customTick()
{
}
/**
* Check if this slime boss has been defeated
*/