/** * Called when a player attempts to pickup an item * * @param event Relevant event details */ @Override public void onPlayerPickupItem(PlayerPickupItemEvent event) { if (event.isCancelled()) { return; } GlobalConfiguration cfg = plugin.getGlobalConfiguration(); WorldConfiguration wcfg = cfg.getWorldConfig(event.getPlayer().getWorld().getName()); if (wcfg.getBlacklist() != null) { Item ci = event.getItem(); if (!wcfg.getBlacklist() .check( new ItemAcquireBlacklistEvent( BukkitPlayer.wrapPlayer(plugin, event.getPlayer()), toVector(ci.getLocation()), ci.getItemStack().getTypeId()), false, false)) { event.setCancelled(true); return; } } }
/** * Creates a new world. * * <p>{@link com.artemis.EntityManager}, {@link ComponentManager} and {@link * AspectSubscriptionManager} are available by default, on top of your own systems. * * @see WorldConfigurationBuilder * @see WorldConfiguration */ public World(WorldConfiguration configuration) { systems = new IdentityHashMap<Class<?>, BaseSystem>(); systemsBag = configuration.systems; changed = new BitSet(); deleted = new BitSet(); final ComponentManager lcm = (ComponentManager) configuration.systems.get(WorldConfiguration.COMPONENT_MANAGER_IDX); final EntityManager lem = (EntityManager) configuration.systems.get(WorldConfiguration.ENTITY_MANAGER_IDX); final AspectSubscriptionManager lam = (AspectSubscriptionManager) configuration.systems.get(WorldConfiguration.ASPECT_SUBSCRIPTION_MANAGER_IDX); cm = lcm == null ? new ComponentManager(configuration.expectedEntityCount()) : lcm; em = lem == null ? new EntityManager(configuration.expectedEntityCount()) : lem; am = lam == null ? new AspectSubscriptionManager() : lam; editPool = new EntityEditPool(em); injector = configuration.injector; if (injector == null) { injector = new CachedInjector(); } configuration.initialize(this, injector, am); if (invocationStrategy == null) { setInvocationStrategy(new InvocationStrategy()); } }
/* * Called when a block is destroyed from burning. */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockBurn(BlockBurnEvent event) { ConfigurationManager cfg = plugin.getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld()); if (cfg.activityHaltToggle) { event.setCancelled(true); return; } if (wcfg.disableFireSpread) { event.setCancelled(true); return; } if (wcfg.fireSpreadDisableToggle) { Block block = event.getBlock(); event.setCancelled(true); checkAndDestroyAround( block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE); return; } if (wcfg.disableFireSpreadBlocks.size() > 0) { Block block = event.getBlock(); if (wcfg.disableFireSpreadBlocks.contains(block.getTypeId())) { event.setCancelled(true); checkAndDestroyAround( block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE); return; } } if (wcfg.isChestProtected(event.getBlock())) { event.setCancelled(true); return; } if (wcfg.useRegions) { Block block = event.getBlock(); int x = block.getX(); int y = block.getY(); int z = block.getZ(); Vector pt = toVector(block); RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld()); ApplicableRegionSet set = mgr.getApplicableRegions(pt); if (!set.allows(DefaultFlag.FIRE_SPREAD)) { checkAndDestroyAround(block.getWorld(), x, y, z, BlockID.FIRE); event.setCancelled(true); return; } } }
/** Called when a block is broken. */ @Override public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) { return; } Player player = event.getPlayer(); WorldConfiguration wcfg = getWorldConfig(player); if (!wcfg.itemDurability) { ItemStack held = player.getItemInHand(); if (held.getTypeId() > 0) { held.setDurability((short) -1); player.setItemInHand(held); } } if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } if (wcfg.getBlacklist() != null) { if (!wcfg.getBlacklist() .check( new BlockBreakBlacklistEvent( plugin.wrapPlayer(player), toVector(event.getBlock()), event.getBlock().getTypeId()), false, false)) { event.setCancelled(true); return; } if (!wcfg.getBlacklist() .check( new DestroyWithBlacklistEvent( plugin.wrapPlayer(player), toVector(event.getBlock()), player.getItemInHand().getTypeId()), false, false)) { event.setCancelled(true); return; } } if (wcfg.isChestProtected(event.getBlock(), player)) { player.sendMessage(ChatColor.DARK_RED + "The chest is protected."); event.setCancelled(true); return; } }
/* * Called when a block is broken. */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); WorldConfiguration wcfg = getWorldConfig(player); if (!wcfg.itemDurability) { ItemStack held = player.getItemInHand(); if (held.getTypeId() > 0 && !(ItemType.usesDamageValue(held.getTypeId()) || BlockType.usesData(held.getTypeId()))) { held.setDurability((short) 0); player.setItemInHand(held); } } if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock()) || !plugin.getGlobalRegionManager().canConstruct(player, event.getBlock())) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } if (wcfg.getBlacklist() != null) { if (!wcfg.getBlacklist() .check( new BlockBreakBlacklistEvent( plugin.wrapPlayer(player), toVector(event.getBlock()), event.getBlock().getTypeId()), false, false)) { event.setCancelled(true); return; } if (!wcfg.getBlacklist() .check( new DestroyWithBlacklistEvent( plugin.wrapPlayer(player), toVector(event.getBlock()), player.getItemInHand().getTypeId()), false, false)) { event.setCancelled(true); return; } } if (wcfg.isChestProtected(event.getBlock(), player)) { player.sendMessage(ChatColor.DARK_RED + "The chest is protected."); event.setCancelled(true); return; } }
/* * Called when a player places a block. */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { Block blockPlaced = event.getBlock(); Player player = event.getPlayer(); World world = blockPlaced.getWorld(); ConfigurationManager cfg = plugin.getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(world); if (wcfg.useRegions) { final Location location = blockPlaced.getLocation(); if (!plugin.getGlobalRegionManager().canBuild(player, location) || !plugin.getGlobalRegionManager().canConstruct(player, location)) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } } if (wcfg.getBlacklist() != null) { if (!wcfg.getBlacklist() .check( new BlockPlaceBlacklistEvent( plugin.wrapPlayer(player), toVector(blockPlaced), blockPlaced.getTypeId()), false, false)) { event.setCancelled(true); return; } } if (wcfg.signChestProtection && wcfg.getChestProtection().isChest(blockPlaced.getTypeId())) { if (wcfg.isAdjacentChestProtected(event.getBlock(), player)) { player.sendMessage( ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for."); event.setCancelled(true); return; } } if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) { if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) { return; } int ox = blockPlaced.getX(); int oy = blockPlaced.getY(); int oz = blockPlaced.getZ(); SpongeUtil.clearSpongeWater(plugin, world, ox, oy, oz); } }
@Override public void onEntityExplode(EntityExplodeEvent event) { if (event.isCancelled()) { return; } GlobalConfiguration cfg = plugin.getGlobalConfiguration(); Location l = event.getLocation(); WorldConfiguration wcfg = cfg.getWorldConfig(l.getWorld().getName()); if (event.getEntity() instanceof LivingEntity) { if (wcfg.blockCreeperBlockDamage) { event.setCancelled(true); return; } if (wcfg.blockCreeperExplosions) { event.setCancelled(true); return; } if (wcfg.useRegions) { Vector pt = toVector(l); RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName()); if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(Flags.CREEPER_EXPLOSION)) { event.setCancelled(true); return; } } } else { // Shall assume that this is TNT if (wcfg.blockTNT) { event.setCancelled(true); return; } if (wcfg.useRegions) { Vector pt = toVector(l); RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName()); if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(Flags.TNT)) { event.setCancelled(true); return; } } } }
/** * Called when a player places a block * * @param event Relevant event details */ @Override public void onBlockPlace(BlockPlaceEvent event) { if (event.isCancelled()) { return; } Block blockPlaced = event.getBlock(); Player player = event.getPlayer(); World world = blockPlaced.getWorld(); ConfigurationManager cfg = plugin.getGlobalConfiguration(); WorldConfiguration wcfg = cfg.get(world); if (wcfg.useRegions) { if (!plugin.getGlobalRegionManager().canBuild(player, blockPlaced.getLocation())) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } } if (wcfg.getBlacklist() != null) { if (!wcfg.getBlacklist() .check( new BlockPlaceBlacklistEvent( plugin.wrapPlayer(player), toVector(blockPlaced), blockPlaced.getTypeId()), false, false)) { event.setCancelled(true); return; } } if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) { if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) { return; } int ox = blockPlaced.getX(); int oy = blockPlaced.getY(); int oz = blockPlaced.getZ(); clearSpongeWater(world, ox, oy, oz); } }
/* * Called when a sign is changed. */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onSignChange(SignChangeEvent event) { Player player = event.getPlayer(); WorldConfiguration wcfg = getWorldConfig(player); if (wcfg.signChestProtection) { if (event.getLine(0).equalsIgnoreCase("[Lock]")) { if (wcfg.isChestProtectedPlacement(event.getBlock(), player)) { player.sendMessage(ChatColor.DARK_RED + "You do not own the adjacent chest."); event.getBlock().breakNaturally(); event.setCancelled(true); return; } if (event.getBlock().getTypeId() != BlockID.SIGN_POST) { player.sendMessage( ChatColor.RED + "The [Lock] sign must be a sign post, not a wall sign."); event.getBlock().breakNaturally(); event.setCancelled(true); return; } if (!event.getLine(1).equalsIgnoreCase(player.getName())) { player.sendMessage(ChatColor.RED + "The first owner line must be your name."); event.getBlock().breakNaturally(); event.setCancelled(true); return; } int below = event.getBlock().getRelative(0, -1, 0).getTypeId(); if (below == BlockID.TNT || below == BlockID.SAND || below == BlockID.GRAVEL || below == BlockID.SIGN_POST) { player.sendMessage( ChatColor.RED + "That is not a safe block that you're putting this sign on."); event.getBlock().breakNaturally(); event.setCancelled(true); return; } event.setLine(0, "[Lock]"); player.sendMessage(ChatColor.YELLOW + "A chest or double chest above is now protected."); } } else if (!wcfg.disableSignChestProtectionCheck) { if (event.getLine(0).equalsIgnoreCase("[Lock]")) { player.sendMessage(ChatColor.RED + "WorldGuard's sign chest protection is disabled."); event.getBlock().breakNaturally(); event.setCancelled(true); return; } } if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } }
public void onPlayerInteract(PlayerInteractEvent event) { if (event.isCancelled()) { return; } Action action = event.getAction(); if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) { Block block = event.getClickedBlock(); Material type = block.getType(); Player player = event.getPlayer(); GlobalConfiguration cfg = plugin.getGlobalConfiguration(); WorldConfiguration wcfg = cfg.getWorldConfig(event.getClickedBlock().getWorld().getName()); if (wcfg.useRegions && player.getItemInHand().getTypeId() == wcfg.regionWand) { Vector pt = toVector(block); RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName()); ApplicableRegionSet app = mgr.getApplicableRegions(pt); List<String> regions = mgr.getApplicableRegionsIDs(pt); if (regions.size() > 0) { player.sendMessage( ChatColor.YELLOW + "Can you build? " + (app.canBuild(BukkitPlayer.wrapPlayer(plugin, player)) ? "Yes" : "No")); StringBuilder str = new StringBuilder(); for (Iterator<String> it = regions.iterator(); it.hasNext(); ) { str.append(it.next()); if (it.hasNext()) { str.append(", "); } } player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString()); } else { player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!"); } } if (block.getType() == Material.CHEST || block.getType() == Material.DISPENSER || block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE || block.getType() == Material.NOTE_BLOCK) { if (wcfg.useRegions) { Vector pt = toVector(block); LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player); RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName()); if (!plugin.hasPermission(player, "region.bypass")) { ApplicableRegionSet set = mgr.getApplicableRegions(pt); if (!set.isStateFlagAllowed(Flags.CHEST_ACCESS) && !set.canBuild(localPlayer)) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } } } } if (wcfg.useRegions && (type == Material.LEVER || type == Material.STONE_BUTTON)) { Vector pt = toVector(block); RegionManager mgr = cfg.getWorldGuardPlugin() .getGlobalRegionManager() .getRegionManager(player.getWorld().getName()); ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt); LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player); if (!applicableRegions.isStateFlagAllowed(Flags.LEVER_AND_BUTTON, localPlayer)) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } } if (wcfg.useRegions && type == Material.CAKE_BLOCK) { Vector pt = toVector(block); if (!cfg.canBuild(player, pt)) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); byte newData = (byte) (block.getData() - 1); newData = newData < 0 ? 0 : newData; block.setData(newData); player.setHealth(player.getHealth() - 3); return; } } if (wcfg.useRegions && wcfg.useiConomy && cfg.getiConomy() != null && (type == Material.SIGN_POST || type == Material.SIGN || type == Material.WALL_SIGN)) { BlockState blockstate = block.getState(); if (((Sign) blockstate).getLine(0).equalsIgnoreCase("[WorldGuard]") && ((Sign) blockstate).getLine(1).equalsIgnoreCase("For sale")) { String regionId = ((Sign) blockstate).getLine(2); // String regionComment = ((Sign)block).getLine(3); if (regionId != null && regionId != "") { RegionManager mgr = cfg.getWorldGuardPlugin() .getGlobalRegionManager() .getRegionManager(player.getWorld().getName()); ProtectedRegion region = mgr.getRegion(regionId); if (region != null) { RegionFlagContainer flags = region.getFlags(); if (flags.getBooleanFlag(Flags.BUYABLE).getValue(false)) { if (iConomy.getBank().hasAccount(player.getName())) { Account account = iConomy.getBank().getAccount(player.getName()); double balance = account.getBalance(); double regionPrice = flags.getDoubleFlag(Flags.PRICE).getValue(); if (balance >= regionPrice) { account.subtract(regionPrice); player.sendMessage( ChatColor.YELLOW + "You have bought the region " + regionId + " for " + iConomy.getBank().format(regionPrice)); DefaultDomain owners = region.getOwners(); owners.addPlayer(player.getName()); region.setOwners(owners); flags.getBooleanFlag(Flags.BUYABLE).setValue(false); account.save(); } else { player.sendMessage(ChatColor.YELLOW + "You have not enough money."); } } else { player.sendMessage(ChatColor.YELLOW + "You have not enough money."); } } else { player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable"); } } else { player.sendMessage( ChatColor.DARK_RED + "The region " + regionId + " does not exist."); } } else { player.sendMessage(ChatColor.DARK_RED + "No region specified."); } } } if (wcfg.getBlacklist() != null) { if (!wcfg.getBlacklist() .check( new BlockInteractBlacklistEvent( BukkitPlayer.wrapPlayer(plugin, player), toVector(block), block.getTypeId()), false, false)) { event.setCancelled(true); return; } } } }
public WorldConfigurationNode(WorldConfiguration parent, String worldname) { super(new MapConfiguration(parent.getNode("worlds", worldname).getValues())); this.parent = parent; this.name = worldname; }