2016-06-18 17:16:32 +02:00
|
|
|
package me.libraryaddict.disguise.commands;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
import me.libraryaddict.disguise.DisguiseAPI;
|
|
|
|
|
2016-11-28 15:01:06 +01:00
|
|
|
public class UndisguiseRadiusCommand implements CommandExecutor {
|
2016-06-18 17:16:32 +02:00
|
|
|
private int maxRadius = 30;
|
|
|
|
|
2016-11-28 15:01:06 +01:00
|
|
|
public UndisguiseRadiusCommand(int maxRadius) {
|
2016-06-18 17:16:32 +02:00
|
|
|
this.maxRadius = maxRadius;
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:01:06 +01:00
|
|
|
private boolean isNumeric(String string) {
|
|
|
|
try {
|
2016-06-18 17:16:32 +02:00
|
|
|
Integer.parseInt(string);
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-28 15:01:06 +01:00
|
|
|
catch (Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-28 15:01:06 +01:00
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
|
|
if (sender.getName().equals("CONSOLE")) {
|
2016-06-18 17:16:32 +02:00
|
|
|
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-28 15:01:06 +01:00
|
|
|
if (sender.hasPermission("libsdisguises.undisguiseradius")) {
|
2016-06-18 17:16:32 +02:00
|
|
|
int radius = maxRadius;
|
2016-11-28 15:01:06 +01:00
|
|
|
if (args.length > 0) {
|
|
|
|
if (!isNumeric(args[0])) {
|
2016-06-18 17:16:32 +02:00
|
|
|
sender.sendMessage(
|
|
|
|
ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED + " is not a number!");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
radius = Integer.parseInt(args[0]);
|
2016-11-28 15:01:06 +01:00
|
|
|
if (radius > maxRadius) {
|
2016-06-18 17:16:32 +02:00
|
|
|
sender.sendMessage(
|
|
|
|
ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?");
|
|
|
|
radius = maxRadius;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int disguisedEntitys = 0;
|
2016-11-28 15:01:06 +01:00
|
|
|
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
|
|
|
|
if (entity == sender) {
|
2016-06-18 17:16:32 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-11-28 15:01:06 +01:00
|
|
|
if (DisguiseAPI.isDisguised(entity)) {
|
2016-06-18 17:16:32 +02:00
|
|
|
DisguiseAPI.undisguiseToAll(entity);
|
|
|
|
disguisedEntitys++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!");
|
|
|
|
}
|
2016-11-28 15:01:06 +01:00
|
|
|
else {
|
2016-06-18 17:16:32 +02:00
|
|
|
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|