Some cleanup
This commit is contained in:
parent
b5f4574b1b
commit
71da87a5ae
@ -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);
|
|
||||||
}
|
|
@ -3,6 +3,8 @@ package mineplex.game.clans.clans.worldevent;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -20,16 +22,18 @@ import mineplex.core.MiniPlugin;
|
|||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.scoreboard.ScoreboardManager;
|
import mineplex.core.scoreboard.ScoreboardManager;
|
||||||
import mineplex.core.scoreboard.elements.ScoreboardElement;
|
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.ClansManager;
|
||||||
import mineplex.game.clans.clans.worldevent.command.WorldEventCommand;
|
import mineplex.game.clans.clans.worldevent.command.WorldEventCommand;
|
||||||
import mineplex.game.clans.clans.worldevent.event.EventState;
|
import mineplex.game.clans.clans.worldevent.event.EventState;
|
||||||
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
|
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
|
||||||
import mineplex.minecraft.game.core.damage.DamageManager;
|
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 WorldEventFactory _factory;
|
||||||
private final Set<WorldEvent> _events;
|
private final List<WorldEvent> _events;
|
||||||
|
|
||||||
private ClansManager _clansManager;
|
private ClansManager _clansManager;
|
||||||
private DamageManager _damageManager;
|
private DamageManager _damageManager;
|
||||||
@ -41,7 +45,7 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener,
|
|||||||
_clansManager = clansManager;
|
_clansManager = clansManager;
|
||||||
_damageManager = damageManager;
|
_damageManager = damageManager;
|
||||||
_factory = new ConcreteWorldEventFactory(this);
|
_factory = new ConcreteWorldEventFactory(this);
|
||||||
_events = new HashSet<WorldEvent>();
|
_events = new LinkedList<WorldEvent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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)
|
private void initializeEvent(WorldEvent event)
|
||||||
{
|
{
|
||||||
assert(event != null);
|
assert(event != null);
|
||||||
|
|
||||||
event.start();
|
event.start();
|
||||||
event.addListener(this);
|
|
||||||
getPlugin().getServer().getPluginManager().registerEvents(event, getPlugin());
|
getPlugin().getServer().getPluginManager().registerEvents(event, getPlugin());
|
||||||
_events.add(event);
|
_events.add(event);
|
||||||
}
|
}
|
||||||
@ -92,15 +114,6 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener,
|
|||||||
return _damageManager;
|
return _damageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete(WorldEvent event)
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
Bukkit.broadcastMessage("World Event Manager On Complete");
|
|
||||||
HandlerList.unregisterAll(event);
|
|
||||||
_events.remove(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCommands()
|
public void addCommands()
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,6 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
|
|||||||
|
|
||||||
protected final void spawnEntity()
|
protected final void spawnEntity()
|
||||||
{
|
{
|
||||||
System.out.println("spawn entity");
|
|
||||||
Location spawnLocation = _entity == null ? _spawnLocation : _entity.getLocation();
|
Location spawnLocation = _entity == null ? _spawnLocation : _entity.getLocation();
|
||||||
T entity = _spawnLocation.getWorld().spawn(spawnLocation, getEntityClass());
|
T entity = _spawnLocation.getWorld().spawn(spawnLocation, getEntityClass());
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import mineplex.core.common.schematic.Schematic;
|
|
||||||
import mineplex.core.common.schematic.SchematicRunnable;
|
import mineplex.core.common.schematic.SchematicRunnable;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.F;
|
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.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
import mineplex.game.clans.clans.worldevent.EventMap;
|
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.WorldEventManager;
|
||||||
import mineplex.game.clans.clans.worldevent.creature.EventCreature;
|
import mineplex.game.clans.clans.worldevent.creature.EventCreature;
|
||||||
import mineplex.minecraft.game.core.damage.DamageManager;
|
import mineplex.minecraft.game.core.damage.DamageManager;
|
||||||
@ -31,19 +29,15 @@ public abstract class WorldEvent implements Listener
|
|||||||
private WorldEventManager _eventManager;
|
private WorldEventManager _eventManager;
|
||||||
private DamageManager _damageManager;
|
private DamageManager _damageManager;
|
||||||
|
|
||||||
private List<WorldEventListener> _listeners;
|
|
||||||
|
|
||||||
private String _name;
|
private String _name;
|
||||||
private EventState _state;
|
private EventState _state;
|
||||||
private Location _cornerLocation;
|
private Location _cornerLocation;
|
||||||
private EventMap _map;
|
private EventMap _map;
|
||||||
|
|
||||||
private Random _random;
|
private Random _random;
|
||||||
private int _ticks;
|
private int _ticks;
|
||||||
|
|
||||||
// Creatures
|
// Creatures
|
||||||
private List<EventCreature> _creatures;
|
private List<EventCreature> _creatures;
|
||||||
|
|
||||||
// Block Restore
|
// Block Restore
|
||||||
private HashMap<Block, BlockData> _blocks;
|
private HashMap<Block, BlockData> _blocks;
|
||||||
|
|
||||||
@ -51,13 +45,16 @@ public abstract class WorldEvent implements Listener
|
|||||||
{
|
{
|
||||||
_eventManager = eventManager;
|
_eventManager = eventManager;
|
||||||
_damageManager = damageManager;
|
_damageManager = damageManager;
|
||||||
|
|
||||||
_name = name;
|
_name = name;
|
||||||
|
_state = EventState.PREPARE;
|
||||||
_cornerLocation = cornerLocation;
|
_cornerLocation = cornerLocation;
|
||||||
_listeners = new ArrayList<WorldEventListener>();
|
_map = null;
|
||||||
_random = new Random();
|
_random = new Random();
|
||||||
|
_ticks = 0;
|
||||||
|
|
||||||
_creatures = new ArrayList<EventCreature>();
|
_creatures = new ArrayList<EventCreature>();
|
||||||
_blocks = new HashMap<Block, BlockData>();
|
_blocks = new HashMap<Block, BlockData>();
|
||||||
_state = EventState.PREPARE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void start()
|
public final void start()
|
||||||
@ -71,6 +68,12 @@ public abstract class WorldEvent implements Listener
|
|||||||
{
|
{
|
||||||
clearCreatures();
|
clearCreatures();
|
||||||
restoreBlocks();
|
restoreBlocks();
|
||||||
|
customCleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void customCleanup()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void cancel()
|
public final void cancel()
|
||||||
@ -80,9 +83,15 @@ public abstract class WorldEvent implements Listener
|
|||||||
customCancel();
|
customCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void customCancel();
|
protected void customCancel()
|
||||||
|
{
|
||||||
|
|
||||||
protected abstract void customTick();
|
}
|
||||||
|
|
||||||
|
protected void customTick()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected void setState(EventState state)
|
protected void setState(EventState state)
|
||||||
{
|
{
|
||||||
@ -94,26 +103,6 @@ public abstract class WorldEvent implements Listener
|
|||||||
return _state;
|
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()
|
public int getTicks()
|
||||||
{
|
{
|
||||||
return _ticks;
|
return _ticks;
|
||||||
|
@ -59,18 +59,6 @@ public class SlimeBoss extends WorldEvent
|
|||||||
announceStart();
|
announceStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void customCancel()
|
|
||||||
{
|
|
||||||
Bukkit.broadcastMessage("Custom Cancel");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void customTick()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this slime boss has been defeated
|
* Check if this slime boss has been defeated
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user