Skip to content

Commit

Permalink
Merge pull request #1237 from SamB440/fix/disconnect-log
Browse files Browse the repository at this point in the history
Fix disconnect log message
  • Loading branch information
AoElite authored Dec 8, 2023
2 parents 2a534bf + 0ea68dd commit 2ab9b2b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/ac/grim/grimac/player/GrimPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import io.github.retrooper.packetevents.util.FoliaCompatUtil;
import io.github.retrooper.packetevents.util.viaversion.ViaVersionUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -402,15 +404,16 @@ public void timedOut() {
}

public void disconnect(Component reason) {
LogUtil.info("Disconnecting " + user.getProfile().getName() + " for " + reason.toString());
final String textReason = LegacyComponentSerializer.legacySection().serialize(reason);
LogUtil.info("Disconnecting " + user.getProfile().getName() + " for " + ChatColor.stripColor(textReason));
try {
user.sendPacket(new WrapperPlayServerDisconnect(reason));
} catch (Exception ignored) { // There may (?) be an exception if the player is in the wrong state...
LogUtil.warn("Failed to send disconnect packet to disconnect " + user.getProfile().getName() + "! Disconnecting anyways.");
}
user.closeConnection();
if (bukkitPlayer != null) {
FoliaCompatUtil.runTaskForEntity(bukkitPlayer, GrimAPI.INSTANCE.getPlugin(), () -> bukkitPlayer.kickPlayer(reason.toString()), null, 1);
FoliaCompatUtil.runTaskForEntity(bukkitPlayer, GrimAPI.INSTANCE.getPlugin(), () -> bukkitPlayer.kickPlayer(textReason), null, 1);
}
}

Expand Down

0 comments on commit 2ab9b2b

Please sign in to comment.