Fix command data generation for Scala
This commit is contained in:
parent
f92cc773c1
commit
83b5f1fec4
2 changed files with 16 additions and 9 deletions
|
@ -201,6 +201,13 @@ public final class IHaveConfig {
|
||||||
val ms = obj.getClass().getDeclaredMethods();
|
val ms = obj.getClass().getDeclaredMethods();
|
||||||
for (val m : ms) {
|
for (val m : ms) {
|
||||||
if (!m.getReturnType().getName().equals(ConfigData.class.getName())) continue;
|
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 {
|
try {
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
List<ConfigData<?>> configList;
|
List<ConfigData<?>> configList;
|
||||||
|
@ -213,7 +220,7 @@ public final class IHaveConfig {
|
||||||
try {
|
try {
|
||||||
return (ConfigData<?>) m.invoke(obj, kv.getValue());
|
return (ConfigData<?>) m.invoke(obj, kv.getValue());
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} 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<?>)
|
if (obj instanceof Component<?>)
|
||||||
TBMCCoreAPI.SendException(msg, e, (Component<?>) obj);
|
TBMCCoreAPI.SendException(msg, e, (Component<?>) obj);
|
||||||
else if (obj instanceof JavaPlugin)
|
else if (obj instanceof JavaPlugin)
|
||||||
|
@ -225,18 +232,18 @@ public final class IHaveConfig {
|
||||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
if (TBMCCoreAPI.IsTestServer())
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
for (val c : configList) {
|
for (val c : configList) {
|
||||||
if (c.getPath().length() == 0)
|
if (c.getPath().length() == 0)
|
||||||
c.setPath(m.getName());
|
c.setPath(mName);
|
||||||
else if (!c.getPath().equals(m.getName()))
|
else if (!c.getPath().equals(mName))
|
||||||
MainPlugin.Instance.getLogger().warning("Config name does not match: " + c.getPath() + " instead of " + m.getName());
|
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
|
c.get(); //Saves the default value if needed - also checks validity
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String msg = "Failed to pregenerate " + m.getName() + " for " + obj + "!";
|
String msg = "Failed to pregenerate " + mName + " for " + obj + "!";
|
||||||
if (obj instanceof Component<?>)
|
if (obj instanceof Component<?>)
|
||||||
TBMCCoreAPI.SendException(msg, e, (Component<?>) obj);
|
TBMCCoreAPI.SendException(msg, e, (Component<?>) obj);
|
||||||
else if (obj instanceof JavaPlugin)
|
else if (obj instanceof JavaPlugin)
|
||||||
|
|
|
@ -253,7 +253,7 @@ public abstract class Command2<TC extends ICommand2<TP>, TP extends Command2Send
|
||||||
}
|
}
|
||||||
val conv = paramConverters.get(cl);
|
val conv = paramConverters.get(cl);
|
||||||
if (conv == null)
|
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);
|
val cparam = conv.converter.apply(param);
|
||||||
if (cparam == null) {
|
if (cparam == null) {
|
||||||
sender.sendMessage(conv.errormsg); //Param conversion failed - ex. plugin not found
|
sender.sendMessage(conv.errormsg); //Param conversion failed - ex. plugin not found
|
||||||
|
@ -355,7 +355,7 @@ public abstract class Command2<TC extends ICommand2<TP>, TP extends Command2Send
|
||||||
if (ht.length > 0)
|
if (ht.length > 0)
|
||||||
ht[0] = "§6---- " + ht[0] + " ----";
|
ht[0] = "§6---- " + ht[0] + " ----";
|
||||||
YamlConfiguration yc = YamlConfiguration.loadConfiguration(new InputStreamReader(str)); //Generated by ButtonProcessor
|
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) {
|
if (ccs != null) {
|
||||||
val cs = ccs.getConfigurationSection(method.getName());
|
val cs = ccs.getConfigurationSection(method.getName());
|
||||||
if (cs != null) {
|
if (cs != null) {
|
||||||
|
@ -371,7 +371,7 @@ public abstract class Command2<TC extends ICommand2<TP>, TP extends Command2Send
|
||||||
for (int j = 0; j < paramArray.length && j < parameters.length; j++)
|
for (int j = 0; j < paramArray.length && j < parameters.length; j++)
|
||||||
parameters[j] = paramArray[j];
|
parameters[j] = paramArray[j];
|
||||||
} else
|
} 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
|
} 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.");
|
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
|
} else
|
||||||
|
|
Loading…
Reference in a new issue