Search in sources :

Example 6 with NotRegisteredException

use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.

the class PlayerCacheUtil method getTownBlockStatus.

/**
	 * Fetch the TownBlockStatus type for this player at this WorldCoord.
	 * 
	 * @param player
	 * @param worldCoord
	 * @return TownBlockStatus type.
	 */
public static TownBlockStatus getTownBlockStatus(Player player, WorldCoord worldCoord) {
    try {
        if (!worldCoord.getTownyWorld().isUsingTowny())
            return TownBlockStatus.OFF_WORLD;
    } catch (NotRegisteredException ex) {
        // Not a registered world
        return TownBlockStatus.NOT_REGISTERED;
    }
    //TownyUniverse universe = plugin.getTownyUniverse();
    TownBlock townBlock;
    Town town;
    try {
        townBlock = worldCoord.getTownBlock();
        town = townBlock.getTown();
        if (townBlock.isLocked()) {
            // Push the TownBlock location to the queue for a snapshot (if it's not already in the queue).
            if (town.getWorld().isUsingPlotManagementRevert() && (TownySettings.getPlotManagementSpeed() > 0)) {
                TownyRegenAPI.addWorldCoord(townBlock.getWorldCoord());
                return TownBlockStatus.LOCKED;
            }
            townBlock.setLocked(false);
        }
    } catch (NotRegisteredException e) {
        // Unclaimed Zone switch rights
        return TownBlockStatus.UNCLAIMED_ZONE;
    }
    /*
		 * Find the resident data for this player.
		 */
    Resident resident;
    try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
    } catch (TownyException e) {
        System.out.print("Failed to fetch resident: " + player.getName());
        return TownBlockStatus.NOT_REGISTERED;
    }
    try {
        // War Time switch rights
        if (TownyUniverse.isWarTime()) {
            if (TownySettings.isAllowWarBlockGriefing()) {
                try {
                    if (!resident.getTown().getNation().isNeutral() && !town.getNation().isNeutral())
                        return TownBlockStatus.WARZONE;
                } catch (NotRegisteredException e) {
                }
            }
            //If this town is not in a nation and we are set to non neutral status during war.
            if (!TownySettings.isWarTimeTownsNeutral() && !town.hasNation())
                return TownBlockStatus.WARZONE;
        }
        // Town Owner Override
        try {
            if (// || townBlock.getTown().hasAssistant(resident))
            townBlock.getTown().isMayor(resident))
                return TownBlockStatus.TOWN_OWNER;
        } catch (NotRegisteredException e) {
        }
        // Resident Plot rights
        try {
            Resident owner = townBlock.getResident();
            if (resident == owner)
                return TownBlockStatus.PLOT_OWNER;
            else if (owner.hasFriend(resident))
                return TownBlockStatus.PLOT_FRIEND;
            else if (resident.hasTown() && CombatUtil.isAlly(owner.getTown(), resident.getTown()))
                return TownBlockStatus.PLOT_ALLY;
            else
                // Exit out and use town permissions
                throw new TownyException();
        } catch (NotRegisteredException x) {
        } catch (TownyException x) {
        }
        // Resident with no town.
        if (!resident.hasTown()) {
            if (townBlock.isWarZone()) {
                if (!TownySettings.isWarTimeTownsNeutral())
                    return TownBlockStatus.WARZONE;
                else
                    return TownBlockStatus.OUTSIDER;
            }
            throw new TownyException();
        }
        if (resident.getTown() != town) {
            // Allied destroy rights
            if (CombatUtil.isAlly(town, resident.getTown()))
                return TownBlockStatus.TOWN_ALLY;
            else if (CombatUtil.isEnemy(resident.getTown(), town)) {
                if (townBlock.isWarZone())
                    return TownBlockStatus.WARZONE;
                else
                    return TownBlockStatus.ENEMY;
            } else
                return TownBlockStatus.OUTSIDER;
        } else if (// || resident.getTown().hasAssistant(resident))
        resident.isMayor())
            return TownBlockStatus.TOWN_OWNER;
        else
            return TownBlockStatus.TOWN_RESIDENT;
    } catch (TownyException e) {
        // Outsider destroy rights
        return TownBlockStatus.OUTSIDER;
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 7 with NotRegisteredException

use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.

the class War method remove.

public void remove(WorldCoord worldCoord) {
    try {
        Town town = worldCoord.getTownBlock().getTown();
        TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeLoseTownBlockMsg(worldCoord, town.getName()));
        warZone.remove(worldCoord);
    } catch (NotRegisteredException e) {
        TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeLoseTownBlockMsg(worldCoord));
        warZone.remove(worldCoord);
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town)

Example 8 with NotRegisteredException

use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.

the class TownyFlatFileSource method loadWorldList.

