mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-29 19:01:22 +01:00
Inventory.FastClick: Fix vl not adding, prepare for 1.5.
This commit is contained in:
parent
325d47fcbc
commit
1b811716e2
@ -1,6 +1,8 @@
|
||||
package fr.neatmonster.nocheatplus.checks.inventory;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
@ -79,10 +81,36 @@ public class FastClick extends Check {
|
||||
// return cancel;
|
||||
// }
|
||||
|
||||
public boolean check(final Player player, final long now, final InventoryData data, final InventoryConfig cc) {
|
||||
public boolean check(final Player player, final long now, final int slot, final ItemStack cursor, final ItemStack clicked, final InventoryData data, final InventoryConfig cc) {
|
||||
// Take time once.
|
||||
|
||||
final float amount;
|
||||
|
||||
if (cursor != null && cc.fastClickTweaks1_5){
|
||||
final Material mat = cursor.getType();
|
||||
final int size = cursor.getAmount();
|
||||
if (mat != data.fastClickLastMat || mat == Material.AIR || size != data.fastClickLastAmount || clicked == null){
|
||||
amount = 1f;
|
||||
}
|
||||
else{
|
||||
final Material cMat = clicked.getType();
|
||||
if (cMat == Material.AIR || cMat == mat){
|
||||
amount = Math.min(cc.fastClickNormalLimit , cc.fastClickShortTermLimit) / (float) size * 0.75f;
|
||||
}
|
||||
else{
|
||||
amount = 1f;
|
||||
}
|
||||
}
|
||||
data.fastClickLastMat = mat;
|
||||
data.fastClickLastAmount = size;
|
||||
}
|
||||
else{
|
||||
data.fastClickLastMat = null;
|
||||
data.fastClickLastAmount = 0;
|
||||
amount = 1f;
|
||||
}
|
||||
|
||||
data.fastClickFreq.add(now, 1f);
|
||||
data.fastClickFreq.add(now, amount);
|
||||
|
||||
float shortTerm = data.fastClickFreq.bucketScore(0);
|
||||
if (shortTerm > cc.fastClickShortTermLimit){
|
||||
@ -103,12 +131,13 @@ public class FastClick extends Check {
|
||||
boolean cancel = false;
|
||||
|
||||
if (violation > 0){
|
||||
data.fastClickVL += violation;
|
||||
final ViolationData vd = new ViolationData(this, player, data.fastClickVL + violation, violation, cc.fastClickActions);
|
||||
cancel = executeActions(vd);
|
||||
}
|
||||
|
||||
if (cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){
|
||||
player.sendMessage("FastClick: " + ((int) data.fastClickFreq.bucketScore(0)) + " / " + ((int) data.fastClickFreq.score(1f)));
|
||||
player.sendMessage("FastClick: " + data.fastClickFreq.bucketScore(0) + " / " + data.fastClickFreq.score(1f));
|
||||
}
|
||||
|
||||
return cancel;
|
||||
|
@ -80,6 +80,7 @@ public class InventoryConfig extends ACheckConfig {
|
||||
|
||||
public final boolean fastClickCheck;
|
||||
public final boolean fastClickSpareCreative;
|
||||
public final boolean fastClickTweaks1_5;
|
||||
public final float fastClickShortTermLimit;
|
||||
public final float fastClickNormalLimit;
|
||||
public final ActionList fastClickActions;
|
||||
@ -110,6 +111,7 @@ public class InventoryConfig extends ACheckConfig {
|
||||
|
||||
fastClickCheck = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_CHECK);
|
||||
fastClickSpareCreative = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_SPARECREATIVE);
|
||||
fastClickTweaks1_5 = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_TWEAKS1_5);
|
||||
fastClickShortTermLimit = (float) data.getDouble(ConfPaths.INVENTORY_FASTCLICK_LIMIT_SHORTTERM);
|
||||
fastClickNormalLimit = (float) data.getDouble(ConfPaths.INVENTORY_FASTCLICK_LIMIT_NORMAL);
|
||||
fastClickActions = data.getOptimizedActionList(
|
||||
|
@ -75,7 +75,7 @@ public class InventoryData extends ACheckData {
|
||||
public double instantEatVL;
|
||||
|
||||
// General.
|
||||
public long lastClickTime = 0;;
|
||||
public long lastClickTime = 0;
|
||||
|
||||
// Data of the drop check.
|
||||
public int dropCount;
|
||||
@ -84,6 +84,8 @@ public class InventoryData extends ACheckData {
|
||||
// Data of the fast click check.
|
||||
// public boolean fastClickLastCancelled;
|
||||
public final ActionFrequency fastClickFreq = new ActionFrequency(5, 200L);
|
||||
public Material fastClickLastMat = null;
|
||||
public int fastClickLastAmount = 0;
|
||||
|
||||
// Data of the instant bow check.
|
||||
public long instantBowInteract;
|
||||
@ -92,4 +94,5 @@ public class InventoryData extends ACheckData {
|
||||
// Data of the instant eat check.
|
||||
public Material instantEatFood;
|
||||
public long instantEatInteract;
|
||||
|
||||
}
|
||||
|
@ -161,18 +161,22 @@ public class InventoryListener extends CheckListener {
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) entity;
|
||||
if (event.getSlot() == InventoryView.OUTSIDE){
|
||||
final int slot = event.getSlot();
|
||||
if (slot == InventoryView.OUTSIDE){
|
||||
InventoryData.getData(player).lastClickTime = now;
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack cursor = event.getCursor();
|
||||
final ItemStack clicked = event.getCurrentItem();
|
||||
|
||||
// Illegal enchantment checks.
|
||||
try{
|
||||
if (Items.checkIllegalEnchantments(player, event.getCurrentItem())) event.setCancelled(true);
|
||||
if (Items.checkIllegalEnchantments(player, clicked)) event.setCancelled(true);
|
||||
}
|
||||
catch(final ArrayIndexOutOfBoundsException e){} // Hotfix (CB)
|
||||
try{
|
||||
if (Items.checkIllegalEnchantments(player, event.getCursor())) event.setCancelled(true);
|
||||
if (Items.checkIllegalEnchantments(player, cursor)) event.setCancelled(true);
|
||||
}
|
||||
catch(final ArrayIndexOutOfBoundsException e){} // Hotfix (CB)
|
||||
|
||||
@ -182,7 +186,7 @@ public class InventoryListener extends CheckListener {
|
||||
if (fastClick.isEnabled(player)){
|
||||
final InventoryConfig cc = InventoryConfig.getConfig(player);
|
||||
if (player.getGameMode() != GameMode.CREATIVE || !cc.fastClickSpareCreative){
|
||||
if (fastClick.check(player, now, data, cc)){
|
||||
if (fastClick.check(player, now, slot, cursor, clicked, data, cc)){
|
||||
// The check requested the event to be cancelled.
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -468,6 +468,7 @@ public abstract class ConfPaths {
|
||||
private static final String INVENTORY_FASTCLICK = INVENTORY + "fastclick.";
|
||||
public static final String INVENTORY_FASTCLICK_CHECK = INVENTORY_FASTCLICK + "active";
|
||||
public static final String INVENTORY_FASTCLICK_SPARECREATIVE = INVENTORY_FASTCLICK + "sparecreative";
|
||||
public static final String INVENTORY_FASTCLICK_TWEAKS1_5 = INVENTORY_FASTCLICK + "tweaks1_5";
|
||||
private static final String INVENTORY_FASTCLICK_LIMIT = INVENTORY_FASTCLICK + "limit.";
|
||||
public static final String INVENTORY_FASTCLICK_LIMIT_SHORTTERM = INVENTORY_FASTCLICK_LIMIT + "shortterm";
|
||||
public static final String INVENTORY_FASTCLICK_LIMIT_NORMAL = INVENTORY_FASTCLICK_LIMIT + "normal";
|
||||
|
@ -360,6 +360,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
|
||||
set(ConfPaths.INVENTORY_FASTCLICK_CHECK, true);
|
||||
set(ConfPaths.INVENTORY_FASTCLICK_SPARECREATIVE, true);
|
||||
set(ConfPaths.INVENTORY_FASTCLICK_TWEAKS1_5, true);
|
||||
set(ConfPaths.INVENTORY_FASTCLICK_LIMIT_SHORTTERM, 4);
|
||||
set(ConfPaths.INVENTORY_FASTCLICK_LIMIT_NORMAL, 15);
|
||||
set(ConfPaths.INVENTORY_FASTCLICK_ACTIONS, "cancel vl>50 log:fastclick:3:5:cif cancel");
|
||||
|
Loading…
Reference in New Issue
Block a user