Search in sources :

Example 16 with NotRegisteredException

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

the class TownyBlockListener method testBlockMove.

private boolean testBlockMove(Block block, BlockFace direction) {
    Block blockTo = block.getRelative(direction);
    Location loc = block.getLocation();
    Location locTo = blockTo.getLocation();
    Coord coord = Coord.parseCoord(loc);
    Coord coordTo = Coord.parseCoord(locTo);
    TownyWorld townyWorld = null;
    TownBlock CurrentTownBlock = null, destinationTownBlock = null;
    try {
        townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
        CurrentTownBlock = townyWorld.getTownBlock(coord);
    } catch (NotRegisteredException e) {
    //System.out.print("Failed to fetch TownBlock");
    }
    try {
        destinationTownBlock = townyWorld.getTownBlock(coordTo);
    } catch (NotRegisteredException e1) {
    //System.out.print("Failed to fetch TownBlockTo");
    }
    if (CurrentTownBlock != destinationTownBlock) {
        // Cancel if either is not null, but other is (wild to town).
        if (((CurrentTownBlock == null) && (destinationTownBlock != null)) || ((CurrentTownBlock != null) && (destinationTownBlock == null))) {
            //event.setCancelled(true);
            return true;
        }
        // If both blocks are owned by the town.
        if (!CurrentTownBlock.hasResident() && !destinationTownBlock.hasResident())
            return false;
        try {
            if ((!CurrentTownBlock.hasResident() && destinationTownBlock.hasResident()) || (CurrentTownBlock.hasResident() && !destinationTownBlock.hasResident()) || (CurrentTownBlock.getResident() != destinationTownBlock.getResident()) || (CurrentTownBlock.getPlotPrice() != -1) || (destinationTownBlock.getPlotPrice() != -1)) {
                return true;
            }
        } catch (NotRegisteredException e) {
            // Failed to fetch a resident
            return true;
        }
    }
    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) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) 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)

Example 17 with NotRegisteredException

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

the class TownyUniverse method getValidatedResidents.

public static List<Resident> getValidatedResidents(Object sender, String[] names) {
    List<Resident> invited = new ArrayList<Resident>();
    for (String name : names) {
        List<Player> matches = BukkitTools.matchPlayer(name);
        if (matches.size() > 1) {
            String line = "Multiple players selected";
            for (Player p : matches) line += ", " + p.getName();
            TownyMessaging.sendErrorMsg(sender, line);
        } else if (matches.size() == 1) {
            // Match found online
            try {
                Resident target = getDataSource().getResident(matches.get(0).getName());
                invited.add(target);
            } catch (TownyException x) {
                TownyMessaging.sendErrorMsg(sender, x.getMessage());
            }
        } else {
            // No online matches so test for offline.
            Resident target;
            try {
                target = getDataSource().getResident(name);
                invited.add(target);
            } catch (NotRegisteredException x) {
                TownyMessaging.sendErrorMsg(sender, x.getMessage());
            }
        }
    }
    return invited;
}
Also used : Player(org.bukkit.entity.Player) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 18 with NotRegisteredException

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

the class PlotClaim method residentUnclaim.

private boolean residentUnclaim(WorldCoord worldCoord) throws TownyException {
    try {
        TownBlock townBlock = worldCoord.getTownBlock();
        townBlock.setResident(null);
        townBlock.setPlotPrice(townBlock.getTown().getPlotTypePrice(townBlock.getType()));
        // Set the plot permissions to mirror the towns.
        townBlock.setType(townBlock.getType());
        TownyUniverse.getDataSource().saveTownBlock(townBlock);
        plugin.updateCache(worldCoord);
    } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_not_own_place"));
    }
    return true;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 19 with NotRegisteredException

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

