Search in sources :

Example 11 with NotRegisteredException

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

the class TownySQLSource method loadTown.

@SuppressWarnings("deprecation")
@Override
public boolean loadTown(Town town) {
    String line;
    String[] tokens;
    TownyMessaging.sendDebugMsg("Loading town " + town.getName());
    if (!getContext())
        return false;
    try {
        Statement s = cntx.createStatement();
        ResultSet rs = s.executeQuery("SELECT * FROM " + tb_prefix + "TOWNS " + " WHERE name='" + town.getName() + "'");
        String search;
        while (rs.next()) {
            line = rs.getString("residents");
            if (line != null) {
                search = (line.contains("#")) ? "#" : ",";
                tokens = line.split(search);
                for (String token : tokens) {
                    if (!token.isEmpty()) {
                        Resident resident = getResident(token);
                        if (resident != null)
                            town.addResident(resident);
                    }
                }
            }
            town.setMayor(getResident(rs.getString("mayor")));
            // line = rs.getString("assistants");
            // if (line != null) {
            // tokens = line.split(",");
            // for (String token : tokens) {
            // if (!token.isEmpty()) {
            // Resident assistant = getResident(token);
            // if ((assistant != null) && (town.hasResident(assistant)))
            // town.addAssistant(assistant);
            // }
            // }
            // }
            town.setTownBoard(rs.getString("townBoard"));
            line = rs.getString("tag");
            if (line != null)
                try {
                    town.setTag(line);
                } catch (TownyException e) {
                    town.setTag("");
                }
            town.setPermissions(rs.getString("protectionStatus").replaceAll("#", ","));
            town.setBonusBlocks(rs.getInt("bonus"));
            town.setTaxPercentage(rs.getBoolean("taxpercent"));
            town.setTaxes(rs.getFloat("taxes"));
            town.setHasUpkeep(rs.getBoolean("hasUpkeep"));
            town.setPlotPrice(rs.getFloat("plotPrice"));
            town.setPlotTax(rs.getFloat("plotTax"));
            town.setEmbassyPlotPrice(rs.getFloat("embassyPlotPrice"));
            town.setEmbassyPlotTax(rs.getFloat("embassyPlotTax"));
            town.setCommercialPlotPrice(rs.getFloat("commercialPlotPrice"));
            town.setCommercialPlotTax(rs.getFloat("commercialPlotTax"));
            town.setOpen(rs.getBoolean("open"));
            town.setPublic(rs.getBoolean("public"));
            town.setAdminDisabledPVP(rs.getBoolean("admindisabledpvp"));
            town.setPurchasedBlocks(rs.getInt("purchased"));
            line = rs.getString("homeBlock");
            if (line != null) {
                search = (line.contains("#")) ? "#" : ",";
                tokens = line.split(search);
                if (tokens.length == 3)
                    try {
                        TownyWorld world = getWorld(tokens[0]);
                        try {
                            int x = Integer.parseInt(tokens[1]);
                            int z = Integer.parseInt(tokens[2]);
                            TownBlock homeBlock = world.getTownBlock(x, z);
                            town.forceSetHomeBlock(homeBlock);
                        } catch (NumberFormatException e) {
                            TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " homeBlock tried to load invalid location.");
                        } catch (NotRegisteredException e) {
                            TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " homeBlock tried to load invalid TownBlock.");
                        } catch (TownyException e) {
                            TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " does not have a home block.");
                        }
                    } catch (NotRegisteredException e) {
                        TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " homeBlock tried to load invalid world.");
                    }
            }
            line = rs.getString("spawn");
            if (line != null) {
                search = (line.contains("#")) ? "#" : ",";
                tokens = line.split(search);
                if (tokens.length >= 4)
                    try {
                        World world = plugin.getServerWorld(tokens[0]);
                        double x = Double.parseDouble(tokens[1]);
                        double y = Double.parseDouble(tokens[2]);
                        double z = Double.parseDouble(tokens[3]);
                        Location loc = new Location(world, x, y, z);
                        if (tokens.length == 6) {
                            loc.setPitch(Float.parseFloat(tokens[4]));
                            loc.setYaw(Float.parseFloat(tokens[5]));
                        }
                        town.forceSetSpawn(loc);
                    } catch (NumberFormatException e) {
                    } catch (NotRegisteredException e) {
                    } catch (NullPointerException e) {
                    }
                // Load outpost spawns
                line = rs.getString("outpostSpawns");
                if (line != null) {
                    String[] outposts = line.split(";");
                    for (String spawn : outposts) {
                        search = (line.contains("#")) ? "#" : ",";
                        tokens = spawn.split(search);
                        if (tokens.length >= 4)
                            try {
                                World world = plugin.getServerWorld(tokens[0]);
                                double x = Double.parseDouble(tokens[1]);
                                double y = Double.parseDouble(tokens[2]);
                                double z = Double.parseDouble(tokens[3]);
                                Location loc = new Location(world, x, y, z);
                                if (tokens.length == 6) {
                                    loc.setPitch(Float.parseFloat(tokens[4]));
                                    loc.setYaw(Float.parseFloat(tokens[5]));
                                }
                                town.forceAddOutpostSpawn(loc);
                            } catch (NumberFormatException e) {
                            } catch (NotRegisteredException e) {
                            } catch (NullPointerException e) {
                            }
                    }
                }
            }
            /*
				 * Attempt these for older databases.
				 */
            try {
                line = rs.getString("townBlocks");
                if (line != null)
                    utilLoadTownBlocks(line, town, null);
            } catch (SQLException e) {
            }
            s.close();
            return true;
        }
        s.close();
        return false;
    } catch (SQLException e) {
        TownyMessaging.sendErrorMsg("SQL: Load Town sql Error - " + e.getMessage());
    } catch (Exception e) {
        TownyMessaging.sendErrorMsg("SQL: Load Town unknown Error - ");
        e.printStackTrace();
    }
    return false;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) World(org.bukkit.World) 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) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) ResultSet(java.sql.ResultSet) Resident(com.palmergames.bukkit.towny.object.Resident) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) Location(org.bukkit.Location)

