2013-09-25 16:49:24 +02:00
|
|
|
package me.libraryaddict.disguise.commands;
|
|
|
|
|
2013-07-16 07:00:49 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2016-05-09 17:28:38 +02:00
|
|
|
import me.libraryaddict.disguise.DisguiseAPI;
|
|
|
|
|
2013-07-16 07:00:49 +02:00
|
|
|
public class UndisguiseRadiusCommand implements CommandExecutor {
|
2015-08-03 00:39:44 +02:00
|
|
|
|
2013-07-16 08:53:39 +02:00
|
|
|
private int maxRadius = 30;
|
2013-07-16 07:00:49 +02:00
|
|
|
|
2013-07-16 13:42:35 +02:00
|
|
|
public UndisguiseRadiusCommand(int maxRadius) {
|
|
|
|
this.maxRadius = maxRadius;
|
|
|
|
}
|
|
|
|
|
2013-07-16 07:00:49 +02:00
|
|
|
private boolean isNumeric(String string) {
|
|
|
|
try {
|
|
|
|
Integer.parseInt(string);
|
|
|
|
return true;
|
|
|
|
} catch (Exception ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
|
|
if (sender.getName().equals("CONSOLE")) {
|
|
|
|
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (sender.hasPermission("libsdisguises.undisguiseradius")) {
|
2013-07-16 08:53:39 +02:00
|
|
|
int radius = maxRadius;
|
2013-07-16 07:00:49 +02:00
|
|
|
if (args.length > 0) {
|
|
|
|
if (!isNumeric(args[0])) {
|
|
|
|
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED
|
|
|
|
+ " is not a number!");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
radius = Integer.parseInt(args[0]);
|
2013-07-16 08:53:39 +02:00
|
|
|
if (radius > maxRadius) {
|
|
|
|
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius
|
|
|
|
+ "! Don't want to make too much lag right?");
|
|
|
|
radius = maxRadius;
|
|
|
|
}
|
2013-07-16 07:00:49 +02:00
|
|
|
}
|
|
|
|
int disguisedEntitys = 0;
|
|
|
|
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
|
2015-08-03 00:39:44 +02:00
|
|
|
if (entity == sender) {
|
2013-07-22 12:36:24 +02:00
|
|
|
continue;
|
2015-08-03 00:39:44 +02:00
|
|
|
}
|
2013-07-22 12:36:24 +02:00
|
|
|
if (DisguiseAPI.isDisguised(entity)) {
|
|
|
|
DisguiseAPI.undisguiseToAll(entity);
|
|
|
|
disguisedEntitys++;
|
|
|
|
}
|
2013-07-16 07:00:49 +02:00
|
|
|
}
|
|
|
|
sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!");
|
2015-08-03 00:39:44 +02:00
|
|
|
} else {
|
2014-06-01 17:52:54 +02:00
|
|
|
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
|
2015-08-03 00:39:44 +02:00
|
|
|
}
|
2013-07-16 07:00:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|