mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Automatic XRay detection, also alerts are now sent to the console.
This commit is contained in:
1 parent
d3e77f4e81
commit
dda661c320
7 files changed
+221
-73
No files matched your search
@@ -32,8 +32,12 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.h31ix.anticheat.event.*;
|
||||
import net.h31ix.anticheat.manage.AnticheatManager;
|
||||
import net.h31ix.anticheat.manage.Utilities;
|
||||
import net.h31ix.anticheat.metrics.Metrics;
|
||||
import net.h31ix.anticheat.xray.XRayListener;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -52,7 +56,7 @@ public class Anticheat extends JavaPlugin
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
//Nothing to do.
|
||||
getServer().getScheduler().cancelAllTasks();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,9 +80,32 @@ public class Anticheat extends JavaPlugin
|
||||
eventList.add(new BlockListener());
|
||||
eventList.add(new EntityListener());
|
||||
eventList.add(new VehicleListener());
|
||||
final XRayTracker xtracker = AnticheatManager.XRAY_TRACKER;
|
||||
if(config.logXRay())
|
||||
{
|
||||
eventList.add(new XRayListener());
|
||||
if(config.alertXRay())
|
||||
{
|
||||
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for(Player player : getServer().getOnlinePlayers())
|
||||
{
|
||||
String name = player.getName();
|
||||
if(!xtracker.hasAlerted(name) && xtracker.sufficientData(name) && xtracker.hasAbnormal(name))
|
||||
{
|
||||
String [] alert = new String[2];
|
||||
alert[0] = ChatColor.YELLOW+"[ALERT] "+ChatColor.WHITE+name+ChatColor.YELLOW+" might be using xray.";
|
||||
alert[1] = ChatColor.YELLOW+"[ALERT] Please check their xray stats using "+ChatColor.WHITE+"/anticheat xray "+name+ChatColor.YELLOW+".";
|
||||
Utilities.alert(alert);
|
||||
xtracker.logAlert(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1200L, 1200L);
|
||||
}
|
||||
}
|
||||
for(Listener listener : eventList)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ public class Configuration {
|
||||
private FileConfiguration bukkit;
|
||||
private boolean logConsole;
|
||||
private boolean logXRay;
|
||||
private boolean alertXRay;
|
||||
private boolean autoUpdate;
|
||||
private boolean verboseStartup;
|
||||
private String updateFolder;
|
||||
@@ -68,6 +69,11 @@ public class Configuration {
|
||||
return logXRay;
|
||||
}
|
||||
|
||||
public boolean alertXRay()
|
||||
{
|
||||
return logXRay;
|
||||
}
|
||||
|
||||
public boolean autoUpdate()
|
||||
{
|
||||
return autoUpdate;
|
||||
@@ -124,7 +130,13 @@ public class Configuration {
|
||||
config.set("System.Verbose startup", false);
|
||||
save();
|
||||
}
|
||||
verboseStartup = config.getBoolean("System.Verbose startup");
|
||||
verboseStartup = config.getBoolean("System.Verbose startup");
|
||||
if(config.getString("XRay.Alert when xray is found") == null)
|
||||
{
|
||||
config.set("XRay.Alert when xray is found", false);
|
||||
save();
|
||||
}
|
||||
alertXRay = config.getBoolean("XRay.Alert when xray is found");
|
||||
}
|
||||
|
||||
public String getResult(String event)
|
||||
|
||||
@@ -33,27 +33,19 @@ public class PlayerManager {
|
||||
|
||||
public void reactMedium(Player player)
|
||||
{
|
||||
execute("Medium",player);
|
||||
for(Player p : player.getServer().getOnlinePlayers())
|
||||
{
|
||||
if(p.hasPermission("anticheat.alert") || p.hasPermission("anticheat.admin") || p.isOp())
|
||||
{
|
||||
p.sendMessage(ChatColor.YELLOW+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.YELLOW+" has entered the MEDIUM hack level.");
|
||||
p.sendMessage(ChatColor.YELLOW+"[ALERT] This means they may be using a hacked client or may have a bad connection!");
|
||||
}
|
||||
}
|
||||
execute("Medium",player);
|
||||
String [] alert = new String[2];
|
||||
alert[0] = ChatColor.YELLOW+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.YELLOW+" has entered the MEDIUM hack level.";
|
||||
alert[1] = ChatColor.YELLOW+"[ALERT] This means they may be using a hacked client or may have a bad connection!";
|
||||
Utilities.alert(alert);
|
||||
}
|
||||
public void reactHigh(Player player)
|
||||
{
|
||||
execute("High",player);
|
||||
for(Player p : player.getServer().getOnlinePlayers())
|
||||
{
|
||||
if(p.hasPermission("anticheat.alert") || p.hasPermission("anticheat.admin") || p.isOp())
|
||||
{
|
||||
p.sendMessage(ChatColor.RED+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.RED+" has entered the HIGH hack level.");
|
||||
p.sendMessage(ChatColor.RED+"[ALERT] This means they probably are hacking or are lagging out!");
|
||||
}
|
||||
}
|
||||
String [] alert = new String[2];
|
||||
alert[0] = ChatColor.RED+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.RED+" has entered the HIGH hack level.";
|
||||
alert[1] = ChatColor.RED+"[ALERT] This means they probably are hacking or are lagging out!";
|
||||
Utilities.alert(alert);
|
||||
}
|
||||
|
||||
public void increaseLevel(Player player)
|
||||
|
||||
@@ -20,6 +20,10 @@ package net.h31ix.anticheat.manage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@@ -34,6 +38,27 @@ public final class Utilities
|
||||
{
|
||||
|
||||
}
|
||||
public static void alert(String [] message)
|
||||
{
|
||||
for(Player p : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
if(p.hasPermission("anticheat.alert") || p.hasPermission("anticheat.admin") || p.isOp())
|
||||
{
|
||||
for(String msg : message)
|
||||
{
|
||||
p.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(AnticheatManager.CONFIGURATION.logConsole())
|
||||
{
|
||||
Logger logger = Logger.getLogger("Minecraft");
|
||||
for(String msg : message)
|
||||
{
|
||||
logger.log(Level.INFO,ChatColor.stripColor(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
public static boolean cantStandAt(Block block)
|
||||
{
|
||||
return !canStand(block) && cantStandClose(block) && cantStandFar(block);
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012 H31IX http://h31ix.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.xray;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class XRayStats {
|
||||
private static final int DIVISOR = 100;
|
||||
private double t = 1;
|
||||
private double d = 0;
|
||||
private double g = 0;
|
||||
private double i = 0;
|
||||
private double c = 0;
|
||||
private double l = 0;
|
||||
private double r = 0;
|
||||
private double o = 0;
|
||||
|
||||
public XRayStats(String player,Map<String,Integer> diamond,Map<String,Integer> gold,Map<String,Integer> iron,Map<String,Integer> coal,Map<String,Integer> lapis,Map<String,Integer> redstone,Map<String,Integer> other,Map<String,Integer> total)
|
||||
{
|
||||
if(total.get(player) != null)
|
||||
{
|
||||
t = total.get(player);
|
||||
}
|
||||
if(diamond.get(player) != null)
|
||||
{
|
||||
d = (diamond.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(gold.get(player) != null)
|
||||
{
|
||||
g = (gold.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(iron.get(player) != null)
|
||||
{
|
||||
i = (iron.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(coal.get(player) != null)
|
||||
{
|
||||
c = (coal.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(lapis.get(player) != null)
|
||||
{
|
||||
l = (lapis.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(redstone.get(player) != null)
|
||||
{
|
||||
r = (redstone.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(other.get(player) != null)
|
||||
{
|
||||
o = (other.get(player)/t)*DIVISOR;
|
||||
}
|
||||
}
|
||||
|
||||
public double getTotal()
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
public double getDiamond()
|
||||
{
|
||||
return d;
|
||||
}
|
||||
|
||||
public double getGold()
|
||||
{
|
||||
return g;
|
||||
}
|
||||
|
||||
public double getIron()
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
public double getCoal()
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
public double getLapis()
|
||||
{
|
||||
return l;
|
||||
}
|
||||
|
||||
public double getRedstone()
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
public double getOther()
|
||||
{
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,9 @@
|
||||
|
||||
package net.h31ix.anticheat.xray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -32,11 +34,11 @@ public class XRayTracker {
|
||||
private Map<String,Integer> redstone = new HashMap<String,Integer>();
|
||||
private Map<String,Integer> block = new HashMap<String,Integer>();
|
||||
private Map<String,Integer> totalblock = new HashMap<String,Integer>();
|
||||
private List<String> alerted = new ArrayList<String>();
|
||||
private static final ChatColor GREEN = ChatColor.GREEN;
|
||||
private static final ChatColor WHITE = ChatColor.WHITE;
|
||||
private static final ChatColor RED = ChatColor.RED;
|
||||
private static final ChatColor GRAY = ChatColor.GRAY;
|
||||
private static final int DIVISOR = 100;
|
||||
private static final int RATIO_DIVISOR = 3;
|
||||
private static final int POWER = 10;
|
||||
private static final int MIN_BLOCK_COUNT = 100;
|
||||
@@ -60,19 +62,27 @@ public class XRayTracker {
|
||||
}
|
||||
cs.sendMessage(GRAY+"Percent "+type+" ore: "+color+round(x)+"%");
|
||||
}
|
||||
public void sendMessage(CommandSender cs, String player, double t, double d, double g, double i, double c, double la, double r, double b)
|
||||
|
||||
public boolean calculate(String player, double x, double b)
|
||||
{
|
||||
cs.sendMessage("--------------------["+GREEN+"X-Ray Stats"+WHITE+"]---------------------");
|
||||
cs.sendMessage(GRAY+"Player: "+WHITE+player);
|
||||
cs.sendMessage(GRAY+"Total blocks broken: "+WHITE+t);
|
||||
calculate(cs,player,d,b,"diamond");
|
||||
calculate(cs,player,g,b,"gold");
|
||||
calculate(cs,player,i,b,"iron");
|
||||
calculate(cs,player,c,b,"coal");
|
||||
calculate(cs,player,la,b,"lapis");
|
||||
calculate(cs,player,r,b,"redstone");
|
||||
cs.sendMessage(GRAY+"Percent all other blocks: "+WHITE+round(b)+"%");
|
||||
cs.sendMessage("-----------------------------------------------------");
|
||||
return x >= b/RATIO_DIVISOR;
|
||||
}
|
||||
|
||||
public boolean hasAbnormal(String player)
|
||||
{
|
||||
XRayStats stats = new XRayStats(player,diamond,gold,iron,coal,lapis,redstone,block,totalblock);
|
||||
double total = stats.getOther();
|
||||
return calculate(player,stats.getDiamond(),total) || calculate(player,stats.getGold(),total) || calculate(player,stats.getIron(),total) || calculate(player,stats.getCoal(),total) || calculate(player,stats.getLapis(),total) || calculate(player,stats.getRedstone(),total);
|
||||
}
|
||||
|
||||
public boolean hasAlerted(String player)
|
||||
{
|
||||
return alerted.contains(player);
|
||||
}
|
||||
|
||||
public void logAlert(String player)
|
||||
{
|
||||
alerted.add(player);
|
||||
}
|
||||
|
||||
public void sendStats(CommandSender cs, String player)
|
||||
@@ -82,47 +92,19 @@ public class XRayTracker {
|
||||
|
||||
public void getStats(CommandSender cs, String player)
|
||||
{
|
||||
double t = 1;
|
||||
double d = 0;
|
||||
double g = 0;
|
||||
double i = 0;
|
||||
double c = 0;
|
||||
double la = 0;
|
||||
double r = 0;
|
||||
double b = 0;
|
||||
if(totalblock.get(player) != null)
|
||||
{
|
||||
t = totalblock.get(player);
|
||||
}
|
||||
if(diamond.get(player) != null)
|
||||
{
|
||||
d = (diamond.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(gold.get(player) != null)
|
||||
{
|
||||
g = (gold.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(iron.get(player) != null)
|
||||
{
|
||||
i = (iron.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(coal.get(player) != null)
|
||||
{
|
||||
c = (coal.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(lapis.get(player) != null)
|
||||
{
|
||||
la = (lapis.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(redstone.get(player) != null)
|
||||
{
|
||||
r = (redstone.get(player)/t)*DIVISOR;
|
||||
}
|
||||
if(block.get(player) != null)
|
||||
{
|
||||
b = (block.get(player)/t)*DIVISOR;
|
||||
}
|
||||
sendMessage(cs,player,t,d,g,i,c,la,r,b);
|
||||
XRayStats stats = new XRayStats(player,diamond,gold,iron,coal,lapis,redstone,block,totalblock);
|
||||
double total = stats.getOther();
|
||||
cs.sendMessage("--------------------["+GREEN+"X-Ray Stats"+WHITE+"]---------------------");
|
||||
cs.sendMessage(GRAY+"Player: "+WHITE+player);
|
||||
cs.sendMessage(GRAY+"Total blocks broken: "+WHITE+stats.getTotal());
|
||||
calculate(cs,player,stats.getDiamond(),total,"diamond");
|
||||
calculate(cs,player,stats.getGold(),total,"gold");
|
||||
calculate(cs,player,stats.getIron(),total,"iron");
|
||||
calculate(cs,player,stats.getCoal(),total,"coal");
|
||||
calculate(cs,player,stats.getLapis(),total,"lapis");
|
||||
calculate(cs,player,stats.getRedstone(),total,"redstone");
|
||||
cs.sendMessage(GRAY+"Percent all other blocks: "+WHITE+round(stats.getOther())+"%");
|
||||
cs.sendMessage("-----------------------------------------------------");
|
||||
}
|
||||
|
||||
public void addDiamond(String player)
|
||||
|
||||
Reference in new issue
Block a user