mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-10 18:37:39 +01:00
Treat farmland and turtle egg PIE as EntityChangeBlock.
Note that as in d37f015f
this decouples the event from interact flag,
meaning that block-trampling must be explicitly set to allow to maintain
previous behavior. It also means that setting interact to allow won't
by default allow players to trample turtle eggs (but this wasn't the case
for farmland, since that was already handled by ECB - thanks Bukkit).
Fixes WORLDGUARD-4163.
This commit is contained in:
parent
0332929531
commit
6f6125fe00
@ -270,14 +270,20 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
boolean trample = fromType == Material.FARMLAND && toType == Material.DIRT;
|
||||
BreakBlockEvent breakDelagate = new BreakBlockEvent(event, cause, block);
|
||||
if (trample) {
|
||||
breakDelagate.setSilent(true);
|
||||
breakDelagate.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
}
|
||||
if (!Events.fireToCancel(event, breakDelagate)) {
|
||||
boolean denied;
|
||||
if (!(denied = Events.fireToCancel(event, breakDelagate))) {
|
||||
PlaceBlockEvent placeDelegate = new PlaceBlockEvent(event, cause, block.getLocation(), toType);
|
||||
if (trample) {
|
||||
placeDelegate.setSilent(true);
|
||||
placeDelegate.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
}
|
||||
Events.fireToCancel(event, placeDelegate);
|
||||
denied = Events.fireToCancel(event, placeDelegate);
|
||||
}
|
||||
if (denied && entity instanceof Player) {
|
||||
playDenyEffect((Player) entity, block.getLocation());
|
||||
}
|
||||
} else {
|
||||
if (toType == Material.AIR) {
|
||||
@ -395,23 +401,37 @@ public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
@Nullable ItemStack item = event.getItem();
|
||||
Block clicked = event.getClickedBlock();
|
||||
Block placed;
|
||||
boolean silent = false;
|
||||
boolean modifiesWorld;
|
||||
Cause cause = create(player);
|
||||
|
||||
switch (event.getAction()) {
|
||||
case PHYSICAL:
|
||||
if (event.useInteractedBlock() != Result.DENY) {
|
||||
if (clicked.getType() == Material.FARMLAND || clicked.getType() == Material.TURTLE_EGG) {
|
||||
BreakBlockEvent breakDelagate = new BreakBlockEvent(event, cause, clicked);
|
||||
breakDelagate.setSilent(true);
|
||||
breakDelagate.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
boolean denied;
|
||||
if (!(denied = Events.fireToCancel(event, breakDelagate))) {
|
||||
PlaceBlockEvent placeDelegate = new PlaceBlockEvent(event, cause, clicked.getLocation(),
|
||||
clicked.getType() == Material.FARMLAND ? Material.DIRT : clicked.getType());
|
||||
placeDelegate.setSilent(true);
|
||||
placeDelegate.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
denied = Events.fireToCancel(event, placeDelegate);
|
||||
}
|
||||
if (denied) {
|
||||
playDenyEffect(player, clicked.getLocation());
|
||||
}
|
||||
return;
|
||||
}
|
||||
DelegateEvent firedEvent = new UseBlockEvent(event, cause, clicked).setAllowed(hasInteractBypass(clicked));
|
||||
if (clicked.getType() == Material.REDSTONE_ORE) {
|
||||
silent = true;
|
||||
firedEvent.setSilent(true);
|
||||
}
|
||||
if (clicked.getType() == Material.FARMLAND || clicked.getType() == Material.TURTLE_EGG) {
|
||||
silent = true;
|
||||
firedEvent.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS);
|
||||
}
|
||||
firedEvent.setSilent(silent);
|
||||
interactDebounce.debounce(clicked, event.getPlayer(), event, firedEvent);
|
||||
if (event.useInteractedBlock() == Result.DENY) {
|
||||
playDenyEffect(player, clicked.getLocation().add(0, 1, 0));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -41,7 +41,6 @@
|
||||
import com.sk89q.worldguard.bukkit.util.Materials;
|
||||
import com.sk89q.worldguard.commands.CommandUtils;
|
||||
import com.sk89q.worldguard.config.WorldConfiguration;
|
||||
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
|
Loading…
Reference in New Issue
Block a user