Search in sources :

Example 1 with WorldCoord

use of com.palmergames.bukkit.towny.object.WorldCoord in project Towny by ElgarL.

the class AreaSelectionUtil method selectWorldCoordAreaCircle.

public static List<WorldCoord> selectWorldCoordAreaCircle(TownBlockOwner owner, WorldCoord pos, String[] args) throws TownyException {
    List<WorldCoord> out = new ArrayList<WorldCoord>();
    if (pos.getTownyWorld().isClaimable()) {
        if (args.length > 0) {
            int r = 0, available = 0;
            if (owner instanceof Town) {
                Town town = (Town) owner;
                available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
            } else if (owner instanceof Resident) {
                available = TownySettings.getMaxResidentPlots((Resident) owner);
            }
            if (args[0].equalsIgnoreCase("auto")) {
                if (// Since: 0 - ceil(Pi * 0^2) >= 0 is a true statement.
                available > 0)
                    while (available - Math.ceil(Math.PI * r * r) >= 0) r += 1;
            } else {
                try {
                    r = Integer.parseInt(args[0]);
                } catch (NumberFormatException e) {
                    throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
                }
            }
            if (r > 1000)
                r = 1000;
            for (int z = -r; z <= r; z++) for (int x = -r; x <= r; x++) if ((x * x + z * z <= r * r) && (out.size() < available))
                out.add(new WorldCoord(pos.getWorldName(), pos.getX() + x, pos.getZ() + z));
        } else {
            throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
        }
    }
    return out;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 2 with WorldCoord

use of com.palmergames.bukkit.towny.object.WorldCoord in project Towny by ElgarL.

the class AreaSelectionUtil method selectWorldCoordAreaRect.

public static List<WorldCoord> selectWorldCoordAreaRect(TownBlockOwner owner, WorldCoord pos, String[] args) throws TownyException {
    List<WorldCoord> out = new ArrayList<WorldCoord>();
    if (pos.getTownyWorld().isClaimable()) {
        if (args.length > 0) {
            int r = 0, available = 1000;
            if (owner instanceof Town) {
                Town town = (Town) owner;
                available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
            } else if (owner instanceof Resident) {
                available = TownySettings.getMaxResidentPlots((Resident) owner);
            }
            if (args[0].equalsIgnoreCase("auto")) {
                while (available - Math.pow((r + 1) * 2 - 1, 2) >= 0) r += 1;
            } else {
                try {
                    r = Integer.parseInt(args[0]);
                } catch (NumberFormatException e) {
                    throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
                }
            }
            if (r > 1000)
                r = 1000;
            for (int z = -r; z <= r; z++) for (int x = -r; x <= r; x++) if (out.size() < available)
                out.add(new WorldCoord(pos.getWorldName(), pos.getX() + x, pos.getZ() + z));
        } else {
            throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
        }
    }
    return out;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 3 with WorldCoord

use of com.palmergames.bukkit.towny.object.WorldCoord in project Towny by ElgarL.

the class CombatUtil method isPvPPlot.

/**
 * Return true if both attacker and defender are in Arena Plots.
 *
 * @param attacker
 * @param defender
 * @return true if both players in an Arena plot.
 */
public static boolean isPvPPlot(Player attacker, Player defender) {
    if ((attacker != null) && (defender != null)) {
        TownBlock attackerTB, defenderTB;
        try {
            attackerTB = new WorldCoord(attacker.getWorld().getName(), Coord.parseCoord(attacker)).getTownBlock();
            defenderTB = new WorldCoord(defender.getWorld().getName(), Coord.parseCoord(defender)).getTownBlock();
            if (defenderTB.getType().equals(TownBlockType.ARENA) && attackerTB.getType().equals(TownBlockType.ARENA))
                return true;
        } catch (NotRegisteredException e) {
        // Not a Town owned Plot
        }
    }
    return false;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 4 with WorldCoord

use of com.palmergames.bukkit.towny.object.WorldCoord in project Towny by ElgarL.

the class TownyPlayerListener method onPlayerBedEnter.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
    if (!TownySettings.getBedUse())
        return;
    boolean isOwner = false;
    boolean isInnPlot = false;
    try {
        Resident resident = TownyUniverse.getDataSource().getResident(event.getPlayer().getName());
        WorldCoord worldCoord = new WorldCoord(event.getPlayer().getWorld().getName(), Coord.parseCoord(event.getBed().getLocation()));
        TownBlock townblock = worldCoord.getTownBlock();
        isOwner = townblock.isOwner(resident);
        isInnPlot = townblock.getType() == TownBlockType.INN;
        if (resident.hasNation() && townblock.getTown().hasNation()) {
            Nation residentNation = resident.getTown().getNation();
            Nation townblockNation = townblock.getTown().getNation();
            if (townblockNation.hasEnemy(residentNation)) {
                event.setCancelled(true);
                TownyMessaging.sendErrorMsg(event.getPlayer(), "You cannot sleep in an enemy's Inn.");
                return;
            }
        }
    } catch (NotRegisteredException e) {
    // Wilderness as it error'd getting a townblock.
    }
    if (!isOwner && !isInnPlot) {
        event.setCancelled(true);
        TownyMessaging.sendErrorMsg(event.getPlayer(), "You do not own the land this bed occupies and it is not an Inn plot.");
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) 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) EventHandler(org.bukkit.event.EventHandler)

Example 5 with WorldCoord

use of com.palmergames.bukkit.towny.object.WorldCoord in project Towny by ElgarL.

the class TownyPlayerListener method onPlayerMove.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    /*
		 * Abort if we havn't really moved
		 */
    if (event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockZ() == event.getTo().getBlockZ() && event.getFrom().getBlockY() == event.getTo().getBlockY()) {
        return;
    }
    Player player = event.getPlayer();
    Location to = event.getTo();
    Location from;
    PlayerCache cache = plugin.getCache(player);
    try {
        from = cache.getLastLocation();
    } catch (NullPointerException e) {
        from = event.getFrom();
    }
    // Prevent fly/double jump cheats
    if (!(event instanceof PlayerTeleportEvent)) {
        if (TownySettings.isUsingCheatProtection() && (player.getGameMode() != GameMode.CREATIVE) && !TownyUniverse.getPermissionSource().has(player, PermissionNodes.CHEAT_BYPASS.getNode())) {
            try {
                if (TownyUniverse.getDataSource().getWorld(player.getWorld().getName()).isUsingTowny())
                    if ((from.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) && (player.getFallDistance() == 0) && (player.getVelocity().getY() <= -0.6) && (player.getLocation().getY() > 0)) {
                        // plugin.sendErrorMsg(player, "Cheat Detected!");
                        Location blockLocation = from;
                        // find the first non air block below us
                        while ((blockLocation.getBlock().getType() == Material.AIR) && (blockLocation.getY() > 0)) blockLocation.setY(blockLocation.getY() - 1);
                        // set to 1 block up so we are not sunk in the
                        // ground
                        blockLocation.setY(blockLocation.getY() + 1);
                        // Update the cache for this location (same
                        // WorldCoord).
                        cache.setLastLocation(blockLocation);
                        player.teleport(blockLocation);
                        return;
                    }
            } catch (NotRegisteredException e1) {
                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
                return;
            }
        }
    }
    try {
        TownyWorld fromWorld = TownyUniverse.getDataSource().getWorld(from.getWorld().getName());
        WorldCoord fromCoord = new WorldCoord(fromWorld.getName(), Coord.parseCoord(from));
        TownyWorld toWorld = TownyUniverse.getDataSource().getWorld(to.getWorld().getName());
        WorldCoord toCoord = new WorldCoord(toWorld.getName(), Coord.parseCoord(to));
        if (!fromCoord.equals(toCoord))
            onPlayerMoveChunk(player, fromCoord, toCoord, from, to, event);
        else {
        // plugin.sendDebugMsg("    From: " + fromCoord);
        // plugin.sendDebugMsg("    To:   " + toCoord);
        // plugin.sendDebugMsg("        " + from.toString());
        // plugin.sendDebugMsg("        " + to.toString());
        }
    } catch (NotRegisteredException e) {
        TownyMessaging.sendErrorMsg(player, e.getMessage());
    }
    // Update the cached players current location
    cache.setLastLocation(to);
// plugin.updateCache(player);
// plugin.sendDebugMsg("onBlockMove: " + player.getName() + ": ");
// plugin.sendDebugMsg("        " + from.toString());
// plugin.sendDebugMsg("        " + to.toString());
}
Also used : Player(org.bukkit.entity.Player) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) PlayerCache(com.palmergames.bukkit.towny.object.PlayerCache) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) Location(org.bukkit.Location) BlockLocation(com.palmergames.bukkit.towny.regen.block.BlockLocation) EventHandler(org.bukkit.event.EventHandler)

Aggregations

WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)20 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)13 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)9 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)6 Resident (com.palmergames.bukkit.towny.object.Resident)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