Allow disguises to use quoted strings to allow spaces in strings
This commit is contained in:
parent
971c091962
commit
94fa3f0a1d
@ -233,7 +233,7 @@ public class DisguiseConfig {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Disguise disguise = DisguiseParser
|
Disguise disguise = DisguiseParser
|
||||||
.parseDisguise(Bukkit.getConsoleSender(), "disguise", toParse.split(" "),
|
.parseDisguise(Bukkit.getConsoleSender(), "disguise", DisguiseParser.split(toParse),
|
||||||
DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise"));
|
DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise"));
|
||||||
|
|
||||||
customDisguises.put(key, disguise);
|
customDisguises.put(key, disguise);
|
||||||
|
@ -45,7 +45,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
Disguise disguise;
|
Disguise disguise;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
disguise = DisguiseParser.parseDisguise(sender, getPermNode(), args, getPermissions(sender));
|
disguise = DisguiseParser.parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(args)), getPermissions(sender));
|
||||||
}
|
}
|
||||||
catch (DisguiseParseException ex) {
|
catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
if (ex.getMessage() != null) {
|
||||||
|
@ -46,7 +46,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
Disguise disguise;
|
Disguise disguise;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
disguise = DisguiseParser.parseDisguise(sender, getPermNode(), args, getPermissions(sender));
|
disguise = DisguiseParser.parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(args)), getPermissions(sender));
|
||||||
}
|
}
|
||||||
catch (DisguiseParseException ex) {
|
catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
if (ex.getMessage() != null) {
|
||||||
|
@ -72,7 +72,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
Disguise disguise;
|
Disguise disguise;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
disguise = DisguiseParser.parseDisguise(sender, getPermNode(), newArgs, map);
|
disguise = DisguiseParser.parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(newArgs)), map);
|
||||||
}
|
}
|
||||||
catch (DisguiseParseException ex) {
|
catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
if (ex.getMessage() != null) {
|
||||||
|
@ -130,7 +130,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
disguise = DisguiseParser.parseDisguise(sender, getPermNode(), newArgs, map);
|
disguise = DisguiseParser.parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(newArgs)), map);
|
||||||
}
|
}
|
||||||
catch (DisguiseParseException ex) {
|
catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
if (ex.getMessage() != null) {
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
package me.libraryaddict.disguise.utilities;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||||
import java.lang.reflect.Method;
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||||
import java.util.ArrayList;
|
import me.libraryaddict.disguise.DisguiseConfig;
|
||||||
import java.util.HashMap;
|
import me.libraryaddict.disguise.disguisetypes.*;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import me.libraryaddict.disguise.utilities.json.SerializerGameProfile;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.bukkit.Art;
|
import org.bukkit.Art;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -20,19 +14,11 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
import me.libraryaddict.disguise.DisguiseConfig;
|
import java.util.HashMap;
|
||||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
import java.util.Map.Entry;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
|
||||||
import sun.reflect.Reflection;
|
|
||||||
|
|
||||||
public class DisguiseParser {
|
public class DisguiseParser {
|
||||||
public static class DisguiseParseException extends Exception {
|
public static class DisguiseParseException extends Exception {
|
||||||
@ -201,8 +187,8 @@ public class DisguiseParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DisguisePerm[] getDisguisePerms() {
|
public static DisguisePerm[] getDisguisePerms() {
|
||||||
DisguisePerm[] perms = new DisguisePerm[DisguiseType.values().length + DisguiseConfig.getCustomDisguises()
|
DisguisePerm[] perms = new DisguisePerm[DisguiseType.values().length +
|
||||||
.size()];
|
DisguiseConfig.getCustomDisguises().size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||||
@ -449,13 +435,22 @@ public class DisguiseParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a string while respecting quotes
|
||||||
|
*/
|
||||||
|
public static String[] split(String string) {
|
||||||
|
return string.split(" (?=\")|(?<=\")\\s");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the disguise if it all parsed correctly. Returns a exception with a complete message if it didn't. The
|
* Returns the disguise if it all parsed correctly. Returns a exception with a complete message if it didn't. The
|
||||||
* commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this point, the
|
* commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this
|
||||||
|
* point, the
|
||||||
* disguise has been feed a proper disguisetype.
|
* disguise has been feed a proper disguisetype.
|
||||||
*/
|
*/
|
||||||
public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args,
|
public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args,
|
||||||
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException {
|
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permissionMap) throws DisguiseParseException,
|
||||||
|
IllegalAccessException, InvocationTargetException {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
DisguiseUtilities.setCommandsUsed();
|
DisguiseUtilities.setCommandsUsed();
|
||||||
}
|
}
|
||||||
@ -525,8 +520,8 @@ public class DisguiseParser {
|
|||||||
// He needs to give the player name
|
// He needs to give the player name
|
||||||
throw new DisguiseParseException(LibsMsg.PARSE_SUPPLY_PLAYER);
|
throw new DisguiseParseException(LibsMsg.PARSE_SUPPLY_PLAYER);
|
||||||
} else {
|
} else {
|
||||||
if (!disguiseOptions.isEmpty() && (!disguiseOptions
|
if (!disguiseOptions.isEmpty() && (!disguiseOptions.containsKey(args[1].toLowerCase()) ||
|
||||||
.containsKey(args[1].toLowerCase()) || !disguiseOptions.get(args[1].toLowerCase()))) {
|
!disguiseOptions.get(args[1].toLowerCase()))) {
|
||||||
throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_NAME);
|
throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,8 +535,8 @@ public class DisguiseParser {
|
|||||||
boolean adult = true;
|
boolean adult = true;
|
||||||
|
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
if (args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("baby")) || args[1]
|
if (args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("baby")) ||
|
||||||
.equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult"))) {
|
args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult"))) {
|
||||||
usedOptions.add("setbaby");
|
usedOptions.add("setbaby");
|
||||||
doCheck(sender, optionPermissions, usedOptions);
|
doCheck(sender, optionPermissions, usedOptions);
|
||||||
adult = args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult"));
|
adult = args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult"));
|
||||||
@ -571,8 +566,8 @@ public class DisguiseParser {
|
|||||||
if (isInteger(args[1])) {
|
if (isInteger(args[1])) {
|
||||||
miscId = Integer.parseInt(args[1]);
|
miscId = Integer.parseInt(args[1]);
|
||||||
} else {
|
} else {
|
||||||
if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK || disguisePerm
|
if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK ||
|
||||||
.getType() == DisguiseType.DROPPED_ITEM) {
|
disguisePerm.getType() == DisguiseType.DROPPED_ITEM) {
|
||||||
for (Material mat : Material.values()) {
|
for (Material mat : Material.values()) {
|
||||||
if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) {
|
if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) {
|
||||||
miscId = mat.getId();
|
miscId = mat.getId();
|
||||||
@ -606,8 +601,8 @@ public class DisguiseParser {
|
|||||||
toSkip++;
|
toSkip++;
|
||||||
}
|
}
|
||||||
if (secondArg != null) {
|
if (secondArg != null) {
|
||||||
if (disguisePerm.getType() != DisguiseType.FALLING_BLOCK && disguisePerm
|
if (disguisePerm.getType() != DisguiseType.FALLING_BLOCK &&
|
||||||
.getType() != DisguiseType.DROPPED_ITEM) {
|
disguisePerm.getType() != DisguiseType.DROPPED_ITEM) {
|
||||||
throw new DisguiseParseException(LibsMsg.PARSE_USE_SECOND_NUM,
|
throw new DisguiseParseException(LibsMsg.PARSE_USE_SECOND_NUM,
|
||||||
DisguiseType.FALLING_BLOCK.toReadable(),
|
DisguiseType.FALLING_BLOCK.toReadable(),
|
||||||
DisguiseType.DROPPED_ITEM.toReadable());
|
DisguiseType.DROPPED_ITEM.toReadable());
|
||||||
@ -667,7 +662,8 @@ public class DisguiseParser {
|
|||||||
|
|
||||||
public static void callMethods(CommandSender sender, Disguise disguise,
|
public static void callMethods(CommandSender sender, Disguise disguise,
|
||||||
HashMap<ArrayList<String>, Boolean> optionPermissions, ArrayList<String> usedOptions,
|
HashMap<ArrayList<String>, Boolean> optionPermissions, ArrayList<String> usedOptions,
|
||||||
String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, DisguiseParseException {
|
String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException,
|
||||||
|
DisguiseParseException {
|
||||||
Method[] methods = ReflectionFlagWatchers.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
|
Method[] methods = ReflectionFlagWatchers.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
|
||||||
|
|
||||||
for (int i = 0; i < args.length; i += 2) {
|
for (int i = 0; i < args.length; i += 2) {
|
||||||
@ -977,13 +973,13 @@ public class DisguiseParser {
|
|||||||
boolean myPerms = true;
|
boolean myPerms = true;
|
||||||
|
|
||||||
for (String option : usedOptions) {
|
for (String option : usedOptions) {
|
||||||
if (!sender.getName().equals("CONSOLE") && option.equalsIgnoreCase("setInvisible") && DisguiseConfig
|
if (!sender.getName().equals("CONSOLE") && option.equalsIgnoreCase("setInvisible") &&
|
||||||
.isDisabledInvisibility()) {
|
DisguiseConfig.isDisabledInvisibility()) {
|
||||||
myPerms = false;
|
myPerms = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(theirPermissions.get(list) && list.contains("*")) && (list.contains(option) != theirPermissions
|
if (!(theirPermissions.get(list) && list.contains("*")) &&
|
||||||
.get(list))) {
|
(list.contains(option) != theirPermissions.get(list))) {
|
||||||
myPerms = false;
|
myPerms = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user