Add a way to try debug stuff

This commit is contained in:
libraryaddict 2024-07-21 11:40:28 +12:00
parent 6349560fc8
commit cafbc40426
4 changed files with 59 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import me.libraryaddict.disguise.commands.libsdisguises.LDCount;
import me.libraryaddict.disguise.commands.libsdisguises.LDDebugDisguiseLoop;
import me.libraryaddict.disguise.commands.libsdisguises.LDDebugMineSkin;
import me.libraryaddict.disguise.commands.libsdisguises.LDDebugPlayer;
import me.libraryaddict.disguise.commands.libsdisguises.LDDebugging;
import me.libraryaddict.disguise.commands.libsdisguises.LDHelp;
import me.libraryaddict.disguise.commands.libsdisguises.LDJson;
import me.libraryaddict.disguise.commands.libsdisguises.LDMetaInfo;
@ -55,6 +56,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
getCommands().add(new LDDebugMineSkin());
getCommands().add(new LDDebugDisguiseLoop());
getCommands().add(new LDMissingDescription());
getCommands().add(new LDDebugging());
}
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {

View File

@ -0,0 +1,45 @@
package me.libraryaddict.disguise.commands.libsdisguises;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.Collections;
import java.util.List;
public class LDDebugging implements LDCommand {
@Override
public List<String> getTabComplete() {
return Collections.singletonList("debugging");
}
@Override
public boolean hasPermission(CommandSender sender) {
return sender.isOp();
}
@Override
public String getPermission() {
return "libsdisguises.disguise";
}
@Override
public boolean isEnabled() {
return !LibsDisguises.getInstance().isReleaseBuild();
}
@Override
public void onCommand(CommandSender sender, String[] args) {
DisguiseUtilities.setDebuggingMode(!DisguiseUtilities.isDebuggingMode());
sender.sendMessage(ChatColor.DARK_AQUA + "Libs Disguises Debugging: " +
(DisguiseUtilities.isDebuggingMode() ? ChatColor.GREEN + "Enabled" : ChatColor.RED + "Disabled"));
}
@Override
public LibsMsg getHelp() {
return LibsMsg.LD_DEBUG_MINESKIN;
}
}

View File

@ -315,6 +315,9 @@ public class DisguiseUtilities {
io.github.retrooper.packetevents.adventure.serializer.gson.GsonComponentSerializer.gson();
@Getter
private static NamespacedKey selfDisguiseScaleNamespace;
@Getter
@Setter
private static boolean debuggingMode;
static {
try {
@ -1637,6 +1640,7 @@ public class DisguiseUtilities {
fancyHiddenTabs = NmsVersion.v1_19_R2.isSupported() && Bukkit.getPluginManager().getPlugin("ViaBackwards") == null;
savedDisguisesKey = new NamespacedKey(LibsDisguises.getInstance(), "SavedDisguises");
selfDisguiseScaleNamespace = new NamespacedKey(LibsDisguises.getInstance(), "Self_Disguise_Scaling");
debuggingMode = LibsDisguises.getInstance().isDebuggingBuild();
recreateGsonSerializer();

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.utilities.params.types.custom;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.reflection.ItemStackSerializer;
@ -63,7 +64,6 @@ public class ParamInfoItemStack<I extends ItemStack> extends ParamInfoEnum<Objec
return StringUtils.join(ItemStackSerializer.serialize(item), "-");
}
protected static ItemStack parseToItemstack(String string) {
if (string.isEmpty()) {
return null;
@ -122,7 +122,14 @@ public class ParamInfoItemStack<I extends ItemStack> extends ParamInfoEnum<Objec
}
if (s.contains("{") || s.contains("[")) {
ItemStack clone = itemStack.clone();
Bukkit.getUnsafe().modifyItemStack(itemStack, s);
if (DisguiseUtilities.isDebuggingMode() && itemStack.equals(clone)) {
LibsDisguises.getInstance().getLogger().info(
"Potential error when trying to modify an item via Bukkit Unsafe. Item Type: " + clone.getType() + ", Data: '" + s +
"'");
}
}
return itemStack;