From eaa242c8eb4539eb8b8f5645d9ee2a7538d4b587 Mon Sep 17 00:00:00 2001 From: replaceitem Date: Sat, 17 Apr 2021 12:33:31 +0200 Subject: [PATCH] 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);