@Override
public boolean loadWorldList() {
    if (plugin != null) {
        TownyMessaging.sendDebugMsg("Loading Server World List");
        for (World world : plugin.getServer().getWorlds()) try {
            newWorld(world.getName());
        } catch (AlreadyRegisteredException e) {
        //e.printStackTrace();
        } catch (NotRegisteredException e) {
        //e.printStackTrace();
        }
    }
    // Can no longer reply on Bukkit to report ALL available worlds.
    TownyMessaging.sendDebugMsg("Loading World List");
    String line;
    BufferedReader fin = null;
    try {
        fin = new BufferedReader(new FileReader(rootFolder + dataFolder + FileMgmt.fileSeparator() + "worlds.txt"));
        while ((line = fin.readLine()) != null) if (!line.equals(""))
            newWorld(line);
        return true;
    } catch (AlreadyRegisteredException e) {
        // Ignore this as the world may have been passed to us by bukkit
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        if (fin != null) {
            try {
                fin.close();
            } catch (IOException ignore) {
            }
        }
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) World(org.bukkit.World) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) InvalidNameException(javax.naming.InvalidNameException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 9 with NotRegisteredException

use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.

the class TownyFlatFileSource method utilLoadTownBlocks.

/**
	 * Load townblocks according to the given line Townblock: x,y,forSale Eg:
	 * townBlocks=world:10,11;10,12,true;|nether:1,1|
	 * 
	 * @param line
	 * @param town
	 * @param resident
	 */
@Deprecated
public void utilLoadTownBlocks(String line, Town town, Resident resident) {
    String[] worlds = line.split("\\|");
    for (String w : worlds) {
        String[] split = w.split(":");
        if (split.length != 2) {
            TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " BlockList does not have a World or data.");
            continue;
        }
        try {
            TownyWorld world = getWorld(split[0]);
            for (String s : split[1].split(";")) {
                String blockTypeData = null;
                int indexOfType = s.indexOf("[");
                if (indexOfType != -1) {
                    //is found
                    int endIndexOfType = s.indexOf("]");
                    if (endIndexOfType != -1) {
                        blockTypeData = s.substring(indexOfType + 1, endIndexOfType);
                    }
                    s = s.substring(endIndexOfType + 1);
                }
                String[] tokens = s.split(",");
                if (tokens.length < 2)
                    continue;
                try {
                    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);
                    if (resident != null && townblock.hasTown())
                        townblock.setResident(resident);
                    if (blockTypeData != null) {
                        utilLoadTownBlockTypeData(townblock, blockTypeData);
                    }
                    //if present set the plot price
                    if (tokens.length >= 3) {
                        if (tokens[2] == "true")
                            townblock.setPlotPrice(town.getPlotPrice());
                        else
                            townblock.setPlotPrice(Double.parseDouble(tokens[2]));
                    }
                } catch (NumberFormatException e) {
                } catch (NotRegisteredException e) {
                }
            }
        } catch (NotRegisteredException e) {
            continue;
        }
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 10 with NotRegisteredException

use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.

the class TownySQLSource method loadTownBlocks.

@Override
public boolean loadTownBlocks() {
    String line = "";
    Boolean result = false;
    // Load town blocks
    if (!getContext())
        return false;
    ResultSet rs;
    for (TownBlock townBlock : getAllTownBlocks()) {
        try {
            Statement s = cntx.createStatement();
            rs = s.executeQuery("SELECT * FROM " + tb_prefix + "TOWNBLOCKS" + " WHERE world='" + townBlock.getWorld().getName() + "' AND x='" + townBlock.getX() + "' AND z='" + townBlock.getZ() + "'");
            while (rs.next()) {
                line = rs.getString("name");
                if (line != null)
                    try {
                        townBlock.setName(line.trim());
                    } catch (Exception e) {
                    }
                line = rs.getString("price");
                if (line != null)
                    try {
                        townBlock.setPlotPrice(Float.parseFloat(line.trim()));
                    } catch (Exception e) {
                    }
                line = rs.getString("town");
                if (line != null)
                    try {
                        Town town = getTown(line.trim());
                        townBlock.setTown(town);
                    } catch (Exception e) {
                    }
                line = rs.getString("resident");
                if (line != null && !line.isEmpty())
                    try {
                        Resident res = getResident(line.trim());
                        townBlock.setResident(res);
                    } catch (Exception e) {
                    }
                line = rs.getString("type");
                if (line != null)
                    try {
                        townBlock.setType(Integer.parseInt(line));
                    } catch (Exception e) {
                    }
                line = rs.getString("outpost");
                if (line != null)
                    try {
                        townBlock.setOutpost(Boolean.parseBoolean(line));
                    } catch (Exception e) {
                    }
                line = rs.getString("permissions");
                if ((line != null) && !line.isEmpty())
                    try {
                        townBlock.setPermissions(line.trim().replaceAll("#", ","));
                    //set = true;
                    } catch (Exception e) {
                    }
                result = rs.getBoolean("changed");
                if (result != null)
                    try {
                        townBlock.setChanged(result);
                    } catch (Exception e) {
                    }
                result = rs.getBoolean("locked");
                if (result != null)
                    try {
                        townBlock.setLocked(result);
                    } catch (Exception e) {
                    }
            }
            //				if (!set) {
            //					// no permissions found so set in relation to it's
            //					// owners perms.
            //					try {
            //						if (townBlock.hasResident()) {
            //							townBlock.setPermissions(townBlock.getResident().getPermissions().toString());
            //						} else {
            //							townBlock.setPermissions(townBlock.getTown().getPermissions().toString());
            //						}
            //					} catch (NotRegisteredException e) {
            //						// Will never reach here
            //					}
            //				}
            s.close();
        } catch (SQLException e) {
            TownyMessaging.sendErrorMsg("Loading Error: Exception while reading TownBlocks ");
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) 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)

Aggregations

NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)80 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)38 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)31 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)27 Resident (com.palmergames.bukkit.towny.object.Resident)24 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)19 Player (org.bukkit.entity.Player)18 Town (com.palmergames.bukkit.towny.object.Town)17 ArrayList (java.util.ArrayList)17 EventHandler (org.bukkit.event.EventHandler)17 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)14 Nation (com.palmergames.bukkit.towny.object.Nation)11 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)9 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)9 IOException (java.io.IOException)9 Location (org.bukkit.Location)9 Entity (org.bukkit.entity.Entity)9 LivingEntity (org.bukkit.entity.LivingEntity)8 Coord (com.palmergames.bukkit.towny.object.Coord)7 BlockLocation (com.palmergames.bukkit.towny.regen.block.BlockLocation)7