private boolean chestHasBlankBooks() {
   Block chest = this.getChest();
   if (Utils.isChest(chest.getType())) {
     Inventory inv = ((Chest) chest.getState()).getInventory();
     return inv.contains(Material.BOOK_AND_QUILL);
   }
   return false;
 }
Beispiel #2
0
 public static void giveTool(Player player, int type) {
   final Inventory inv = player.getInventory();
   if (inv.contains(type))
     player.sendMessage(ChatColor.RED + "You have already a " + materialName(type));
   else {
     final int free = inv.firstEmpty();
     if (free >= 0) {
       if (player.getItemInHand() != null && player.getItemInHand().getTypeId() != 0)
         inv.setItem(free, player.getItemInHand());
       player.setItemInHand(new ItemStack(type, 1));
       player.sendMessage(ChatColor.GREEN + "Here's your " + materialName(type));
     } else player.sendMessage(ChatColor.RED + "You have no empty slot in your inventory");
   }
 }
  @EventHandler
  public void gun(PlayerInteractEvent event) {
    if (!event.getPlayer().getWorld().getName().equals(getName())) return;
    if (event.getPlayer().getGameMode() == GameMode.SURVIVAL) {
      Player player = event.getPlayer();
      Location loc = player.getLocation();
      Action action = event.getAction();
      ItemStack i = player.getItemInHand();
      Inventory inv = player.getInventory();
      Material tool = i.getType();
      final World world = loc.getWorld();

      if (tool == Material.BLAZE_ROD) {

        if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {

          if (inv.contains(Material.FLINT)) {
            player.launchProjectile(Arrow.class);
            world.playSound(loc, Sound.COW_WALK, 10, 10);
            ItemStack AMMO = new ItemStack(Material.FLINT, 1);
            inv.removeItem(AMMO);

            ItemMeta ammo = AMMO.getItemMeta();
            ammo.setDisplayName(ChatColor.BLUE + "Ammunition");
            AMMO.setItemMeta(ammo);
            inv.removeItem(AMMO);

            // Make it remove normal flints, too.
            player.updateInventory();
          } else {
            world.playSound(loc, Sound.CLICK, 10, 10);
          }
        }
      }
    }
  }
 /**
  * Check whether or not the inventory contains the given material.
  *
  * @param inventory inventory to search
  * @param material material to check for
  * @return true if the inventory contains the material, false otherwise.
  */
 public static boolean contains(Inventory inventory, Material material) {
   return inventory.contains(material);
 }
Beispiel #5
0
  public static boolean isSortApplicable(String line, Minecart minecart) {
    if (line.equalsIgnoreCase("All")) {
      return true;
    }
    Entity test = minecart.getPassenger();
    Player player = null;
    if (test instanceof Player) player = (Player) test;

    if ((line.equalsIgnoreCase("Unoccupied") || line.equalsIgnoreCase("Empty"))
        && minecart.getPassenger() == null) {
      return true;
    }

    if (line.equalsIgnoreCase("Storage") && minecart instanceof StorageMinecart) {
      return true;
    } else if (line.equalsIgnoreCase("Powered") && minecart instanceof PoweredMinecart) {
      return true;
    } else if (line.equalsIgnoreCase("Minecart") && minecart instanceof Minecart) {
      return true;
    }

    if ((line.equalsIgnoreCase("Occupied") || line.equalsIgnoreCase("Full"))
        && minecart.getPassenger() != null) {
      return true;
    }

    if (line.equalsIgnoreCase("Animal") && test instanceof Animals) {
      return true;
    }

    if (line.equalsIgnoreCase("Mob") && test instanceof Monster) {
      return true;
    }

    if ((line.equalsIgnoreCase("Player") || line.equalsIgnoreCase("Ply")) && player != null) {
      return true;
    }

    String[] parts = line.split(":");

    if (parts.length >= 2) {
      if (player != null && parts[0].equalsIgnoreCase("Held")) {
        try {
          int item = Integer.parseInt(parts[1]);
          if (player.getItemInHand().getTypeId() == item) {
            return true;
          }
        } catch (NumberFormatException e) {
        }
      } else if (player != null && parts[0].equalsIgnoreCase("Ply")) {
        if (parts[1].equalsIgnoreCase(player.getName())) {
          return true;
        }
      } else if (parts[0].equalsIgnoreCase("Mob")) {
        String testMob = parts[1];
        test.toString().toLowerCase().equalsIgnoreCase(testMob);
      } else if (minecart instanceof StorageMinecart && parts[0].equalsIgnoreCase("Ctns")) {
        StorageMinecart storageCart = (StorageMinecart) minecart;
        Inventory storageInventory = storageCart.getInventory();

        if (parts.length == 3) {
          try {
            int item = Integer.parseInt(parts[1]);
            short durability = Short.parseShort(parts[2]);
            if (storageInventory.contains(new ItemStack(item, 1, durability))) {
              return true;
            }
          } catch (NumberFormatException e) {
          }
        } else {
          try {
            int item = Integer.parseInt(parts[1]);
            if (storageInventory.contains(item)) {
              return true;
            }
          } catch (NumberFormatException e) {
          }
        }
      }
    }

    return false;
  }