Skip to content

Commit

Permalink
Merged v1.7 changes to master
Browse files Browse the repository at this point in the history
  • Loading branch information
RadBuilder committed Jan 15, 2018
2 parents 7dcfb99 + 9d8ed9f commit b8e1f9a
Show file tree
Hide file tree
Showing 39 changed files with 1,227 additions and 653 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 RadBuilder
Copyright (c) 2018 RadBuilder

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![view on SpigotMC](https://img.shields.io/badge/view%20on-spigotmc-orange.svg)](https://www.spigotmc.org/resources/emojichat.50955/)
[![wiki](https://img.shields.io/badge/go%20to-wiki-blue.svg)](https://github.com/RadBuilder/EmojiChat/wiki)
## EmojiChat
EmojiChat is a simple opensource plugin that adds emojis to your chat!
EmojiChat is a simple, configurable, opensource plugin that adds emojis to your chat, signs, and more!

[![ChatExample](https://i.imgur.com/wa0LeVd.png)](https://i.imgur.com/zJUVyst.png)

Expand Down
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file added assets/variant 2/unicode_page_5a.psd
Binary file not shown.
Binary file added assets/variant 2/unicode_page_5a.xcf
Binary file not shown.
Binary file added assets/variant 2/unicode_page_5b.psd
Binary file not shown.
Binary file added assets/variant 2/unicode_page_5b.xcf
Binary file not shown.
18 changes: 9 additions & 9 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.6</version>
<version>1.7</version>
</parent>

<name>EmojiChat Plugin</name>
<artifactId>emojichat-plugin</artifactId>
<version>1.6</version>
<version>1.7</version>
<packaging>jar</packaging>

<build>
Expand All @@ -26,6 +26,8 @@
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
<include>list.txt</include>
<include>hash.txt</include>
</includes>
</resource>
</resources>
Expand Down Expand Up @@ -92,12 +94,10 @@
<version>2.8.2</version>
<scope>provided</scope>
</dependency>
<!--<dependency>-->
<!--<groupId>de.Linus122</groupId>-->
<!--<artifactId>TelegramChat</artifactId>-->
<!--<version>LATEST</version>-->
<!--<scope>system</scope>-->
<!--<systemPath>TelegramChat.jar</systemPath>-->
<!--</dependency>-->
<dependency>
<groupId>com.github.mastercake10</groupId>
<artifactId>TelegramChat</artifactId>
<version>1.0.9.9</version>
</dependency>
</dependencies>
</project>
24 changes: 8 additions & 16 deletions plugin/src/main/java/io/github/radbuilder/emojichat/EmojiChat.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.github.radbuilder.emojichat;

import com.google.common.io.BaseEncoding;
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.TelegramChatHook;
import io.github.radbuilder.emojichat.metrics.MetricsHandler;
import io.github.radbuilder.emojichat.utils.EmojiChatConfigUpdater;
import io.github.radbuilder.emojichat.utils.EmojiChatUpdateChecker;
Expand All @@ -21,7 +20,7 @@
* EmojiChat main class.
*
* @author RadBuilder
* @version 1.6
* @version 1.7
* @since 1.0
*/
public class EmojiChat extends JavaPlugin {
Expand All @@ -37,14 +36,6 @@ public class EmojiChat extends JavaPlugin {
* The EmojiChat update checker.
*/
EmojiChatUpdateChecker updateChecker;
/**
* The ResourcePack URL.
*/
final String PACK_URL = "https://github.com/RadBuilder/EmojiChat/releases/download/v1.6/EmojiChat.ResourcePack.v1.6.zip";
/**
* The SHA1 sum of the ResourcePack as a byte array.
*/
byte[] PACK_SHA1;
/**
* List of enabled EmojiChat hooks.
*/
Expand All @@ -71,15 +62,16 @@ public void onEnable() {

metricsHandler = new MetricsHandler(this); // Creates the metrics handler for metrics gathering

PACK_SHA1 = BaseEncoding.base16().lowerCase().decode("45bd1b12a2007f8121b0ac041a0dbb3b6e934180"); // Allows applying a cached version of the ResourcePack if available

// Register the chat listener
Bukkit.getPluginManager().registerEvents(new EmojiChatListener(this), this);

// Register the "emojichat" and "ec" commands
EmojiChatCommand emojiChatCommand = new EmojiChatCommand(this);
EmojiChatTabComplete emojiChatTabComplete = new EmojiChatTabComplete();
getCommand("emojichat").setExecutor(emojiChatCommand);
getCommand("emojichat").setTabCompleter(emojiChatTabComplete);
getCommand("ec").setExecutor(emojiChatCommand);
getCommand("ec").setTabCompleter(emojiChatTabComplete);
}

@Override
Expand All @@ -105,9 +97,9 @@ private void loadHooks() {
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { // Hook PlaceholderAPI if installed
enabledHooks.add(new PlaceholderApiHook(this));
}
// if (Bukkit.getPluginManager().isPluginEnabled("TelegramChat")) { // Hook TelegramChat if installed
// enabledHooks.add(new TelegramChatHook(this));
// }
if (Bukkit.getPluginManager().isPluginEnabled("TelegramChat")) { // Hook TelegramChat if installed
enabledHooks.add(new TelegramChatHook(this));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* EmojiChat command class.
*
* @author RadBuilder
* @version 1.6
* @version 1.7
* @since 1.0
*/
class EmojiChatCommand implements CommandExecutor {
Expand All @@ -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.6 by RadBuilder");
sender.sendMessage(ChatColor.AQUA + "EmojiChat v1.7 by RadBuilder");
sender.sendMessage(ChatColor.AQUA + "Use " + ChatColor.GREEN + "/emojichat help" + ChatColor.AQUA + " for help.");
return true;
}
Expand All @@ -49,7 +49,7 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
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.");
sender.sendMessage(ChatColor.GREEN + "/emojichat list: " + ChatColor.AQUA + "Lists all of the enabled emojis.");
return true;
case "resourcepack":
if (!sender.hasPermission("emojichat.see")) {
Expand All @@ -58,8 +58,8 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
}

if (sender instanceof Player) {
((Player) sender).setResourcePack(plugin.PACK_URL);
sender.sendMessage(ChatColor.GREEN + "Sent EmojiChat ResourcePack.");
((Player) sender).setResourcePack(plugin.getEmojiHandler().getPackVariant().getUrl());
sender.sendMessage(ChatColor.GREEN + "Sent the EmojiChat ResourcePack.");
sender.sendMessage(ChatColor.AQUA + "If you still can't see emojis, make sure the settings for this server (on the server list) have the resource pack option set to prompt or enabled.");
}
return true;
Expand Down Expand Up @@ -91,7 +91,7 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
sender.sendMessage(ChatColor.RED + "You need " + ChatColor.GOLD + "emojichat.list" + ChatColor.RED + " to use this command.");
return true;
}
if (!(sender instanceof Player) || (args.length > 1 && args[1].equalsIgnoreCase("chat"))) { // Send chat version if not a player or specified
if (!(sender instanceof Player)) { // Send chat version if the sender isn't a player
sender.sendMessage(ChatColor.AQUA + "---------- EmojiChat List ----------");
for (String key : plugin.getEmojiHandler().getEmojis().keySet()) {
sender.sendMessage(ChatColor.AQUA + key + " " + ChatColor.RESET + plugin.getEmojiHandler().getEmojis().get(key));
Expand All @@ -101,7 +101,7 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
}
return true;
default:
sender.sendMessage(ChatColor.RED + "Unknown sub-command. Use " + ChatColor.GOLD + "/emojichat help" + ChatColor.RED + " for help.");
sender.sendMessage(ChatColor.RED + "Unknown sub-command '" + args[0] + "'. Use " + ChatColor.GOLD + "/emojichat help" + ChatColor.RED + " for help.");
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package io.github.radbuilder.emojichat;

import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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.block.SignChangeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;

/**
* EmojiChat listener class.
*
* @author RadBuilder
* @version 1.6
* @version 1.7
* @since 1.0
*/
class EmojiChatListener implements Listener {
Expand Down Expand Up @@ -57,57 +58,100 @@ void onJoin(PlayerJoinEvent event) {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
if (player.hasPermission("emojichat.see")) { // If the player can see emojis
try {
player.setResourcePack(plugin.PACK_URL, plugin.PACK_SHA1); // If the Spigot version supports loading cached versions
player.setResourcePack(plugin.getEmojiHandler().getPackVariant().getUrl(), plugin.getEmojiHandler().getPackVariant().getHash()); // If the Spigot version supports loading cached versions
} catch (Exception | NoSuchMethodError e) {
player.setResourcePack(plugin.PACK_URL); // If the Spigot version doesn't support loading cached versions
player.setResourcePack(plugin.getEmojiHandler().getPackVariant().getUrl()); // If the Spigot version doesn't support loading cached versions
}
}
}, 20L); // Give time for the player to join
}

@EventHandler(priority = EventPriority.HIGH)
void onChat(AsyncPlayerChatEvent event) {
if (!event.getPlayer().hasPermission("emojichat.use"))
if (!event.getPlayer().hasPermission("emojichat.use") || !event.getPlayer().hasPermission("emojichat.use.chat"))
return; // Don't do anything if they don't have permission

String message = event.getMessage();

// 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));
}
message = plugin.getEmojiHandler().translateShorthand(message);
}

// Replace shortcuts with emojis
// If we're not fixing the coloring, or the message is too small to have coloring
if (!plugin.getEmojiHandler().fixColoring() || message.length() < 3) {
for (String key : plugin.getEmojiHandler().getEmojis().keySet()) {
plugin.getMetricsHandler().addEmojiUsed(StringUtils.countMatches(message, key));
message = message.replace(key, plugin.getEmojiHandler().getEmojis().get(key));
message = plugin.getEmojiHandler().toEmojiFromChat(message);

// If the message contains a disabled character
if (plugin.getEmojiHandler().containsDisabledCharacter(message)) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "Oops! You can't use disabled emoji characters!");
return;
}

event.setMessage(message);
}

@EventHandler(priority = EventPriority.HIGH)
void onSignChange(SignChangeEvent event) {
if (!event.getPlayer().hasPermission("emojichat.use") || !event.getPlayer().hasPermission("emojichat.use.sign"))
return; // Don't do anything if they don't have permission

if (!plugin.getConfig().getBoolean("emojis-on-signs")) // Feature is disabled
return;

for (int i = 0; i < 4; i++) {
String line = event.getLine(i);

// Checks if the user disabled shortcuts via /emojichat toggle
if (!plugin.getEmojiHandler().hasShortcutsOff(event.getPlayer())) {
line = plugin.getEmojiHandler().translateShorthand(line);
}
} else {
String chatColor = message.substring(0, 2); // Gets the chat color of the message, i.e. §a
boolean hasColor = chatColor.contains("§");
for (String key : plugin.getEmojiHandler().getEmojis().keySet()) {
plugin.getMetricsHandler().addEmojiUsed(StringUtils.countMatches(message, key));
message = message.replace(key, ChatColor.WHITE + plugin.getEmojiHandler().getEmojis().get(key) + (hasColor ? chatColor : "")); // Sets the emoji color to white for correct coloring

// Replace shortcuts with emojis
line = plugin.getEmojiHandler().toEmojiFromSign(line);

// If the message contains a disabled character
if (plugin.getEmojiHandler().containsDisabledCharacter(line)) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "Oops! You can't use disabled emoji characters!");
return;
}

event.setLine(i, line);
}
}

@EventHandler(priority = EventPriority.HIGH)
void onCommandPreProcess(PlayerCommandPreprocessEvent event) {
if (!event.getPlayer().hasPermission("emojichat.use") || !event.getPlayer().hasPermission("emojichat.use.command"))
return; // Don't do anything if they don't have permission

if (plugin.getEmojiHandler().verifyDisabledList()) { // If the message should be checked for disabled characters
for (String disabledCharacter : plugin.getEmojiHandler().getDisabledCharacters()) {
if (message.contains(disabledCharacter)) { // Message contains a disabled character
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "Oops! You can't use disabled emoji characters!");
return;
}
}
if (!plugin.getConfig().getBoolean("emojis-in-commands")) // Feature is disabled
return;

String command = event.getMessage();

// only-command-list is enabled and the command-list doesn't contain the command being ran
if (plugin.getConfig().getBoolean("only-command-list") && !plugin.getConfig().getStringList("command-list").contains(command.split(" ")[0].toLowerCase())) {
return;
}

event.setMessage(message);
// Checks if the user disabled shortcuts via /emojichat toggle
if (!plugin.getEmojiHandler().hasShortcutsOff(event.getPlayer())) {
command = plugin.getEmojiHandler().translateShorthand(command);
}

// Replace shortcuts with emojis
command = plugin.getEmojiHandler().toEmoji(command);

// If the message contains a disabled character
if (plugin.getEmojiHandler().containsDisabledCharacter(command)) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "Oops! You can't use disabled emoji characters!");
return;
}

event.setMessage(command);
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.github.radbuilder.emojichat;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.util.StringUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* EmojiChat tab completer.
*
* @author RadBuilder
* @version 1.7
* @since 1.7
*/
class EmojiChatTabComplete implements TabCompleter {
/**
* The list of /emojichat sub-commands.
*/
private final List<String> SUB_COMMANDS = new ArrayList<>(Arrays.asList("help", "resourcepack", "reload", "toggle", "list"));

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String s, String[] args) {
// The possible completions
List<String> completions = new ArrayList<>();
// Gets the matches
StringUtil.copyPartialMatches(args[0], SUB_COMMANDS, completions);
// Sort the completions
Collections.sort(completions);
return completions;
}
}
Loading

0 comments on commit b8e1f9a

Please sign in to comment.