diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java index ac5218c4..f3cd41b7 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/global/LeaveSign.java @@ -44,14 +44,7 @@ public class LeaveSign extends GlobalProtection { setText(); } - public void setText() { - sign.setLine(0, ChatColor.BLUE + "############"); - sign.setLine(1, ChatColor.DARK_GREEN + "Leave"); - sign.setLine(2, ""); - sign.setLine(3, ChatColor.BLUE + "############"); - sign.update(); - } - + /* Getters and setters */ @Override public Set getBlocks() { if (blocks == null) { @@ -64,6 +57,34 @@ public class LeaveSign extends GlobalProtection { return blocks; } + /* Actions */ + public void setText() { + sign.setLine(0, ChatColor.BLUE + "############"); + sign.setLine(1, ChatColor.DARK_GREEN + "Leave"); + sign.setLine(2, ""); + sign.setLine(3, ChatColor.BLUE + "############"); + sign.update(); + } + + public void onPlayerInteract(Player player) { + DGamePlayer dplayer = DGamePlayer.getByPlayer(player); + + if (dplayer != null) { + dplayer.leave(); + return; + + } else { + DGroup group = DGroup.getByPlayer(player); + if (group != null) { + group.removePlayer(player); + MessageUtil.sendMessage(player, DMessages.PLAYER_LEAVE_GROUP.getMessage()); + return; + } + } + + return; + } + @Override public void save(FileConfiguration config) { String preString = "protections.leaveSigns." + sign.getWorld().getName() + "." + getId(); @@ -89,32 +110,4 @@ public class LeaveSign extends GlobalProtection { return null; } - /* SUBJECT TO CHANGE */ - @Deprecated - public static boolean playerInteract(Block block, Player player) { - - LeaveSign leaveSign = getByBlock(block); - - if (leaveSign == null) { - return false; - } - - DGamePlayer dplayer = DGamePlayer.getByPlayer(player); - - if (dplayer != null) { - dplayer.leave(); - return true; - - } else { - DGroup dgroup = DGroup.getByPlayer(player); - if (dgroup != null) { - dgroup.removePlayer(player); - MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.PLAYER_LEAVE_GROUP)); - return true; - } - } - - return false; - } - } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 73cdbbbe..3dfe7871 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -264,8 +264,9 @@ public class PlayerListener implements Listener { event.setCancelled(true); } - // Leave Sign - if (LeaveSign.playerInteract(event.getClickedBlock(), player)) { + LeaveSign leaveSign = LeaveSign.getByBlock(clickedBlock); + if (leaveSign != null) { + leaveSign.onPlayerInteract(player); event.setCancelled(true); }