Skip to content

Commit

Permalink
Merged v1.8.3 changes to master
Browse files Browse the repository at this point in the history
  • Loading branch information
RadBuilder committed Dec 7, 2019
2 parents d83c5d7 + 3bdad1e commit c179126
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: java
sudo: false
script: mvn clean verify
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
17 changes: 11 additions & 6 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.radbuilder</groupId>
<artifactId>emojichat-parent</artifactId>
<version>1.8.2</version>
<version>1.8.3</version>
</parent>

<properties>
Expand All @@ -18,7 +18,7 @@

<name>EmojiChat Plugin</name>
<artifactId>emojichat-plugin</artifactId>
<version>1.8.2</version>
<version>1.8.3</version>
<packaging>jar</packaging>

<build>
Expand Down Expand Up @@ -81,13 +81,18 @@
<dependency>
<groupId>com.discordsrv</groupId>
<artifactId>discordsrv</artifactId>
<version>1.16.6</version>
<version>1.17.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.DiscordSRV</groupId>
<artifactId>Staff-Chat</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>be.maximvdw</groupId>
<artifactId>MVdWPlaceholderAPI</artifactId>
<version>2.1.1-SNAPSHOT</version>
<version>3.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.spigotmc</groupId>
Expand All @@ -98,13 +103,13 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.9.2</version>
<version>2.10.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.mastercake10</groupId>
<artifactId>TelegramChat</artifactId>
<version>1.0.9.9</version>
<version>1.0.14</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,7 +16,7 @@
* EmojiChat main class.
*
* @author RadBuilder
* @version 1.7
* @version 1.8.3
* @since 1.0
*/
public class EmojiChat extends JavaPlugin {
Expand Down Expand Up @@ -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));
}
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.8.2
* @version 1.8.3
* @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.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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* EmojiChat gui class.
*
* @author RadBuilder
* @version 1.8.3
* @since 1.2
* @version 1.5
*/
class EmojiChatGui {
/**
Expand Down Expand Up @@ -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<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 @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* PlaceholderAPI hook.
*
* @author RadBuilder
* @version 1.7
* @version 1.8.3
* @since 1.4
*/
public class PlaceholderApiHook implements EmojiChatHook {
Expand All @@ -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
Expand Down Expand Up @@ -63,6 +63,6 @@ public EmojiChatHookType getHookType() {
@Override
public void disable() {
enabled = false;
PlaceholderAPI.unregisterPlaceholderHook(plugin);
PlaceholderAPI.unregisterPlaceholderHook("EmojiChat");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
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;

/**
* TelegramChat hook.
*
* @author RadBuilder
* @version 1.7
* @version 1.8.3
* @since 1.7
*/
public class TelegramChatHook implements EmojiChatHook {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Metrics handler class.
*
* @author RadBuilder
* @version 1.8
* @version 1.8.3
* @since 1.4
*/
public class MetricsHandler {
Expand All @@ -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.
*/
Expand All @@ -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"));
Expand Down Expand Up @@ -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"))));

Expand Down Expand Up @@ -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;
}
}

/**
Expand Down
Loading

0 comments on commit c179126

Please sign in to comment.