下面列出了怎么用org.bukkit.entity.Egg的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler
public void projectileLaunch(ProjectileLaunchEvent e) {
Projectile projectile = e.getEntity();
if (projectile instanceof Snowball || projectile instanceof Egg || projectile instanceof Arrow) {
if (projectile.getShooter() instanceof Player) {
Player player = (Player) projectile.getShooter();
GameMap gMap = MatchManager.get().getPlayerMap(player);
if (gMap != null) {
PlayerStat ps = PlayerStat.getPlayerStats(player.getUniqueId());
if (ps != null) {
String key = ps.getProjectileEffect();
ProjectileEffectOption peo = (ProjectileEffectOption) ProjectileEffectOption.getPlayerOptionByKey(key);
if (peo != null) {
List<ParticleEffect> effects = peo.getEffects();
if (key != null && effects != null) {
if (!key.equalsIgnoreCase("none")) {
SkyWarsReloaded.getOM().addProjectile(projectile, effects);
}
}
}
}
}
}
}
}
public PlayerEggThrowEvent(final Player player, final Egg egg, final boolean hatching, final byte numHatches, final EntityType hatchingType) {
super(player);
this.egg = egg;
this.hatching = hatching;
this.numHatches = numHatches;
this.hatchType = hatchingType;
}
public static String getTranslationKey(Entity entity) {
if(entity instanceof TNTPrimed) {
return "tile.tnt.name";
} else if(entity instanceof Egg) {
return "item.egg.name";
} else {
final String id = EntityTypes.b(((CraftEntity) entity).getHandle());
return "entity." + (id != null ? id : "generic") + ".name";
}
}
@Deprecated
public Egg throwEgg() {
return launchProjectile(Egg.class);
}
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
net.minecraft.entity.Entity launch = null;
if (Snowball.class.isAssignableFrom(projectile)) {
launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
} else if (Egg.class.isAssignableFrom(projectile)) {
launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
} else if (Arrow.class.isAssignableFrom(projectile)) {
launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
} else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
} else if (Fireball.class.isAssignableFrom(projectile)) {
Location location = getEyeLocation();
Vector direction = location.getDirection().multiply(10);
if (SmallFireball.class.isAssignableFrom(projectile)) {
launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
} else if (WitherSkull.class.isAssignableFrom(projectile)) {
launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
} else {
launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
}
((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
Validate.notNull(launch, "Projectile not supported");
if (velocity != null) {
((T) launch.getBukkitEntity()).setVelocity(velocity);
}
world.spawnEntityInWorld(launch);
return (T) launch.getBukkitEntity();
}
/**
* Gets the egg involved in this event.
*
* @return the egg involved in this event
*/
public Egg getEgg() {
return egg;
}