mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 22:14:49 +00:00
Restore inventories looted by fast inventory and flush magic values when reloaded
This commit is contained in:
1 parent
873a1b9d60
commit
96f3906eff
6 files changed
+61
-8
No files matched your search
@@ -27,6 +27,9 @@ import net.h31ix.anticheat.util.Configuration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InventoryListener extends EventListener {
|
||||
|
||||
@@ -42,9 +45,9 @@ public class InventoryListener extends EventListener {
|
||||
CheckResult result = backend.checkInventoryClicks(player);
|
||||
if (result.failed()) {
|
||||
if (!config.silentMode()) {
|
||||
event.setCancelled(!config.silentMode());
|
||||
player.damage(9999);
|
||||
// TODO: Return items
|
||||
getUserManager().getUser(player.getName()).restore(event.getInventory());
|
||||
player.getInventory().clear();
|
||||
player.damage(99999);
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.FAST_INVENTORY);
|
||||
} else {
|
||||
@@ -55,4 +58,14 @@ public class InventoryListener extends EventListener {
|
||||
|
||||
Anticheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
getUserManager().getUser(event.getPlayer().getName()).setSnapshot(event.getInventory().getContents());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
getUserManager().getUser(event.getPlayer().getName()).removeSnapshot();
|
||||
}
|
||||
}
|
||||
@@ -100,11 +100,15 @@ public class Backend {
|
||||
private static final CheckResult PASS = new CheckResult(Result.PASSED);
|
||||
|
||||
public Backend(AnticheatManager instance) {
|
||||
magic = new Magic(instance.getConfiguration().getMagic(), instance.getConfiguration(), CommentedConfiguration.loadConfiguration(instance.getPlugin().getResource("magic.yml")));
|
||||
magic = instance.getConfiguration().getMagicInstance();
|
||||
micromanage = instance;
|
||||
lang = micromanage.getConfiguration().getLang();
|
||||
transparent.add((byte) -1);
|
||||
}
|
||||
|
||||
public void updateMagic(Magic magic) {
|
||||
this.magic = magic;
|
||||
}
|
||||
|
||||
public void garbageClean(Player player) {
|
||||
String pN = player.getName();
|
||||
@@ -795,7 +799,7 @@ public class Backend {
|
||||
|
||||
public CheckResult checkAutoTool(Player player) {
|
||||
if (itemInHand.containsKey(player.getName()) && itemInHand.get(player.getName()) != player.getItemInHand().getType()) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" switched tools too fast (had "+itemInHand.get(player.getName())+", has "+player.getItemInHand().getType());
|
||||
return new CheckResult(Result.FAILED, player.getName()+" switched tools too fast (had "+itemInHand.get(player.getName())+", has "+player.getItemInHand().getType()+")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@ import net.h31ix.anticheat.util.Utilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class User {
|
||||
private final String name;
|
||||
@@ -32,6 +37,7 @@ public class User {
|
||||
private int med;
|
||||
private Location goodLocation;
|
||||
private boolean silentMode;
|
||||
private List<ItemStack> inventorySnapshot = null;
|
||||
|
||||
public User(String name) {
|
||||
this.name = name;
|
||||
@@ -114,5 +120,26 @@ public class User {
|
||||
|
||||
goodLocation = e;
|
||||
}
|
||||
|
||||
|
||||
public void setSnapshot(ItemStack[] is) {
|
||||
inventorySnapshot = new ArrayList<ItemStack>();
|
||||
for(int i=0;i<is.length;i++) {
|
||||
if(is[i] != null) {
|
||||
inventorySnapshot.add(is[i].clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSnapshot() {
|
||||
inventorySnapshot = null;
|
||||
}
|
||||
|
||||
public void restore(Inventory inventory) {
|
||||
inventory.clear();
|
||||
for(ItemStack is : inventorySnapshot) {
|
||||
if(is != null) {
|
||||
inventory.addItem(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,7 @@ public class Configuration {
|
||||
private String chatActionBan;
|
||||
private static Language language;
|
||||
private List<String> exemptWorlds = new ArrayList<String>();
|
||||
private Magic magicInstance;
|
||||
|
||||
public Configuration(AnticheatManager instance) {
|
||||
micromanage = instance;
|
||||
@@ -219,6 +220,10 @@ public class Configuration {
|
||||
exemptWorlds = config.getStringList("Disable in");
|
||||
// End pulling values from config
|
||||
save();
|
||||
magicInstance = new Magic(getMagic(), this, CommentedConfiguration.loadConfiguration(micromanage.getPlugin().getResource("magic.yml")));
|
||||
if(micromanage.getBackend() != null) { // If this is first run, backend may not be setup yet
|
||||
micromanage.getBackend().updateMagic(magicInstance);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getBoolean(String entry, boolean d) {
|
||||
@@ -293,4 +298,8 @@ public class Configuration {
|
||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Magic getMagicInstance() {
|
||||
return magicInstance;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user