Skip to content

Commit

Permalink
Fix servername not getting aquired on MC 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Feb 5, 2024
1 parent 46873fb commit 36ba49d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

public class PluginChannelCommunicator extends PluginChannelCommunicatorBase implements PluginMessageListener, Listener
{
private static final String CHANNEL_BUNGEE_CORD = "BungeeCord";

@Getter @Setter(AccessLevel.PRIVATE) private static String serverName = null;

private final MarriageMaster plugin;
Expand Down Expand Up @@ -85,7 +87,7 @@ public void close()
@Override
protected void receiveUnknownChannel(@NotNull String channel, byte[] bytes)
{
if (channel.equals(CHANNEL_BUNGEE_CORD))
if (channel.equals(CHANNEL_BUNGEE_CORD) || channel.equals("bungeecord:main"))
{
try(DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes)))
{
Expand Down Expand Up @@ -196,8 +198,10 @@ public void onPlayerLoginEvent(PlayerJoinEvent event)
{
if(!serverNameUpdated)
{
logger.info("Request server name from BungeeCord ...");
sendMessage(CHANNEL_BUNGEE_CORD, buildStringMessage("GetServer"));
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
logger.info("Request server name from BungeeCord ...");
sendMessage(CHANNEL_BUNGEE_CORD, buildStringMessage("GetServer"));
}, 20);
}
// If the server is empty and a player joins the server we have to do a re-sync
if(plugin.getServer().getOnlinePlayers().size() == 1)
Expand All @@ -216,7 +220,9 @@ public void sendMessage(final byte[] data)
private void sendMessage(String channel, byte[] data)
{
if (Bukkit.isPrimaryThread())
{
performSendMessage(channel, data);
}
else
{
Bukkit.getScheduler().runTask(plugin, () -> performSendMessage(channel, data));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 GeorgH93
* Copyright (C) 2024 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -29,7 +29,7 @@
public abstract class PluginChannelCommunicatorBase
{
private static final String MESSAGE_UNKNOWN_COMMAND = ConsoleColor.YELLOW + "Received unknown command via plugin channel! Command: {0} " + ConsoleColor.RESET;
protected static final String CHANNEL_MARRIAGE_MASTER = "marriagemaster:main", CHANNEL_BUNGEE_CORD = "BungeeCord";
protected static final String CHANNEL_MARRIAGE_MASTER = "marriagemaster:main";

protected final Logger logger;
protected final BaseDatabase database;
Expand Down

0 comments on commit 36ba49d

Please sign in to comment.