private void changeMobData(String type, Entity spawned, String data, User user) throws Exception {
   if ("Slime".equalsIgnoreCase(type)) {
     try {
       ((Slime) spawned).setSize(Integer.parseInt(data));
     } catch (Exception e) {
       throw new Exception(Util.i18n("slimeMalformedSize"), e);
     }
   }
   if ("Sheep".equalsIgnoreCase(type)) {
     try {
       if (data.equalsIgnoreCase("random")) {
         Random rand = new Random();
         ((Sheep) spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]);
       } else {
         ((Sheep) spawned).setColor(DyeColor.valueOf(data.toUpperCase()));
       }
     } catch (Exception e) {
       throw new Exception(Util.i18n("sheepMalformedColor"), e);
     }
   }
   if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("tamed")) {
     Wolf wolf = ((Wolf) spawned);
     wolf.setTamed(true);
     wolf.setOwner(user);
     wolf.setSitting(true);
   }
   if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("angry")) {
     ((Wolf) spawned).setAngry(true);
   }
   if ("Creeper".equalsIgnoreCase(type) && data.equalsIgnoreCase("powered")) {
     ((Creeper) spawned).setPowered(true);
   }
 }
  protected Entity setEntity(MageController controller, Entity entity) {
    this.entity = entity;
    if (noTarget) {
      entity.setMetadata("notarget", new FixedMetadataValue(controller.getPlugin(), true));
    }
    if (customName != null) {
      entity.setCustomName(customName);
      entity.setCustomNameVisible(true);
    }

    if (entity instanceof LivingEntity) {
      ((LivingEntity) entity).setMaxHealth(1000.0);
      ((LivingEntity) entity).setHealth(1000.0);
    }
    if (entity instanceof Slime) {
      ((Slime) entity).setSize(1);
    }

    if (entity instanceof Ageable) {
      if (isBaby) {
        ((Ageable) entity).setBaby();
      } else {
        ((Ageable) entity).setAdult();
      }
    } else if (entity instanceof Zombie) {
      ((Zombie) entity).setBaby(isBaby);
    } else if (entity instanceof PigZombie) {
      ((PigZombie) entity).setBaby(isBaby);
    } else if (entity instanceof Slime && isBaby) {
      Slime slime = (Slime) entity;
      slime.setSize(0);
    }

    if (entity instanceof Horse) {
      Horse.Variant variant = Horse.Variant.UNDEAD_HORSE;
      if (variantName != null) {
        try {
          variant = Horse.Variant.valueOf(variantName.toUpperCase());
        } catch (Exception ex) {
        }
      } else {
        variant = Horse.Variant.UNDEAD_HORSE;
      }

      ((Horse) entity).setVariant(variant);
    }

    if (entity instanceof Ocelot) {
      Ocelot ocelot = (Ocelot) entity;
      Ocelot.Type variant = Ocelot.Type.WILD_OCELOT;
      if (variantName != null) {
        try {
          variant = Ocelot.Type.valueOf(variantName.toUpperCase());
        } catch (Exception ex) {
        }
      } else {
        variant = Ocelot.Type.WILD_OCELOT;
      }

      ocelot.setCatType(variant);
    }
    if (entity instanceof Sheep) {
      Sheep sheep = (Sheep) entity;
      DyeColor color = DyeColor.WHITE;
      if (variantName != null) {
        try {
          color = DyeColor.valueOf(variantName.toUpperCase());
        } catch (Exception ex) {

        }
      }
      sheep.setColor(color);
    }
    if (entity instanceof Wolf) {
      Wolf wolf = (Wolf) entity;
      if (variantName != null) {
        // Only set collar color if a variant is set..
        // this makes it a dog, versus a wolf. Technically.
        DyeColor color = DyeColor.RED;
        try {
          color = DyeColor.valueOf(variantName.toUpperCase());
          wolf.setTamed(true);
        } catch (Exception ex) {

        }
        wolf.setCollarColor(color);
      }
    }
    targeting.ignoreEntity(entity);
    return entity;
  }
