use of com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method handleBlockRightClick.
/**
* Handle the right click of a block while an item is held.
*
* @param event the original event
* @param cause the list of cause
* @param item the item
* @param placed the placed block
* @param <T> the event type
*/
private static <T extends Event & Cancellable> void handleBlockRightClick(T event, Cause cause, @Nullable ItemStack item, Block clicked, Block placed) {
if (item != null && item.getType() == Material.TNT) {
// Workaround for a bug that allowed TNT to trigger instantly if placed
// next to redstone, without plugins getting the clicked place event
// (not sure if this actually still happens) -- note Jun 2019 - happens with dispensers still, tho not players
Events.fireToCancel(event, new UseBlockEvent(event, cause, clicked.getLocation(), Material.TNT));
// Workaround for http://leaky.bukkit.org/issues/1034
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), Material.TNT));
return;
}
// Handle created Minecarts
if (item != null && Materials.isMinecart(item.getType())) {
EntityType entityType = Materials.getRelatedEntity(item.getType());
if (entityType == null) {
entityType = EntityType.MINECART;
}
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, clicked.getLocation().add(0.5, 0, 0.5), entityType));
return;
}
// Handle created boats
if (item != null && Materials.isBoat(item.getType())) {
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT));
return;
}
// Handle created armor stands
if (item != null && item.getType() == Material.ARMOR_STAND) {
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.ARMOR_STAND));
return;
}
if (item != null && item.getType() == Material.END_CRYSTAL) {
/*&& placed.getType() == Material.BEDROCK) {*/
// in vanilla you can only place them on bedrock but who knows what plugins will add
// may be overprotective as a result, but better than being underprotective
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.ENDER_CRYSTAL));
return;
}
// Handle created spawn eggs
if (item != null && Materials.isSpawnEgg(item.getType())) {
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), Materials.getEntitySpawnEgg(item.getType())));
return;
}
// handle water/lava placement
if (item != null && (item.getType() == Material.WATER_BUCKET || item.getType() == Material.LAVA_BUCKET)) {
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), item.getType() == Material.WATER_BUCKET ? Material.WATER : Material.LAVA));
return;
}
}
Aggregations