Determine plugin from stacktrace since its more reliable
This commit is contained in:
parent
6c5c298195
commit
a82b90ce7d
1 changed files with 24 additions and 8 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
package net.frankheijden.serverutils.velocity.reflection;
|
package net.frankheijden.serverutils.velocity.reflection;
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.velocitypowered.api.command.Command;
|
|
||||||
import com.velocitypowered.api.command.CommandManager;
|
import com.velocitypowered.api.command.CommandManager;
|
||||||
import com.velocitypowered.api.command.CommandMeta;
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
|
@ -16,6 +15,7 @@ import java.lang.reflect.Proxy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
import net.frankheijden.serverutils.velocity.ServerUtils;
|
||||||
import net.frankheijden.serverutils.velocity.utils.ReflectionUtils;
|
import net.frankheijden.serverutils.velocity.utils.ReflectionUtils;
|
||||||
|
|
||||||
public class RVelocityCommandManager {
|
public class RVelocityCommandManager {
|
||||||
|
|
@ -90,20 +90,36 @@ public class RVelocityCommandManager {
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
Object obj = method.invoke(commandRegistrar, args);
|
Object obj = method.invoke(commandRegistrar, args);
|
||||||
if (method.getName().equals("register")) {
|
if (method.getName().equals("register")) {
|
||||||
handleRegisterMethod((CommandMeta) args[0], (Command) args[1]);
|
handleRegisterMethod((CommandMeta) args[0]);
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRegisterMethod(CommandMeta commandMeta, Command command) {
|
private void handleRegisterMethod(CommandMeta commandMeta) {
|
||||||
ClassLoader classLoader = command.getClass().getClassLoader();
|
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
|
||||||
|
|
||||||
|
// Skip the first four elements, which is our overhead here
|
||||||
|
for (int i = 4; i < elements.length; i++) {
|
||||||
|
Class<?> clazz;
|
||||||
|
try {
|
||||||
|
clazz = Class.forName(elements[i].getClassName());
|
||||||
|
} catch (ClassNotFoundException ex) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassLoader classLoader = clazz.getClassLoader();
|
||||||
for (PluginContainer container : proxy.getPluginManager().getPlugins()) {
|
for (PluginContainer container : proxy.getPluginManager().getPlugins()) {
|
||||||
if (container.getInstance().filter(i -> i.getClass().getClassLoader() == classLoader).isPresent()) {
|
if (container.getInstance().filter(o -> o.getClass().getClassLoader() == classLoader).isPresent()) {
|
||||||
registrationConsumer.accept(container, commandMeta);
|
registrationConsumer.accept(container, commandMeta);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerUtils.getInstance().getLogger().warn(
|
||||||
|
"Couldn't find the registering plugin for the following aliases: {}",
|
||||||
|
commandMeta.getAliases()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue