下面列出了怎么用org.bukkit.Effect的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler(priority = EventPriority.MONITOR)
public void onBlitzPlayerEliminated(final BlitzPlayerEliminatedEvent event) {
this.eliminatedPlayers.add(event.getPlayer().getBukkit().getUniqueId());
World world = event.getMatch().getWorld();
Location death = event.getDeathLocation();
double radius = 0.1;
int n = 8;
for (int i = 0; i < 6; i++) {
double angle = 2 * Math.PI * i / n;
Location base =
death.clone().add(new Vector(radius * Math.cos(angle), 0, radius * Math.sin(angle)));
for (int j = 0; j <= 8; j++) {
world.playEffect(base, Effect.SMOKE, j);
}
}
}
@Override
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result && this.isPlaced() && this.getType() == Material.JUKEBOX) {
CraftWorld world = (CraftWorld) this.getWorld();
Material record = this.getPlaying();
if (record == Material.AIR) {
world.getHandle().setBlockState(new BlockPos(this.getX(), this.getY(), this.getZ()),
Blocks.JUKEBOX.getDefaultState()
.withProperty(BlockJukebox.HAS_RECORD, false), 3);
} else {
world.getHandle().setBlockState(new BlockPos(this.getX(), this.getY(), this.getZ()),
Blocks.JUKEBOX.getDefaultState()
.withProperty(BlockJukebox.HAS_RECORD, true), 3);
}
world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record.getId());
}
return result;
}
private void handleElimination(final MatchPlayer player) {
if (!eliminatedPlayers.add(player.getBukkit().getUniqueId())) return;
World world = player.getMatch().getWorld();
Location death = player.getBukkit().getLocation();
double radius = 0.1;
int n = 8;
for(int i = 0; i < 6; i++) {
double angle = 2 * Math.PI * i / n;
Location base = death.clone().add(new Vector(radius * Math.cos(angle), 0, radius * Math.sin(angle)));
for(int j = 0; j <= 8; j++) {
world.playEffect(base, Effect.SMOKE, j);
}
}
checkEnd();
}
@Override
public ItemUseHandler getItemHandler() {
return e -> {
Optional<Block> block = e.getClickedBlock();
if (block.isPresent()) {
Block b = block.get();
if (b.getType() == getInput() && SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), ProtectableAction.BREAK_BLOCK)) {
ItemStack output = getRandomOutput();
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
b.setType(Material.AIR);
if (output.getType() != Material.AIR) {
b.getWorld().dropItemNaturally(b.getLocation(), output.clone());
}
}
}
e.cancel();
};
}
private void dropFruitFromTree(Block block) {
for (int x = -1; x < 2; x++) {
for (int y = -1; y < 2; y++) {
for (int z = -1; z < 2; z++) {
// inspect a cube at the reference
Block fruit = block.getRelative(x, y, z);
if (fruit.isEmpty()) continue;
Location loc = fruit.getLocation();
SlimefunItem check = BlockStorage.check(loc);
if (check == null) continue;
for (Tree tree : ExoticGarden.getTrees()) {
if (check.getID().equalsIgnoreCase(tree.getFruitID())) {
BlockStorage.clearBlockInfo(loc);
ItemStack fruits = check.getItem();
fruit.getWorld().playEffect(loc, Effect.STEP_SOUND, Material.OAK_LEAVES);
fruit.getWorld().dropItemNaturally(loc, fruits);
fruit.setType(Material.AIR);
break;
}
}
}
}
}
}
@Override
public ItemUseHandler getItemHandler() {
return e -> {
if (e.getClickedBlock().isPresent()) {
Block b = e.getClickedBlock().get();
if (b.getType() == Material.DIRT) {
if (e.getPlayer().getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(e.getItem(), false);
}
b.setType(Material.GRASS_BLOCK);
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
b.getRelative(BlockFace.UP).setType(Material.GRASS);
}
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.GRASS);
}
}
};
}
public boolean checkParticle(){
if(wild.getConfig().getBoolean("DoParticle")) {
try {
String[] tmp = Bukkit.getVersion().split("MC: ");
String version = tmp[tmp.length - 1].substring(0, 3);
if (version.equals("1.9") || version.equals("1.1"))
Particle.valueOf(wild.getConfig().getString("Particle").toUpperCase());
else
Effect.valueOf(wild.getConfig().getString("Particle").toUpperCase());
} catch (IllegalArgumentException e) {
return false;
}
}else
return true;
return true;
}
public <T> void playEffect(Location loc, Effect effect, T data, int radius) {
if (data != null) {
Validate.isTrue(data.getClass().equals(effect.getData()), "Wrong kind of data for this effect!");
} else {
Validate.isTrue(effect.getData() == null, "Wrong kind of data for this effect!");
}
if (data != null && data.getClass().equals( org.bukkit.material.MaterialData.class )) {
org.bukkit.material.MaterialData materialData = (org.bukkit.material.MaterialData) data;
Validate.isTrue( materialData.getItemType().isBlock(), "Material must be block" );
spigot().playEffect( loc, effect, materialData.getItemType().getId(), materialData.getData(), 0, 0, 0, 1, 1, radius );
} else {
int dataValue = data == null ? 0 : CraftEffect.getDataValue( effect, data );
playEffect( loc, effect, dataValue, radius );
}
}
@Override
public void effect(Event e, ItemStack item, int level) {
if (e instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
LivingEntity target = (LivingEntity) event.getEntity();
int armorCounter = 0;
for (ItemStack piece : target.getEquipment().getArmorContents())
if (!piece.getType().equals(Material.AIR))
armorCounter++;
if (armorCounter == 0)
return;
event.setDamage(DamageModifier.ARMOR, 0); //Completely remove effects of Armor
target.getWorld().playEffect(target.getLocation(), Effect.ZOMBIE_DESTROY_DOOR, 10);
}
}
@Override
public boolean effect(Event event, final Player player) {
final PlayerMoveEvent e = (PlayerMoveEvent) event;
final Block b = e.getTo().getBlock();
if(!Tools.checkWorldGuard(e.getTo(), player, "PVP", false))
return false;
if(b.getType().equals(Material.AIR)) {
b.setType(Material.FIRE);
new BukkitRunnable() {
@Override
public void run() {
if(b.getType().equals(Material.FIRE)) {
player.getWorld().playEffect(e.getTo(), Effect.EXTINGUISH, 60);
b.setType(Material.AIR);
}
}
}.runTaskLater(main, FlameDuration);
}
return true;
}
@Override
protected void executeTask() {
if (p.getInventory().getBoots() == null || p.getInventory().getBoots().getType() == Material.AIR) {
return;
}
double accuracy = DoubleHandler.fixDouble(boots.getSpeed() - 0.7);
if (boots.removeItemCharge(p.getInventory().getBoots(), COST)) {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, (float) 0.25, 1);
p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1, 1);
p.setFallDistance(0F);
double gravity = 0.04;
double offset = ThreadLocalRandom.current().nextBoolean() ? accuracy : -accuracy;
Vector vector = new Vector(p.getEyeLocation().getDirection().getX() * boots.getSpeed() + offset, gravity, p.getEyeLocation().getDirection().getZ() * boots.getSpeed() - offset);
p.setVelocity(vector);
}
else {
Bukkit.getScheduler().cancelTask(id);
}
}
@Override
protected void executeTask() {
if (p.getInventory().getChestplate() == null || p.getInventory().getChestplate().getType() == Material.AIR) {
return;
}
if (jetpack.removeItemCharge(p.getInventory().getChestplate(), COST)) {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, (float) 0.25, 1);
p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1, 1);
p.setFallDistance(0F);
Vector vector = new Vector(0, 1, 0);
vector.multiply(jetpack.getThrust());
vector.add(p.getEyeLocation().getDirection().multiply(0.2F));
p.setVelocity(vector);
}
else {
Bukkit.getScheduler().cancelTask(id);
}
}
private void stomp(EntityDamageEvent e) {
Player p = (Player) e.getEntity();
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 2F);
p.setVelocity(new Vector(0.0, 0.7, 0.0));
for (Entity n : p.getNearbyEntities(4, 4, 4)) {
if (n instanceof LivingEntity && !n.getUniqueId().equals(p.getUniqueId())) {
Vector velocity = n.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().multiply(1.4);
n.setVelocity(velocity);
if (!(n instanceof Player) || (p.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, n.getLocation(), ProtectableAction.PVP))) {
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, n, DamageCause.ENTITY_ATTACK, e.getDamage() / 2);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) ((LivingEntity) n).damage(e.getDamage() / 2);
}
}
}
for (BlockFace face : BlockFace.values()) {
Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
}
}
@Override
protected void breakBlock(Player p, ItemStack item, Block b, int fortune, List<ItemStack> drops) {
if (MaterialTools.getBreakableByShovel().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK)) {
SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK);
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
for (ItemStack drop : b.getDrops(getItem())) {
if (drop != null) {
b.getWorld().dropItemNaturally(b.getLocation(), drop);
}
}
b.setType(Material.AIR);
damageItem(p, item);
}
}
@Override
protected void dig(Block b, BlockMenu menu, Block block) {
Collection<ItemStack> drops = block.getDrops(effectivePickaxe);
if (!MaterialCollections.getAllUnbreakableBlocks().contains(block.getType()) && !drops.isEmpty() && SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), block.getLocation(), ProtectableAction.BREAK_BLOCK)) {
AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b));
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// We only want to break non-Slimefun blocks
String blockId = BlockStorage.checkID(block);
if (blockId == null) {
for (ItemStack drop : drops) {
if (menu.fits(drop, getOutputSlots())) {
menu.pushItem(drop, getOutputSlots());
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
block.setType(Material.AIR);
}
}
}
}
}
@Override
protected boolean chopTree(Block b, BlockMenu menu, BlockFace face) {
if (MaterialCollections.getAllLogs().contains(b.getRelative(face).getType())) {
List<Block> list = Vein.find(b.getRelative(face), 180, block -> MaterialCollections.getAllLogs().contains(block.getType()));
if (!list.isEmpty()) {
Block log = list.get(list.size() - 1);
log.getWorld().playEffect(log.getLocation(), Effect.STEP_SOUND, log.getType());
if (SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), log.getLocation(), ProtectableAction.BREAK_BLOCK)) {
breakLog(log, b, menu, face);
}
return false;
}
}
return true;
}
@Override
public void effect(Event e, ItemStack item, final int level) {
if(e instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
Entity target = event.getEntity();
if(!(target instanceof Player))
return;
Player p = (Player) ((Projectile) event.getDamager()).getShooter();
Material bountyDrop = getBounty();
for(int i = 10; i>0; i--) {
p.getWorld().playEffect(p.getLocation(), Effect.COLOURED_DUST, 10);
p.getWorld().playEffect(target.getLocation(), Effect.COLOURED_DUST, 10);
}
p.getInventory().addItem(new ItemStack(bountyDrop, Tools.random.nextInt(MaximumBounty+level)+1));
p.sendMessage(ChatColor.GOLD + "You have collected a bounty on " + target.getName() + "!");
this.generateCooldown(p, Cooldown);
}
}
private void placeSlimefunBlock(SlimefunItem sfItem, ItemStack item, Block block, Dispenser dispenser) {
block.setType(item.getType());
BlockStorage.store(block, sfItem.getID());
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, item.getType());
if (item.getType() == Material.SPAWNER && sfItem instanceof RepairedSpawner) {
Optional<EntityType> entity = ((RepairedSpawner) sfItem).getEntityType(item);
if (entity.isPresent()) {
CreatureSpawner spawner = (CreatureSpawner) block.getState();
spawner.setSpawnedType(entity.get());
spawner.update(true, false);
}
}
if (dispenser.getInventory().containsAtLeast(item, 2)) {
dispenser.getInventory().removeItem(new CustomItem(item, 1));
}
else {
Slimefun.runSync(() -> dispenser.getInventory().removeItem(item), 2L);
}
}
private void craft(Player p, Block b, ItemStack output, Inventory outputInv) {
for (int i = 0; i < 4; i++) {
int j = i;
Bukkit.getScheduler().runTaskLater(SlimefunPlugin.instance, () -> {
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1);
p.getWorld().playEffect(b.getRelative(BlockFace.UP).getLocation(), Effect.SMOKE, 4);
p.getWorld().playEffect(b.getRelative(BlockFace.UP).getLocation(), Effect.SMOKE, 4);
p.getWorld().playEffect(b.getRelative(BlockFace.UP).getLocation(), Effect.SMOKE, 4);
if (j < 3) {
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_TNT_PRIMED, 1F, 1F);
}
else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
outputInv.addItem(output);
}
}, i * 20L);
}
}
private void startAnimation(Player p, Block b, Inventory inv, ItemStack output) {
for (int j = 0; j < 4; j++) {
int current = j;
Bukkit.getScheduler().runTaskLater(SlimefunPlugin.instance, () -> {
p.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
p.getWorld().playEffect(b.getLocation(), Effect.ENDER_SIGNAL, 1);
if (current < 3) {
p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1F, 1F);
}
else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
inv.addItem(output);
}
}, j * 20L);
}
}
@Override
public void onInteract(Player p, Block b) {
ItemStack log = p.getInventory().getItemInMainHand();
Optional<Material> planks = MaterialConverter.getPlanksFromLog(log.getType());
if (planks.isPresent()) {
if (p.getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(log, true);
}
ItemStack output = new ItemStack(planks.get(), 8);
Inventory outputChest = findOutputChest(b, output);
if (outputChest != null) {
outputChest.addItem(output);
}
else {
b.getWorld().dropItemNaturally(b.getLocation(), output);
}
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, log.getType());
}
}
@Override
public ItemUseHandler getItemHandler() {
return e -> {
Optional<Block> block = e.getClickedBlock();
e.setUseBlock(Result.DENY);
if (block.isPresent()) {
Block b = block.get();
if (b.getType() == Material.NETHER_WART) {
Ageable ageable = (Ageable) b.getBlockData();
if (ageable.getAge() < ageable.getMaximumAge()) {
ageable.setAge(ageable.getMaximumAge());
b.setBlockData(ageable);
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
if (e.getPlayer().getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(e.getItem(), false);
}
}
}
}
};
}
@Override
public ItemUseHandler getItemHandler() {
return e -> {
Player p = e.getPlayer();
if (p.getFoodLevel() >= 2) {
if (p.getInventory().getItemInMainHand().getType() != Material.SHEARS && p.getGameMode() != GameMode.CREATIVE) {
FoodLevelChangeEvent event = new FoodLevelChangeEvent(p, p.getFoodLevel() - 2);
Bukkit.getPluginManager().callEvent(event);
p.setFoodLevel(event.getFoodLevel());
}
p.setVelocity(p.getEyeLocation().getDirection().multiply(4));
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1);
p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1);
p.setFallDistance(0F);
}
else {
SlimefunPlugin.getLocalization().sendMessage(p, "messages.hungry", true);
}
};
}
@Override
public void tickLoaded() {
super.tickLoaded();
this.particleClock++;
if (this.flag.getDefinition().showBeam()) {
for (MatchPlayer player : flag.getMatch().getPlayers()) {
if (this.canSeeParticles(player.getBukkit())) {
player
.getBukkit()
.spigot()
.playEffect(
this.getLocation().clone().add(0, 56, 0),
Effect.TILE_DUST,
Material.WOOL.getId(),
flag.getDyeColor().getWoolData(),
0.15f, // radius on each axis of the particle ball
24f,
0.15f,
0f, // initial horizontal velocity
40, // number of particles
200); // radius in blocks to show particles
}
}
}
}
public void highlight(Hawk hawk, World world, double blocksAway, double accuracy) {
Bukkit.getScheduler().scheduleSyncDelayedTask(hawk, () -> {
for (double x = 0; x < blocksAway; x += accuracy) {
world.playEffect(getPointAtDistance(x).toLocation(world), Effect.COLOURED_DUST, 1);
}
}, 0L);
}
@Override
public void onRun() {
// Location to spawn the blood-item.
Location location = getLocation();
location.add(0, RandomUtils.random.nextFloat() * height, 0);
location.getWorld().playEffect(location, Effect.STEP_SOUND, material);
Entity entity = getEntity();
if (hurt && entity != null) {
entity.playEffect(org.bukkit.EntityEffect.HURT);
}
}
@Override
public void tickLoaded() {
super.tickLoaded();
if(this.particleClock % 10 == 0) {
this.flag.getMatch().getWorld().playEffect(this.getLocation().clone().add(0, 1, 0),
Effect.PORTAL,
0, 0,
0, 0, 0,
1, 8, 64);
}
}
@Override
public boolean effect(Event event, Player player) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
Entity entity = e.getEntity();
if(e.getDamager() == player && entity.getFireTicks() > 0) {
e.setDamage(damageMultiplier * e.getDamage());
entity.getWorld().playEffect(entity.getLocation(), Effect.ZOMBIE_DESTROY_DOOR, 10);
EffectManager.playSound(entity.getLocation(), "BLOCK_ANVIL_LAND", 1f, 0.001f);
return true;
}
return false;
}
@GameEvent
public void onStep(@Nonnull PlayerInteractEvent event) {
if (event.getAction() == Action.PHYSICAL) {
if (!Tag.WOODEN_PRESSURE_PLATES.isTagged(event.getClickedBlock().getType()) &&
event.getClickedBlock().getType() != Material.STONE_PRESSURE_PLATE) {
return;
}
if (event.isCancelled()) {
return;
}
double strength = 1.5;
double up = 1;
if (event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState() instanceof Sign) {
Sign sign = (Sign) event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState();
if (sign.getLine(0).contains("[Boom]")) {
try {
strength = Double.parseDouble(sign.getLine(1));
up = Double.parseDouble(sign.getLine(2));
} catch (final Exception ex) {
log.warning("Invalid boom sign at " + sign.getLocation());
}
}
}
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ENDER_DRAGON_SHOOT, 10.0F, 1.0F);
event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 10);
Vector v = event.getPlayer().getLocation().getDirection().multiply(strength / 2).setY(up / 2);
event.getPlayer().setVelocity(v);
event.setCancelled(true);
}
}
@GameEvent
public void onEntityDamage(EntityDamageEvent e) {
if (e.getEntityType() == EntityType.PLAYER) {
e.getEntity().getWorld().playEffect(e.getEntity().getLocation(), Effect.STEP_SOUND, Material.REDSTONE_WIRE);
e.getEntity().playEffect(EntityEffect.HURT);
}
}