Skip to content

Commit

Permalink
Don't send death message to self server which dead player located
Browse files Browse the repository at this point in the history
To fix the bungee hook issue that receive duplicated death message in the server which the player dead.
  • Loading branch information
Dreeam-qwq committed Dec 17, 2024
1 parent 0df5318 commit dc77b19
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class HookInstance {
public WorldGuardExtension worldGuardExtension;
public boolean worldGuardEnabled;

public String bungeeServerName;
public String bungeeServerName; // Own identification name in Bungee
public String bungeeServerDisplayName;
public boolean bungeeServerNameRequest = true;
public boolean bungeeInit = false;

Expand Down Expand Up @@ -73,13 +74,13 @@ public void registerHooks() {
if (FileStore.CONFIG.getBoolean(Config.HOOKS_BUNGEE_ENABLED)) {
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(instance, "BungeeCord");
Bukkit.getServer().getMessenger().registerIncomingPluginChannel(instance, "BungeeCord", new PluginMessaging());
DeathMessages.LOGGER.info("Bungee Hook enabled!");
if (FileStore.CONFIG.getBoolean(Config.HOOKS_BUNGEE_SERVER_NAME_GET_FROM_BUNGEE)) {
bungeeInit = true;
} else {
bungeeInit = false;
bungeeServerName = FileStore.CONFIG.getString(Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME);
bungeeServerDisplayName = FileStore.CONFIG.getString(Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME);
}
DeathMessages.LOGGER.info("Bungee Hook enabled!");
}

if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ public void onPluginMessageReceived(String channel, @NotNull Player player, byte
if (subChannel.equals("GetServer")) {
String serverName = stream.readUTF();
DeathMessages.LOGGER.info("Server-Name successfully initialized from Bungee! ({})", serverName);
DeathMessages.getHooks().bungeeServerName = serverName;
FileStore.CONFIG.set(Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME, Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME, serverName);
DeathMessages.getHooks().bungeeServerName = DeathMessages.getHooks().bungeeServerDisplayName = serverName;
FileStore.CONFIG.set(Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME, Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME, serverName); // name get from bungee will override displayname, why?
FileStore.CONFIG.save();
DeathMessages.getHooks().bungeeServerNameRequest = false;
} else if (subChannel.equals("DeathMessages")) {
String[] data = stream.readUTF().split("######");
String serverName = data[0];
String rawMsg = data[1];

if (DeathMessages.getHooks().bungeeServerName != null && serverName.equals(DeathMessages.getHooks().bungeeServerName)) return; // Don't send to self

Component prefix = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Bungee.Message"))
.replaceText(TextReplacementConfig.builder()
.matchLiteral("%server_name%")
Expand Down Expand Up @@ -86,15 +89,15 @@ public static void sendPluginMSG(Player player, String msg) {
out.writeUTF("Forward");
out.writeUTF(server);
out.writeUTF("DeathMessages");
out.writeUTF(DeathMessages.getHooks().bungeeServerName + "######" + msg);
out.writeUTF(DeathMessages.getHooks().bungeeServerDisplayName + "######" + msg);
player.sendPluginMessage(DeathMessages.getInstance(), "BungeeCord", out.toByteArray());
}
} else {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Forward");
out.writeUTF("ONLINE");
out.writeUTF("DeathMessages");
out.writeUTF(DeathMessages.getHooks().bungeeServerName + "######" + msg);
out.writeUTF(DeathMessages.getHooks().bungeeServerDisplayName + "######" + msg);
player.sendPluginMessage(DeathMessages.getInstance(), "BungeeCord", out.toByteArray());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class HookInstance {
public WorldGuardExtension worldGuardExtension;
public boolean worldGuardEnabled;

public String bungeeServerName;
public String bungeeServerName; // Own identification name in Bungee
public String bungeeServerDisplayName;
public boolean bungeeServerNameRequest = true;
public boolean bungeeInit = false;

Expand Down Expand Up @@ -70,13 +71,13 @@ public void registerHooks() {
if (FileStore.CONFIG.getBoolean(Config.HOOKS_BUNGEE_ENABLED)) {
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(instance, "BungeeCord");
Bukkit.getServer().getMessenger().registerIncomingPluginChannel(instance, "BungeeCord", new PluginMessaging());
DeathMessages.LOGGER.info("Bungee Hook enabled!");
if (FileStore.CONFIG.getBoolean(Config.HOOKS_BUNGEE_SERVER_NAME_GET_FROM_BUNGEE)) {
bungeeInit = true;
} else {
bungeeInit = false;
bungeeServerName = FileStore.CONFIG.getString(Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME);
bungeeServerDisplayName = FileStore.CONFIG.getString(Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME);
}
DeathMessages.LOGGER.info("Bungee Hook enabled!");
}

if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ public void onPluginMessageReceived(String channel, @NotNull Player player, byte
if (subChannel.equals("GetServer")) {
String serverName = stream.readUTF();
DeathMessages.LOGGER.info("Server-Name successfully initialized from Bungee! ({})", serverName);
DeathMessages.getHooks().bungeeServerName = serverName;
FileStore.CONFIG.set(Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME, Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME, serverName);
DeathMessages.getHooks().bungeeServerName = DeathMessages.getHooks().bungeeServerDisplayName = serverName;
FileStore.CONFIG.set(Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME, Config.HOOKS_BUNGEE_SERVER_NAME_DISPLAY_NAME, serverName); // name get from bungee will override displayname, why?
FileStore.CONFIG.save();
DeathMessages.getHooks().bungeeServerNameRequest = false;
} else if (subChannel.equals("DeathMessages")) {
String[] data = stream.readUTF().split("######");
String serverName = data[0];
String rawMsg = data[1];

if (DeathMessages.getHooks().bungeeServerName != null && serverName.equals(DeathMessages.getHooks().bungeeServerName)) return; // Don't send to self

Component prefix = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Bungee.Message"))
.replaceText(TextReplacementConfig.builder()
.matchLiteral("%server_name%")
Expand Down Expand Up @@ -85,15 +88,15 @@ public static void sendPluginMSG(Player player, String msg) {
out.writeUTF("Forward");
out.writeUTF(server);
out.writeUTF("DeathMessages");
out.writeUTF(DeathMessages.getHooks().bungeeServerName + "######" + msg);
out.writeUTF(DeathMessages.getHooks().bungeeServerDisplayName + "######" + msg);
player.sendPluginMessage(DeathMessages.getInstance(), "BungeeCord", out.toByteArray());
}
} else {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Forward");
out.writeUTF("ONLINE");
out.writeUTF("DeathMessages");
out.writeUTF(DeathMessages.getHooks().bungeeServerName + "######" + msg);
out.writeUTF(DeathMessages.getHooks().bungeeServerDisplayName + "######" + msg);
player.sendPluginMessage(DeathMessages.getInstance(), "BungeeCord", out.toByteArray());
}
}
Expand Down

0 comments on commit dc77b19

Please sign in to comment.