/**
   * Creates a new GraveYardSign / SpawnChest with the given {@link PlayerDropModificator}
   *
   * @param piMod
   * @return the list of Items NOT saved
   */
  public List<ItemStack> createSpawnContainer(PlayerDropModificator piMod) {
    Player player = piMod.getPlayer();
    piMod.modifyForSpawnContainer();

    World world = piMod.getPlayer().getWorld();
    if (worldIsOnIgnore(world)) {
      return piMod.getTransferredItems();
    }

    if (!DeathChest.getPlugin()
        .getPermissionsManager()
        .checkPermissionsSilent(player, PermissionNode.spawnChest)) {
      return (piMod.getTransferredItems());
    }

    Class<?> clazz = plugin.getConfigManager().getSpawnContainerUsage();

    if (clazz == null) return piMod.getTransferredItems();

    if (clazz.equals(SpawnChest.class)) return spawnChest(piMod);

    if (clazz.equals(SpawnSign.class)) return createSign(piMod);

    return null;
  }
示例#2
0
  @EventHandler
  public void onPlayerDeath(PlayerDeathEvent event) {
    if (plugin.isBattleNight(event.getEntity())) return;

    boolean filledDeathChest = false;
    boolean filledSpawnChest = false;

    int originalDrops = event.getDrops().size();

    if (event.getDrops().isEmpty() && event.getDroppedExp() == 0) return;
    Player player = (Player) event.getEntity();

    int exp = player.getTotalExperience();

    LinkedList<ItemStack> toRemove = saveToDeathChest(player);
    filledDeathChest = !toRemove.isEmpty();

    if (exp != player.getTotalExperience()) {
      event.setDroppedExp(0);
    }

    for (ItemStack item : toRemove) event.getDrops().remove(item);

    if (event.getDrops().isEmpty()
        && (event.getDroppedExp() == 0 || plugin.getConfigManager().getEXPMulti() == 0)) return;

    if (!event.getDrops().isEmpty() || player.getTotalExperience() != 0) {
      toRemove = plugin.interactSpawnContainerController().createSpawnContainer(player);

      if (plugin.getConfigManager().getSpawnContainerUsage().equals(SpawnSign.class)
          && player.getTotalExperience() != exp) event.setDroppedExp(0);

      if (toRemove != null) {
        filledSpawnChest = !toRemove.isEmpty();

        for (ItemStack item : toRemove) event.getDrops().remove(item);
      }
    }

    if (event.getDrops().size() > 0 && filledDeathChest) {
      int maxTransfer = plugin.getChestContainer().getMaxTransferLimit(player);
      if (originalDrops > maxTransfer)
        player.sendMessage(
            ChatColor.RED
                + "Only "
                + maxTransfer
                + " items could be transfered. The rest is dropped at your death location.");
      else
        player.sendMessage(
            ChatColor.RED
                + "Your total inventory did not fit in the box. The rest items were dropped at your death location.");
    }

    if (!filledDeathChest && !filledSpawnChest && simplePermissionUse(player))
      player.sendMessage(ChatColor.RED + "You don't have a Chest set yet. Sorry for you. :(");
  }
示例#3
0
  /**
   * saves the PlayerInventory to his deathChest returns an empty list if player has no Permission
   * or no DeathChest exists for the player
   *
   * @param player
   * @return the list of Items saved
   */
  private LinkedList<ItemStack> saveToDeathChest(Player player) {
    LinkedList<ItemStack> emptyReturnList = new LinkedList<ItemStack>();

    if (!simplePermissionUse(player)) return emptyReturnList;

    ChestContainer container = plugin.getChestContainer();
    if (!container.checkPlayerHasChest(player.getWorld(), player)) {
      return emptyReturnList;
    }

    int maxTransferItems = plugin.getChestContainer().getMaxTransferLimit(player);
    if (maxTransferItems <= 0) return emptyReturnList;

    ChestContainer chestContainer = container.getChestOfPlayer(player.getWorld(), player);

    ChestPosition chestPos = (ChestPosition) chestContainer;
    Location chestLocation = chestPos.getLocation();

    Block chestBlock = chestLocation.getBlock();

    if (chestBlock.getType() != Material.CHEST) {
      player.sendMessage(
          ChatColor.RED
              + "No chest found at Position: "
              + "X: "
              + chestLocation.getBlockX()
              + "Y: "
              + chestLocation.getBlockY()
              + "Z: "
              + chestLocation.getBlockZ());
      return emptyReturnList;
    }

    double multiplicator = plugin.getConfigManager().getEXPMulti();
    int totalExperience = (int) (player.getTotalExperience() * multiplicator);
    chestPos.addEXP(totalExperience);

    if (multiplicator != 0) player.setTotalExperience(0);

    LinkedList<ItemStack> toRemove =
        copyInventoryToChest((Chest) chestBlock.getState(), false, player);
    player.sendMessage(
        ChatColor.GREEN
            + "Your inventory was stored in your DeathChest on world: "
            + chestLocation.getWorld().getName()
            + ".");
    return toRemove;
  }
 /**
  * Creates a new GraveYardSign with the given {@link PlayerDropModificator}
  *
  * @param piMod
  * @return the List of Items NOT saved
  */
 public List<ItemStack> createSign(PlayerDropModificator piMod) {
   Player player = piMod.getPlayer();
   SpawnSign sign = new SpawnSign(piMod).spawnSign();
   signs.add(sign);
   if (plugin.getConfigManager().getEXPMulti() >= 0) player.setTotalExperience(0);
   return new LinkedList<ItemStack>();
 }
  public SpawnContainerController() {
    plugin = DeathChest.getPlugin();
    signs = new ArrayList<SpawnSign>();
    chests = new ArrayList<SpawnChest>();
    new SpawnContainerTicker();

    loadAllSigns();
    RandomText.createDefaults();
  }
  /** Loads all GraveYardSigns saved in the Data-Path */
  public void loadAllSigns() {
    File file = new File(plugin.getDataFolder() + File.separator + "gravestones" + File.separator);
    if (!file.exists()) return;

    // File filter for directories
    FileFilter fileFilter =
        new FileFilter() {
          public boolean accept(File file) {
            return file.isFile();
          }
        };

    for (File possibleSign : file.listFiles(fileFilter)) {
      SpawnSign sign = SpawnSign.loadSign(possibleSign.toString());
      if (sign != null) signs.add(sign);
    }

    if (signs.size() != 0) plugin.log("loaded " + signs.size() + " graves");
  }
  private boolean worldIsOnIgnore(World world) {
    String worldName = world.getName();

    for (String ignoreWorld : plugin.getConfigManager().getDisableSpawnContainerInWorlds()) {
      if (ignoreWorld.equals(worldName)) {
        return true;
      }
    }

    return false;
  }
示例#8
0
 private boolean simplePermissionUse(Player player) {
   return plugin
       .getPermissionsManager()
       .hasAnyPermissionSilent(player, PermissionNode.simpleUseArray);
 }
 @Override
 public void run() {
   plugin.interactSpawnContainerController().tick();
 }
 public SpawnContainerTicker() {
   plugin = DeathChest.getPlugin();
   Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this, 20, 20);
 }