Example 12 with NotRegisteredException

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

the class TownyFlatFileSource method loadTown.

@Override
public boolean loadTown(Town town) {
    String line;
    String[] tokens;
    String path = getTownFilename(town);
    File fileTown = new File(path);
    if (fileTown.exists() && fileTown.isFile()) {
        try {
            KeyValueFile kvFile = new KeyValueFile(path);
            line = kvFile.get("residents");
            if (line != null) {
                tokens = line.split(",");
                for (String token : tokens) {
                    if (!token.isEmpty()) {
                        TownyMessaging.sendDebugMsg("Town Fetching Resident: " + token);
                        Resident resident = getResident(token);
                        if (resident != null) {
                            try {
                                town.addResident(resident);
                            } catch (AlreadyRegisteredException e) {
                                TownyMessaging.sendErrorMsg("Loading Error: " + resident.getName() + " is already a member of a town (" + resident.getTown().getName() + ").");
                            }
                        }
                    }
                }
            }
            line = kvFile.get("mayor");
            if (line != null)
                town.setMayor(getResident(line));
            //				line = kvFile.get("assistants");
            //				if (line != null) {
            //					tokens = line.split(",");
            //					for (String token : tokens) {
            //						if (!token.isEmpty()) {
            //							Resident assistant = getResident(token);
            //							if ((assistant != null) && (town.hasResident(assistant)))
            //								town.addAssistant(assistant);
            //						}
            //					}
            //				}
            town.setTownBoard(kvFile.get("townBoard"));
            line = kvFile.get("tag");
            if (line != null)
                try {
                    town.setTag(line);
                } catch (TownyException e) {
                    town.setTag("");
                }
            line = kvFile.get("protectionStatus");
            if (line != null)
                town.setPermissions(line);
            line = kvFile.get("bonusBlocks");
            if (line != null)
                try {
                    town.setBonusBlocks(Integer.parseInt(line));
                } catch (Exception e) {
                    town.setBonusBlocks(0);
                }
            line = kvFile.get("purchasedBlocks");
            if (line != null)
                try {
                    town.setPurchasedBlocks(Integer.parseInt(line));
                } catch (Exception e) {
                    town.setPurchasedBlocks(0);
                }
            line = kvFile.get("plotPrice");
            if (line != null)
                try {
                    town.setPlotPrice(Double.parseDouble(line));
                } catch (Exception e) {
                    town.setPlotPrice(0);
                }
            line = kvFile.get("hasUpkeep");
            if (line != null)
                try {
                    town.setHasUpkeep(Boolean.parseBoolean(line));
                } catch (NumberFormatException nfe) {
                } catch (Exception e) {
                }
            line = kvFile.get("taxpercent");
            if (line != null)
                try {
                    town.setTaxPercentage(Boolean.parseBoolean(line));
                } catch (NumberFormatException nfe) {
                } catch (Exception e) {
                }
            line = kvFile.get("taxes");
            if (line != null)
                try {
                    town.setTaxes(Double.parseDouble(line));
                } catch (Exception e) {
                    town.setTaxes(0);
                }
            line = kvFile.get("plotTax");
            if (line != null)
                try {
                    town.setPlotTax(Double.parseDouble(line));
                } catch (Exception e) {
                    town.setPlotTax(0);
                }
            line = kvFile.get("commercialPlotPrice");
            if (line != null)
                try {
                    town.setCommercialPlotPrice(Double.parseDouble(line));
                } catch (Exception e) {
                    town.setCommercialPlotPrice(0);
                }
            line = kvFile.get("commercialPlotTax");
            if (line != null)
                try {
                    town.setCommercialPlotTax(Double.parseDouble(line));
                } catch (Exception e) {
                    town.setCommercialPlotTax(0);
                }
            line = kvFile.get("embassyPlotPrice");
            if (line != null)
                try {
                    town.setEmbassyPlotPrice(Double.parseDouble(line));
                } catch (Exception e) {
                    town.setEmbassyPlotPrice(0);
                }
            line = kvFile.get("embassyPlotTax");
            if (line != null)
                try {
                    town.setEmbassyPlotTax(Double.parseDouble(line));
                } catch (Exception e) {
                    town.setEmbassyPlotTax(0);
                }
            line = kvFile.get("adminDisabledPvP");
            if (line != null)
                try {
                    town.setAdminDisabledPVP(Boolean.parseBoolean(line));
                } catch (NumberFormatException nfe) {
                } catch (Exception e) {
                }
            /*
				 * line = kvFile.get("mobs");
				 * if (line != null)
				 * try {
				 * town.setHasMobs(Boolean.parseBoolean(line));
				 * } catch (NumberFormatException nfe) {
				 * } catch (Exception e) {
				 * }
				 */
            line = kvFile.get("open");
            if (line != null)
                try {
                    town.setOpen(Boolean.parseBoolean(line));
                } catch (NumberFormatException nfe) {
                } catch (Exception e) {
                }
            line = kvFile.get("public");
            if (line != null)
                try {
                    town.setPublic(Boolean.parseBoolean(line));
                } catch (NumberFormatException nfe) {
                } catch (Exception e) {
                }
            /*
				 * line = kvFile.get("explosion");
				 * if (line != null)
				 * try {
				 * town.setBANG(Boolean.parseBoolean(line));
				 * } catch (NumberFormatException nfe) {
				 * } catch (Exception e) {
				 * }
				 * 
				 * line = kvFile.get("fire");
				 * if (line != null)
				 * try {
				 * town.setFire(Boolean.parseBoolean(line));
				 * } catch (NumberFormatException nfe) {
				 * } catch (Exception e) {
				 * }
				 */
            line = kvFile.get("townBlocks");
            if (line != null)
                utilLoadTownBlocks(line, town, null);
            line = kvFile.get("homeBlock");
            if (line != null) {
                tokens = line.split(",");
                if (tokens.length == 3)
                    try {
                        TownyWorld world = getWorld(tokens[0]);
                        try {
                            int x = Integer.parseInt(tokens[1]);
                            int z = Integer.parseInt(tokens[2]);
                            TownBlock homeBlock = world.getTownBlock(x, z);
                            town.forceSetHomeBlock(homeBlock);
                        } catch (NumberFormatException e) {
                            TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " homeBlock tried to load invalid location.");
                        } catch (NotRegisteredException e) {
                            TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " homeBlock tried to load invalid TownBlock.");
                        } catch (TownyException e) {
                            TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " does not have a home block.");
                        }
                    } catch (NotRegisteredException e) {
                        TownyMessaging.sendErrorMsg("[Warning] " + town.getName() + " homeBlock tried to load invalid world.");
                    }
            }
            line = kvFile.get("spawn");
            if (line != null) {
                tokens = line.split(",");
                if (tokens.length >= 4)
                    try {
                        World world = plugin.getServerWorld(tokens[0]);
                        double x = Double.parseDouble(tokens[1]);
                        double y = Double.parseDouble(tokens[2]);
                        double z = Double.parseDouble(tokens[3]);
                        Location loc = new Location(world, x, y, z);
                        if (tokens.length == 6) {
                            loc.setPitch(Float.parseFloat(tokens[4]));
                            loc.setYaw(Float.parseFloat(tokens[5]));
                        }
                        town.forceSetSpawn(loc);
                    } catch (NumberFormatException e) {
                    } catch (NotRegisteredException e) {
                    } catch (NullPointerException e) {
                    }
            }
            // Load outpost spawns
            line = kvFile.get("outpostspawns");
            if (line != null) {
                String[] outposts = line.split(";");
                for (String spawn : outposts) {
                    tokens = spawn.split(",");
                    if (tokens.length >= 4)
                        try {
                            World world = plugin.getServerWorld(tokens[0]);
                            double x = Double.parseDouble(tokens[1]);
                            double y = Double.parseDouble(tokens[2]);
                            double z = Double.parseDouble(tokens[3]);
                            Location loc = new Location(world, x, y, z);
                            if (tokens.length == 6) {
                                loc.setPitch(Float.parseFloat(tokens[4]));
                                loc.setYaw(Float.parseFloat(tokens[5]));
                            }
                            town.forceAddOutpostSpawn(loc);
                        } catch (NumberFormatException e) {
                        } catch (NotRegisteredException e) {
                        } catch (NullPointerException e) {
                        }
                }
            }
        } catch (Exception e) {
            TownyMessaging.sendErrorMsg("Loading Error: Exception while reading town file " + town.getName());
            return false;
        }
        return true;
    } else
        return false;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) KeyValueFile(com.palmergames.util.KeyValueFile) 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) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) Resident(com.palmergames.bukkit.towny.object.Resident) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) File(java.io.File) KeyValueFile(com.palmergames.util.KeyValueFile) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) Location(org.bukkit.Location)

