Add API methods to get a parsed custom disguise

This commit is contained in:
libraryaddict 2019-04-17 08:10:15 +12:00
parent d307264211
commit 3d4ee8a020
2 changed files with 37 additions and 12 deletions

View File

@ -9,10 +9,13 @@ import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.translations.TranslateType; import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -127,6 +130,28 @@ public class DisguiseConfig {
explicitDisguisePermissions = explictDisguisePermission; explicitDisguisePermissions = explictDisguisePermission;
} }
public static Entry<DisguisePerm, Disguise> getParsedCustomDisguise(
String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException {
Entry<DisguisePerm, String> entry = getCustomDisguise(disguise);
return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(entry.getValue()));
}
public static Entry<DisguisePerm, Disguise> getParsedCustomDisguise(Entity target,
String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException {
Entry<DisguisePerm, String> entry = getCustomDisguise(disguise);
return new HashMap.SimpleEntry(entry.getKey(),
DisguiseParser.parseDisguise(Bukkit.getConsoleSender(), target, entry.getValue()));
}
public static Entry<DisguisePerm, Disguise> getParsedCustomDisguise(CommandSender invoker, Entity target,
String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException {
Entry<DisguisePerm, String> entry = getCustomDisguise(disguise);
return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(invoker, target, entry.getValue()));
}
public static Entry<DisguisePerm, String> getCustomDisguise(String disguise) { public static Entry<DisguisePerm, String> getCustomDisguise(String disguise) {
for (Entry<DisguisePerm, String> entry : customDisguises.entrySet()) { for (Entry<DisguisePerm, String> entry : customDisguises.entrySet()) {
String name = entry.getKey().toReadable(); String name = entry.getKey().toReadable();
@ -367,18 +392,6 @@ public class DisguiseConfig {
try { try {
String[] disguiseArgs = DisguiseUtilities.split(toParse); String[] disguiseArgs = DisguiseUtilities.split(toParse);
for (int i = 0; i < disguiseArgs.length; i++) {
String arg = disguiseArgs[i];
// If argument is for the command user name
if (arg.equals("%player%")) {
disguiseArgs[i] = "libraryaddict";
} else if (arg.equals("%skin%")) { // If argument is for the command user skin
disguiseArgs[i] = "{\"id\":\"a149f81bf7844f8987c554afdd4db533\",\"name\":\"libraryaddict\"," +
"\"properties\":[]}";
}
}
Disguise disguise = DisguiseParser Disguise disguise = DisguiseParser
.parseTestDisguise(Bukkit.getConsoleSender(), "disguise", disguiseArgs, .parseTestDisguise(Bukkit.getConsoleSender(), "disguise", disguiseArgs,
DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise")); DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise"));

View File

@ -8,6 +8,7 @@ import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType; import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -269,6 +270,17 @@ public class DisguiseParser {
return parseDisguise(sender, null, permNode, args, permissions); return parseDisguise(sender, null, permNode, args, permissions);
} }
public static Disguise parseDisguise(
String disguise) throws IllegalAccessException, InvocationTargetException, DisguiseParseException {
return parseDisguise(Bukkit.getConsoleSender(), null, disguise);
}
public static Disguise parseDisguise(CommandSender sender, Entity target,
String disguise) throws IllegalAccessException, InvocationTargetException, DisguiseParseException {
return parseDisguise(sender, target, "disguise", DisguiseUtilities.split(disguise),
new DisguisePermissions(Bukkit.getConsoleSender(), "disguise"));
}
/** /**
* 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 * commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this