diff --git a/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java b/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java index a2b1a3e5..adea0235 100644 --- a/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/PlayCommand.java @@ -4,6 +4,7 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; @@ -92,6 +93,16 @@ public class PlayCommand extends DCommand { DGroup dGroup = new DGroup(player, identifier, multiFloor); + DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); + + if (event.isCancelled()) { + dGroup = null; + } + + if (dGroup == null) { + return; + } + if (dGroup.getGameWorld() == null) { dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName())); } diff --git a/src/io/github/dre2n/dungeonsxl/command/TestCommand.java b/src/io/github/dre2n/dungeonsxl/command/TestCommand.java index 8fb9567e..23cee7cf 100644 --- a/src/io/github/dre2n/dungeonsxl/command/TestCommand.java +++ b/src/io/github/dre2n/dungeonsxl/command/TestCommand.java @@ -3,6 +3,7 @@ package io.github.dre2n.dungeonsxl.command; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPlayer; @@ -68,6 +69,16 @@ public class TestCommand extends DCommand { DGroup dGroup = new DGroup(player, identifier, multiFloor); + DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND); + + if (event.isCancelled()) { + dGroup = null; + } + + if (dGroup == null) { + return; + } + if (dGroup.getGameWorld() == null) { dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName())); } diff --git a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java index a018d5ae..4c82b0d4 100644 --- a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java +++ b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupCreateEvent.java @@ -8,14 +8,25 @@ import org.bukkit.event.HandlerList; public class DGroupCreateEvent extends DGroupEvent implements Cancellable { + public enum Cause { + + COMMAND, + GROUP_SIGN, + CUSTOM; + + } + private static final HandlerList handlers = new HandlerList(); private boolean cancelled; private Player creator; - public DGroupCreateEvent(DGroup dGroup, Player creator) { + private Cause cause; + + public DGroupCreateEvent(DGroup dGroup, Player creator, Cause cause) { super(dGroup); this.creator = creator; + this.cause = cause; } /** @@ -33,6 +44,21 @@ public class DGroupCreateEvent extends DGroupEvent implements Cancellable { this.creator = creator; } + /** + * @return the cause + */ + public Cause getCause() { + return cause; + } + + /** + * @param cause + * the cause to set + */ + public void setCause(Cause cause) { + this.cause = cause; + } + @Override public HandlerList getHandlers() { return handlers; diff --git a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupJoinGameWorldEvent.java b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupStartFloorEvent.java similarity index 86% rename from src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupJoinGameWorldEvent.java rename to src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupStartFloorEvent.java index 1e658d62..1dc9d1c0 100644 --- a/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupJoinGameWorldEvent.java +++ b/src/io/github/dre2n/dungeonsxl/event/dgroup/DGroupStartFloorEvent.java @@ -6,14 +6,14 @@ import io.github.dre2n.dungeonsxl.player.DGroup; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -public class DGroupJoinGameWorldEvent extends DGroupEvent implements Cancellable { +public class DGroupStartFloorEvent extends DGroupEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; private GameWorld gameWorld; - public DGroupJoinGameWorldEvent(DGroup dGroup, GameWorld gameWorld) { + public DGroupStartFloorEvent(DGroup dGroup, GameWorld gameWorld) { super(dGroup); this.gameWorld = gameWorld; } diff --git a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 7728f68f..0fc1f541 100644 --- a/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -6,6 +6,7 @@ import io.github.dre2n.dungeonsxl.dungeon.DLootInventory; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameChest; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.file.DMessages; import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.global.DPortal; @@ -47,7 +48,7 @@ import org.bukkit.scheduler.BukkitRunnable; public class PlayerListener implements Listener { - DungeonsXL plugin = DungeonsXL.getPlugin(); + static DungeonsXL plugin = DungeonsXL.getPlugin(); DMessages dMessages = plugin.getDMessages(); @EventHandler(priority = EventPriority.HIGH) @@ -464,6 +465,16 @@ public class PlayerListener implements Listener { DGroup dGroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false); + DGroupCreateEvent createEvent = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.GROUP_SIGN); + + if (createEvent.isCancelled()) { + dGroup = null; + } + + if (dGroup == null) { + continue; + } + if (dGroup.getGameWorld() == null) { dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName())); dGroup.getGameWorld().setTutorial(true); diff --git a/src/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/io/github/dre2n/dungeonsxl/player/DGroup.java index 415803e6..479416e4 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -3,6 +3,7 @@ package io.github.dre2n.dungeonsxl.player; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupStartFloorEvent; import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.requirement.Requirement; @@ -239,6 +240,12 @@ public class DGroup { } public void startGame() { + DGroupStartFloorEvent event = new DGroupStartFloorEvent(this, gameWorld); + + if (event.isCancelled()) { + return; + } + playing = true; gameWorld.startGame(); floorCount++; diff --git a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java index 2936d5f3..28689ceb 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DPlayer.java +++ b/src/io/github/dre2n/dungeonsxl/player/DPlayer.java @@ -6,6 +6,8 @@ import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.DLootInventory; import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent; +import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent; import io.github.dre2n.dungeonsxl.file.DMessages; import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.reward.Reward; @@ -306,6 +308,13 @@ public class DPlayer { } else if (specifiedFloor != null) { newFloor = specifiedFloor; } + + DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor); + + if (event.isCancelled()) { + return; + } + dGroup.removeUnplayedFloor(dGroup.getMapName()); dGroup.setMapName(newFloor); GameWorld gameWorld = GameWorld.load(newFloor); @@ -342,6 +351,12 @@ public class DPlayer { } } + DGroupFinishDungeonEvent event = new DGroupFinishDungeonEvent(dGroup); + + if (event.isCancelled()) { + return; + } + for (Player player : dGroup.getPlayers()) { DPlayer dPlayer = getByPlayer(player); dPlayer.leave();