1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
package org.bukkit.craftbukkit.event;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.minecraft.server.ChunkCoordinates;
import net.minecraft.server.Container;
import net.minecraft.server.DamageSource;
import net.minecraft.server.Entity;
import net.minecraft.server.EntityArrow;
import net.minecraft.server.EntityDamageSource;
import net.minecraft.server.EntityDamageSourceIndirect;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityItem;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.EntityPotion;
import net.minecraft.server.InventoryCrafting;
import net.minecraft.server.Item;
import net.minecraft.server.ItemStack;
import net.minecraft.server.Packet101CloseWindow;
import net.minecraft.server.World;
import net.minecraft.server.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Pig;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.ThrownExpBottle;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.Event;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.inventory.InventoryView;
public class CraftEventFactory {
// helper methods
private static boolean canBuild(CraftWorld world, Player player, int x, int z) {
WorldServer worldServer = world.getHandle();
int spawnSize = Bukkit.getServer().getSpawnRadius();
if (world.getHandle().dimension != 0) return true;
if (spawnSize <= 0) return true;
if (player.isOp()) return true;
ChunkCoordinates chunkcoordinates = worldServer.getSpawn();
int distanceFromSpawn = (int) Math.max(Math.abs(x - chunkcoordinates.x), Math.abs(z - chunkcoordinates.z));
return distanceFromSpawn >= spawnSize;
}
public static <T extends Event> T callEvent(T event) {
Bukkit.getServer().getPluginManager().callEvent(event);
return event;
}
/**
* Block place methods
*/
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
CraftWorld craftWorld = ((WorldServer) world).getWorld();
CraftServer craftServer = ((WorldServer) world).getServer();
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
Block placedBlock = replacedBlockState.getBlock();
boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());
BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, player.getItemInHand(), player, canBuild);
craftServer.getPluginManager().callEvent(event);
return event;
}
/**
* Bucket methods
*/
public static PlayerBucketEmptyEvent callPlayerBucketEmptyEvent(EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemInHand) {
return (PlayerBucketEmptyEvent) getPlayerBucketEvent(false, who, clickedX, clickedY, clickedZ, clickedFace, itemInHand, Item.BUCKET);
}
public static PlayerBucketFillEvent callPlayerBucketFillEvent(EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemInHand, net.minecraft.server.Item bucket) {
return (PlayerBucketFillEvent) getPlayerBucketEvent(true, who, clickedX, clickedY, clickedZ, clickedFace, itemInHand, bucket);
}
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemstack, net.minecraft.server.Item item) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = new CraftItemStack(new ItemStack(item));
Material bucket = Material.getMaterial(itemstack.id);
CraftWorld craftWorld = (CraftWorld) player.getWorld();
CraftServer craftServer = (CraftServer) player.getServer();
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);
PlayerEvent event = null;
if (isFilling) {
event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
} else {
event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
}
craftServer.getPluginManager().callEvent(event);
return event;
}
/**
* Player Interact event
*/
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, ItemStack itemstack) {
if (action != Action.LEFT_CLICK_AIR && action != Action.RIGHT_CLICK_AIR) {
throw new IllegalArgumentException();
}
return callPlayerInteractEvent(who, action, 0, 256, 0, 0, itemstack);
}
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemstack) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = new CraftItemStack(itemstack);
CraftWorld craftWorld = (CraftWorld) player.getWorld();
CraftServer craftServer = (CraftServer) player.getServer();
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);
if (clickedY > 255) {
blockClicked = null;
switch (action) {
case LEFT_CLICK_BLOCK:
action = Action.LEFT_CLICK_AIR;
break;
case RIGHT_CLICK_BLOCK:
action = Action.RIGHT_CLICK_AIR;
break;
}
}
if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
itemInHand = null;
}
PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace);
craftServer.getPluginManager().callEvent(event);
return event;
}
/**
* EntityShootBowEvent
*/
public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, ItemStack itemstack, EntityArrow entityArrow, float force) {
LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
CraftItemStack itemInHand = new CraftItemStack(itemstack);
Arrow arrow = (Arrow) entityArrow.getBukkitEntity();
if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
itemInHand = null;
}
EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force);
Bukkit.getPluginManager().callEvent(event);
return event;
}
/**
* BlockDamageEvent
*/
public static BlockDamageEvent callBlockDamageEvent(EntityHuman who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = new CraftItemStack(itemstack);
CraftWorld craftWorld = (CraftWorld) player.getWorld();
CraftServer craftServer = (CraftServer) player.getServer();
Block blockClicked = craftWorld.getBlockAt(x, y, z);
BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak);
craftServer.getPluginManager().callEvent(event);
return event;
}
/**
* CreatureSpawnEvent
*/
public static CreatureSpawnEvent callCreatureSpawnEvent(EntityLiving entityliving, SpawnReason spawnReason) {
LivingEntity entity = (LivingEntity) entityliving.getBukkitEntity();
CraftServer craftServer = (CraftServer) entity.getServer();
CreatureSpawnEvent event = new CreatureSpawnEvent(entity, spawnReason);
craftServer.getPluginManager().callEvent(event);
return event;
}
/**
* EntityTameEvent
*/
public static EntityTameEvent callEntityTameEvent(EntityLiving entity, EntityHuman tamer) {
org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
org.bukkit.entity.AnimalTamer bukkitTamer = (tamer != null ? (AnimalTamer) tamer.getBukkitEntity() : null);
CraftServer craftServer = (CraftServer) bukkitEntity.getServer();
EntityTameEvent event = new EntityTameEvent((LivingEntity) bukkitEntity, bukkitTamer);
craftServer.getPluginManager().callEvent(event);
return event;
}
/**
* ItemSpawnEvent
*/
public static ItemSpawnEvent callItemSpawnEvent(EntityItem entityitem) {
org.bukkit.entity.Item entity = (org.bukkit.entity.Item) entityitem.getBukkitEntity();
CraftServer craftServer = (CraftServer) entity.getServer();
ItemSpawnEvent event = new ItemSpawnEvent(entity, entity.getLocation());
craftServer.getPluginManager().callEvent(event);
return event;
}
/**
* ItemDespawnEvent
*/
public static ItemDespawnEvent callItemDespawnEvent(EntityItem entityitem) {
org.bukkit.entity.Item entity = (org.bukkit.entity.Item) entityitem.getBukkitEntity();
ItemDespawnEvent event = new ItemDespawnEvent(entity, entity.getLocation());
((CraftServer) entity.getServer()).getPluginManager().callEvent(event);
return event;
}
/**
* PotionSplashEvent
*/
public static PotionSplashEvent callPotionSplashEvent(EntityPotion potion, Map<LivingEntity, Double> affectedEntities) {
ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity();
PotionSplashEvent event = new PotionSplashEvent(thrownPotion, affectedEntities);
Bukkit.getPluginManager().callEvent(event);
return event;
}
/**
* BlockFadeEvent
*/
public static BlockFadeEvent callBlockFadeEvent(Block block, int type) {
BlockState state = block.getState();
state.setTypeId(type);
BlockFadeEvent event = new BlockFadeEvent(block, state);
Bukkit.getPluginManager().callEvent(event);
return event;
}
public static void handleBlockSpreadEvent(Block block, Block source, int type, int data) {
BlockState state = block.getState();
state.setTypeId(type);
state.setRawData((byte) data);
BlockSpreadEvent event = new BlockSpreadEvent(block, source, state);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
state.update(true);
}
}
public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim) {
return callEntityDeathEvent(victim, new ArrayList<org.bukkit.inventory.ItemStack>(0));
}
public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim, List<org.bukkit.inventory.ItemStack> drops) {
CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward());
org.bukkit.World world = entity.getWorld();
Bukkit.getServer().getPluginManager().callEvent(event);
victim.expToDrop = event.getDroppedExp();
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
if (stack == null || stack.getType() == Material.AIR) continue;
if (stack instanceof CraftItemStack) {
// Use the internal item to preserve possible data.
victim.a(((CraftItemStack) stack).getHandle(), 0.0f);
}
else {
world.dropItemNaturally(entity.getLocation(), stack);
}
}
return event;
}
public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage) {
CraftPlayer entity = (CraftPlayer) victim.getBukkitEntity();
PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
org.bukkit.World world = entity.getWorld();
Bukkit.getServer().getPluginManager().callEvent(event);
victim.keepLevel = event.getKeepLevel();
victim.newLevel = event.getNewLevel();
victim.newTotalExp = event.getNewTotalExp();
victim.expToDrop = event.getDroppedExp();
victim.newExp = event.getNewExp();
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
if (stack == null || stack.getType() == Material.AIR) continue;
if (stack instanceof CraftItemStack) {
// Use the internal item to preserve possible data.
victim.a(((CraftItemStack) stack).getHandle(), 0.0f);
} else {
world.dropItemNaturally(entity.getLocation(), stack);
}
}
return event;
}
/**
* Server methods
*/
public static ServerListPingEvent callServerListPingEvent(Server craftServer, InetAddress address, String motd, int numPlayers, int maxPlayers) {
ServerListPingEvent event = new ServerListPingEvent(address, motd, numPlayers, maxPlayers);
craftServer.getPluginManager().callEvent(event);
return event;
}
/**
* EntityDamage(ByEntityEvent)
*/
public static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, int damage) {
EntityDamageEvent event;
if (damager != null) {
event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, damage);
} else {
event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, damage);
}
callEvent(event);
if (!event.isCancelled()) {
event.getEntity().setLastDamageCause(event);
}
return event;
}
public static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, int damage) {
Entity damager = source.getEntity();
DamageCause cause = DamageCause.ENTITY_ATTACK;
if (source instanceof EntityDamageSourceIndirect) {
damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource();
if (damager.getBukkitEntity() instanceof ThrownPotion) {
cause = DamageCause.MAGIC;
} else if (damager.getBukkitEntity() instanceof Projectile) {
cause = DamageCause.PROJECTILE;
}
}
return callEntityDamageEvent(damager, entity, cause, damage);
}
// Non-Living Entities such as EntityEnderCrystal need to call this
public static boolean handleNonLivingEntityDamageEvent(Entity entity, DamageSource source, int damage) {
if (!(source instanceof EntityDamageSource)) {
return false;
}
EntityDamageEvent event = handleEntityDamageEvent(entity, source, damage);
return event.isCancelled() || event.getDamage() == 0;
}
public static PlayerLevelChangeEvent callPlayerLevelChangeEvent(Player player, int oldLevel, int newLevel) {
PlayerLevelChangeEvent event = new PlayerLevelChangeEvent(player, oldLevel, newLevel);
Bukkit.getPluginManager().callEvent(event);
return event;
}
public static PlayerExpChangeEvent callPlayerExpChangeEvent(EntityHuman entity, int expAmount) {
Player player = (Player) entity.getBukkitEntity();
PlayerExpChangeEvent event = new PlayerExpChangeEvent(player, expAmount);
Bukkit.getPluginManager().callEvent(event);
return event;
}
public static void handleBlockGrowEvent(World world, int x, int y, int z, int type, int data) {
Block block = world.getWorld().getBlockAt(x, y, z);
CraftBlockState state = (CraftBlockState) block.getState();
state.setTypeId(type);
state.setRawData((byte) data);
BlockGrowEvent event = new BlockGrowEvent(block, state);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
state.update(true);
}
}
public static FoodLevelChangeEvent callFoodLevelChangeEvent(EntityHuman entity, int level) {
FoodLevelChangeEvent event = new FoodLevelChangeEvent((Player) entity.getBukkitEntity(), level);
entity.getBukkitEntity().getServer().getPluginManager().callEvent(event);
return event;
}
public static PigZapEvent callPigZapEvent(Entity pig, Entity lightning, Entity pigzombie) {
PigZapEvent event = new PigZapEvent((Pig) pig.getBukkitEntity(), (LightningStrike) lightning.getBukkitEntity(), (PigZombie) pigzombie.getBukkitEntity());
pig.getBukkitEntity().getServer().getPluginManager().callEvent(event);
return event;
}
public static EntityChangeBlockEvent callEntityChangeBlockEvent(org.bukkit.entity.Entity entity, Block block, Material material) {
return callEntityChangeBlockEvent(entity, block, material, 0);
}
public static EntityChangeBlockEvent callEntityChangeBlockEvent(Entity entity, Block block, Material material) {
return callEntityChangeBlockEvent(entity.getBukkitEntity(), block, material, 0);
}
public static EntityChangeBlockEvent callEntityChangeBlockEvent(Entity entity, int x, int y, int z, int type, int data) {
Block block = entity.world.getWorld().getBlockAt(x, y, z);
Material material = Material.getMaterial(type);
return callEntityChangeBlockEvent(entity.getBukkitEntity(), block, material, data);
}
public static EntityChangeBlockEvent callEntityChangeBlockEvent(org.bukkit.entity.Entity entity, Block block, Material material, int data) {
EntityChangeBlockEvent event = new EntityChangeBlockEvent(entity, block, material, (byte) data);
entity.getServer().getPluginManager().callEvent(event);
return event;
}
public static CreeperPowerEvent callCreeperPowerEvent(Entity creeper, Entity lightning, CreeperPowerEvent.PowerCause cause) {
CreeperPowerEvent event = new CreeperPowerEvent((Creeper) creeper.getBukkitEntity(), (LightningStrike) lightning.getBukkitEntity(), cause);
creeper.getBukkitEntity().getServer().getPluginManager().callEvent(event);
return event;
}
public static EntityTargetEvent callEntityTargetEvent(Entity entity, Entity target, EntityTargetEvent.TargetReason reason) {
EntityTargetEvent event = new EntityTargetEvent(entity.getBukkitEntity(), target == null ? null : target.getBukkitEntity(), reason);
entity.getBukkitEntity().getServer().getPluginManager().callEvent(event);
return event;
}
public static EntityTargetLivingEntityEvent callEntityTargetLivingEvent(Entity entity, EntityLiving target, EntityTargetEvent.TargetReason reason) {
EntityTargetLivingEntityEvent event = new EntityTargetLivingEntityEvent(entity.getBukkitEntity(), (LivingEntity) target.getBukkitEntity(), reason);
entity.getBukkitEntity().getServer().getPluginManager().callEvent(event);
return event;
}
public static EntityBreakDoorEvent callEntityBreakDoorEvent(Entity entity, int x, int y, int z) {
org.bukkit.entity.Entity entity1 = entity.getBukkitEntity();
Block block = entity1.getWorld().getBlockAt(x, y, z);
EntityBreakDoorEvent event = new EntityBreakDoorEvent((LivingEntity) entity1, block);
entity1.getServer().getPluginManager().callEvent(event);
return event;
}
public static Container callInventoryOpenEvent(EntityPlayer player, Container container) {
if (player.activeContainer != player.defaultContainer) { // fire INVENTORY_CLOSE if one already open
player.netServerHandler.handleContainerClose(new Packet101CloseWindow(player.activeContainer.windowId));
}
CraftServer server = ((WorldServer) player.world).getServer();
CraftPlayer craftPlayer = (CraftPlayer) player.getBukkitEntity();
player.activeContainer.transferTo(container, craftPlayer);
InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
container.transferTo(player.activeContainer, craftPlayer);
return null;
}
return container;
}
public static ItemStack callPreCraftEvent(InventoryCrafting matrix, ItemStack result, InventoryView lastCraftView, boolean isRepair) {
CraftInventoryCrafting inventory = new CraftInventoryCrafting(matrix, matrix.resultInventory);
inventory.setResult(new CraftItemStack(result));
PrepareItemCraftEvent event = new PrepareItemCraftEvent(inventory, lastCraftView, isRepair);
Bukkit.getPluginManager().callEvent(event);
org.bukkit.inventory.ItemStack bitem = event.getInventory().getResult();
return CraftItemStack.createNMSItemStack(bitem);
}
public static ProjectileLaunchEvent callProjectileLaunchEvent(Entity entity) {
Projectile bukkitEntity = (Projectile) entity.getBukkitEntity();
ProjectileLaunchEvent event = new ProjectileLaunchEvent(bukkitEntity);
Bukkit.getPluginManager().callEvent(event);
return event;
}
public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) {
ThrownExpBottle bottle = (ThrownExpBottle) entity.getBukkitEntity();
ExpBottleEvent event = new ExpBottleEvent(bottle, exp);
Bukkit.getPluginManager().callEvent(event);
return event;
}
public static BlockRedstoneEvent callRedstoneChange(World world, int x, int y, int z, int oldCurrent, int newCurrent) {
BlockRedstoneEvent event = new BlockRedstoneEvent(world.getWorld().getBlockAt(x, y, z), oldCurrent, newCurrent);
world.getServer().getPluginManager().callEvent(event);
return event;
}
public static NotePlayEvent callNotePlayEvent(World world, int x, int y, int z, byte instrument, byte note) {
NotePlayEvent event = new NotePlayEvent(world.getWorld().getBlockAt(x, y, z), org.bukkit.Instrument.getByType(instrument), new org.bukkit.Note(note));
world.getServer().getPluginManager().callEvent(event);
return event;
}
public static void callPlayerItemBreakEvent(EntityHuman human, ItemStack brokenItem) {
CraftItemStack item = new CraftItemStack(brokenItem);
PlayerItemBreakEvent event = new PlayerItemBreakEvent((Player) human.getBukkitEntity(), item);
Bukkit.getPluginManager().callEvent(event);
}
}
|