-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from RMJTromp/2.3.2
v2.3.2 Added Essentials Messaging Support
- Loading branch information
Showing
7 changed files
with
173 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/com/rmjtromp/chatemojis/PluginListeners.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters