use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyFlatFileSource method loadTownBlockList.
/*
* Load keys
*/
@Override
public boolean loadTownBlockList() {
TownyMessaging.sendDebugMsg("Loading TownBlock List");
String line;
BufferedReader fin = null;
try {
fin = new BufferedReader(new FileReader(rootFolder + dataFolder + FileMgmt.fileSeparator() + "townblocks.txt"));
while ((line = fin.readLine()) != null) if (!line.equals("")) {
String[] tokens = line.split(",");
if (tokens.length < 3)
continue;
TownyWorld world;
try {
world = getWorld(tokens[0]);
} catch (NotRegisteredException ex) {
/*
* The world is not listed.
* Allow the creation of new worlds here to account
* for mod worlds which are not reported at startup.
*/
newWorld(tokens[0]);
world = getWorld(tokens[0]);
}
int x = Integer.parseInt(tokens[1]);
int z = Integer.parseInt(tokens[2]);
try {
world.newTownBlock(x, z);
} catch (AlreadyRegisteredException e) {
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (fin != null) {
try {
fin.close();
} catch (IOException ignore) {
}
}
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyCustomListener method onPlayerChangePlotEvent.
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerChangePlotEvent(PlayerChangePlotEvent event) {
Player player = event.getPlayer();
WorldCoord from = event.getFrom();
WorldCoord to = event.getTo();
// TODO: Player mode
if (plugin.hasPlayerMode(player, "townclaim"))
TownCommand.parseTownClaimCommand(player, new String[] {});
if (plugin.hasPlayerMode(player, "townunclaim"))
TownCommand.parseTownUnclaimCommand(player, new String[] {});
if (plugin.hasPlayerMode(player, "map"))
TownyCommand.showMap(player);
// Check if player has entered a new town/wilderness
try {
if (to.getTownyWorld().isUsingTowny() && TownySettings.getShowTownNotifications()) {
ChunkNotification chunkNotifier = new ChunkNotification(from, to);
String msg = chunkNotifier.getNotificationString();
if (msg != null)
player.sendMessage(msg);
}
} catch (NotRegisteredException e) {
e.printStackTrace();
}
if (plugin.hasPlayerMode(player, "plotborder")) {
CellBorder cellBorder = BorderUtil.getPlotBorder(to);
cellBorder.runBorderedOnSurface(1, 2, DrawSmokeTaskFactory.sendToPlayer(player));
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyEntityListener method onHangingPlace.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingPlace(HangingPlaceEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
long start = System.currentTimeMillis();
Player player = event.getPlayer();
Entity hanging = event.getEntity();
try {
TownyWorld townyWorld = TownyUniverse.getDataSource().getWorld(hanging.getWorld().getName());
if (!townyWorld.isUsingTowny())
return;
// Get build permissions (updates if none exist)
boolean bBuild = PlayerCacheUtil.getCachePermission(player, hanging.getLocation(), 321, (byte) 0, TownyPermission.ActionType.BUILD);
// Allow placing if we are permitted
if (bBuild)
return;
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
event.setCancelled(true);
if (cache.hasBlockErrMsg())
TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
} catch (NotRegisteredException e1) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
event.setCancelled(true);
return;
}
TownyMessaging.sendDebugMsg("onHangingBreak took " + (System.currentTimeMillis() - start) + "ms (" + event.getEventName() + ", " + event.isCancelled() + ")");
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyEntityListener method onHangingBreak.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
TownyWorld townyWorld = null;
String worldName = null;
Entity hanging = event.getEntity();
try {
worldName = hanging.getWorld().getName();
townyWorld = TownyUniverse.getDataSource().getWorld(worldName);
if (!townyWorld.isUsingTowny())
return;
} catch (NotRegisteredException e1) {
// event.setCancelled(true);
return;
}
if (event instanceof HangingBreakByEntityEvent) {
HangingBreakByEntityEvent evt = (HangingBreakByEntityEvent) event;
Object remover = evt.getRemover();
/*
* Check if this has a shooter.
*/
if (remover instanceof Projectile) {
remover = ((Projectile) remover).getShooter();
}
if (remover instanceof Player) {
Player player = (Player) remover;
// Get destroy permissions (updates if none exist)
boolean bDestroy = PlayerCacheUtil.getCachePermission(player, hanging.getLocation(), 321, (byte) 0, TownyPermission.ActionType.DESTROY);
// Allow the removal if we are permitted
if (bDestroy)
return;
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
event.setCancelled(true);
if (cache.hasBlockErrMsg())
TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
} else {
// Explosions are blocked in this plot
if (!locationCanExplode(townyWorld, hanging.getLocation()))
event.setCancelled(true);
}
} else {
switch(event.getCause()) {
case EXPLOSION:
if (!locationCanExplode(townyWorld, event.getEntity().getLocation()))
event.setCancelled(true);
break;
default:
}
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyEntityListener method onEntityDeath.
/**
* Prevent monsters from dropping blocks if within an arena plot.
*
* @param event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
if (plugin.isError()) {
return;
}
Entity entity = event.getEntity();
if (entity instanceof Monster) {
Location loc = entity.getLocation();
TownyWorld townyWorld = null;
try {
townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
// remove drops from monster deaths if in an arena plot
if (townyWorld.isUsingTowny()) {
if (townyWorld.getTownBlock(Coord.parseCoord(loc)).getType() == TownBlockType.ARENA)
event.getDrops().clear();
}
} catch (NotRegisteredException e) {
// Unknown world or not in a town
}
}
}
Aggregations