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