Package simpleserver.nbt.Inventory

Examples of simpleserver.nbt.Inventory.Slot


    }
  }

  public void execute(Player player, String message) {
    String[] parts = message.trim().split(" ");
    Slot item;
    if (parts.length == 1) {
      if ((item = getSessionItem(player, false)) == null) {
        player.addTMessage(Color.GRAY, "You have to select an item to enchant first.");
        player.addTMessage(Color.GRAY, "Use: %s%s ITEM", commandPrefix(), name);
      } else {
        chatItem(player, item);
      }
    } else if (parts[1].equals("add")) {
      if ((item = getSessionItem(player)) == null) {
        return;
      }
      boolean changed = false;
      for (int i = 2; i < parts.length; i++) {
        String[] ench = parts[i].split(":");
        try {
          Integer id = Integer.valueOf(ench[0]);
          int level = 10;
          if (ench.length >= 2) {
            level = Integer.valueOf(ench[1]);
            if (level < 1 || level > 10) {
              player.addTMessage(Color.RED, "The enchantment level must be between 1 and 10");
              continue;
            }
          }
          if (!availableEnchantments(item).contains(id)) {
            if (ENCHANTMENTS.containsKey(Integer.valueOf(id))) {
              player.addTMessage(Color.RED, "%s is not available for the current item", ENCHANTMENTS.get(id));
            } else {
              player.addTMessage(Color.RED, "No enchantment with id %s exists.", id);
            }

          } else {
            item.addEnchantment(new Enchantment(id, level));
            changed = true;
          }
        } catch (NumberFormatException e) {
          player.addTMessage(Color.RED, "%s is not a valid enchantment", parts[i]);
        }
      }
      if (changed) {
        chatItem(player, item);
      }
    } else if (parts[1].equals("remove")) {
      if ((item = getSessionItem(player)) == null) {
        return;
      }
      boolean changed = false;
      for (int i = 2; i < parts.length; i++) {
        try {
          Integer id = Integer.valueOf(parts[i]);
          if (!item.enchantedWith(id)) {
            player.addTMessage(Color.RED, "The item was not enchanted with %s", (ENCHANTMENTS.containsKey(id) ? ENCHANTMENTS.get(id) : id));
          } else {
            item.removeEnchantment(id);
            changed = true;
          }
        } catch (NumberFormatException e) {
          player.addTMessage(Color.RED, "%s is not a valid enchantment", parts[i]);
        }
      }
      if (changed) {
        chatItem(player, item);
      }
    } else if (parts[1].equals("spawn") || parts[1].equals("give")) {
      if ((item = getSessionItem(player)) == null) {
        return;
      }
      Giver bot = new Giver(player);
      bot.add(item);
      try {
        player.getServer().bots.connect(bot);
      } catch (ConnectException e) {
        player.addTMessage(Color.RED, "An unknown error occured");
      }
    } else {
      int id = 0;
      if (parts.length == 2) {
        try {
          id = Integer.valueOf(parts[1]);
        } catch (NumberFormatException e) {
          GiveAliasList alias = player.getServer().giveAliasList;
          Item itemAlias = alias.getItemId(parts[1]);
          if (itemAlias == null) {
            Suggestion correctName = alias.findWithLevenshtein(parts[1]);
            if (correctName.distance < 4) {
              id = alias.getItemId(correctName.name).id;
            }
          } else {
            id = itemAlias.id;
          }
        }
      } else {
        String name = WordUtils.capitalize(extractArgument(message));
        if (ITEMS.containsValue(name)) {
          for (Integer itemID : ITEMS.keySet()) {
            if (ITEMS.get(itemID).equals(name)) {
              id = itemID;
              break;
            }
          }
        }
      }
      if (id == 0) {
        player.addTMessage(Color.RED, "Can't find item");
      } else if (!ITEMS.containsKey(id)) {
        player.addTMessage(Color.RED, "This item is not enchantable");
      } else {
        item = new Slot(id);
        chatItem(player, item);
        player.addTMessage(Color.GRAY, "You can now add enchantments with %s%s%s", commandPrefix(), name, " add ID:LEVEL");
        sessions.put(player, item);
      }
    }
View Full Code Here


  protected void drop() throws IOException {
    super.ready();
    writeLock.lock();
    for (byte i = 0; i < count; i++) {
      Slot slot = inv.get(i);
      out.writeByte(0x66);
      out.writeByte(0);
      out.writeShort(Inventory.networkSlot(i));
      out.writeByte(0);
      out.writeShort(i * 2);
      out.writeBoolean(false);
      slot.write(out);
      out.flush();
      out.writeByte(0x66);
      out.writeByte(0);
      out.writeShort(-999);
      out.writeByte(0);
View Full Code Here

TOP

Related Classes of simpleserver.nbt.Inventory.Slot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.