A bit of class refactoring and possibly a fix for visuals check

This commit is contained in:
H31IX committed 2012-06-14 12:38:00 -04:00
1 parent ff368ba431
commit dd1d13fe41
17 files changed
+34 -38

No files matched your search

@@ -0,0 +1,104 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012 AntiCheat Team | 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.util;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
/**
* <p>
* All the types of checks and their corresponding permission nodes.
*/
public enum CheckType
{
ZOMBE_FLY(Permission.CHECK_ZOMBE_FLY),
ZOMBE_NOCLIP(Permission.CHECK_ZOMBE_NOCLIP),
ZOMBE_CHEAT(Permission.CHECK_ZOMBE_CHEAT),
FLY(Permission.CHECK_FLY),
WATER_WALK(Permission.CHECK_WATERWALK),
NO_SWING(Permission.CHECK_NOSWING),
FAST_BREAK(Permission.CHECK_FASTBREAK),
FAST_PLACE(Permission.CHECK_FASTPLACE),
SPAM(Permission.CHECK_SPAM),
SPRINT(Permission.CHECK_SPRINT),
SNEAK(Permission.CHECK_SNEAK),
SPEED(Permission.CHECK_SPEED),
VISUAL(Permission.CHECK_VISUAL),
SPIDER(Permission.CHECK_SPIDER),
NOFALL(Permission.CHECK_NOFALL),
FAST_BOW(Permission.CHECK_FASTBOW),
FAST_EAT(Permission.CHECK_FASTEAT),
FAST_HEAL(Permission.CHECK_FASTHEAL),
FORCEFIELD(Permission.CHECK_FORCEFIELD),
XRAY(Permission.CHECK_XRAY),
LONG_REACH(Permission.CHECK_LONGREACH),
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE),
ITEM_SPAM(Permission.CHECK_ITEMSPAM);
private final Permission permission;
private final Map<String, Integer> level = new HashMap<String, Integer>();
private CheckType(Permission perm)
{
this.permission = perm;
}
public boolean checkPermission(Player player)
{
return permission.get(player);
}
public void logUse(Player player)
{
String name = player.getName();
if (level.get(name) == null)
{
level.put(name, 1);
}
else
{
int amount = level.get(name) + 1;
level.put(name, amount);
}
}
public void clearUse(Player player)
{
level.put(player.getName(), 0);
}
public int getUses(Player player)
{
int use = 0;
if (level.get(player.getName()) != null)
{
use = level.get(player.getName());
}
return use;
}
public static String getName(CheckType type)
{
char[] chars = type.toString().replaceAll("_", " ").toLowerCase().toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
return new String(chars);
}
}
@@ -0,0 +1,265 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012 AntiCheat Team | 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.util;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.h31ix.anticheat.manage.AnticheatManager;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class Configuration
{
private AnticheatManager micromanage = null; //like a boss!
private File configFile = null;
private File levelFile = null;
private File bukkitFile = null;
private File langFile = null;
private FileConfiguration config;
private FileConfiguration level;
private FileConfiguration lang;
private boolean logConsole;
private boolean logXRay;
private boolean alertXRay;
private boolean autoUpdate;
private boolean verboseStartup;
private boolean chatSpam;
private boolean commandSpam;
private int fileLogLevel = 0;
private String updateFolder;
private static Language language;
private List<String> worlds = new ArrayList<String>();
public Configuration(AnticheatManager instance)
{
micromanage = instance;
configFile = new File(micromanage.getPlugin().getDataFolder() + "/config.yml");
levelFile = new File(micromanage.getPlugin().getDataFolder() + "/data/level.yml");
bukkitFile = new File("bukkit.yml");
langFile = new File(micromanage.getPlugin().getDataFolder() + "/lang.yml");
load();
}
private void save()
{
try
{
config.save(configFile);
}
catch (IOException ex)
{
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
}
}
public boolean logConsole()
{
return logConsole;
}
public boolean logXRay()
{
return logXRay;
}
public boolean alertXRay()
{
return alertXRay;
}
public boolean autoUpdate()
{
return autoUpdate;
}
public boolean verboseStartup()
{
return verboseStartup;
}
public boolean chatSpam()
{
return chatSpam;
}
public boolean commandSpam()
{
return commandSpam;
}
public String updateFolder()
{
return updateFolder;
}
public int getFileLogLevel()
{
return fileLogLevel;
}
public Language getLang()
{
return language;
}
public final void load()
{
FileConfiguration bukkit;
micromanage.getPlugin().checkConfig();
config = YamlConfiguration.loadConfiguration(configFile);
level = YamlConfiguration.loadConfiguration(levelFile);
bukkit = YamlConfiguration.loadConfiguration(bukkitFile);
lang = YamlConfiguration.loadConfiguration(langFile);
language = new Language(lang);
updateFolder = bukkit.getString("settings.update-folder");
if (config.getString("Logging.Log to console") != null)
{
boolean b = config.getBoolean("Logging.Log to console");
config.set("Logging", null);
config.set("System.Log to console", b);
save();
}
logConsole = config.getBoolean("System.Log to console");
if (config.getList("Enable in") == null)
{
List<String> w = new ArrayList<String>();
for (World world : Bukkit.getServer().getWorlds())
{
w.add(world.getName());
}
config.set("Enable in", w);
save();
}
worlds = config.getStringList("Enable in");
if (config.getString("XRay.Log xray stats") == null)
{
config.set("XRay.Log xray stats", true);
save();
}
logXRay = config.getBoolean("XRay.Log xray stats");
if (config.getString("System.Auto update") == null)
{
config.set("System.Auto update", true);
save();
}
autoUpdate = config.getBoolean("System.Auto update");
if (config.getString("System.Verbose startup") == null)
{
config.set("System.Verbose startup", false);
save();
}
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");
if (config.getString("System.File log level") == null)
{
config.set("System.File log level", 1);
save();
}
fileLogLevel = config.getInt("System.File log level");
if (config.getString("System.Block chat spam") == null)
{
config.set("System.Block chat spam", true);
save();
}
chatSpam = config.getBoolean("System.Block chat spam");
if (config.getString("System.Block command spam") == null)
{
config.set("System.Block command spam", true);
save();
}
commandSpam = config.getBoolean("System.Block command spam");
}
public String getResult(String event)
{
return config.getString("Events.Level " + event);
}
public void setLog(boolean b)
{
config.set("System.Log to console", b);
this.logConsole = b;
try
{
config.save(configFile);
}
catch (IOException ex)
{
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List<String> getWorlds()
{
return worlds;
}
public File getConfigFile()
{
return configFile;
}
public File getLevelFile()
{
return levelFile;
}
public boolean checkInWorld(World world)
{
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);
}
}
}
@@ -0,0 +1,57 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012 AntiCheat Team | 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.util;
import org.bukkit.Location;
public class Distance
{
private final Location l1, l2;
public Distance(Location from, Location to)
{
l1 = to;
l2 = from;
}
public double fromY()
{
return l2.getY();
}
public double toY()
{
return l1.getY();
}
public double getXDifference()
{
return Math.abs(l1.getX() - l2.getX());
}
public double getZDifference()
{
return Math.abs(l1.getZ() - l2.getZ());
}
public double getYDifference()
{
return Math.abs(l1.getY() - l2.getY());
}
}
@@ -0,0 +1,78 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012 AntiCheat Team | 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.util;
import org.bukkit.configuration.file.FileConfiguration;
public class Language
{
private static String[] medAlert = null;
private static String[] highAlert = null;
private static String[] warning = null;
private static String banReason = null;
private static String banBroadcast = null;
private static String kickReason = null;
private static String kickBroadcast = null;
public Language(FileConfiguration file)
{
medAlert = file.getList("alert.medium_alert").toArray(new String[file.getList("alert.medium_alert").size()]);
highAlert = file.getList("alert.high_alert").toArray(new String[file.getList("alert.high_alert").size()]);
warning = file.getList("warning.player_warning").toArray(new String[file.getList("warning.player_warning").size()]);
banReason = file.getString("ban.ban_reason");
banBroadcast = file.getString("ban.ban_broadcast");
kickReason = file.getString("kick.kick_reason");
kickBroadcast = file.getString("kick.kick_broadcast");
}
public String[] getMediumAlert()
{
return medAlert;
}
public String[] getHighAlert()
{
return highAlert;
}
public String[] getWarning()
{
return warning;
}
public String getBanReason()
{
return banReason;
}
public String getBanBroadcast()
{
return banBroadcast;
}
public String getKickReason()
{
return kickReason;
}
public String getKickBroadcast()
{
return kickBroadcast;
}
}
@@ -0,0 +1,71 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012 AntiCheat Team | 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.util;
import org.bukkit.command.CommandSender;
public enum Permission
{
/* Check Nodes */
CHECK_ZOMBE_FLY,
CHECK_ZOMBE_NOCLIP,
CHECK_ZOMBE_CHEAT,
CHECK_FLY,
CHECK_WATERWALK,
CHECK_NOSWING,
CHECK_FASTBREAK,
CHECK_FASTPLACE,
CHECK_SPAM,
CHECK_SPRINT,
CHECK_SNEAK,
CHECK_SPEED,
CHECK_SPIDER,
CHECK_NOFALL,
CHECK_FASTBOW,
CHECK_FASTEAT,
CHECK_FASTHEAL,
CHECK_FORCEFIELD,
CHECK_XRAY,
CHECK_LONGREACH,
CHECK_FASTPROJECTILE,
CHECK_ITEMSPAM,
CHECK_VISUAL,
/* System Nodes */
SYSTEM_LOG,
SYSTEM_XRAY,
SYSTEM_RESET,
SYSTEM_SPY,
SYSTEM_HELP,
SYSTEM_UPDATE,
SYSTEM_REPORT,
SYSTEM_RELOAD;
public boolean get(CommandSender cs)
{
return cs.hasPermission(toString());
}
@Override
public String toString()
{
return "anticheat." + this.name().toLowerCase().replace("_", ".");
}
}