From 5eca9c9d125ecb8c854508b6a8c87d4f71e802ae Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 16 Jul 2013 18:53:39 +1200 Subject: [PATCH] Now able to set the max radius for disguiseradius and undisguiseradius --- config.yml | 6 +++++- .../disguise/Commands/DisguiseRadiusCommand.java | 12 +++++++++--- .../disguise/Commands/UndisguiseRadiusCommand.java | 12 +++++++++++- src/me/libraryaddict/disguise/LibsDisguises.java | 6 +++--- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/config.yml b/config.yml index d0dc58af..d42238cf 100644 --- a/config.yml +++ b/config.yml @@ -1,4 +1,8 @@ # Shall I notify people of a LibsDisguises update? NotifyUpdate: true # Whats the permission to get the notification? -Permission: 'libsdisguises.update' \ No newline at end of file +Permission: 'libsdisguises.update' +# Whats the max size allowed for command disguiseradius +DisguiseRadiusMax: 30 +# Whats the max size allowed for command undisguiseradius +UndisguiseRadiusMax: 30 \ No newline at end of file diff --git a/src/me/libraryaddict/disguise/Commands/DisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/Commands/DisguiseRadiusCommand.java index 2ffd5003..06b692e6 100644 --- a/src/me/libraryaddict/disguise/Commands/DisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/Commands/DisguiseRadiusCommand.java @@ -19,6 +19,11 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; public class DisguiseRadiusCommand implements CommandExecutor { + private int maxRadius = 30; + + public DisguiseRadiusCommand(int maxRadius) { + this.maxRadius = maxRadius; + } private ArrayList allowedDisguises(CommandSender sender) { ArrayList names = new ArrayList(); @@ -75,9 +80,10 @@ public class DisguiseRadiusCommand implements CommandExecutor { if (allowedDisguises.contains(args[1].toLowerCase())) { // He can use the disguise huh. int radius = Integer.parseInt(args[0]); - if (radius > 30) { - sender.sendMessage(ChatColor.RED + "Limited radius to 30! Don't want to make too much lag right?"); - radius = 30; + if (radius > maxRadius) { + sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + + "! Don't want to make too much lag right?"); + radius = maxRadius; } Disguise disguise = null; // Time to start constructing the disguise. diff --git a/src/me/libraryaddict/disguise/Commands/UndisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/Commands/UndisguiseRadiusCommand.java index f656b960..6989d53e 100644 --- a/src/me/libraryaddict/disguise/Commands/UndisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/Commands/UndisguiseRadiusCommand.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; public class UndisguiseRadiusCommand implements CommandExecutor { + private int maxRadius = 30; private boolean isNumeric(String string) { try { @@ -20,6 +21,10 @@ public class UndisguiseRadiusCommand implements CommandExecutor { } } + public UndisguiseRadiusCommand(int maxRadius) { + this.maxRadius = maxRadius; + } + @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { @@ -27,7 +32,7 @@ public class UndisguiseRadiusCommand implements CommandExecutor { return true; } if (sender.hasPermission("libsdisguises.undisguiseradius")) { - int radius = 30; + int radius = maxRadius; if (args.length > 0) { if (!isNumeric(args[0])) { sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED @@ -35,6 +40,11 @@ public class UndisguiseRadiusCommand implements CommandExecutor { return true; } radius = Integer.parseInt(args[0]); + if (radius > maxRadius) { + sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + + "! Don't want to make too much lag right?"); + radius = maxRadius; + } } int disguisedEntitys = 0; for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 26df1032..af27bfc3 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -220,6 +220,7 @@ public class LibsDisguises extends JavaPlugin implements Listener { } } }); + saveDefaultConfig(); DisguiseListener listener = new DisguiseListener(this); Bukkit.getPluginManager().registerEvents(listener, this); getCommand("disguise").setExecutor(new DisguiseCommand()); @@ -228,9 +229,8 @@ public class LibsDisguises extends JavaPlugin implements Listener { getCommand("undisguiseplayer").setExecutor(new UndisguisePlayerCommand()); getCommand("undisguiseentity").setExecutor(new UndisguiseEntityCommand(listener)); getCommand("disguiseentity").setExecutor(new DisguiseEntityCommand(listener)); - getCommand("disguiseradius").setExecutor(new DisguiseRadiusCommand()); - getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand()); - saveDefaultConfig(); + getCommand("disguiseradius").setExecutor(new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax"))); + getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax"))); permission = getConfig().getString("Permission"); if (getConfig().getBoolean("NotifyUpdate")) { currentVersion = getDescription().getVersion();