import java.util.*; public class Jail extends PluginListener { int DISTANCE = 100; private Set jailed = new HashSet(); public Jail() { } public boolean onTeleport(Player player, Location from, Location to) { if ( jailed.contains( player.getName()) ) { Warp jailWarp = etc.getDataSource().getWarp("jail"); if (jailWarp == null) //abort if jailwarp was not found return false; if (HoerupUtils.calcDistance(jailWarp.Location, to) > DISTANCE) { player.sendMessage("You have been jailed and can not teleport outside containment area"); return true; } } return false; } public void onPlayerMove(Player player, Location from, Location to) { if ( jailed.contains(player.getName()) ){ Warp jailWarp = etc.getDataSource().getWarp("jail"); if (jailWarp == null) //abort if jailwarp was not found return; Location jail = jailWarp.Location; if (HoerupUtils.calcDistance(jailWarp.Location, to) > DISTANCE) { player.sendMessage("You have been jailed and can not move outside containment area"); player.teleportTo(from); } } } public boolean onCommand(Player player, String[] split) { if (!player.isAdmin() ) return false; if (split[0].equals("/jaillist") ) { StringBuilder sb = new StringBuilder(); Iterator it = jailed.iterator(); while (it.hasNext() ) { String p = it.next(); if (sb.length() > 0) sb.append(" "); sb.append(p); } player.sendMessage("Currently jailed: " + sb.toString() ); return true; } if (split[0].equals("/jail") ) { if (split.length != 2) { player.sendMessage("Usage: /jail [player]"); return true; } Player inmate = etc.getServer().getPlayer(split[1]); if (inmate == null) { player.sendMessage("/jail, player not found: " + split[1] ); return true; } if (jailed.contains(inmate.getName() ) ) { player.sendMessage("/jail: " + inmate.getName() + " is already jailed"); return true; } Warp jail = etc.getDataSource().getWarp("jail"); if (jail == null) { player.sendMessage("/jail: jail warp point not set !"); return true; } jailed.add( inmate.getName() ); inmate.teleportTo(jail.Location); inmate.sendMessage(Colors.Red + "You have been jailed"); player.sendMessage(Colors.Red + "Player has been jailed"); return true; } if ( split[0].equals("/jailfree") ) { if (split.length != 2) { player.sendMessage("Usage: /jailfree [player]"); return true; } if (!jailed.contains(split[1]) ) { player.sendMessage("/jailfree: player is not jailed"); return true; } jailed.remove(split[1]); player.sendMessage(Colors.Red + "jail, " + split[1] + " has been released"); Player inmate = etc.getServer().getPlayer( split[1] ); if (inmate != null) { inmate.sendMessage(Colors.Red + "You have been released from jail"); } return true; } return false; } }