use of com.palmergames.bukkit.towny.object.TownyWorld 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.object.TownyWorld in project Towny by ElgarL.
the class TownyFlatFileSource method utilSaveTownBlocks.
@Deprecated
public String utilSaveTownBlocks(List<TownBlock> townBlocks) {
HashMap<TownyWorld, ArrayList<TownBlock>> worlds = new HashMap<TownyWorld, ArrayList<TownBlock>>();
String out = "";
// Sort all town blocks according to what world its in
for (TownBlock townBlock : townBlocks) {
TownyWorld world = townBlock.getWorld();
if (!worlds.containsKey(world))
worlds.put(world, new ArrayList<TownBlock>());
worlds.get(world).add(townBlock);
}
for (TownyWorld world : worlds.keySet()) {
out += world.getName() + ":";
for (TownBlock townBlock : worlds.get(world)) {
out += "[" + townBlock.getType().getId();
out += "," + (townBlock.isOutpost() ? "1" : "0");
out += "]" + townBlock.getX() + "," + townBlock.getZ() + "," + townBlock.getPlotPrice() + ";";
}
out += "|";
}
return out;
}
use of com.palmergames.bukkit.towny.object.TownyWorld 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.object.TownyWorld 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.object.TownyWorld 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