Example #1
0
 private PVPClass(Builder builder) {
   weapon = ItemStack.of(builder.weapon, 1);
   inventory =
       builder
           .inventory
           .stream()
           .map(pair -> ItemStack.of(pair.getA(), pair.getB()))
           .collect(Collectors.toList());
   meleModifier = builder.meleModifier;
   bowModifier = builder.bowModifier;
   projectileVelocityModifier = builder.projectileVelocity;
   icon = weapon.copy();
   List<Text> lore =
       Arrays.asList(
           Text.builder(builder.title)
               .color(TextColors.DARK_PURPLE)
               .style(TextStyles.BOLD)
               .build(),
           Text.builder(builder.description).color(TextColors.DARK_AQUA).build());
   icon.offer(Keys.ITEM_LORE, lore);
   /*
   helmet.get(Keys.ITEM_ENCHANTMENTS).get().add(new ItemEnchantment(Enchantments.PROTECTION, 1));
   chest.get(Keys.ITEM_ENCHANTMENTS).get().add(new ItemEnchantment(Enchantments.PROTECTION, 1));
   leggings.get(Keys.ITEM_ENCHANTMENTS).get().add(new ItemEnchantment(Enchantments.PROTECTION, 1));
   boots.get(Keys.ITEM_ENCHANTMENTS).get().add(new ItemEnchantment(Enchantments.PROTECTION, 1));
   */
 }
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    if (src instanceof Player) {
      Player player = (Player) src;

      if (player.getItemInHand().isPresent()) {
        ItemStack itemInHand = player.getItemInHand().get();
        player.sendMessage(
            Text.of(
                TextColors.GOLD,
                "The ID of the item in your hand is: ",
                TextColors.GRAY,
                itemInHand.getItem().getName()));
        player.sendMessage(
            Text.of(
                TextColors.GOLD,
                "The meta of the item in your hand is: ",
                TextColors.GRAY,
                itemInHand.toContainer().get(DataQuery.of("UnsafeDamage")).get().toString()));
      } else {
        player.sendMessage(
            Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must hold an item."));
      }
    } else {
      src.sendMessage(
          Text.of(
              TextColors.DARK_RED,
              "Error! ",
              TextColors.RED,
              "You must be an in-game player to use this command."));
    }

    return CommandResult.success();
  }
Example #3
0
 @Override
 @SuppressWarnings("deprecation")
 public int clear(int id, int data) {
   int removed = 0;
   for (Slot slot : this.getHandle().<Slot>slots()) {
     Optional<org.spongepowered.api.item.inventory.ItemStack> stackOptional = slot.peek();
     if (stackOptional.isPresent()) {
       org.spongepowered.api.item.inventory.ItemStack stack = stackOptional.get();
       if (id == -1 || stack.getItem() == MaterialConverter.asItem(Material.getMaterial(id))) {
         int damage = DurabilityConverter.getDamageValue(stack.getContainers());
         if (data == -1 || damage == data) {
           removed += stack.getQuantity();
           slot.clear();
         }
       }
     }
   }
   return removed;
 }
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    EntityType entityType = ctx.<EntityType>getOne("mob").get();

    if (src instanceof Player) {
      Player player = (Player) src;

      ItemStack mobSpawnerStack =
          ItemStack.builder().itemType(ItemTypes.MOB_SPAWNER).quantity(1).build();
      Optional<MobSpawnerData> mobSpawnerData = mobSpawnerStack.getOrCreate(MobSpawnerData.class);

      if (mobSpawnerData.isPresent()) {
        MobSpawnerData data = mobSpawnerData.get();
        data.nextEntityToSpawn().set(entityType, null);

        if (mobSpawnerStack.offer(data).isSuccessful()) {
          player.setItemInHand(mobSpawnerStack);
          player.sendMessage(
              Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Created mob spawner."));
        } else {
          player.sendMessage(
              Text.of(
                  TextColors.DARK_RED,
                  "Error! ",
                  TextColors.RED,
                  "Failed to set mob spawner entity."));
        }
      } else {
        player.sendMessage(
            Text.of(
                TextColors.DARK_RED, "Error! ", TextColors.RED, "Failed to create mob spawner."));
      }
    } else {
      src.sendMessage(
          Text.of(
              TextColors.DARK_RED,
              "Error! ",
              TextColors.RED,
              "Must be an in-game player to use /mobspawner!"));
    }

    return CommandResult.success();
  }
Example #5
0
  @Listener
  public void onInventoryInteract(ClickInventoryEvent event) {
    if (!event.getTargetInventory().equals(this.container)
        && !event.getTargetInventory().first().parent().equals(this.inventory)) {
      return;
    }

    System.out.print("Event:\n");
    boolean cancel = false;
    for (SlotTransaction transaction : event.getTransactions()) {
      ItemStack origStack = transaction.getOriginal().createStack();
      ItemStack finalStack = transaction.getFinal().createStack();
      String origString =
          origStack.getItem().equals(ItemTypes.NONE)
              ? origStack.getItem().getId()
              : origStack.getItem().getId() + " " + origStack.getQuantity();
      String finalString =
          finalStack.getItem().equals(ItemTypes.NONE)
              ? finalStack.getItem().getId()
              : finalStack.getItem().getId() + " " + finalStack.getQuantity();
      System.out.print(origString + "->" + finalString + "\n");

      boolean upper =
          !(transaction.getSlot().parent()
              instanceof
              PlayerInventory); // TODO this will not work when viewing another playerinventory
      if (upper) {
        if (checkTransaction(event, transaction, origStack, finalStack)) {
          cancel = true;
        } else {
          runOnChange();
        }
      }
      // else lower inventory was affected ; actually we don't care (yet)
    }
    if (cancel) {
      System.out.print("Cancelled\n");
    }
    System.out.print("\n");
  }
Example #6
0
 public void equip(ArmorEquipable e) {
   e.setItemInHand(weapon.copy());
   // for (ItemStack i : inventory) e.getInventory().offer(i.copy());
 }
Example #7
0
 public ItemStack getIcon() {
   return icon.copy();
 }