Add meta index info to libsdisguises command

This commit is contained in:
libraryaddict 2020-01-17 16:55:05 +13:00
parent e7dd114705
commit caf5587ccb
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
4 changed files with 92 additions and 18 deletions

View File

@ -49,7 +49,7 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.5.1-SNAPSHOT</version>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>

View File

@ -2,8 +2,12 @@ package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -76,16 +80,61 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!");
}
} else if (args.length > 0) {
if (sender.hasPermission("libsdisguises.reload")) {
if (args[0].equalsIgnoreCase("reload")) {
DisguiseConfig.loadConfig();
sender.sendMessage(LibsMsg.RELOADED_CONFIG.get());
if (args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("libsdisguises.reload")) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
DisguiseConfig.loadConfig();
sender.sendMessage(LibsMsg.RELOADED_CONFIG.get());
return true;
} else if (args[0].equalsIgnoreCase("metainfo") || args[0].equalsIgnoreCase("meta")) {
if (!sender.hasPermission("libsdisguises.metainfo")) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length > 1) {
MetaIndex index = MetaIndex.getMetaIndexByName(args[1]);
if (index == null) {
sender.sendMessage(LibsMsg.META_NOT_FOUND.get());
return true;
}
sender.sendMessage(index.toString());
} else {
sender.sendMessage(LibsMsg.LIBS_RELOAD_WRONG.get());
ArrayList<String> names = new ArrayList<>();
for (MetaIndex index : MetaIndex.values()) {
names.add(MetaIndex.getName(index));
}
names.sort(String::compareToIgnoreCase);
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(LibsMsg.META_VALUES.get());
Iterator<String> itel = names.iterator();
while (itel.hasNext()) {
String name = itel.next();
builder.appendLegacy(name);
builder.event(
new ClickEvent(ClickEvent.Action.RUN_COMMAND, cmd.getName() + " metainfo " + name));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder("").appendLegacy(LibsMsg.META_CLICK_SHOW.get(name)).create()));
if (itel.hasNext()) {
builder.appendLegacy(LibsMsg.META_VALUE_SEPERATOR.get());
}
}
sender.spigot().sendMessage(builder.create());
}
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
sender.sendMessage(LibsMsg.LIBS_COMMAND_WRONG_ARG.get());
}
}
return true;

View File

@ -7,7 +7,7 @@ import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.comphenix.protocol.wrappers.nbt.NbtType;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Particle;
@ -596,7 +596,6 @@ public class MetaIndex<Y> {
* All flag types should never occur twice.
*/
public static void validateMetadata() {
HashMap<Class, Integer> maxValues = new HashMap<>();
for (MetaIndex type : values()) {
@ -639,10 +638,14 @@ public class MetaIndex<Y> {
}
}
public String toString() {
return LibsMsg.META_INFO.get(getName(this), getFlagWatcher().getSimpleName(), getIndex(),
getDefault().getClass().getSimpleName(), DisguiseUtilities.getGson().toJson(getDefault()));
}
/**
* Used for debugging purposes, prints off the registered MetaIndexes
*/
@Deprecated
public static void printMetadata() {
ArrayList<String> toPrint = new ArrayList<>();
@ -653,9 +656,7 @@ public class MetaIndex<Y> {
MetaIndex index = (MetaIndex) field.get(null);
toPrint.add(
index.getFlagWatcher().getSimpleName() + " " + field.getName() + " " + index.getIndex() + " " +
index.getDefault().getClass().getSimpleName());
toPrint.add(index.toString());
}
}
catch (Exception ex) {
@ -742,10 +743,28 @@ public class MetaIndex<Y> {
return _values;
}
public static MetaIndex getMetaIndexByName(String name) {
name = name.toUpperCase();
try {
for (Field field : MetaIndex.class.getFields()) {
if (!field.getName().equals(name) || field.getType() != MetaIndex.class) {
continue;
}
return (MetaIndex) field.get(null);
}
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
/**
* Get the field name of a registered MetaIndex
*/
@Deprecated
public static String getName(MetaIndex metaIndex) {
try {
for (Field field : MetaIndex.class.getFields()) {

View File

@ -113,7 +113,7 @@ public enum LibsMsg {
PLEASE_WAIT(ChatColor.GRAY + "Please wait..."),
INVALID_CLONE(ChatColor.DARK_RED + "Unknown option '%s' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' " +
"'DoSneak' 'DoSprint'"),
LIBS_RELOAD_WRONG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?"),
LIBS_COMMAND_WRONG_ARG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload' or 'metainfo'?"),
LIMITED_RADIUS(ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"),
LISTEN_ENTITY_ENTITY_DISG_ENTITY(ChatColor.RED + "Disguised %s as a %s!"),
LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise %s as a %s!"),
@ -220,7 +220,8 @@ public enum LibsMsg {
"Means '/savedisguise Notch player Notch setsneaking'"),
SAVE_DISG_HELP_5(ChatColor.GREEN + "Remember! You can upload your own skins, then reference those skins!"),
GRAB_DISG_HELP_1(ChatColor.GREEN +
"You can choose a name to save the skins under, the names will be usable as if it was an actual player skin"),
"You can choose a name to save the skins under, the names will be usable as if it was an actual player " +
"skin"),
GRAB_DISG_HELP_2(ChatColor.DARK_GREEN + "/grabskin https://somesite.com/myskin.png <Optional Name>"),
GRAB_DISG_HELP_3(ChatColor.DARK_GREEN + "/grabskin myskin.png <Optional Name> - Skins must be in the folder!"),
GRAB_DISG_HELP_4(ChatColor.DARK_GREEN + "/grabskin <Player name or UUID> <Optional Name>"),
@ -229,7 +230,12 @@ public enum LibsMsg {
CUSTOM_DISGUISE_NAME_CONFLICT(
ChatColor.RED + "Cannot create the custom disguise '%s' as there is a name conflict!"),
ERROR_LOADING_CUSTOM_DISGUISE(ChatColor.RED + "Error while loading custom disguise '%s'%s"),
SKIN_API_INTERNAL_ERROR(ChatColor.RED + "Internal error in the skin API, perhaps bad data?");
SKIN_API_INTERNAL_ERROR(ChatColor.RED + "Internal error in the skin API, perhaps bad data?"),
META_INFO(ChatColor.GREEN + "Name: %s, Watcher: %s, Index: %s, Type: %s, Default: %s"),
META_NOT_FOUND(ChatColor.RED + "No meta exists under that name!"),
META_VALUES(ChatColor.BLUE + "Metas: " + ChatColor.DARK_AQUA),
META_VALUE_SEPERATOR(ChatColor.AQUA + ", " + ChatColor.DARK_AQUA),
META_CLICK_SHOW(ChatColor.GOLD + "Click to show %s");
private String string;