the class TownyEntityListener method onEntityInteract.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityInteract(EntityInteractEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    Block block = event.getBlock();
    Entity entity = event.getEntity();
    Entity passenger = entity.getPassenger();
    TownyWorld World = null;
    try {
        World = TownyUniverse.getDataSource().getWorld(block.getLocation().getWorld().getName());
        if (!World.isUsingTowny())
            return;
    } catch (NotRegisteredException e) {
        // World not registered with Towny.
        e.printStackTrace();
        return;
    }
    try {
        TownyWorld townyWorld = TownyUniverse.getDataSource().getWorld(block.getLocation().getWorld().getName());
        if (townyWorld.isUsingTowny()) {
            // Prevent creatures trampling crops
            if (townyWorld.isDisableCreatureTrample()) {
                if ((block.getType() == Material.SOIL) || (block.getType() == Material.CROPS)) {
                    if (entity instanceof Creature) {
                        event.setCancelled(true);
                        return;
                    }
                }
            }
            /*
				 * Allow players in vehicles to activate pressure plates if they
				 * are permitted.
				 */
            if (passenger != null && passenger instanceof Player) {
                if (TownySettings.isSwitchMaterial(block.getType().name())) {
                    if (!plugin.getPlayerListener().onPlayerSwitchEvent((Player) passenger, block, null, World))
                        return;
                }
            }
            // Prevent creatures triggering stone pressure plates
            if (TownySettings.isCreatureTriggeringPressurePlateDisabled()) {
                if (block.getType() == Material.STONE_PLATE) {
                    if (entity instanceof Creature) {
                        event.setCancelled(true);
                        return;
                    }
                }
            }
        }
    } catch (NotRegisteredException e) {
        // Failed to fetch world
        e.printStackTrace();
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Creature(org.bukkit.entity.Creature) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) EventHandler(org.bukkit.event.EventHandler)

Example 20 with NotRegisteredException

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

the class TownyEntityListener method onEntityExplode.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    TownyWorld townyWorld;
    /**
		 * Perform this test outside the block loop so we only get the world
		 * once per explosion.
		 */
    try {
        townyWorld = TownyUniverse.getDataSource().getWorld(event.getLocation().getWorld().getName());
        if (!townyWorld.isUsingTowny())
            return;
    } catch (NotRegisteredException e) {
        // failed to get world so abort
        return;
    }
    Coord coord;
    List<Block> blocks = event.blockList();
    Entity entity = event.getEntity();
    int count = 0;
    // Sort blocks by height (lowest to highest).
    Collections.sort(blocks, ArraySort.getInstance());
    for (Block block : blocks) {
        coord = Coord.parseCoord(block.getLocation());
        count++;
        // Warzones
        if (townyWorld.isWarZone(coord)) {
            if (!TownyWarConfig.isAllowingExplosionsInWarZone()) {
                if (event.getEntity() != null)
                    TownyMessaging.sendDebugMsg("onEntityExplode: Canceled " + event.getEntity().getEntityId() + " from exploding within " + coord.toString() + ".");
                event.setCancelled(true);
                return;
            } else {
                if (TownyWarConfig.explosionsBreakBlocksInWarZone()) {
                    if (TownyWarConfig.regenBlocksAfterExplosionInWarZone()) {
                    // ***********************************
                    // TODO
                    // On completion, remove TODO from config.yml
                    // comments.
                    /*
							 * if
							 * (!plugin.getTownyUniverse().hasProtectionRegenTask
							 * (new BlockLocation(block.getLocation()))) {
							 * ProtectionRegenTask task = new
							 * ProtectionRegenTask(plugin.getTownyUniverse(),
							 * block, false);
							 * task.setTaskId(plugin.getServer().getScheduler().
							 * scheduleSyncDelayedTask(plugin, task,
							 * ((TownySettings.getPlotManagementWildRegenDelay()
							 * + count)*20)));
							 * plugin.getTownyUniverse().addProtectionRegenTask
							 * (task ); }
							 */
                    // TODO
                    // ***********************************
                    }
                // Break the block
                } else {
                    event.blockList().remove(block);
                }
            }
            return;
        }
        // TODO: expand to protect neutrals during a war
        try {
            TownBlock townBlock = townyWorld.getTownBlock(coord);
            // and the towns has no nation
            if (townyWorld.isUsingTowny() && !townyWorld.isForceExpl()) {
                if ((!townBlock.getPermissions().explosion) || (TownyUniverse.isWarTime() && TownySettings.isAllowWarBlockGriefing() && !townBlock.getTown().hasNation() && !townBlock.getTown().isBANG())) {
                    if (event.getEntity() != null)
                        TownyMessaging.sendDebugMsg("onEntityExplode: Canceled " + event.getEntity().getEntityId() + " from exploding within " + coord.toString() + ".");
                    event.setCancelled(true);
                    return;
                }
            }
        } catch (TownyException x) {
            // Wilderness explosion regeneration
            if (townyWorld.isUsingTowny())
                if (townyWorld.isExpl()) {
                    if (townyWorld.isUsingPlotManagementWildRevert() && (entity != null)) {
                        TownyMessaging.sendDebugMsg("onEntityExplode: Testing entity: " + entity.getType().getEntityClass().getSimpleName().toLowerCase() + " @ " + coord.toString() + ".");
                        if (townyWorld.isProtectingExplosionEntity(entity)) {
                            if ((!TownyRegenAPI.hasProtectionRegenTask(new BlockLocation(block.getLocation()))) && (block.getType() != Material.TNT)) {
                                ProtectionRegenTask task = new ProtectionRegenTask(plugin, block, false);
                                task.setTaskId(plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, ((TownySettings.getPlotManagementWildRegenDelay() + count) * 20)));
                                TownyRegenAPI.addProtectionRegenTask(task);
                                event.setYield((float) 0.0);
                                block.getDrops().clear();
                            }
                        }
                    }
                } else {
                    event.setCancelled(true);
                    return;
                }
        }
    }
}
Also used : Coord(com.palmergames.bukkit.towny.object.Coord) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) ProtectionRegenTask(com.palmergames.bukkit.towny.tasks.ProtectionRegenTask) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) BlockLocation(com.palmergames.bukkit.towny.regen.block.BlockLocation) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) 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