Added multi-world settings along with a reload function.

This commit is contained in:
Adam committed 2012-04-28 17:19:11 -04:00
1 parent 272bd83382
commit f2475d5803
6 files changed
+79 -1

No files matched your search

@@ -1,6 +1,7 @@
package net.h31ix.anticheat;
import java.io.File;
import java.util.List;
import net.h31ix.anticheat.manage.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -11,6 +12,7 @@ import net.h31ix.anticheat.event.PlayerListener;
import net.h31ix.anticheat.manage.BowManager;
import net.h31ix.anticheat.manage.ItemManager;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Anticheat extends JavaPlugin {
@@ -33,6 +35,7 @@ public class Anticheat extends JavaPlugin {
public boolean lagged = false;
public boolean logConsole;
public FileConfiguration log;
private List<String> worlds;
@Override
public void onDisable() {
@@ -47,7 +50,7 @@ public class Anticheat extends JavaPlugin {
config = new Configuration(this);
tracker = new PlayerTracker(this);
logConsole = config.logConsole;
worlds = config.getWorlds();
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
getServer().getPluginManager().registerEvents(new BlockListener(this), this);
getServer().getPluginManager().registerEvents(new EntityListener(this), this);
@@ -77,5 +80,20 @@ public class Anticheat extends JavaPlugin {
l.log(Level.WARNING,"[AntiCheat] "+s);
}
}
public boolean check(Player player)
{
boolean check = false;
String pworld = player.getWorld().getName();
for(String world : worlds)
{
if(world.equals(pworld))
{
check = true;
break;
}
}
return check;
}
}
@@ -2,8 +2,12 @@ package net.h31ix.anticheat;
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 org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -12,12 +16,38 @@ public class Configuration {
private FileConfiguration config;
private Anticheat plugin;
public boolean logConsole;
private List<String> worlds = new ArrayList<String>();
public Configuration(Anticheat plugin)
{
this.plugin = plugin;
load();
}
private void save()
{
try {
config.save(configFile);
} catch (IOException ex) {
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void load()
{
config = YamlConfiguration.loadConfiguration(configFile);
logConsole = config.getBoolean("Logging.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 = (List<String>)(config.getList("Enable in"));
}
public String getResult(String event)
@@ -37,4 +67,8 @@ public class Configuration {
}
}
public List<String> getWorlds()
{
return worlds;
}
}
@@ -102,6 +102,14 @@ public class CommandManager implements CommandExecutor {
}
}
}
else if(args[0].equalsIgnoreCase("reload"))
{
if(hasPermission("admin",cs))
{
plugin.config.load();
cs.sendMessage(green+"AntiCheat configuration reloaded.");
}
}
else
{
cs.sendMessage("Unrecognized command.");
@@ -32,6 +32,8 @@ public class BlockListener implements Listener {
Player player = event.getPlayer();
Block block = event.getBlock();
if(player != null)
{
if(plugin.check(player))
{
//Check if an animation was done before this
if(!am.swungArm(player))
@@ -64,6 +66,7 @@ public class BlockListener implements Listener {
}
am.reset(player);
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
@@ -71,6 +74,8 @@ public class BlockListener implements Listener {
Player player = event.getPlayer();
Block block = event.getBlock();
if(player != null)
{
if(plugin.check(player))
{
if(block.getType() != Material.LADDER)
{
@@ -100,4 +105,5 @@ public class BlockListener implements Listener {
}
am.reset(player);
}
}
}
@@ -33,6 +33,8 @@ public class EntityListener implements Listener {
if(event.getEntity() instanceof Player)
{
Player player = (Player)event.getEntity();
if(plugin.check(player))
{
if(!player.hasPermission("anticheat.autofire"))
{
//This mostly prevents bow spam, hopefully more auto-firing in the future
@@ -50,6 +52,7 @@ public class EntityListener implements Listener {
}
}
}
}
@EventHandler
public void onEntityDamage(EntityDamageEvent event)
@@ -60,6 +63,8 @@ public class EntityListener implements Listener {
if (e.getDamager() instanceof Player)
{
Player p = (Player) e.getDamager();
if(plugin.check(p))
{
if(event.getEntity() instanceof Player)
{
Player player = (Player)event.getEntity();
@@ -86,4 +91,5 @@ public class EntityListener implements Listener {
}
}
}
}
}
@@ -72,6 +72,8 @@ public class PlayerListener implements Listener {
public void onPlayerDropItem(PlayerDropItemEvent event)
{
Player player = event.getPlayer();
if(plugin.check(player))
{
if(!player.hasPermission("anticheat.spamdrop"))
{
if(!im.hasDropped(player))
@@ -87,6 +89,7 @@ public class PlayerListener implements Listener {
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerAnimation(PlayerAnimationEvent event)
@@ -153,6 +156,8 @@ public class PlayerListener implements Listener {
public void onPlayerMove(PlayerMoveEvent event)
{
Player player = event.getPlayer();
if(plugin.check(player))
{
if(!plugin.lagged && !ex.isHit(player))
{
//Log the player's health level
@@ -354,6 +359,7 @@ public class PlayerListener implements Listener {
}
}
}
}
public boolean canStand(Block block)
{