mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-04 23:07:44 +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 double reachDistance;
|
||||||
public boolean armswung = true;
|
public boolean armswung = true;
|
||||||
|
public final SimpleLocation lastDamagedBlock = new SimpleLocation();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearCriticalData() {
|
public void clearCriticalData() {
|
||||||
|
@ -57,6 +57,14 @@ public class BlockBreakEventManager extends EventManagerImpl {
|
|||||||
|
|
||||||
data.brokenBlockLocation.set(event.getBlock());
|
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) {
|
for(BlockBreakCheck check : checks) {
|
||||||
// If it should be executed, do it
|
// If it should be executed, do it
|
||||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||||
@ -71,13 +79,20 @@ public class BlockBreakEventManager extends EventManagerImpl {
|
|||||||
@Override
|
@Override
|
||||||
protected void handleBlockDamageEvent(final BlockDamageEvent event, final Priority priority) {
|
protected void handleBlockDamageEvent(final BlockDamageEvent event, final Priority priority) {
|
||||||
|
|
||||||
// Only interested in insta-break events here
|
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||||
if(!event.getInstaBreak())
|
BlockBreakData data = BlockBreakCheck.getData(player.getDataStore());
|
||||||
return;
|
|
||||||
|
// 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
|
@Override
|
||||||
|
@ -23,6 +23,15 @@ public final class SimpleLocation {
|
|||||||
return block.getX() == x && block.getY() == y && block.getZ() == z;
|
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) {
|
public final void set(Block block) {
|
||||||
x = block.getX();
|
x = block.getX();
|
||||||
y = block.getY();
|
y = block.getY();
|
||||||
|
Loading…
Reference in New Issue
Block a user