Example 13 with NotRegisteredException

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

the class TownyFlatFileSource method saveTown.

@Override
public boolean saveTown(Town town) {
    List<String> list = new ArrayList<String>();
    // Name
    list.add("name=" + town.getName());
    // Residents
    list.add("residents=" + StringMgmt.join(town.getResidents(), ","));
    // Mayor
    if (town.hasMayor())
        list.add("mayor=" + town.getMayor().getName());
    // Nation
    if (town.hasNation())
        try {
            list.add("nation=" + town.getNation().getName());
        } catch (NotRegisteredException e) {
        }
    // Assistants
    list.add("assistants=" + StringMgmt.join(town.getAssistants(), ","));
    list.add(newLine);
    // Town Board
    list.add("townBoard=" + town.getTownBoard());
    // tag
    list.add("tag=" + town.getTag());
    // Town Protection
    list.add("protectionStatus=" + town.getPermissions().toString());
    // Bonus Blocks
    list.add("bonusBlocks=" + Integer.toString(town.getBonusBlocks()));
    // Purchased Blocks
    list.add("purchasedBlocks=" + Integer.toString(town.getPurchasedBlocks()));
    // Taxpercent
    list.add("taxpercent=" + Boolean.toString(town.isTaxPercentage()));
    // Taxes
    list.add("taxes=" + Double.toString(town.getTaxes()));
    // Plot Price
    list.add("plotPrice=" + Double.toString(town.getPlotPrice()));
    // Plot Tax
    list.add("plotTax=" + Double.toString(town.getPlotTax()));
    // Commercial Plot Price
    list.add("commercialPlotPrice=" + Double.toString(town.getCommercialPlotPrice()));
    // Commercial Tax
    list.add("commercialPlotTax=" + Double.toString(town.getCommercialPlotTax()));
    // Embassy Plot Price
    list.add("embassyPlotPrice=" + Double.toString(town.getEmbassyPlotPrice()));
    // Embassy Tax
    list.add("embassyPlotTax=" + Double.toString(town.getEmbassyPlotTax()));
    // Upkeep
    list.add("hasUpkeep=" + Boolean.toString(town.hasUpkeep()));
    // Open
    list.add("open=" + Boolean.toString(town.isOpen()));
    // PVP
    list.add("adminDisabledPvP=" + Boolean.toString(town.isAdminDisabledPVP()));
    /* // Mobs
		* fout.write("mobs=" + Boolean.toString(town.hasMobs()) + newLine);
		*/
    // Public
    list.add("public=" + Boolean.toString(town.isPublic()));
    // Home Block
    if (town.hasHomeBlock())
        try {
            list.add("homeBlock=" + town.getHomeBlock().getWorld().getName() + "," + Integer.toString(town.getHomeBlock().getX()) + "," + Integer.toString(town.getHomeBlock().getZ()));
        } catch (TownyException e) {
        }
    // Spawn
    if (town.hasSpawn())
        try {
            list.add("spawn=" + town.getSpawn().getWorld().getName() + "," + Double.toString(town.getSpawn().getX()) + "," + Double.toString(town.getSpawn().getY()) + "," + Double.toString(town.getSpawn().getZ()) + "," + Float.toString(town.getSpawn().getPitch()) + "," + Float.toString(town.getSpawn().getYaw()));
        } catch (TownyException e) {
        }
    // Outpost Spawns
    if (town.hasOutpostSpawn()) {
        String outpostArray = "outpostspawns=";
        for (Location spawn : new ArrayList<Location>(town.getAllOutpostSpawns())) {
            outpostArray += (spawn.getWorld().getName() + "," + Double.toString(spawn.getX()) + "," + Double.toString(spawn.getY()) + "," + Double.toString(spawn.getZ()) + "," + Float.toString(spawn.getPitch()) + "," + Float.toString(spawn.getYaw()) + ";");
        }
        list.add(outpostArray);
    }
    /*
		 *  Make sure we only save in async
		 */
    this.queryQueue.add(new FlatFile_Task(list, getTownFilename(town)));
    return true;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) ArrayList(java.util.ArrayList) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) Location(org.bukkit.Location)

