From 0de469e5148b9489bb70f6c9657488d9e3d510ef Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 8 Aug 2017 15:08:43 +0200 Subject: [PATCH 1/3] No longer sending messages to those who disabled it --- .travis.yml | 23 +++++++++++++++++++ deploy.sh | 10 ++++++++ pom.xml | 6 +++++ .../buttondevteam/chat/ChatProcessing.java | 8 ++++--- .../java/buttondevteam/chat/VanillaUtils.java | 18 +++++++++++++++ 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 deploy.sh create mode 100644 src/main/java/buttondevteam/chat/VanillaUtils.java diff --git a/.travis.yml b/.travis.yml index 9bcf999..dfd0224 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,26 @@ +cache: + directories: + - $HOME/.m2/repository/org/ +before_install: | # Wget BuildTools and run if cached folder not found + if [ ! -d "$HOME/.m2/repository/org/spigotmc/spigot/1.12.1-R0.1-SNAPSHOT" ]; then + wget -O BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar + # grep so that download counts don't appear in log files + java -jar BuildTools.jar --rev 1.12.1 | grep -vE "[^/ ]*/[^/ ]*\s*KB\s*$" | grep -v "^\s*$" + fi language: java jdk: - oraclejdk8 +sudo: true +deploy: + # deploy develop to the staging environment + - provider: script + script: chmod +x deploy.sh && sh deploy.sh staging + on: + branch: dev + skip_cleanup: true + # deploy master to production + - provider: script + script: chmod +x deploy.sh && sh deploy.sh production + on: + branch: master + skip_cleanup: true diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..606423b --- /dev/null +++ b/deploy.sh @@ -0,0 +1,10 @@ +#!/bin/sh +FILENAME=$(find target/ -maxdepth 1 ! -name '*original*' -name '*.jar') +echo Found file: $FILENAME + +if [ $1 = 'production' ]; then +echo Production mode +echo $UPLOAD_KEY > upload_key +chmod 400 upload_key +yes | scp -B -i upload_key -o StrictHostKeyChecking=no $FILENAME travis@server.figytuna.com:/minecraft/main/plugins +fi diff --git a/pom.xml b/pom.xml index c1b0016..b3918e0 100644 --- a/pom.xml +++ b/pom.xml @@ -169,6 +169,12 @@ 1.16.16 provided + + org.spigotmc + spigot + 1.12-R0.1-SNAPSHOT + provided + ButtonChat diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 4b40d66..b45db0a 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -131,9 +131,11 @@ public class ChatProcessing { if (channel.filteranderrormsg != null) { Objective obj = PluginMain.SB.getObjective(channel.ID); int score = -1; - for (Player p : Bukkit.getOnlinePlayers()) - obj.getScore(p.getName()).setScore( - p.getUniqueId().equals(player.getUniqueId()) ? score = e.getMCScore(p) : e.getMCScore(p)); + for (Player p : Bukkit.getOnlinePlayers()) { + final int mcScore = VanillaUtils.getMCScoreIfChatOn(p, e); + obj.getScore(p.getName()) + .setScore(p.getUniqueId().equals(player.getUniqueId()) ? score = mcScore : mcScore); + } PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String.format( "tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, score, jsonstr)); } else diff --git a/src/main/java/buttondevteam/chat/VanillaUtils.java b/src/main/java/buttondevteam/chat/VanillaUtils.java new file mode 100644 index 0000000..68f749b --- /dev/null +++ b/src/main/java/buttondevteam/chat/VanillaUtils.java @@ -0,0 +1,18 @@ +package buttondevteam.chat; + +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import buttondevteam.lib.TBMCChatEvent; +import lombok.experimental.UtilityClass; +import net.minecraft.server.v1_12_R1.EntityHuman.EnumChatVisibility; + +@UtilityClass +public class VanillaUtils { + public int getMCScoreIfChatOn(Player p, TBMCChatEvent e) { + if (!(p instanceof CraftPlayer) || ((CraftPlayer) p).getHandle().getChatFlags() == EnumChatVisibility.FULL) // Only send if client allows chat + return e.getMCScore(p); + else + return -1; + } +} From 51c3e1dec6a34dc5c87981e1b021d78be0e189c6 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 17 Aug 2017 17:31:17 +0200 Subject: [PATCH 2/3] Added /lenny and made tests optional + a fix --- pom.xml | 18 ++++++++++++++- .../commands/appendtext/LennyCommand.java | 18 +++++++++++++++ ...{ChatFormatTest.java => ChatFormatIT.java} | 23 +++++++++---------- 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java rename src/test/java/buttondevteam/chat/{ChatFormatTest.java => ChatFormatIT.java} (74%) diff --git a/pom.xml b/pom.xml index b3918e0..e093f58 100644 --- a/pom.xml +++ b/pom.xml @@ -82,6 +82,22 @@ + + org.apache.maven.plugins + maven-failsafe-plugin + 2.12.4 + + + + integration-test + verify + + + + + true + + buttondevteam @@ -121,7 +137,7 @@ org.spigotmc spigot-api - 1.12-R0.1-SNAPSHOT + 1.12.1-R0.1-SNAPSHOT com.github.TBMCPlugins.ButtonCore diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java new file mode 100644 index 0000000..c106f4a --- /dev/null +++ b/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java @@ -0,0 +1,18 @@ +package buttondevteam.chat.commands.appendtext; + +public final class LennyCommand extends AppendTextCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Lenny ----", // + "This command appends a Lenny face after your message", // + "Or just sends ne", // + "Use either /" + alias + " or just /" + alias }; // + } + + @Override + public String GetAppendedText() { + return "( ͡° ͜ʖ ͡°)"; + } + +} diff --git a/src/test/java/buttondevteam/chat/ChatFormatTest.java b/src/test/java/buttondevteam/chat/ChatFormatIT.java similarity index 74% rename from src/test/java/buttondevteam/chat/ChatFormatTest.java rename to src/test/java/buttondevteam/chat/ChatFormatIT.java index 9e97bf0..19c8f59 100644 --- a/src/test/java/buttondevteam/chat/ChatFormatTest.java +++ b/src/test/java/buttondevteam/chat/ChatFormatIT.java @@ -21,7 +21,7 @@ import buttondevteam.lib.chat.Color; import junit.framework.TestCase; @RunWith(ObjectTestRunner.class) -public class ChatFormatTest extends TestCase { +public class ChatFormatIT extends TestCase { @Objects public static List data() { TestPrepare.PrepareServer(); @@ -30,18 +30,18 @@ public class ChatFormatTest extends TestCase { List list = new ArrayList(); - list.add(new ChatFormatTest(sender, "*test*", new TellrawPart("test").setItalic(true).setColor(Color.White))); - list.add(new ChatFormatTest(sender, "**test**", new TellrawPart("test").setBold(true).setColor(Color.White))); - list.add(new ChatFormatTest(sender, "***test***", + list.add(new ChatFormatIT(sender, "*test*", new TellrawPart("test").setItalic(true).setColor(Color.White))); + list.add(new ChatFormatIT(sender, "**test**", new TellrawPart("test").setBold(true).setColor(Color.White))); + list.add(new ChatFormatIT(sender, "***test***", new TellrawPart("test").setBold(true).setItalic(true).setColor(Color.White))); - list.add(new ChatFormatTest(sender, "***_test_***", + list.add(new ChatFormatIT(sender, "***_test_***", new TellrawPart("test").setBold(true).setItalic(true).setUnderlined(true).setColor(Color.White))); - list.add(new ChatFormatTest(sender, "***_~~test~~_***", new TellrawPart("test").setBold(true).setItalic(true) + list.add(new ChatFormatIT(sender, "***_~~test~~_***", new TellrawPart("test").setBold(true).setItalic(true) .setUnderlined(true).setStrikethrough(true).setColor(Color.White))); - list.add(new ChatFormatTest(sender, "¯\\\\\\_(ツ)\\_/¯", new TellrawPart("¯").setColor(Color.White), + list.add(new ChatFormatIT(sender, "¯\\\\\\_(ツ)\\_/¯", new TellrawPart("¯").setColor(Color.White), new TellrawPart("\\").setColor(Color.White), new TellrawPart("_(ツ)").setColor(Color.White), new TellrawPart("_/¯").setColor(Color.White))); - list.add(new ChatFormatTest(sender, "https://google.hu/", + list.add(new ChatFormatIT(sender, "https://google.hu/", new TellrawPart("https://google.hu/").setColor(Color.White).setUnderlined(true) .setHoverEvent(TellrawEvent.create(HoverAction.SHOW_TEXT, new TellrawPart("Click to open").setColor(Color.Blue))) @@ -54,7 +54,7 @@ public class ChatFormatTest extends TestCase { private final String message; private final TellrawPart[] extras; - public ChatFormatTest(CommandSender sender, String message, TellrawPart... expectedextras) { + public ChatFormatIT(CommandSender sender, String message, TellrawPart... expectedextras) { this.sender = sender; this.message = message; this.extras = expectedextras; @@ -62,7 +62,7 @@ public class ChatFormatTest extends TestCase { @Test public void testMessage() { - /*ArrayList cfs = ChatProcessing.addFormatters(Color.White); + ArrayList cfs = ChatProcessing.addFormatters(Color.White); final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender, null); final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, chid); ChatFormatter.Combine(cfs, message, tp); @@ -72,7 +72,6 @@ public class ChatFormatTest extends TestCase { // System.out.println("Raw: " + ChatProcessing.toJson(expectedtp)); for (TellrawPart extra : extras) expectedtp.addExtra(extra); - assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp));*/ - assertTrue(true); + assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp)); } } From 16acba643f3afe60dd9185921d4b975123412e0f Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 17 Aug 2017 17:49:15 +0200 Subject: [PATCH 3/3] Added 3 chars --- pom.xml | 2 +- .../buttondevteam/chat/commands/appendtext/LennyCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e093f58..58c30ba 100644 --- a/pom.xml +++ b/pom.xml @@ -188,7 +188,7 @@ org.spigotmc spigot - 1.12-R0.1-SNAPSHOT + 1.12.1-R0.1-SNAPSHOT provided diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java index c106f4a..8d04cf2 100644 --- a/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java +++ b/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java @@ -6,7 +6,7 @@ public final class LennyCommand extends AppendTextCommandBase { public String[] GetHelpText(String alias) { return new String[] { "§6---- Lenny ----", // "This command appends a Lenny face after your message", // - "Or just sends ne", // + "Or just sends one", // "Use either /" + alias + " or just /" + alias }; // }