下面列出了怎么用org.bukkit.entity.Fish的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public Class<? extends Fish> getType() {
if (!init && wildcard)
return Fish.class;
init = false;
switch (pattern) {
case 1:
return Cod.class;
case 2:
return PufferFish.class;
case 3:
return Salmon.class;
case 4:
return TropicalFish.class;
}
return Fish.class;
}
@Override
protected boolean init(@Nullable Class<? extends Fish> c, @Nullable Fish e) {
int matchedPattern = getInitPattern(e);
if (matchedPattern == 0)
wildcard = true;
pattern = (matchedPattern == 0) ? ThreadLocalRandom.current().nextInt(1, 5) : matchedPattern;
return true;
}
private static int getInitPattern(@Nullable Fish f) {
if (f == null)
return 0;
else if (f instanceof Cod)
return 1;
else if (f instanceof PufferFish)
return 2;
else if (f instanceof Salmon)
return 3;
else if (f instanceof TropicalFish)
return 4;
return 0;
}
public PlayerFishEvent(final Player player, final Entity entity, final Fish hookEntity, final State state) {
super(player);
this.entity = entity;
this.hookEntity = hookEntity;
this.state = state;
}
@Override
public void set(Fish entity) {
// Setting of entity already handled by init() functions
}
@Override
protected boolean match(Fish entity) {
return wildcard ? true : getPattern(entity) == pattern;
}
@Override
protected boolean equals_i(EntityData<?> obj) {
return obj instanceof Fish ? (wildcard ? true : getPattern((Fish) obj) == pattern) : false;
}
@Override
public boolean isSupertypeOf(EntityData<?> e) {
return e instanceof Fish ? (wildcard ? true : getPattern((Fish) e) == pattern) : false;
}
private int getPattern(@Nullable Fish f) {
int p = getInitPattern(f);
return p == 0 ? pattern : p;
}
@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 fishing hook.
*
* @return Fish the entity representing the fishing hook/bobber.
*/
public Fish getHook() {
return hookEntity;
}