Configuration file for some event customization and options.

This commit is contained in:
Adam committed 2012-04-22 01:49:52 -04:00
1 parent 2d96b467ef
commit fe1d1596a8
5 files changed
+92 -8

No files matched your search

@@ -1,5 +1,6 @@
package net.h31ix.anticheat;
import java.io.File;
import net.h31ix.anticheat.manage.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -18,13 +19,13 @@ public class Anticheat extends JavaPlugin {
public ItemManager im = new ItemManager(this);
public BowManager bm = new BowManager(this);
public HealthManager hm = new HealthManager();
public PlayerTracker tracker = new PlayerTracker();
public Configuration config;
public PlayerTracker tracker;
private static final Logger l = Logger.getLogger("Minecraft");
private long lastTime = System.currentTimeMillis();
private long time = 0;
public boolean lagged = false;
public boolean log = false;
public boolean log;
@Override
public void onDisable() {
@@ -32,6 +33,14 @@ public class Anticheat extends JavaPlugin {
@Override
public void onEnable() {
if(!new File(this.getDataFolder()+"\\config.yml").exists())
{
this.saveDefaultConfig();
}
config = new Configuration(this);
tracker = new PlayerTracker(this);
log = config.logConsole;
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
getServer().getPluginManager().registerEvents(new BlockListener(this), this);
getServer().getPluginManager().registerEvents(new EntityListener(this), this);
@@ -0,0 +1,40 @@
package net.h31ix.anticheat;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class Configuration {
private File configFile = new File("plugins/AntiCheat/config.yml");
private FileConfiguration config;
private Anticheat plugin;
public boolean logConsole;
public Configuration(Anticheat plugin)
{
this.plugin = plugin;
config = YamlConfiguration.loadConfiguration(configFile);
logConsole = config.getBoolean("Logging.Log to console");
}
public String getResult(String event)
{
return config.getString("Events.Level "+event);
}
public void setLog(boolean b)
{
config.set("Logging.Log to console", b);
this.logConsole = b;
plugin.log = b;
try {
config.save(configFile);
} catch (IOException ex) {
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@@ -6,12 +6,14 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class PlayerTracker {
public Map<Player,Integer> level = new HashMap<Player,Integer>();
Anticheat plugin;
Configuration config;
public PlayerTracker()
public PlayerTracker(Anticheat plugin)
{
this.plugin = plugin;
this.config = plugin.config;
}
public void increaseLevel(Player player)
@@ -26,6 +28,7 @@ public class PlayerTracker {
level.put(player, playerLevel+2);
if(playerLevel <= 10 && playerLevel+1 > 10 && playerLevel+1 <= 40)
{
execute("Medium",player);
for(Player p : player.getServer().getOnlinePlayers())
{
if(p.hasPermission("anticheat.admin"))
@@ -37,6 +40,7 @@ public class PlayerTracker {
}
if(playerLevel <= 40 && playerLevel+1 > 40)
{
execute("High",player);
for(Player p : player.getServer().getOnlinePlayers())
{
if(p.hasPermission("anticheat.admin"))
@@ -69,4 +73,25 @@ public class PlayerTracker {
return 0;
}
}
public void execute(String level, Player player)
{
String result = config.getResult(level);
if(result.equalsIgnoreCase("KICK"))
{
player.kickPlayer(ChatColor.RED+"Kicked by AntiCheat");
player.getServer().broadcastMessage(ChatColor.RED+"[AntiCheat] "+player.getName()+" was kicked for hacking.");
}
else if(result.equalsIgnoreCase("WARN"))
{
player.sendMessage(ChatColor.RED+"[AntiCheat] Hacks are not allowed on this server.");
player.sendMessage(ChatColor.RED+"[AntiCheat] If you continue to use hacks, action will be taken.");
}
else if(result.equalsIgnoreCase("BAN"))
{
player.setBanned(true);
player.kickPlayer(ChatColor.RED+"Banned by AntiCheat");
player.getServer().broadcastMessage(ChatColor.RED+"[AntiCheat] "+player.getName()+" was banned for hacking.");
}
}
}
@@ -32,12 +32,12 @@ public class CommandManager implements CommandExecutor {
{
if(args[1].equalsIgnoreCase("enable"))
{
plugin.log = true;
plugin.config.setLog(true);
cs.sendMessage("Logging enabled. Check the console.");
}
else if(args[1].equalsIgnoreCase("disable"))
{
plugin.log = false;
plugin.config.setLog(false);
cs.sendMessage("Logs will no longer be sent to the console.");
}
else