diff --git a/assets/unicode pages/unicode_page_ad.psd b/assets/unicode pages/unicode_page_ad.psd
index a04672c..bcf1fc0 100644
Binary files a/assets/unicode pages/unicode_page_ad.psd and b/assets/unicode pages/unicode_page_ad.psd differ
diff --git a/assets/unicode pages/unicode_page_ad.xcf b/assets/unicode pages/unicode_page_ad.xcf
index 57304c0..8dd9f4e 100644
Binary files a/assets/unicode pages/unicode_page_ad.xcf and b/assets/unicode pages/unicode_page_ad.xcf differ
diff --git a/plugin/pom.xml b/plugin/pom.xml
index 3e29ff1..77a27dd 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -7,12 +7,12 @@
io.github.radbuilder
emojichat-parent
- 1.4
+ 1.5
EmojiChat Plugin
emojichat-plugin
- 1.4
+ 1.5
jar
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 d115aab..d62a0e6 100644
--- a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChat.java
+++ b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChat.java
@@ -7,6 +7,9 @@
import io.github.radbuilder.emojichat.hooks.PlaceholderApiHook;
//import io.github.radbuilder.emojichat.hooks.TelegramChatHook;
import io.github.radbuilder.emojichat.metrics.MetricsHandler;
+import io.github.radbuilder.emojichat.utils.EmojiChatConfigUpdater;
+import io.github.radbuilder.emojichat.utils.EmojiChatUpdateChecker;
+import io.github.radbuilder.emojichat.utils.EmojiHandler;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@@ -18,6 +21,7 @@
*
* @author RadBuilder
* @since 1.0
+ * @version 1.5
*/
public class EmojiChat extends JavaPlugin {
/**
@@ -35,7 +39,7 @@ public class EmojiChat extends JavaPlugin {
/**
* The ResourcePack URL.
*/
- final String PACK_URL = "https://github.com/RadBuilder/EmojiChat/releases/download/v1.4/EmojiChat.ResourcePack.v1.4.zip";
+ final String PACK_URL = "https://github.com/RadBuilder/EmojiChat/releases/download/v1.5/EmojiChat.ResourcePack.v1.5.zip";
/**
* The SHA1 sum of the ResourcePack as a byte array.
*/
@@ -51,6 +55,8 @@ public class EmojiChat extends JavaPlugin {
@Override
public void onEnable() {
+ new EmojiChatConfigUpdater(this);
+
saveDefaultConfig();
enabledHooks = new ArrayList<>();
@@ -62,7 +68,7 @@ public void onEnable() {
metricsHandler = new MetricsHandler(this); // Creates the metrics handler for metrics gathering
- PACK_SHA1 = BaseEncoding.base16().lowerCase().decode("c0143b56fb568ec4787320ea1e6af245d8a8140c"); // Allows applying a cached version of the ResourcePack if available
+ PACK_SHA1 = BaseEncoding.base16().lowerCase().decode("787dc51caa5b01ced40517bd3d1fcf0f0873ab4e"); // Allows applying a cached version of the ResourcePack if available
// Register the chat listener
Bukkit.getPluginManager().registerEvents(new EmojiChatListener(this), this);
@@ -71,15 +77,6 @@ public void onEnable() {
EmojiChatCommand emojiChatCommand = new EmojiChatCommand(this);
getCommand("emojichat").setExecutor(emojiChatCommand);
getCommand("ec").setExecutor(emojiChatCommand);
-
- // Check for updates
- Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
- updateChecker.checkForUpdates();
- if (updateChecker.updateAvailable) {
- getLogger().info("An update for EmojiChat is available.");
- getLogger().info("Current version: " + updateChecker.currentVersion + ". Latest version: " + updateChecker.latestVersion + ".");
- }
- });
}
@Override
@@ -89,6 +86,7 @@ public void onDisable() {
}
enabledHooks.clear();
emojiHandler.disable();
+ updateChecker.cancelUpdateTask();
}
/**
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 e668fdb..fb80866 100644
--- a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatCommand.java
+++ b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatCommand.java
@@ -11,12 +11,13 @@
*
* @author RadBuilder
* @since 1.0
+ * @version 1.5
*/
class EmojiChatCommand implements CommandExecutor {
/**
* EmojiChat main class instance.
*/
- private EmojiChat plugin;
+ private final EmojiChat plugin;
/**
* Creates the EmojiChat command class with the main class instance.
@@ -30,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.4 by RadBuilder");
+ sender.sendMessage(ChatColor.AQUA + "EmojiChat v1.5 by RadBuilder");
sender.sendMessage(ChatColor.AQUA + "Use " + ChatColor.GREEN + "/emojichat help" + ChatColor.AQUA + " for help.");
return true;
}
@@ -47,6 +48,7 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
sender.sendMessage(ChatColor.GREEN + "/emojichat help: " + ChatColor.AQUA + "Opens up this help menu.");
sender.sendMessage(ChatColor.GREEN + "/emojichat resourcepack: " + ChatColor.AQUA + "Re-sends the resourcepack.");
sender.sendMessage(ChatColor.GREEN + "/emojichat reload: " + ChatColor.AQUA + "Reloads the EmojiChat config.");
+ sender.sendMessage(ChatColor.GREEN + "/emojichat toggle: " + ChatColor.AQUA + "Toggles emoji shortcuts on or off.");
sender.sendMessage(ChatColor.GREEN + "/emojichat list: " + ChatColor.AQUA + "Lists all of the emojis configured.");
return true;
case "resourcepack":
@@ -71,6 +73,19 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
plugin.getEmojiHandler().load(plugin);
sender.sendMessage(ChatColor.GREEN + "EmojiChat config reloaded.");
return true;
+ case "toggle":
+ if (!sender.hasPermission("emojichat.toggle")) {
+ sender.sendMessage(ChatColor.RED + "You need " + ChatColor.GOLD + "emojichat.toggle" + ChatColor.RED + " to use this command.");
+ return true;
+ }
+
+ if (sender instanceof Player) {
+ plugin.getEmojiHandler().toggleShortcutsOff((Player) sender);
+ sender.sendMessage(ChatColor.AQUA + "Emoji shortcuts are now " + (plugin.getEmojiHandler().hasShortcutsOff((Player) sender) ? ChatColor.RED + "disabled" : ChatColor.GREEN + "enabled") + ChatColor.AQUA + ".");
+ } else {
+ sender.sendMessage(ChatColor.RED + "Oops, you have to be a player to toggle shortcuts.");
+ }
+ return true;
case "list":
if (!sender.hasPermission("emojichat.list")) {
sender.sendMessage(ChatColor.RED + "You need " + ChatColor.GOLD + "emojichat.list" + ChatColor.RED + " to use this command.");
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 43ba34a..7941b5c 100644
--- a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatGui.java
+++ b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatGui.java
@@ -1,5 +1,6 @@
package io.github.radbuilder.emojichat;
+import io.github.radbuilder.emojichat.utils.EmojiHandler;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@@ -15,12 +16,13 @@
*
* @author RadBuilder
* @since 1.2
+ * @version 1.5
*/
class EmojiChatGui {
/**
* EmojiChat main class instance.
*/
- private EmojiChat plugin;
+ private final EmojiChat plugin;
/**
* Creates the EmojiChat gui class with the main class instance.
@@ -90,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 io.github.radbuilder.emojichat.EmojiHandler#emojis} keys.
- * @param emojiMapPosition The current position in the {@link io.github.radbuilder.emojichat.EmojiHandler#emojis}.
+ * @param keyList The list of {@link EmojiHandler#emojis} keys.
+ * @param emojiMapPosition The current position in the {@link EmojiHandler#emojis}.
*/
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/EmojiChatListener.java b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatListener.java
index 17a2921..340cea0 100644
--- a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatListener.java
+++ b/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatListener.java
@@ -6,6 +6,7 @@
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
@@ -15,13 +16,18 @@
* EmojiChat listener class.
*
* @author RadBuilder
+ * @version 1.5
* @since 1.0
*/
class EmojiChatListener implements Listener {
/**
* EmojiChat main class instance.
*/
- private EmojiChat plugin;
+ private final EmojiChat plugin;
+ /**
+ * If EmojiChat should automatically download the ResourcePack for the player.
+ */
+ private final boolean autoDownloadResourcePack;
/**
* Creates the EmojiChat listener class with the main class instance.
@@ -30,6 +36,7 @@ class EmojiChatListener implements Listener {
*/
EmojiChatListener(EmojiChat plugin) {
this.plugin = plugin;
+ autoDownloadResourcePack = plugin.getConfig().getBoolean("download-resourcepack");
}
@EventHandler
@@ -43,6 +50,9 @@ void onJoin(PlayerJoinEvent event) {
+ ChatColor.AQUA + ". Latest version: " + ChatColor.GOLD + plugin.updateChecker.latestVersion + ChatColor.AQUA + ".");
}
+ if (!autoDownloadResourcePack) // If auto downloading of the ResourcePack is disabled
+ return;
+
// Send the player the resource pack
Bukkit.getScheduler().runTaskLater(plugin, () -> {
if (player.hasPermission("emojichat.see")) { // If the player can see emojis
@@ -55,23 +65,34 @@ void onJoin(PlayerJoinEvent event) {
}, 20L); // Give time for the player to join
}
- @EventHandler
+ @EventHandler(priority = EventPriority.HIGH)
void onChat(AsyncPlayerChatEvent event) {
if (!event.getPlayer().hasPermission("emojichat.use"))
return; // Don't do anything if they don't have permission
String message = event.getMessage();
- // Replaces shorthand ("shortcuts" in config) with correct emoji shortcuts
- for (String key : plugin.getEmojiHandler().getShortcuts().keySet()) {
- plugin.getMetricsHandler().addShortcutUsed(StringUtils.countMatches(message, key));
- message = message.replace(key, plugin.getEmojiHandler().getShortcuts().get(key));
+ // Checks if the user disabled shortcuts via /emojichat toggle
+ if (!plugin.getEmojiHandler().hasShortcutsOff(event.getPlayer())) {
+ // Replaces shorthand ("shortcuts" in config) with correct emoji shortcuts
+ for (String key : plugin.getEmojiHandler().getShortcuts().keySet()) {
+ plugin.getMetricsHandler().addShortcutUsed(StringUtils.countMatches(message, key));
+ message = message.replace(key, plugin.getEmojiHandler().getShortcuts().get(key));
+ }
}
// Replace shortcuts with emojis
- for (String key : plugin.getEmojiHandler().getEmojis().keySet()) {
- plugin.getMetricsHandler().addEmojiUsed(StringUtils.countMatches(message, key));
- message = message.replace(key, (plugin.getEmojiHandler().fixColoring() ? ChatColor.RESET : "") + plugin.getEmojiHandler().getEmojis().get(key));
+ if (!plugin.getEmojiHandler().fixColoring()) {
+ for (String key : plugin.getEmojiHandler().getEmojis().keySet()) {
+ plugin.getMetricsHandler().addEmojiUsed(StringUtils.countMatches(message, key));
+ message = message.replace(key, plugin.getEmojiHandler().getEmojis().get(key));
+ }
+ } else {
+ for (String key : plugin.getEmojiHandler().getEmojis().keySet()) {
+ plugin.getMetricsHandler().addEmojiUsed(StringUtils.countMatches(message, key));
+ String chatColor = message.substring(0, 2); // Gets the chat color of the message, i.e. §a
+ message = message.replace(key, ChatColor.WHITE + plugin.getEmojiHandler().getEmojis().get(key) + (chatColor.contains("§") ? chatColor : "")); // Sets the emoji color to white for correct coloring
+ }
}
if (plugin.getEmojiHandler().verifyDisabledList()) { // If the message should be checked for disabled characters
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 ff6679a..0960b47 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
@@ -13,6 +13,7 @@
*
* @author RadBuilder
* @since 1.4
+ * @version 1.5
*/
public class DiscordSrvHook implements EmojiChatHook {
/**
diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/EmojiChatHook.java b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/EmojiChatHook.java
index 0261dd4..a1a4202 100644
--- a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/EmojiChatHook.java
+++ b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/EmojiChatHook.java
@@ -5,6 +5,7 @@
*
* @author RadBuilder
* @since 1.4
+ * @version 1.4
*/
public interface EmojiChatHook {
/**
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 d0fd3bd..b9f6601 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
@@ -5,6 +5,7 @@
*
* @author RadBuilder
* @since 1.4
+ * @version 1.4
*/
public enum EmojiChatHookType {
/**
diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/MVdWPlaceholderApiHook.java b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/MVdWPlaceholderApiHook.java
index 2af0e59..4d00783 100644
--- a/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/MVdWPlaceholderApiHook.java
+++ b/plugin/src/main/java/io/github/radbuilder/emojichat/hooks/MVdWPlaceholderApiHook.java
@@ -8,6 +8,7 @@
*
* @author RadBuilder
* @since 1.4
+ * @version 1.4
*/
public class MVdWPlaceholderApiHook implements EmojiChatHook {
/**
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 e40493f..930980e 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
@@ -10,6 +10,7 @@
*
* @author RadBuilder
* @since 1.4
+ * @version 1.4
*/
public class PlaceholderApiHook implements EmojiChatHook {
/**
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 2f49957..f13da82 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,6 +10,7 @@
* Metrics handler class.
*
* @author RadBuilder
+ * @version 1.5
* @since 1.4
*/
public class MetricsHandler {
@@ -31,31 +32,61 @@ public MetricsHandler(EmojiChat plugin) {
emojisUsed = 0;
shortcutsUsed = 0;
- Metrics metrics = new Metrics(plugin); // Start Metrics
-
- metrics.addCustomChart(new Metrics.SingleLineChart("emojisUsed", () -> {
- int temp = emojisUsed;
- emojisUsed = 0; // Reset the number of emojis used when this is called
- return temp;
- }));
+ MetricsLevel metricsLevel = MetricsLevel.valueOf(plugin.getConfig().getString("metrics-collection"));
+ if (metricsLevel == MetricsLevel.OFF) {
+ return;
+ }
- metrics.addCustomChart(new Metrics.SingleLineChart("shortcutsUsed", () -> {
- int temp = shortcutsUsed;
- shortcutsUsed = 0; // Reset the number of shortcuts used when this is called
- return temp;
- }));
+ Metrics metrics = new Metrics(plugin); // Start Metrics
- metrics.addCustomChart(new Metrics.AdvancedPie("usedHooks", () -> {
- Map usedHooksMap = new HashMap<>();
- if (plugin.getEnabledHooks().size() < 1) {
- usedHooksMap.put("None", 1);
- } else {
- for (EmojiChatHook hook : plugin.getEnabledHooks()) {
- usedHooksMap.put(hook.getName(), 1);
- }
- }
- return usedHooksMap;
- }));
+ switch (metricsLevel) {
+ case FULL:
+ // If fix-emoji-coloring is being used
+ metrics.addCustomChart(new Metrics.SimplePie("usingFixEmojiColoring", () -> Boolean.toString(plugin.getConfig().getBoolean("fix-emoji-coloring"))));
+
+ // If verify-disabled-list is being used
+ metrics.addCustomChart(new Metrics.SimplePie("usingVerifyDisabledList", () -> Boolean.toString(plugin.getConfig().getBoolean("verify-disabled-list"))));
+
+ // If download-resourcepack is being used
+ metrics.addCustomChart(new Metrics.SimplePie("usingDownloadResourcePack", () -> Boolean.toString(plugin.getConfig().getBoolean("download-resourcepack"))));
+
+ // What emojis are listed under disabled-emojis
+ metrics.addCustomChart(new Metrics.AdvancedPie("disabledEmojis", () -> {
+ Map disabledEmojis = new HashMap<>();
+ plugin.getConfig().getStringList("disabled-emojis").forEach(s -> disabledEmojis.put(s, 1));
+ return disabledEmojis;
+ }));
+ case SOME:
+ // Which hooks are being used (value of 1 per hook, or "None" if no hooks)
+ metrics.addCustomChart(new Metrics.AdvancedPie("usedHooks", () -> {
+ Map usedHooksMap = new HashMap<>();
+ if (plugin.getEnabledHooks().size() < 1) {
+ usedHooksMap.put("None", 1);
+ } else {
+ for (EmojiChatHook hook : plugin.getEnabledHooks()) {
+ usedHooksMap.put(hook.getName(), 1);
+ }
+ }
+ return usedHooksMap;
+ }));
+ case BASIC:
+ // The number of emojis used
+ metrics.addCustomChart(new Metrics.SingleLineChart("emojisUsed", () -> {
+ int temp = emojisUsed;
+ emojisUsed = 0; // Reset the number of emojis used when this is called
+ return temp;
+ }));
+
+ // The number of shortcuts used
+ metrics.addCustomChart(new Metrics.SingleLineChart("shortcutsUsed", () -> {
+ int temp = shortcutsUsed;
+ shortcutsUsed = 0; // Reset the number of shortcuts used when this is called
+ return temp;
+ }));
+ default:
+ metrics.addCustomChart(new Metrics.SimplePie("metricsCollection", () -> metricsLevel.name().toLowerCase()));
+ break;
+ }
}
/**
@@ -76,3 +107,30 @@ public void addShortcutUsed(int shortcutsUsed) {
this.shortcutsUsed += shortcutsUsed;
}
}
+
+/**
+ * The different levels of metrics data collection.
+ *
+ * @author RadBuilder
+ * @version 1.5
+ * @since 1.5
+ */
+enum MetricsLevel {
+ /**
+ * Collects what {@link #SOME} collects, and data on what config options you're using, and what hooks you're using.
+ */
+ FULL,
+ /**
+ * Collects what {@link #BASIC} collects, and data on which hooks ({@link io.github.radbuilder.emojichat.hooks.EmojiChatHook}) you're using.
+ */
+ SOME,
+ /**
+ * Collects data on what Java version you're using, Bukkit/Spigot version you're using, other general server
+ * information like player count, how many emojis you've used, and shortcuts you've used.
+ */
+ BASIC,
+ /**
+ * Collects NO DATA, however, I would appreciate it if you send at least {@link #BASIC} data.
+ */
+ OFF;
+}
\ No newline at end of file
diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatConfigUpdater.java b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatConfigUpdater.java
new file mode 100644
index 0000000..b38dda8
--- /dev/null
+++ b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatConfigUpdater.java
@@ -0,0 +1,169 @@
+package io.github.radbuilder.emojichat.utils;
+
+import io.github.radbuilder.emojichat.EmojiChat;
+import org.bukkit.configuration.file.FileConfiguration;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+/**
+ * EmojiChat config updater.
+ *
+ * @author RadBuilder
+ * @version 1.5
+ * @since 1.5
+ */
+public class EmojiChatConfigUpdater {
+ /**
+ * The current config version number.
+ */
+ private final int CONFIG_VERSION = 2;
+
+ /**
+ * Creates the EmojiChat config updater with the main class instance.
+ *
+ * @param plugin The EmojiChat main class instance.
+ */
+ public EmojiChatConfigUpdater(EmojiChat plugin) {
+ int configVersion = plugin.getConfig().getInt("config-version");
+
+ if (configVersion + 1 == CONFIG_VERSION) {
+ plugin.getLogger().info("Updating your config now...");
+ updateConfig(plugin, plugin.getConfig());
+ } else if (configVersion + 1 < CONFIG_VERSION) {
+ plugin.getLogger().info("Your config is too old to update...");
+ plugin.getLogger().info("Your config has been renamed to 'config_old.yml' and a new one has been generated.");
+ }
+ }
+
+ /**
+ * Updates the EmojiChat config.
+ *
+ * @param plugin The EmojiChat main class instance.
+ * @param config The EmojiChat config.
+ */
+ private void updateConfig(EmojiChat plugin, FileConfiguration config) {
+ // Old config values
+ boolean fixEmojiColoring = config.getBoolean("fix-emoji-coloring");
+ boolean verifyDisabledList = config.getBoolean("verify-disabled-list");
+ List disabledEmojis = config.getStringList("disabled-emojis");
+ LinkedHashMap> shortcuts = new LinkedHashMap<>();
+ for (String key : config.getConfigurationSection("shortcuts").getKeys(false)) { // Gets all of the headers/keys in the shortcuts section
+ shortcuts.put(key, config.getStringList("shortcuts." + key));
+ }
+
+ // Config lines
+ List configLines = new ArrayList<>();
+ configLines.add("# Configuration file for EmojiChat by RadBuilder");
+ configLines.add("");
+ configLines.add("# EmojiChat collects metrics in order to get a better understanding of what configurations are used.");
+ configLines.add("# Statistics include how many servers it's being used on and what version of Bukkit/Spigot they're using,");
+ configLines.add("# how many players are using it, server information such as Java version, how many emojis are used,");
+ configLines.add("# and how many servers are using each feature. This data is anonymous, and is submitted to understand what");
+ configLines.add("# types of server configurations are being used to build a better plugin (i.e. MC/Java versions to continue supporting,");
+ configLines.add("# features to keep/remove). Data collection has very little/no impact on server performance. I'd appreciate if you");
+ configLines.add("# keep this set to FULL, but I completely understand if you want to send less data or opt out.");
+ configLines.add("#");
+ configLines.add("# 'FULL' collects what 'SOME' collects, and data on what config options you're using.");
+ configLines.add("# 'SOME' collects what 'BASIC' collects, and what hooks you're using.");
+ configLines.add("# 'BASIC' collects data on what Java version you're using, Bukkit/Spigot version you're using, other general server");
+ configLines.add("# information like player count, how many emojis you've used, and shortcuts you've used.");
+ configLines.add("# 'OFF' collects NO DATA, however, I would appreciate it if you send at least basic data.");
+ configLines.add("metrics-collection: 'FULL'");
+ configLines.add("");
+ configLines.add("# If you're using chat color plugins, this will remove the coloring for emojis to be displayed correctly.");
+ configLines.add("fix-emoji-coloring: " + fixEmojiColoring);
+ configLines.add("");
+ configLines.add("# This prevents players from using the characters associated with disabled emojis.");
+ configLines.add("# Disabling this will still disable the emojis listed in 'disabled-emojis', but won't check");
+ configLines.add("# if the player is using it in chat.");
+ configLines.add("verify-disabled-list: " + verifyDisabledList);
+ configLines.add("");
+ configLines.add("# If EmojiChat should auto download the ResourcePack. If you'd rather have your players manually");
+ configLines.add("# download or use /emojichat resourcepack, set this to false.");
+ configLines.add("download-resourcepack: true");
+ configLines.add("");
+ configLines.add("# Shortcuts will replace the items in the list with the correct emoji name.");
+ configLines.add("# For example, :) will be replaced with :grinning:, which then will turn it into the emoji.");
+ configLines.add("shortcuts:");
+ for (String shortcutKey : shortcuts.keySet()) {
+ configLines.add(" " + shortcutKey + ":");
+ for (String shortcutListItem : shortcuts.get(shortcutKey)) {
+ configLines.add(" - '" + shortcutListItem + "'");
+ }
+ }
+ configLines.add(" crazy_face:");
+ configLines.add(" - ':crazy:'");
+ configLines.add(" face_with_raised_eyebrow:");
+ configLines.add(" - ':hmm:'");
+ configLines.add(" shushing_face:");
+ configLines.add(" - ':shh:'");
+ configLines.add("");
+ configLines.add("# Emojis to disable. Remove them from the list to enable them.");
+ configLines.add("# By default, profane and potentially offensive emojis are disabled.");
+ configLines.add("disabled-emojis:");
+ for (String disabledEmoji : disabledEmojis) {
+ configLines.add("- '" + disabledEmoji + "'");
+ }
+ configLines.add("- ':sweat_drops:'");
+ configLines.add("- ':banana:'");
+ configLines.add("- ':cherries:'");
+ configLines.add("- ':peach:'");
+ configLines.add("- ':tomato:'");
+ configLines.add("- ':eggplant:'");
+ configLines.add("- ':cucumber:'");
+ configLines.add("- ':beer:'");
+ configLines.add("- ':beers:'");
+ configLines.add("- ':clinking_glasses:'");
+ configLines.add("- ':wine_glass:'");
+ configLines.add("- ':tumbler_glass:'");
+ configLines.add("- ':cocktail:'");
+ configLines.add("- ':face_with_symbols_over_mouth:'");
+ configLines.add("- ':face_vomiting:'");
+ configLines.add("");
+ configLines.add("# The config version, used to be able to update your config when future versions come out.");
+ configLines.add("# Don't change this, or you'll experience issues with EmojiChat.");
+ configLines.add("config-version: 2");
+
+ // Update the config
+ setConfig(plugin, configLines);
+ }
+
+ /**
+ * Sets the config to be the specified set of lines.
+ *
+ * @param plugin The EmojiChat main class instance.
+ * @param configLines The list of lines to set the config to.
+ */
+ private void setConfig(EmojiChat plugin, List configLines) {
+ try {
+ File configFile = new File(plugin.getDataFolder() + "/config.yml");
+ configFile.delete(); // Delete the old config
+
+ // Create the new config
+ configFile = new File(plugin.getDataFolder() + "/config.yml");
+ FileOutputStream fileOutputStream = new FileOutputStream(configFile);
+ OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream);
+ Writer writer = new BufferedWriter(outputStreamWriter);
+ for (String configLine : configLines) {
+ writer.write(configLine + "\n");
+ }
+
+ // Cleanup
+ writer.close();
+ outputStreamWriter.close();
+ fileOutputStream.close();
+ configLines.clear();
+ plugin.getLogger().info("Config successfully updated.");
+ } catch (Exception e) {
+ plugin.getLogger().severe("An error occured while updating your config. More details below.");
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatUpdateChecker.java b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatUpdateChecker.java
similarity index 63%
rename from plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatUpdateChecker.java
rename to plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatUpdateChecker.java
index 3dbf8c6..8f62330 100644
--- a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChatUpdateChecker.java
+++ b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiChatUpdateChecker.java
@@ -1,5 +1,8 @@
-package io.github.radbuilder.emojichat;
+package io.github.radbuilder.emojichat.utils;
+import io.github.radbuilder.emojichat.EmojiChat;
+import org.bukkit.Bukkit;
+import org.bukkit.scheduler.BukkitTask;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
@@ -14,34 +17,41 @@
*
* @author RadBuilder
* @since 1.3
+ * @version 1.5
*/
-class EmojiChatUpdateChecker {
+public class EmojiChatUpdateChecker {
/**
* The current version of EmojiChat.
*/
- final double currentVersion;
+ public final double currentVersion;
/**
* If an update is available.
*/
- boolean updateAvailable;
+ public boolean updateAvailable;
/**
* The latest version of EmojiChat.
*/
- double latestVersion;
+ public double latestVersion;
+ /**
+ * The update checker {@link org.bukkit.scheduler.BukkitTask}, which runs every 4 hours after 10 seconds.
+ */
+ private final BukkitTask updateTask;
/**
* Creates the EmojiChat update checker class with the main class instance.
*
* @param plugin The EmojiChat main class instance.
*/
- EmojiChatUpdateChecker(EmojiChat plugin) {
+ public EmojiChatUpdateChecker(EmojiChat plugin) {
currentVersion = Double.parseDouble(plugin.getDescription().getVersion());
+
+ updateTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this::checkForUpdates, 20L * 10L, 20L * 60L * 60L * 4L); // Start checking for updates after 10 seconds, then every 4 hours
}
/**
* Checks if updates are available.
*/
- void checkForUpdates() {
+ private void checkForUpdates() {
try {
URL url = new URL("https://api.spiget.org/v2/resources/50955/versions?size=1&sort=-id");
@@ -60,4 +70,11 @@ void checkForUpdates() {
updateAvailable = false;
}
}
+
+ /**
+ * Cancel the {@link #updateTask}.
+ */
+ public void cancelUpdateTask() {
+ updateTask.cancel();
+ }
}
\ No newline at end of file
diff --git a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiHandler.java b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java
similarity index 78%
rename from plugin/src/main/java/io/github/radbuilder/emojichat/EmojiHandler.java
rename to plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java
index ad05f8c..8e123ee 100644
--- a/plugin/src/main/java/io/github/radbuilder/emojichat/EmojiHandler.java
+++ b/plugin/src/main/java/io/github/radbuilder/emojichat/utils/EmojiHandler.java
@@ -1,31 +1,35 @@
-package io.github.radbuilder.emojichat;
+package io.github.radbuilder.emojichat.utils;
+import io.github.radbuilder.emojichat.EmojiChat;
import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.TreeMap;
+import java.util.UUID;
/**
* Emoji handler class.
*
* @author RadBuilder
+ * @version 1.5
* @since 1.4
*/
public class EmojiHandler {
/**
* The emojis.
*/
- private TreeMap emojis;
+ private final TreeMap emojis;
/**
* Shortcuts for the emojis, if specified.
*/
- private HashMap shortcuts;
+ private final HashMap shortcuts;
/**
* Disabled emoji characters to prevent others from using them with the resource pack.
*/
- private List disabledCharacters;
+ private final List disabledCharacters;
/**
* If we should fix the emoji's color (colored chat removes emoji coloring)
*/
@@ -34,16 +38,21 @@ public class EmojiHandler {
* If the characters associated with disabled emojis should be checked.
*/
private boolean verifyDisabledList;
+ /**
+ * A list of users (by UUID) who turned shortcuts off.
+ */
+ private List shortcutsOff;
/**
* Creates the emoji handler with the main class instance.
*
* @param plugin The EmojiChat main class instance.
*/
- EmojiHandler(EmojiChat plugin) {
+ public EmojiHandler(EmojiChat plugin) {
emojis = new TreeMap<>();
shortcuts = new HashMap<>();
disabledCharacters = new ArrayList<>();
+ shortcutsOff = new ArrayList<>();
load(plugin);
}
@@ -75,6 +84,29 @@ public HashMap getShortcuts() {
return shortcuts;
}
+ /**
+ * Checks if the specified player has emoji shortcuts off.
+ *
+ * @param player The player to check.
+ * @return True if the player has shortcuts off, false otherwise.
+ */
+ public boolean hasShortcutsOff(Player player) {
+ return shortcutsOff.contains(player.getUniqueId());
+ }
+
+ /**
+ * Toggles emoji shortcut use on/off for the specified player.
+ *
+ * @param player The player to toggle emoji shortcuts on/off for.
+ */
+ public void toggleShortcutsOff(Player player) {
+ if (shortcutsOff.contains(player.getUniqueId())) {
+ shortcutsOff.remove(player.getUniqueId());
+ } else {
+ shortcutsOff.add(player.getUniqueId());
+ }
+ }
+
/**
* If the list of disabled emojis specified in the config should be verified.
*
@@ -132,7 +164,7 @@ private void loadDisabledEmojis(FileConfiguration config, EmojiChat plugin) {
*
* @return True if emoji coloring should be fixed, false otherwise.
*/
- boolean fixColoring() {
+ public boolean fixColoring() {
return fixColoring;
}
@@ -460,15 +492,108 @@ private void loadEmojis() {
emojis.put(":open_umbrella:", "괽");
emojis.put(":umbrella:", "괾");
emojis.put(":droplet:", "괿");
+ emojis.put(":sweat_drops:", "굀");
+ emojis.put(":ocean:", "굁");
+ emojis.put(":green_apple:", "굂");
+ emojis.put(":apple:", "굃");
+ emojis.put(":pear:", "굄");
+ emojis.put(":tangerine:", "굅");
+ emojis.put(":lemon:", "굆");
+ emojis.put(":banana:", "굇");
+ emojis.put(":watermelon:", "굈");
+ emojis.put(":grapes:", "굉");
+ emojis.put(":strawberry:", "굊");
+ emojis.put(":melon:", "굋");
+ emojis.put(":cherries:", "굌");
+ emojis.put(":peach:", "굍");
+ emojis.put(":pineapple:", "굎");
+ emojis.put(":kiwi_fruit:", "굏");
+ emojis.put(":avocado:", "교");
+ emojis.put(":tomato:", "굑");
+ emojis.put(":eggplant:", "굒");
+ emojis.put(":cucumber:", "굓");
+ emojis.put(":carrot:", "굔");
+ emojis.put(":hot_pepper:", "굕");
+ emojis.put(":potato:", "굖");
+ emojis.put(":corn:", "굗");
+ emojis.put(":sweet_potato:", "굘");
+ emojis.put(":peanuts:", "굙");
+ emojis.put(":honey_pot:", "굚");
+ emojis.put(":croissant:", "굛");
+ emojis.put(":bread:", "굜");
+ emojis.put(":baguette_bread:", "굝");
+ emojis.put(":cheese:", "굞");
+ emojis.put(":egg:", "굟");
+ emojis.put(":bacon:", "굠");
+ emojis.put(":pancakes:", "굡");
+ emojis.put(":poultry_leg:", "굢");
+ emojis.put(":meat_on_bone:", "굣");
+ emojis.put(":fried_shrimp:", "굤");
+ emojis.put(":fried_egg:", "굥");
+ emojis.put(":hamburger:", "굦");
+ emojis.put(":fries:", "굧");
+ emojis.put(":stuffed_flatbread:", "굨");
+ emojis.put(":hotdog:", "굩");
+ emojis.put(":pizza:", "굪");
+ emojis.put(":spaghetti:", "굫");
+ emojis.put(":taco:", "구");
+ emojis.put(":burrito:", "국");
+ emojis.put(":green_salad:", "굮");
+ emojis.put(":shallow_pan_of_food:", "굯");
+ emojis.put(":ramen:", "군");
+ emojis.put(":stew:", "굱");
+ emojis.put(":fish_cake:", "굲");
+ emojis.put(":sushi:", "굳");
+ emojis.put(":bento:", "굴");
+ emojis.put(":curry:", "굵");
+ emojis.put(":rice_ball:", "굶");
+ emojis.put(":rice:", "굷");
+ emojis.put(":rice_cracker:", "굸");
+ emojis.put(":oden:", "굹");
+ emojis.put(":dango:", "굺");
+ emojis.put(":shaved_ice:", "굻");
+ emojis.put(":ice_cream:", "굼");
+ emojis.put(":icecream:", "굽");
+ emojis.put(":cake:", "굾");
+ emojis.put(":birthday:", "굿");
+ emojis.put(":custard:", "궀");
+ emojis.put(":candy:", "궁");
+ emojis.put(":lollipop:", "궂");
+ emojis.put(":chocolate_bar:", "궃");
+ emojis.put(":popcorn:", "궄");
+ emojis.put(":doughnut:", "궅");
+ emojis.put(":cookie:", "궆");
+ emojis.put(":milk_glass:", "궇");
+ emojis.put(":beer:", "궈");
+ emojis.put(":beers:", "궉");
+ emojis.put(":clinking_glasses:", "궊");
+ emojis.put(":wine_glass:", "궋");
+ emojis.put(":tumbler_glass:", "권");
+ emojis.put(":cocktail:", "궍");
+ emojis.put(":tropical_drink:", "궎");
+ emojis.put(":champagne:", "궏");
+ emojis.put(":sake:", "궐");
+ emojis.put(":tea:", "궑");
+ emojis.put(":coffee:", "궒");
+ emojis.put(":crazy_face:", "궓");
+ emojis.put(":face_with_monocle:", "궔");
+ emojis.put(":face_with_raised_eyebrow:", "궕");
+ emojis.put(":shushing_face:", "궖");
+ emojis.put(":face_with_hand_over_mouth:", "궗");
+ emojis.put(":face_with_symbols_over_mouth:", "궘");
+ emojis.put(":star_struck:", "궙");
+ emojis.put(":exploding_head:", "궚");
+ emojis.put(":face_vomiting:", "궛");
}
/**
* Clears the {@link #emojis}, {@link #shortcuts}, and {@link #disabledCharacters} maps.
*/
- void disable() {
+ public void disable() {
emojis.clear();
shortcuts.clear();
disabledCharacters.clear();
+ shortcutsOff.clear();
}
/**
@@ -476,7 +601,7 @@ void disable() {
*
* @param plugin The EmojiChat main class instance.
*/
- void load(EmojiChat plugin) {
+ public void load(EmojiChat plugin) {
disable();
loadEmojis(); // Loads ALL emojis
diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml
index 3ad308e..d19c2a7 100644
--- a/plugin/src/main/resources/config.yml
+++ b/plugin/src/main/resources/config.yml
@@ -1,7 +1,19 @@
# Configuration file for EmojiChat by RadBuilder
-# The config version, used to be able to update your config when future versions come out.
-config-version: 1
+# EmojiChat collects metrics in order to get a better understanding of what configurations are used.
+# Statistics include how many servers it's being used on and what version of Bukkit/Spigot they're using,
+# how many players are using it, server information such as Java version, how many emojis are used,
+# and how many servers are using each feature. This data is anonymous, and is submitted to understand what
+# types of server configurations are being used to build a better plugin (i.e. MC/Java versions to continue supporting,
+# features to keep/remove). Data collection has very little/no impact on server performance. I'd appreciate if you
+# keep this set to FULL, but I completely understand if you want to send less data or opt out.
+#
+# 'FULL' collects what 'SOME' collects, and data on what config options you're using.
+# 'SOME' collects what 'BASIC' collects, and what hooks you're using.
+# 'BASIC' collects data on what Java version you're using, Bukkit/Spigot version you're using, other general server
+# information like player count, how many emojis you've used, and shortcuts you've used.
+# 'OFF' collects NO DATA, however, I would appreciate it if you send at least basic data.
+metrics-collection: 'FULL'
# If you're using chat color plugins, this will remove the coloring for emojis to be displayed correctly.
fix-emoji-coloring: false
@@ -11,6 +23,10 @@ fix-emoji-coloring: false
# if the player is using it in chat.
verify-disabled-list: true
+# If EmojiChat should auto download the ResourcePack. If you'd rather have your players manually
+# download or use /emojichat resourcepack, set this to false.
+download-resourcepack: true
+
# Shortcuts will replace the items in the list with the correct emoji name.
# For example, :) will be replaced with :grinning:, which then will turn it into the emoji.
shortcuts:
@@ -39,6 +55,12 @@ shortcuts:
v:
- ':peace:'
- ':peace_hand:'
+ crazy_face:
+ - ':crazy:'
+ face_with_raised_eyebrow:
+ - ':hmm:'
+ shushing_face:
+ - ':shh:'
# Emojis to disable. Remove them from the list to enable them.
# By default, profane and potentially offensive emojis are disabled.
@@ -47,4 +69,23 @@ disabled-emojis:
- ':lips:'
- ':tongue:'
- ':bikini:'
-- ':kiss:'
\ No newline at end of file
+- ':kiss:'
+- ':sweat_drops:'
+- ':banana:'
+- ':cherries:'
+- ':peach:'
+- ':tomato:'
+- ':eggplant:'
+- ':cucumber:'
+- ':beer:'
+- ':beers:'
+- ':clinking_glasses:'
+- ':wine_glass:'
+- ':tumbler_glass:'
+- ':cocktail:'
+- ':face_with_symbols_over_mouth:'
+- ':face_vomiting:'
+
+# The config version, used to be able to update your config when future versions come out.
+# Don't change this, or you'll experience issues with EmojiChat.
+config-version: 2
\ No newline at end of file
diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml
index 7b14cac..b7ae613 100644
--- a/plugin/src/main/resources/plugin.yml
+++ b/plugin/src/main/resources/plugin.yml
@@ -1,5 +1,5 @@
name: EmojiChat
-version: 1.4
+version: 1.5
description: Adds emojis to your chat
author: RadBuilder
website: "https://github.com/RadBuilder/EmojiChat/"
@@ -20,6 +20,7 @@ permissions:
emojichat.help: true
emojichat.see: true
emojichat.list: true
+ emojichat.toggle: true
emojichat.use: true
emojichat.reload: true
emojichat.updates: true
@@ -32,6 +33,9 @@ permissions:
emojichat.list:
description: Allows you to list all of the emojis
default: op
+ emojichat.toggle:
+ description: Allows you to toggle emoji shortcuts on or off
+ default: op
emojichat.use:
description: Allows you to use emojis in chat
default: op
diff --git a/pom.xml b/pom.xml
index 3488ddb..3be727f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
io.github.radbuilder
EmojiChat Parent
emojichat-parent
- 1.4
+ 1.5
pom
diff --git a/resourcepack/assets/minecraft/textures/font/unicode_page_ad.png b/resourcepack/assets/minecraft/textures/font/unicode_page_ad.png
index 8976dfe..c89cfef 100644
Binary files a/resourcepack/assets/minecraft/textures/font/unicode_page_ad.png and b/resourcepack/assets/minecraft/textures/font/unicode_page_ad.png differ
diff --git a/resourcepack/pack.mcmeta b/resourcepack/pack.mcmeta
index f131d39..a40a59c 100644
--- a/resourcepack/pack.mcmeta
+++ b/resourcepack/pack.mcmeta
@@ -1,6 +1,6 @@
{
"pack": {
"pack_format": 4,
- "description": "EmojiChat v1.4 ResourcePack by RadBuilder"
+ "description": "EmojiChat v1.5 ResourcePack by RadBuilder"
}
}