diff --git a/src/com/bekvon/bukkit/residence/Residence.java b/src/com/bekvon/bukkit/residence/Residence.java index 5209071..7f9c94c 100644 --- a/src/com/bekvon/bukkit/residence/Residence.java +++ b/src/com/bekvon/bukkit/residence/Residence.java @@ -85,6 +85,7 @@ public class Residence extends JavaPlugin { protected static Server server; protected static HelpEntry helppages; protected static Language language; + protected static Logger log; protected static EconomyInterface economy; public final static int saveVersion = 1; protected static File dataFolder; @@ -135,6 +136,10 @@ public class Residence extends JavaPlugin { return leasemanager; } + public static Logger getLog() { + return log; + } + public static PermissionManager getPermissionManager() { return gmanager; } @@ -333,8 +338,8 @@ public class Residence extends JavaPlugin { try { File worldFolder = new File(saveFolder, "Worlds"); if (!saveFolder.isDirectory()) { - this.getLogger().warning("保存目录不存在..."); - this.getLogger().warning("请重新启动服务器"); + this.getLogger().warning("领地数据保存目录不存在..."); + this.getLogger().warning("请重新启动服务器生成新的文件..."); return true; } YMLSaveHelper yml; @@ -409,6 +414,7 @@ public class Residence extends JavaPlugin { @Override public void onEnable() { try { + log = this.getLogger(); bukkitver = this.getServer().getBukkitVersion().substring(0, 5); initsuccess = false; deleteConfirm = new HashMap(); diff --git a/src/com/bekvon/bukkit/residence/protection/ClaimedResidence.java b/src/com/bekvon/bukkit/residence/protection/ClaimedResidence.java index 1df7f1c..fa50204 100644 --- a/src/com/bekvon/bukkit/residence/protection/ClaimedResidence.java +++ b/src/com/bekvon/bukkit/residence/protection/ClaimedResidence.java @@ -1,10 +1,20 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * To change this template, choose Tools | Templates and open the template in the editor. */ package com.bekvon.bukkit.residence.protection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; import com.bekvon.bukkit.residence.Residence; import com.bekvon.bukkit.residence.economy.ResidenceBank; @@ -15,952 +25,1010 @@ import com.bekvon.bukkit.residence.itemlist.ResidenceItemList; import com.bekvon.bukkit.residence.permissions.PermissionGroup; import com.bekvon.bukkit.residence.text.help.InformationPager; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; - /** - * + * * @author Administrator - * + * */ public class ClaimedResidence { - protected ClaimedResidence parent; - protected Map areas; - protected Map subzones; - protected ResidencePermissions perms; - protected ResidenceBank bank; - protected Location tpLoc; - protected String enterMessage; - protected String leaveMessage; - protected ResidenceItemList ignorelist; - protected ResidenceItemList blacklist; + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static ClaimedResidence load(Map root, ClaimedResidence parent) throws Exception { + ClaimedResidence res = new ClaimedResidence(); + if (root == null) + throw new Exception("Null residence!"); + res.enterMessage = (String) root.get("EnterMessage"); + res.leaveMessage = (String) root.get("LeaveMessage"); + if (root.containsKey("StoredMoney")) { + res.bank.setStoredMoney((Integer) root.get("StoredMoney")); + } + if (root.containsKey("BlackList")) { + res.blacklist = ResidenceItemList + .load(res, (Map) root.get("BlackList")); + } + if (root.containsKey("IgnoreList")) { + res.ignorelist = ResidenceItemList.load(res, + (Map) root.get("IgnoreList")); + } + Map areamap = (Map) root.get("Areas"); + res.perms = ResidencePermissions.load(res, (Map) root.get("Permissions")); + World world = Residence.getServ().getWorld(res.perms.getWorld()); + if (world == null) + throw new Exception("Cant Find World: " + res.perms.getWorld()); + for (Entry map : areamap.entrySet()) { + res.areas.put(map.getKey(), + CuboidArea.load((Map) map.getValue(), world)); + } + Map subzonemap = (Map) root.get("Subzones"); + for (Entry map : subzonemap.entrySet()) { + ClaimedResidence subres = ClaimedResidence.load((Map) map.getValue(), + res); + if (Residence.getConfigManager().flagsInherit()) { + subres.getPermissions().setParent(res.getPermissions()); + } + res.subzones.put(map.getKey(), subres); + } + res.parent = parent; + Map tploc = (Map) root.get("TPLoc"); + if (tploc != null) { + res.tpLoc = new Location(world, (Integer) tploc.get("X"), (Integer) tploc.get("Y"), + (Integer) tploc.get("Z")); + } + return res; + } - private ClaimedResidence() { - subzones = new HashMap(); - areas = new HashMap(); - bank = new ResidenceBank(this); - blacklist = new ResidenceItemList(this, ListType.BLACKLIST); - ignorelist = new ResidenceItemList(this, ListType.IGNORELIST); - } + protected ClaimedResidence parent; + protected Map areas; + protected Map subzones; + protected ResidencePermissions perms; + protected ResidenceBank bank; + protected Location tpLoc; + protected String enterMessage; + protected String leaveMessage; + protected ResidenceItemList ignorelist; - public ClaimedResidence(String creationWorld) { - this("Server Land", creationWorld); - } + protected ResidenceItemList blacklist; - public ClaimedResidence(String creator, String creationWorld) { - this(); - perms = new ResidencePermissions(this, creator, creationWorld); - } + private ClaimedResidence() { + subzones = new HashMap(); + areas = new HashMap(); + bank = new ResidenceBank(this); + blacklist = new ResidenceItemList(this, ListType.BLACKLIST); + ignorelist = new ResidenceItemList(this, ListType.IGNORELIST); + } - public ClaimedResidence(String creator, String creationWorld, ClaimedResidence parentResidence) { - this(creator, creationWorld); - parent = parentResidence; - } + public ClaimedResidence(String creationWorld) { + this("Server Land", creationWorld); + } - public boolean addArea(CuboidArea area, String name) { - return addArea(null, area, name, true); - } + public ClaimedResidence(String creator, String creationWorld) { + this(); + perms = new ResidencePermissions(this, creator, creationWorld); + } - public boolean addArea(Player player, CuboidArea area, String name, boolean resadmin) { - if (!Residence.validName(name)) { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidNameCharacters")); - } - return false; - } - if (areas.containsKey(name)) { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaExists")); - } - return false; - } - if (!resadmin && Residence.getConfigManager().getEnforceAreaInsideArea() && this.getParent() == null) { - boolean inside = false; - for (CuboidArea are: areas.values()) { - if (are.isAreaWithinArea(area)) { - inside = true; - } - } - if (!inside) { - return false; - } - } - if (!area.getWorld().getName().equalsIgnoreCase(perms.getWorld())) { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaDiffWorld")); - } - return false; - } - if (parent == null) { - String collideResidence = Residence.getResidenceManager().checkAreaCollision(area, this); - if (collideResidence != null) { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaCollision", ChatColor.YELLOW + collideResidence)); - } - return false; - } - } else { - String[] szs = parent.listSubzones(); - for (String sz : szs) { - ClaimedResidence res = parent.getSubzone(sz); - if (res != null && res != this) { - if (res.checkCollision(area)) { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaSubzoneCollision", ChatColor.YELLOW + sz)); - } - return false; - } - } - } - } - if (!resadmin && player != null) { - if (!this.perms.hasResidencePermission(player, true)) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return false; - } - if (parent != null) { - if (!parent.containsLoc(area.getHighLoc()) || !parent.containsLoc(area.getLowLoc())) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaNotWithinParent")); - return false; - } - if (!parent.getPermissions().hasResidencePermission(player, true) && !parent.getPermissions().playerHas(player.getName(), "subzone", true)) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ParentNoPermission")); - return false; - } - } - PermissionGroup group = Residence.getPermissionManager().getGroup(player); - if (!group.canCreateResidences() && !player.hasPermission("residence.create")) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return false; - } - if (areas.size() >= group.getMaxPhysicalPerResidence()) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaMaxPhysical")); - return false; - } - if (!group.inLimits(area)) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaSizeLimit")); - return false; - } - if (group.getMinHeight() > area.getLowLoc().getBlockY()) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaLowLimit", ChatColor.YELLOW + String.format("%d", group.getMinHeight()))); - return false; - } - if (group.getMaxHeight() < area.getHighLoc().getBlockY()) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaHighLimit", ChatColor.YELLOW + String.format("%d", group.getMaxHeight()))); - return false; - } - if (parent == null && Residence.getConfigManager().enableEconomy()) { - int chargeamount = (int) Math.ceil((double) area.getSize() * group.getCostPerBlock()); - if (!TransactionManager.chargeEconomyMoney(player, chargeamount)) { - return false; - } - } - } - Residence.getResidenceManager().removeChunkList(getName()); - areas.put(name, area); - Residence.getResidenceManager().calculateChunks(getName()); - if (player != null) { - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("AreaCreate", ChatColor.YELLOW + name)); - } - return true; - } + public ClaimedResidence(String creator, String creationWorld, ClaimedResidence parentResidence) { + this(creator, creationWorld); + parent = parentResidence; + } - public boolean replaceArea(CuboidArea neware, String name) { - return this.replaceArea(null, neware, name, true); - } + public boolean addArea(CuboidArea area, String name) { + return addArea(null, area, name, true); + } - public boolean replaceArea(Player player, CuboidArea newarea, String name, boolean resadmin) { - if (!areas.containsKey(name)) { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaNonExist")); - return false; - } - CuboidArea oldarea = areas.get(name); - if (!newarea.getWorld().getName().equalsIgnoreCase(perms.getWorld())) { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaDiffWorld")); - return false; - } - if (parent == null) { - String collideResidence = Residence.getResidenceManager().checkAreaCollision(newarea, this); - if (collideResidence != null) { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaCollision", ChatColor.YELLOW + collideResidence)); - return false; - } - } else { - String[] szs = parent.listSubzones(); - for (String sz : szs) { - ClaimedResidence res = parent.getSubzone(sz); - if (res != null && res != this) { - if (res.checkCollision(newarea)) { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaSubzoneCollision", ChatColor.YELLOW + sz)); - return false; - } - } - } - } - //Remove subzones that are not in the area anymore - String[] szs = listSubzones(); - for (String sz : szs) { - ClaimedResidence res = getSubzone(sz); - if (res != null && res != this) { - String[] areas = res.getAreaList(); - for (String area: areas) { - if (!newarea.isAreaWithinArea(res.getArea(area))) { - boolean good = false; - for (CuboidArea arae: getAreaArray()) { - if (arae != oldarea && arae.isAreaWithinArea(res.getArea(area))) { - good = true; - } - } - if (!good) { - res.removeArea(area); - } - } - } - if (res.getAreaArray().length == 0) { - removeSubzone(sz); - } - } - } - if (!resadmin && player != null) { - if (!this.perms.hasResidencePermission(player, true)) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return false; - } - if (parent != null) { - if (!parent.containsLoc(newarea.getHighLoc()) || !parent.containsLoc(newarea.getLowLoc())) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaNotWithinParent")); - return false; - } - if (!parent.getPermissions().hasResidencePermission(player, true) && !parent.getPermissions().playerHas(player.getName(), "subzone", true)) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ParentNoPermission")); - return false; - } - } - PermissionGroup group = Residence.getPermissionManager().getGroup(player); - if (!group.canCreateResidences() && !player.hasPermission("residence.create")) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return false; - } - if (!group.inLimits(newarea)) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaSizeLimit")); - return false; - } - if (group.getMinHeight() > newarea.getLowLoc().getBlockY()) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaLowLimit", ChatColor.YELLOW + String.format("%d", group.getMinHeight()))); - return false; - } - if (group.getMaxHeight() < newarea.getHighLoc().getBlockY()) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaHighLimit", ChatColor.YELLOW + String.format("%d", group.getMaxHeight()))); - return false; - } - if (parent == null && Residence.getConfigManager().enableEconomy()) { - int chargeamount = (int) Math.ceil((double) (newarea.getSize() - oldarea.getSize()) * group.getCostPerBlock()); - if (chargeamount > 0) { - if (!TransactionManager.chargeEconomyMoney(player, chargeamount)) { - return false; - } - } - } + public boolean addArea(Player player, CuboidArea area, String name, boolean resadmin) { + if (!Residence.validName(name)) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidNameCharacters")); + } + return false; + } + if (areas.containsKey(name)) { + if (player != null) { + player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaExists")); + } + return false; + } + if (!resadmin && Residence.getConfigManager().getEnforceAreaInsideArea() + && this.getParent() == null) { + boolean inside = false; + for (CuboidArea are : areas.values()) { + if (are.isAreaWithinArea(area)) { + inside = true; + } + } + if (!inside) + return false; + } + if (!area.getWorld().getName().equalsIgnoreCase(perms.getWorld())) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaDiffWorld")); + } + return false; + } + if (parent == null) { + String collideResidence = Residence.getResidenceManager() + .checkAreaCollision(area, this); + if (collideResidence != null) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaCollision", + ChatColor.YELLOW + collideResidence)); + } + return false; + } + } else { + String[] szs = parent.listSubzones(); + for (String sz : szs) { + ClaimedResidence res = parent.getSubzone(sz); + if (res != null && res != this) { + if (res.checkCollision(area)) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaSubzoneCollision", + ChatColor.YELLOW + sz)); + } + return false; + } + } + } + } + if (!resadmin && player != null) { + if (!this.perms.hasResidencePermission(player, true)) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); + return false; + } + if (parent != null) { + if (!parent.containsLoc(area.getHighLoc()) || !parent.containsLoc(area.getLowLoc())) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaNotWithinParent")); + return false; + } + if (!parent.getPermissions().hasResidencePermission(player, true) + && !parent.getPermissions().playerHas(player.getName(), "subzone", true)) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("ParentNoPermission")); + return false; + } + } + PermissionGroup group = Residence.getPermissionManager().getGroup(player); + if (!group.canCreateResidences() && !player.hasPermission("residence.create")) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); + return false; + } + if (areas.size() >= group.getMaxPhysicalPerResidence()) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaMaxPhysical")); + return false; + } + if (!group.inLimits(area)) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaSizeLimit")); + return false; + } + if (group.getMinHeight() > area.getLowLoc().getBlockY()) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaLowLimit", + ChatColor.YELLOW + String.format("%d", group.getMinHeight()))); + return false; + } + if (group.getMaxHeight() < area.getHighLoc().getBlockY()) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaHighLimit", + ChatColor.YELLOW + String.format("%d", group.getMaxHeight()))); + return false; + } + if (parent == null && Residence.getConfigManager().enableEconomy()) { + int chargeamount = (int) Math.ceil(area.getSize() * group.getCostPerBlock()); + if (!TransactionManager.chargeEconomyMoney(player, chargeamount)) + return false; + } + } + Residence.getResidenceManager().removeChunkList(getName()); + areas.put(name, area); + Residence.getResidenceManager().calculateChunks(getName()); + if (player != null) { + player.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase("AreaCreate", ChatColor.YELLOW + name)); + } + return true; + } - } - Residence.getResidenceManager().removeChunkList(getName()); - areas.remove(name); - areas.put(name, newarea); - Residence.getResidenceManager().calculateChunks(getName()); - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("AreaUpdate")); - return true; - } + public boolean addSubzone(Player player, Location loc1, Location loc2, String name, + boolean resadmin) { + if (player == null) + return this.addSubzone(null, "Server Land", loc1, loc2, name, resadmin); + else + return this.addSubzone(player, player.getName(), loc1, loc2, name, resadmin); + } - public boolean addSubzone(String name, Location loc1, Location loc2) { - return this.addSubzone(null, loc1, loc2, name, true); - } + public boolean addSubzone(Player player, String owner, Location loc1, Location loc2, + String name, boolean resadmin) { + if (!Residence.validName(name)) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidNameCharacters")); + } + return false; + } + if (!(this.containsLoc(loc1) && this.containsLoc(loc2))) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("SubzoneSelectInside")); + } + return false; + } + if (subzones.containsKey(name)) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("SubzoneExists", + ChatColor.YELLOW + name)); + } + return false; + } + if (!resadmin && player != null) { + if (!this.perms.hasResidencePermission(player, true)) { + if (!this.perms.playerHas(player.getName(), "subzone", + this.perms.playerHas(player.getName(), "admin", false))) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); + return false; + } + } + PermissionGroup group = Residence.getPermissionManager().getGroup(player); + if (this.getZoneDepth() >= group.getMaxSubzoneDepth()) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("SubzoneMaxDepth")); + return false; + } + } + CuboidArea newArea = new CuboidArea(loc1, loc2); + Set> set = subzones.entrySet(); + for (Entry resEntry : set) { + ClaimedResidence res = resEntry.getValue(); + if (res.checkCollision(newArea)) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("SubzoneCollide", + ChatColor.YELLOW + resEntry.getKey())); + } + return false; + } + } + ClaimedResidence newres; + if (player != null) { + newres = new ClaimedResidence(owner, perms.getWorld(), this); + newres.addArea(player, newArea, name, resadmin); + } else { + newres = new ClaimedResidence(owner, perms.getWorld(), this); + newres.addArea(newArea, name); + } + if (newres.getAreaCount() != 0) { + newres.getPermissions().applyDefaultFlags(); + if (player != null) { + PermissionGroup group = Residence.getPermissionManager().getGroup(player); + newres.setEnterMessage(group.getDefaultEnterMessage()); + newres.setLeaveMessage(group.getDefaultLeaveMessage()); + } + if (Residence.getConfigManager().flagsInherit()) { + newres.getPermissions().setParent(perms); + } + subzones.put(name, newres); + if (player != null) { + player.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase("SubzoneCreate", + ChatColor.YELLOW + name)); + } + return true; + } else { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("SubzoneCreateFail", + ChatColor.YELLOW + name)); + } + return false; + } + } - public boolean addSubzone(Player player, Location loc1, Location loc2, String name, boolean resadmin) { - if (player == null) { - return this.addSubzone(null, "Server Land", loc1, loc2, name, resadmin); - } else { - return this.addSubzone(player, player.getName(), loc1, loc2, name, resadmin); - } - } + public boolean addSubzone(String name, Location loc1, Location loc2) { + return this.addSubzone(null, loc1, loc2, name, true); + } - public boolean addSubzone(Player player, String owner, Location loc1, Location loc2, String name, boolean resadmin) { - if (!Residence.validName(name)) { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidNameCharacters")); - } - return false; - } - if (!(this.containsLoc(loc1) && this.containsLoc(loc2))) { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("SubzoneSelectInside")); - } - return false; - } - if (subzones.containsKey(name)) { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("SubzoneExists", ChatColor.YELLOW + name)); - } - return false; - } - if (!resadmin && player != null) { - if (!this.perms.hasResidencePermission(player, true)) { - if (!this.perms.playerHas(player.getName(), "subzone", this.perms.playerHas(player.getName(), "admin", false))) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return false; - } - } - PermissionGroup group = Residence.getPermissionManager().getGroup(player); - if (this.getZoneDepth() >= group.getMaxSubzoneDepth()) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("SubzoneMaxDepth")); - return false; - } - } - CuboidArea newArea = new CuboidArea(loc1, loc2); - Set> set = subzones.entrySet(); - for (Entry resEntry : set) { - ClaimedResidence res = resEntry.getValue(); - if (res.checkCollision(newArea)) { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("SubzoneCollide", ChatColor.YELLOW + resEntry.getKey())); - } - return false; - } - } - ClaimedResidence newres; - if (player != null) { - newres = new ClaimedResidence(owner, perms.getWorld(), this); - newres.addArea(player, newArea, name, resadmin); - } else { - newres = new ClaimedResidence(owner, perms.getWorld(), this); - newres.addArea(newArea, name); - } - if (newres.getAreaCount() != 0) { - newres.getPermissions().applyDefaultFlags(); - if (player != null) { - PermissionGroup group = Residence.getPermissionManager().getGroup(player); - newres.setEnterMessage(group.getDefaultEnterMessage()); - newres.setLeaveMessage(group.getDefaultLeaveMessage()); - } - if (Residence.getConfigManager().flagsInherit()) { - newres.getPermissions().setParent(perms); - } - subzones.put(name, newres); - if (player != null) - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("SubzoneCreate", ChatColor.YELLOW + name)); - return true; - } else { - if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("SubzoneCreateFail", ChatColor.YELLOW + name)); - } - return false; - } - } + public boolean checkCollision(CuboidArea area) { + Set set = areas.keySet(); + for (String key : set) { + CuboidArea checkarea = areas.get(key); + if (checkarea != null) { + if (checkarea.checkCollision(area)) + return true; + } + } + return false; + } - public String getSubzoneNameByLoc(Location loc) { - Set> set = subzones.entrySet(); - ClaimedResidence res = null; - String key = null; - for (Entry entry : set) { - res = entry.getValue(); - if (res.containsLoc(loc)) { - key = entry.getKey(); - break; - } - } - if (key == null) { - return null; - } - String subname = res.getSubzoneNameByLoc(loc); - if (subname != null) { - return key + "." + subname; - } - return key; - } + public boolean containsLoc(Location loc) { + Collection keys = areas.values(); + for (CuboidArea key : keys) { + if (key.containsLoc(loc)) { + if (parent != null) + return parent.containsLoc(loc); + return true; + } + } + return false; + } - public ClaimedResidence getSubzoneByLoc(Location loc) { - Set> set = subzones.entrySet(); - boolean found = false; - ClaimedResidence res = null; - for (Entry entry : set) { - res = entry.getValue(); - if (res.containsLoc(loc)) { - found = true; - break; - } - } - if (!found) { - return null; - } - ClaimedResidence subrez = res.getSubzoneByLoc(loc); - if (subrez == null) { - return res; - } - return subrez; - } + public CuboidArea getArea(String name) { + return areas.get(name); + } - public ClaimedResidence getSubzone(String subzonename) { - if (!subzonename.contains(".")) { - return subzones.get(subzonename); - } - String split[] = subzonename.split("\\."); - ClaimedResidence get = subzones.get(split[0]); - for (int i = 1; i < split.length; i++) { - if (get == null) { - return null; - } - get = get.getSubzone(split[i]); - } - return get; - } + public CuboidArea[] getAreaArray() { + CuboidArea[] temp = new CuboidArea[areas.size()]; + int i = 0; + for (CuboidArea area : areas.values()) { + temp[i] = area; + i++; + } + return temp; + } - public String getSubzoneNameByRes(ClaimedResidence res) { - Set> set = subzones.entrySet(); - for (Entry entry : set) { - if (entry.getValue() == res) { - return entry.getKey(); - } - String n = entry.getValue().getSubzoneNameByRes(res); - if (n != null) { - return entry.getKey() + "." + n; - } - } - return null; - } + protected CuboidArea getAreaByLoc(Location loc) { + for (CuboidArea thisarea : areas.values()) { + if (thisarea.containsLoc(loc)) + return thisarea; + } + return null; + } - public String[] getSubzoneList() { - ArrayList zones = new ArrayList(); - Set set = subzones.keySet(); - for (String key : set) { - if (key != null) { - zones.add(key); - } - } - return zones.toArray(new String[zones.size()]); - } + public int getAreaCount() { + return areas.size(); + } - public boolean checkCollision(CuboidArea area) { - Set set = areas.keySet(); - for (String key : set) { - CuboidArea checkarea = areas.get(key); - if (checkarea != null) { - if (checkarea.checkCollision(area)) { - return true; - } - } - } - return false; - } + public String getAreaIDbyLoc(Location loc) { + for (Entry area : areas.entrySet()) { + if (area.getValue().containsLoc(loc)) + return area.getKey(); + } + return null; + } - public boolean containsLoc(Location loc) { - Collection keys = areas.values(); - for (CuboidArea key : keys) { - if (key.containsLoc(loc)) { - if (parent != null) - return parent.containsLoc(loc); - return true; - } - } - return false; - } + public String[] getAreaList() { + String arealist[] = new String[areas.size()]; + int i = 0; + for (Entry entry : areas.entrySet()) { + arealist[i] = entry.getKey(); + i++; + } + return arealist; + } - public ClaimedResidence getParent() { - return parent; - } + public ResidenceBank getBank() { + return bank; + } - public ClaimedResidence getTopParent() { - if (parent == null) - return this; - return parent.getTopParent(); - } + public String getEnterMessage() { + return enterMessage; + } - public boolean removeSubzone(String name) { - return this.removeSubzone(null, name, true); - } + public ResidenceItemList getItemBlacklist() { + return blacklist; + } - public boolean removeSubzone(Player player, String name, boolean resadmin) { - ClaimedResidence res = subzones.get(name); - if (player != null && !res.perms.hasResidencePermission(player, true) && !resadmin) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return false; - } - subzones.remove(name); - if (player != null) { - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("SubzoneRemove", ChatColor.YELLOW + name + ChatColor.GREEN)); - } - return true; - } + public ResidenceItemList getItemIgnoreList() { + return ignorelist; + } - public long getTotalSize() { - Collection set = areas.values(); - long size = 0; - for (CuboidArea entry : set) { - size = size + entry.getSize(); - } - return size; - } + public String getLeaveMessage() { + return leaveMessage; + } - public CuboidArea[] getAreaArray() { - CuboidArea[] temp = new CuboidArea[areas.size()]; - int i = 0; - for (CuboidArea area : areas.values()) { - temp[i] = area; - i++; - } - return temp; - } + public String getName() { + return Residence.getResidenceManager().getNameByRes(this); + } - public ResidencePermissions getPermissions() { - return perms; - } - - public String getEnterMessage() { - return enterMessage; - } - - public String getLeaveMessage() { - return leaveMessage; - } - - public void setEnterMessage(String message) { - enterMessage = message; - } - - public void setLeaveMessage(String message) { - leaveMessage = message; - } - - public void setEnterLeaveMessage(Player player, String message, boolean enter, boolean resadmin) { - // if(message!=null && - // Residence.getConfigManager().getResidenceNameRegex() != null) { - // Removed pending further action - // player.sendMessage(ChatColor.RED+Residence.getLanguage().getPhrase("InvalidCharacters")); - // return; - // } - if (message != null) { - if (message.equals("")) { - message = null; - } - } - PermissionGroup group = Residence.getPermissionManager().getGroup(perms.getOwner(), perms.getWorld()); - if (!group.canSetEnterLeaveMessages() && !resadmin) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("OwnerNoPermission")); - return; - } - if (!perms.hasResidencePermission(player, false) && !resadmin) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return; - } - if (enter) { - this.setEnterMessage(message); - } else { - this.setLeaveMessage(message); - } - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("MessageChange")); - } - - @SuppressWarnings("deprecation") + @SuppressWarnings("deprecation") public Location getOutsideFreeLoc(Location insideLoc) { - int maxIt = 100; - CuboidArea area = this.getAreaByLoc(insideLoc); - if (area == null) { - return insideLoc; - } - Location highLoc = area.getHighLoc(); - Location newLoc = new Location(highLoc.getWorld(), highLoc.getBlockX(), highLoc.getBlockY(), highLoc.getBlockZ()); - boolean found = false; - int it = 0; - while (!found && it < maxIt) { - it++; - Location lowLoc; - newLoc.setX(newLoc.getBlockX() + 1); - newLoc.setZ(newLoc.getBlockZ() + 1); - lowLoc = new Location(newLoc.getWorld(), newLoc.getBlockX(), 254, newLoc.getBlockZ()); - newLoc.setY(255); - while ((newLoc.getBlock().getTypeId() != 0 || lowLoc.getBlock().getTypeId() == 0) && lowLoc.getBlockY() > -126) { - newLoc.setY(newLoc.getY() - 1); - lowLoc.setY(lowLoc.getY() - 1); - } - if (newLoc.getBlock().getTypeId() == 0 - && lowLoc.getBlock().getTypeId() != 0) { - found = true; - } - } - if (found) { - return newLoc; - } else { - World world = Residence.getServ().getWorld(perms.getWorld()); - if (world != null) { - return world.getSpawnLocation(); - } - return insideLoc; - } - } + int maxIt = 100; + CuboidArea area = this.getAreaByLoc(insideLoc); + if (area == null) + return insideLoc; + Location highLoc = area.getHighLoc(); + Location newLoc = new Location(highLoc.getWorld(), highLoc.getBlockX(), + highLoc.getBlockY(), highLoc.getBlockZ()); + boolean found = false; + int it = 0; + while (!found && it < maxIt) { + it++; + Location lowLoc; + newLoc.setX(newLoc.getBlockX() + 1); + newLoc.setZ(newLoc.getBlockZ() + 1); + lowLoc = new Location(newLoc.getWorld(), newLoc.getBlockX(), 254, newLoc.getBlockZ()); + newLoc.setY(255); + while ((newLoc.getBlock().getTypeId() != 0 || lowLoc.getBlock().getTypeId() == 0) + && lowLoc.getBlockY() > -126) { + newLoc.setY(newLoc.getY() - 1); + lowLoc.setY(lowLoc.getY() - 1); + } + if (newLoc.getBlock().getTypeId() == 0 && lowLoc.getBlock().getTypeId() != 0) { + found = true; + } + } + if (found) + return newLoc; + else { + World world = Residence.getServ().getWorld(perms.getWorld()); + if (world != null) + return world.getSpawnLocation(); + return insideLoc; + } + } - protected CuboidArea getAreaByLoc(Location loc) { - for (CuboidArea thisarea : areas.values()) { - if (thisarea.containsLoc(loc)) { - return thisarea; - } - } - return null; - } + public String getOwner() { + return perms.getOwner(); + } - public String[] listSubzones() { - String list[] = new String[subzones.size()]; - int i = 0; - for (String res : subzones.keySet()) { - list[i] = res; - i++; - } - return list; - } + public ClaimedResidence getParent() { + return parent; + } - public void printSubzoneList(Player player, int page) { - ArrayList temp = new ArrayList(); - for (Entry sz : subzones.entrySet()) { - temp.add(ChatColor.GREEN + sz.getKey() + ChatColor.YELLOW + " - " + Residence.getLanguage().getPhrase("Owner") + ": " + sz.getValue().getOwner()); - } - InformationPager.printInfo(player, Residence.getLanguage().getPhrase("Subzones"), temp, page); - } + public ResidencePermissions getPermissions() { + return perms; + } - public void printAreaList(Player player, int page) { - ArrayList temp = new ArrayList(); - for (String area : areas.keySet()) { - temp.add(area); - } - InformationPager.printInfo(player, Residence.getLanguage().getPhrase("PhysicalAreas"), temp, page); - } + public ArrayList getPlayersInResidence() { + ArrayList within = new ArrayList(); + for (Player player : Bukkit.getServer().getOnlinePlayers()) { + if (this.containsLoc(player.getLocation())) { + within.add(player); + } + } + return within; + } - public void printAdvancedAreaList(Player player, int page) { - ArrayList temp = new ArrayList(); - for (Entry entry : areas.entrySet()) { - CuboidArea a = entry.getValue(); - Location h = a.getHighLoc(); - Location l = a.getLowLoc(); - temp.add(ChatColor.GREEN + "{" + ChatColor.YELLOW + "ID:" + ChatColor.RED + entry.getKey() + " " + ChatColor.YELLOW + "P1:" + ChatColor.RED + "(" + h.getBlockX() + "," + h.getBlockY() + "," + h.getBlockZ() + ") " + ChatColor.YELLOW + "P2:" + ChatColor.RED + "(" + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ() + ") " + ChatColor.YELLOW + "(Size:" + ChatColor.RED + a.getSize() + ChatColor.YELLOW + ")" + ChatColor.GREEN + "} "); - } - InformationPager.printInfo(player, Residence.getLanguage().getPhrase("PhysicalAreas"), temp, page); - } + public ClaimedResidence getSubzone(String subzonename) { + if (!subzonename.contains(".")) + return subzones.get(subzonename); + String split[] = subzonename.split("\\."); + ClaimedResidence get = subzones.get(split[0]); + for (int i = 1; i < split.length; i++) { + if (get == null) + return null; + get = get.getSubzone(split[i]); + } + return get; + } - public String[] getAreaList() { - String arealist[] = new String[areas.size()]; - int i = 0; - for (Entry entry : areas.entrySet()) { - arealist[i] = entry.getKey(); - i++; - } - return arealist; - } + public ClaimedResidence getSubzoneByLoc(Location loc) { + Set> set = subzones.entrySet(); + boolean found = false; + ClaimedResidence res = null; + for (Entry entry : set) { + res = entry.getValue(); + if (res.containsLoc(loc)) { + found = true; + break; + } + } + if (!found) + return null; + ClaimedResidence subrez = res.getSubzoneByLoc(loc); + if (subrez == null) + return res; + return subrez; + } - public int getZoneDepth() { - int count = 0; - ClaimedResidence res = parent; - while (res != null) { - count++; - res = res.getParent(); - } - return count; - } + public String[] getSubzoneList() { + ArrayList zones = new ArrayList(); + Set set = subzones.keySet(); + for (String key : set) { + if (key != null) { + zones.add(key); + } + } + return zones.toArray(new String[zones.size()]); + } - public void setTpLoc(Player player, boolean resadmin) { - if (!this.perms.hasResidencePermission(player, false) && !resadmin) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return; - } - if (!this.containsLoc(player.getLocation())) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NotInResidence")); - return; - } - tpLoc = player.getLocation(); - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("SetTeleportLocation")); - } + public String getSubzoneNameByLoc(Location loc) { + Set> set = subzones.entrySet(); + ClaimedResidence res = null; + String key = null; + for (Entry entry : set) { + res = entry.getValue(); + if (res.containsLoc(loc)) { + key = entry.getKey(); + break; + } + } + if (key == null) + return null; + String subname = res.getSubzoneNameByLoc(loc); + if (subname != null) + return key + "." + subname; + return key; + } - public void tpToResidence(Player reqPlayer, Player targetPlayer, boolean resadmin) { - if (!resadmin) { - PermissionGroup group = Residence.getPermissionManager().getGroup(reqPlayer); - if (!group.hasTpAccess()) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("TeleportDeny")); - return; - } - if (!reqPlayer.equals(targetPlayer)) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return; - } - if (!this.perms.playerHas(reqPlayer.getName(), "tp", true)) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("TeleportNoFlag")); - return; - } - } - if (tpLoc != null) { - ResidenceTPEvent tpevent = new ResidenceTPEvent(this, tpLoc, targetPlayer, reqPlayer); - Residence.getServ().getPluginManager().callEvent(tpevent); - if (!tpevent.isCancelled()) { - targetPlayer.teleport(tpLoc); - targetPlayer.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("TeleportSuccess")); - } - } else { - CuboidArea area = areas.values().iterator().next(); - if (area == null) { - reqPlayer.sendMessage(ChatColor.RED + "Could not find area to teleport to..."); - return; - } - Location targloc = this.getOutsideFreeLoc(area.getHighLoc()); - ResidenceTPEvent tpevent = new ResidenceTPEvent(this, targloc, targetPlayer, reqPlayer); - Residence.getServ().getPluginManager().callEvent(tpevent); - if (!tpevent.isCancelled()) { - targetPlayer.teleport(targloc); - targetPlayer.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("TeleportNear")); - } - } - } + public String getSubzoneNameByRes(ClaimedResidence res) { + Set> set = subzones.entrySet(); + for (Entry entry : set) { + if (entry.getValue() == res) + return entry.getKey(); + String n = entry.getValue().getSubzoneNameByRes(res); + if (n != null) + return entry.getKey() + "." + n; + } + return null; + } - public String getAreaIDbyLoc(Location loc) { - for (Entry area : areas.entrySet()) { - if (area.getValue().containsLoc(loc)) - return area.getKey(); - } - return null; - } + public ClaimedResidence getTopParent() { + if (parent == null) + return this; + return parent.getTopParent(); + } - public void removeArea(String id) { - Residence.getResidenceManager().removeChunkList(getName()); - areas.remove(id); - Residence.getResidenceManager().calculateChunks(getName()); - } + public long getTotalSize() { + Collection set = areas.values(); + long size = 0; + for (CuboidArea entry : set) { + size = size + entry.getSize(); + } + return size; + } - public void removeArea(Player player, String id, boolean resadmin) { + public String getWorld() { + return perms.getWorld(); + } - if (this.getPermissions().hasResidencePermission(player, true) || resadmin) { - if (!areas.containsKey(id)) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaNonExist")); - return; - } - if (areas.size() == 1 && !Residence.getConfigManager().allowEmptyResidences()) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaRemoveLast")); - return; - } - removeArea(id); - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("AreaRemove")); - } else { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - } - } + public int getZoneDepth() { + int count = 0; + ClaimedResidence res = parent; + while (res != null) { + count++; + res = res.getParent(); + } + return count; + } - public Map save() { - Map root = new HashMap(); - Map areamap = new HashMap(); - root.put("EnterMessage", enterMessage); - root.put("LeaveMessage", leaveMessage); - root.put("StoredMoney", bank.getStoredMoney()); - root.put("BlackList", blacklist.save()); - root.put("IgnoreList", ignorelist.save()); - for (Entry entry : areas.entrySet()) - { - areamap.put(entry.getKey(), entry.getValue().save()); - } - root.put("Areas", areamap); - Map subzonemap = new HashMap(); - for (Entry sz : subzones.entrySet()) - { - subzonemap.put(sz.getKey(), sz.getValue().save()); - } - root.put("Subzones", subzonemap); - root.put("Permissions", perms.save()); - if (tpLoc != null) - { - Map tpmap = new HashMap(); - tpmap.put("X", tpLoc.getBlockX()); - tpmap.put("Y", tpLoc.getBlockY()); - tpmap.put("Z", tpLoc.getBlockZ()); - root.put("TPLoc", tpmap); - } - return root; - } + public String[] listSubzones() { + String list[] = new String[subzones.size()]; + int i = 0; + for (String res : subzones.keySet()) { + list[i] = res; + i++; + } + return list; + } - @SuppressWarnings("unchecked") - public static ClaimedResidence load(Map root, ClaimedResidence parent) throws Exception { - ClaimedResidence res = new ClaimedResidence(); - if (root == null) - throw new Exception("Null residence!"); - res.enterMessage = (String) root.get("EnterMessage"); - res.leaveMessage = (String) root.get("LeaveMessage"); - if (root.containsKey("StoredMoney")) - res.bank.setStoredMoney((Integer) root.get("StoredMoney")); - if (root.containsKey("BlackList")) - res.blacklist = ResidenceItemList.load(res, (Map) root.get("BlackList")); - if (root.containsKey("IgnoreList")) - res.ignorelist = ResidenceItemList.load(res, (Map) root.get("IgnoreList")); - Map areamap = (Map) root.get("Areas"); - res.perms = ResidencePermissions.load(res, - (Map) root.get("Permissions")); - World world = Residence.getServ().getWorld(res.perms.getWorld()); - if (world == null) - throw new Exception("Cant Find World: " + res.perms.getWorld()); - for (Entry map : areamap.entrySet()) { - res.areas.put(map.getKey(), CuboidArea.load((Map) map.getValue(), world)); - } - Map subzonemap = (Map) root.get("Subzones"); - for (Entry map : subzonemap.entrySet()) { - ClaimedResidence subres = ClaimedResidence.load((Map) map.getValue(), res); - if (Residence.getConfigManager().flagsInherit()) - subres.getPermissions().setParent(res.getPermissions()); - res.subzones.put(map.getKey(), subres); - } - res.parent = parent; - Map tploc = (Map) root.get("TPLoc"); - if (tploc != null) { - res.tpLoc = new Location(world, (Integer) tploc.get("X"), (Integer) tploc.get("Y"), (Integer) tploc.get("Z")); - } - return res; - } + public void printAdvancedAreaList(Player player, int page) { + ArrayList temp = new ArrayList(); + for (Entry entry : areas.entrySet()) { + CuboidArea a = entry.getValue(); + Location h = a.getHighLoc(); + Location l = a.getLowLoc(); + temp.add(ChatColor.GREEN + "{" + ChatColor.YELLOW + "ID:" + ChatColor.RED + + entry.getKey() + " " + ChatColor.YELLOW + "P1:" + ChatColor.RED + "(" + + h.getBlockX() + "," + h.getBlockY() + "," + h.getBlockZ() + ") " + + ChatColor.YELLOW + "P2:" + ChatColor.RED + "(" + l.getBlockX() + "," + + l.getBlockY() + "," + l.getBlockZ() + ") " + ChatColor.YELLOW + "(Size:" + + ChatColor.RED + a.getSize() + ChatColor.YELLOW + ")" + ChatColor.GREEN + "} "); + } + InformationPager.printInfo(player, Residence.getLanguage().getPhrase("PhysicalAreas"), + temp, page); + } - public int getAreaCount() - { - return areas.size(); - } + public void printAreaList(Player player, int page) { + ArrayList temp = new ArrayList(); + for (String area : areas.keySet()) { + temp.add(area); + } + InformationPager.printInfo(player, Residence.getLanguage().getPhrase("PhysicalAreas"), + temp, page); + } - public boolean renameSubzone(String oldName, String newName) - { - return this.renameSubzone(null, oldName, newName, true); - } + public void printSubzoneList(Player player, int page) { + ArrayList temp = new ArrayList(); + for (Entry sz : subzones.entrySet()) { + temp.add(ChatColor.GREEN + sz.getKey() + ChatColor.YELLOW + " - " + + Residence.getLanguage().getPhrase("Owner") + ": " + sz.getValue().getOwner()); + } + InformationPager.printInfo(player, Residence.getLanguage().getPhrase("Subzones"), temp, + page); + } - public boolean renameSubzone(Player player, String oldName, String newName, boolean resadmin) - { - if (!Residence.validName(newName)) - { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidNameCharacters")); - return false; - } - ClaimedResidence res = subzones.get(oldName); - if (res == null) - { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidSubzone")); - return false; - } - if (player != null && !res.getPermissions().hasResidencePermission(player, true) && !resadmin) - { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return false; - } - if (subzones.containsKey(newName)) - { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("SubzoneExists", ChatColor.YELLOW + newName)); - return false; - } - subzones.put(newName, res); - subzones.remove(oldName); - if (player != null) - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("SubzoneRename", oldName + "." + newName)); - return true; - } + public void remove() { + String name = getName(); + if (name != null) { + Residence.getResidenceManager().removeResidence(name); + Residence.getResidenceManager().removeChunkList(name); + } + } - public boolean renameArea(String oldName, String newName) - { - return this.renameArea(null, oldName, newName, true); - } + public void removeArea(Player player, String id, boolean resadmin) { - public boolean renameArea(Player player, String oldName, String newName, boolean resadmin) - { - if (!Residence.validName(newName)) - { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidNameCharacters")); - return false; - } - if (player == null || perms.hasResidencePermission(player, true) || resadmin) - { - if (areas.containsKey(newName)) - { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaExists")); - return false; - } - CuboidArea area = areas.get(oldName); - if (area == null) - { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("AreaInvalidName")); - return false; - } - areas.put(newName, area); - areas.remove(oldName); - if (player != null) - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("AreaRename", oldName + "." + newName)); - return true; - } - else - { - if (player != null) - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); - return false; - } - } + if (this.getPermissions().hasResidencePermission(player, true) || resadmin) { + if (!areas.containsKey(id)) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaNonExist")); + return; + } + if (areas.size() == 1 && !Residence.getConfigManager().allowEmptyResidences()) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaRemoveLast")); + return; + } + removeArea(id); + player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("AreaRemove")); + } else { + player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); + } + } - public CuboidArea getArea(String name) - { - return areas.get(name); - } + public void removeArea(String id) { + Residence.getResidenceManager().removeChunkList(getName()); + areas.remove(id); + Residence.getResidenceManager().calculateChunks(getName()); + } - public String getName() { - return Residence.getResidenceManager().getNameByRes(this); - } + public boolean removeSubzone(Player player, String name, boolean resadmin) { + ClaimedResidence res = subzones.get(name); + if (player != null && !res.perms.hasResidencePermission(player, true) && !resadmin) { + player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); + return false; + } + subzones.remove(name); + if (player != null) { + player.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase("SubzoneRemove", + ChatColor.YELLOW + name + ChatColor.GREEN)); + } + return true; + } - public void remove() { - String name = getName(); - if (name != null) { - Residence.getResidenceManager().removeResidence(name); - Residence.getResidenceManager().removeChunkList(name); - } - } + public boolean removeSubzone(String name) { + return this.removeSubzone(null, name, true); + } - public ResidenceBank getBank() - { - return bank; - } + public boolean renameArea(Player player, String oldName, String newName, boolean resadmin) { + if (!Residence.validName(newName)) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidNameCharacters")); + return false; + } + if (player == null || perms.hasResidencePermission(player, true) || resadmin) { + if (areas.containsKey(newName)) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaExists")); + } + return false; + } + CuboidArea area = areas.get(oldName); + if (area == null) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaInvalidName")); + } + return false; + } + areas.put(newName, area); + areas.remove(oldName); + if (player != null) { + player.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase("AreaRename", oldName + "." + newName)); + } + return true; + } else { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); + } + return false; + } + } - public String getWorld() - { - return perms.getWorld(); - } + public boolean renameArea(String oldName, String newName) { + return this.renameArea(null, oldName, newName, true); + } - public String getOwner() - { - return perms.getOwner(); - } + public boolean renameSubzone(Player player, String oldName, String newName, boolean resadmin) { + if (!Residence.validName(newName)) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidNameCharacters")); + return false; + } + ClaimedResidence res = subzones.get(oldName); + if (res == null) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidSubzone")); + } + return false; + } + if (player != null && !res.getPermissions().hasResidencePermission(player, true) + && !resadmin) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); + } + return false; + } + if (subzones.containsKey(newName)) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("SubzoneExists", + ChatColor.YELLOW + newName)); + } + return false; + } + subzones.put(newName, res); + subzones.remove(oldName); + if (player != null) { + player.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase("SubzoneRename", oldName + "." + newName)); + } + return true; + } - public ResidenceItemList getItemBlacklist() - { - return blacklist; - } + public boolean renameSubzone(String oldName, String newName) { + return this.renameSubzone(null, oldName, newName, true); + } - public ResidenceItemList getItemIgnoreList() - { - return ignorelist; - } + public boolean replaceArea(CuboidArea neware, String name) { + return this.replaceArea(null, neware, name, true); + } - public ArrayList getPlayersInResidence() { - ArrayList within = new ArrayList(); - for (Player player : Bukkit.getServer().getOnlinePlayers()) { - if (this.containsLoc(player.getLocation())) { - within.add(player); - } - } - return within; - } + public boolean replaceArea(Player player, CuboidArea newarea, String name, boolean resadmin) { + if (!areas.containsKey(name)) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaNonExist")); + } + return false; + } + CuboidArea oldarea = areas.get(name); + if (!newarea.getWorld().getName().equalsIgnoreCase(perms.getWorld())) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaDiffWorld")); + } + return false; + } + if (parent == null) { + String collideResidence = Residence.getResidenceManager().checkAreaCollision(newarea, + this); + if (collideResidence != null) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaCollision", + ChatColor.YELLOW + collideResidence)); + } + return false; + } + } else { + String[] szs = parent.listSubzones(); + for (String sz : szs) { + ClaimedResidence res = parent.getSubzone(sz); + if (res != null && res != this) { + if (res.checkCollision(newarea)) { + if (player != null) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaSubzoneCollision", + ChatColor.YELLOW + sz)); + } + return false; + } + } + } + } + // Remove subzones that are not in the area anymore + String[] szs = listSubzones(); + for (String sz : szs) { + ClaimedResidence res = getSubzone(sz); + if (res != null && res != this) { + String[] areas = res.getAreaList(); + for (String area : areas) { + if (!newarea.isAreaWithinArea(res.getArea(area))) { + boolean good = false; + for (CuboidArea arae : getAreaArray()) { + if (arae != oldarea && arae.isAreaWithinArea(res.getArea(area))) { + good = true; + } + } + if (!good) { + res.removeArea(area); + } + } + } + if (res.getAreaArray().length == 0) { + removeSubzone(sz); + } + } + } + if (!resadmin && player != null) { + if (!this.perms.hasResidencePermission(player, true)) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); + return false; + } + if (parent != null) { + if (!parent.containsLoc(newarea.getHighLoc()) + || !parent.containsLoc(newarea.getLowLoc())) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaNotWithinParent")); + return false; + } + if (!parent.getPermissions().hasResidencePermission(player, true) + && !parent.getPermissions().playerHas(player.getName(), "subzone", true)) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("ParentNoPermission")); + return false; + } + } + PermissionGroup group = Residence.getPermissionManager().getGroup(player); + if (!group.canCreateResidences() && !player.hasPermission("residence.create")) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); + return false; + } + if (!group.inLimits(newarea)) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaSizeLimit")); + return false; + } + if (group.getMinHeight() > newarea.getLowLoc().getBlockY()) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaLowLimit", + ChatColor.YELLOW + String.format("%d", group.getMinHeight()))); + return false; + } + if (group.getMaxHeight() < newarea.getHighLoc().getBlockY()) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("AreaHighLimit", + ChatColor.YELLOW + String.format("%d", group.getMaxHeight()))); + return false; + } + if (parent == null && Residence.getConfigManager().enableEconomy()) { + int chargeamount = (int) Math.ceil((newarea.getSize() - oldarea.getSize()) + * group.getCostPerBlock()); + if (chargeamount > 0) { + if (!TransactionManager.chargeEconomyMoney(player, chargeamount)) + return false; + } + } + + } + Residence.getResidenceManager().removeChunkList(getName()); + areas.remove(name); + areas.put(name, newarea); + Residence.getResidenceManager().calculateChunks(getName()); + player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("AreaUpdate")); + return true; + } + + public Map save() { + Map root = new HashMap(); + Map areamap = new HashMap(); + root.put("EnterMessage", enterMessage); + root.put("LeaveMessage", leaveMessage); + root.put("StoredMoney", bank.getStoredMoney()); + root.put("BlackList", blacklist.save()); + root.put("IgnoreList", ignorelist.save()); + for (Entry entry : areas.entrySet()) { + areamap.put(entry.getKey(), entry.getValue().save()); + } + root.put("Areas", areamap); + Map subzonemap = new HashMap(); + for (Entry sz : subzones.entrySet()) { + subzonemap.put(sz.getKey(), sz.getValue().save()); + } + root.put("Subzones", subzonemap); + root.put("Permissions", perms.save()); + if (tpLoc != null) { + Map tpmap = new HashMap(); + tpmap.put("X", tpLoc.getBlockX()); + tpmap.put("Y", tpLoc.getBlockY()); + tpmap.put("Z", tpLoc.getBlockZ()); + root.put("TPLoc", tpmap); + } + return root; + } + + public void setEnterLeaveMessage(Player player, String message, boolean enter, boolean resadmin) { + // if(message!=null && + // Residence.getConfigManager().getResidenceNameRegex() != null) { + // Removed pending further action + // player.sendMessage(ChatColor.RED+Residence.getLanguage().getPhrase("InvalidCharacters")); + // return; + // } + if (message != null) { + if (message.equals("")) { + message = null; + } + } + PermissionGroup group = Residence.getPermissionManager().getGroup(perms.getOwner(), + perms.getWorld()); + if (!group.canSetEnterLeaveMessages() && !resadmin) { + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("OwnerNoPermission")); + return; + } + if (!perms.hasResidencePermission(player, false) && !resadmin) { + player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); + return; + } + if (enter) { + this.setEnterMessage(message); + } else { + this.setLeaveMessage(message); + } + player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("MessageChange")); + } + + public void setEnterMessage(String message) { + enterMessage = message; + } + + public void setLeaveMessage(String message) { + leaveMessage = message; + } + + public void setTpLoc(Player player, boolean resadmin) { + if (!this.perms.hasResidencePermission(player, false) && !resadmin) { + player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); + return; + } + if (!this.containsLoc(player.getLocation())) { + player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NotInResidence")); + return; + } + tpLoc = player.getLocation(); + player.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase("SetTeleportLocation")); + } + + public void tpToResidence(Player reqPlayer, Player targetPlayer, boolean resadmin) { + if (!resadmin) { + PermissionGroup group = Residence.getPermissionManager().getGroup(reqPlayer); + if (!group.hasTpAccess()) { + reqPlayer.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("TeleportDeny")); + return; + } + if (!reqPlayer.equals(targetPlayer)) { + reqPlayer.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); + return; + } + if (!this.perms.playerHas(reqPlayer.getName(), "tp", true)) { + reqPlayer.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("TeleportNoFlag")); + return; + } + } + if (tpLoc != null) { + ResidenceTPEvent tpevent = new ResidenceTPEvent(this, tpLoc, targetPlayer, reqPlayer); + Residence.getServ().getPluginManager().callEvent(tpevent); + if (!tpevent.isCancelled()) { + targetPlayer.teleport(tpLoc); + targetPlayer.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase("TeleportSuccess")); + } + } else { + CuboidArea area = areas.values().iterator().next(); + if (area == null) { + reqPlayer.sendMessage(ChatColor.RED + "Could not find area to teleport to..."); + return; + } + Location targloc = this.getOutsideFreeLoc(area.getHighLoc()); + ResidenceTPEvent tpevent = new ResidenceTPEvent(this, targloc, targetPlayer, reqPlayer); + Residence.getServ().getPluginManager().callEvent(tpevent); + if (!tpevent.isCancelled()) { + targetPlayer.teleport(targloc); + targetPlayer.sendMessage(ChatColor.YELLOW + + Residence.getLanguage().getPhrase("TeleportNear")); + } + } + } } diff --git a/src/com/bekvon/bukkit/residence/protection/ResidenceManager.java b/src/com/bekvon/bukkit/residence/protection/ResidenceManager.java index 1d3c435..b95e8f4 100644 --- a/src/com/bekvon/bukkit/residence/protection/ResidenceManager.java +++ b/src/com/bekvon/bukkit/residence/protection/ResidenceManager.java @@ -1,6 +1,5 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * To change this template, choose Tools | Templates and open the template in the editor. */ package com.bekvon.bukkit.residence.protection; @@ -42,6 +41,7 @@ public class ResidenceManager { // For more info, see CraftBukkit.CraftWorld.getChunkAt( Location ) return val >> 4; } + private final int z; private final int x; @@ -49,6 +49,7 @@ public class ResidenceManager { this.x = x; this.z = z; } + public ChunkRef(Location loc) { this.x = getChunkCoord(loc.getBlockX()); this.z = getChunkCoord(loc.getBlockZ()); @@ -74,13 +75,14 @@ public class ResidenceManager { /** * Useful for debug */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append( "{ x: " ).append(x).append( ", z: " ).append( z ).append( " }" ); - return sb.toString(); - } + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{ x: ").append(x).append(", z: ").append(z).append(" }"); + return sb.toString(); + } } + private static List getChunks(ClaimedResidence res) { List chunks = new ArrayList(); for (CuboidArea area : res.getAreaArray()) { @@ -95,13 +97,12 @@ public class ResidenceManager { if (root == null) return resm; for (World world : Residence.getServ().getWorlds()) { - Map reslist = (Map) root.get(world - .getName()); + Map reslist = (Map) root.get(world.getName()); if (reslist != null) { try { resm.chunkResidences.put(world.getName(), loadMap(reslist, resm)); } catch (Exception ex) { - System.out.println("Error in loading save file for world: " + world.getName()); + Residence.getLog().warning("载入世界: " + world.getName() + "的领地数据时发生错误!"); if (Residence.getConfigManager().stopOnSaveError()) throw (ex); } @@ -111,7 +112,8 @@ public class ResidenceManager { } @SuppressWarnings("unchecked") - public static Map> loadMap(Map root, ResidenceManager resm) throws Exception { + public static Map> loadMap(Map root, + ResidenceManager resm) throws Exception { Map> retRes = new HashMap>(); if (root != null) { for (Entry res : root.entrySet()) { @@ -128,7 +130,8 @@ public class ResidenceManager { } resm.residences.put(res.getKey(), residence); } catch (Exception ex) { - System.out.print("[Residence] Failed to load residence (" + res.getKey() + ")! Reason:" + ex.getMessage() + " Error Log:"); + System.out.print("[Residence] Failed to load residence (" + res.getKey() + + ")! Reason:" + ex.getMessage() + " Error Log:"); Logger.getLogger(ResidenceManager.class.getName()).log(Level.SEVERE, null, ex); if (Residence.getConfigManager().stopOnSaveError()) throw (ex); @@ -147,34 +150,43 @@ public class ResidenceManager { chunkResidences = new HashMap>>(); } - public boolean addResidence(Player player, String name, Location loc1, Location loc2, boolean resadmin) { + public boolean addResidence(Player player, String name, Location loc1, Location loc2, + boolean resadmin) { return this.addResidence(player, player.getName(), name, loc1, loc2, resadmin); } - public boolean addResidence(Player player, String owner, String name, Location loc1, Location loc2, boolean resadmin) { + public boolean addResidence(Player player, String owner, String name, Location loc1, + Location loc2, boolean resadmin) { if (!Residence.validName(name)) { if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidNameCharacters")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidNameCharacters")); } return false; } - if (loc1 == null || loc2 == null || !loc1.getWorld().getName().equals(loc2.getWorld().getName())) { + if (loc1 == null || loc2 == null + || !loc1.getWorld().getName().equals(loc2.getWorld().getName())) { if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("SelectPoints")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("SelectPoints")); } return false; } - PermissionGroup group = Residence.getPermissionManager().getGroup(owner, loc1.getWorld().getName()); - boolean createpermission = group.canCreateResidences() || (player == null ? true : player.hasPermission("residence.create")); + PermissionGroup group = Residence.getPermissionManager().getGroup(owner, + loc1.getWorld().getName()); + boolean createpermission = group.canCreateResidences() + || (player == null ? true : player.hasPermission("residence.create")); if (!createpermission && !resadmin) { if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); } return false; } if (player != null) { if (getOwnedZoneCount(player.getName()) >= group.getMaxZones() && !resadmin) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceTooMany")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("ResidenceTooMany")); return false; } } @@ -192,7 +204,9 @@ public class ResidenceManager { name = resevent.getResidenceName(); if (residences.containsKey(name)) { if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceAlreadyExists", ChatColor.YELLOW + name + ChatColor.RED)); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("ResidenceAlreadyExists", + ChatColor.YELLOW + name + ChatColor.RED)); } return false; } @@ -206,11 +220,14 @@ public class ResidenceManager { calculateChunks(name); Residence.getLeaseManager().removeExpireTime(name); if (player != null) { - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("ResidenceCreate", ChatColor.YELLOW + name + ChatColor.GREEN)); + player.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase("ResidenceCreate", + ChatColor.YELLOW + name + ChatColor.GREEN)); } if (Residence.getConfigManager().useLeases()) { if (player != null) { - Residence.getLeaseManager().setExpireTime(player, name, group.getLeaseGiveTime()); + Residence.getLeaseManager().setExpireTime(player, name, + group.getLeaseGiveTime()); } else { Residence.getLeaseManager().setExpireTime(name, group.getLeaseGiveTime()); } @@ -262,7 +279,7 @@ public class ResidenceManager { ClaimedResidence res = null; boolean found = false; String world = loc.getWorld().getName(); - ChunkRef chunk = new ChunkRef( loc ); + ChunkRef chunk = new ChunkRef(loc); if (chunkResidences.get(world) != null) { if (chunkResidences.get(world).get(chunk) != null) { for (String key : chunkResidences.get(world).get(chunk)) { @@ -306,7 +323,7 @@ public class ResidenceManager { String name = null; boolean found = false; String world = loc.getWorld().getName(); - ChunkRef chunk = new ChunkRef( loc ); + ChunkRef chunk = new ChunkRef(loc); if (chunkResidences.get(world) != null) { if (chunkResidences.get(world).get(chunk) != null) { for (String key : chunkResidences.get(world).get(chunk)) { @@ -365,44 +382,55 @@ public class ResidenceManager { return this.getResidenceList(null, showhidden, showsubzones, false); } - public ArrayList getResidenceList(String targetplayer, boolean showhidden, boolean showsubzones) { + public ArrayList getResidenceList(String targetplayer, boolean showhidden, + boolean showsubzones) { return this.getResidenceList(targetplayer, showhidden, showsubzones, false); } - public ArrayList getResidenceList(String targetplayer, boolean showhidden, boolean showsubzones, boolean formattedOutput) { + public ArrayList getResidenceList(String targetplayer, boolean showhidden, + boolean showsubzones, boolean formattedOutput) { ArrayList list = new ArrayList(); for (Entry res : residences.entrySet()) { - this.getResidenceList(targetplayer, showhidden, showsubzones, "", res.getKey(), res.getValue(), list, formattedOutput); + this.getResidenceList(targetplayer, showhidden, showsubzones, "", res.getKey(), + res.getValue(), list, formattedOutput); } return list; } - private void getResidenceList(String targetplayer, boolean showhidden, boolean showsubzones, String parentzone, String resname, ClaimedResidence res, ArrayList list, boolean formattedOutput) { + private void getResidenceList(String targetplayer, boolean showhidden, boolean showsubzones, + String parentzone, String resname, ClaimedResidence res, ArrayList list, + boolean formattedOutput) { boolean hidden = res.getPermissions().has("hidden", false); if ((showhidden) || (!showhidden && !hidden)) { - if (targetplayer == null || res.getPermissions().getOwner().equalsIgnoreCase(targetplayer)) { + if (targetplayer == null + || res.getPermissions().getOwner().equalsIgnoreCase(targetplayer)) { if (formattedOutput) { - list.add(ChatColor.GREEN + parentzone + resname + ChatColor.YELLOW + " - " + Residence.getLanguage().getPhrase("World") + ": " + res.getWorld()); + list.add(ChatColor.GREEN + parentzone + resname + ChatColor.YELLOW + " - " + + Residence.getLanguage().getPhrase("World") + ": " + res.getWorld()); } else { list.add(parentzone + resname); } } if (showsubzones) { for (Entry sz : res.subzones.entrySet()) { - this.getResidenceList(targetplayer, showhidden, showsubzones, parentzone + resname + ".", sz.getKey(), sz.getValue(), list, formattedOutput); + this.getResidenceList(targetplayer, showhidden, showsubzones, parentzone + + resname + ".", sz.getKey(), sz.getValue(), list, formattedOutput); } } } } - public void giveResidence(Player reqPlayer, String targPlayer, String residence, boolean resadmin) { + public void giveResidence(Player reqPlayer, String targPlayer, String residence, + boolean resadmin) { ClaimedResidence res = getByName(residence); if (res == null) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence")); + reqPlayer.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidResidence")); return; } if (!res.getPermissions().hasResidencePermission(reqPlayer, true) && !resadmin) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); + reqPlayer + .sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); return; } Player giveplayer = Residence.getServ().getPlayer(targPlayer); @@ -413,25 +441,35 @@ public class ResidenceManager { CuboidArea[] areas = res.getAreaArray(); PermissionGroup g = Residence.getPermissionManager().getGroup(giveplayer); if (areas.length > g.getMaxPhysicalPerResidence() && !resadmin) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceGiveLimits")); + reqPlayer.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("ResidenceGiveLimits")); return; } if (getOwnedZoneCount(giveplayer.getName()) >= g.getMaxZones() && !resadmin) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceGiveLimits")); + reqPlayer.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("ResidenceGiveLimits")); return; } if (!resadmin) { for (CuboidArea area : areas) { if (!g.inLimits(area)) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceGiveLimits")); + reqPlayer.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("ResidenceGiveLimits")); return; } } } res.getPermissions().setOwner(giveplayer.getName(), true); // Fix phrases here - reqPlayer.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("ResidenceGive", ChatColor.YELLOW + residence + ChatColor.GREEN + "." + ChatColor.YELLOW + giveplayer.getName() + ChatColor.GREEN)); - giveplayer.sendMessage(Residence.getLanguage().getPhrase("ResidenceRecieve", ChatColor.GREEN + residence + ChatColor.YELLOW + "." + ChatColor.GREEN + reqPlayer.getName() + ChatColor.YELLOW)); + reqPlayer.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase( + "ResidenceGive", + ChatColor.YELLOW + residence + ChatColor.GREEN + "." + ChatColor.YELLOW + + giveplayer.getName() + ChatColor.GREEN)); + giveplayer.sendMessage(Residence.getLanguage().getPhrase( + "ResidenceRecieve", + ChatColor.GREEN + residence + ChatColor.YELLOW + "." + ChatColor.GREEN + + reqPlayer.getName() + ChatColor.YELLOW)); } public void listAllResidences(Player player, int page) { @@ -446,7 +484,8 @@ public class ResidenceManager { if (showhidden && !Residence.isResAdminOn(player)) { showhidden = false; } - InformationPager.printInfo(player, Residence.getLanguage().getPhrase("Residences"), this.getResidenceList(null, showhidden, showsubzones, true), page); + InformationPager.printInfo(player, Residence.getLanguage().getPhrase("Residences"), + this.getResidenceList(null, showhidden, showsubzones, true), page); } public void listResidences(Player player) { @@ -473,23 +512,29 @@ public class ResidenceManager { this.listResidences(player, targetplayer, page, showhidden, false); } - public void listResidences(Player player, String targetplayer, int page, boolean showhidden, boolean showsubzones) { + public void listResidences(Player player, String targetplayer, int page, boolean showhidden, + boolean showsubzones) { if (showhidden && !Residence.isResAdminOn(player) && !player.getName().equals(targetplayer)) { showhidden = false; } - InformationPager.printInfo(player, Residence.getLanguage().getPhrase("Residences") + " - " + targetplayer, this.getResidenceList(targetplayer, showhidden, showsubzones, true), page); + InformationPager.printInfo(player, Residence.getLanguage().getPhrase("Residences") + " - " + + targetplayer, + this.getResidenceList(targetplayer, showhidden, showsubzones, true), page); } public void mirrorPerms(Player reqPlayer, String targetArea, String sourceArea, boolean resadmin) { ClaimedResidence reciever = this.getByName(targetArea); ClaimedResidence source = this.getByName(sourceArea); if (source == null || reciever == null) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence")); + reqPlayer.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidResidence")); return; } if (!resadmin) { - if (!reciever.getPermissions().hasResidencePermission(reqPlayer, true) || !source.getPermissions().hasResidencePermission(reqPlayer, true)) { - reqPlayer.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); + if (!reciever.getPermissions().hasResidencePermission(reqPlayer, true) + || !source.getPermissions().hasResidencePermission(reqPlayer, true)) { + reqPlayer.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); return; } } @@ -499,35 +544,78 @@ public class ResidenceManager { public void printAreaInfo(String areaname, Player player) { ClaimedResidence res = this.getByName(areaname); if (res == null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidResidence")); return; } ResidencePermissions perms = res.getPermissions(); if (Residence.getConfigManager().enableEconomy()) { - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Residence") + ":" + ChatColor.DARK_GREEN + " " + areaname + " " + ChatColor.YELLOW + "Bank: " + ChatColor.GOLD + res.getBank().getStoredMoney()); + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Residence") + + ":" + ChatColor.DARK_GREEN + " " + areaname + " " + ChatColor.YELLOW + + "Bank: " + ChatColor.GOLD + res.getBank().getStoredMoney()); } else { - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Residence") + ":" + ChatColor.DARK_GREEN + " " + areaname); + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Residence") + + ":" + ChatColor.DARK_GREEN + " " + areaname); } - if (Residence.getConfigManager().enabledRentSystem() && Residence.getRentManager().isRented(areaname)) { - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Owner") + ":" + ChatColor.RED + " " + perms.getOwner() + ChatColor.YELLOW + " Rented by: " + ChatColor.RED + Residence.getRentManager().getRentingPlayer(areaname)); + if (Residence.getConfigManager().enabledRentSystem() + && Residence.getRentManager().isRented(areaname)) { + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Owner") + ":" + + ChatColor.RED + " " + perms.getOwner() + ChatColor.YELLOW + " Rented by: " + + ChatColor.RED + Residence.getRentManager().getRentingPlayer(areaname)); } else { - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Owner") + ":" + ChatColor.RED + " " + perms.getOwner() + ChatColor.YELLOW + " - " + Residence.getLanguage().getPhrase("World") + ": " + ChatColor.RED + perms.getWorld()); + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Owner") + ":" + + ChatColor.RED + " " + perms.getOwner() + ChatColor.YELLOW + " - " + + Residence.getLanguage().getPhrase("World") + ": " + ChatColor.RED + + perms.getWorld()); } - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Flags") + ":" + ChatColor.BLUE + " " + perms.listFlags()); - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Your.Flags") + ": " + ChatColor.GREEN + perms.listPlayerFlags(player.getName())); - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Group.Flags") + ":" + ChatColor.RED + " " + perms.listGroupFlags()); - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Others.Flags") + ":" + ChatColor.RED + " " + perms.listOtherPlayersFlags(player.getName())); + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Flags") + ":" + + ChatColor.BLUE + " " + perms.listFlags()); + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Your.Flags") + + ": " + ChatColor.GREEN + perms.listPlayerFlags(player.getName())); + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Group.Flags") + + ":" + ChatColor.RED + " " + perms.listGroupFlags()); + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Others.Flags") + + ":" + ChatColor.RED + " " + perms.listOtherPlayersFlags(player.getName())); String aid = res.getAreaIDbyLoc(player.getLocation()); if (aid != null) { - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("CurrentArea") + ": " + ChatColor.GOLD + aid); + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("CurrentArea") + + ": " + ChatColor.GOLD + aid); } - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Total.Size") + ":" + ChatColor.LIGHT_PURPLE + " " + res.getTotalSize()); + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("Total.Size") + ":" + + ChatColor.LIGHT_PURPLE + " " + res.getTotalSize()); if (aid != null) { - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("CoordsT") + ": " + ChatColor.LIGHT_PURPLE + Residence.getLanguage().getPhrase("CoordsTop", res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockX() + "." + res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockY() + "." + res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockZ())); - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("CoordsB") + ": " + ChatColor.LIGHT_PURPLE + Residence.getLanguage().getPhrase("CoordsBottom", res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockX() + "." + res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockY() + "." + res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockZ())); + player.sendMessage(ChatColor.YELLOW + + Residence.getLanguage().getPhrase("CoordsT") + + ": " + + ChatColor.LIGHT_PURPLE + + Residence.getLanguage().getPhrase( + "CoordsTop", + res.getAreaByLoc(player.getLocation()).getHighLoc().getBlockX() + + "." + + res.getAreaByLoc(player.getLocation()).getHighLoc() + .getBlockY() + + "." + + res.getAreaByLoc(player.getLocation()).getHighLoc() + .getBlockZ())); + player.sendMessage(ChatColor.YELLOW + + Residence.getLanguage().getPhrase("CoordsB") + + ": " + + ChatColor.LIGHT_PURPLE + + Residence.getLanguage().getPhrase( + "CoordsBottom", + res.getAreaByLoc(player.getLocation()).getLowLoc().getBlockX() + + "." + + res.getAreaByLoc(player.getLocation()).getLowLoc() + .getBlockY() + + "." + + res.getAreaByLoc(player.getLocation()).getLowLoc() + .getBlockZ())); } - if (Residence.getConfigManager().useLeases() && Residence.getLeaseManager().leaseExpires(areaname)) { - player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("LeaseExpire") + ":" + ChatColor.GREEN + " " + Residence.getLeaseManager().getExpireTime(areaname)); + if (Residence.getConfigManager().useLeases() + && Residence.getLeaseManager().leaseExpires(areaname)) { + player.sendMessage(ChatColor.YELLOW + Residence.getLanguage().getPhrase("LeaseExpire") + + ":" + ChatColor.GREEN + " " + + Residence.getLeaseManager().getExpireTime(areaname)); } } @@ -535,12 +623,14 @@ public class ResidenceManager { this.removeAllByOwner(player, owner, residences); } - private void removeAllByOwner(Player player, String owner, Map resholder) { + private void removeAllByOwner(Player player, String owner, + Map resholder) { Iterator it = resholder.values().iterator(); while (it.hasNext()) { ClaimedResidence res = it.next(); if (res.getOwner().equalsIgnoreCase(owner)) { - ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(player, res, player == null ? DeleteCause.OTHER : DeleteCause.PLAYER_DELETE); + ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(player, res, + player == null ? DeleteCause.OTHER : DeleteCause.PLAYER_DELETE); Residence.getServ().getPluginManager().callEvent(resevent); if (resevent.isCancelled()) return; @@ -569,9 +659,11 @@ public class ResidenceManager { chunkResidences.remove(world); chunkResidences.put(world, new HashMap>()); if (count == 0) { - sender.sendMessage(ChatColor.RED + "No residences found in world: " + ChatColor.YELLOW + world); + sender.sendMessage(ChatColor.RED + "No residences found in world: " + ChatColor.YELLOW + + world); } else { - sender.sendMessage(ChatColor.RED + "Removed " + ChatColor.YELLOW + count + ChatColor.RED + " residences in world: " + ChatColor.YELLOW + world); + sender.sendMessage(ChatColor.RED + "Removed " + ChatColor.YELLOW + count + + ChatColor.RED + " residences in world: " + ChatColor.YELLOW + world); } } @@ -597,11 +689,13 @@ public class ResidenceManager { if (res != null) { if (player != null && !resadmin) { if (!res.getPermissions().hasResidencePermission(player, true) && !resadmin) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); return; } } - ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(player, res, player == null ? DeleteCause.OTHER : DeleteCause.PLAYER_DELETE); + ResidenceDeleteEvent resevent = new ResidenceDeleteEvent(player, res, + player == null ? DeleteCause.OTHER : DeleteCause.PLAYER_DELETE); Residence.getServ().getPluginManager().callEvent(resevent); if (resevent.isCancelled()) return; @@ -610,7 +704,9 @@ public class ResidenceManager { removeChunkList(name); residences.remove(name); if (player != null) { - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("ResidenceRemove", ChatColor.YELLOW + name + ChatColor.GREEN)); + player.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase("ResidenceRemove", + ChatColor.YELLOW + name + ChatColor.GREEN)); } } else { String[] split = name.split("\\."); @@ -627,7 +723,8 @@ public class ResidenceManager { } else { if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidResidence")); } } } @@ -638,13 +735,15 @@ public class ResidenceManager { public boolean renameResidence(Player player, String oldName, String newName, boolean resadmin) { if (!Residence.validName(newName)) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidNameCharacters")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidNameCharacters")); return false; } ClaimedResidence res = this.getByName(oldName); if (res == null) { if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("InvalidResidence")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("InvalidResidence")); } return false; } @@ -652,7 +751,9 @@ public class ResidenceManager { if (res.getParent() == null) { if (residences.containsKey(newName)) { if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("ResidenceAlreadyExists", ChatColor.YELLOW + newName + ChatColor.RED)); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("ResidenceAlreadyExists", + ChatColor.YELLOW + newName + ChatColor.RED)); } return false; } @@ -669,7 +770,11 @@ public class ResidenceManager { Residence.getRentManager().updateRentableName(oldName, newName); } if (player != null) { - player.sendMessage(ChatColor.GREEN + Residence.getLanguage().getPhrase("ResidenceRename", ChatColor.YELLOW + oldName + ChatColor.GREEN + "." + ChatColor.YELLOW + newName + ChatColor.GREEN)); + player.sendMessage(ChatColor.GREEN + + Residence.getLanguage().getPhrase( + "ResidenceRename", + ChatColor.YELLOW + oldName + ChatColor.GREEN + "." + + ChatColor.YELLOW + newName + ChatColor.GREEN)); } return true; } else { @@ -679,7 +784,8 @@ public class ResidenceManager { } } else { if (player != null) { - player.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPermission")); + player.sendMessage(ChatColor.RED + + Residence.getLanguage().getPhrase("NoPermission")); } return false; } @@ -698,8 +804,10 @@ public class ResidenceManager { try { resmap.put(res.getKey(), res.getValue().save()); } catch (Exception ex) { - System.out.println("[Residence] Failed to save residence (" + res.getKey() + ")!"); - Logger.getLogger(ResidenceManager.class.getName()).log(Level.SEVERE, null, ex); + System.out.println("[Residence] Failed to save residence (" + res.getKey() + + ")!"); + Logger.getLogger(ResidenceManager.class.getName()).log(Level.SEVERE, null, + ex); } } }