mirror of
https://github.com/bloodmc/GriefDefender.git
synced 2025-02-18 02:11:23 +01:00
Fix wrong data passed in block form/spread events.
* Fix entity block damage being ignored in wilderness. * Fix owners not being able to damage untamed animals. Fixes #195 Fixes #174 Fixes #167
This commit is contained in:
parent
3dbce18e82
commit
c3b6e3b6fb
@ -104,24 +104,24 @@ public BlockEventHandler(BaseStorage dataStore) {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockFadeEvent(BlockFadeEvent event) {
|
||||
CommonBlockEventHandler.getInstance().handleBlockModify(event, event.getBlock(), event.getNewState().getBlock());
|
||||
CommonBlockEventHandler.getInstance().handleBlockModify(event, event.getBlock(), event.getNewState());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
CommonBlockEventHandler.getInstance().handleBlockSpread(event, event.getBlock(), event.getNewState().getBlock());
|
||||
CommonBlockEventHandler.getInstance().handleBlockPlace(event, event.getBlock(), event.getNewState());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockSpreadEvent(BlockSpreadEvent event) {
|
||||
CommonBlockEventHandler.getInstance().handleBlockSpread(event, event.getSource(), event.getNewState().getBlock());
|
||||
CommonBlockEventHandler.getInstance().handleBlockSpread(event, event.getSource(), event.getNewState());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
final Block fromBlock = NMSUtil.getInstance().getIgnitingBlock(event);
|
||||
final Block toBlock = event.getBlock();
|
||||
CommonBlockEventHandler.getInstance().handleBlockModify(event, fromBlock, toBlock);
|
||||
CommonBlockEventHandler.getInstance().handleBlockModify(event, fromBlock, toBlock.getState());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@ -316,7 +316,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
GDCauseStackManager.getInstance().pushCause(event.getPlayer());
|
||||
}
|
||||
final Object source = event.getIgnitingBlock() != null ? event.getIgnitingBlock() : event.getIgnitingEntity();
|
||||
CommonBlockEventHandler.getInstance().handleBlockModify(event, source, event.getBlock());
|
||||
CommonBlockEventHandler.getInstance().handleBlockModify(event, source, event.getBlock().getState());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
|
@ -27,12 +27,13 @@
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import com.griefdefender.GriefDefenderPlugin;
|
||||
import com.griefdefender.api.Tristate;
|
||||
import com.griefdefender.api.claim.TrustTypes;
|
||||
@ -62,7 +63,7 @@ public CommonBlockEventHandler() {
|
||||
this.storage = GriefDefenderPlugin.getInstance().dataStore;
|
||||
}
|
||||
|
||||
public void handleBlockSpread(Event event, Block fromBlock, Block toBlock) {
|
||||
public void handleBlockSpread(Event event, Block fromBlock, BlockState newState) {
|
||||
if (!GDFlags.BLOCK_SPREAD) {
|
||||
return;
|
||||
}
|
||||
@ -75,16 +76,16 @@ public void handleBlockSpread(Event event, Block fromBlock, Block toBlock) {
|
||||
final Location sourceLocation = fromBlock != null ? fromBlock.getLocation() : null;
|
||||
final GDPermissionUser user = CauseContextHelper.getEventUser(sourceLocation);
|
||||
|
||||
Location location = toBlock.getLocation();
|
||||
Location location = newState.getLocation();
|
||||
GDClaim targetClaim = this.storage.getClaimAt(location);
|
||||
|
||||
final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_SPREAD, fromBlock, toBlock, user, TrustTypes.BUILDER, true);
|
||||
final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_SPREAD, fromBlock, newState, user, TrustTypes.BUILDER, true);
|
||||
if (result == Tristate.FALSE) {
|
||||
((Cancellable) event).setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleBlockModify(Event event, Object source, Block toBlock) {
|
||||
public void handleBlockModify(Event event, Object source, BlockState newState) {
|
||||
if (!GDFlags.BLOCK_MODIFY) {
|
||||
return;
|
||||
}
|
||||
@ -93,16 +94,16 @@ public void handleBlockModify(Event event, Object source, Block toBlock) {
|
||||
if (source instanceof Block) {
|
||||
fromBlock = (Block) source;
|
||||
}
|
||||
if (!(event instanceof BlockBurnEvent) && fromBlock != null && toBlock != null && !fromBlock.getLocation().equals(toBlock.getLocation())) {
|
||||
handleBlockSpread(event, fromBlock, toBlock);
|
||||
if (!(event instanceof BlockBurnEvent) && fromBlock != null && newState != null && !fromBlock.getLocation().equals(newState.getLocation())) {
|
||||
handleBlockSpread(event, fromBlock, newState);
|
||||
return;
|
||||
}
|
||||
if (source instanceof Entity) {
|
||||
handleBlockPlace(event, source, toBlock);
|
||||
handleBlockPlace(event, source, newState);
|
||||
return;
|
||||
}
|
||||
|
||||
final World world = toBlock.getWorld();
|
||||
final World world = newState.getWorld();
|
||||
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
|
||||
return;
|
||||
}
|
||||
@ -110,39 +111,42 @@ public void handleBlockModify(Event event, Object source, Block toBlock) {
|
||||
final Location sourceLocation = fromBlock != null ? fromBlock.getLocation() : null;
|
||||
final GDPermissionUser user = CauseContextHelper.getEventUser(sourceLocation);
|
||||
|
||||
Location location = toBlock.getLocation();
|
||||
Location location = newState.getLocation();
|
||||
GDClaim targetClaim = this.storage.getClaimAt(location);
|
||||
|
||||
final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_MODIFY, source, toBlock, user, TrustTypes.BUILDER, true);
|
||||
final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_MODIFY, source, newState, user, TrustTypes.BUILDER, true);
|
||||
if (result == Tristate.FALSE) {
|
||||
((Cancellable) event).setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleBlockPlace(Event event, Object source, Block block) {
|
||||
public void handleBlockPlace(Event event, Object source, BlockState newState) {
|
||||
if (!GDFlags.BLOCK_PLACE) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = source instanceof Player ? (Player) source : null;
|
||||
final Location location = block.getLocation();
|
||||
final Location location = newState.getLocation();
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final World world = block.getWorld();
|
||||
final World world = newState.getWorld();
|
||||
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player == null) {
|
||||
final GDPermissionUser user = CauseContextHelper.getEventUser(location);
|
||||
player = user != null ? user.getOnlinePlayer() : null;
|
||||
// BlockFormEvent's are triggered based on world conditions and should not be caused by a player
|
||||
if (!(source instanceof Entity) && !(event instanceof BlockFormEvent)) {
|
||||
final GDPermissionUser user = CauseContextHelper.getEventUser(location);
|
||||
player = user != null ? user.getOnlinePlayer() : null;
|
||||
}
|
||||
}
|
||||
|
||||
GDClaim targetClaim = this.storage.getClaimAt(location);
|
||||
|
||||
final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_PLACE, source, block, player, TrustTypes.BUILDER, true);
|
||||
final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_PLACE, source, newState, player, TrustTypes.BUILDER, true);
|
||||
if (result == Tristate.FALSE) {
|
||||
((Cancellable) event).setCancelled(true);
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ public EntityEventHandler(BaseStorage dataStore) {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onEntityBlockFormEvent(EntityBlockFormEvent event) {
|
||||
CommonBlockEventHandler.getInstance().handleBlockPlace(event, event.getEntity(), event.getBlock());
|
||||
CommonBlockEventHandler.getInstance().handleBlockPlace(event, event.getEntity(), event.getNewState());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@ -138,9 +138,6 @@ public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
|
||||
|
||||
final Location location = block.getLocation();
|
||||
final GDClaim targetClaim = this.baseStorage.getClaimAt(location);
|
||||
if (targetClaim.isWilderness()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Entity source = event.getEntity();
|
||||
GDPermissionUser user = null;
|
||||
@ -353,6 +350,12 @@ public void onEntityDamage(EntityDamageByEntityEvent event) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// always allow owner to damage their untamed animals
|
||||
final GDClaim claim = this.baseStorage.getClaimAt(event.getEntity().getLocation());
|
||||
if (player.getUniqueId().equals(claim.getOwnerUniqueId())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -366,6 +369,10 @@ public void onEntityDamage(EntityDamageByEntityEvent event) {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
// Ignore as this is handled above
|
||||
return;
|
||||
}
|
||||
GDTimings.ENTITY_DAMAGE_EVENT.startTiming();
|
||||
if (protectEntity(event, event.getCause(), event.getEntity())) {
|
||||
event.setCancelled(true);
|
||||
|
Loading…
Reference in New Issue
Block a user