mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-03 06:28:52 +00:00
Level data now persists across restarts/reloads
This commit is contained in:
1 parent
2ce2235280
commit
ce19d564e2
6 files changed
+118
-17
No files matched your search
@@ -27,7 +27,9 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import net.h31ix.anticheat.event.*;
|
import net.h31ix.anticheat.event.*;
|
||||||
@@ -58,6 +60,14 @@ public class Anticheat extends JavaPlugin
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
|
Map<String,Integer> map = AnticheatManager.PLAYER_MANAGER.getLevels();
|
||||||
|
Iterator<String> set = map.keySet().iterator();
|
||||||
|
while(set.hasNext())
|
||||||
|
{
|
||||||
|
String player = set.next();
|
||||||
|
config.saveLevel(player, map.get(player));
|
||||||
|
}
|
||||||
|
config.saveLevels();
|
||||||
getServer().getScheduler().cancelAllTasks();
|
getServer().getScheduler().cancelAllTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,6 +174,11 @@ public class Anticheat extends JavaPlugin
|
|||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
for(Player player : getServer().getOnlinePlayers())
|
||||||
|
{
|
||||||
|
String name = player.getName();
|
||||||
|
AnticheatManager.PLAYER_MANAGER.setLevel(player, config.getLevel(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveFile(String file, String url)
|
private void saveFile(String file, String url)
|
||||||
|
|||||||
@@ -31,8 +31,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
private File configFile = new File(Anticheat.getPlugin().getDataFolder()+"/config.yml");
|
private File configFile = new File(Anticheat.getPlugin().getDataFolder()+"/config.yml");
|
||||||
|
private File levelFile = new File(Anticheat.getPlugin().getDataFolder()+"/data/level.yml");
|
||||||
private File bukkitFile = new File("bukkit.yml");
|
private File bukkitFile = new File("bukkit.yml");
|
||||||
private FileConfiguration config;
|
private FileConfiguration config;
|
||||||
|
private FileConfiguration level;
|
||||||
private FileConfiguration bukkit;
|
private FileConfiguration bukkit;
|
||||||
private boolean logConsole;
|
private boolean logConsole;
|
||||||
private boolean logXRay;
|
private boolean logXRay;
|
||||||
@@ -93,6 +95,7 @@ public class Configuration {
|
|||||||
{
|
{
|
||||||
Anticheat.checkConfig();
|
Anticheat.checkConfig();
|
||||||
config = YamlConfiguration.loadConfiguration(configFile);
|
config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
level = YamlConfiguration.loadConfiguration(levelFile);
|
||||||
bukkit = YamlConfiguration.loadConfiguration(bukkitFile);
|
bukkit = YamlConfiguration.loadConfiguration(bukkitFile);
|
||||||
updateFolder = bukkit.getString("settings.update-folder");
|
updateFolder = bukkit.getString("settings.update-folder");
|
||||||
if(config.getString("Logging.Log to console") != null)
|
if(config.getString("Logging.Log to console") != null)
|
||||||
@@ -169,8 +172,40 @@ public class Configuration {
|
|||||||
return configFile;
|
return configFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getLevelFile()
|
||||||
|
{
|
||||||
|
return levelFile;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean checkInWorld(World world)
|
public boolean checkInWorld(World world)
|
||||||
{
|
{
|
||||||
return worlds.contains(world.getName());
|
return worlds.contains(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLevel(String player)
|
||||||
|
{
|
||||||
|
int x = 0;
|
||||||
|
if(level.getString(player) != null)
|
||||||
|
{
|
||||||
|
x = level.getInt(player);
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveLevel(String player, int x)
|
||||||
|
{
|
||||||
|
level.set(player,x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveLevels()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
level.save(levelFile);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ public class EventListener implements Listener
|
|||||||
private static final Anticheat PLUGIN = Anticheat.getPlugin();
|
private static final Anticheat PLUGIN = Anticheat.getPlugin();
|
||||||
private static final PlayerManager PLAYER_MANAGER = AnticheatManager.PLAYER_MANAGER;
|
private static final PlayerManager PLAYER_MANAGER = AnticheatManager.PLAYER_MANAGER;
|
||||||
|
|
||||||
public static void log(String message,Player player, CheckType type)
|
public void log(String message,Player player, CheckType type)
|
||||||
{
|
{
|
||||||
if(AnticheatManager.CONFIGURATION.logConsole())
|
if(AnticheatManager.CONFIGURATION.logConsole())
|
||||||
{
|
{
|
||||||
@@ -46,17 +46,17 @@ public class EventListener implements Listener
|
|||||||
logCheat(type);
|
logCheat(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void logCheat(CheckType type)
|
private void logCheat(CheckType type)
|
||||||
{
|
{
|
||||||
usageList.put(type, getCheats(type)+1);
|
usageList.put(type, getCheats(type)+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetCheck(CheckType type)
|
public void resetCheck(CheckType type)
|
||||||
{
|
{
|
||||||
usageList.put(type, 0);
|
usageList.put(type, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getCheats(CheckType type)
|
public int getCheats(CheckType type)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
if(usageList.get(type) != null)
|
if(usageList.get(type) != null)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package net.h31ix.anticheat.event;
|
package net.h31ix.anticheat.event;
|
||||||
|
|
||||||
import net.h31ix.anticheat.manage.*;
|
import net.h31ix.anticheat.manage.*;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -60,6 +61,11 @@ public class PlayerListener extends EventListener
|
|||||||
if(checkManager.willCheck(player, CheckType.SPAM))
|
if(checkManager.willCheck(player, CheckType.SPAM))
|
||||||
{
|
{
|
||||||
backend.logChat(player);
|
backend.logChat(player);
|
||||||
|
if(backend.checkSpam(player, event.getMessage()))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.sendMessage(ChatColor.RED+"Please do not spam.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +165,10 @@ public class PlayerListener extends EventListener
|
|||||||
player.sendMessage("§f §f §4 §0 §9 §6");
|
player.sendMessage("§f §f §4 §0 §9 §6");
|
||||||
}
|
}
|
||||||
backend.logJoin(event.getPlayer());
|
backend.logJoin(event.getPlayer());
|
||||||
|
if(!AnticheatManager.PLAYER_MANAGER.hasLevel(player))
|
||||||
|
{
|
||||||
|
AnticheatManager.PLAYER_MANAGER.setLevel(player, AnticheatManager.CONFIGURATION.getLevel(player.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ public class Backend
|
|||||||
private List<String> healed = new ArrayList<String>();
|
private List<String> healed = new ArrayList<String>();
|
||||||
private List<String> sprinted = new ArrayList<String>();
|
private List<String> sprinted = new ArrayList<String>();
|
||||||
private List<String> instantBreakExempt = new ArrayList<String>();
|
private List<String> instantBreakExempt = new ArrayList<String>();
|
||||||
|
private Map<String,String> oldMessage = new HashMap<String,String>();
|
||||||
|
private Map<String,String> lastMessage = new HashMap<String,String>();
|
||||||
private Map<String,Integer> flightViolation = new HashMap<String,Integer>();
|
private Map<String,Integer> flightViolation = new HashMap<String,Integer>();
|
||||||
private Map<String,Integer> chatLevel = new HashMap<String,Integer>();
|
private Map<String,Integer> chatLevel = new HashMap<String,Integer>();
|
||||||
private Map<String,Integer> chatKicks = new HashMap<String,Integer>();
|
private Map<String,Integer> chatKicks = new HashMap<String,Integer>();
|
||||||
@@ -156,12 +158,10 @@ public class Backend
|
|||||||
{
|
{
|
||||||
if(!player.isSprinting())
|
if(!player.isSprinting())
|
||||||
{
|
{
|
||||||
System.out.println(x+" "+z);
|
|
||||||
return x > XZ_SPEED_MAX || z > XZ_SPEED_MAX;
|
return x > XZ_SPEED_MAX || z > XZ_SPEED_MAX;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.out.println(x+" "+z);
|
|
||||||
return x > XZ_SPEED_MAX_SPRINT || z > XZ_SPEED_MAX_SPRINT;
|
return x > XZ_SPEED_MAX_SPRINT || z > XZ_SPEED_MAX_SPRINT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,6 +307,29 @@ public class Backend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean checkSpam(Player player, String msg)
|
||||||
|
{
|
||||||
|
String name = player.getName();
|
||||||
|
if(lastMessage.get(name) == null)
|
||||||
|
{
|
||||||
|
lastMessage.put(name, msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(oldMessage.get(name) != null && lastMessage.get(name).equals(msg) && oldMessage.get(name).equals(msg))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
oldMessage.put(name, lastMessage.get(name));
|
||||||
|
lastMessage.put(name, msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void clearChatLevel(Player player)
|
public void clearChatLevel(Player player)
|
||||||
{
|
{
|
||||||
chatLevel.remove(player.getName());
|
chatLevel.remove(player.getName());
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class PlayerManager {
|
public class PlayerManager {
|
||||||
private static Map<Player,Integer> level = new HashMap<Player,Integer>();
|
private static Map<String,Integer> level = new HashMap<String,Integer>();
|
||||||
private static Configuration config = AnticheatManager.CONFIGURATION;
|
private static Configuration config = AnticheatManager.CONFIGURATION;
|
||||||
private static final int MED_THRESHOLD = 20;
|
private static final int MED_THRESHOLD = 20;
|
||||||
private static final int HIGH_THRESHOLD = 50;
|
private static final int HIGH_THRESHOLD = 50;
|
||||||
@@ -50,14 +50,15 @@ public class PlayerManager {
|
|||||||
|
|
||||||
public void increaseLevel(Player player)
|
public void increaseLevel(Player player)
|
||||||
{
|
{
|
||||||
if(level.get(player) == null || level.get(player) == 0)
|
final String name = player.getName();
|
||||||
|
if(level.get(name) == null || level.get(name) == 0)
|
||||||
{
|
{
|
||||||
level.put(player,1);
|
level.put(name,1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
final int playerLevel = level.get(player);
|
final int playerLevel = level.get(name);
|
||||||
level.put(player, playerLevel+1);
|
level.put(name, playerLevel+1);
|
||||||
if(playerLevel <= MED_THRESHOLD && playerLevel+1 > MED_THRESHOLD && playerLevel+1 <= HIGH_THRESHOLD)
|
if(playerLevel <= MED_THRESHOLD && playerLevel+1 > MED_THRESHOLD && playerLevel+1 <= HIGH_THRESHOLD)
|
||||||
{
|
{
|
||||||
reactMedium(player);
|
reactMedium(player);
|
||||||
@@ -71,18 +72,20 @@ public class PlayerManager {
|
|||||||
|
|
||||||
public void decreaseLevel(Player player)
|
public void decreaseLevel(Player player)
|
||||||
{
|
{
|
||||||
if(level.get(player) != null && level.get(player) != 0)
|
final String name = player.getName();
|
||||||
|
if(level.get(name) != null && level.get(name) != 0)
|
||||||
{
|
{
|
||||||
int playerLevel = level.get(player)-1;
|
int playerLevel = level.get(name)-1;
|
||||||
level.put(player, playerLevel);
|
level.put(name, playerLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLevel(Player player)
|
public int getLevel(Player player)
|
||||||
{
|
{
|
||||||
if(level.get(player) != null)
|
final String name = player.getName();
|
||||||
|
if(level.get(name) != null)
|
||||||
{
|
{
|
||||||
return level.get(player);
|
return level.get(name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -90,9 +93,24 @@ public class PlayerManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLevel(Player player, int x)
|
||||||
|
{
|
||||||
|
level.put(player.getName(), x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasLevel(Player player)
|
||||||
|
{
|
||||||
|
return level.containsKey(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
public void reset(Player player)
|
public void reset(Player player)
|
||||||
{
|
{
|
||||||
level.put(player,0);
|
level.put(player.getName(),0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String,Integer> getLevels()
|
||||||
|
{
|
||||||
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void execute(String level, Player player)
|
private static void execute(String level, Player player)
|
||||||
|
|||||||
Reference in new issue
Block a user