diff --git a/src/main/java/ch/njol/skript/expressions/ExprMessage.java b/src/main/java/ch/njol/skript/expressions/ExprMessage.java index a3b54f43c4c..b973852dcc5 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprMessage.java +++ b/src/main/java/ch/njol/skript/expressions/ExprMessage.java @@ -48,23 +48,27 @@ @SuppressWarnings("deprecation") @Name("Message") @Description("The (chat) message of a chat event, the join message of a join event, the quit message of a quit event, or the death message on a death event. This expression is mostly useful for being changed.") -@Examples({"on chat:", - " player has permission \"admin\"", - " set message to \"&c%message%\"", +@Examples({ + "on chat:", + "\tplayer has permission \"admin\"", + "\tset message to \"&c%message%\"", "", "on first join:", - " set join message to \"Welcome %player% to our awesome server!\"", + "\tset join message to \"Welcome %player% to our awesome server!\"", "", "on join:", - " player has played before", - " set join message to \"Welcome back, %player%!\"", + "\tplayer has played before", + "\tset join message to \"Welcome back, %player%!\"", "", "on quit:", - " set quit message to \"%player% left this awesome server!\"", + "\tif {vanish::%player's uuid%} is set:", + "\t\tclear quit message", + "\telse:", + "\t\tset quit message to \"%player% left this awesome server!\"", "", "on death:", - " set the death message to \"%player% died!\""}) -@Since("1.4.6 (chat message), 1.4.9 (join & quit messages), 2.0 (death message)") + "\tset the death message to \"%player% died!\""}) +@Since("1.4.6 (chat message), 1.4.9 (join & quit messages), 2.0 (death message), INSERT VERSION (clear message)") @Events({"chat", "join", "quit", "death"}) public class ExprMessage extends SimpleExpression { @@ -181,18 +185,18 @@ protected String[] get(final Event e) { @Override @Nullable public Class[] acceptChange(final ChangeMode mode) { - if (mode == ChangeMode.SET) + if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) return CollectionUtils.array(String.class); return null; } @Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { - assert mode == ChangeMode.SET; - assert delta != null; + assert mode == ChangeMode.SET || mode == ChangeMode.DELETE; for (final Class c : type.events) { - if (c.isInstance(e)) - type.set(e, "" + delta[0]); + if (c.isInstance(e)) { + type.set(e, (mode == ChangeMode.DELETE) ? "" : delta[0].toString()); + } } } diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/ExprDropsTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprDropsTest.java similarity index 94% rename from src/test/java/org/skriptlang/skript/test/tests/syntaxes/ExprDropsTest.java rename to src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprDropsTest.java index f9216d5352c..f9f9c372176 100644 --- a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/ExprDropsTest.java +++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprDropsTest.java @@ -16,7 +16,7 @@ * * Copyright Peter Güttinger, SkriptLang team and contributors */ -package org.skriptlang.skript.test.tests.syntaxes; +package org.skriptlang.skript.test.tests.syntaxes.expressions; import ch.njol.skript.test.runner.SkriptJUnitTest; import org.bukkit.entity.Pig; diff --git a/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprMessageTest.java b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprMessageTest.java new file mode 100644 index 00000000000..1b0cbefa703 --- /dev/null +++ b/src/test/java/org/skriptlang/skript/test/tests/syntaxes/expressions/ExprMessageTest.java @@ -0,0 +1,53 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package org.skriptlang.skript.test.tests.syntaxes.expressions; + +import ch.njol.skript.test.runner.SkriptJUnitTest; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.PluginManager; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +public class ExprMessageTest extends SkriptJUnitTest { + + private Player testPlayer; + + @Before + public void setup() { + testPlayer = EasyMock.niceMock(Player.class); + } + + @Test + public void test() { + Set viewers = new HashSet<>(); + viewers.add(testPlayer); + PluginManager manager = Bukkit.getServer().getPluginManager(); + manager.callEvent(new AsyncPlayerChatEvent(false, testPlayer, "hi", viewers)); + manager.callEvent(new PlayerJoinEvent(testPlayer, "hi")); + manager.callEvent(new PlayerQuitEvent(testPlayer, "hi")); + } +} diff --git a/src/test/skript/junit/ExprDrops.sk b/src/test/skript/junit/ExprDrops.sk index 3df908f9f03..c13fe31671f 100644 --- a/src/test/skript/junit/ExprDrops.sk +++ b/src/test/skript/junit/ExprDrops.sk @@ -12,13 +12,13 @@ test "ExprDropsJUnit" when running JUnit: set {_tests::11} to "add and remove experience from drops doesn't modify items" set {_tests::12} to "remove all experience from drops doesn't modify items" set {_tests::13} to "drops test complete" - ensure junit test "org.skriptlang.skript.test.tests.syntaxes.ExprDropsTest" completes {_tests::*} + ensure junit test "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprDropsTest" completes {_tests::*} # NOTE: Do NOT take the behavior described in this test as a guide for how ExprDrops SHOULD work, only for how it DOES work in 2.7.x. # The behavior should change in 2.8 and this test will be updated accordingly. on death of pig: - set {_test} to "org.skriptlang.skript.test.tests.syntaxes.ExprDropsTest" + set {_test} to "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprDropsTest" junit test is {_test} # Items diff --git a/src/test/skript/junit/ExprMessage.sk b/src/test/skript/junit/ExprMessage.sk new file mode 100644 index 00000000000..656e4d88109 --- /dev/null +++ b/src/test/skript/junit/ExprMessage.sk @@ -0,0 +1,44 @@ +test "ExprMessageJUnit" when running JUnit: + set {_tests::1} to "set chat message" + set {_tests::2} to "clear chat message" + set {_tests::3} to "set join message" + set {_tests::4} to "clear join message" + set {_tests::5} to "set quit message" + set {_tests::6} to "clear quit message" + ensure junit test "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprMessageTest" completes {_tests::*} + +on chat: + set {_test} to "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprMessageTest" + junit test is {_test} + + set chat message to "hello" + if chat message is "hello": + complete objective "set chat message" for {_test} + + clear message + if message is "": + complete objective "clear chat message" for {_test} + +on join: + set {_test} to "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprMessageTest" + junit test is {_test} + + set login message to "I joined" + if log in message is "I joined": + complete objective "set join message" for {_test} + + clear join message + if join message is "": + complete objective "clear join message" for {_test} + +on quit: + set {_test} to "org.skriptlang.skript.test.tests.syntaxes.expressions.ExprMessageTest" + junit test is {_test} + + set logout message to "I left" + if log out message is "I left": + complete objective "set quit message" for {_test} + + clear quit message + if leave message is "": + complete objective "clear quit message" for {_test} \ No newline at end of file