Can't make most of listeners to work on SpongeForge

I have a very simple code for testing purpose inside the Plugin instance class

    @Listener
    public void test(ClientConnectionEvent.Join e, @First Player player) {
        getLogger().info(String.valueOf(player));
    }

Some of them are working well such as GameAboutToStartServerEvent

    @Listener
    public void onInitialize(GameAboutToStartServerEvent e) {
/*        CommandSpec cs = CommandSpec.builder()
                .permission("triggerreactor.admin")
                .arguments(GenericArguments.remainingJoinedStrings(Text.of("arguments")))
                .executor(new CommandExecutor() {

                    @Override
                    public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
                        if (src instanceof Player) {
                            onCommand(new SpongePlayer((Player) src), "triggerreactor",
                                    args.<String>getOne("arguments").get().split(" "));
                        } else {
                            onCommand(new SpongeCommandSender(src), "triggerreactor",
                                    args.<String>getOne("arguments").get().split(" "));
                        }

                        return CommandResult.success();
                    }

                }).build();
        Sponge.getCommandManager().register(this, cs, "trg", "trigger");*/

        Sponge.getCommandManager().register(this, new CommandCallable() {

            @Override
            public CommandResult process(CommandSource src, String args) throws CommandException {
                if (src instanceof Player) {
                    onCommand(new SpongePlayer((Player) src), "triggerreactor",
                            args.split(" "));
                } else {
                    onCommand(new SpongeCommandSender(src), "triggerreactor",
                            args.split(" "));
                }

                return CommandResult.success();
            }

            @Override
            public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition)
                    throws CommandException {
                return new ArrayList<>();
            }

            @Override
            public boolean testPermission(CommandSource source) {
                return source.hasPermission("triggerreactor.admin");
            }

            @Override
            public Optional<Text> getShortDescription(CommandSource source) {
                return Optional.of(Text.of("TriggerReactor"));
            }

            @Override
            public Optional<Text> getHelp(CommandSource source) {
                return Optional.of(Text.of("/trg for details"));
            }

            @Override
            public Text getUsage(CommandSource source) {
                return Text.of("/trg for details");
            }

        }, "trg", "trigger");
    }

This code works well.

And the code is placed right below the Listener for ClientConnectionEvent.Join, so if I didnā€™t do anything wrong here, it should be called when a player join the server.

But even if I join server several times, the event doesnā€™t seem to fire at all. I donā€™t see any message related to the player. Even if player was null (which is not likely happen), it should print null at least.

It happens for events like InteractBlockEvent etc. too.

This is extremely frustrating as Iā€™m porting this plugin, and it might be worth nothing if I canā€™t hook events properly.

Any idea from anyone?

Thank you


Ā§rĀ§7 MinecraftĀ§rĀ§7: Ā§r1.12.2Ā§r
Ā§rĀ§7 SpongeAPIĀ§rĀ§7: Ā§r7.1.0-SNAPSHOT-d453c3eĀ§r
Ā§rĀ§7 SpongeForgeĀ§rĀ§7: Ā§r1.12.2-2705-7.1.0-BETA-3206Ā§r
Ā§rĀ§7 Minecraft ForgeĀ§rĀ§7: Ā§r14.23.4.2705Ā§r

Can you re-test on the latest (not reccomended) build from SpongeDownloads ?

Hi, thank you for the quick reply!

Do you mean 1.12.2-2705-7.1.0-BETA-3206?

Just to make sure

Thank you

Try the first build under ā€˜All buildsā€™ - 1.12.2-2705-7.1.0-BETA-3307

Still doesnā€™t work

