From f065ea22ed580ddb6137fc3f01b92fe5b23beb6c Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sat, 21 Sep 2024 15:46:15 +0200
Subject: [PATCH 01/15] init commit
---
.../skript/classes/data/BukkitClasses.java | 9 ++++
.../skript/conditions/CondChatColors.java | 39 +++++++++++++++
.../skript/conditions/CondChatFiltering.java | 37 ++++++++++++++
.../expressions/ExprChatVisibility.java | 44 +++++++++++++++++
src/main/resources/lang/default.lang | 7 +++
.../expressions/ExprChatVisibilityTest.java | 48 +++++++++++++++++++
src/test/skript/junit/ExprChatVisibility.sk | 18 +++++++
7 files changed, 202 insertions(+)
create mode 100644 src/main/java/ch/njol/skript/conditions/CondChatColors.java
create mode 100644 src/main/java/ch/njol/skript/conditions/CondChatFiltering.java
create mode 100644 src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
create mode 100644 src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
create mode 100644 src/test/skript/junit/ExprChatVisibility.sk
diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
index ba0a66a1f41..65ba8dd51a9 100644
--- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
+++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
@@ -30,6 +30,7 @@
import java.util.stream.Collectors;
import ch.njol.skript.bukkitutil.BukkitUtils;
+import com.destroystokyo.paper.ClientOption;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Difficulty;
@@ -1526,6 +1527,14 @@ public String toVariableNameString(EnchantmentOffer eo) {
.name("Transform Reason")
.description("Represents a transform reason of an entity transform event.")
.since("2.8.0"));
+
+ if (Skript.classExists("com.destroystokyo.paper.ClientOption$ChatVisibility"))
+ Classes.registerClass(new EnumClassInfo<>(ClientOption.ChatVisibility.class, "chatvisibility", "chat visibilities")
+ .user("chat ?visibility")
+ .name("Chat Visibility")
+ .description("The chat visibility of a player.")
+ .requiredPlugins("Paper")
+ .since("INSERT VERSION"));
}
}
diff --git a/src/main/java/ch/njol/skript/conditions/CondChatColors.java b/src/main/java/ch/njol/skript/conditions/CondChatColors.java
new file mode 100644
index 00000000000..c9bd02afb68
--- /dev/null
+++ b/src/main/java/ch/njol/skript/conditions/CondChatColors.java
@@ -0,0 +1,39 @@
+package ch.njol.skript.conditions;
+
+import ch.njol.skript.Skript;
+import ch.njol.skript.conditions.base.PropertyCondition;
+import ch.njol.skript.doc.*;
+import com.destroystokyo.paper.ClientOption;
+import org.bukkit.entity.Player;
+
+@Name("Can See Chat Colors")
+@Description("Checks whether a player can see chat colors.")
+@Examples({
+ "if player can see chat colors:",
+ "\tsend \"Find the red word in this message.\"",
+ "else:",
+ "\tsend \"You cannot partake in finding the colored word.\""
+})
+@RequiredPlugins("Paper")
+@Since("INSERT VERSION")
+public class CondChatColors extends PropertyCondition {
+
+ private static final boolean SUPPORTS_CLIENT_OPTION =
+ Skript.classExists("com.destroystokyo.paper.ClientOption");
+
+ static {
+ if (SUPPORTS_CLIENT_OPTION)
+ register(CondChatColors.class, PropertyType.CAN, "see chat colo[u]r[s|ing]", "players");
+ }
+
+ @Override
+ public boolean check(Player player) {
+ return player.getClientOption(ClientOption.CHAT_COLORS_ENABLED);
+ }
+
+ @Override
+ protected String getPropertyName() {
+ return "can see chat colors";
+ }
+
+}
diff --git a/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java b/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java
new file mode 100644
index 00000000000..9593f0a2b5f
--- /dev/null
+++ b/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java
@@ -0,0 +1,37 @@
+package ch.njol.skript.conditions;
+
+import ch.njol.skript.Skript;
+import ch.njol.skript.conditions.base.PropertyCondition;
+import ch.njol.skript.doc.*;
+import com.destroystokyo.paper.ClientOption;
+import org.bukkit.entity.Player;
+
+@Name("Has Chat Filtering")
+@Description("Checks whether a player has chat filtering enabled.")
+@Examples({
+ "if player doesn't have chat filtering enabled:",
+ "send \"This server may contain mature chat messages. You have been warned!\" to player",
+})
+@RequiredPlugins("Paper")
+@Since("INSERT VERSION")
+public class CondChatFiltering extends PropertyCondition {
+
+ private static final boolean SUPPORTS_CLIENT_OPTION =
+ Skript.classExists("com.destroystokyo.paper.ClientOption");
+
+ static {
+ if (SUPPORTS_CLIENT_OPTION)
+ register(CondChatFiltering.class, PropertyType.HAVE, "(chat|text) filtering (on|enabled)", "players");
+ }
+
+ @Override
+ public boolean check(Player player) {
+ return player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
+ }
+
+ @Override
+ protected String getPropertyName() {
+ return "has chat filtering enabled";
+ }
+
+}
diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java b/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
new file mode 100644
index 00000000000..990d3d5067d
--- /dev/null
+++ b/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
@@ -0,0 +1,44 @@
+package ch.njol.skript.expressions;
+
+import ch.njol.skript.Skript;
+import ch.njol.skript.doc.*;
+import ch.njol.skript.expressions.base.SimplePropertyExpression;
+import com.destroystokyo.paper.ClientOption;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.Nullable;
+
+@Name("Chat Visibility")
+@Description("The chat visibility of a player.")
+@Examples({
+ "if chat visibility of player is hidden:",
+ "\tsend actionbar \"Server restart in 5 minutes\" to player"
+})
+@RequiredPlugins("Paper")
+@Since("INSERT VERSION")
+public class ExprChatVisibility extends SimplePropertyExpression {
+
+ private static final boolean SUPPORTS_CHAT_VISIBILITY =
+ Skript.classExists("com.destroystokyo.paper.ClientOption$ChatVisibility");
+
+ static {
+ if (SUPPORTS_CHAT_VISIBILITY)
+ register(ExprChatVisibility.class, ClientOption.ChatVisibility.class,
+ "chat visibility", "players");
+ }
+
+ @Override
+ public @Nullable ClientOption.ChatVisibility convert(Player from) {
+ return from.getClientOption(ClientOption.CHAT_VISIBILITY);
+ }
+
+ @Override
+ public Class getReturnType() {
+ return ClientOption.ChatVisibility.class;
+ }
+
+ @Override
+ protected String getPropertyName() {
+ return "chat visibility";
+ }
+
+}
diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang
index fec454c2ac5..82271e01af2 100644
--- a/src/main/resources/lang/default.lang
+++ b/src/main/resources/lang/default.lang
@@ -2275,6 +2275,13 @@ transform reasons:
unknown: unknown
infection: infection, villager infection
+# -- Chat Visibilities --
+chat visibilities:
+ full: full, visible
+ hidden: hidden
+ system: system, commands only, only commands
+ unknown: unknown
+
# -- Boolean --
boolean:
true:
diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
new file mode 100644
index 00000000000..39df1bb4ce4
--- /dev/null
+++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
@@ -0,0 +1,48 @@
+package org.skriptlang.skript.test.tests.syntaxes.expressions;
+
+import ch.njol.skript.Skript;
+import ch.njol.skript.test.runner.SkriptJUnitTest;
+import com.destroystokyo.paper.ClientOption;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerMoveEvent;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ExprChatVisibilityTest extends SkriptJUnitTest {
+
+ private static final boolean SUPPORTS_CHAT_VISIBILITY =
+ Skript.classExists("com.destroystokyo.paper.ClientOption$ChatVisibility");
+
+ static {
+ setShutdownDelay(1);
+ }
+
+ private Player player;
+
+ @Before
+ public void setup() {
+ if (!SUPPORTS_CHAT_VISIBILITY)
+ return;
+
+ player = EasyMock.niceMock(Player.class);
+ }
+
+ @Test
+ public void test() {
+ if (!SUPPORTS_CHAT_VISIBILITY)
+ return;
+
+ EasyMock.expect(player.getClientOption(ClientOption.CHAT_VISIBILITY))
+ .andReturn(ClientOption.ChatVisibility.SYSTEM);
+ EasyMock.expect(player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED))
+ .andReturn(false);
+ EasyMock.expect(player.getClientOption(ClientOption.CHAT_COLORS_ENABLED))
+ .andReturn(true);
+
+ Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(player, ""));
+ }
+
+}
diff --git a/src/test/skript/junit/ExprChatVisibility.sk b/src/test/skript/junit/ExprChatVisibility.sk
new file mode 100644
index 00000000000..8ec1862d646
--- /dev/null
+++ b/src/test/skript/junit/ExprChatVisibility.sk
@@ -0,0 +1,18 @@
+test "ExprChatVisibilityJUnit" when running JUnit:
+ set {_tests::1} to "chat visibility is only commands"
+ set {_tests::2} to "no chat filtering"
+ set {_tests::3} to "can see chat colours"
+ ensure junit test "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprChatVisibilityTest" completes {_tests::*}
+
+on join:
+ set {_test} to "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprChatVisibilityTest"
+ junit test is {_test}
+
+ if player's chat visibility is only commands:
+ complete objective "chat visibility is only commands" for {_test}
+
+ if player doesn't have chat filtering enabled:
+ complete objective "no chat filtering" for {_test}
+
+ if player can see chat colours:
+ complete objective "can see chat colours" for {_test}
\ No newline at end of file
From 77f3ce974a41978be9cf24f0b727b00f1c5f6e82 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sat, 21 Sep 2024 15:50:19 +0200
Subject: [PATCH 02/15] update
---
src/main/resources/lang/default.lang | 1 +
.../test/tests/syntaxes/expressions/ExprChatVisibilityTest.java | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang
index 82271e01af2..5165a38badc 100644
--- a/src/main/resources/lang/default.lang
+++ b/src/main/resources/lang/default.lang
@@ -2361,6 +2361,7 @@ types:
quitreason: quit reason¦s @a
inventoryclosereason: inventory close reason¦s @an
transformreason: transform reason¦s @a
+ chatvisibility: chat visibility¦s @a
# Skript
weathertype: weather type¦s @a
diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
index 39df1bb4ce4..b1d1a62e8ea 100644
--- a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
+++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
@@ -6,7 +6,6 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
-import org.bukkit.event.player.PlayerMoveEvent;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
From 2e8e32774e4f7147425fc8c76b7094cd096f8755 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sat, 21 Sep 2024 15:51:43 +0200
Subject: [PATCH 03/15] update
---
.../expressions/ExprChatVisibilityTest.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
index b1d1a62e8ea..2ba8a622335 100644
--- a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
+++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
@@ -27,12 +27,6 @@ public void setup() {
return;
player = EasyMock.niceMock(Player.class);
- }
-
- @Test
- public void test() {
- if (!SUPPORTS_CHAT_VISIBILITY)
- return;
EasyMock.expect(player.getClientOption(ClientOption.CHAT_VISIBILITY))
.andReturn(ClientOption.ChatVisibility.SYSTEM);
@@ -40,8 +34,14 @@ public void test() {
.andReturn(false);
EasyMock.expect(player.getClientOption(ClientOption.CHAT_COLORS_ENABLED))
.andReturn(true);
+ }
+
+ @Test
+ public void test() {
+ if (!SUPPORTS_CHAT_VISIBILITY)
+ return;
- Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(player, ""));
+ Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(player, "hi"));
}
}
From d8e7b21881cdea700368932c8ef7347e11e38109 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sat, 21 Sep 2024 15:53:38 +0200
Subject: [PATCH 04/15] update doc
---
.../java/ch/njol/skript/expressions/ExprChatVisibility.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java b/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
index 990d3d5067d..9cee8bf3f88 100644
--- a/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
+++ b/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
@@ -1,6 +1,7 @@
package ch.njol.skript.expressions;
import ch.njol.skript.Skript;
+import ch.njol.skript.classes.Changer;
import ch.njol.skript.doc.*;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import com.destroystokyo.paper.ClientOption;
@@ -8,9 +9,9 @@
import org.jetbrains.annotations.Nullable;
@Name("Chat Visibility")
-@Description("The chat visibility of a player.")
+@Description("The chat visibility of a player. Can only be read.")
@Examples({
- "if chat visibility of player is hidden:",
+ "if chat visibility of player is hidden or commands only:",
"\tsend actionbar \"Server restart in 5 minutes\" to player"
})
@RequiredPlugins("Paper")
From 856cc979c78cff59bdd54841373a5b14dc2d618f Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sat, 21 Sep 2024 16:26:42 +0200
Subject: [PATCH 05/15] weird error
---
src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java | 1 -
.../test/tests/syntaxes/expressions/ExprChatVisibilityTest.java | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java b/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
index 9cee8bf3f88..5050f00b3e2 100644
--- a/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
+++ b/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
@@ -1,7 +1,6 @@
package ch.njol.skript.expressions;
import ch.njol.skript.Skript;
-import ch.njol.skript.classes.Changer;
import ch.njol.skript.doc.*;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import com.destroystokyo.paper.ClientOption;
diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
index 2ba8a622335..a6c8aa585db 100644
--- a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
+++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
@@ -34,6 +34,7 @@ public void setup() {
.andReturn(false);
EasyMock.expect(player.getClientOption(ClientOption.CHAT_COLORS_ENABLED))
.andReturn(true);
+ EasyMock.expect(player.hasPermission("skript.admin")).andReturn(false);
}
@Test
From 65b65015ae50513168de1598a30e035d0e880678 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sat, 21 Sep 2024 16:32:06 +0200
Subject: [PATCH 06/15] weird error
---
.../test/tests/syntaxes/expressions/ExprChatVisibilityTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
index a6c8aa585db..7e74fde8baf 100644
--- a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
+++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
@@ -34,7 +34,7 @@ public void setup() {
.andReturn(false);
EasyMock.expect(player.getClientOption(ClientOption.CHAT_COLORS_ENABLED))
.andReturn(true);
- EasyMock.expect(player.hasPermission("skript.admin")).andReturn(false);
+ EasyMock.replay(player);
}
@Test
From 62001745f5c2f413cf40c4cf80c8b9698c5ae488 Mon Sep 17 00:00:00 2001
From: Efy <35348263+Efnilite@users.noreply.github.com>
Date: Sat, 21 Sep 2024 17:02:28 +0200
Subject: [PATCH 07/15] Apply suggestions from code review
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
---
src/main/java/ch/njol/skript/conditions/CondChatColors.java | 2 +-
.../java/ch/njol/skript/conditions/CondChatFiltering.java | 2 +-
src/main/resources/lang/default.lang | 4 ++--
src/test/skript/junit/ExprChatVisibility.sk | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/java/ch/njol/skript/conditions/CondChatColors.java b/src/main/java/ch/njol/skript/conditions/CondChatColors.java
index c9bd02afb68..26f2b81e168 100644
--- a/src/main/java/ch/njol/skript/conditions/CondChatColors.java
+++ b/src/main/java/ch/njol/skript/conditions/CondChatColors.java
@@ -33,7 +33,7 @@ public boolean check(Player player) {
@Override
protected String getPropertyName() {
- return "can see chat colors";
+ return "see chat colors";
}
}
diff --git a/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java b/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java
index 9593f0a2b5f..b377e038e0c 100644
--- a/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java
+++ b/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java
@@ -31,7 +31,7 @@ public boolean check(Player player) {
@Override
protected String getPropertyName() {
- return "has chat filtering enabled";
+ return "chat filtering enabled";
}
}
diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang
index 5165a38badc..0e9af33d8b1 100644
--- a/src/main/resources/lang/default.lang
+++ b/src/main/resources/lang/default.lang
@@ -2277,9 +2277,9 @@ transform reasons:
# -- Chat Visibilities --
chat visibilities:
- full: full, visible
+ full: fully visible, visible
hidden: hidden
- system: system, commands only, only commands
+ system: system messages only, only system messages, commands only, only commands
unknown: unknown
# -- Boolean --
diff --git a/src/test/skript/junit/ExprChatVisibility.sk b/src/test/skript/junit/ExprChatVisibility.sk
index 8ec1862d646..b6a667d8ee8 100644
--- a/src/test/skript/junit/ExprChatVisibility.sk
+++ b/src/test/skript/junit/ExprChatVisibility.sk
@@ -15,4 +15,4 @@ on join:
complete objective "no chat filtering" for {_test}
if player can see chat colours:
- complete objective "can see chat colours" for {_test}
\ No newline at end of file
+ complete objective "can see chat colours" for {_test}
From 27a50f19a347a3ee646a04edd0fe727937dcf9c6 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sun, 22 Sep 2024 11:36:48 +0200
Subject: [PATCH 08/15] ok
---
src/main/resources/lang/default.lang | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang
index 0e9af33d8b1..f5d637a75b0 100644
--- a/src/main/resources/lang/default.lang
+++ b/src/main/resources/lang/default.lang
@@ -2361,7 +2361,6 @@ types:
quitreason: quit reason¦s @a
inventoryclosereason: inventory close reason¦s @an
transformreason: transform reason¦s @a
- chatvisibility: chat visibility¦s @a
# Skript
weathertype: weather type¦s @a
From 3c63d7fb9641e6f9e00dd72b37c45150c3caac31 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sun, 22 Sep 2024 23:42:39 +0200
Subject: [PATCH 09/15] add new cond
---
.../skript/conditions/CondChatColors.java | 5 +-
.../skript/conditions/CondChatFiltering.java | 8 +-
.../skript/conditions/CondChatVisibility.java | 84 +++++++++++++++++++
.../expressions/ExprChatVisibility.java | 5 +-
src/main/resources/lang/default.lang | 7 --
src/test/skript/junit/ExprChatVisibility.sk | 2 +-
6 files changed, 90 insertions(+), 21 deletions(-)
create mode 100644 src/main/java/ch/njol/skript/conditions/CondChatVisibility.java
diff --git a/src/main/java/ch/njol/skript/conditions/CondChatColors.java b/src/main/java/ch/njol/skript/conditions/CondChatColors.java
index 26f2b81e168..25f90805835 100644
--- a/src/main/java/ch/njol/skript/conditions/CondChatColors.java
+++ b/src/main/java/ch/njol/skript/conditions/CondChatColors.java
@@ -18,11 +18,8 @@
@Since("INSERT VERSION")
public class CondChatColors extends PropertyCondition {
- private static final boolean SUPPORTS_CLIENT_OPTION =
- Skript.classExists("com.destroystokyo.paper.ClientOption");
-
static {
- if (SUPPORTS_CLIENT_OPTION)
+ if (Skript.classExists("com.destroystokyo.paper.ClientOption"))
register(CondChatColors.class, PropertyType.CAN, "see chat colo[u]r[s|ing]", "players");
}
diff --git a/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java b/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java
index b377e038e0c..0cd28cfab10 100644
--- a/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java
+++ b/src/main/java/ch/njol/skript/conditions/CondChatFiltering.java
@@ -16,12 +16,10 @@
@Since("INSERT VERSION")
public class CondChatFiltering extends PropertyCondition {
- private static final boolean SUPPORTS_CLIENT_OPTION =
- Skript.classExists("com.destroystokyo.paper.ClientOption");
-
static {
- if (SUPPORTS_CLIENT_OPTION)
- register(CondChatFiltering.class, PropertyType.HAVE, "(chat|text) filtering (on|enabled)", "players");
+ if (Skript.classExists("com.destroystokyo.paper.ClientOption"))
+ register(CondChatFiltering.class, PropertyType.HAVE,
+ "(chat|text) filtering (on|enabled)", "players");
}
@Override
diff --git a/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java b/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java
new file mode 100644
index 00000000000..59d19fb57de
--- /dev/null
+++ b/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java
@@ -0,0 +1,84 @@
+package ch.njol.skript.conditions;
+
+import ch.njol.skript.Skript;
+import ch.njol.skript.doc.Description;
+import ch.njol.skript.doc.Examples;
+import ch.njol.skript.doc.Name;
+import ch.njol.skript.doc.Since;
+import ch.njol.skript.lang.Condition;
+import ch.njol.skript.lang.Expression;
+import ch.njol.skript.lang.SkriptParser.ParseResult;
+import ch.njol.util.Kleenean;
+import com.destroystokyo.paper.ClientOption;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Event;
+import org.jetbrains.annotations.Nullable;
+
+@Name("Can See Messages")
+@Description("Checks whether a player can see specific message types in chat.")
+@Examples({
+ "if player can see all messages:",
+ "\tsend \"You can see all messages.\"",
+ "if player can only see commands:",
+ "\tsend \"This game doesn't work with commands-only chat.\"",
+ "if player can't see any messages:",
+ "\tsend action bar \"Server shutting down in 5 minutes!\""
+})
+@Since("INSERT VERSION")
+public class CondChatVisibility extends Condition {
+
+ static {
+ if (Skript.classExists("com.destroystokyo.paper.ClientOption$ChatVisibility"))
+ Skript.registerCondition(CondChatVisibility.class,
+ "%player% can see all messages [in chat]",
+ "%player% can only see (commands|system messages) [in chat]",
+ "%player% can('t|[ ]not) see any (command[s]|message[s]) [in chat]",
+ "%player% can('t|[ ]not) see all messages [in chat]",
+ "%player% can('t|[ ]not) only see (commands|system messages) [in chat]");
+ }
+
+ private int pattern = 0;
+ private Expression player;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean init(Expression>[] expressions, int matchedPattern,
+ Kleenean isDelayed, ParseResult parseResult) {
+ pattern = matchedPattern;
+ player = (Expression) expressions[0];
+
+ setNegated(matchedPattern > 1);
+ return true;
+ }
+
+ @Override
+ public boolean check(Event event) {
+ Player player = this.player.getSingle(event);
+
+ if (player == null)
+ return false;
+
+ ClientOption.ChatVisibility current = player.getClientOption(ClientOption.CHAT_VISIBILITY);
+
+ return switch (pattern) {
+ case 0 -> current == ClientOption.ChatVisibility.FULL;
+ case 1 -> current == ClientOption.ChatVisibility.SYSTEM;
+ case 2 -> current == ClientOption.ChatVisibility.HIDDEN;
+ case 3 -> current != ClientOption.ChatVisibility.FULL;
+ case 4 -> current != ClientOption.ChatVisibility.SYSTEM;
+ default -> throw new IllegalStateException("Unexpected value: " + pattern);
+ };
+ }
+
+ @Override
+ public String toString(@Nullable Event event, boolean debug) {
+ return switch (pattern) {
+ case 0 -> player.toString(event, debug) + " can see all messages";
+ case 1 -> player.toString(event, debug) + " can only see commands";
+ case 2 -> player.toString(event, debug) + " can't see any messages";
+ case 3 -> player.toString(event, debug) + " can't see all messages";
+ case 4 -> player.toString(event, debug) + " can't only see commands";
+ default -> throw new IllegalStateException("Unexpected value: " + pattern);
+ };
+ }
+}
diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java b/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
index 5050f00b3e2..2c2ec95bf1d 100644
--- a/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
+++ b/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
@@ -17,11 +17,8 @@
@Since("INSERT VERSION")
public class ExprChatVisibility extends SimplePropertyExpression {
- private static final boolean SUPPORTS_CHAT_VISIBILITY =
- Skript.classExists("com.destroystokyo.paper.ClientOption$ChatVisibility");
-
static {
- if (SUPPORTS_CHAT_VISIBILITY)
+ if (Skript.classExists("com.destroystokyo.paper.ClientOption$ChatVisibility"))
register(ExprChatVisibility.class, ClientOption.ChatVisibility.class,
"chat visibility", "players");
}
diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang
index 1102d974197..8b249d6c6b4 100644
--- a/src/main/resources/lang/default.lang
+++ b/src/main/resources/lang/default.lang
@@ -2301,13 +2301,6 @@ transform reasons:
unknown: unknown
infection: infection, villager infection
-# -- Chat Visibilities --
-chat visibilities:
- full: fully visible, visible
- hidden: hidden
- system: system messages only, only system messages, commands only, only commands
- unknown: unknown
-
# -- Boolean --
boolean:
true:
diff --git a/src/test/skript/junit/ExprChatVisibility.sk b/src/test/skript/junit/ExprChatVisibility.sk
index b6a667d8ee8..ad9c5f71c7f 100644
--- a/src/test/skript/junit/ExprChatVisibility.sk
+++ b/src/test/skript/junit/ExprChatVisibility.sk
@@ -8,7 +8,7 @@ on join:
set {_test} to "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprChatVisibilityTest"
junit test is {_test}
- if player's chat visibility is only commands:
+ if player can only see commands:
complete objective "chat visibility is only commands" for {_test}
if player doesn't have chat filtering enabled:
From 69fa64b22c92c80c92737b8d3f9fc25d7608a067 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sun, 22 Sep 2024 23:46:24 +0200
Subject: [PATCH 10/15] remove chat visibility type
---
.../java/ch/njol/skript/classes/data/BukkitClasses.java | 8 --------
1 file changed, 8 deletions(-)
diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
index d109d0133aa..a24ac37409c 100644
--- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
+++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
@@ -1534,14 +1534,6 @@ public String toVariableNameString(EnchantmentOffer eo) {
.name("Entity Potion Cause")
.description("Represents the cause of the action of a potion effect on an entity, e.g. arrow, command")
.since("INSERT VERSION"));
-
- if (Skript.classExists("com.destroystokyo.paper.ClientOption$ChatVisibility"))
- Classes.registerClass(new EnumClassInfo<>(ClientOption.ChatVisibility.class, "chatvisibility", "chat visibilities")
- .user("chat ?visibility")
- .name("Chat Visibility")
- .description("The chat visibility of a player.")
- .requiredPlugins("Paper")
- .since("INSERT VERSION"));
}
}
From a8a7d74d06cfa89f7825df56994b2c24e2a1fda2 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sun, 22 Sep 2024 23:47:36 +0200
Subject: [PATCH 11/15] remove old
---
.../expressions/ExprChatVisibility.java | 41 -------------------
1 file changed, 41 deletions(-)
delete mode 100644 src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java b/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
deleted file mode 100644
index 2c2ec95bf1d..00000000000
--- a/src/main/java/ch/njol/skript/expressions/ExprChatVisibility.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package ch.njol.skript.expressions;
-
-import ch.njol.skript.Skript;
-import ch.njol.skript.doc.*;
-import ch.njol.skript.expressions.base.SimplePropertyExpression;
-import com.destroystokyo.paper.ClientOption;
-import org.bukkit.entity.Player;
-import org.jetbrains.annotations.Nullable;
-
-@Name("Chat Visibility")
-@Description("The chat visibility of a player. Can only be read.")
-@Examples({
- "if chat visibility of player is hidden or commands only:",
- "\tsend actionbar \"Server restart in 5 minutes\" to player"
-})
-@RequiredPlugins("Paper")
-@Since("INSERT VERSION")
-public class ExprChatVisibility extends SimplePropertyExpression {
-
- static {
- if (Skript.classExists("com.destroystokyo.paper.ClientOption$ChatVisibility"))
- register(ExprChatVisibility.class, ClientOption.ChatVisibility.class,
- "chat visibility", "players");
- }
-
- @Override
- public @Nullable ClientOption.ChatVisibility convert(Player from) {
- return from.getClientOption(ClientOption.CHAT_VISIBILITY);
- }
-
- @Override
- public Class getReturnType() {
- return ClientOption.ChatVisibility.class;
- }
-
- @Override
- protected String getPropertyName() {
- return "chat visibility";
- }
-
-}
From 15f2accd4e8bca042875bbaa7059fdeca6992a59 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sun, 22 Sep 2024 23:49:06 +0200
Subject: [PATCH 12/15] fix names
---
.../CondChatVisibilityTest.java} | 4 ++--
.../junit/{ExprChatVisibility.sk => CondChatVisibility.sk} | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
rename src/test/java/org/skriptlang/skript/test/tests/syntaxes/{expressions/ExprChatVisibilityTest.java => conditions/CondChatVisibilityTest.java} (90%)
rename src/test/skript/junit/{ExprChatVisibility.sk => CondChatVisibility.sk} (63%)
diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/conditions/CondChatVisibilityTest.java
similarity index 90%
rename from src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
rename to src/test/java/org/skriptlang/skript/test/tests/syntaxes/conditions/CondChatVisibilityTest.java
index 7e74fde8baf..1dbcdc98c19 100644
--- a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprChatVisibilityTest.java
+++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/conditions/CondChatVisibilityTest.java
@@ -1,4 +1,4 @@
-package org.skriptlang.skript.test.tests.syntaxes.expressions;
+package org.skriptlang.skript.test.tests.syntaxes.conditions;
import ch.njol.skript.Skript;
import ch.njol.skript.test.runner.SkriptJUnitTest;
@@ -10,7 +10,7 @@
import org.junit.Before;
import org.junit.Test;
-public class ExprChatVisibilityTest extends SkriptJUnitTest {
+public class CondChatVisibilityTest extends SkriptJUnitTest {
private static final boolean SUPPORTS_CHAT_VISIBILITY =
Skript.classExists("com.destroystokyo.paper.ClientOption$ChatVisibility");
diff --git a/src/test/skript/junit/ExprChatVisibility.sk b/src/test/skript/junit/CondChatVisibility.sk
similarity index 63%
rename from src/test/skript/junit/ExprChatVisibility.sk
rename to src/test/skript/junit/CondChatVisibility.sk
index ad9c5f71c7f..9ce5f39dd9c 100644
--- a/src/test/skript/junit/ExprChatVisibility.sk
+++ b/src/test/skript/junit/CondChatVisibility.sk
@@ -1,11 +1,11 @@
-test "ExprChatVisibilityJUnit" when running JUnit:
+test "CondChatVisibilityJUnit" when running JUnit:
set {_tests::1} to "chat visibility is only commands"
set {_tests::2} to "no chat filtering"
set {_tests::3} to "can see chat colours"
- ensure junit test "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprChatVisibilityTest" completes {_tests::*}
+ ensure junit test "org.skriptlang.skript.test.tests.syntaxes.conditions.CondChatVisibilityTest" completes {_tests::*}
on join:
- set {_test} to "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprChatVisibilityTest"
+ set {_test} to "org.skriptlang.skript.test.tests.syntaxes.conditions.CondChatVisibilityTest"
junit test is {_test}
if player can only see commands:
From 7081e209197bbf291b0cb7a041d4c1e2a68c9ee4 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Thu, 26 Sep 2024 06:19:02 +0200
Subject: [PATCH 13/15] oops
---
src/main/java/ch/njol/skript/classes/data/BukkitClasses.java | 1 -
src/main/java/ch/njol/skript/conditions/CondChatVisibility.java | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
index a24ac37409c..63e98bca90f 100644
--- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
+++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
@@ -30,7 +30,6 @@
import java.util.stream.Collectors;
import ch.njol.skript.bukkitutil.BukkitUtils;
-import com.destroystokyo.paper.ClientOption;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Difficulty;
diff --git a/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java b/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java
index 59d19fb57de..37aa08d3919 100644
--- a/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java
+++ b/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java
@@ -81,4 +81,5 @@ public String toString(@Nullable Event event, boolean debug) {
default -> throw new IllegalStateException("Unexpected value: " + pattern);
};
}
+
}
From 54dee32e9b44550a926f4c06c4e66f73b7b933ba Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Thu, 26 Sep 2024 06:19:43 +0200
Subject: [PATCH 14/15] oops
---
src/main/java/ch/njol/skript/classes/data/BukkitClasses.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
index 63e98bca90f..94b5fe789c4 100644
--- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
+++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
@@ -1527,7 +1527,6 @@ public String toVariableNameString(EnchantmentOffer eo) {
.name("Transform Reason")
.description("Represents a transform reason of an entity transform event.")
.since("2.8.0"));
-
Classes.registerClass(new EnumClassInfo<>(EntityPotionEffectEvent.Cause.class, "entitypotioncause", "entity potion causes")
.user("(entity )?potion ?effect ?cause")
.name("Entity Potion Cause")
From 0a704de9194faa40d792773e20aab287b1270979 Mon Sep 17 00:00:00 2001
From: Efnilite <35348263+Efnilite@users.noreply.github.com>
Date: Sun, 29 Sep 2024 11:46:27 +0200
Subject: [PATCH 15/15] aight
---
.../java/ch/njol/skript/conditions/CondChatVisibility.java | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java b/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java
index 37aa08d3919..b8045cc952f 100644
--- a/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java
+++ b/src/main/java/ch/njol/skript/conditions/CondChatVisibility.java
@@ -1,10 +1,7 @@
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
-import ch.njol.skript.doc.Description;
-import ch.njol.skript.doc.Examples;
-import ch.njol.skript.doc.Name;
-import ch.njol.skript.doc.Since;
+import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
@@ -24,6 +21,7 @@
"if player can't see any messages:",
"\tsend action bar \"Server shutting down in 5 minutes!\""
})
+@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class CondChatVisibility extends Condition {