public boolean isEnemy(String a, String b) { try { Resident residentA = getDataSource().getResident(a); Resident residentB = getDataSource().getResident(b); if (residentA.getTown() == residentB.getTown()) return false; if (residentA.getTown().getNation() == residentB.getTown().getNation()) return false; if (residentA.getTown().getNation().hasEnemy(residentB.getTown().getNation())) return true; } catch (NotRegisteredException e) { return false; } return false; }
public boolean canAttackEnemy(String a, String b) { try { Resident residentA = getDataSource().getResident(a); Resident residentB = getDataSource().getResident(b); if (residentA.getTown() == residentB.getTown()) return false; if (residentA.getTown().getNation() == residentB.getTown().getNation()) return false; Nation nationA = residentA.getTown().getNation(); Nation nationB = residentB.getTown().getNation(); if (nationA.isNeutral() || nationB.isNeutral()) return false; if (nationA.hasEnemy(nationB)) return true; } catch (NotRegisteredException e) { return false; } return false; }
public Location getTownSpawnLocation(Player player) throws TownyException { try { Resident resident = getDataSource().getResident(player.getName()); Town town = resident.getTown(); return town.getSpawn(); } catch (TownyException x) { throw new TownyException("Unable to get spawn location"); } }
public void onLogin(Player player) throws AlreadyRegisteredException, NotRegisteredException { if (!player.isOnline()) return; // Test and kick any players with invalid names. if ((player.getName().trim() == null) || (player.getName().contains(" "))) { player.kickPlayer("Invalid name!"); return; } Resident resident; if (!getDataSource().hasResident(player.getName())) { getDataSource().newResident(player.getName()); resident = getDataSource().getResident(player.getName()); TownyMessaging.sendMessage(player, TownySettings.getRegistrationMsg(player.getName())); resident.setRegistered(System.currentTimeMillis()); if (!TownySettings.getDefaultTownName().equals("")) try { Town town = getDataSource().getTown(TownySettings.getDefaultTownName()); town.addResident(resident); getDataSource().saveTown(town); } catch (NotRegisteredException e) { } catch (AlreadyRegisteredException e) { } getDataSource().saveResident(resident); getDataSource().saveResidentList(); } else { resident = getDataSource().getResident(player.getName()); resident.setLastOnline(System.currentTimeMillis()); getDataSource().saveResident(resident); } try { TownyMessaging.sendTownBoard(player, resident.getTown()); } catch (NotRegisteredException e) { } if (isWarTime()) getWarEvent().sendScores(player, 3); // Schedule to setup default modes when the player has finished loading if (getPlugin() .getServer() .getScheduler() .scheduleSyncDelayedTask(getPlugin(), new SetDefaultModes(this, player, false), 1) == -1) TownyMessaging.sendErrorMsg("Could not set default modes for " + player.getName() + "."); setChangedNotify(PLAYER_LOGIN); }
public TownBlockStatus getStatusCache(Player player, WorldCoord worldCoord) { // if (isTownyAdmin(player)) // return TownBlockStatus.ADMIN; if (!worldCoord.getWorld().isUsingTowny()) return TownBlockStatus.OFF_WORLD; // TownyUniverse universe = plugin.getTownyUniverse(); TownBlock townBlock; Town town; try { townBlock = worldCoord.getTownBlock(); town = townBlock.getTown(); if (townBlock.isLocked()) { // Push the TownBlock location to the queue for a snapshot (if it's not already in the // queue). if (town.getWorld().isUsingPlotManagementRevert() && (TownySettings.getPlotManagementSpeed() > 0)) { TownyRegenAPI.addWorldCoord(townBlock.getWorldCoord()); return TownBlockStatus.LOCKED; } townBlock.setLocked(false); } } catch (NotRegisteredException e) { // Unclaimed Zone switch rights return TownBlockStatus.UNCLAIMED_ZONE; } Resident resident; try { resident = TownyUniverse.getDataSource().getResident(player.getName()); } catch (TownyException e) { System.out.print("Failed to fetch resident: " + player.getName()); return TownBlockStatus.NOT_REGISTERED; } try { // War Time switch rights if (isWarTime()) { if (TownySettings.isAllowWarBlockGriefing()) { try { if (!resident.getTown().getNation().isNeutral() && !town.getNation().isNeutral()) return TownBlockStatus.WARZONE; } catch (NotRegisteredException e) { } } // If this town is not in a nation and we are set to non neutral status during war. if (!TownySettings.isWarTimeTownsNeutral() && !town.hasNation()) return TownBlockStatus.WARZONE; } // Town Owner Override try { if (townBlock.getTown().isMayor(resident) || townBlock.getTown().hasAssistant(resident)) return TownBlockStatus.TOWN_OWNER; } catch (NotRegisteredException e) { } // Resident Plot switch rights try { Resident owner = townBlock.getResident(); if (resident == owner) return TownBlockStatus.PLOT_OWNER; else if (owner.hasFriend(resident)) return TownBlockStatus.PLOT_FRIEND; else if (resident.hasTown() && isAlly(owner.getTown(), resident.getTown())) return TownBlockStatus.PLOT_ALLY; else // Exit out and use town permissions throw new TownyException(); } catch (NotRegisteredException x) { } catch (TownyException x) { } // Town resident destroy rights if (!resident.hasTown()) throw new TownyException(); if (resident.getTown() != town) { // Allied destroy rights if (isAlly(town, resident.getTown())) return TownBlockStatus.TOWN_ALLY; else if (isEnemy(resident.getTown(), town)) { if (townBlock.isWarZone()) return TownBlockStatus.WARZONE; else return TownBlockStatus.ENEMY; } else return TownBlockStatus.OUTSIDER; } else if (resident.isMayor() || resident.getTown().hasAssistant(resident)) return TownBlockStatus.TOWN_OWNER; else return TownBlockStatus.TOWN_RESIDENT; } catch (TownyException e) { // Outsider destroy rights return TownBlockStatus.OUTSIDER; } }