mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Add in inventory checks. Fixes Issue 55.
This commit is contained in:
1 parent
80f13d9adc
commit
4186151609
8 files changed
+135
-4
No files matched your search
@@ -59,7 +59,8 @@ public class Anticheat extends JavaPlugin
|
||||
eventList.add(new PlayerListener());
|
||||
eventList.add(new BlockListener());
|
||||
eventList.add(new EntityListener());
|
||||
eventList.add(new VehicleListener());
|
||||
eventList.add(new VehicleListener());
|
||||
eventList.add(new InventoryListener());
|
||||
// Order is important in some cases, don't screw with these unless needed, especially config
|
||||
setupConfig();
|
||||
// Xray must come before events
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.event;
|
||||
|
||||
import net.h31ix.anticheat.Anticheat;
|
||||
import net.h31ix.anticheat.manage.Backend;
|
||||
import net.h31ix.anticheat.manage.CheckManager;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.util.Configuration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class InventoryListener extends EventListener{
|
||||
|
||||
private final Backend backend = getBackend();
|
||||
private final CheckManager checkManager = getCheckManager();
|
||||
private final Configuration config = Anticheat.getManager().getConfiguration();
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getWhoClicked() instanceof Player)
|
||||
{
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if(checkManager.willCheck(player, CheckType.FAST_INVENTORY))
|
||||
{
|
||||
if(backend.checkInventoryClicks(player))
|
||||
{
|
||||
event.setCancelled(!config.silentMode());
|
||||
log("tried to use inventories too fast", player, CheckType.FAST_INVENTORY);
|
||||
}
|
||||
else
|
||||
{
|
||||
decrease(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,9 @@ public class Backend
|
||||
private Map<String, Long> movingExempt = new HashMap<String, Long>();
|
||||
private Map<String, Long> blockTime = new HashMap<String, Long>();
|
||||
private Map<String, Integer> blocksDropped = new HashMap<String, Integer>();
|
||||
private Map<String, Long> lastInventoryTime = new HashMap<String, Long>();
|
||||
private Map<String, Long> inventoryTime = new HashMap<String, Long>();
|
||||
private Map<String, Integer> inventoryChanges = new HashMap<String, Integer>();
|
||||
|
||||
private Magic magic;
|
||||
private AnticheatManager micromanage = null;
|
||||
@@ -883,6 +886,53 @@ public class Backend
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkInventoryClicks(Player player)
|
||||
{
|
||||
String name = player.getName();
|
||||
long time = System.currentTimeMillis();
|
||||
if (!inventoryTime.containsKey(name) || !inventoryChanges.containsKey(name))
|
||||
{
|
||||
inventoryTime.put(name, 0l);
|
||||
if(!inventoryChanges.containsKey(name))
|
||||
{
|
||||
inventoryChanges.put(name, 0);
|
||||
}
|
||||
}
|
||||
else if (inventoryChanges.containsKey(name) && inventoryChanges.get(name) > magic.INVENTORY_MAXVIOLATIONS)
|
||||
{
|
||||
long diff = System.currentTimeMillis() - lastInventoryTime.get(name);
|
||||
System.out.println("inventoryTime = " + inventoryTime.get(name));
|
||||
System.out.println("diff = " + diff);
|
||||
if (inventoryTime.get(name) > 0 && diff < magic.INVENTORY_MAXVIOLATIONTIME)
|
||||
{
|
||||
inventoryTime.put(name, diff);
|
||||
player.sendMessage(ChatColor.RED + "[AntiCheat] Inventory hack detected. Please wait 10 seconds before using inventories.");
|
||||
return true;
|
||||
} else if (inventoryTime.get(name) > 0 && diff > magic.INVENTORY_MAXVIOLATIONTIME)
|
||||
{
|
||||
inventoryChanges.put(name, 0);
|
||||
}
|
||||
}
|
||||
else if (inventoryTime.containsKey(name))
|
||||
{
|
||||
long last = lastInventoryTime.get(name);
|
||||
long thisTime = time - last;
|
||||
if (thisTime < magic.INVENTORY_TIMEMAX)
|
||||
{
|
||||
inventoryChanges.put(name, inventoryChanges.get(name) + 1);
|
||||
if(inventoryChanges.get(name) > magic.INVENTORY_MAXVIOLATIONS)
|
||||
{
|
||||
inventoryTime.put(name, thisTime);
|
||||
player.sendMessage(ChatColor.RED + "[AntiCheat] Inventory hack detected. Please wait 10 seconds before using inventories.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
inventoryTime.put(name, thisTime);
|
||||
}
|
||||
lastInventoryTime.put(name, time);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clearChatLevel(Player player)
|
||||
{
|
||||
chatLevel.remove(player.getName());
|
||||
|
||||
@@ -52,7 +52,8 @@ public enum CheckType
|
||||
XRAY(Permission.CHECK_XRAY),
|
||||
LONG_REACH(Permission.CHECK_LONGREACH),
|
||||
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE),
|
||||
ITEM_SPAM(Permission.CHECK_ITEMSPAM);
|
||||
ITEM_SPAM(Permission.CHECK_ITEMSPAM),
|
||||
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY);
|
||||
|
||||
private final Permission permission;
|
||||
private final Map<String, Integer> level = new HashMap<String, Integer>();
|
||||
|
||||
@@ -304,6 +304,18 @@ public class Magic
|
||||
* Maximum times a player can fail the speed check before action is taken; Type=integer, +Leniency=Increase.
|
||||
*/
|
||||
public final int SPEED_MAX;
|
||||
/**
|
||||
* Number of times a player can fail the inventory check before action is taken; Type=integer, +Leniency=Increase.
|
||||
*/
|
||||
public final int INVENTORY_MAXVIOLATIONS;
|
||||
/**
|
||||
* Time player is forced to wait after inventory detection; Type=integer; +Leniency=Decrease.
|
||||
*/
|
||||
public final int INVENTORY_MAXVIOLATIONTIME;
|
||||
/**
|
||||
* Time between inventory changes that triggers inventory violations; Type=integer; +Leniency=Decrease.
|
||||
*/
|
||||
public final int INVENTORY_TIMEMAX;
|
||||
|
||||
private FileConfiguration defaults;
|
||||
private FileConfiguration magic;
|
||||
@@ -382,6 +394,9 @@ public class Magic
|
||||
XZ_SPEED_MAX_WATER = getDouble("XZ_SPEED_MAX_WATER");
|
||||
XZ_SPEED_MAX_WATER_SPRINT = getDouble("XZ_SPEED_MAX_WATER_SPRINT");
|
||||
SPEED_MAX = getInt("SPEED_MAX");
|
||||
INVENTORY_MAXVIOLATIONS = getInt("INVENTORY_MAXVIOLATIONS");
|
||||
INVENTORY_MAXVIOLATIONTIME = getInt("INVENTORY_MAXVIOLATIONTIME");
|
||||
INVENTORY_TIMEMAX = getInt("INVENTORY_TIMEMAX");
|
||||
}
|
||||
|
||||
private int getInt(String path)
|
||||
|
||||
@@ -47,6 +47,7 @@ public enum Permission
|
||||
CHECK_FASTPROJECTILE,
|
||||
CHECK_ITEMSPAM,
|
||||
CHECK_VISUAL,
|
||||
CHECK_FASTINVENTORY,
|
||||
|
||||
/* System Nodes */
|
||||
SYSTEM_LOG,
|
||||
|
||||
Reference in new issue
Block a user