Merge pull request #200

Add config option to use action bar for titles
This commit is contained in:
Flemmli97 2022-11-26 20:35:22 +01:00 committed by GitHub
commit 404fe80e1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 10 deletions

View File

@ -19,8 +19,10 @@ 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.chat.Style;
import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket;
import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket;
import net.minecraft.resources.ResourceLocation;
@ -34,6 +36,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 +583,29 @@ 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, @Nullable Component title, @Nullable Component subtitle) {
if (title == null) return;
if (ConfigHandler.config.claimDisplayActionBar) {
if (subtitle != null) {
MutableComponent message = title.copy().append(Component.literal(" | ").setStyle(Style.EMPTY.withColor(ChatFormatting.WHITE))).append(subtitle);
player.sendSystemMessage(message, ChatType.GAME_INFO);
return;
}
player.sendSystemMessage(title, ChatType.GAME_INFO);
return;
}
player.connection.send(new ClientboundSetTitleTextPacket(title));
if (subtitle != null) {
player.connection.send(new ClientboundSetSubtitleTextPacket(subtitle));
}
}
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);
}
/**

View File

@ -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();
@ -169,6 +170,7 @@ public class Config {
if (obj.has("inspectionItem"))
this.inspectionItem = CrossPlatformStuff.INSTANCE.registryItems().getFromId(new ResourceLocation((obj.get("inspectionItem").getAsString())));
this.claimDisplayTime = ConfigHandler.fromJson(obj, "claimDisplayTime", this.claimDisplayTime);
this.claimDisplayActionBar = ConfigHandler.fromJson(obj, "claimDisplayActionBar", this.claimDisplayActionBar);
this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel);
this.buySellHandler.fromJson(ConfigHandler.fromJson(obj, "buySellHandler"));
@ -265,6 +267,7 @@ public class Config {
obj.addProperty("claimingItem", CrossPlatformStuff.INSTANCE.registryItems().getIDFrom(this.claimingItem).toString());
obj.addProperty("inspectionItem", CrossPlatformStuff.INSTANCE.registryItems().getIDFrom(this.inspectionItem).toString());
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
obj.addProperty("claimDisplayActionBar", this.claimDisplayActionBar);
obj.addProperty("permissionLevel", this.permissionLevel);
obj.add("buySellHandler", this.buySellHandler.toJson());