Implemented DGroup events

This commit is contained in:
Daniel Saukel 2016-01-12 22:39:52 +01:00
parent 418e2cb075
commit 6ec3808a25
7 changed files with 85 additions and 4 deletions

View File

@ -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()));
}

View File

@ -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()));
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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++;

View File

@ -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();