Пример #1
0
  public void restore(Player player) {
    if (!player.isOnline()) {
      plugin.logDebug("Player " + player.getName() + " is offline. Skipping restore...");
      return;
    }

    Restoration restoration = getRestoration(player);

    if (restoration.enabled) {
      player.getInventory().clear();

      player.getInventory().setContents(restoration.inventory);
      player.getInventory().setArmorContents(restoration.armour);
      if (plugin.isMc19or110()) {
        player.getInventory().setItemInOffHand(restoration.offHand);
      }
      if (player.hasPermission(PERM_LEVEL)
          || !plugin.config.permsEnabled()
          || (player.isOp() && plugin.config.opsAllPerms())) {
        plugin.logDebug("Player " + player.getName() + " does have " + PERM_LEVEL + " permission.");
        player.setLevel(restoration.level);
        plugin.logDebug("Player " + player.getName() + " gets " + restoration.level + " level.");
      } else {
        plugin.logDebug(
            "Player " + player.getName() + " does NOT have " + PERM_LEVEL + " permission.");
      }
      if (player.hasPermission(PERM_EXP)
          || !plugin.config.permsEnabled()
          || (player.isOp() && plugin.config.opsAllPerms())) {
        plugin.logDebug("Player " + player.getName() + " does have " + PERM_EXP + " permission.");
        player.setExp(restoration.exp);
        plugin.logDebug("Player " + player.getName() + " gets " + restoration.exp + " XP.");
      } else {
        plugin.logDebug(
            "Player " + player.getName() + " does NOT have " + PERM_EXP + " permission.");
      }
      if (plugin.config.shouldNotify()) {
        plugin.message(player, plugin.config.msgRecovered());
      }
      removeRestoration(player);
      if (hasRestoration(player)) {
        plugin.message(player, "Restore exists!!!");
      }
    }
  }
Пример #2
0
 public void cmdRestore(Player player) {
   if (player.hasPermission(PERM_RESTORE_INV)) {
     if (hasRestoration(player)) {
       Restoration restoration = getRestoration(player);
       player.getInventory().clear();
       player.getInventory().setContents(restoration.inventory);
       player.getInventory().setArmorContents(restoration.armour);
       if (plugin.isMc19or110()) {
         player.getInventory().setItemInOffHand(restoration.offHand);
       }
       player.setLevel(restoration.level);
       player.setExp(restoration.exp);
       removeRestoration(player);
     } else {
       plugin.message(player, "Nothing to restore.");
     }
   } else {
     plugin.message(player, plugin.config.msgNoPerm());
   }
 }
Пример #3
0
 public void cmdCollect(Player player) {
   if (player.hasPermission(PERM_SAVE_INV)) {
     if (plugin.config.shouldNotify()) {
       plugin.message(player, plugin.config.msgSaving());
     }
     Restoration restoration = new Restoration();
     restoration.enabled = false;
     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();
     restoration.level = player.getLevel();
     restoration.exp = player.getExp();
     player.setLevel(0);
     player.setExp(0f);
     player.getInventory().clear();
     addRestoration(player, restoration);
   } else {
     plugin.message(player, plugin.config.msgNoPerm());
   }
 }
Пример #4
0
 public void printRestorations(CommandSender sender) {
   plugin.message(sender, "Restorations:");
   for (String key : RESTORATIONS.keySet()) {
     plugin.message(sender, "  " + key);
   }
 }
Пример #5
0
  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);
  }