Stop boats from breaking item frames in claims (#1029)

This commit is contained in:
DrBot7 2020-09-26 14:54:19 -05:00 committed by GitHub
parent 9622eea434
commit 6e055c90c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,6 +57,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.InventoryHolder;
@ -1015,4 +1016,21 @@ public class BlockEventHandler implements Listener
}
}
}
@EventHandler(ignoreCancelled = true)
public void onItemFrameBrokenByBoat(final HangingBreakEvent event)
{
// Checks if the event is caused by physics - 90% of cases caused by a boat (other 10% would be block,
// however since it's in a claim, unless you use a TNT block we don't need to worry about it).
if (event.getCause() != HangingBreakEvent.RemoveCause.PHYSICS)
{
return;
}
// Cancels the event if in a claim, as we can not efficiently retrieve the person/entity who broke the Item Frame/Hangable Item.
if (this.dataStore.getClaimAt(event.getEntity().getLocation(), false, null) != null)
{
event.setCancelled(true);
}
}
}