Ra-add the instant-break compatibility code.

For whatever reason it was commented out, it is now put back, assuming
that the reason was "it did not help with mcMMO", because mcMMO used to
fire extra BlockBreakEventS.

Now we use a tri-state and set it to MAYBE if instantBreak is set
already on lowest priority, to have a rough indicator if a plugin set
it, or if the server might have done it. Later we might let FastBreak
assume some maximal duration for either case, instead of ignoring these.
This commit is contained in:
asofold 2014-06-04 22:29:51 +02:00
parent d6e66dc22d
commit a75e32b2d3
3 changed files with 39 additions and 20 deletions

View File

@ -18,6 +18,7 @@ import org.bukkit.inventory.ItemStack;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.inventory.Items;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
@ -48,7 +49,7 @@ public class BlockBreakListener extends CheckListener {
/** The wrong block check. */
private final WrongBlock wrongBlock = addCheck(new WrongBlock());
private boolean isInstaBreak = false;
private AlmostBoolean isInstaBreak = AlmostBoolean.NO;
public BlockBreakListener(){
super(CheckType.BLOCKBREAK);
@ -73,7 +74,7 @@ public class BlockBreakListener extends CheckListener {
// Cancelled events only leads to resetting insta break.
if (event.isCancelled()) {
isInstaBreak = false;
isInstaBreak = AlmostBoolean.NO;
return;
}
@ -142,7 +143,7 @@ public class BlockBreakListener extends CheckListener {
// data.clickedX = Integer.MAX_VALUE;
}
if (isInstaBreak) {
if (isInstaBreak.decideOptimistically()) {
data.wasInstaBreak = now;
}
else {
@ -152,7 +153,7 @@ public class BlockBreakListener extends CheckListener {
// Adjust data.
data.fastBreakBreakTime = now;
// data.fastBreakfirstDamage = now;
isInstaBreak = false;
isInstaBreak = AlmostBoolean.NO;
}
/**
@ -185,18 +186,32 @@ public class BlockBreakListener extends CheckListener {
// Return if it is not left clicking a block.
// (Allows right click to be ignored.)
isInstaBreak = false;
if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
isInstaBreak = AlmostBoolean.NO;
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
return;
}
checkBlockDamage(event.getPlayer(), event.getClickedBlock(), event);
}
@EventHandler(
ignoreCancelled = false, priority = EventPriority.MONITOR)
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public void onBlockDamageLowest(final BlockDamageEvent event) {
if (event.getInstaBreak()) {
// Indicate that this might have been set by CB/MC.
isInstaBreak = AlmostBoolean.MAYBE;
}
}
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onBlockDamage(final BlockDamageEvent event) {
// System.out.println("Damage("+event.isCancelled()+"): " + event.getBlock());
if (!event.isCancelled() && event.getInstaBreak()) isInstaBreak = true;
else isInstaBreak = false;
if (!event.isCancelled() && event.getInstaBreak()) {
// Keep MAYBE.
if (isInstaBreak != AlmostBoolean.MAYBE) {
isInstaBreak = AlmostBoolean.YES;
}
}
else {
isInstaBreak = AlmostBoolean.NO;
}
checkBlockDamage(event.getPlayer(), event.getBlock(), event);
}

View File

@ -10,6 +10,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.ViolationData;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.PotionUtil;
@ -40,7 +41,7 @@ public class FastBreak extends Check {
* @param elaspedTime
* @return true, if successful
*/
public boolean check(final Player player, final Block block, final boolean isInstaBreak, final BlockBreakConfig cc, final BlockBreakData data) {
public boolean check(final Player player, final Block block, final AlmostBoolean isInstaBreak, final BlockBreakConfig cc, final BlockBreakData data) {
final long now = System.currentTimeMillis();
boolean cancel = false;
@ -65,11 +66,12 @@ public class FastBreak extends Check {
}
// Check if the time used time is lower than expected.
// if (isInstaBreak){
// // Ignore those for now.
// }
// else
if (elapsedTime < 0){
if (isInstaBreak.decideOptimistically()){
// Ignore those for now.
// TODO: Find out why this was commented out long ago a) did not fix mcMMO b) exploits.
// TODO: Maybe adjust time to min(time, SOMETHING) for MAYBE/YES.
}
else if (elapsedTime < 0){
// Ignore it. TODO: ?
}
else if (elapsedTime + cc.fastBreakDelay < breakingTime){
@ -114,7 +116,7 @@ public class FastBreak extends Check {
final ItemStack stack = player.getItemInHand();
final boolean isValidTool = BlockProperties.isValidTool(blockId, stack);
final double haste = PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.FAST_DIGGING);
String msg = (isInstaBreak ? "[Insta]" : "[Normal]") + "[" + blockId + "] "+ elapsedTime + "u / " + breakingTime +"r (" + (isValidTool?"tool":"no-tool") + ")" + (haste == Double.NEGATIVE_INFINITY ? "" : " haste=" + ((int) haste + 1));
String msg = (isInstaBreak.decideOptimistically() ? ("[Insta=" + isInstaBreak + "]") : "[Normal]") + "[" + blockId + "] "+ elapsedTime + "u / " + breakingTime +"r (" + (isValidTool?"tool":"no-tool") + ")" + (haste == Double.NEGATIVE_INFINITY ? "" : " haste=" + ((int) haste + 1));
player.sendMessage(msg);
// net.minecraft.server.Item mcItem = net.minecraft.server.Item.byId[stack.getTypeId()];
// if (mcItem != null){

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.TrigUtil;
@ -26,7 +27,7 @@ public class WrongBlock extends Check {
* @param isInstaBreak
* @return
*/
public boolean check(final Player player, final Block block, final BlockBreakConfig cc, final BlockBreakData data, final boolean isInstaBreak) {
public boolean check(final Player player, final Block block, final BlockBreakConfig cc, final BlockBreakData data, final AlmostBoolean isInstaBreak) {
boolean cancel = false;
@ -34,6 +35,7 @@ public class WrongBlock extends Check {
final int dist = Math.min(4, data.clickedX == Integer.MAX_VALUE ? 100 : TrigUtil.manhattan(data.clickedX, data.clickedY, data.clickedZ, block));
final boolean wrongBlock;
final long now = System.currentTimeMillis();
// TODO: Remove isInstaBreak argument or use it.
if (dist == 0) {
if (wrongTime) {
data.fastBreakBreakTime = now;