Search in sources :

Example 16 with WorldCoord

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));
    }
}
Also used : Player(org.bukkit.entity.Player) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) CellBorder(com.palmergames.bukkit.towny.object.CellBorder) ChunkNotification(com.palmergames.bukkit.towny.ChunkNotification) EventHandler(org.bukkit.event.EventHandler)

Example 17 with WorldCoord

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);
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord)

Example 18 with WorldCoord

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);
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Player(org.bukkit.entity.Player) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 19 with WorldCoord

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);
    }
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) PlayerCache(com.palmergames.bukkit.towny.object.PlayerCache) TownBlockStatus(com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus)

Aggregations

WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)19 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)12 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)8 Resident (com.palmergames.bukkit.towny.object.Resident)5 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)5 ArrayList (java.util.ArrayList)5 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)4 Player (org.bukkit.entity.Player)4 EventHandler (org.bukkit.event.EventHandler)4 TownBlockStatus (com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus)3 Town (com.palmergames.bukkit.towny.object.Town)3 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)3 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)2 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)2 CellBorder (com.palmergames.bukkit.towny.object.CellBorder)2 Nation (com.palmergames.bukkit.towny.object.Nation)2 EOFException (java.io.EOFException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InvalidNameException (javax.naming.InvalidNameException)2