[21:36:08] [Server thread/INFO] [net.minecraft.server.dedicated.DedicatedServer]: Done (3.600s)! For help, type ā€œhelpā€ or ā€œ?ā€
[21:36:14] [Netty Server IO #1/INFO] [FML]: Client protocol version 2
[21:36:14] [Netty Server IO #1/INFO] [FML]: Client attempting to join with 5 mods : [email protected],[email protected],[email protected],[email protected],[email protected]
[21:36:14] [Netty Server IO #1/INFO] [FML]: Attempting connection with missing mods [spongeapi, sponge, triggerreactor] at CLIENT
[21:36:14] [Server thread/INFO] [FML]: [Server thread] Server side modded connection established
[21:36:14] [Server thread/INFO] [net.minecraft.server.management.PlayerList]: test[/127.0.0.1:8293] logged in with entity id 356 in world(0) at (177.00014559217166, 79.0, 267.6992568374489)
[21:36:15] [Server thread/INFO] [net.minecraft.server.dedicated.DedicatedServer]: Ā§etestĀ§rĀ§e joined the gameĀ§r
[21:36:23] [Server thread/INFO] [net.minecraft.network.NetHandlerPlayServer]: test lost connection: Disconnected
[21:36:23] [Server thread/INFO] [net.minecraft.server.dedicated.DedicatedServer]: Ā§etestĀ§rĀ§e left the gameĀ§r
[21:36:54] [Netty Server IO #3/INFO] [FML]: Client protocol version 2
[21:36:54] [Netty Server IO #3/INFO] [FML]: Client attempting to join with 5 mods : [email protected],[email protected],[email protected],[email protected],[email protected]
[21:36:54] [Netty Server IO #3/INFO] [FML]: Attempting connection with missing mods [spongeapi, sponge, triggerreactor] at CLIENT
[21:36:54] [Server thread/INFO] [FML]: [Server thread] Server side modded connection established
[21:36:54] [Server thread/INFO] [net.minecraft.server.management.PlayerList]: test[/127.0.0.1:8306] logged in with entity id 357 in world(0) at (177.00014559217166, 79.0, 267.6992568374489)
[21:36:54] [Server thread/INFO] [net.minecraft.server.dedicated.DedicatedServer]: Ā§etestĀ§rĀ§e joined the gameĀ§r
[21:37:21] [Server thread/INFO] [net.minecraft.server.dedicated.DedicatedServer]: Ā§eĀ§lSpongeForgeĀ§r
Ā§rĀ§7 MinecraftĀ§rĀ§7: Ā§r1.12.2Ā§r
Ā§rĀ§7 SpongeAPIĀ§rĀ§7: Ā§r7.1.0-SNAPSHOT-a1418aeĀ§r
Ā§rĀ§7 SpongeForgeĀ§rĀ§7: Ā§r1.12.2-2705-7.1.0-BETA-3307Ā§r
Ā§rĀ§7 Minecraft ForgeĀ§rĀ§7: Ā§r14.23.4.2705Ā§r

I just tested locally, and couldnā€™t reproduce the issue. Can you confirm that the listener is actually being hit (via a breakpoint, throwing an exception, etc)? I suspect that the issue actually lies with the getLogger().info call

image

Iā€™m debugging with server, and it doesnā€™t fire the method at all.

Which is strange as onInitialize() is working well. Otherwise, I couldnā€™t use /trg command

Just for additional info, my main class extends another class

@Plugin(id = TriggerReactor.ID, version = TriggerReactor.VERSION)
public class TriggerReactor extends 
io.github.wysohn.triggerreactor.core.main.TriggerReactor{
    protected static final String ID = "triggerreactor";
    protected static final String VERSION = "2.0.0";

Can you upload your debug.log to pastebin or http://paste.feed-the-beast.com/ ?

https://paste.feed-the-beast.com/view/4b93635b

Thank you :slight_smile:

I think I will head off to bed

I appreciate all the efforts.

Iā€™ve compiled it again just to make sure everything is up-to-date, restarted server with the newly created jar, and the problem is still persisting.

Let me know if you find anything

And thanks to all of the sponge developers! The API is just gorgeous to work with compared to Bukkit

1 Like

This is quite odd - when I ran your plugin, your test() listener executed for me when I joined.

If youā€™re running your plugin from your IDE, are you certain that the proper version of it is being used? The only thing I can think of is that an old version of your plugin jar is somehow getting put on the classpath in place of the actual module in your IDE

Which means something is not quite the same

Even if the break point is off line because of IDE, the console output should be shown at least.

Weird thing is that if I put getLogger().info(ā€œtestā€) in the GameAboutToStartServerEvent handling method, it works somehow.

To make things more clear, I registered anonymous EventListener which handles ClientConnectionEvent.Join, it doesnā€™t work too.

@Listener
public void onInitialize(GameAboutToStartServerEvent e) {
    Sponge.getEventManager().registerListener(this, ClientConnectionEvent.Join.class, new EventListener<ClientConnectionEvent.Join>(){

        @Override
        public void handle(Join event) throws Exception {
            getLogger().info(String.valueOf(event.getCause().first(Player.class).orElseGet(null)));
        }

    });

... blah blah

What am I missing?

If it didnā€™t work for both GameAboutToStartServerEvent and ClientConnectionEvent.Join, it might be registering stuff, but one is working while other is not.

Maybe it has something to do with Forge?

Iā€™m using forge-1.12.2-14.23.4.2705

Just another test

image

Code:

@Listener
public void onJoin(ClientConnectionEvent.Join e) {
    getLogger().info("onJoinTest");
}

@Listener
public void onInitialize(GameAboutToStartServerEvent e) {
    getLogger().info("inInitTest");
    ....
}

image

Tested in vanilla and same. Nothing to do with forge in that case

To be honest, Iā€™m completely at a loss. The only thing I can suggest is to try completing rebuilding your development/server workspace, and re-test.

Ok, I got some clue.

I just created a fresh new test plugin without no other classes at all

Just a main class and minimal configs, and now itā€™s working.

hmm

Oh wow, I had this piece of code in main class:

Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

It helped me when I load Bukkit API in javascript parser, but it seems the classloader for Sponge wasnā€™t same obviously.

I commented it out, and itā€™s now working!

Thank you for you time anyway!

1 Like

Actually, I found the real cause.

I was unregistering listeners right after listeners are registered without knowing it

Damnā€¦

No wonder why GameAboutToStartServerEvent worked

It was fired before itā€™s unregistered:(

I feel sorry for confusing you xD

Donā€™t worry about it :slight_smile: Glad to see that your issue is resolved.