use of com.palmergames.bukkit.towny.object.WorldCoord 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.object.WorldCoord in project Towny by ElgarL.
the class War method damage.
public void damage(Town attacker, TownBlock townBlock) throws NotRegisteredException {
WorldCoord worldCoord = townBlock.getWorldCoord();
int hp = warZone.get(worldCoord) - 1;
if (hp > 0) {
warZone.put(worldCoord, hp);
//if (hp % 10 == 0) {
TownyMessaging.sendMessageToMode(townBlock.getTown(), Colors.Gray + "[" + townBlock.getTown().getName() + "](" + townBlock.getCoord().toString() + ") HP: " + hp, "");
TownyMessaging.sendMessageToMode(attacker, Colors.Gray + "[" + townBlock.getTown().getName() + "](" + townBlock.getCoord().toString() + ") HP: " + hp, "");
//}
} else
remove(attacker, townBlock);
}
use of com.palmergames.bukkit.towny.object.WorldCoord in project Towny by ElgarL.
the class WarTimerTask method run.
@Override
public void run() {
//TODO: check if war has ended and end gracefully
if (!warEvent.isWarTime()) {
warEvent.end();
universe.clearWarEvent();
plugin.resetCache();
TownyMessaging.sendDebugMsg("War ended.");
return;
}
int numPlayers = 0;
for (Player player : BukkitTools.getOnlinePlayers()) {
if (player != null) {
numPlayers += 1;
TownyMessaging.sendDebugMsg("[War] " + player.getName() + ": ");
try {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
if (resident.hasNation()) {
Nation nation = resident.getTown().getNation();
TownyMessaging.sendDebugMsg("[War] hasNation");
if (nation.isNeutral()) {
if (warEvent.isWarringNation(nation))
warEvent.nationLeave(nation);
continue;
}
TownyMessaging.sendDebugMsg("[War] notNeutral");
if (!warEvent.isWarringNation(nation))
continue;
TownyMessaging.sendDebugMsg("[War] warringNation");
//TODO: Cache player coord & townblock
WorldCoord worldCoord = new WorldCoord(player.getWorld().getName(), Coord.parseCoord(player));
if (!warEvent.isWarZone(worldCoord))
continue;
TownyMessaging.sendDebugMsg("[War] warZone");
if (player.getLocation().getBlockY() < TownySettings.getMinWarHeight())
continue;
TownyMessaging.sendDebugMsg("[War] aboveMinHeight");
//universe.getWorld(player.getWorld().getName()).getTownBlock(worldCoord);
TownBlock townBlock = worldCoord.getTownBlock();
if (nation == townBlock.getTown().getNation() || townBlock.getTown().getNation().hasAlly(nation))
continue;
TownyMessaging.sendDebugMsg("[War] notAlly");
//Enemy nation
warEvent.damage(resident.getTown(), townBlock);
TownyMessaging.sendDebugMsg("[War] damaged");
}
} catch (NotRegisteredException e) {
continue;
}
}
}
TownyMessaging.sendDebugMsg("[War] # Players: " + numPlayers);
}
use of com.palmergames.bukkit.towny.object.WorldCoord in project Towny by ElgarL.
the class PlayerCacheUtil method getCachePermission.
/**
* Returns player cached permission for BUILD, DESTROY, SWITCH or ITEM_USE
* at this location for the specified item id.
*
* Generates the cache if it doesn't exist.
*
* @param player
* @param location
* @param blockId
* @param data
* @param action
* @return true if the player has permission.
*/
public static boolean getCachePermission(Player player, Location location, Integer blockId, byte data, ActionType action) {
WorldCoord worldCoord;
try {
worldCoord = new WorldCoord(player.getWorld().getName(), Coord.parseCoord(location));
PlayerCache cache = plugin.getCache(player);
cache.updateCoord(worldCoord);
TownyMessaging.sendDebugMsg("Cache permissions for " + action.toString() + " : " + cache.getCachePermission(blockId, data, action));
// Throws NullPointerException if the cache is empty
return cache.getCachePermission(blockId, data, action);
} catch (NullPointerException e) {
// New or old cache permission was null, update it
worldCoord = new WorldCoord(player.getWorld().getName(), Coord.parseCoord(location));
TownBlockStatus status = cacheStatus(player, worldCoord, getTownBlockStatus(player, worldCoord));
triggerCacheCreate(player, location, worldCoord, status, blockId, data, action);
PlayerCache cache = plugin.getCache(player);
cache.updateCoord(worldCoord);
TownyMessaging.sendDebugMsg("New Cache Created and updated!");
TownyMessaging.sendDebugMsg("New Cache permissions for " + blockId + ":" + action.toString() + ":" + status.name() + " = " + cache.getCachePermission(blockId, data, action));
return cache.getCachePermission(blockId, data, action);
}
}
Aggregations