Exemplo n.º 1
0
  public boolean fuelCheck(Player player, Material single, Material block) {

    Inventory fuelInventory = getFuelInventory(player);
    ItemStack rocketBoots = player.getInventory().getBoots();

    int fuelCost = 0;

    switch (rocketBoots.getType()) {
      case LEATHER_BOOTS:
        fuelCost = 1 + getBootPowerLevel(rocketBoots);
        break;

      case IRON_BOOTS:
        fuelCost = 2 + getBootPowerLevel(rocketBoots);
        break;

      case GOLD_BOOTS:
        fuelCost = 3 + getBootPowerLevel(rocketBoots);
        break;

      case DIAMOND_BOOTS:
        fuelCost = 4 + getBootPowerLevel(rocketBoots);
        break;
    }

    if (fuelInventory.containsAtLeast(new ItemStack(block), fuelCost)) return true;
    if (fuelInventory.containsAtLeast(new ItemStack(single), fuelCost)) return true;

    commonString.messageSend(
        RocketInit.getPlugin(),
        player,
        true,
        RocketLanguage.FuelRequired(single.name().toLowerCase()));
    RocketInit.rocketTimeout.add(player.getUniqueId());

    new BukkitRunnable() {
      int c = 5;

      @Override
      public void run() {
        if (c <= 0) {
          RocketInit.rocketTimeout.remove(player.getUniqueId());
          this.cancel();
          return;
        }
        player.setFlying(false);
        c--;
      }
    }.runTaskTimer(RocketInit.getPlugin(), 0, 20);

    return false;
  }
  @SuppressWarnings("deprecation")
  private boolean removeItems(Player player, int amount) {
    Inventory inv = player.getInventory();
    ItemStack item =
        new ItemStack(DragonTravel.getInstance().getConfigHandler().getPaymentItemType(), amount);

    ItemMeta im = item.getItemMeta();
    if (!DragonTravel.getInstance()
        .getConfigHandler()
        .getPaymentItemName()
        .equalsIgnoreCase("<default>"))
      im.setDisplayName(
          ChatColor.translateAlternateColorCodes(
              '&', DragonTravel.getInstance().getConfigHandler().getPaymentItemName()));
    item.setItemMeta(im);

    if (inv.containsAtLeast(item, amount)) {
      Map<Integer, ItemStack> leftover = inv.removeItem(item);
      if (!leftover.isEmpty()) {
        Bukkit.getLogger()
            .warning(
                "Removing items from "
                    + player.getName()
                    + "'s inventory gave a leftover; allowing payment anyways.");
      }

      player.updateInventory();

      String message =
          DragonTravel.getInstance()
              .getMessagesHandler()
              .getMessage("Messages.Payment.Resources.Successful.WithdrawMessage");
      message = message.replace("{amount}", "%d");
      message = String.format(message, amount);
      player.sendMessage(message);
      return true;
    } else {
      player.sendMessage(
          DragonTravel.getInstance()
              .getMessagesHandler()
              .getMessage("Messages.Payment.Resources.Error.NotEnoughResources"));
      return false;
    }
  }