From 6b2ead46c83122edfab4b93eab293ed492d11360 Mon Sep 17 00:00:00 2001 From: replaceitem Date: Sun, 28 Feb 2021 13:50:54 +0100 Subject: [PATCH 1/7] Added list header and motd option to display_title() --- docs/scarpet/api/Auxiliary.md | 13 +++++- .../java/carpet/script/api/Auxiliary.java | 45 ++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index cede1808..4b54660d 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -264,9 +264,20 @@ Sends the player (or players if `players` is a list) a title of a specific type, Executing with those will set the times to the specified ones. Note that `actionbar` type doesn't support changing times (vanilla bug, see [MC-106167](https://bugs.mojang.com/browse/MC-106167)). +### `display_title(players, 'motd', motd),` + +Changes the motd (message of the day) of the server. The `player` value is ignored for the `'motd'` text. +Note that when the `customMOTD` carpet rule is active, this will not work and instead use the MOTD from the rule. + +### `display_title(players, 'header', header, footer),` + +Changes the header and footer of the player list. +Keep in mind this would interfere with carpet's loggers, so if you are using this, you need to keep them off. + ### `logger(msg), logger(type, msg)` -Prints the message to system logs, and not to chat. By default prints an info, unless you specify otherwise in the `type` parameter. +Prints the message to system logs, and not to chat. +By default prints an info, unless you specify otherwise in the `type` parameter. Available output types: diff --git a/src/main/java/carpet/script/api/Auxiliary.java b/src/main/java/carpet/script/api/Auxiliary.java index a0268cc7..1f1f16a2 100644 --- a/src/main/java/carpet/script/api/Auxiliary.java +++ b/src/main/java/carpet/script/api/Auxiliary.java @@ -6,6 +6,7 @@ import carpet.fakes.MinecraftServerInterface; import carpet.fakes.StatTypeInterface; import carpet.fakes.ThreadedAnvilChunkStorageInterface; import carpet.helpers.FeatureGenerator; +import carpet.mixins.PlayerListHeaderS2CPacketMixin; import carpet.script.bundled.Module; import carpet.script.CarpetContext; import carpet.script.CarpetEventServer; @@ -48,6 +49,7 @@ import net.minecraft.nbt.NbtHelper; import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket; +import net.minecraft.network.packet.s2c.play.PlayerListHeaderS2CPacket; import net.minecraft.network.packet.s2c.play.TitleS2CPacket; import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action; import net.minecraft.particle.ParticleEffect; @@ -508,7 +510,8 @@ public class Auxiliary { return player; }); TitleS2CPacket.Action action; - switch (lv.get(1).evalValue(c).getString().toLowerCase(Locale.ROOT)) + String actionString = lv.get(1).evalValue(c).getString().toLowerCase(Locale.ROOT); + switch (actionString) { case "title": action = Action.TITLE; @@ -522,8 +525,46 @@ public class Auxiliary { case "clear": action = Action.CLEAR; break; + case "header": + Text header; + Text footer; + if (lv.size() > 3) + { + pVal = lv.get(2).evalValue(c); + if (pVal instanceof FormattedTextValue) + header = ((FormattedTextValue) pVal).getText(); + else + header = new LiteralText(pVal.getString()); + pVal = lv.get(3).evalValue(c); + if (pVal instanceof FormattedTextValue) + footer = ((FormattedTextValue) pVal).getText(); + else + footer = new LiteralText(pVal.getString()); + } else throw new InternalExpressionException("Third and fourth argument of 'display_title' must be present for 'header' type"); + PlayerListHeaderS2CPacket packet = new PlayerListHeaderS2CPacket(); + ((PlayerListHeaderS2CPacketMixin) packet).setFooter(footer); + ((PlayerListHeaderS2CPacketMixin) packet).setHeader(header); + AtomicInteger total = new AtomicInteger(0); + targets.forEach(p -> { + p.networkHandler.sendPacket(packet); + total.getAndIncrement(); + }); + Value ret = NumericValue.of(total.get()); + return (cc, tt) -> ret; + case "motd": + Text title; + if (lv.size() > 2) + { + pVal = lv.get(2).evalValue(c); + if (pVal instanceof FormattedTextValue) + title = ((FormattedTextValue) pVal).getText(); + else + title = new LiteralText(pVal.getString()); + } else throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type"); + server.getServerMetadata().setDescription(title); + return LazyValue.TRUE; default: - throw new InternalExpressionException("'display_title' requires 'title', 'subtitle', 'actionbar' or 'clear' as second argument"); + throw new InternalExpressionException("'display_title' requires 'title', 'subtitle', 'actionbar', 'clear', 'header' or 'motd' as second argument"); } if (action != Action.CLEAR && lv.size() < 3) throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type"); From 472e1be6639e85f0fa790ddb2f2c07d5760724f3 Mon Sep 17 00:00:00 2001 From: replaceitem <40722305+replaceitem@users.noreply.github.com> Date: Sat, 17 Apr 2021 11:41:15 +0200 Subject: [PATCH 2/7] replace 'header' with 'player_list' Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com> --- docs/scarpet/api/Auxiliary.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index b060e28a..0145ba05 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -282,7 +282,7 @@ Sends the player (or players if `players` is a list) a title of a specific type, Changes the motd (message of the day) of the server. The `player` value is ignored for the `'motd'` text. Note that when the `customMOTD` carpet rule is active, this will not work and instead use the MOTD from the rule. -### `display_title(players, 'header', header, footer),` +### `display_title(players, 'player_list', header, footer),` Changes the header and footer of the player list. Keep in mind this would interfere with carpet's loggers, so if you are using this, you need to keep them off. From fad68163c210322ca4fcceb99afe7d2dea036461 Mon Sep 17 00:00:00 2001 From: replaceitem <40722305+replaceitem@users.noreply.github.com> Date: Sat, 17 Apr 2021 11:41:33 +0200 Subject: [PATCH 3/7] player_list Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com> --- src/main/java/carpet/script/api/Auxiliary.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/api/Auxiliary.java b/src/main/java/carpet/script/api/Auxiliary.java index 67d87d8d..0f06d053 100644 --- a/src/main/java/carpet/script/api/Auxiliary.java +++ b/src/main/java/carpet/script/api/Auxiliary.java @@ -560,7 +560,7 @@ public class Auxiliary { case "clear": action = Action.CLEAR; break; - case "header": + case "player_list": Text header; Text footer; if (lv.size() > 3) From 794a80e4d4888e3b754257591135ad263f7a2297 Mon Sep 17 00:00:00 2001 From: replaceitem <40722305+replaceitem@users.noreply.github.com> Date: Sat, 17 Apr 2021 11:42:02 +0200 Subject: [PATCH 4/7] update exception Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com> --- src/main/java/carpet/script/api/Auxiliary.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/api/Auxiliary.java b/src/main/java/carpet/script/api/Auxiliary.java index 0f06d053..97061e6c 100644 --- a/src/main/java/carpet/script/api/Auxiliary.java +++ b/src/main/java/carpet/script/api/Auxiliary.java @@ -599,7 +599,7 @@ public class Auxiliary { server.getServerMetadata().setDescription(title); return LazyValue.TRUE; default: - throw new InternalExpressionException("'display_title' requires 'title', 'subtitle', 'actionbar', 'clear', 'header' or 'motd' as second argument"); + throw new InternalExpressionException("'display_title' requires 'title', 'subtitle', 'actionbar', 'player_list' or 'clear' as second argument"); } if (action != Action.CLEAR && lv.size() < 3) throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type"); From 53fc6fab9c06ce35672c516c79f565c85301cb7e Mon Sep 17 00:00:00 2001 From: replaceitem Date: Sat, 17 Apr 2021 11:47:53 +0200 Subject: [PATCH 5/7] Removed 'motd' --- src/main/java/carpet/script/api/Auxiliary.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/main/java/carpet/script/api/Auxiliary.java b/src/main/java/carpet/script/api/Auxiliary.java index 97061e6c..2d5d4d85 100644 --- a/src/main/java/carpet/script/api/Auxiliary.java +++ b/src/main/java/carpet/script/api/Auxiliary.java @@ -575,7 +575,7 @@ public class Auxiliary { footer = ((FormattedTextValue) pVal).getText(); else footer = new LiteralText(pVal.getString()); - } else throw new InternalExpressionException("Third and fourth argument of 'display_title' must be present for 'header' type"); + } else throw new InternalExpressionException("Third and fourth argument of 'display_title' must be present for 'player_list' type"); PlayerListHeaderS2CPacket packet = new PlayerListHeaderS2CPacket(); ((PlayerListHeaderS2CPacketMixin) packet).setFooter(footer); ((PlayerListHeaderS2CPacketMixin) packet).setHeader(header); @@ -586,18 +586,6 @@ public class Auxiliary { }); Value ret = NumericValue.of(total.get()); return (cc, tt) -> ret; - case "motd": - Text title; - if (lv.size() > 2) - { - pVal = lv.get(2).evalValue(c); - if (pVal instanceof FormattedTextValue) - title = ((FormattedTextValue) pVal).getText(); - else - title = new LiteralText(pVal.getString()); - } else throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type"); - server.getServerMetadata().setDescription(title); - return LazyValue.TRUE; default: throw new InternalExpressionException("'display_title' requires 'title', 'subtitle', 'actionbar', 'player_list' or 'clear' as second argument"); } From a106f2611f9e4125d8319769e4e512b4f2075f9a Mon Sep 17 00:00:00 2001 From: replaceitem Date: Sat, 17 Apr 2021 11:48:05 +0200 Subject: [PATCH 6/7] Update docs --- docs/scarpet/api/Auxiliary.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index 0145ba05..29d08f99 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -277,11 +277,6 @@ Sends the player (or players if `players` is a list) a title of a specific type, Executing with those will set the times to the specified ones. Note that `actionbar` type doesn't support changing times (vanilla bug, see [MC-106167](https://bugs.mojang.com/browse/MC-106167)). -### `display_title(players, 'motd', motd),` - -Changes the motd (message of the day) of the server. The `player` value is ignored for the `'motd'` text. -Note that when the `customMOTD` carpet rule is active, this will not work and instead use the MOTD from the rule. - ### `display_title(players, 'player_list', header, footer),` Changes the header and footer of the player list. From eaa242c8eb4539eb8b8f5645d9ee2a7538d4b587 Mon Sep 17 00:00:00 2001 From: replaceitem Date: Sat, 17 Apr 2021 12:33:31 +0200 Subject: [PATCH 7/7] Added option to only set footer, and clear both --- docs/scarpet/api/Auxiliary.md | 5 ++++- .../java/carpet/script/api/Auxiliary.java | 21 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index 29d08f99..f905be84 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -277,9 +277,12 @@ Sends the player (or players if `players` is a list) a title of a specific type, Executing with those will set the times to the specified ones. Note that `actionbar` type doesn't support changing times (vanilla bug, see [MC-106167](https://bugs.mojang.com/browse/MC-106167)). -### `display_title(players, 'player_list', header, footer),` +### `display_title(players, 'player_list')` +### `display_title(players, 'player_list', footer)` +### `display_title(players, 'player_list', header, footer)` Changes the header and footer of the player list. +When no `header` and `footer` is specified, they will be reset. Keep in mind this would interfere with carpet's loggers, so if you are using this, you need to keep them off. ### `logger(msg), logger(type, msg)` diff --git a/src/main/java/carpet/script/api/Auxiliary.java b/src/main/java/carpet/script/api/Auxiliary.java index 2d5d4d85..d370e7e2 100644 --- a/src/main/java/carpet/script/api/Auxiliary.java +++ b/src/main/java/carpet/script/api/Auxiliary.java @@ -561,21 +561,34 @@ public class Auxiliary { action = Action.CLEAR; break; case "player_list": - Text header; Text footer; - if (lv.size() > 3) - { + Text header; + + if(lv.size() == 2) { + footer = new LiteralText(""); + header = new LiteralText(""); + } else if(lv.size() == 3) { + pVal = lv.get(2).evalValue(c); + if (pVal instanceof FormattedTextValue) + footer = ((FormattedTextValue) pVal).getText(); + else + footer = new LiteralText(pVal.getString()); + + header = new LiteralText(""); + } else { pVal = lv.get(2).evalValue(c); if (pVal instanceof FormattedTextValue) header = ((FormattedTextValue) pVal).getText(); else header = new LiteralText(pVal.getString()); + pVal = lv.get(3).evalValue(c); if (pVal instanceof FormattedTextValue) footer = ((FormattedTextValue) pVal).getText(); else footer = new LiteralText(pVal.getString()); - } else throw new InternalExpressionException("Third and fourth argument of 'display_title' must be present for 'player_list' type"); + } + PlayerListHeaderS2CPacket packet = new PlayerListHeaderS2CPacket(); ((PlayerListHeaderS2CPacketMixin) packet).setFooter(footer); ((PlayerListHeaderS2CPacketMixin) packet).setHeader(header);