コード例 #1
0
  @EventHandler
  public void onEntityTameEvent(EntityTameEvent event) {

    /*
    Get the entity being tamed.
     */
    LivingEntity entity = event.getEntity();

    if (StackUtils.hasRequiredData(entity)) {

      /*
      Get the new quantity. Current size, less one (One being tamed)
       */
      int newQuantity = StackUtils.getStackSize(entity) - 1;

      /*
      Clear the name of the entity that was just tamed.
       */
      entity.setCustomName("");

      /*
      If there are any mobs remaining in the stack, then peel em off to form a new stack.
       */
      if (newQuantity > 0) {

        LivingEntity newEntity = getPlugin().getStackUtils().peelOffStack(entity, false);

        /*
        If there was an age in question, then assign it.
         */
        if (newEntity instanceof Ageable) {
          ((Ageable) newEntity).setAge(((Ageable) event.getEntity()).getAge());
        }

        /*
         * Yes I know the following aren't possible, but if someone uses a plugin that allows for taming of other mobs through NMS,
         * then this will account for that.
         */

        /*
        If the stack had a colour, assign it.
         */
        if (newEntity instanceof Colorable) {
          ((Colorable) newEntity).setColor(((Colorable) event.getEntity()).getColor());
        }

        /*
        If it was a sheep, keep it's sheared status.
         */
        if (newEntity instanceof Sheep) {
          ((Sheep) newEntity).setSheared(((Sheep) event.getEntity()).isSheared());
        }
      }
    }
  }
コード例 #2
0
  @EventHandler
  public void interactEvent(PlayerInteractEntityEvent event) {

    /*
    If a LivingEntity was right clicked with a name tag, and stack custom named mobs is false, then follow.
     */
    if (!getPlugin().getConfig().getBoolean("stack-custom-named-mobs")
        && event.getPlayer().getItemInHand().getType() == Material.NAME_TAG
        && event.getRightClicked() instanceof LivingEntity) {

      LivingEntity entity = (LivingEntity) event.getRightClicked();
      ;

      /*
      Initialised blank name tag to get default name if it changes in future updates.
       */
      ItemStack normalNameTag = new ItemStack(Material.NAME_TAG, 1, (byte) 0);

      /*
      Get the item the player is holding.
       */
      ItemStack itemInHand = event.getPlayer().getItemInHand();

      /*
      If the creature has the required data and the name tag isn't blank, then follow.
       */
      if (StackUtils.hasRequiredData(entity)
          && !itemInHand
              .getItemMeta()
              .getDisplayName()
              .equalsIgnoreCase(normalNameTag.getItemMeta().getDisplayName())) {

        /*
        If there is more than one creature in the stack, then peel one off and don't allow it to stack again.
         */
        if (StackUtils.getStackSize(entity) > 1) {

          getPlugin().getStackUtils().peelOffStack(entity, false);

        } else {
          entity.removeMetadata("quantity", getPlugin());
        }
      }
    }
  }