Added perms for the command, added safety check
This commit is contained in:
parent
bd38aa428a
commit
83e0ffb223
@ -18,26 +18,62 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public class DisguiseCommand implements CommandExecutor {
|
public class DisguiseCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
private ArrayList<String> allowedDisguises(CommandSender sender) {
|
||||||
|
ArrayList<String> names = new ArrayList<String>();
|
||||||
|
for (DisguiseType type : DisguiseType.values()) {
|
||||||
|
String name = type.name().toLowerCase();
|
||||||
|
if (sender.hasPermission("libsdisguises.disguise." + name))
|
||||||
|
names.add(name);
|
||||||
|
}
|
||||||
|
Collections.sort(names);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<String> forbiddenDisguises(CommandSender sender) {
|
||||||
|
ArrayList<String> names = new ArrayList<String>();
|
||||||
|
for (DisguiseType type : DisguiseType.values()) {
|
||||||
|
String name = type.name().toLowerCase();
|
||||||
|
if (!sender.hasPermission("libsdisguises.disguise." + name))
|
||||||
|
names.add(name);
|
||||||
|
}
|
||||||
|
Collections.sort(names);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNumeric(String string) {
|
||||||
|
try {
|
||||||
|
Integer.parseInt(string);
|
||||||
|
return true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
if (sender.isOp()) {
|
Player p = (Player) sender;
|
||||||
Player p = (Player) sender;
|
if (args.length == 0) {
|
||||||
if (args.length == 0) {
|
ArrayList<String> names = allowedDisguises(sender);
|
||||||
ArrayList<String> names = new ArrayList<String>();
|
ArrayList<String> otherNames = forbiddenDisguises(sender);
|
||||||
for (DisguiseType type : DisguiseType.values()) {
|
if (names.size() > 0) {
|
||||||
names.add(type.name().toLowerCase());
|
|
||||||
}
|
|
||||||
Collections.sort(names);
|
|
||||||
sender.sendMessage(ChatColor.RED + "You can use the disguises: " + ChatColor.GREEN
|
sender.sendMessage(ChatColor.RED + "You can use the disguises: " + ChatColor.GREEN
|
||||||
+ StringUtils.join(names, ChatColor.RED + ", " + ChatColor.GREEN));
|
+ StringUtils.join(names, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||||
} else if (args[0].equalsIgnoreCase("undiguise") || args[0].equalsIgnoreCase("undis")
|
if (otherNames.size() > 0) {
|
||||||
|| args[0].equalsIgnoreCase("un")) {
|
sender.sendMessage(ChatColor.RED + "Other disguises: " + ChatColor.GREEN
|
||||||
|
+ StringUtils.join(names, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||||
|
} else if (args[0].equalsIgnoreCase("undiguise") || args[0].equalsIgnoreCase("undis") || args[0].equalsIgnoreCase("un")) {
|
||||||
|
if (sender.hasPermission("libsdisguises.disguise.undisguise")) {
|
||||||
if (DisguiseAPI.isDisguised(p.getName())) {
|
if (DisguiseAPI.isDisguised(p.getName())) {
|
||||||
DisguiseAPI.undisguiseToAll(p);
|
DisguiseAPI.undisguiseToAll(p);
|
||||||
sender.sendMessage(ChatColor.RED + "You are no longer disguised");
|
sender.sendMessage(ChatColor.RED + "You are no longer disguised");
|
||||||
} else
|
} else
|
||||||
sender.sendMessage(ChatColor.RED + "You are not disguised!");
|
sender.sendMessage(ChatColor.RED + "You are not disguised!");
|
||||||
} else if (args[0].equalsIgnoreCase("player")) {
|
} else
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||||
|
} else if (args[0].equalsIgnoreCase("player")) {
|
||||||
|
if (sender.hasPermission("libsdisguises.disguise.player")) {
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
String name = ChatColor.translateAlternateColorCodes('&',
|
String name = ChatColor.translateAlternateColorCodes('&',
|
||||||
StringUtils.join(args, " ").substring(args[0].length() + 1));
|
StringUtils.join(args, " ").substring(args[0].length() + 1));
|
||||||
@ -48,34 +84,62 @@ public class DisguiseCommand implements CommandExecutor {
|
|||||||
} else
|
} else
|
||||||
sender.sendMessage(ChatColor.RED + "You need to provide a player name");
|
sender.sendMessage(ChatColor.RED + "You need to provide a player name");
|
||||||
} else {
|
} else {
|
||||||
DisguiseType type;
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command");
|
||||||
try {
|
}
|
||||||
type = DisguiseType.valueOf(args[0].toUpperCase());
|
|
||||||
} catch (Exception ex) {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + "Failed to find disguise: " + ChatColor.GREEN + args[0]
|
if (allowedDisguises(sender).size() == 0) {
|
||||||
+ "\n/disguise player <Name>\n/disguise <Mob Name>\n/disguise undisguise/un/undis");
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
boolean adult = true;
|
DisguiseType type;
|
||||||
|
try {
|
||||||
|
type = DisguiseType.valueOf(args[0].toUpperCase());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Failed to find disguise: " + ChatColor.GREEN + args[0]
|
||||||
|
+ "\n/disguise player <Name>\n/disguise <Mob Name>\n/disguise undisguise/un/undis");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (sender.hasPermission("libsdisguises.disguise." + type.name().toLowerCase())) {
|
||||||
|
Object args1 = true;
|
||||||
|
if (type.isMisc())
|
||||||
|
args1 = -1;
|
||||||
|
int args2 = -1;
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
if (args[1].equalsIgnoreCase("true")) {
|
if (type.isMob()) {
|
||||||
adult = false;
|
if (args[1].equalsIgnoreCase("true")) {
|
||||||
} else if (!args[1].equalsIgnoreCase("false")) {
|
args1 = false;
|
||||||
sender.sendMessage(ChatColor.RED + "Set baby: " + ChatColor.GREEN + args[1] + ChatColor.RED
|
} else if (!args[1].equalsIgnoreCase("false")) {
|
||||||
+ " - Thats not true or false..");
|
sender.sendMessage(ChatColor.RED + "Set baby: " + ChatColor.GREEN + args[1] + ChatColor.RED
|
||||||
return true;
|
+ " - Thats not true or false..");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (type.isMisc()) {
|
||||||
|
if (isNumeric(args[1])) {
|
||||||
|
args1 = Integer.parseInt(args[1]);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + args[1] + " is not a number");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length > 2)
|
||||||
|
if (isNumeric(args[2])) {
|
||||||
|
args2 = Integer.parseInt(args[2]);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.RED + args[2] + " is not a number");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Disguise disguise;
|
Disguise disguise;
|
||||||
if (type.isMob())
|
if (type.isMob())
|
||||||
disguise = new MobDisguise(type, adult);
|
disguise = new MobDisguise(type, (Boolean) args1);
|
||||||
else
|
else
|
||||||
disguise = new MiscDisguise(type);
|
disguise = new MiscDisguise(type, (Integer) args1, args2);
|
||||||
DisguiseAPI.disguiseToAll(p, disguise);
|
DisguiseAPI.disguiseToAll(p, disguise);
|
||||||
sender.sendMessage(ChatColor.RED + "Now disguised as a " + type.name().toLowerCase() + "!");
|
sender.sendMessage(ChatColor.RED + "Now disguised as a " + type.name().toLowerCase() + "!");
|
||||||
}
|
} else
|
||||||
} else
|
sender.sendMessage(ChatColor.RED + "You do not have permission to use this disguise.");
|
||||||
sender.sendMessage(ChatColor.RED + "You do not have permission");
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,10 @@ public class MiscDisguise extends Disguise {
|
|||||||
|
|
||||||
public MiscDisguise(DisguiseType disguiseType, int id, int data) {
|
public MiscDisguise(DisguiseType disguiseType, int id, int data) {
|
||||||
super(disguiseType);
|
super(disguiseType);
|
||||||
|
if (id == -1)
|
||||||
|
id = disguiseType.getDefaultId();
|
||||||
|
if (data == -1)
|
||||||
|
data = disguiseType.getDefaultData();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user