From 884c430fd41d21adb2e0d001b937cfcd71ae8cf5 Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Sat, 28 Sep 2019 18:29:38 -0700 Subject: [PATCH 01/12] Updated dependencies, updated hooks, and now allowing http connections to repos instead of forcing https --- plugin/pom.xml | 8 ++++---- .../radbuilder/emojichat/hooks/PlaceholderApiHook.java | 4 ++-- .../radbuilder/emojichat/hooks/TelegramChatHook.java | 5 +++-- pom.xml | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/plugin/pom.xml b/plugin/pom.xml index 8ce99a2..7e8e428 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -81,13 +81,13 @@ com.discordsrv discordsrv - 1.16.6 + 1.17.1 provided be.maximvdw MVdWPlaceholderAPI - 2.1.1-SNAPSHOT + 3.0.1-SNAPSHOT org.spigotmc @@ -98,13 +98,13 @@ me.clip placeholderapi - 2.9.2 + 2.10.4 provided com.github.mastercake10 TelegramChat - 1.0.9.9 + 1.0.14 \ No newline at end of file diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/PlaceholderApiHook.java b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/PlaceholderApiHook.java index 0d0f75b..cf36e2f 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/PlaceholderApiHook.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/PlaceholderApiHook.java @@ -9,7 +9,7 @@ * PlaceholderAPI hook. * * @author RadBuilder - * @version 1.7 + * @version 1.8.3 * @since 1.4 */ public class PlaceholderApiHook implements EmojiChatHook { @@ -29,7 +29,7 @@ public class PlaceholderApiHook implements EmojiChatHook { */ public PlaceholderApiHook(EmojiChat plugin) { this.plugin = plugin; - PlaceholderAPI.registerPlaceholderHook(plugin, new PlaceholderHook() { + PlaceholderAPI.registerPlaceholderHook("EmojiChat", new PlaceholderHook() { @Override public String onPlaceholderRequest(Player player, String identifier) { if (player != null && !player.hasPermission("emojichat.use")) // Make sure the player, if specified, has permission to use emojis diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/TelegramChatHook.java b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/TelegramChatHook.java index a9ed4a3..0d40472 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/TelegramChatHook.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/TelegramChatHook.java @@ -5,6 +5,7 @@ import de.Linus122.TelegramChat.TelegramActionListener; import de.Linus122.TelegramComponents.Chat; import de.Linus122.TelegramComponents.ChatMessageToMc; +import de.Linus122.TelegramComponents.ChatMessageToTelegram; import io.github.radbuilder.emojichat.EmojiChat; import org.apache.commons.lang.StringUtils; @@ -12,7 +13,7 @@ * TelegramChat hook. * * @author RadBuilder - * @version 1.7 + * @version 1.8.3 * @since 1.7 */ public class TelegramChatHook implements EmojiChatHook { @@ -30,7 +31,7 @@ public TelegramChatHook(EmojiChat plugin) { Telegram telegram = API.getTelegramHook(); telegram.addListener(new TelegramActionListener() { @Override - public void onSendToTelegram(Chat chat) { + public void onSendToTelegram(ChatMessageToTelegram chat) { // Replace emojis with shortcuts for (String key : plugin.getEmojiHandler().getEmojis().keySet()) { // Don't count metrics as it's already counted in the normal chat listener diff --git a/pom.xml b/pom.xml index f84943a..ecf84b8 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ - clean package install + clean package install -Dmaven.wagon.http.ssl.insecure=true ${project.name} src/main/java From 3307bed2da88b47dee6b355ebc2027c1eda2c1dd Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Sat, 28 Sep 2019 18:34:22 -0700 Subject: [PATCH 02/12] Fixed Travis and GitHub Actions workflow Allowing http connections instead of forcing https --- .github/workflows/maven.yml | 2 +- .travis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 73ac252..1f3167d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -14,4 +14,4 @@ jobs: with: java-version: 1.8 - name: Build with Maven - run: mvn package --file pom.xml + run: mvn package --file pom.xml -Dmaven.wagon.http.ssl.insecure=true diff --git a/.travis.yml b/.travis.yml index 58a1e9b..c6ae9ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: java sudo: false -script: mvn clean verify \ No newline at end of file +script: mvn clean verify -Dmaven.wagon.http.ssl.insecure=true \ No newline at end of file From af29ab8dbfcc38275111e78ce85e70fc2dd4a2c0 Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Sat, 28 Sep 2019 18:39:35 -0700 Subject: [PATCH 03/12] Last try to get Travis working --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c6ae9ec..7161590 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: java sudo: false -script: mvn clean verify -Dmaven.wagon.http.ssl.insecure=true \ No newline at end of file +script: mvn package --file pom.xml -Dmaven.wagon.http.ssl.insecure=true \ No newline at end of file From 21b889281c4ea21aa5fccdefa96d3e144d6cc4d6 Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Sun, 29 Sep 2019 09:54:13 -0700 Subject: [PATCH 04/12] Changed Travis build script --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7161590..2aa140d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: java sudo: false -script: mvn package --file pom.xml -Dmaven.wagon.http.ssl.insecure=true \ No newline at end of file +script: mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true package --file pom.xml \ No newline at end of file From 4694a1129fd64021b61266c4265b2090c7ce213a Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Sun, 29 Sep 2019 16:01:17 -0700 Subject: [PATCH 05/12] Change Travis install script --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 2aa140d..f78d4ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: java sudo: false +install: mvn install -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -DskipTests=true -Dmaven.javadoc.skip=true -B -V script: mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true package --file pom.xml \ No newline at end of file From 7e0831f3cc01065d5797627ee3fda30b0f0f74e5 Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Mon, 30 Sep 2019 14:00:30 -0700 Subject: [PATCH 06/12] Added ability to escape emoji shortcuts with backslash, fixed issue with http:// and https:// converting to emoji --- .../emojichat/metrics/MetricsHandler.java | 25 ++++++++++++++-- .../emojichat/utils/EmojiHandler.java | 30 +++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/metrics/MetricsHandler.java b/plugin/src/main/java/io/github/radbuilder/emojichat/metrics/MetricsHandler.java index dbf98db..d3fc66f 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/metrics/MetricsHandler.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/metrics/MetricsHandler.java @@ -10,7 +10,7 @@ * Metrics handler class. * * @author RadBuilder - * @version 1.8 + * @version 1.8.3 * @since 1.4 */ public class MetricsHandler { @@ -22,6 +22,10 @@ public class MetricsHandler { * The number of shortcuts used. */ private int shortcutsUsed; + /** + * The number of escapes used. + */ + private int escapesUsed; /** * The {@link MetricsLevel} being used. */ @@ -35,6 +39,7 @@ public class MetricsHandler { public MetricsHandler(EmojiChat plugin) { emojisUsed = 0; shortcutsUsed = 0; + escapesUsed = 0; try { metricsLevel = MetricsLevel.valueOf(plugin.getConfig().getString("metrics-collection")); @@ -117,7 +122,14 @@ public MetricsHandler(EmojiChat plugin) { shortcutsUsed = 0; // Reset the number of shortcuts used when this is called return temp; })); - + + // The number of escapes used + metrics.addCustomChart(new Metrics.SingleLineChart("escapesUsed", () -> { + int temp = escapesUsed; + escapesUsed = 0; // Reset the number of escapes used when this is called + return temp; + })); + // Which pack variant is being used metrics.addCustomChart(new Metrics.SimplePie("packVariant", () -> String.valueOf(plugin.getConfig().getInt("pack-variant")))); @@ -146,6 +158,15 @@ public void addEmojiUsed(int emojisUsed) { public void addShortcutUsed(int shortcutsUsed) { this.shortcutsUsed += shortcutsUsed; } + + /** + * Adds the specified number of escapes used to {@link #escapesUsed}. + * + * @param escapesUsed The number of escapes used to add to {@link #escapesUsed}. + */ + public void addEscapesUsed(int escapesUsed) { + this.escapesUsed += escapesUsed; + } } /** diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java index 3870403..1e8b888 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java @@ -19,7 +19,7 @@ * Emoji handler class. * * @author RadBuilder - * @version 1.7 + * @version 1.8.3 * @since 1.4 */ public class EmojiHandler { @@ -296,9 +296,33 @@ public String toEmojiFromChat(String message) { * @return The message with correct emoji shortcuts. */ public String translateShorthand(String message) { + message = message.replace("http://", "http\\://").replace("https://", "https\\://"); + StringBuilder replaced = new StringBuilder(); + int previousPosition = 0; + + // Go through all shortcuts for (String key : plugin.getEmojiHandler().getShortcuts().keySet()) { - plugin.getMetricsHandler().addShortcutUsed(StringUtils.countMatches(message, key)); - message = message.replace(key, plugin.getEmojiHandler().getShortcuts().get(key)); + // If the message has the shortcut + if (message.contains(key)) { + // Find location in string of occurrences of shortcut (going forward) + for (int i = -1; (i = message.indexOf(key, i + 1)) != -1; i++) { + // If character before shortcut is not an escape character + if (i - 1 < 0 || message.charAt(i - 1) != '\\') { // Then replace shortcut with emoji + replaced.append(message.substring(previousPosition, i)).append(getShortcuts().get(key)); // Add previous text and emoji, but not anything after to prevent replacement issue later + plugin.getMetricsHandler().addShortcutUsed(1); + previousPosition = i + key.length(); + } else { // Otherwise remove backslash as it's cancelling an emoji + replaced.append(message.substring(previousPosition, i - 1)).append(message.substring(i, i + key.length())); // Add previous text and remove backslash, exclude the matched key but not anything after + plugin.getMetricsHandler().addEscapesUsed(1); + previousPosition = i + key.length(); + } + } + } + // Reset necessary variables for next shortcut + replaced.append(message.substring(previousPosition)); // Add remaining text + previousPosition = 0; + message = replaced.toString(); + replaced = new StringBuilder(); } return message; } From 1202c557eb61679a4c5ac345a1a19dd6038e4df5 Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Mon, 30 Sep 2019 21:13:34 -0700 Subject: [PATCH 07/12] Misc adjustments --- .../radbuilder/emojichat/EmojiChatGui.java | 6 +++--- .../utils/EmojiChatUpdateChecker.java | 6 +++--- .../emojichat/utils/EmojiHandler.java | 18 +++++++++--------- .../emojichat/utils/EmojiPackVariant.java | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatGui.java b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatGui.java index 7941b5c..649651a 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatGui.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatGui.java @@ -15,8 +15,8 @@ * EmojiChat gui class. * * @author RadBuilder + * @version 1.8.3 * @since 1.2 - * @version 1.5 */ class EmojiChatGui { /** @@ -92,8 +92,8 @@ private void addNextArrow(Inventory gui) { * Adds an EmojiList item to the gui specified. * * @param gui The gui {@link org.bukkit.inventory.Inventory}. - * @param keyList The list of {@link EmojiHandler#emojis} keys. - * @param emojiMapPosition The current position in the {@link EmojiHandler#emojis}. + * @param keyList The list of emoji keys. + * @param emojiMapPosition The current position in the emoji map, {@link EmojiHandler#getEmojis()}. */ private void addItem(Inventory gui, List keyList, int emojiMapPosition) { ItemStack stack = new ItemStack(Material.PAPER, 1); diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatUpdateChecker.java b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatUpdateChecker.java index fa84260..513d475 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatUpdateChecker.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatUpdateChecker.java @@ -16,7 +16,7 @@ * EmojiChat update checker class. * * @author RadBuilder - * @version 1.8.1 + * @version 1.8.3 * @since 1.3 */ public class EmojiChatUpdateChecker { @@ -45,7 +45,7 @@ public class EmojiChatUpdateChecker { public EmojiChatUpdateChecker(EmojiChat plugin) { String version = plugin.getDescription().getVersion().replaceAll("[^0-9]", ""); // Make versions 3 characters long for int comparison, i.e. 1.8 -> 180, 1.8.1 -> 181, so 1.9 -> 190 not 19 - currentVersion = Integer.valueOf(version.length() < 3 ? version + "0" : version); + currentVersion = Integer.parseInt(version.length() < 3 ? version + "0" : version); updateTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this::checkForUpdates, 20L * 10L, 20L * 60L * 60L * 4L); // Start checking for updates after 10 seconds, then every 4 hours } @@ -67,7 +67,7 @@ private void checkForUpdates() { String version = ((JSONObject) value.get(value.size() - 1)).get("name").toString().replaceAll("[^0-9]", ""); // Make versions 3 characters long for int comparison, i.e. 1.8 -> 180, 1.8.1 -> 181, so 1.9 -> 190 not 19 - latestVersion = Integer.valueOf(version.length() < 3 ? version + "0" : version); + latestVersion = Integer.parseInt(version.length() < 3 ? version + "0" : version); updateAvailable = currentVersion < latestVersion; } catch (Exception ignored) { // Something happened, not sure what (possibly no internet connection), so no updates available diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java index 1e8b888..795d2b3 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java @@ -156,11 +156,11 @@ private void loadShortcuts(FileConfiguration config) { private void loadDisabledEmojis(FileConfiguration config, EmojiChat plugin) { if (config.getBoolean("disable-emojis")) { for (String disabledEmoji : config.getStringList("disabled-emojis")) { - if (disabledEmoji == null || !emojis.containsKey(disabledEmoji)) { + if (disabledEmoji == null || !getEmojis().containsKey(disabledEmoji)) { plugin.getLogger().warning("Invalid emoji specified in 'disabled-emojis': '" + disabledEmoji + "'. Skipping..."); continue; } - disabledCharacters.add(emojis.remove(disabledEmoji)); // Remove disabled emojis from the emoji list + disabledCharacters.add(getEmojis().remove(disabledEmoji)); // Remove disabled emojis from the emoji list } } } @@ -247,9 +247,9 @@ public void load(EmojiChat plugin) { * @return The converted message. */ public String toEmoji(String message) { - for (String key : emojis.keySet()) { + for (String key : getEmojis().keySet()) { plugin.getMetricsHandler().addEmojiUsed(StringUtils.countMatches(message, key)); - message = message.replace(key, plugin.getEmojiHandler().getEmojis().get(key).toString()); + message = message.replace(key, getEmojis().get(key).toString()); } return message; } @@ -261,9 +261,9 @@ public String toEmoji(String message) { * @return The converted line from sign. */ public String toEmojiFromSign(String line) { - for (String key : emojis.keySet()) { + for (String key : getEmojis().keySet()) { plugin.getMetricsHandler().addEmojiUsed(StringUtils.countMatches(line, key)); - line = line.replace(key, ChatColor.WHITE + "" + emojis.get(key) + ChatColor.BLACK); // Sets the emoji color to white for correct coloring + line = line.replace(key, ChatColor.WHITE + "" + getEmojis().get(key) + ChatColor.BLACK); // Sets the emoji color to white for correct coloring } return line; } @@ -281,9 +281,9 @@ public String toEmojiFromChat(String message) { } else { String chatColor = message.substring(0, 2); // Gets the chat color of the message, i.e. §a boolean hasColor = chatColor.contains("§"); - for (String key : emojis.keySet()) { + for (String key : getEmojis().keySet()) { plugin.getMetricsHandler().addEmojiUsed(StringUtils.countMatches(message, key)); - message = message.replace(key, ChatColor.WHITE + "" + emojis.get(key) + (hasColor ? chatColor : "")); // Sets the emoji color to white for correct coloring + message = message.replace(key, ChatColor.WHITE + "" + getEmojis().get(key) + (hasColor ? chatColor : "")); // Sets the emoji color to white for correct coloring } } return message; @@ -301,7 +301,7 @@ public String translateShorthand(String message) { int previousPosition = 0; // Go through all shortcuts - for (String key : plugin.getEmojiHandler().getShortcuts().keySet()) { + for (String key : getShortcuts().keySet()) { // If the message has the shortcut if (message.contains(key)) { // Find location in string of occurrences of shortcut (going forward) diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiPackVariant.java b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiPackVariant.java index 69616af..93797ae 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiPackVariant.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiPackVariant.java @@ -8,7 +8,7 @@ * The emoji replacement variant. * * @author RadBuilder - * @version 1.8.1 + * @version 1.8.3 * @since 1.7 */ public enum EmojiPackVariant { @@ -119,7 +119,7 @@ private byte[][] byteHash(int id) { String[] values = line.split(","); for (int i = 0; i < 20; i++) { - hash[i] = Byte.valueOf(values[i]); + hash[i] = Byte.parseByte(values[i]); } hashes[hashesPosition] = hash; hashesPosition++; From 7df5f94c90852573fc159f6d04a3ecbf1efac369 Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Mon, 30 Sep 2019 21:17:05 -0700 Subject: [PATCH 08/12] Fixed PlaceholderAPI deprecation --- .../github/radbuilder/emojichat/hooks/PlaceholderApiHook.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/PlaceholderApiHook.java b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/PlaceholderApiHook.java index cf36e2f..0927070 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/PlaceholderApiHook.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/PlaceholderApiHook.java @@ -63,6 +63,6 @@ public EmojiChatHookType getHookType() { @Override public void disable() { enabled = false; - PlaceholderAPI.unregisterPlaceholderHook(plugin); + PlaceholderAPI.unregisterPlaceholderHook("EmojiChat"); } } From 5f36f49520a126de458fe5e7bf486af12e6679cf Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Wed, 2 Oct 2019 19:53:36 -0700 Subject: [PATCH 09/12] Lowered listener priority for DiscordSrvHook --- .../io/github/radbuilder/emojichat/hooks/DiscordSrvHook.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/DiscordSrvHook.java b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/DiscordSrvHook.java index 07584d0..b68f316 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/DiscordSrvHook.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/DiscordSrvHook.java @@ -37,7 +37,7 @@ public DiscordSrvHook(EmojiChat plugin) { enabled = true; } - @Subscribe(priority = ListenerPriority.MONITOR) + @Subscribe(priority = ListenerPriority.HIGHEST) public void onChatMessageFromInGame(GameChatMessagePreProcessEvent event) { // From in-game to Discord if (!event.getPlayer().hasPermission("emojichat.use")) return; // Don't do anything if they don't have permission @@ -53,7 +53,7 @@ public void onChatMessageFromInGame(GameChatMessagePreProcessEvent event) { // F event.setMessage(message); } - @Subscribe(priority = ListenerPriority.MONITOR) + @Subscribe(priority = ListenerPriority.HIGHEST) public void onChatMessageFromDiscord(DiscordGuildMessagePostProcessEvent event) { // From Discord to in-game // TODO: Add permission checking for Discord String message = event.getProcessedMessage(); From 3c4e124faced11dd88bae1a604e7dd5f82b13dd5 Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Thu, 28 Nov 2019 08:54:10 -0800 Subject: [PATCH 10/12] Added hook for DiscordSRV Staff Chat --- plugin/pom.xml | 5 + .../radbuilder/emojichat/EmojiChat.java | 13 ++- .../hooks/DiscordSrvStaffChatHook.java | 103 ++++++++++++++++++ .../emojichat/hooks/EmojiChatHookType.java | 4 + plugin/src/main/resources/plugin.yml | 2 +- 5 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 plugin/src/main/java/io/github/radbuilder/emojichat/hooks/DiscordSrvStaffChatHook.java diff --git a/plugin/pom.xml b/plugin/pom.xml index 7e8e428..5c84ae0 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -84,6 +84,11 @@ 1.17.1 provided + + com.github.DiscordSRV + Staff-Chat + 1.3.0 + be.maximvdw MVdWPlaceholderAPI diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChat.java b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChat.java index 907d1db..0b90d13 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChat.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChat.java @@ -1,10 +1,6 @@ package io.github.radbuilder.emojichat; -import io.github.radbuilder.emojichat.hooks.DiscordSrvHook; -import io.github.radbuilder.emojichat.hooks.EmojiChatHook; -import io.github.radbuilder.emojichat.hooks.MVdWPlaceholderApiHook; -import io.github.radbuilder.emojichat.hooks.PlaceholderApiHook; -import io.github.radbuilder.emojichat.hooks.TelegramChatHook; +import io.github.radbuilder.emojichat.hooks.*; import io.github.radbuilder.emojichat.metrics.MetricsHandler; import io.github.radbuilder.emojichat.utils.EmojiChatConfigUpdater; import io.github.radbuilder.emojichat.utils.EmojiChatUpdateChecker; @@ -20,7 +16,7 @@ * EmojiChat main class. * * @author RadBuilder - * @version 1.7 + * @version 1.8.3 * @since 1.0 */ public class EmojiChat extends JavaPlugin { @@ -91,6 +87,11 @@ private void loadHooks() { if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) { // Hook DiscordSRV if installed enabledHooks.add(new DiscordSrvHook(this)); } + if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV-Staff-Chat")) { // Hook DiscordSRV Staff Chat if installed + DiscordSrvStaffChatHook discordSrvStaffChatHook = new DiscordSrvStaffChatHook(this); + enabledHooks.add(discordSrvStaffChatHook); + Bukkit.getPluginManager().registerEvents(discordSrvStaffChatHook, this); + } if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) { // Hook MVdWPlaceholderAPI if installed enabledHooks.add(new MVdWPlaceholderApiHook(this)); } diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/DiscordSrvStaffChatHook.java b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/DiscordSrvStaffChatHook.java new file mode 100644 index 0000000..1668bbd --- /dev/null +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/DiscordSrvStaffChatHook.java @@ -0,0 +1,103 @@ +package io.github.radbuilder.emojichat.hooks; + +import com.rezzedup.discordsrv.staffchat.events.DiscordStaffChatMessageEvent; +import com.rezzedup.discordsrv.staffchat.events.PlayerStaffChatMessageEvent; +import com.vdurmont.emoji.EmojiParser; +import io.github.radbuilder.emojichat.EmojiChat; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; + +/** + * DiscordSRV Staff Chat hook. + * + * @author RadBuilder + * @version 1.8.3 + * @since 1.8.3 + */ +public class DiscordSrvStaffChatHook implements EmojiChatHook, Listener { + /** + * EmojiChat main class instance. + */ + private final EmojiChat plugin; + /** + * If this hook is enabled. + */ + private boolean enabled; + + /** + * Creates the DiscordSRV Staff Chat hook with the main class instance. + * + * @param plugin The EmojiChat main class instance. + */ + public DiscordSrvStaffChatHook(EmojiChat plugin) { + this.plugin = plugin; + plugin.getLogger().info("Hooked " + getName()); + enabled = true; + } + + @EventHandler(priority = EventPriority.HIGH) + public void onDiscordStaffChat(DiscordStaffChatMessageEvent event) { + // TODO: Add permission checking for Discord + String message = EmojiParser.parseToAliases(event.getText()); // Call emoji translation before staff chat plugin does + + // Replace shortcuts with emojis + for (String key : plugin.getEmojiHandler().getEmojis().keySet()) { + plugin.getMetricsHandler().addEmojiUsed(StringUtils.countMatches(message, key)); // Count metrics + message = message.replace(key, plugin.getEmojiHandler().getEmojis().get(key).toString()); + } + event.setText(message); + } + + @EventHandler(priority = EventPriority.HIGH) + public void onMinecraftStaffChat(PlayerStaffChatMessageEvent event) { + if (!event.getAuthor().hasPermission("emojichat.use")) + return; // Don't do anything if they don't have permission + + String message = event.getText(); + + // Checks if the user disabled shortcuts via /emojichat toggle + if (!plugin.getEmojiHandler().hasShortcutsOff(event.getAuthor())) { + message = plugin.getEmojiHandler().translateShorthand(message); + } + + // Replace shortcuts with emojis + for (String key : plugin.getEmojiHandler().getEmojis().keySet()) { + // Metrics counted later + message = message.replace(key, plugin.getEmojiHandler().getEmojis().get(key).toString()); + } + + // If the message contains a disabled character + if (plugin.getEmojiHandler().containsDisabledCharacter(message)) { + event.setCancelled(true); + event.getAuthor().sendMessage(ChatColor.RED + "Oops! You can't use disabled emoji characters!"); + return; + } + + event.setText(message); // Calls DiscordGuildMessagePostProcessEvent + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public String getName() { + return "DiscordSRVStaffChat"; + } + + @Override + public EmojiChatHookType getHookType() { + return EmojiChatHookType.DISCORDSRVSTAFFCHAT; + } + + @Override + public void disable() { + HandlerList.unregisterAll(this); + enabled = false; + } +} diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/EmojiChatHookType.java b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/EmojiChatHookType.java index b9f6601..7dcbc00 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/EmojiChatHookType.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/EmojiChatHookType.java @@ -12,6 +12,10 @@ public enum EmojiChatHookType { * DiscordSRV plugin: https://www.spigotmc.org/resources/discordsrv.18494/ */ DISCORDSRV, + /** + * DiscordSRV Staff Chat: https://www.spigotmc.org/resources/discordsrv-staff-chat.44245/ + */ + DISCORDSRVSTAFFCHAT, /** * MVdWPlaceholderAPI plugin: https://www.spigotmc.org/resources/mvdwplaceholderapi.11182/ */ diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index e5107bd..67723aa 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -6,7 +6,7 @@ website: "https://github.com/RadBuilder/EmojiChat/" main: io.github.radbuilder.emojichat.EmojiChat api-version: 1.14 -softdepend: [DiscordSRV, MVdWPlaceholderAPI, PlaceholderAPI, TelegramChat] +softdepend: [DiscordSRV, DiscordSRV-Staff-Chat, MVdWPlaceholderAPI, PlaceholderAPI, TelegramChat] commands: emojichat: From b5f0c8842f9f2f6ab9bf3b9e054b37d7570af8dc Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Thu, 28 Nov 2019 08:59:19 -0800 Subject: [PATCH 11/12] Removed api-version from plugin.yml api-version 1.14 was preventing EmojiChat from running on earlier versions of Spigot --- plugin/src/main/resources/plugin.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index 67723aa..3f0c4fa 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -4,7 +4,6 @@ description: Adds emojis to your chat author: RadBuilder website: "https://github.com/RadBuilder/EmojiChat/" main: io.github.radbuilder.emojichat.EmojiChat -api-version: 1.14 softdepend: [DiscordSRV, DiscordSRV-Staff-Chat, MVdWPlaceholderAPI, PlaceholderAPI, TelegramChat] From 3bdad1ef9b8eace0fbcaa280505884b13b526ca9 Mon Sep 17 00:00:00 2001 From: RadBuilder Date: Thu, 28 Nov 2019 09:21:36 -0800 Subject: [PATCH 12/12] Updated version number to 1.8.3 --- plugin/pom.xml | 4 ++-- .../java/io/github/radbuilder/emojichat/EmojiChatCommand.java | 4 ++-- plugin/src/main/resources/plugin.yml | 2 +- pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugin/pom.xml b/plugin/pom.xml index 5c84ae0..2514132 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -7,7 +7,7 @@ io.github.radbuilder emojichat-parent - 1.8.2 + 1.8.3 @@ -18,7 +18,7 @@ EmojiChat Plugin emojichat-plugin - 1.8.2 + 1.8.3 jar diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatCommand.java b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatCommand.java index 22e092f..f793f29 100644 --- a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatCommand.java +++ b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatCommand.java @@ -10,7 +10,7 @@ * EmojiChat command class. * * @author RadBuilder - * @version 1.8.2 + * @version 1.8.3 * @since 1.0 */ class EmojiChatCommand implements CommandExecutor { @@ -31,7 +31,7 @@ class EmojiChatCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { if (args.length < 1) { - sender.sendMessage(ChatColor.AQUA + "EmojiChat v1.8.2 by RadBuilder"); + sender.sendMessage(ChatColor.AQUA + "EmojiChat v1.8.3 by RadBuilder"); sender.sendMessage(ChatColor.AQUA + "Use " + ChatColor.GREEN + "/emojichat help" + ChatColor.AQUA + " for help."); return true; } diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index 3f0c4fa..76b2449 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: EmojiChat -version: 1.8.2 +version: 1.8.3 description: Adds emojis to your chat author: RadBuilder website: "https://github.com/RadBuilder/EmojiChat/" diff --git a/pom.xml b/pom.xml index ecf84b8..44a6d7c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.github.radbuilder EmojiChat Parent emojichat-parent - 1.8.2 + 1.8.3 pom