Search in sources :

Example 21 with TownyWorld

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

the class HealthRegenTimerTask method run.

@Override
public void run() {
    if (TownyUniverse.isWarTime())
        return;
    for (Player player : server.getOnlinePlayers()) {
        if (player.getHealth() <= 0)
            continue;
        Coord coord = Coord.parseCoord(player);
        try {
            TownyWorld world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
            TownBlock townBlock = world.getTownBlock(coord);
            if (CombatUtil.isAlly(townBlock.getTown(), TownyUniverse.getDataSource().getResident(player.getName()).getTown()))
                if (// only regen if not in an arena
                !townBlock.getType().equals(TownBlockType.ARENA))
                    incHealth(player);
        } catch (TownyException x) {
        }
    }
//if (TownySettings.getDebug())
//	System.out.println("[Towny] Debug: Health Regen");
}
Also used : Coord(com.palmergames.bukkit.towny.object.Coord) Player(org.bukkit.entity.Player) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 22 with TownyWorld

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

the class TownyHModFlatFileSource method loadWorlds.

@Override
public boolean loadWorlds() {
    System.out.println("[Towny] [hMod Conversion] Town Blocks");
    String line;
    String[] tokens;
    //Default world is the first one loaded
    TownyWorld world = getWorlds().toArray(new TownyWorld[0])[0];
    try {
        BufferedReader fin = new BufferedReader(new FileReader(rootFolder + dataFolder + "/townblocks.csv"));
        while ((line = fin.readLine()) != null) {
            tokens = line.split(",");
            if (tokens.length >= 4)
                try {
                    Town town = getTown(tokens[2]);
                    int x = Integer.parseInt(tokens[0]);
                    int z = Integer.parseInt(tokens[1]);
                    try {
                        world.newTownBlock(x, z);
                    } catch (AlreadyRegisteredException e) {
                    }
                    TownBlock townblock = world.getTownBlock(x, z);
                    if (town != null)
                        townblock.setTown(town);
                    try {
                        townblock.setResident(getResident(tokens[3]));
                    } catch (NotRegisteredException e) {
                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (NotRegisteredException e) {
                    e.printStackTrace();
                }
        }
        fin.close();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Example 23 with TownyWorld

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

the class TownySQLSource method loadTownBlockList.

/*
	 * Load keys
	 */
@Override
public boolean loadTownBlockList() {
    TownyMessaging.sendDebugMsg("Loading TownBlock List");
    if (!getContext())
        return false;
    try {
        Statement s = cntx.createStatement();
        ResultSet rs = s.executeQuery("SELECT world,x,z FROM " + tb_prefix + "TOWNBLOCKS");
        while (rs.next()) {
            TownyWorld world = getWorld(rs.getString("world"));
            int x = Integer.parseInt(rs.getString("x"));
            int z = Integer.parseInt(rs.getString("z"));
            try {
                world.newTownBlock(x, z);
            } catch (AlreadyRegisteredException e) {
            }
        }
        s.close();
        return true;
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) ResultSet(java.sql.ResultSet) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) SQLException(java.sql.SQLException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 24 with TownyWorld

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

the class TownClaim method run.

@Override
public void run() {
    List<TownyWorld> worlds = new ArrayList<TownyWorld>();
    List<Town> towns = new ArrayList<Town>();
    TownyWorld world;
    if (player != null)
        TownyMessaging.sendMsg(player, "Processing " + ((claim) ? "Town Claim..." : "Town unclaim..."));
    if (selection != null) {
        for (WorldCoord worldCoord : selection) {
            try {
                world = worldCoord.getTownyWorld();
                if (!worlds.contains(world))
                    worlds.add(world);
                if (claim) {
                    // Claim
                    townClaim(town, worldCoord, outpost);
                    // Reset so we only flag the first plot as an outpost.
                    outpost = false;
                } else {
                    // Unclaim
                    this.town = worldCoord.getTownBlock().getTown();
                    townUnclaim(town, worldCoord, forced);
                }
                // Mark this town as modified for saving.
                if (!towns.contains(town))
                    towns.add(town);
            } catch (NotRegisteredException e) {
                // Invalid world
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_err_not_configured"));
            } catch (TownyException x) {
                TownyMessaging.sendErrorMsg(player, x.getMessage());
            }
        }
    } else if (!claim) {
        if (town == null) {
            TownyMessaging.sendMsg(player, "Nothing to unclaim!");
            return;
        }
        townUnclaimAll(town);
    }
    if (!towns.isEmpty())
        for (Town test : towns) TownyUniverse.getDataSource().saveTown(test);
    if (!worlds.isEmpty())
        for (TownyWorld test : worlds) TownyUniverse.getDataSource().saveWorld(test);
    plugin.resetCache();
    if (player != null) {
        if (claim) {
            TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_annexed_area"), (selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
            if (town.getWorld().isUsingPlotManagementRevert())
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_wait_locked"));
        } else if (forced) {
            TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_admin_unclaim_area"), (selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0]))));
            if ((town != null) && (town.getWorld().isUsingPlotManagementRevert()))
                TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_wait_locked"));
        }
    }
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 25 with TownyWorld

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

the class TownyBlockListener method onBurn.

private boolean onBurn(Block block) {
    Location loc = block.getLocation();
    Coord coord = Coord.parseCoord(loc);
    TownyWorld townyWorld;
    try {
        townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
        if (!townyWorld.isUsingTowny())
            return false;
        try {
            if (townyWorld.isWarZone(coord)) {
                if (TownyWarConfig.isAllowingFireInWarZone()) {
                    return false;
                } else {
                    TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getType().name() + " from igniting within " + coord.toString() + ".");
                    return true;
                }
            }
            TownBlock townBlock = townyWorld.getTownBlock(coord);
            if ((block.getRelative(BlockFace.DOWN).getType() != Material.OBSIDIAN) && ((!townBlock.getTown().isFire() && !townyWorld.isForceFire() && !townBlock.getPermissions().fire) || (TownyUniverse.isWarTime() && TownySettings.isAllowWarBlockGriefing() && !townBlock.getTown().hasNation()))) {
                TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getType().name() + " from igniting within " + coord.toString() + ".");
                return true;
            }
        } catch (TownyException x) {
            // Not a town so check the world setting for fire
            if (!townyWorld.isFire()) {
                TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getType().name() + " from igniting within " + coord.toString() + ".");
                return true;
            }
        }
    } catch (NotRegisteredException e) {
    // Failed to fetch the world
    }
    return false;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Coord(com.palmergames.bukkit.towny.object.Coord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) Location(org.bukkit.Location) BlockLocation(com.palmergames.bukkit.towny.regen.block.BlockLocation) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)33 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)27 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)15 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)14 EventHandler (org.bukkit.event.EventHandler)12 Player (org.bukkit.entity.Player)11 Entity (org.bukkit.entity.Entity)9 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)7 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)7 BlockLocation (com.palmergames.bukkit.towny.regen.block.BlockLocation)7 Location (org.bukkit.Location)7 LivingEntity (org.bukkit.entity.LivingEntity)7 Coord (com.palmergames.bukkit.towny.object.Coord)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Resident (com.palmergames.bukkit.towny.object.Resident)5 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)5 Block (org.bukkit.block.Block)5 Town (com.palmergames.bukkit.towny.object.Town)3 Projectile (org.bukkit.entity.Projectile)3