From a875356a1a117a182d9dacc95c7ae067f1c4a3eb Mon Sep 17 00:00:00 2001 From: Jarva <4622609+Jarva@users.noreply.github.com> Date: Thu, 24 Nov 2022 16:20:37 +0000 Subject: [PATCH] feat: add actionbar message config option --- .../io/github/flemmli97/flan/claim/Claim.java | 30 ++++++++++++------- .../github/flemmli97/flan/config/Config.java | 1 + 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java b/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java index fe10c4d..12ec6b9 100644 --- a/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java +++ b/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java @@ -19,6 +19,7 @@ import io.github.flemmli97.flan.player.LogoutTracker; import io.github.flemmli97.flan.player.PlayerClaimData; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket; @@ -34,6 +35,7 @@ import net.minecraft.world.effect.MobEffects; import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.phys.AABB; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -580,20 +582,28 @@ public class Claim implements IPermissionContainer { this.setDirty(true); } - public void displayEnterTitle(ServerPlayer player) { - if (this.enterTitle != null) { - player.connection.send(new ClientboundSetTitleTextPacket(this.enterTitle)); - if (this.enterSubtitle != null) - player.connection.send(new ClientboundSetSubtitleTextPacket(this.enterSubtitle)); + private void displayTitleMessage(ServerPlayer player, Component title, @Nullable Component subtitle) { + if (ConfigHandler.config.claimDisplayActionBar) { + if (subtitle != null) { + MutableComponent message = this.enterTitle.copy().append(" - ").append(this.enterSubtitle); + player.sendSystemMessage(message, ChatType.GAME_INFO); + return; + } + player.sendSystemMessage(this.enterTitle, ChatType.GAME_INFO); + return; + } + player.connection.send(new ClientboundSetTitleTextPacket(this.enterTitle)); + if (subtitle != null) { + player.connection.send(new ClientboundSetSubtitleTextPacket(this.enterSubtitle)); } } + public void displayEnterTitle(ServerPlayer player) { + displayTitleMessage(player, enterTitle, enterSubtitle); + } + public void displayLeaveTitle(ServerPlayer player) { - if (this.leaveTitle != null) { - player.connection.send(new ClientboundSetTitleTextPacket(this.leaveTitle)); - if (this.leaveSubtitle != null) - player.connection.send(new ClientboundSetSubtitleTextPacket(this.leaveSubtitle)); - } + displayTitleMessage(player, leaveTitle, leaveSubtitle); } /** diff --git a/common/src/main/java/io/github/flemmli97/flan/config/Config.java b/common/src/main/java/io/github/flemmli97/flan/config/Config.java index ee5216a..4b36208 100644 --- a/common/src/main/java/io/github/flemmli97/flan/config/Config.java +++ b/common/src/main/java/io/github/flemmli97/flan/config/Config.java @@ -45,6 +45,7 @@ public class Config { public Item inspectionItem = Items.STICK; public int claimDisplayTime = 1000; + public boolean claimDisplayActionBar = false; public int permissionLevel = 2; public BuySellHandler buySellHandler = new BuySellHandler();