示例#3
0
  public static void setEntityTypeData(final Entity entity, final String data) {
    if (data == "") return;

    final String parts[] = data.split(",");
    if (entity instanceof LivingEntity) {
      ((LivingEntity) entity).setMaxHealth(Double.parseDouble(parts[1]));
      ((LivingEntity) entity).setHealth(Double.parseDouble(parts[0]));
      if (!parts[2].equals("null")) ((LivingEntity) entity).setCustomName(parts[2]);
      if (entity instanceof Animals) {
        ((Animals) entity).setAge(Integer.parseInt(parts[3]));
        if (entity instanceof Sheep) {
          ((Sheep) entity).setSheared(Boolean.parseBoolean(parts[4]));
          ((Sheep) entity).setColor(sheepColors.get(parts[5]));
        } else if (entity instanceof Wolf) {
          if (Boolean.parseBoolean(parts[4])) {
            ((Wolf) entity).setAngry(Boolean.parseBoolean(parts[4]));
          } else if (parts.length > 5) {
            ((Tameable) entity).setTamed(true);
            ((Tameable) entity).setOwner(getPlayer(parts[5]));
            ((Wolf) entity).setCollarColor(DyeColor.valueOf(parts[6]));
          }
        } else if (entity instanceof Ocelot) {
          if (parts.length > 4) {
            ((Tameable) entity).setTamed(true);
            ((Tameable) entity).setOwner(getPlayer(parts[4]));
            ((Ocelot) entity).setCatType(catTypes.get(parts[5]));
          }
        } else if (entity instanceof Pig) {
          ((Pig) entity).setSaddle(Boolean.parseBoolean(parts[4]));
        } else if (entity instanceof Horse) {
          ((Horse) entity).setVariant(horseVariants.get(parts[4]));
          ((Horse) entity).setStyle(horseStyles.get(parts[5]));
          ((Horse) entity).setColor(horseColors.get(parts[6]));
          ((Horse) entity).setDomestication(Integer.parseInt(parts[7]));
          ((Horse) entity).setMaxDomestication(Integer.parseInt(parts[8]));
          ((Horse) entity).setJumpStrength(Double.parseDouble(parts[9]));
          if (parts.length > 10) {
            ((Tameable) entity).setTamed(true);
            if (!parts[10].equals("null")) ((Tameable) entity).setOwner(getPlayer(parts[10]));
            ((Horse) entity)
                .getInventory()
                .setSaddle(ItemStackUtil.stringToItemStack(parts[11])[0]);
            ((Horse) entity).getInventory().setArmor(ItemStackUtil.stringToItemStack(parts[12])[0]);
            if (parts.length > 13) {
              ((Horse) entity).setCarryingChest(true);
              ((Horse) entity)
                  .getInventory()
                  .setContents(ItemStackUtil.stringToItemStack(parts[13]));
            }
          }
        }
      } else if (entity instanceof Villager) {
        ((Villager) entity).setProfession(villagerProfessions.get(parts[3]));
        ((Villager) entity).setAge(Integer.parseInt(parts[4]));
      } else if (entity instanceof Creeper) {
        ((Creeper) entity).setPowered(Boolean.parseBoolean(parts[3]));
      } else if (entity instanceof Slime) {
        ((Slime) entity).setSize(Integer.parseInt(parts[3]));
      } else if (entity instanceof Skeleton) {
        ((Skeleton) entity).setSkeletonType(skeletonTypes.get(parts[3]));
        if (parts[3].equals("0")) {
          ((Skeleton) entity).getEquipment().setItemInHand(new ItemStack(Material.BOW));
        } else {
          ((Skeleton) entity).getEquipment().setItemInHand(new ItemStack(Material.BOW));
        }
      } else if (entity instanceof PigZombie) {
        ((LivingEntity) entity).getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD));
      }
    }
  }
