LibsDisguises/src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java

69 lines
2.2 KiB
Java
Raw Normal View History

package me.libraryaddict.disguise.commands;
2017-06-19 11:23:02 +02:00
import me.libraryaddict.disguise.DisguiseAPI;
2017-06-19 19:06:35 +02:00
import me.libraryaddict.disguise.utilities.LibsMsg;
2017-06-19 11:23:02 +02:00
import me.libraryaddict.disguise.utilities.TranslateType;
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-11-28 15:01:06 +01:00
public class UndisguiseRadiusCommand implements CommandExecutor {
private int maxRadius = 30;
2016-11-28 15:01:06 +01:00
public UndisguiseRadiusCommand(int maxRadius) {
this.maxRadius = maxRadius;
}
2016-11-28 15:01:06 +01:00
private boolean isNumeric(String string) {
try {
Integer.parseInt(string);
return true;
}
2016-11-28 15:01:06 +01:00
catch (Exception ex) {
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")) {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
2017-06-19 19:06:35 +02:00
2016-11-28 15:01:06 +01:00
if (sender.hasPermission("libsdisguises.undisguiseradius")) {
int radius = maxRadius;
2016-11-28 15:01:06 +01:00
if (args.length > 0) {
if (!isNumeric(args[0])) {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[0]));
return true;
}
radius = Integer.parseInt(args[0]);
2016-11-28 15:01:06 +01:00
if (radius > maxRadius) {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius));
radius = maxRadius;
}
}
2017-06-19 11:23:02 +02:00
int disguisedEntitys = 0;
2016-11-28 15:01:06 +01:00
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
if (entity == sender) {
continue;
}
2016-11-28 15:01:06 +01:00
if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(entity);
disguisedEntitys++;
}
}
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.UNDISRADIUS.get(disguisedEntitys));
2017-06-19 11:23:02 +02:00
} else {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
}