public void processAward(Player player, Integer ratio, Integer amount) {
   if (ratio == 0) return;
   else if (Expra.rando.nextInt(ratio) == 0) {
     ExperienceOrb xp = player.getWorld().spawn(player.getLocation(), ExperienceOrb.class);
     xp.setExperience(amount);
   }
 }
예제 #2
0
  protected void die() {
    String message = spell.getMessage("death_broadcast").replace("$name", commandName);
    if (message.length() > 0) {
      controller.sendToMages(message, center);
    }

    // Kill power block
    if (castCommandBlock == null) {
      castCommandBlock = center.getBlock();
    }

    for (BlockFace powerFace : POWER_FACES) {
      Block checkForPower = castCommandBlock.getRelative(powerFace);
      if (commandReload) {
        controller.unregisterAutomata(checkForPower);
      }
      if (checkForPower.getType() == POWER_MATERIAL) {
        BlockData commitBlock = UndoList.register(checkForPower);
        commitBlock.setMaterial(Material.AIR);
        commitBlock.modify(checkForPower);
        commitBlock.commit();
      } else {
        BlockData commitBlock = UndoList.getBlockData(checkForPower.getLocation());
        if (commitBlock != null) {
          commitBlock.setMaterial(Material.AIR);
        }
      }
    }

    // Drop item
    if (dropItem != null && dropItem.length() > 0) {
      Wand magicItem = controller.createWand(dropItem);
      if (magicItem != null) {
        center.getWorld().dropItemNaturally(center, magicItem.getItem());
      }
    }

    // Drop Xp
    if (dropXp > 0) {
      Entity entity = center.getWorld().spawnEntity(center, EntityType.EXPERIENCE_ORB);
      if (entity != null && entity instanceof ExperienceOrb) {
        ExperienceOrb orb = (ExperienceOrb) entity;
        orb.setExperience(dropXp);
      }
    }
    if (includeCommands && castCommandBlock != null) {
      BlockData commitBlock = UndoList.register(castCommandBlock);
      commitBlock.setMaterial(Material.AIR);
      commitBlock.modify(castCommandBlock);
      commitBlock.commit();
    }

    if (level != null) {
      level.onDeath(mage, birthMaterial);
    }
    if (!mage.isPlayer()) {
      controller.removeMage(mage);
    }
  }
예제 #3
0
  public void dropExp(LivingEntity entity, int amount) {
    Location loc = entity.getLocation();
    ExperienceOrb orb =
        (ExperienceOrb) entity.getWorld().spawnEntity(loc, EntityType.EXPERIENCE_ORB);
    orb.setExperience(level);

    // Old EXP Drop method
    /*for (double x = 10; x > 0; x--){
    	int e = (int) Math.round(amount*Math.pow(0.5041379, x));
    	if (e > 0) {
    		ExperienceOrb orb = (ExperienceOrb) entity.getWorld().spawnEntity(loc, EntityType.EXPERIENCE_ORB);
    		orb.setExperience(e);
    		orb.setMetadata("level", new FixedMetadataValue(plugin, this.level));
    	}
    }*/
  }
  @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);
  }