mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-04 23:47:45 +01:00
Add explicit ender crystal protection.
Fixes WORLDGUARD-2620.
This commit is contained in:
parent
e5e1f71a2a
commit
12fc1438c2
@ -889,23 +889,36 @@ private static <T extends Event & Cancellable> void handleBlockRightClick(T even
|
|||||||
// next to redstone, without plugins getting the clicked place event
|
// next to redstone, without plugins getting the clicked place event
|
||||||
// (not sure if this actually still happens)
|
// (not sure if this actually still happens)
|
||||||
Events.fireToCancel(event, new UseBlockEvent(event, cause, clicked.getLocation(), Material.TNT));
|
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
|
// Handle created Minecarts
|
||||||
if (item != null && Materials.isMinecart(item.getType())) {
|
if (item != null && Materials.isMinecart(item.getType())) {
|
||||||
// TODO: Give a more specific Minecart type
|
// TODO: Give a more specific Minecart type
|
||||||
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.MINECART));
|
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.MINECART));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle created boats
|
// Handle created boats
|
||||||
if (item != null && Materials.isBoat(item.getType())) {
|
if (item != null && Materials.isBoat(item.getType())) {
|
||||||
// TODO as above
|
// TODO as above
|
||||||
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT));
|
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle created armor stands
|
// Handle created armor stands
|
||||||
if (item != null && item.getType() == Materials.ARMOR_STAND) {
|
if (item != null && item.getType() == Materials.ARMOR_STAND) {
|
||||||
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.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() == Materials.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
|
// Handle created spawn eggs
|
||||||
@ -918,6 +931,7 @@ private static <T extends Event & Cancellable> void handleBlockRightClick(T even
|
|||||||
}
|
}
|
||||||
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), type));
|
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), type));
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle cocoa beans
|
// Handle cocoa beans
|
||||||
@ -926,11 +940,7 @@ private static <T extends Event & Cancellable> void handleBlockRightClick(T even
|
|||||||
if (!(faceClicked == BlockFace.DOWN || faceClicked == BlockFace.UP)) {
|
if (!(faceClicked == BlockFace.DOWN || faceClicked == BlockFace.UP)) {
|
||||||
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), Material.COCOA));
|
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), Material.COCOA));
|
||||||
}
|
}
|
||||||
}
|
return;
|
||||||
|
|
||||||
// Workaround for http://leaky.bukkit.org/issues/1034
|
|
||||||
if (item != null && item.getType() == Material.TNT) {
|
|
||||||
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), Material.TNT));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
|
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
|
||||||
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
|
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
|
||||||
|
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||||
import com.sk89q.worldguard.bukkit.util.Materials;
|
import com.sk89q.worldguard.bukkit.util.Materials;
|
||||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
@ -61,10 +62,6 @@ public void onPlaceBlock(final PlaceBlockEvent event) {
|
|||||||
|
|
||||||
Block block;
|
Block block;
|
||||||
if ((block = event.getCause().getFirstBlock()) != null) {
|
if ((block = event.getCause().getFirstBlock()) != null) {
|
||||||
// ================================================================
|
|
||||||
// PISTONS flag
|
|
||||||
// ================================================================
|
|
||||||
|
|
||||||
if (Materials.isPistonBlock(block.getType())) {
|
if (Materials.isPistonBlock(block.getType())) {
|
||||||
event.filter(testState(query, DefaultFlag.PISTONS), false);
|
event.filter(testState(query, DefaultFlag.PISTONS), false);
|
||||||
}
|
}
|
||||||
@ -80,31 +77,22 @@ public void onBreakBlock(final BreakBlockEvent event) {
|
|||||||
|
|
||||||
Block block;
|
Block block;
|
||||||
if ((block = event.getCause().getFirstBlock()) != null) {
|
if ((block = event.getCause().getFirstBlock()) != null) {
|
||||||
// ================================================================
|
|
||||||
// PISTONS flag
|
|
||||||
// ================================================================
|
|
||||||
|
|
||||||
if (Materials.isPistonBlock(block.getType())) {
|
if (Materials.isPistonBlock(block.getType())) {
|
||||||
event.filter(testState(query, DefaultFlag.PISTONS), false);
|
event.filter(testState(query, DefaultFlag.PISTONS), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================================================
|
|
||||||
// CREEPER_EXPLOSION flag
|
|
||||||
// ================================================================
|
|
||||||
|
|
||||||
if (event.getCause().find(EntityType.CREEPER) != null) { // Creeper
|
if (event.getCause().find(EntityType.CREEPER) != null) { // Creeper
|
||||||
event.filter(testState(query, DefaultFlag.CREEPER_EXPLOSION), config.explosionFlagCancellation);
|
event.filter(testState(query, DefaultFlag.CREEPER_EXPLOSION), config.explosionFlagCancellation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================================================
|
|
||||||
// ENDERDRAGON_BLOCK_DAMAGE flag
|
|
||||||
// ================================================================
|
|
||||||
|
|
||||||
if (event.getCause().find(EntityType.ENDER_DRAGON) != null) { // Enderdragon
|
if (event.getCause().find(EntityType.ENDER_DRAGON) != null) { // Enderdragon
|
||||||
event.filter(testState(query, DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE), config.explosionFlagCancellation);
|
event.filter(testState(query, DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE), config.explosionFlagCancellation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.getCause().find(Entities.enderCrystalType) != null) { // should be nullsafe even if enderCrystalType field is null
|
||||||
|
event.filter(testState(query, DefaultFlag.OTHER_EXPLOSION), config.explosionFlagCancellation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
@ -182,6 +182,8 @@ public static boolean isNonPlayerCreature(Entity entity) {
|
|||||||
|
|
||||||
private static final EntityType armorStandType =
|
private static final EntityType armorStandType =
|
||||||
Enums.findByValue(EntityType.class, "ARMOR_STAND");
|
Enums.findByValue(EntityType.class, "ARMOR_STAND");
|
||||||
|
public static final EntityType enderCrystalType =
|
||||||
|
Enums.findByValue(EntityType.class, "ENDER_CRYSTAL");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether using the given entity should be considered "building"
|
* Test whether using the given entity should be considered "building"
|
||||||
@ -192,7 +194,8 @@ public static boolean isNonPlayerCreature(Entity entity) {
|
|||||||
*/
|
*/
|
||||||
public static boolean isConsideredBuildingIfUsed(Entity entity) {
|
public static boolean isConsideredBuildingIfUsed(Entity entity) {
|
||||||
return entity instanceof Hanging
|
return entity instanceof Hanging
|
||||||
|| entity.getType() == armorStandType;
|
|| entity.getType() == armorStandType
|
||||||
|
|| entity.getType() == enderCrystalType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final EntityType tippedArrow = Enums.findByValue(EntityType.class, "TIPPED_ARROW");
|
private static final EntityType tippedArrow = Enums.findByValue(EntityType.class, "TIPPED_ARROW");
|
||||||
|
@ -47,12 +47,16 @@ public final class Materials {
|
|||||||
private static final Set<PotionEffectType> DAMAGE_EFFECTS = new HashSet<PotionEffectType>();
|
private static final Set<PotionEffectType> DAMAGE_EFFECTS = new HashSet<PotionEffectType>();
|
||||||
|
|
||||||
public static Material ARMOR_STAND;
|
public static Material ARMOR_STAND;
|
||||||
|
public static Material END_CRYSTAL;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
|
// for backwards compatible access to material enum
|
||||||
ARMOR_STAND = Material.ARMOR_STAND;
|
ARMOR_STAND = Material.ARMOR_STAND;
|
||||||
|
END_CRYSTAL = Material.END_CRYSTAL;
|
||||||
} catch (NoSuchFieldError ignored) {
|
} catch (NoSuchFieldError ignored) {
|
||||||
ARMOR_STAND = null;
|
ARMOR_STAND = null;
|
||||||
|
END_CRYSTAL = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ENTITY_ITEMS.put(EntityType.PAINTING, Material.PAINTING);
|
ENTITY_ITEMS.put(EntityType.PAINTING, Material.PAINTING);
|
||||||
|
Loading…
Reference in New Issue
Block a user