Formatted WorldEventManager (seperate commit for formatting so that confusion doesn't arise in future commits)
This commit is contained in:
parent
a0ac15dec5
commit
8a972075da
@ -6,20 +6,6 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
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.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -31,9 +17,24 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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
|
public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
||||||
{
|
{
|
||||||
private final List<WorldEvent> _events;
|
private final List<WorldEvent> _runningEvents;
|
||||||
|
|
||||||
private Random _random;
|
private Random _random;
|
||||||
private ClansManager _clansManager;
|
private ClansManager _clansManager;
|
||||||
@ -55,7 +56,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
|||||||
_damageManager = damageManager;
|
_damageManager = damageManager;
|
||||||
_lootManager = lootManager;
|
_lootManager = lootManager;
|
||||||
_blockRestore = blockRestore;
|
_blockRestore = blockRestore;
|
||||||
_events = new LinkedList<WorldEvent>();
|
_runningEvents = new LinkedList<WorldEvent>();
|
||||||
_lastEventEnd = System.currentTimeMillis();
|
_lastEventEnd = System.currentTimeMillis();
|
||||||
updateNextEventTime();
|
updateNextEventTime();
|
||||||
}
|
}
|
||||||
@ -63,7 +64,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
|||||||
@Override
|
@Override
|
||||||
public void disable()
|
public void disable()
|
||||||
{
|
{
|
||||||
for (WorldEvent event : _events)
|
for (WorldEvent event : _runningEvents)
|
||||||
{
|
{
|
||||||
event.cancel();
|
event.cancel();
|
||||||
}
|
}
|
||||||
@ -72,12 +73,11 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void removeEvent(UpdateEvent event)
|
public void removeEvent(UpdateEvent event)
|
||||||
{
|
{
|
||||||
if (event.getType() != UpdateType.SEC)
|
if (event.getType() != UpdateType.SEC) return;
|
||||||
return;
|
|
||||||
|
|
||||||
boolean removed = false;
|
boolean removed = false;
|
||||||
|
|
||||||
Iterator<WorldEvent> iterator = _events.iterator();
|
Iterator<WorldEvent> iterator = _runningEvents.iterator();
|
||||||
while (iterator.hasNext())
|
while (iterator.hasNext())
|
||||||
{
|
{
|
||||||
WorldEvent worldEvent = iterator.next();
|
WorldEvent worldEvent = iterator.next();
|
||||||
@ -87,38 +87,39 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
|||||||
iterator.remove();
|
iterator.remove();
|
||||||
|
|
||||||
// If the event was cancelled, we don't need to run a cleanup
|
// 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;
|
removed = true;
|
||||||
_lastEventEnd = System.currentTimeMillis();
|
_lastEventEnd = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removed && _events.size() == 0)
|
if (removed && _runningEvents.size() == 0)
|
||||||
{
|
{
|
||||||
updateNextEventTime();
|
updateNextEventTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @EventHandler
|
@EventHandler
|
||||||
// public void startEvent(UpdateEvent event)
|
public void startEvent(UpdateEvent event)
|
||||||
// {
|
{
|
||||||
// if (event.getType() != UpdateType.SEC)
|
if (event.getType() != UpdateType.SEC) return;
|
||||||
// return;
|
|
||||||
//
|
if (_runningEvents.size() == 0 && System.currentTimeMillis() > _nextEventStart)
|
||||||
// if (_events.size() == 0 && System.currentTimeMillis() > _nextEventStart)
|
{
|
||||||
// {
|
if (UtilServer.getPlayers().length > 0)
|
||||||
// if (UtilServer.getPlayers().length > 0)
|
{
|
||||||
// {
|
startRandomEvent();
|
||||||
// Bukkit.broadcastMessage("Starting new event from random...");
|
}
|
||||||
// startRandomEvent();
|
else
|
||||||
// }
|
{
|
||||||
// else
|
updateNextEventTime();
|
||||||
// {
|
}
|
||||||
// updateNextEventTime();
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private void startRandomEvent()
|
private void startRandomEvent()
|
||||||
{
|
{
|
||||||
@ -143,7 +144,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
|||||||
event.loadMap();
|
event.loadMap();
|
||||||
event.start();
|
event.start();
|
||||||
getPlugin().getServer().getPluginManager().registerEvents(event, getPlugin());
|
getPlugin().getServer().getPluginManager().registerEvents(event, getPlugin());
|
||||||
_events.add(event);
|
_runningEvents.add(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldEvent startEventFromName(Location location, String name)
|
public WorldEvent startEventFromName(Location location, String name)
|
||||||
@ -161,7 +162,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
|||||||
|
|
||||||
public void clearEvents()
|
public void clearEvents()
|
||||||
{
|
{
|
||||||
Iterator<WorldEvent> iterator = _events.iterator();
|
Iterator<WorldEvent> iterator = _runningEvents.iterator();
|
||||||
while (iterator.hasNext())
|
while (iterator.hasNext())
|
||||||
{
|
{
|
||||||
WorldEvent event = iterator.next();
|
WorldEvent event = iterator.next();
|
||||||
@ -211,7 +212,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
|||||||
{
|
{
|
||||||
ArrayList<String> output = new ArrayList<String>();
|
ArrayList<String> output = new ArrayList<String>();
|
||||||
|
|
||||||
Iterator<WorldEvent> iterator = _events.iterator();
|
Iterator<WorldEvent> iterator = _runningEvents.iterator();
|
||||||
while (iterator.hasNext())
|
while (iterator.hasNext())
|
||||||
{
|
{
|
||||||
WorldEvent event = iterator.next();
|
WorldEvent event = iterator.next();
|
||||||
@ -243,14 +244,13 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
|||||||
|
|
||||||
public List<WorldEvent> getEvents()
|
public List<WorldEvent> getEvents()
|
||||||
{
|
{
|
||||||
return _events;
|
return _runningEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void gear(PlayerCommandPreprocessEvent event)
|
public void gear(PlayerCommandPreprocessEvent event)
|
||||||
{
|
{
|
||||||
if (!event.getPlayer().isOp())
|
if (!event.getPlayer().isOp()) return;
|
||||||
return;
|
|
||||||
|
|
||||||
// TODO: Remove
|
// TODO: Remove
|
||||||
if (event.getMessage().equalsIgnoreCase("/dgear"))
|
if (event.getMessage().equalsIgnoreCase("/dgear"))
|
||||||
|
Loading…
Reference in New Issue
Block a user