Skip to content

Commit

Permalink
Merged v1.5 changes to master
Browse files Browse the repository at this point in the history
  • Loading branch information
RadBuilder committed Dec 30, 2017
2 parents 15f3a2c + 8327acc commit 6911b60
Show file tree
Hide file tree
Showing 21 changed files with 526 additions and 71 deletions.
Binary file modified assets/unicode pages/unicode_page_ad.psd
Binary file not shown.
Binary file modified assets/unicode pages/unicode_page_ad.xcf
Binary file not shown.
4 changes: 2 additions & 2 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<parent>
<groupId>io.github.radbuilder</groupId>
<artifactId>emojichat-parent</artifactId>
<version>1.4</version>
<version>1.5</version>
</parent>

<name>EmojiChat Plugin</name>
<artifactId>emojichat-plugin</artifactId>
<version>1.4</version>
<version>1.5</version>
<packaging>jar</packaging>

<build>
Expand Down
20 changes: 9 additions & 11 deletions plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,6 +21,7 @@
*
* @author RadBuilder
* @since 1.0
* @version 1.5
*/
public class EmojiChat extends JavaPlugin {
/**
Expand All @@ -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.
*/
Expand All @@ -51,6 +55,8 @@ public class EmojiChat extends JavaPlugin {

@Override
public void onEnable() {
new EmojiChatConfigUpdater(this);

saveDefaultConfig();

enabledHooks = new ArrayList<>();
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -89,6 +86,7 @@ public void onDisable() {
}
enabledHooks.clear();
emojiHandler.disable();
updateChecker.cancelUpdateTask();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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":
Expand All @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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<String> keyList, int emojiMapPosition) {
ItemStack stack = new ItemStack(Material.PAPER, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -30,6 +36,7 @@ class EmojiChatListener implements Listener {
*/
EmojiChatListener(EmojiChat plugin) {
this.plugin = plugin;
autoDownloadResourcePack = plugin.getConfig().getBoolean("download-resourcepack");
}

@EventHandler
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* @author RadBuilder
* @since 1.4
* @version 1.5
*/
public class DiscordSrvHook implements EmojiChatHook {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* @author RadBuilder
* @since 1.4
* @version 1.4
*/
public interface EmojiChatHook {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* @author RadBuilder
* @since 1.4
* @version 1.4
*/
public enum EmojiChatHookType {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* @author RadBuilder
* @since 1.4
* @version 1.4
*/
public class MVdWPlaceholderApiHook implements EmojiChatHook {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*
* @author RadBuilder
* @since 1.4
* @version 1.4
*/
public class PlaceholderApiHook implements EmojiChatHook {
/**
Expand Down
Loading

0 comments on commit 6911b60

Please sign in to comment.