diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index afb264a8..0d9bf292 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -362,6 +362,14 @@ public class DGamePlayer extends DInstancePlayer { /* Actions */ @Override public void leave() { + leave(true); + } + + /** + * @param message + * if messages should be sent + */ + public void leave(boolean message) { GameRules rules = Game.getByWorld(getWorld()).getRules(); delete(); @@ -380,7 +388,7 @@ public class DGamePlayer extends DInstancePlayer { DGroup dGroup = DGroup.getByPlayer(getPlayer()); if (dGroup != null) { - dGroup.removePlayer(getPlayer()); + dGroup.removePlayer(getPlayer(), message); } GameWorld gameWorld = GameWorld.getByWorld(getWorld()); @@ -436,7 +444,9 @@ public class DGamePlayer extends DInstancePlayer { // Captain here! Player newCaptain = dGroup.getPlayers().get(0); dGroup.setCaptain(newCaptain); - MessageUtil.sendMessage(newCaptain, DMessages.PLAYER_NEW_CAPTAIN.getMessage()); + if (message) { + MessageUtil.sendMessage(newCaptain, DMessages.PLAYER_NEW_CAPTAIN.getMessage()); + } // ...*flies away* } } @@ -608,6 +618,12 @@ public class DGamePlayer extends DInstancePlayer { } } + /** + * The DGamePlayer finishs the current floor. + * + * @param specifiedFloor + * the name of the next floor + */ public void finishFloor(String specifiedFloor) { MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_FINISHED_DUNGEON.getMessage()); finished = true; @@ -679,10 +695,17 @@ public class DGamePlayer extends DInstancePlayer { dGroup.startGame(game); } + /** + * The DGamePlayer finishs the current game. + */ public void finish() { finish(true); } + /** + * @param message + * if messages should be sent + */ public void finish(boolean message) { if (message) { MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_FINISHED_DUNGEON.getMessage()); @@ -737,7 +760,7 @@ public class DGamePlayer extends DInstancePlayer { plugin.getServer().getPluginManager().callEvent(dGroupRewardEvent); for (Player player : dGroup.getPlayers()) { DGamePlayer dPlayer = getByPlayer(player); - dPlayer.leave(); + dPlayer.leave(false); if (!dGroupRewardEvent.isCancelled()) { for (Reward reward : dGroup.getRewards()) { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 4d11bbea..e7ef3f72 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -157,33 +157,59 @@ public class DGroup { } /** + * Sends messages by default. + * * @param player * the player to add */ public void addPlayer(Player player) { + addPlayer(player, true); + } + + /** + * @param player + * the player to add + * @param message + * if messages should be sent + */ + public void addPlayer(Player player, boolean message) { DPlayerJoinDGroupEvent event = new DPlayerJoinDGroupEvent(DGamePlayer.getByPlayer(player), false, this); plugin.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { - sendMessage(plugin.getMessageConfig().getMessage(DMessages.GROUP_PLAYER_JOINED, player.getName())); - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.PLAYER_JOIN_GROUP)); + if (message) { + sendMessage(DMessages.GROUP_PLAYER_JOINED.getMessage(player.getName())); + MessageUtil.sendMessage(player, DMessages.PLAYER_JOIN_GROUP.getMessage()); + } players.add(player); } } /** + * Sends messages by default. + * * @param player * the player to remove */ public void removePlayer(Player player) { + removePlayer(player, true); + } + + /** + * @param player + * the player to remove + * @param message + * if messages should be sent + */ + public void removePlayer(Player player, boolean message) { players.remove(player); GroupSign.updatePerGroup(this); - // Send message - sendMessage(plugin.getMessageConfig().getMessage(DMessages.PLAYER_LEFT_GROUP, player.getName())); + if (message) { + sendMessage(plugin.getMessageConfig().getMessage(DMessages.PLAYER_LEFT_GROUP, player.getName())); + } - // Check group if (isEmpty()) { DGroupDisbandEvent event = new DGroupDisbandEvent(this, player, DGroupDisbandEvent.Cause.GROUP_IS_EMPTY); plugin.getServer().getPluginManager().callEvent(event);