From 83b5f1fec42183e859ad97a6808829b23dfdefc9 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 26 Aug 2021 01:59:18 +0200 Subject: [PATCH] Fix command data generation for Scala --- .../lib/architecture/IHaveConfig.java | 19 +++++++++++++------ .../java/buttondevteam/lib/chat/Command2.java | 6 +++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Chroma-Core/src/main/java/buttondevteam/lib/architecture/IHaveConfig.java b/Chroma-Core/src/main/java/buttondevteam/lib/architecture/IHaveConfig.java index 129ec53..6904000 100644 --- a/Chroma-Core/src/main/java/buttondevteam/lib/architecture/IHaveConfig.java +++ b/Chroma-Core/src/main/java/buttondevteam/lib/architecture/IHaveConfig.java @@ -201,6 +201,13 @@ public final class IHaveConfig { val ms = obj.getClass().getDeclaredMethods(); for (val m : ms) { if (!m.getReturnType().getName().equals(ConfigData.class.getName())) continue; + final String mName; + { + var name = m.getName(); + var ind = name.lastIndexOf('$'); + if (ind == -1) mName = name; + else mName = name.substring(ind + 1); + } try { m.setAccessible(true); List> configList; @@ -213,7 +220,7 @@ public final class IHaveConfig { try { return (ConfigData) m.invoke(obj, kv.getValue()); } catch (IllegalAccessException | InvocationTargetException e) { - String msg = "Failed to pregenerate " + m.getName() + " for " + obj + " using config " + kv.getKey() + "!"; + String msg = "Failed to pregenerate " + mName + " for " + obj + " using config " + kv.getKey() + "!"; if (obj instanceof Component) TBMCCoreAPI.SendException(msg, e, (Component) obj); else if (obj instanceof JavaPlugin) @@ -225,18 +232,18 @@ public final class IHaveConfig { }).filter(Objects::nonNull).collect(Collectors.toList()); } else { if (TBMCCoreAPI.IsTestServer()) - MainPlugin.Instance.getLogger().warning("Method " + m.getName() + " returns a config but its parameters are unknown: " + Arrays.toString(m.getParameterTypes())); + MainPlugin.Instance.getLogger().warning("Method " + mName + " returns a config but its parameters are unknown: " + Arrays.toString(m.getParameterTypes())); continue; } for (val c : configList) { if (c.getPath().length() == 0) - c.setPath(m.getName()); - else if (!c.getPath().equals(m.getName())) - MainPlugin.Instance.getLogger().warning("Config name does not match: " + c.getPath() + " instead of " + m.getName()); + c.setPath(mName); + else if (!c.getPath().equals(mName)) + MainPlugin.Instance.getLogger().warning("Config name does not match: " + c.getPath() + " instead of " + mName); c.get(); //Saves the default value if needed - also checks validity } } catch (Exception e) { - String msg = "Failed to pregenerate " + m.getName() + " for " + obj + "!"; + String msg = "Failed to pregenerate " + mName + " for " + obj + "!"; if (obj instanceof Component) TBMCCoreAPI.SendException(msg, e, (Component) obj); else if (obj instanceof JavaPlugin) diff --git a/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java b/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java index 1ed14fd..51d9eb3 100644 --- a/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java +++ b/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java @@ -253,7 +253,7 @@ public abstract class Command2, TP extends Command2Send } val conv = paramConverters.get(cl); if (conv == null) - throw new Exception("No suitable converter found for parameter type '" + cl.getCanonicalName() + "' for command '" + sd.method.toString() + "'"); + throw new Exception("No suitable converter found for parameter type '" + cl.getCanonicalName() + "' for command '" + sd.method + "'"); val cparam = conv.converter.apply(param); if (cparam == null) { sender.sendMessage(conv.errormsg); //Param conversion failed - ex. plugin not found @@ -355,7 +355,7 @@ public abstract class Command2, TP extends Command2Send if (ht.length > 0) ht[0] = "ยง6---- " + ht[0] + " ----"; YamlConfiguration yc = YamlConfiguration.loadConfiguration(new InputStreamReader(str)); //Generated by ButtonProcessor - val ccs = yc.getConfigurationSection(method.getDeclaringClass().getCanonicalName()); + val ccs = yc.getConfigurationSection(method.getDeclaringClass().getCanonicalName().replace('$', '.')); if (ccs != null) { val cs = ccs.getConfigurationSection(method.getName()); if (cs != null) { @@ -371,7 +371,7 @@ public abstract class Command2, TP extends Command2Send for (int j = 0; j < paramArray.length && j < parameters.length; j++) parameters[j] = paramArray[j]; } else - TBMCCoreAPI.SendException("Error while getting command data for " + method + "!", new Exception("Method '" + method.toString() + "' != " + mname + " or params is " + params), MainPlugin.Instance); + TBMCCoreAPI.SendException("Error while getting command data for " + method + "!", new Exception("Method '" + method + "' != " + mname + " or params is " + params), MainPlugin.Instance); } else MainPlugin.Instance.getLogger().warning("Failed to get command data for " + method + " (cs is null)! Make sure to use 'clean install' when building the project."); } else