/** * Performs transfer of specified JailPrisoner. If you just want to transfer someone, I recommend * using prisoner.transfer, because it supports offline transfer and it's easier to do. * * @param prisoner Prisoner that will be transfered * @param player Player that will be teleported */ public static void Transfer(JailPrisoner prisoner, Player player) { if (prisoner.getTransferDestination() == "find nearest") prisoner.setTransferDestination( JailZoneManager.findNearestJail(player.getLocation(), prisoner.getJail().getName()) .getName()); if (prisoner.getCell() != null) { Inventory inventory = player.getInventory(); JailCell cell = prisoner.getCell(); cell.setPlayerName(""); for (Sign sign : cell.getSigns()) { sign.setLine(0, ""); sign.setLine(1, ""); sign.setLine(2, ""); sign.setLine(3, ""); sign.update(); } if (cell.getChest() != null) { for (ItemStack i : cell.getChest().getInventory().getContents()) { if (i == null || i.getType() == Material.AIR) continue; inventory.addItem(i); } cell.getChest().getInventory().clear(); } if (cell.getSecondChest() != null) { for (ItemStack i : cell.getSecondChest().getInventory().getContents()) { if (i == null || i.getType() == Material.AIR) continue; inventory.addItem(i); } cell.getSecondChest().getInventory().clear(); } prisoner.setCell(null); } prisoner.SetBeingReleased(true); String targetJail = prisoner.getTransferDestination(); if (targetJail.contains(":")) { prisoner.setRequestedCell(targetJail.split(":")[1]); targetJail = targetJail.split(":")[0]; } JailZone jail = Jail.zones.get(targetJail); prisoner.setJail(jail); prisoner.setTransferDestination(""); prisoner.setOfflinePending(false); Util.Message(jail.getSettings().getString(Setting.MessageTransfer), player); Jail.prisoners.put(prisoner.getName(), prisoner); JailCell cell = jail.getRequestedCell(prisoner); if (cell == null || (cell.getPlayerName() != null && !cell.getPlayerName().equals("") && !cell.getPlayerName().equals(prisoner.getName()))) { cell = null; cell = jail.getEmptyCell(); } if (cell != null) { cell.setPlayerName(player.getName()); prisoner.setCell(cell); player.teleport(prisoner.getTeleportLocation()); prisoner.updateSign(); if (jail.getSettings().getBoolean(Setting.StoreInventory) && cell.getChest() != null) { Chest chest = cell.getChest(); chest.getInventory().clear(); for (int i = 0; i < 40; i++) { if (chest.getInventory().getSize() <= Util.getNumberOfOccupiedItemSlots(chest.getInventory().getContents())) break; if (player.getInventory().getItem(i) == null || player.getInventory().getItem(i).getType() == Material.AIR) continue; chest.getInventory().addItem(player.getInventory().getItem(i)); player.getInventory().clear(i); } if (cell.getSecondChest() != null) { chest = cell.getSecondChest(); chest.getInventory().clear(); for (int i = 0; i < 40; i++) { if (chest.getInventory().getSize() <= Util.getNumberOfOccupiedItemSlots(chest.getInventory().getContents())) break; if (player.getInventory().getItem(i) == null || player.getInventory().getItem(i).getType() == Material.AIR) continue; chest.getInventory().addItem(player.getInventory().getItem(i)); player.getInventory().clear(i); } } } cell.update(); } else { player.teleport(prisoner.getTeleportLocation()); } if (jail.getSettings().getBoolean(Setting.StoreInventory)) { prisoner.storeInventory(player.getInventory()); player.getInventory().clear(); } prisoner.SetBeingReleased(false); InputOutput.UpdatePrisoner(prisoner); }
/** * Performs jailing of specified JailPrisoner. If you just want to jail someone, I recommend using * JailAPI.jailPlayer, because it supports offline jail and it's easier to do. * * @param prisoner JailPrisoner class of the new prisoner. Must be already inserted into database * @param player Player that will be teleported */ public static void Jail(JailPrisoner prisoner, Player player) { if (!prisoner.getName().equals(player.getName().toLowerCase())) return; prisoner.SetBeingReleased(true); JailZone jail = prisoner.getJail(); if (jail == null) { Util.debug(prisoner, "searching for nearest jail"); jail = JailZoneManager.findNearestJail(player.getLocation()); prisoner.setJail(jail); } if (jail == null) { Util.Message("You are lucky! Server admin was too lazy to set up jail. Go now!", player); Jail.log.info( "[Jail] There is no jail to pick! Make sure, you have build at least one jail and at least one jail is set to automatic!"); return; } prisoner.setOfflinePending(false); if (prisoner.getReason().isEmpty()) Util.Message(jail.getSettings().getString(Setting.MessageJail), player); else Util.Message( jail.getSettings() .getString(Setting.MessageJailReason) .replace("<Reason>", prisoner.getReason()), player); if (jail.getSettings().getBoolean(Setting.DeleteInventoryOnJail)) player.getInventory().clear(); prisoner.setPreviousPosition(player.getLocation()); JailCell cell = jail.getRequestedCell(prisoner); if (cell == null || (cell.getPlayerName() != null && !cell.getPlayerName().equals("") && !cell.getPlayerName().equals(prisoner.getName()))) { Util.debug(prisoner, "No requested cell. searching for empty cell"); cell = null; cell = jail.getEmptyCell(); } if (cell != null) { Util.debug(prisoner, "Found cell!"); cell.setPlayerName(player.getName()); prisoner.setCell(cell); player.teleport(prisoner.getTeleportLocation()); prisoner.updateSign(); if (jail.getSettings().getBoolean(Setting.StoreInventory) && cell.getChest() != null) { Chest chest = cell.getChest(); chest.getInventory().clear(); for (int i = 0; i < 40; i++) { if (chest.getInventory().getSize() <= Util.getNumberOfOccupiedItemSlots(chest.getInventory().getContents())) break; if (player.getInventory().getItem(i) == null || player.getInventory().getItem(i).getType() == Material.AIR) continue; chest.getInventory().addItem(player.getInventory().getItem(i)); player.getInventory().clear(i); } if (cell.getSecondChest() != null) { chest = cell.getSecondChest(); chest.getInventory().clear(); for (int i = 0; i < 40; i++) { if (chest.getInventory().getSize() <= Util.getNumberOfOccupiedItemSlots(chest.getInventory().getContents())) break; if (player.getInventory().getItem(i) == null || player.getInventory().getItem(i).getType() == Material.AIR) continue; chest.getInventory().addItem(player.getInventory().getItem(i)); player.getInventory().clear(i); } } } cell.update(); } else { player.teleport(prisoner.getTeleportLocation()); } if (jail.getSettings().getBoolean(Setting.StoreInventory)) { prisoner.storeInventory(player.getInventory()); for (int i = 0; i < 40; i++) { player.getInventory().clear(i); } } if (jail.getSettings().getBoolean(Setting.SpoutChangeSkin)) Util.changeSkin(player, jail.getSettings().getString(Setting.SpoutSkinChangeURL)); if (jail.getSettings().getBoolean(Setting.EnableChangingPermissions)) { prisoner.setOldPermissions( Util.getPermissionsGroups( player.getName(), jail.getTeleportLocation().getWorld().getName())); Util.setPermissionsGroups( player.getName(), (ArrayList<String>) jail.getSettings().getList(Setting.PrisonersPermissionsGroups), jail.getTeleportLocation().getWorld().getName()); } if (prisoner.getJail().getSettings().getBoolean(Setting.IgnorePrisonersSleepingState)) player.setSleepingIgnored(true); if (Jail.prisoners.containsKey(prisoner.getName())) InputOutput.UpdatePrisoner(prisoner); else InputOutput.InsertPrisoner(prisoner); InputOutput.LogJail(prisoner, "jail"); Jail.prisoners.put(prisoner.getName(), prisoner); prisoner.SetBeingReleased(false); for (Object o : jail.getSettings().getList(Setting.ExecutedCommandsOnJail)) { String s = (String) o; CraftServer cs = (CraftServer) Jail.instance.getServer(); CommandSender coms = Jail.instance.getServer().getConsoleSender(); cs.dispatchCommand(coms, prisoner.parseTags(s)); } }