コード例 #1
0
 @Override
 public void getParameterOptions(Spell spell, String parameterKey, Collection<String> examples) {
   if (parameterKey.equals("type")) {
     for (EntityType type : EntityType.values()) {
       examples.add(type.name().toLowerCase());
     }
   } else if (parameterKey.equals("reason")) {
     for (CreatureSpawnEvent.SpawnReason type : CreatureSpawnEvent.SpawnReason.values()) {
       examples.add(type.name().toLowerCase());
     }
   } else if (parameterKey.equals("skeleton_type")) {
     for (Skeleton.SkeletonType type : Skeleton.SkeletonType.values()) {
       examples.add(type.name().toLowerCase());
     }
   } else if (parameterKey.equals("ocelot_type")) {
     for (Ocelot.Type type : Ocelot.Type.values()) {
       examples.add(type.name().toLowerCase());
     }
   } else if (parameterKey.equals("villager_profession")) {
     for (Villager.Profession profession : Villager.Profession.values()) {
       examples.add(profession.name().toLowerCase());
     }
   } else if (parameterKey.equals("rabbity_type")) {
     for (Rabbit.Type type : Rabbit.Type.values()) {
       examples.add(type.name().toLowerCase());
     }
   } else if (parameterKey.equals("horse_variant")) {
     for (Horse.Variant type : Horse.Variant.values()) {
       examples.add(type.name().toLowerCase());
     }
   } else if (parameterKey.equals("horse_style")) {
     for (Horse.Style type : Horse.Style.values()) {
       examples.add(type.name().toLowerCase());
     }
   } else if (parameterKey.equals("horse_color")) {
     for (Horse.Color type : Horse.Color.values()) {
       examples.add(type.name().toLowerCase());
     }
   } else if (parameterKey.equals("color")) {
     for (DyeColor type : DyeColor.values()) {
       examples.add(type.name().toLowerCase());
     }
   } else if (parameterKey.equals("track")
       || parameterKey.equals("loot")
       || parameterKey.equals("baby")) {
     examples.addAll(Arrays.asList((BaseSpell.EXAMPLE_BOOLEANS)));
   } else if (parameterKey.equals("name")) {
     examples.add("Philbert");
   } else if (parameterKey.equals("speed")) {
     examples.addAll(Arrays.asList((BaseSpell.EXAMPLE_SIZES)));
   } else {
     super.getParameterOptions(spell, parameterKey, examples);
   }
 }
コード例 #2
0
 static {
   horseStyles = new HashMap<>();
   for (final Horse.Style e : Horse.Style.values()) {
     horseStyles.put(e.name(), e);
   }
 }
コード例 #3
0
ファイル: TamingManager.java プロジェクト: jjm223/mcMMO
  /**
   * Handle the Call of the Wild ability.
   *
   * @param type The type of entity to summon.
   * @param summonAmount The amount of material needed to summon the entity
   */
  private void callOfTheWild(EntityType type, int summonAmount) {
    Player player = getPlayer();

    ItemStack heldItem = player.getInventory().getItemInMainHand();
    int heldItemAmount = heldItem.getAmount();
    Location location = player.getLocation();

    if (heldItemAmount < summonAmount) {
      player.sendMessage(
          LocaleLoader.getString(
              "Skills.NeedMore", StringUtils.getPrettyItemString(heldItem.getType())));
      return;
    }

    if (!rangeCheck(type)) {
      return;
    }

    int amount = Config.getInstance().getTamingCOTWAmount(type);
    int tamingCOTWLength = Config.getInstance().getTamingCOTWLength(type);

    for (int i = 0; i < amount; i++) {
      if (!summonAmountCheck(type)) {
        return;
      }

      location = Misc.getLocationOffset(location, 1);
      LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(location, type);

      FakeEntityTameEvent event = new FakeEntityTameEvent(entity, player);
      mcMMO.p.getServer().getPluginManager().callEvent(event);

      if (event.isCancelled()) {
        continue;
      }

      entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
      ((Tameable) entity).setOwner(player);
      entity.setRemoveWhenFarAway(false);

      addToTracker(entity);

      switch (type) {
        case OCELOT:
          ((Ocelot) entity).setCatType(Ocelot.Type.values()[1 + Misc.getRandom().nextInt(3)]);
          break;

        case WOLF:
          entity.setMaxHealth(20.0);
          entity.setHealth(entity.getMaxHealth());
          break;

        case HORSE:
          Horse horse = (Horse) entity;

          entity.setMaxHealth(15.0 + (Misc.getRandom().nextDouble() * 15));
          entity.setHealth(entity.getMaxHealth());
          horse.setColor(
              Horse.Color.values()[Misc.getRandom().nextInt(Horse.Color.values().length)]);
          horse.setStyle(
              Horse.Style.values()[Misc.getRandom().nextInt(Horse.Style.values().length)]);
          horse.setJumpStrength(
              Math.max(
                  AdvancedConfig.getInstance().getMinHorseJumpStrength(),
                  Math.min(
                      Math.min(Misc.getRandom().nextDouble(), Misc.getRandom().nextDouble()) * 2,
                      AdvancedConfig.getInstance().getMaxHorseJumpStrength())));
          // TODO: setSpeed, once available
          break;

        default:
          break;
      }

      if (Permissions.renamePets(player)) {
        entity.setCustomName(
            LocaleLoader.getString(
                "Taming.Summon.Name.Format",
                player.getName(),
                StringUtils.getPrettyEntityTypeString(type)));
      }

      ParticleEffectUtils.playCallOfTheWildEffect(entity);
    }

    player
        .getInventory()
        .setItemInMainHand(
            heldItemAmount == summonAmount
                ? null
                : new ItemStack(heldItem.getType(), heldItemAmount - summonAmount));

    String lifeSpan = "";
    if (tamingCOTWLength > 0) {
      lifeSpan = LocaleLoader.getString("Taming.Summon.Lifespan", tamingCOTWLength);
    }

    player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete") + lifeSpan);
    player.playSound(location, SoundAdapter.FIREWORK_BLAST_FAR, 1F, 0.5F);
  }