Example 14 with NotRegisteredException

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

the class TownySQLSource method loadWorldList.

@Override
public boolean loadWorldList() {
    TownyMessaging.sendDebugMsg("Loading World List");
    if (!getContext())
        return false;
    try {
        Statement s = cntx.createStatement();
        ResultSet rs = s.executeQuery("SELECT name FROM " + tb_prefix + "WORLDS");
        while (rs.next()) {
            try {
                newWorld(rs.getString("name"));
            } catch (AlreadyRegisteredException e) {
            }
        }
        s.close();
    } catch (SQLException e) {
        TownyMessaging.sendErrorMsg("SQL: world list sql error : " + e.getMessage());
    } catch (Exception e) {
        TownyMessaging.sendErrorMsg("SQL: world list unknown error : ");
        e.printStackTrace();
    }
    // Check for any new worlds registered with bukkit.
    if (plugin != null) {
        for (World world : plugin.getServer().getWorlds()) try {
            newWorld(world.getName());
        } catch (AlreadyRegisteredException e) {
        // e.printStackTrace();
        } catch (NotRegisteredException e) {
        // e.printStackTrace();
        }
    }
    return true;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) ResultSet(java.sql.ResultSet) World(org.bukkit.World) 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 15 with NotRegisteredException

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

the class TownyBlockListener method onBlockPlace.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    Player player = event.getPlayer();
    Block block = event.getBlock();
    WorldCoord worldCoord;
    try {
        TownyWorld world = TownyUniverse.getDataSource().getWorld(block.getWorld().getName());
        worldCoord = new WorldCoord(world.getName(), Coord.parseCoord(block));
        //Get build permissions (updates if none exist)
        boolean bBuild = PlayerCacheUtil.getCachePermission(player, block.getLocation(), BukkitTools.getTypeId(block), BukkitTools.getData(block), TownyPermission.ActionType.BUILD);
        // Allow build if we are permitted
        if (bBuild)
            return;
        /*
			 * Fetch the players cache
			 */
        PlayerCache cache = plugin.getCache(player);
        TownBlockStatus status = cache.getStatus();
        /*
			 * Flag war
			 */
        if (((status == TownBlockStatus.ENEMY) && TownyWarConfig.isAllowingAttacks()) && (event.getBlock().getType() == TownyWarConfig.getFlagBaseMaterial())) {
            try {
                if (TownyWar.callAttackCellEvent(plugin, player, block, worldCoord))
                    return;
            } catch (TownyException e) {
                TownyMessaging.sendErrorMsg(player, e.getMessage());
            }
            event.setBuild(false);
            event.setCancelled(true);
        } else if (status == TownBlockStatus.WARZONE) {
            if (!TownyWarConfig.isEditableMaterialInWarZone(block.getType())) {
                event.setBuild(false);
                event.setCancelled(true);
                TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_warzone_cannot_edit_material"), "build", block.getType().toString().toLowerCase()));
            }
            return;
        } else {
            event.setBuild(false);
            event.setCancelled(true);
        }
        /* 
			 * display any error recorded for this plot
			 */
        if ((cache.hasBlockErrMsg()) && (event.isCancelled()))
            TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
    } catch (NotRegisteredException e1) {
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) PlayerCache(com.palmergames.bukkit.towny.object.PlayerCache) TownBlockStatus(com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) EventHandler(org.bukkit.event.EventHandler)

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