下面列出了怎么用org.bukkit.entity.Fireball的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler
public void onFireballThrow(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (!Main.isPlayerInGame(player)) {
return;
}
if (event.getItem() != null) {
ItemStack stack = event.getItem();
String unhash = APIUtils.unhashFromInvisibleStringStartsWith(stack, THROWABLE_FIREBALL_PREFIX);
if (unhash != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)) {
String[] properties = unhash.split(":");
double damage = Double.parseDouble(properties[2]);
float explosion = (float) Double.parseDouble(properties[2]);
Fireball fireball = player.launchProjectile(Fireball.class);
fireball.setIsIncendiary(false);
fireball.setYield(explosion);
Main.registerGameEntity(fireball, Main.getPlayerGameProfile(player).getGame());
event.setCancelled(true);
if (stack.getAmount() > 1) {
stack.setAmount(stack.getAmount() - 1);
} else {
player.getInventory().remove(stack);
}
player.updateInventory();
}
}
}
@EventHandler
public void onFireballThrow(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (!Main.isPlayerInGame(player)) {
return;
}
if (event.getItem() != null) {
ItemStack stack = event.getItem();
String unhash = APIUtils.unhashFromInvisibleStringStartsWith(stack, THROWABLE_FIREBALL_PREFIX);
if (unhash != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)) {
String[] properties = unhash.split(":");
double damage = Double.parseDouble(properties[2]);
float explosion = (float) Double.parseDouble(properties[2]);
Fireball fireball = player.launchProjectile(Fireball.class);
fireball.setIsIncendiary(false);
fireball.setYield(explosion);
Main.registerGameEntity(fireball, Main.getPlayerGameProfile(player).getGame());
event.setCancelled(true);
if (stack.getAmount() > 1) {
stack.setAmount(stack.getAmount() - 1);
} else {
player.getInventory().remove(stack);
}
player.updateInventory();
}
}
}
@EventHandler
public void onGhastExplode(EntityExplodeEvent event) {
if (!plugin.getWorldManager().isSkyNether(event.getEntity().getWorld())) {
return; // Bail out, not our problem
}
// TODO: 23/09/2015 - R4zorax: Perhaps enable this when island has a certain level?
if (event.getEntity() instanceof Fireball) {
Fireball fireball = (Fireball) event.getEntity();
fireball.setIsIncendiary(false);
fireball.setFireTicks(0);
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onProjectileHitEvent(ProjectileHitEvent event) {
if (event.getEntity() instanceof Arrow) {
ArrowFiredCache afc = CivCache.arrowsFired.get(event.getEntity().getUniqueId());
if (afc != null) {
afc.setHit(true);
}
}
if (event.getEntity() instanceof Fireball) {
CannonFiredCache cfc = CivCache.cannonBallsFired.get(event.getEntity().getUniqueId());
if (cfc != null) {
cfc.setHit(true);
FireworkEffect fe = FireworkEffect.builder().withColor(Color.RED).withColor(Color.BLACK).flicker(true).with(Type.BURST).build();
Random rand = new Random();
int spread = 30;
for (int i = 0; i < 15; i++) {
int x = rand.nextInt(spread) - spread/2;
int y = rand.nextInt(spread) - spread/2;
int z = rand.nextInt(spread) - spread/2;
Location loc = event.getEntity().getLocation();
Location location = new Location(loc.getWorld(), loc.getX(),loc.getY(), loc.getZ());
location.add(x, y, z);
TaskMaster.syncTask(new FireWorkTask(fe, loc.getWorld(), loc, 5), rand.nextInt(30));
}
}
}
}
public CannonFiredCache(CannonTower fromTower, Location target, Fireball fireball) {
this.fromTower = fromTower;
this.target = target;
this.fireball = fireball;
this.uuid = fireball.getUniqueId();
expired = Calendar.getInstance();
expired.set(Calendar.SECOND, 30);
}
@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();
}
public Fireball getFireball() {
return fireball;
}
public void setFireball(Fireball fireball) {
this.fireball = fireball;
}