示例#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 {
    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();
  }