/* * 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; } } }
/** * Checks to see whether a flag is allowed. * * @param flag * @param loc * @return */ public boolean allows(StateFlag flag, Location loc) { World world = loc.getWorld(); WorldConfiguration worldConfig = config.get(world); if (!worldConfig.useRegions) { return true; } RegionManager mgr = plugin.getGlobalRegionManager().get(world); return mgr.getApplicableRegions(toVector(loc)).allows(flag); }
public void checkRegion(Player sender, String[] args) { if (!sender.hasPermission("iceprotect.buy")) { sender.sendMessage(ChatColor.RED + "You don't have permission!"); return; } if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } String id = "icp__tempregion"; Location loc = sender.getLocation(); BlockVector min = new BlockVector(loc.getX() - 1, loc.getY() - 1, loc.getZ() - 1); BlockVector max = new BlockVector(loc.getX() + 1, loc.getY() + 1, loc.getZ() + 1); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); RegionManager mgr = plugin.getGlobalRegionManager().get(sender.getWorld()); ApplicableRegionSet regions = mgr.getApplicableRegions(region); ProtectedRegion appReg = null; for (ProtectedRegion r : regions) { if (econ.isRegionForSale(r.getId())) { appReg = r; break; } } if (appReg == null) { sender.sendMessage(ChatColor.RED + "No nearby regions for sale!"); return; } else { double cost = regionsForSale.getDouble("regions." + appReg.getId() + ".price", 0D); if (cost == 0) { sender.sendMessage( ChatColor.RED + "(this shouldn't happen) You can't buy this region. Notify an admin!"); return; } sender.sendMessage( ChatColor.YELLOW + "This region " + appReg.getId() + " is for sale by " + regionsForSale.getString("regions." + appReg.getId() + ".seller")); sender.sendMessage(ChatColor.YELLOW + "And costs $" + cost + "."); } }
@Test public void testExit() throws Exception { ApplicableRegionSet appl; appl = manager.getApplicableRegions(inExit); // ProtectedRegion rg = appl.iterator().next(); // System.out.println("rg " + rg.getId()); // System.out.println("own " + rg.getOwners().toGroupsString()); // System.out.println("flag " + appl.getFlag(DefaultFlag.EXIT)); // System.out.println("grp " + appl.getFlag(DefaultFlag.EXIT.getRegionGroupFlag())); // System.out.println("==="); assertTrue("Allowed Exit", appl.allows(DefaultFlag.EXIT, builder_player)); assertFalse("Forbidden Exit", appl.allows(DefaultFlag.EXIT, vip_player)); }
public boolean isWGRegion(Block block) { try { if (wg == null) { return false; } RegionManager manager = wg.getRegionManager(block.getWorld()); ApplicableRegionSet regions = manager.getApplicableRegions(block.getLocation()); return regions != null && regions.size() > 0; } catch (Exception ex) { return false; } }
@EventHandler public void move(PlayerMoveEvent event) { if (worldGuard == null) return; Player player = event.getPlayer(); if (!regionsVisited.containsKey(player.getUniqueId())) regionsVisited.put(player.getUniqueId(), new ArrayList<>()); RegionContainer container = worldGuard.getWorldGuard().getRegionContainer(); RegionManager manager = container.get(player.getWorld()); if (manager == null) return; ApplicableRegionSet regions = manager.getApplicableRegions(event.getTo()); List<ProtectedRegion> visited = regionsVisited.get(player.getUniqueId()); try { for (ProtectedRegion region : regions.getRegions()) { if (!visited.contains(region)) { // i've never seen this place before in my life... or maybe in 30 seconds visited.add(region); Bukkit.getScheduler() .runTaskLaterAsynchronously( JavaPlugin.getPlugin(Tyrant.class), () -> enter(player, region), 1); } } Bukkit.getScheduler() .runTaskLater( JavaPlugin.getPlugin(Tyrant.class), () -> { for (ProtectedRegion region2 : visited) { if (!regions.getRegions().contains(region2)) { // leaving the tavern visited.remove(region2); Bukkit.getScheduler() .runTaskLaterAsynchronously( JavaPlugin.getPlugin(Tyrant.class), () -> exit(player), 1); } } }, 1); } catch (ConcurrentModificationException e) { e.printStackTrace(); } }
/** * Check if a player has permission to build at a location. * * @param player * @param loc * @return */ public boolean canBuild(Player player, Location loc) { World world = loc.getWorld(); WorldConfiguration worldConfig = config.get(world); if (!worldConfig.useRegions) { return true; } LocalPlayer localPlayer = plugin.wrapPlayer(player); if (!hasBypass(player, world)) { RegionManager mgr = get(world); if (!mgr.getApplicableRegions(BukkitUtil.toVector(loc)).canBuild(localPlayer)) { return false; } } return true; }
/** * Called when a block is destroyed from burning * * @param event Relevant event details */ @Override public void onBlockBurn(BlockBurnEvent event) { if (event.isCancelled()) { return; } ConfigurationManager cfg = plugin.getGlobalConfiguration(); WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld()); if (wcfg.disableFireSpread) { event.setCancelled(true); return; } if (wcfg.fireSpreadDisableToggle) { event.setCancelled(true); return; } if (wcfg.disableFireSpreadBlocks.size() > 0) { Block block = event.getBlock(); if (wcfg.disableFireSpreadBlocks.contains(block.getTypeId())) { event.setCancelled(true); return; } } if (wcfg.useRegions) { Block block = event.getBlock(); Vector pt = toVector(block); RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld()); ApplicableRegionSet set = mgr.getApplicableRegions(pt); if (!set.allows(DefaultFlag.FIRE_SPREAD)) { event.setCancelled(true); return; } } }
public void buyRegion(Player sender, String[] args) { if (!sender.hasPermission("iceprotect.buy")) { sender.sendMessage(ChatColor.RED + "You don't have permission!"); return; } if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } String id = "icp__tempregion"; Location loc = sender.getLocation(); BlockVector min = new BlockVector(loc.getX() - 1, loc.getY() - 1, loc.getZ() - 1); BlockVector max = new BlockVector(loc.getX() + 1, loc.getY() + 1, loc.getZ() + 1); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); RegionManager mgr = plugin.getGlobalRegionManager().get(sender.getWorld()); ApplicableRegionSet regions = mgr.getApplicableRegions(region); ProtectedRegion appReg = null; for (ProtectedRegion r : regions) { if (econ.isRegionForSale(r.getId())) { appReg = r; break; } } if (appReg == null) { sender.sendMessage(ChatColor.RED + "No nearby regions for sale!"); return; } econ.buyRegion(appReg, sender, mgr); }
protected static boolean inAnyArea(Player sender) { RegionManager rm = RegionTeleport.getWorldGuard().getRegionManager(sender.getWorld()); ApplicableRegionSet set = rm.getApplicableRegions(sender.getLocation()); return set.size() > 0; }
protected static String getAreaName(Player sender) { RegionManager rm = RegionTeleport.getWorldGuard().getRegionManager(sender.getWorld()); ApplicableRegionSet set = rm.getApplicableRegions(sender.getLocation()); String id = set.iterator().next().getId(); return id; }
public void setRegion(Player sender, String[] args) { if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } LocalPlayer wgPlayer = plugin.wrapPlayer(sender); String id = "icp_" + sender.getName() + "_" + args[1]; if (!ProtectedRegion.isValidId(id)) { sender.sendMessage(ChatColor.RED + "Invalid region name specified!"); return; } Selection sel = worldEdit.getSelection(sender); if (sel == null) { sender.sendMessage(ChatColor.RED + "Select a region with a wooden axe first."); return; } RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld()); if (mgr.hasRegion(id)) { sender.sendMessage( ChatColor.RED + "That region name is already taken. Please choose a new name."); return; } int regionCount = mgr.getRegionCountOfPlayer(wgPlayer); if (regionCount > Economy.maxDonatorAllowedRegions && !sender.isOp() && sender.hasPermission("iceprotect.freeprotect")) { sender.sendMessage( ChatColor.RED + "You have reached the maximum allowed regions per user (" + Economy.maxDonatorAllowedRegions + ")."); sender.sendMessage(ChatColor.RED + "Please contact an admin."); return; } ProtectedRegion region = null; if (sel instanceof Polygonal2DSelection) { Polygonal2DSelection polySel = (Polygonal2DSelection) sel; int minY = polySel.getNativeMinimumPoint().getBlockY(); int maxY = polySel.getNativeMaximumPoint().getBlockY(); region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY); } else if (sel instanceof CuboidSelection) { BlockVector min = sel.getNativeMinimumPoint().toBlockVector(); BlockVector max = sel.getNativeMaximumPoint().toBlockVector(); region = new ProtectedCuboidRegion(id, min, max); } else { sender.sendMessage( ChatColor.RED + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!"); return; } String[] names = new String[1]; names[0] = sender.getName(); region.setOwners(RegionUtil.parseDomainString(names, 0)); ApplicableRegionSet regions = mgr.getApplicableRegions(region); if (!regions.isOwnerOfAll(wgPlayer)) { sender.sendMessage(ChatColor.RED + "That region overlaps with another one not owned by you!"); return; } double cost = (int) Math.ceil(econ.getCost(region.volume())); if (cost > Economy.maxDonatorAllowedCost && sender.hasPermission("iceprotect.freeprotect")) { sender.sendMessage( ChatColor.RED + "You have exceeded the maximum allowed price for this region!"); sender.sendMessage( ChatColor.RED + "Cost: " + ChatColor.GRAY + "$" + cost + ChatColor.RED + ", " + ChatColor.GRAY + "$" + Economy.maxDonatorAllowedCost + " allowed."); return; } if (!sender.hasPermission("iceprotect.freeprotect") && !econ.chargePlayer(sender, cost)) { sender.sendMessage(ChatColor.RED + "You don't have enough money! $" + cost + " needed."); return; } mgr.addRegion(region); try { mgr.save(); sender.sendMessage( ChatColor.YELLOW + "Region saved as " + args[1] + ". " + (sender.hasPermission("iceprotect.freeprotect") ? "" : "Cost: $" + cost + ".")); } catch (IOException e) { sender.sendMessage( ChatColor.RED + "(shouldn't happen) Failed to write regions file: " + e.getMessage()); e.printStackTrace(); return; } }
/* * Called when a block gets ignited. */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockIgnite(BlockIgniteEvent event) { IgniteCause cause = event.getCause(); Block block = event.getBlock(); World world = block.getWorld(); ConfigurationManager cfg = plugin.getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(world); if (cfg.activityHaltToggle) { event.setCancelled(true); return; } boolean isFireSpread = cause == IgniteCause.SPREAD; if (wcfg.preventLightningFire && cause == IgniteCause.LIGHTNING) { event.setCancelled(true); return; } if (wcfg.preventLavaFire && cause == IgniteCause.LAVA) { event.setCancelled(true); return; } if (wcfg.disableFireSpread && isFireSpread) { event.setCancelled(true); return; } if (wcfg.blockLighter && (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL) && event.getPlayer() != null && !plugin.hasPermission(event.getPlayer(), "worldguard.override.lighter")) { event.setCancelled(true); return; } if (wcfg.fireSpreadDisableToggle && isFireSpread) { event.setCancelled(true); return; } if (wcfg.disableFireSpreadBlocks.size() > 0 && isFireSpread) { int x = block.getX(); int y = block.getY(); int z = block.getZ(); if (wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y - 1, z)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x + 1, y, z)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x - 1, y, z)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y, z - 1)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y, z + 1))) { event.setCancelled(true); return; } } if (wcfg.useRegions) { Vector pt = toVector(block); Player player = event.getPlayer(); RegionManager mgr = plugin.getGlobalRegionManager().get(world); ApplicableRegionSet set = mgr.getApplicableRegions(pt); if (player != null && !plugin.getGlobalRegionManager().hasBypass(player, world)) { LocalPlayer localPlayer = plugin.wrapPlayer(player); // this is preliminarily handled in the player listener under handleBlockRightClick // why it's handled here too, no one knows if (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL) { if (!set.allows(DefaultFlag.LIGHTER) && !set.canBuild(localPlayer) && !plugin.hasPermission(player, "worldguard.override.lighter")) { event.setCancelled(true); return; } } } if (wcfg.highFreqFlags && isFireSpread && !set.allows(DefaultFlag.FIRE_SPREAD)) { event.setCancelled(true); return; } if (wcfg.highFreqFlags && cause == IgniteCause.LAVA && !set.allows(DefaultFlag.LAVA_FIRE)) { event.setCancelled(true); return; } if (cause == IgniteCause.FIREBALL && event.getPlayer() == null) { // wtf bukkit, FIREBALL is supposed to be reserved to players if (!set.allows(DefaultFlag.GHAST_FIREBALL)) { event.setCancelled(true); return; } } if (cause == IgniteCause.LIGHTNING && !set.allows(DefaultFlag.LIGHTNING)) { event.setCancelled(true); return; } } }
protected static void claim(String regionname, CommandSender sender) throws CommandException { Player player = WGExtender.getInstance().getWorldGuard().checkPlayer(sender); LocalPlayer localPlayer = WGExtender.getInstance().getWorldGuard().wrapPlayer(player); RegionPermissionModel permModel = getPermissionModel(sender); if (!permModel.mayClaim()) { throw new CommandPermissionsException(); } String id = checkRegionId(regionname, false); RegionManager manager = checkRegionManager(WGExtender.getInstance().getWorldGuard(), player.getWorld()); checkRegionDoesNotExist(manager, id, false); ProtectedRegion region = checkRegionFromSelection(player, id); WorldConfiguration wcfg = WGExtender.getInstance().getWorldGuard().getGlobalStateManager().get(player.getWorld()); if (!permModel.mayClaimRegionsUnbounded()) { int maxRegionCount = wcfg.getMaxRegionCount(player); if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(localPlayer) >= maxRegionCount) { throw new CommandException( "У вас слишком много регионов, удалите один из них перед тем как заприватить новый."); } } ProtectedRegion existing = manager.getRegion(id); if (existing != null) { if (!existing.getOwners().contains(localPlayer)) { throw new CommandException("Регион уже существует, и вы им не владеете."); } } ApplicableRegionSet regions = manager.getApplicableRegions(region); if (regions.size() > 0) { if (!regions.isOwnerOfAll(localPlayer)) { throw new CommandException("Это регион перекрывает чужой регион."); } } else { if (wcfg.claimOnlyInsideExistingRegions) { throw new CommandException("Вы можете приватить только внутри своих регионов."); } } if (wcfg.maxClaimVolume >= Integer.MAX_VALUE) { throw new CommandException( "The maximum claim volume get in the configuration is higher than is supported. " + "Currently, it must be " + Integer.MAX_VALUE + " or smaller. Please contact a server administrator."); } if (!permModel.mayClaimRegionsUnbounded()) { if (region instanceof ProtectedPolygonalRegion) { throw new CommandException("Полигональные регионы не поддерживаются."); } if (region.volume() > wcfg.maxClaimVolume) { player.sendMessage(ChatColor.RED + "Размер региона слишком большой."); player.sendMessage( ChatColor.RED + "Максимальный размер: " + wcfg.maxClaimVolume + ", ваш размер: " + region.volume()); return; } } RegionAdder task = new RegionAdder(WGExtender.getInstance().getWorldGuard(), manager, region); task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY); task.setOwnersInput(new String[] {player.getName()}); try { task.call(); sender.sendMessage(ChatColor.YELLOW + "Вы заприватили регион " + id); } catch (Exception e) { sender.sendMessage(ChatColor.YELLOW + "Произошла ошибка при привате региона " + id); e.printStackTrace(); } }
/** Called when a block gets ignited. */ @Override public void onBlockIgnite(BlockIgniteEvent event) { if (event.isCancelled()) { return; } IgniteCause cause = event.getCause(); Block block = event.getBlock(); World world = block.getWorld(); ConfigurationManager cfg = plugin.getGlobalConfiguration(); WorldConfiguration wcfg = cfg.get(world); boolean isFireSpread = cause == IgniteCause.SPREAD; if (wcfg.preventLightningFire && cause == IgniteCause.LIGHTNING) { event.setCancelled(true); return; } if (wcfg.preventLavaFire && cause == IgniteCause.LAVA) { event.setCancelled(true); return; } if (wcfg.disableFireSpread && isFireSpread) { event.setCancelled(true); return; } /* if (wcfg.blockLighter && cause == IgniteCause.FLINT_AND_STEEL) { event.setCancelled(true); return; } */ if (wcfg.fireSpreadDisableToggle && isFireSpread) { event.setCancelled(true); return; } if (wcfg.disableFireSpreadBlocks.size() > 0 && isFireSpread) { int x = block.getX(); int y = block.getY(); int z = block.getZ(); if (wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y - 1, z)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x + 1, y, z)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x - 1, y, z)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y, z - 1)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y, z + 1))) { event.setCancelled(true); return; } } if (wcfg.useRegions) { Vector pt = toVector(block); Player player = event.getPlayer(); RegionManager mgr = plugin.getGlobalRegionManager().get(world); ApplicableRegionSet set = mgr.getApplicableRegions(pt); if (player != null && !plugin.getGlobalRegionManager().hasBypass(player, world)) { LocalPlayer localPlayer = plugin.wrapPlayer(player); if (cause == IgniteCause.FLINT_AND_STEEL && !set.canBuild(localPlayer)) { event.setCancelled(true); return; } if (cause == IgniteCause.FLINT_AND_STEEL && !set.allows(DefaultFlag.LIGHTER)) { event.setCancelled(true); return; } } if (wcfg.highFreqFlags && isFireSpread && !set.allows(DefaultFlag.FIRE_SPREAD)) { event.setCancelled(true); return; } if (wcfg.highFreqFlags && cause == IgniteCause.LAVA && !set.allows(DefaultFlag.LAVA_FIRE)) { event.setCancelled(true); return; } } }
public void collect(Player player, List<ItemStack> itemDrops, EntityDeathEvent event) { if (itemDrops.isEmpty() && !levelAllow(player) && !expAllow(player)) { return; } if (plugin.config.dropOnPVPDeath() && player.getKiller() instanceof Player) { plugin.message(player, plugin.config.msgPVPDeath()); return; } if (plugin.config.residence()) { ClaimedResidence res = Residence.getResidenceManager().getByLoc(player.getLocation()); if (res != null) { ResidencePermissions perms = res.getPermissions(); if (perms.playerHas(player.getName(), plugin.config.resFlag(), true)) { plugin.logDebug( "Player '" + player.getName() + "' is not allowed to use Scavenger in this residence. Items will be dropped."); plugin.message(player, plugin.config.msgInsideRes()); return; } else { plugin.logDebug( "Player '" + player.getName() + "' is allowed to use Scavenger in this residence."); } } } if (plugin.config.factionEnemyDrops() && plugin.factionHook != null) { if (plugin.factionHook.isPlayerInEnemyFaction(player)) { return; } } if (plugin.config.dungeonMazeDrops() && plugin.dmHook != null) { plugin.logDebug("Checking if '" + player.getName() + "' is in DungeonMaze."); if (plugin.dmHook.isPlayerInDungeon(player)) { plugin.logDebug("Player '" + player.getName() + "' is in DungeonMaze."); plugin.message(player, plugin.config.msgInsideDungeonMaze()); return; } } if (plugin.getWorldGuard() != null) { plugin.logDebug("Checking region support for '" + player.getWorld().getName() + "'"); if (plugin.getWorldGuard().getRegionManager(player.getWorld()) != null) { try { RegionManager regionManager = plugin.getWorldGuard().getRegionManager(player.getWorld()); ApplicableRegionSet set = regionManager.getApplicableRegions(player.getLocation()); if (set.allows(DefaultFlag.PVP) && plugin.config.wgPVPIgnore()) { plugin.logDebug( "This is a WorldGuard PVP zone and WorldGuardPVPIgnore is " + plugin.config.wgPVPIgnore()); if (!plugin.config.msgInsideWGPVP().isEmpty()) { plugin.message(player, plugin.config.msgInsideWGPVP()); } return; } if (!set.allows(DefaultFlag.PVP) && plugin.config.wgGuardPVPOnly()) { plugin.logDebug( "This is NOT a WorldGuard PVP zone and WorldGuardPVPOnly is " + plugin.config.wgGuardPVPOnly()); if (!plugin.config.msgInsideWGPVP().isEmpty()) { plugin.message(player, plugin.config.msgInsideWGPVPOnly()); } return; } } catch (NullPointerException ex) { plugin.logDebug(ex.getMessage()); } } else { plugin.logDebug("Region support disabled for '" + player.getWorld().getName() + "'"); } } if (plugin.getUltimateArena() != null) { if (UltimateArenaAPI.hookIntoUA(plugin).isInArena(player)) { if (!plugin.config.msgInsideUA().isEmpty()) { plugin.message(player, plugin.config.msgInsideUA()); } return; } } if (plugin.maHandler != null && plugin.maHandler.isPlayerInArena(player)) { if (!plugin.config.msgInsideMA().isEmpty()) { plugin.message(player, plugin.config.msgInsideMA()); } return; } if (plugin.pvpHandler != null && !PVPArenaAPI.getArenaName(player).equals("")) { String x = plugin.config.msgInsidePA(); if (!x.isEmpty()) { x = x.replace("%ARENA%", PVPArenaAPI.getArenaName(player)); plugin.message(player, x); } return; } if (plugin.battleArena) { mc.alk.arena.objects.ArenaPlayer ap = mc.alk.arena.BattleArena.toArenaPlayer(player); if (ap != null) { Match match = BattleArena.getBAController().getMatch(ap); if (match != null) { if (match.isInMatch(ap)) { String x = plugin.config.msgInsideBA(); if (!x.isEmpty()) { plugin.message(player, x); } return; } } } } if (plugin.minigames != null) { if (plugin.minigames.playerInMinigame(player)) { plugin.logDebug( "Player '" + player.getName() + "' is in a Minigame. Not recovering items."); return; } } if (hasRestoration(player)) { plugin.error(player, "Restoration already exists, ignoring."); return; } if (plugin.getEconomy() != null && !(player.hasPermission(PERM_FREE) || (player.isOp() && plugin.config.opsAllPerms())) && plugin.config.economyEnabled()) { NumberFormat formatter = NumberFormat.getInstance(new Locale(plugin.config.countryCode())); formatter.setMaximumFractionDigits(plugin.config.decimalPlaces()); double restoreCost = plugin.config.restoreCost(); double withdrawAmount; double playerBalance = plugin.getEconomy().getBalance(player); double percentCost = plugin.config.percentCost(); double minCost = plugin.config.minCost(); double maxCost = plugin.config.maxCost(); EconomyResponse er; String currency; if (plugin.config.percent()) { if (playerBalance < 0) { withdrawAmount = 0; } else { withdrawAmount = playerBalance * (percentCost / 100.0); } plugin.logDebug("withdrawAmount: " + withdrawAmount); plugin.logDebug("playeBalance: " + playerBalance); plugin.logDebug("percentCost: " + percentCost + "(" + (percentCost / 100.0) + ")"); if (plugin.config.addMin()) { withdrawAmount = withdrawAmount + minCost; plugin.logDebug("withdrawAmount (addMin): " + withdrawAmount); } else if (withdrawAmount < minCost) { withdrawAmount = minCost; } if (withdrawAmount > maxCost && maxCost > 0) { withdrawAmount = maxCost; } } else { withdrawAmount = restoreCost; } er = plugin.getEconomy().withdrawPlayer(player, withdrawAmount); if (er.transactionSuccess()) { plugin.logDebug("Withdraw success!"); if (withdrawAmount == 1) { currency = plugin.getEconomy().currencyNameSingular(); } else { currency = plugin.getEconomy().currencyNamePlural(); } String x = plugin.config.msgSaveForFee(); if (!x.isEmpty()) { x = x.replace("%COST%", formatter.format(withdrawAmount)); x = x.replace("%CURRENCY%", currency); plugin.message(player, x); } if (!plugin.config.depositDestination().isEmpty()) { plugin.logDebug("DepositDesination: " + plugin.config.depositDestination()); if (plugin.config.depositType().equalsIgnoreCase("bank")) { plugin.logDebug("DepositType: BANK"); if (plugin.getEconomy().hasBankSupport()) { plugin.logDebug("Bank support is enabled"); plugin.getEconomy().bankDeposit(plugin.config.depositDestination(), withdrawAmount); } else { plugin.logDebug("Bank support is NOT enabled"); } } else if (plugin.config.depositType().equalsIgnoreCase("player")) { plugin.logDebug("DepositType: PLAYER"); plugin.logDebug("DepositDestination: " + plugin.config.depositDestination()); if (plugin.getEconomy().hasAccount(plugin.config.depositDestination())) { plugin.logDebug("DepositDestination: VALID"); plugin.getEconomy().depositPlayer(plugin.config.depositDestination(), withdrawAmount); } else { plugin.logDebug("DepositDestination: INVALID"); } } else { plugin.logDebug("DepositType: INVALID"); } } else { plugin.logDebug("No deposit destination!"); } } else { plugin.logDebug("Withdraw fail! " + er.errorMessage); if (playerBalance == 1) { currency = plugin.getEconomy().currencyNameSingular(); } else { currency = plugin.getEconomy().currencyNamePlural(); } String x = plugin.config.msgNotEnoughMoney(); if (!x.isEmpty()) { x = x.replace("%BALANCE%", formatter.format(playerBalance)); x = x.replace("%COST%", formatter.format(withdrawAmount)); x = x.replace("%CURRENCY%", currency); x = x.replace("%ERRORMESSAGE%", er.errorMessage); plugin.message(player, x); } return; } } else { plugin.message(player, plugin.config.msgSaving()); } Restoration restoration = new Restoration(); restoration.enabled = false; // temporary fix for 1.9 restoration.inventory = Arrays.copyOfRange(player.getInventory().getContents(), 0, 36); restoration.armour = player.getInventory().getArmorContents(); if (plugin.isMc19or110()) { restoration.offHand = player.getInventory().getItemInOffHand(); } restoration.playerName = player.getDisplayName(); itemDrops.clear(); if (levelAllow(player)) { plugin.logDebug("Collecting level " + player.getLevel() + " for " + player.getName()); restoration.level = player.getLevel(); } if (expAllow(player)) { plugin.logDebug("Collecting exp " + player.getExp() + " for " + player.getName()); restoration.exp = player.getExp(); event.setDroppedExp(0); } String deathCause = "NULL"; if (player.getLastDamageCause() != null) { if (player.getLastDamageCause().getCause() != null) { deathCause = player.getLastDamageCause().getCause().toString(); } } String deathCausePermission = PERM_SCAVENGE_PREFIX + deathCause; plugin.logDebug( "[p:" + player.getName() + "] [" + PERM_SCAVENGE + ":" + player.hasPermission(PERM_SCAVENGE) + "]" + " [" + deathCausePermission + ":" + player.hasPermission(deathCausePermission) + "]"); if (player.hasPermission(PERM_SCAVENGE) || player.hasPermission(deathCausePermission)) { plugin.logDebug("Permissions are okay. Time to scavenge..."); if (plugin.config.chanceToDrop() > 0 && !player.hasPermission(PERM_NO_CHANCE)) { checkChanceToDropItems(restoration.armour, itemDrops); checkChanceToDropItems(restoration.inventory, itemDrops); if (plugin.isMc19or110()) { checkChanceToDropItems(restoration.offHand, itemDrops); } } if (plugin.config.singleItemDrops()) { checkSingleItemDrops(player, restoration.armour, itemDrops); checkSingleItemDrops(player, restoration.inventory, itemDrops); checkSingleItemDrops(player, restoration.offHand, itemDrops); } else if (plugin.config.singleItemKeeps()) { checkSingleItemKeeps(player, "armour", restoration.armour, itemDrops); checkSingleItemKeeps(player, "inv", restoration.inventory, itemDrops); if (plugin.isMc19or110()) { checkSingleItemKeeps(player, "offhand", restoration.offHand, itemDrops, 1); } } else if (plugin.config.slotBasedRecovery()) { checkSlots(player, "armour", restoration.armour, itemDrops); checkSlots(player, "inv", restoration.inventory, itemDrops); if (plugin.isMc19or110()) { checkSlots(player, "offhand", restoration.offHand, itemDrops, 1); } } } else { plugin.logDebug("Permissions are NOT okay. Dropping items..."); dropItems(restoration.armour, itemDrops); dropItems(restoration.inventory, itemDrops); dropItem(restoration.offHand, itemDrops); } addRestoration(player, restoration); }