Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PermissionsEx Chat Handling #521

Open
Andrew2070 opened this issue May 22, 2018 · 13 comments
Open

PermissionsEx Chat Handling #521

Andrew2070 opened this issue May 22, 2018 · 13 comments

Comments

@Andrew2070
Copy link

Andrew2070 commented May 22, 2018

Hi again,

I created a class called ChatHandler which overrides the ChatManager class.

It basically does this:
[CitizenRank][EmpireName] Username: message
example: [L][Rome] Player123: Hello World

I want it to do this:
[PexPrefix][CitizenRank][EmpireName][PexSuffix] Username: message
example: [Admin][L][Rome] Username: message
**No suffix in this example ^

Was wondering if you could help me set this up, because i get this error:

Caused by: java.lang.ClassNotFoundException: ru.tehkode.permissions.bukkit.PermissionsEx
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:101) ~[launchwrapper-1.12.jar:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_73]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_73]

So i modified the class to include:

	empire = CommandsEMP.getEmpireFromCitizen(res);
					rank = CommandsEMP.getRankFromCitizen(res);
					// TODO: Add herochat support?

					String rankChat = "[" + rank.getChatName() + "]";
					String empireChat = "[" + empire + "]";
					if (ClassUtils.isBukkitLoaded() == true) {

					if (Bukkit.getPluginManager().getPlugin("PermissionsEx").isEnabled() == true) {	
						Empires.instance.LOG.warn("[Empires Mod] PermissiosnEX detected.. Applying hooks");
						//get pex prefix below					
					Player bukkitplayer = Bukkit.getPlayer(target.getUniqueID());
					String pexPrefix = ChatComponentPEX.getPrefix(bukkitplayer);
					String pexSuffix = ChatComponentPEX.getSuffix(bukkitplayer);

					
					
					
					
					Method method = ChatComponentPEX.class.getDeclaredMethod("getPrefix", Player.class);
					String chat = pexPrefix + EnumChatFormatting.RED + rankChat + EnumChatFormatting.GOLD + empireChat + " "
								+ EnumChatFormatting.WHITE + player.getDisplayName() + pexSuffix + ": " + event.message;
						//add pex prefix here ^

						target.addChatMessage(new ChatComponentTranslation(chat));
					}
@Andrew2070
Copy link
Author

Andrew2070 commented May 22, 2018

ChatHandler:

Not sure if have to use reflection here... if so i don't know how to do that properly.

@jgoett154
Copy link
Member

jgoett154 commented May 22, 2018 via email

@Andrew2070
Copy link
Author

Yeah.
Bukkit plugins are on another classpath.
Forge mods are on another classpath.

The error comes from calling the PermissionsEx.user().getPrefix()/getSuffix().
This happens while the server is running (with PEX installed), and as soon as i send a chat.

I set up the deploader to download PEX and the gradle script to compile it.

I built a fresh build with ./gradlew clean build -i

I'm pretty sure this is going to require reflection, but my reflection code hasn't fixed it.

@Andrew2070
Copy link
Author

Andrew2070 commented May 22, 2018

I got the reflection part nailed:
Now i get a different error, when I chat, and the chat message doesn't get printed.

[00:40:57 INFO]: [Empires Mod] PermissionsEX detected.. Applying hooks
[00:40:57 WARN]: java.lang.IllegalArgumentException: argument type mismatch
[00:40:57 WARN]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[00:40:57 WARN]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[00:40:57 WARN]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[00:40:57 WARN]: 	at java.lang.reflect.Method.invoke(Method.java:497)
[00:40:57 WARN]: 	at EmpiresMod.Handlers.ChatHandler.onServerChatReceivedEvent(ChatHandler.java:68)
[00:40:57 WARN]: 	at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_ChatHandler_onServerChatReceivedEvent_ServerChatEvent.invoke(.dynamic)
[00:40:57 WARN]: 	at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
[00:40:57 WARN]: 	at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140)
[00:40:57 WARN]: 	at net.minecraftforge.common.ForgeHooks.onServerChatEvent(ForgeHooks.java:394)