示例#4
0
  // Mob combat private functions
  private void attemptGiveBattleWinnings(
      String guild, Player playerLooter, RpgMonster rpgMobDefender) {
    List<RpgPlayer> recipients = new ArrayList<RpgPlayer>();
    double baseCash;
    double baseExp;
    double donatorBaseCash;
    double donatorBaseExp;
    double cash;
    double exp;
    double guildBonus = 1;
    int powerLevelPrevention = FC_Rpg.balanceConfig.getPowerLevelPrevention();
    boolean checkPowerLeveling;

    if (rpgMobDefender.getIsBoss()) checkPowerLeveling = false;
    else checkPowerLeveling = (powerLevelPrevention > -1);

    if (guild != null) {
      recipients = FC_Rpg.rpgEntityManager.getNearbyPartiedRpgPlayers(playerLooter, 50);
      guildBonus = FC_Rpg.guildConfig.getGuildBonus(recipients.size());
    } else recipients.add(FC_Rpg.rpgEntityManager.getRpgPlayer(playerLooter));

    // Determine base amount of cash and experience to give.
    baseCash = rpgMobDefender.baseCash * FC_Rpg.eventCashMultiplier;
    baseExp = rpgMobDefender.baseExp * FC_Rpg.eventExpMultiplier;

    // Add in guild bonus if there is one.
    if (guildBonus > 1) {
      baseCash *= guildBonus;
      baseExp *= guildBonus;
    }

    // For slimes we reduce the gold and exp based on size.
    if (rpgMobDefender.getEntity() instanceof Slime) {
      Slime slime = (Slime) rpgMobDefender.getEntity();
      int slimeSize = slime.getSize();

      if (slimeSize == 2) {
        baseExp *= .25;
        baseCash *= .25;
      } else if (slimeSize == 1) {
        baseExp *= .125;
        baseCash *= .125;
      }
    }

    donatorBaseCash = baseCash * (1 + FC_Rpg.generalConfig.getDonatorLootBonusPercent());
    donatorBaseExp = baseExp * (1 + FC_Rpg.generalConfig.getDonatorLootBonusPercent());

    // If we check power leveling and the player isn't solo, then...
    if (checkPowerLeveling && recipients.size() != 1) {
      // Variable Declaration
      RpgPlayer rPlayer = FC_Rpg.rpgEntityManager.getRpgPlayer(playerLooter);

      // Check to see if killer is too strong to give exp.
      // Mob Level - Player Level = levelDifference : Positive = Mob stronger, negative = mob
      // weaker.
      if (rpgMobDefender.getLevel() - rPlayer.playerConfig.getClassLevel() > powerLevelPrevention) {
        rPlayer.attemptMonsterOutOfRangeNotification();
        return;
      } else if (rpgMobDefender.getLevel() - rPlayer.playerConfig.getClassLevel()
          < powerLevelPrevention * -1) {
        MessageLib msgLib = new MessageLib(rPlayer.getPlayer());
        msgLib.standardError("You annhilated the monster so brutally most loot was destroyed.");
        return;
      }
    }

    for (RpgPlayer rpgLooter : recipients) {
      // Set up loot amounts.
      if (rpgLooter.playerConfig.isDonator()) {
        cash = donatorBaseCash;
        exp = donatorBaseExp;
      } else {
        cash = baseCash;
        exp = baseExp;
      }

      if (rpgLooter.playerConfig.getStatusActiveRpgPlayer(SpellEffect.BONUS_EXPERIENCE.getID()))
        exp *= rpgLooter.playerConfig.getStatusMagnitude(SpellEffect.BONUS_EXPERIENCE.getID());

      if (rpgLooter.playerConfig.getStatusActiveRpgPlayer(SpellEffect.BONUS_GOLD.getID()))
        exp *= rpgLooter.playerConfig.getStatusMagnitude(SpellEffect.BONUS_GOLD.getID());

      rpgLooter.playerConfig.addGold(cash);
      rpgLooter.addClassExperience(exp, true);

      // Send a message to the player showing experience and loot gains.
      rpgLooter.attemptMonsterDeathNotification(rpgMobDefender.getLevel(), exp, cash);
    }
  }
  @SuppressWarnings("deprecation")
  public void assignMobProps(Entity baseEntity, ISpawnableEntity data) {

    // This needs to be before everything else!
    if (data.getRider() != null) {
      addRider(baseEntity, data.getRider());
    }

    Vector v1 = data.getVelocity(baseEntity);
    Vector v2 = data.getVelocity2(baseEntity);
    if (v2.getX() == 0 && v2.getY() == 0 && v2.getZ() == 0) {
      baseEntity.setVelocity(data.getVelocity(baseEntity).clone());
    } else {
      Vector v3 = randomVector(v1, v2);
      baseEntity.setVelocity(v3.clone());
    }
    baseEntity.setFireTicks(data.getFireTicks(baseEntity));

    if (baseEntity instanceof LivingEntity) {
      LivingEntity entity = (LivingEntity) baseEntity;
      setBasicProps(entity, data);

      if (data.showCustomName()) {
        setCustomName(entity, data);
      }

      if (entity instanceof Ageable) {
        Ageable a = (Ageable) entity;
        setAgeProps(a, data);
      }

      if (entity instanceof Animals) {
        Animals animal = (Animals) entity;

        // Setting animal specific properties
        if (animal instanceof Pig) {
          Pig p = (Pig) animal;
          p.setSaddle(data.isSaddled());
        } else if (animal instanceof Sheep) {
          Sheep s = (Sheep) animal;
          DyeColor color = DyeColor.valueOf(data.getColor());
          s.setColor(color);
        } else if (animal instanceof Wolf) {
          Wolf w = (Wolf) animal;
          w.setAngry(data.isAngry());
          w.setTamed(data.isTamed());
          if (data.isTamed()) {

            ArrayList<Player> nearPlayers = getNearbyPlayers(w.getLocation(), 16);
            int index = (int) Math.round(Math.rint(nearPlayers.size() - 1));
            if (nearPlayers != null) {
              w.setOwner(nearPlayers.get(index));
            }

            w.setSitting(data.isSitting());
          }
        } else if (animal instanceof Ocelot) {
          Ocelot o = (Ocelot) animal;
          o.setTamed(data.isTamed());
          if (data.isTamed()) {
            Ocelot.Type catType = Ocelot.Type.valueOf(data.getCatType());
            o.setCatType(catType);

            ArrayList<Player> nearPlayers = getNearbyPlayers(o.getLocation(), 16);
            int index = (int) Math.round(Math.rint(nearPlayers.size() - 1));
            if (nearPlayers != null) {
              o.setOwner(nearPlayers.get(index));
            }

            o.setSitting(data.isSitting());
          }
        }
      } else if (entity instanceof Villager) {
        Villager v = (Villager) entity;
        v.setAge(data.getAge(baseEntity));
        v.setProfession(data.getProfession());
      } else if (entity instanceof Monster) {
        Monster monster = (Monster) entity;

        // Setting monster specific properties.
        if (monster instanceof Enderman) {
          Enderman e = (Enderman) monster;
          e.setCarriedMaterial(data.getEndermanBlock());
        } else if (monster instanceof Creeper) {
          Creeper c = (Creeper) monster;
          c.setPowered(data.isCharged());
        } else if (monster instanceof PigZombie) {
          PigZombie p = (PigZombie) monster;
          if (data.isAngry()) {
            p.setAngry(true);
          }
          p.setBaby((data.getAge(baseEntity) < -1) ? true : false);
        } else if (monster instanceof Spider) {
          Spider s = (Spider) monster;
          if (data.isJockey()) {
            makeJockey(s, data);
          }
        } else if (monster instanceof Zombie) {
          Zombie z = (Zombie) monster;
          boolean isVillager = false;
          if (data.hasProp("zombie")) {
            isVillager = (Boolean) (data.getProp("zombie"));
          }
          z.setBaby((data.getAge(baseEntity) < -1) ? true : false);
          z.setVillager(isVillager);
        } else if (monster instanceof Skeleton) {
          Skeleton sk = (Skeleton) monster;
          SkeletonType skType = SkeletonType.NORMAL;

          if (data.hasProp("wither")) {
            skType =
                ((Boolean) (data.getProp("wither")) == true)
                    ? SkeletonType.WITHER
                    : SkeletonType.NORMAL;
          }

          sk.setSkeletonType(skType);
        }
      } else if (entity instanceof Golem) {
        Golem golem = (Golem) entity;

        if (golem instanceof IronGolem) {
          IronGolem i = (IronGolem) golem;
          if (data.isAngry()) {
            ArrayList<Player> nearPlayers = getNearbyPlayers(i.getLocation(), 16);
            int index = (int) Math.round(Math.rint(nearPlayers.size() - 1));
            if (nearPlayers != null) {
              i.setPlayerCreated(false);
              i.damage(0, nearPlayers.get(index));
              i.setTarget(nearPlayers.get(index));
            }
          }
        }
        // Some are not classified as animals or monsters
      } else if (entity instanceof Slime) {
        Slime s = (Slime) entity;
        s.setSize(data.getSlimeSize());
      } else if (entity instanceof MagmaCube) {
        MagmaCube m = (MagmaCube) entity;
        m.setSize(data.getSlimeSize());
      }

    } else if (baseEntity instanceof Projectile) {
      Projectile pro = (Projectile) baseEntity;

      // Eventually add explosive arrows and such :D

      if (pro instanceof Fireball) {
        Fireball f = (Fireball) pro;
        setExplosiveProps(f, data);
        f.setVelocity(new Vector(0, 0, 0));
        f.setDirection(data.getVelocity(baseEntity));
      } else if (pro instanceof SmallFireball) {
        SmallFireball f = (SmallFireball) pro;
        setExplosiveProps(f, data);
        f.setVelocity(new Vector(0, 0, 0));
        f.setDirection(data.getVelocity(baseEntity));
      }

    } else if (baseEntity instanceof Explosive) {

      Explosive ex = (Explosive) baseEntity;

      if (ex instanceof TNTPrimed) {
        TNTPrimed tnt = (TNTPrimed) ex;
        setExplosiveProps(tnt, data);
        tnt.setFuseTicks(data.getFuseTicks(baseEntity));
      }

    } else if (baseEntity instanceof Firework) {

      Firework f = (Firework) baseEntity;
      ItemMeta meta = data.getItemType().getItemMeta();
      if (meta != null) {
        if (meta instanceof FireworkMeta) {
          FireworkMeta fMeta = (FireworkMeta) meta;
          if (fMeta != null) {
            f.setFireworkMeta(fMeta);
          }
        }
      }

    } else if (baseEntity instanceof Minecart) {

      Minecart m = (Minecart) baseEntity;
      if (data.hasProp("minecartSpeed")) {
        m.setMaxSpeed((Double) data.getProp("minecartSpeed"));
      }

    } else if (baseEntity instanceof ExperienceOrb) {
      ExperienceOrb o = (ExperienceOrb) baseEntity;
      o.setExperience(data.getDroppedExp(baseEntity));
    }

    setNBT(baseEntity, data);
  }