use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyCommand method parseTownyCommand.
private void parseTownyCommand(Player player, String[] split) {
if (split.length == 0) {
for (String line : towny_general_help) player.sendMessage(line);
return;
} else if (split[0].equalsIgnoreCase("?") || split[0].equalsIgnoreCase("help")) {
for (String line : towny_help) player.sendMessage(Colors.strip(line));
return;
}
try {
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY.getNode(split[0].toLowerCase())))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split[0].equalsIgnoreCase("map"))
if (split.length > 1 && split[1].equalsIgnoreCase("big"))
TownyAsciiMap.generateAndSend(plugin, player, 18);
else
showMap(player);
else if (split[0].equalsIgnoreCase("prices")) {
Town town = null;
if (split.length > 1) {
try {
town = TownyUniverse.getDataSource().getTown(split[1]);
} catch (NotRegisteredException x) {
sendErrorMsg(player, x.getMessage());
return;
}
} else if (split.length == 1)
try {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
town = resident.getTown();
} catch (NotRegisteredException x) {
}
for (String line : getTownyPrices(town)) player.sendMessage(line);
} else if (split[0].equalsIgnoreCase("top")) {
TopCommand(player, StringMgmt.remFirstArg(split));
} else if (split[0].equalsIgnoreCase("tree")) {
consoleUseOnly(player);
} else if (split[0].equalsIgnoreCase("time")) {
TownyMessaging.sendMsg(player, "Time until a New Day: " + TimeMgmt.formatCountdownTime(TownyTimerHandler.townyTime()));
} else if (split[0].equalsIgnoreCase("universe")) {
for (String line : getUniverseStats()) player.sendMessage(line);
} else if (split[0].equalsIgnoreCase("version") || split[0].equalsIgnoreCase("v")) {
player.sendMessage(towny_version);
} else if (split[0].equalsIgnoreCase("war")) {
boolean war = TownyWar(StringMgmt.remFirstArg(split));
for (String line : towny_war) player.sendMessage(Colors.strip(line));
if (!war)
sendErrorMsg(player, "The world isn't currently at war.");
towny_war.clear();
} else if (split[0].equalsIgnoreCase("spy")) {
if (plugin.isPermissions() && TownyUniverse.getPermissionSource().has(player, PermissionNodes.TOWNY_CHAT_SPY.getNode())) {
if (plugin.hasPlayerMode(player, "spy"))
plugin.removePlayerMode(player);
else
plugin.setPlayerMode(player, split, true);
} else
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_command_disable"));
} else
sendErrorMsg(player, "Invalid sub command.");
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyRegenAPI method doDeleteTownBlockIds.
/**
* Deletes all of a specified block type from a TownBlock
*
* @param worldCoord
*/
public static void doDeleteTownBlockIds(WorldCoord worldCoord) {
//Block block = null;
World world = null;
int plotSize = TownySettings.getTownBlockSize();
TownyMessaging.sendDebugMsg("Processing deleteTownBlockIds");
world = worldCoord.getBukkitWorld();
if (world != null) {
/*
* if
* (!world.isChunkLoaded(MinecraftTools.calcChunk(townBlock.getX()),
* MinecraftTools.calcChunk(townBlock.getZ())))
* return;
*/
int height = world.getMaxHeight() - 1;
int worldx = worldCoord.getX() * plotSize, worldz = worldCoord.getZ() * plotSize;
for (int z = 0; z < plotSize; z++) for (int x = 0; x < plotSize; x++) for (int y = height; y > 0; y--) {
//Check from bottom up else minecraft won't remove doors
Block block = world.getBlockAt(worldx + x, y, worldz + z);
try {
if (worldCoord.getTownyWorld().isPlotManagementDeleteIds(block.getType().name())) {
block.setType(Material.AIR);
}
} catch (NotRegisteredException e) {
// Not a registered world
}
block = null;
}
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class DailyTimerTask method collectNationTaxes.
/**
* Collect taxes due to the nation from it's member towns.
*
* @param nation
* @throws EconomyException
*/
protected void collectNationTaxes(Nation nation) throws EconomyException {
if (nation.getTaxes() > 0) {
List<Town> towns = new ArrayList<Town>(nation.getTowns());
ListIterator<Town> townItr = towns.listIterator();
Town town = null;
while (townItr.hasNext()) {
town = townItr.next();
/*
* Only collect nation tax from this town if it really still
* exists.
* We are running in an Async thread so MUST verify all objects.
*/
if (TownyUniverse.getDataSource().hasTown(town.getName())) {
if (town.isCapital() || !town.hasUpkeep())
continue;
if (!town.payTo(nation.getTaxes(), nation, "Nation Tax")) {
try {
TownyMessaging.sendNationMessage(nation, TownySettings.getCouldntPayTaxesMsg(town, "nation"));
nation.removeTown(town);
} catch (EmptyNationException e) {
// Always has 1 town (capital) so ignore
} catch (NotRegisteredException e) {
}
TownyUniverse.getDataSource().saveTown(town);
TownyUniverse.getDataSource().saveNation(nation);
}
} else
TownyMessaging.sendTownMessage(town, TownySettings.getPayedTownTaxMsg() + nation.getTaxes());
}
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class MobRemovalTimerTask method run.
@Override
public void run() {
// Build a list of mobs to be removed
List<LivingEntity> livingEntitiesToRemove = new ArrayList<LivingEntity>();
for (World world : server.getWorlds()) {
TownyWorld townyWorld;
// Filter worlds not registered
try {
townyWorld = TownyUniverse.getDataSource().getWorld(world.getName());
} catch (NotRegisteredException e) {
// World was not registered by Towny, so we skip all mobs in it.
continue;
} catch (NullPointerException ex) {
// Spigot has unloaded this world.
continue;
}
// Filter worlds not using towny.
if (!townyWorld.isUsingTowny())
continue;
// Filter worlds that will always pass all checks in a world, regardless of possible conditions.
if (townyWorld.isForceTownMobs() && townyWorld.hasWorldMobs())
continue;
//
for (LivingEntity livingEntity : world.getLivingEntities()) {
Location livingEntityLoc = livingEntity.getLocation();
if (!livingEntityLoc.getChunk().isLoaded())
continue;
Coord coord = Coord.parseCoord(livingEntityLoc);
try {
TownBlock townBlock = townyWorld.getTownBlock(coord);
// Check if mobs are always allowed inside towns in this world.
if (townyWorld.isForceTownMobs())
continue;
// Check if plot allows mobs.
if (townBlock.getPermissions().mobs)
continue;
// Check if the plot is registered to a town.
Town town = townBlock.getTown();
// Check if the town this plot is registered to allows mobs.
if (town.hasMobs())
continue;
// Check that Towny is removing this type of entity inside towns.
if (!isRemovingTownEntity(livingEntity))
continue;
} catch (NotRegisteredException x) {
// Check if we're allowing mobs in unregistered plots in this world.
if (townyWorld.hasWorldMobs())
continue;
// Check that Towny is removing this type of entity in unregistered plots.
if (!isRemovingWorldEntity(livingEntity))
continue;
}
// Check if entity is a Citizens NPC
if (plugin.isCitizens2()) {
if (CitizensAPI.getNPCRegistry().isNPC(livingEntity))
continue;
}
livingEntitiesToRemove.add(livingEntity);
}
}
MobRemovalEvent mobRemovalEvent;
for (LivingEntity livingEntity : livingEntitiesToRemove) {
mobRemovalEvent = new MobRemovalEvent(livingEntity);
plugin.getServer().getPluginManager().callEvent(mobRemovalEvent);
if (!mobRemovalEvent.isCancelled()) {
TownyMessaging.sendDebugMsg("MobRemoval Removed: " + livingEntity.toString());
livingEntity.remove();
}
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class OnPlayerLogin method run.
@Override
public void run() {
Resident resident = null;
if (!TownyUniverse.getDataSource().hasResident(player.getName())) {
/*
* No record of this resident exists
* So create a fresh set of data.
*/
try {
TownyUniverse.getDataSource().newResident(player.getName());
resident = TownyUniverse.getDataSource().getResident(player.getName());
TownyMessaging.sendMessage(player, TownySettings.getRegistrationMsg(player.getName()));
resident.setRegistered(System.currentTimeMillis());
if (!TownySettings.getDefaultTownName().equals(""))
try {
Town town = TownyUniverse.getDataSource().getTown(TownySettings.getDefaultTownName());
town.addResident(resident);
TownyUniverse.getDataSource().saveTown(town);
} catch (NotRegisteredException ex) {
} catch (AlreadyRegisteredException ex) {
}
TownyUniverse.getDataSource().saveResident(resident);
TownyUniverse.getDataSource().saveResidentList();
} catch (AlreadyRegisteredException ex) {
// Should never happen
} catch (NotRegisteredException ex) {
// Should never happen
}
} else {
/*
* This resident is known so fetch the data and update it.
*/
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
resident.setLastOnline(System.currentTimeMillis());
TownyUniverse.getDataSource().saveResident(resident);
} catch (NotRegisteredException ex) {
// Should never happen
}
}
if (resident != null)
TownyPerms.assignPermissions(resident, player);
try {
TownyMessaging.sendTownBoard(player, resident.getTown());
} catch (NotRegisteredException ex) {
}
if (TownyUniverse.isWarTime())
universe.getWarEvent().sendScores(player, 3);
//Schedule to setup default modes when the player has finished loading
if (BukkitTools.scheduleSyncDelayedTask(new SetDefaultModes(player.getName(), false), 1) == -1)
TownyMessaging.sendErrorMsg("Could not set default modes for " + player.getName() + ".");
// Send any warning messages at login.
warningMessage(resident);
universe.setChangedNotify(PLAYER_LOGIN);
}
Aggregations