@jgoett154
Copy link
Member

For the invoke calls, replace instance with null and Player.class with the actual Player instance. Doing that should fix the IllegalArgumentException.

@Andrew2070
Copy link
Author

Andrew2070 commented May 24, 2018

Yeah that fixed IllegalArgumentException but caused:
btw, do you have a discord?

13:22:11 WARN]: java.lang.reflect.InvocationTargetException
[13:22:11 WARN]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[13:22:11 WARN]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[13:22:11 WARN]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[13:22:11 WARN]: 	at java.lang.reflect.Method.invoke(Method.java:497)

[13:22:11 WARN]: 	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
[13:22:11 WARN]: 	at java.lang.Thread.run(Thread.java:745)
[13:22:11 WARN]: Caused by: java.lang.NoClassDefFoundError: ru/tehkode/permissions/bukkit/PermissionsEx
[13:22:11 WARN]: 	at EmpiresMod.API.Chat.ChatComponentPEX.getPrefix(ChatComponentPEX.java:19)
[13:22:11 WARN]: 	... 39 more
[13:22:11 WARN]: Caused by: java.lang.ClassNotFoundException: ru.tehkode.permissions.bukkit.PermissionsEx
[13:22:11 WARN]: 	at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:101)
[13:22:11 WARN]: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[13:22:11 WARN]: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[13:22:11 WARN]: 	... 40 more
[13:22:15 INFO]: [Empires Mod] PermissionsEX detected.. Applying hooks
[13:22:15 WARN]: java.lang.reflect.InvocationTargetException
[13:22:15 WARN]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[13:22:15 WARN]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[13:22:15 WARN]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[13:22:15 WARN]: 	at java.lang.reflect.Method.invoke(Method.java:497)
[13:22:15 WARN]: 	at EmpiresMod.Handlers.ChatHandler.onServerChatReceivedEvent(ChatHandler.java:79)
[13:22:15 WARN]: 	at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_ChatHandler_onServerChatReceivedEvent_ServerChatEvent.invoke(.dynamic)
[13:22:15 WARN]: 	at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

@jgoett154
Copy link
Member

jgoett154 commented May 24, 2018 via email

@Andrew2070
Copy link
Author

Hmm.
Well by making a plugin you still have to solve the classpath problem but from another perspective.

I think you added a modified bukkit.jar to the dependencies to fix the problem because i can't find any reflection in the MT2 src.

I'm at a loss here, don't know what to do.

@jgoett154
Copy link
Member

jgoett154 commented May 25, 2018 via email

@jgoett154
Copy link
Member

jgoett154 commented May 25, 2018 via email

@jgoett154
Copy link
Member

jgoett154 commented May 25, 2018 via email

@Andrew2070
Copy link
Author

Ahahahaha, Yeah the modified bukkit jar is a splendid way to go about it. :P

The code is already setup to work with PermissionsEx, although i can't find explicit references to it's API.

However, i can't seem to use reflection to import its methods.

I tried to go another route, and create two chat handler classes, one for forge and the other for bukkit, where the latter gets triggered if it's installation is detected.

For some reason, i can't import methods from bukkitchathandler.instance into forgechathandler.instance.

So the crude, manual way of doing this doesn't work either.

Guess i'll have to go the reflection route, and if you have time it would be easier to work together.

@Andrew2070
Copy link
Author

Is this information fine for the deps.info file?

    {
    	"repo": "http://pex-repo.aoeu.xyz/ru/tehkode/PermissionsEx/1.22.7/PermissionsEx-1.22.7.jar"
    	"file": "PermissionsEx-1.22.7.jar"
    	"class": "ru.tehkode.permissions.bukkit.PermissionsEx"


    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants