Skip to content

Commit

Permalink
Merge pull request #3 from RMJTromp/2.3.2
Browse files Browse the repository at this point in the history
v2.3.2 Added Essentials Messaging Support
  • Loading branch information
RMJTromp authored Aug 12, 2022
2 parents a0d91f7 + 6d5b849 commit fcd93ec
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 59 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build

on:
workflow_dispatch:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Prepare Project
uses: actions/checkout@v3
with:
ref: 'main'

- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven

- name: Build with Maven
run: |
mvn -B install --file pom.xml
echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: 'v${{ env.PROJECT_VERSION }}'
release_name: ChatEmojis
draft: false
prerelease: false

- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: './target/ChatEmojis-${{ env.PROJECT_VERSION }}.jar'
asset_name: 'ChatEmojis-${{ env.PROJECT_VERSION }}.jar'
asset_content_type: 'application/java-archive'
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ Grouped emojis permission needs to include the path to the group (ex. `chatemoji
If you still don't understand how to get emoji-specific permission- as a server operator you're able to hover over the emoji (in the `/emoji` list) to view the permission node for that specific emoji.

# Dependencies
ChatEmojis does not hard-depend on any other plugins.
**PlaceholderAPI** is a soft-dependency which means it's **NOT** required for ChatEmojis to work. If you'd like to use placeholders in your emojis, you're able to do so by also installing PlaceholderAPI.
ChatEmojis does not hard-depend on any other plugins; Meaning **none** of these dependencies are required for ChatEmojis to work.
- **[PlaceholderAPI](https://www.spigotmc.org/resources/placeholderapi.6245/)** is used for placeholder parsing.
- **[EssentialsX](https://www.spigotmc.org/resources/essentialsx.9089/)** is used for parsing emoticons in direct messages.

Please note that if you are using PlaceholderAPI, you must also install the PlaceholderAPI Extension corresponding to the placeholder you're trying to access, more about this can be found [here](https://github.com/PlaceholderAPI/PlaceholderAPI/wiki/Placeholders).

Expand Down
22 changes: 21 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.rmjtromp</groupId>
<artifactId>ChatEmojis</artifactId>
<version>2.3.1</version>
<version>2.3.2</version>
<packaging>jar</packaging>

<name>ChatEmojis</name>
Expand Down Expand Up @@ -82,6 +82,14 @@
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>essentials-releases</id>
<url>https://repo.essentialsx.net/releases/</url>
</repository>
<repository>
<id>paper-repo</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -97,6 +105,18 @@
<version>2.10.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.essentialsx</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.19.0</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
56 changes: 3 additions & 53 deletions src/main/java/com/rmjtromp/chatemojis/ChatEmojis.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
import org.bukkit.ChatColor;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

Expand All @@ -38,9 +30,9 @@ public final class ChatEmojis extends JavaPlugin {
static final Pattern NAME_PATTERN = Pattern.compile("(?<=\\.)?([^.]+?)$", Pattern.CASE_INSENSITIVE);

private final Config config;
private EmojiGroup emojis = null;
EmojiGroup emojis = null;
private static ChatEmojis plugin;
private boolean papiIsLoaded = false;
boolean papiIsLoaded = false;
public final ConfigurationReference<Boolean> useOnSigns, useInBooks;
private SettingsWindow settingsWindow = null;

Expand Down Expand Up @@ -68,45 +60,7 @@ public void onEnable() {
settingsWindow = new SettingsWindow(this);
papiIsLoaded = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;

getServer().getPluginManager().registerEvents(new Listener() {

@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent e) {
String resetColor = ChatColor.RESET + ChatColor.getLastColors(e.getMessage());
e.setMessage(emojis.parse(e.getPlayer(), resetColor, e.getMessage(), false));
}

@EventHandler
public void onPluginEnable(PluginEnableEvent e) {
if(e.getPlugin().getName().equals("PlaceholderAPI")) papiIsLoaded = true;
}

@EventHandler
public void onPluginDisable(PluginDisableEvent e) {
if(e.getPlugin().getName().equals("PlaceholderAPI")) papiIsLoaded = false;
}

@EventHandler
public void onSignChange(SignChangeEvent e) {
if(Boolean.TRUE.equals(useOnSigns.getValue())) {
for(int i = 0; i < e.getLines().length; i++) {
e.setLine(i, emojis.parse(e.getPlayer(), ChatColor.RESET + ChatColor.getLastColors(e.getLine(i)), e.getLine(i), false));
}
}
}

@EventHandler
public void onPlayerBookEdit(PlayerEditBookEvent e) {
if(Boolean.TRUE.equals(useInBooks.getValue())) {
List<String> newContent = new ArrayList<>();
BookMeta meta = e.getNewBookMeta();
meta.getPages().forEach(string -> newContent.add(emojis.parse(e.getPlayer(), ChatColor.RESET + ChatColor.getLastColors(string), string, false)));
meta.setPages(newContent);
e.setNewBookMeta(meta);
}
}

}, this);
getServer().getPluginManager().registerEvents(new PluginListeners(), this);

getCommand("emoji").setExecutor((sender, command, label, args) -> {
if(sender.hasPermission("chatemojis.command") || sender.hasPermission("chatemojis.list")) {
Expand Down Expand Up @@ -179,10 +133,6 @@ public Config getConfig() {
return config;
}

boolean isPapiLoaded() {
return papiIsLoaded;
}

static ChatEmojis getInstance() {
return plugin;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/rmjtromp/chatemojis/Emoji.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ public String parse(@NotNull Player player, @NotNull String resetColor, @NotNull
Matcher matcher = getPattern().matcher(message);
while(matcher.find()) {
if(getEmojis().size() > 1) {
message = matcher.replaceFirst(ChatColor.RESET + (!plugin.isPapiLoaded() ? getEmoji() : PlaceholderAPI.setPlaceholders(player, getEmoji())) + resetColor);
message = matcher.replaceFirst(ChatColor.RESET + (!plugin.papiIsLoaded ? getEmoji() : PlaceholderAPI.setPlaceholders(player, getEmoji())) + resetColor);
matcher = getPattern().matcher(message);
} else message = matcher.replaceAll(ChatColor.RESET + (!plugin.isPapiLoaded() ? getEmoji() : PlaceholderAPI.setPlaceholders(player, getEmoji())) + resetColor);
} else message = matcher.replaceAll(ChatColor.RESET + (!plugin.papiIsLoaded ? getEmoji() : PlaceholderAPI.setPlaceholders(player, getEmoji())) + resetColor);
}
}
return message;
Expand Down
93 changes: 93 additions & 0 deletions src/main/java/com/rmjtromp/chatemojis/PluginListeners.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.rmjtromp.chatemojis;

import com.earth2me.essentials.User;
import net.ess3.api.events.PrivateMessagePreSendEvent;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.inventory.meta.BookMeta;

import java.util.ArrayList;
import java.util.List;

class PluginListeners implements Listener {

private static final ChatEmojis PLUGIN = ChatEmojis.getInstance();

private final Listener ESSENTIALS_LISTENER = new Listener() {

@EventHandler(ignoreCancelled = true)
public void onPrivateMessagePreSend(PrivateMessagePreSendEvent e) {
if(e.getSender() instanceof User) {
Player sender = ((User) e.getSender()).getBase();
String resetColor = ChatColor.RESET + ChatColor.getLastColors(e.getMessage());
e.setMessage(PLUGIN.emojis.parse(sender, resetColor, e.getMessage(), false));
}
}

};

@EventHandler(ignoreCancelled = true)
public void onPlayerChat(AsyncPlayerChatEvent e) {
String resetColor = ChatColor.RESET + ChatColor.getLastColors(e.getMessage());
e.setMessage(PLUGIN.emojis.parse(e.getPlayer(), resetColor, e.getMessage(), false));
}

@EventHandler
public void onPluginEnable(PluginEnableEvent e) {
switch(e.getPlugin().getName()) {
case "PlaceholderAPI":
PLUGIN.papiIsLoaded = true;
break;
case "Essentials":
PLUGIN.getServer().getPluginManager().registerEvents(ESSENTIALS_LISTENER, PLUGIN);
break;
}
}

@EventHandler
public void onPluginDisable(PluginDisableEvent e) {
switch(e.getPlugin().getName()) {
case "PlaceholderAPI":
PLUGIN.papiIsLoaded = false;
break;
case "Essentials":
HandlerList.unregisterAll(ESSENTIALS_LISTENER);
break;
}
}

@EventHandler(ignoreCancelled = true)
public void onSignChange(SignChangeEvent e) {
if(Boolean.TRUE.equals(PLUGIN.useOnSigns.getValue())) {
for(int i = 0; i < e.getLines().length; i++) {
String line = e.getLine(i);
assert line != null;
String resetColor = ChatColor.RESET + ChatColor.getLastColors(line);
e.setLine(i, PLUGIN.emojis.parse(e.getPlayer(), resetColor, line, false));
}
}
}

@EventHandler(ignoreCancelled = true)
public void onPlayerBookEdit(PlayerEditBookEvent e) {
if(Boolean.TRUE.equals(PLUGIN.useInBooks.getValue())) {
List<String> newContent = new ArrayList<>();
BookMeta meta = e.getNewBookMeta();
meta.getPages().forEach(string -> {
String resetColor = ChatColor.RESET + ChatColor.getLastColors(string);
newContent.add(PLUGIN.emojis.parse(e.getPlayer(), resetColor, string, false));
});
meta.setPages(newContent);
e.setNewBookMeta(meta);
}
}

}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: ${project.version}
main: com.rmjtromp.chatemojis.ChatEmojis
api-version: 1.13
authors: [ RMJTromp ]
soft-depend: [ PlaceholderAPI ]
soft-depend: [ PlaceholderAPI, Essentials ]

commands:
emoji:
Expand Down

0 comments on commit fcd93ec

Please sign in to comment.