mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Add join/leave/death messages to bridge
This commit is contained in:
1 parent
4018f03df4
commit
245ef56d94
2 files changed
+59
-11
No files matched your search
@@ -1,9 +1,8 @@
|
|||||||
package net.draycia.simplechat.listeners;
|
package net.draycia.simplechat.listeners;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.kyori.adventure.text.event.HoverEvent;
|
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@@ -12,9 +11,8 @@ import org.bukkit.event.entity.PlayerDeathEvent;
|
|||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.javacord.api.DiscordApi;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@@ -24,6 +22,7 @@ public class PlayerListener implements Listener {
|
|||||||
this.simpleChat = simpleChat;
|
this.simpleChat = simpleChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Chat messages
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerchat(AsyncPlayerChatEvent event) {
|
public void onPlayerchat(AsyncPlayerChatEvent event) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@@ -37,19 +36,60 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
// Player joins
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
// TODO: join messages (placeholderapi support)
|
if (!simpleChat.getConfig().getBoolean("listeners.join")) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
ChatChannel chatChannel = simpleChat.getDefaultChannel();
|
||||||
|
|
||||||
|
if (chatChannel != null && chatChannel.getChannelId() > -1) {
|
||||||
|
DiscordApi api = simpleChat.getDiscordManager().getDiscordAPI();
|
||||||
|
String message = simpleChat.getConfig().getString("language.player-joined");
|
||||||
|
|
||||||
|
api.getServerTextChannelById(chatChannel.getChannelId()).ifPresent(channel -> {
|
||||||
|
channel.sendMessage(PlaceholderAPI.setPlaceholders(event.getPlayer(), message));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Player quits
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||||
// TODO: leave messages (placeholderapi support)
|
if (!simpleChat.getConfig().getBoolean("listeners.leave")) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
ChatChannel chatChannel = simpleChat.getDefaultChannel();
|
||||||
|
|
||||||
|
if (chatChannel != null && chatChannel.getChannelId() > -1) {
|
||||||
|
DiscordApi api = simpleChat.getDiscordManager().getDiscordAPI();
|
||||||
|
String message = simpleChat.getConfig().getString("language.player-left");
|
||||||
|
|
||||||
|
api.getServerTextChannelById(chatChannel.getChannelId()).ifPresent(channel -> {
|
||||||
|
channel.sendMessage(PlaceholderAPI.setPlaceholders(event.getPlayer(), message));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Player deaths
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||||
// TODO: death messages (placeholderapi support)
|
if (!simpleChat.getConfig().getBoolean("listeners.death")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatChannel chatChannel = simpleChat.getDefaultChannel();
|
||||||
|
|
||||||
|
if (chatChannel != null && chatChannel.getChannelId() > -1) {
|
||||||
|
DiscordApi api = simpleChat.getDiscordManager().getDiscordAPI();
|
||||||
|
|
||||||
|
api.getServerTextChannelById(chatChannel.getChannelId()).ifPresent(channel -> {
|
||||||
|
channel.sendMessage(event.getDeathMessage());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -48,6 +48,8 @@ language:
|
|||||||
not-ignoring-user: '<green>You are no longer ignoring <gold><player><green>!'
|
not-ignoring-user: '<green>You are no longer ignoring <gold><player><green>!'
|
||||||
is-now-shadow-muted: '<yellow>User <user> is now shadow muted!'
|
is-now-shadow-muted: '<yellow>User <user> is now shadow muted!'
|
||||||
no-longer-shadow-muted: '<yellow>User <user> is no longer shadow muted!'
|
no-longer-shadow-muted: '<yellow>User <user> is no longer shadow muted!'
|
||||||
|
player-left: '%player_displayname% has left <server>!'
|
||||||
|
player-joined: '%player_displayname% has joined <server>!'
|
||||||
|
|
||||||
server-name: 'Server'
|
server-name: 'Server'
|
||||||
|
|
||||||
@@ -65,3 +67,9 @@ pings:
|
|||||||
volume: 10.0
|
volume: 10.0
|
||||||
pitch: 1.0
|
pitch: 1.0
|
||||||
highlight: true # Independent of the "enabled" option!
|
highlight: true # Independent of the "enabled" option!
|
||||||
|
|
||||||
|
listeners:
|
||||||
|
join: true # sends join messages in discord
|
||||||
|
leave: true # sends leave messages in discord
|
||||||
|
death: true # sends death messages in discord
|
||||||
|
# TODO: NuVofitier support
|
||||||
Reference in new issue
Block a user