Skip to content

Commit

Permalink
Switch to onPlayerRegisterChannel so we don't have to schedule the event
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHaws committed Oct 8, 2022
1 parent f11f95f commit 9601925
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/dev/chaws/xaeros/map/spigot/WorldMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRegisterChannelEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.BufferedReader;
Expand Down Expand Up @@ -41,15 +41,16 @@ public void onDisable() {
this.getServer().getMessenger().unregisterOutgoingPluginChannel(this);
}

// Use PlayerRegisterChannelEvent instead of PlayerLoginEvent because
// the client mod might not have registered to events on the channel yet
// so the packet won't get picked up by the mod.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
// Needs to be run in the future to ensure the mod has loaded on the client
// Otherwise the packet doesn't get picked up by the mod.
// Might want to make the ticks configurable in the future to allow
// for tweaking the value for slower clients
this.getServer().getScheduler().runTaskLater(this, () -> {
sendPlayerWorldId(event.getPlayer());
}, 60);
public void onPlayerRegisterChannel(PlayerRegisterChannelEvent event) {
if (!event.getChannel().equals(channel)) {
return;
}

sendPlayerWorldId(event.getPlayer());
}

@EventHandler
Expand Down

0 comments on commit 9601925

Please sign in to comment.