mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Customizable sleeping actionbar messages
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
||||
Date: Sat, 3 Jul 2021 21:52:15 -0500
|
||||
Subject: [PATCH] Customizable sleeping actionbar messages
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
index 1327e9f3c81f2cf05986cc66fea1f91515f6a457..38dd5b8d756069b8cf9b5cbd570a34435151dd2d 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -4,6 +4,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import co.aikar.timings.TimingHistory; // Paper
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
+import io.papermc.paper.adventure.PaperAdventure;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||
@@ -34,6 +35,9 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
+
|
||||
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
+import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.minecraft.CrashReport;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.DefaultedRegistry;
|
||||
@@ -158,6 +162,7 @@ import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.phys.shapes.BooleanOp;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
+import net.pl3x.purpur.PurpurConfig;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -1087,11 +1092,29 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||||
if (this.canSleepThroughNights()) {
|
||||
if (!this.getServer().isSingleplayer() || this.getServer().isPublished()) {
|
||||
int i = this.getGameRules().getInt(GameRules.RULE_PLAYERS_SLEEPING_PERCENTAGE);
|
||||
- TranslatableComponent chatmessage;
|
||||
+ Component chatmessage; // Purpur
|
||||
|
||||
if (this.sleepStatus.areEnoughSleeping(i)) {
|
||||
+ // Purpur start
|
||||
+ if (PurpurConfig.sleepSkippingNight.isBlank()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ if (!PurpurConfig.sleepSkippingNight.equalsIgnoreCase("default")) {
|
||||
+ chatmessage = PaperAdventure.asVanilla(MiniMessage.get().parse(PurpurConfig.sleepSkippingNight));
|
||||
+ } else
|
||||
+ // Purpur
|
||||
chatmessage = new TranslatableComponent("sleep.skipping_night");
|
||||
} else {
|
||||
+ // Purpur start
|
||||
+ if (PurpurConfig.sleepingPlayersPercent.isBlank()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ if (!PurpurConfig.sleepingPlayersPercent.equalsIgnoreCase("default")) {
|
||||
+ chatmessage = PaperAdventure.asVanilla(MiniMessage.get().parse(PurpurConfig.sleepingPlayersPercent,
|
||||
+ Template.of("count", Integer.toString(this.sleepStatus.amountSleeping())),
|
||||
+ Template.of("total", Integer.toString(this.sleepStatus.sleepersNeeded(i)))));
|
||||
+ } else
|
||||
+ // Purpur end
|
||||
chatmessage = new TranslatableComponent("sleep.players_sleeping", new Object[]{this.sleepStatus.amountSleeping(), this.sleepStatus.sleepersNeeded(i)});
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
index b70a59e80c4861f8be6fd34b326140a6d3f917ed..209ddb614b98edcf340b49c1f12331bf169f8058 100644
|
||||
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
@@ -165,6 +165,8 @@ public class PurpurConfig {
|
||||
public static String pingCommandOutput = "<green>%s's ping is %sms";
|
||||
public static String uptimeCommandOutput = "<green>Server uptime is <uptime>";
|
||||
public static String unverifiedUsername = "default";
|
||||
+ public static String sleepSkippingNight = "default";
|
||||
+ public static String sleepingPlayersPercent = "default";
|
||||
private static void messages() {
|
||||
cannotRideMob = getString("settings.messages.cannot-ride-mob", cannotRideMob);
|
||||
afkBroadcastAway = getString("settings.messages.afk-broadcast-away", afkBroadcastAway);
|
||||
@@ -176,6 +178,8 @@ public class PurpurConfig {
|
||||
pingCommandOutput = getString("settings.messages.ping-command-output", pingCommandOutput);
|
||||
uptimeCommandOutput = getString("settings.messages.uptime-command-output", uptimeCommandOutput);
|
||||
unverifiedUsername = getString("settings.messages.unverified-username", unverifiedUsername);
|
||||
+ sleepSkippingNight = getString("settings.messages.sleep-skipping-night", sleepSkippingNight);
|
||||
+ sleepingPlayersPercent = getString("settings.messages.sleeping-players-percent", sleepingPlayersPercent);
|
||||
}
|
||||
|
||||
public static boolean advancementOnlyBroadcastToAffectedPlayer = false;
|
||||
Reference in New Issue
Block a user