mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-02 13:57:49 +01:00
Ignore Blockbreak events if the block clearly wasn't broken by a
player manually
This commit is contained in:
parent
5818a32fc0
commit
5d56a8c66c
@ -30,6 +30,7 @@ public class BlockBreakData implements DataItem {
|
||||
|
||||
public double reachDistance;
|
||||
public boolean armswung = true;
|
||||
public final SimpleLocation lastDamagedBlock = new SimpleLocation();
|
||||
|
||||
@Override
|
||||
public void clearCriticalData() {
|
||||
|
@ -57,6 +57,14 @@ public class BlockBreakEventManager extends EventManagerImpl {
|
||||
|
||||
data.brokenBlockLocation.set(event.getBlock());
|
||||
|
||||
// Only if the block got damaged before, do the check(s)
|
||||
if(!data.brokenBlockLocation.equals(data.lastDamagedBlock)) {
|
||||
// Something caused a blockbreak event that's not from the player
|
||||
// Don't check it at all
|
||||
data.lastDamagedBlock.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
for(BlockBreakCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
@ -71,13 +79,20 @@ public class BlockBreakEventManager extends EventManagerImpl {
|
||||
@Override
|
||||
protected void handleBlockDamageEvent(final BlockDamageEvent event, final Priority priority) {
|
||||
|
||||
// Only interested in insta-break events here
|
||||
if(!event.getInstaBreak())
|
||||
return;
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
BlockBreakData data = BlockBreakCheck.getData(player.getDataStore());
|
||||
|
||||
// Only interested in insta-break events here
|
||||
if(event.getInstaBreak()) {
|
||||
// Remember this location. We ignore block breaks in the block-break
|
||||
// direction check that are insta-breaks
|
||||
data.instaBrokenBlockLocation.set(event.getBlock());
|
||||
}
|
||||
|
||||
// Remember this location. Only blockbreakevents for this specific block
|
||||
// will be handled at all
|
||||
data.lastDamagedBlock.set(event.getBlock());
|
||||
|
||||
// Remember this location. We ignore block breaks in the block-break
|
||||
// direction check that are insta-breaks
|
||||
BlockBreakCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore()).instaBrokenBlockLocation.set(event.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,15 @@ public final class SimpleLocation {
|
||||
return block.getX() == x && block.getY() == y && block.getZ() == z;
|
||||
}
|
||||
|
||||
public final boolean equals(SimpleLocation simpleLocation) {
|
||||
if(!isSet() && !simpleLocation.isSet())
|
||||
return true;
|
||||
else if(!isSet() || !simpleLocation.isSet())
|
||||
return false;
|
||||
|
||||
return simpleLocation.x == x && simpleLocation.y == y && simpleLocation.z == z;
|
||||
}
|
||||
|
||||
public final void set(Block block) {
|
||||
x = block.getX();
|
||||
y = block.getY();
|
||||
|
Loading…
Reference in New Issue
Block a user