This commit is contained in:
Daniel Saukel 2016-07-28 17:28:11 +02:00
parent f1de40ef2f
commit 0da5d76742
2 changed files with 32 additions and 38 deletions

View File

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

View File

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