Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Modules #150

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 76 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,77 +144,93 @@ file-version: 9
# Supports Mini-Message/Legacy Color Codes
# ==========================================================

# Prefix for the plugin. %plugin-prefix% usable anywhere.
plugin-prefix: "&8[<bold><rainbow>SimpleProxyChat&r&8]"

# Minecraft Stuff
minecraft:
join:
use: true
message: "&e%player% &ahas joined the network. (%server%)"
leave:
use: true
message: "&e%player% &chas left the network. (%server%)"
message: "&8[&3%server%&8] &e%player% &9» &7%message%"
discord:
message: "**%server%** %player% » %message%"
embed:
use: false
title: "[%server%] %player%"
message: "%message%"
color: "#FFC0CB"
use-timestamp: true
switch:
use: true
default: "&e%player% &7moved from &c%from% &7to &a%to%&7."
no-from: "&e%player% &7moved &7to &a%to%&7."
command:
no-permission: "%plugin-prefix% &cSorry, you do not have permission to run this command."
unknown: "%plugin-prefix% &cUnknown command."
must-be-player: "%plugin-prefix% &cYou must be a player to run this command."
reload: "%plugin-prefix% &aThe plugin has been successfully reloaded!"
chat-lock:
usage: "%plugin-prefix% &cCorrect usage is &a/spc-chat all lock/unlock &c or &a/spc-chat lock/unlock"
single:
locked: "%plugin-prefix% &6%server% &cwill no longer send proxy chat messages."
unlocked: "%plugin-prefix% &6%server% &awill now send proxy chat messages."
all:
locked: "%plugin-prefix% &cAll servers will no longer send proxy chat messages."
unlocked: "%plugin-prefix% &aAll servers will now send proxy chat messages."
join:
enabled: true
message: "&e%player% &ahas joined the network. (%server%)"
leave:
enabled: true
message: "&e%player% &chas left the network. (%server%)"
chat:
enabled: true
message: "&8[&3%server%&8] &e%player% &9» &7%message%"
switch:
enabled: true
default: "&e%player% &7moved from &c%from% &7to &a%to%&7."
no-from: "&e%player% &7moved &7to &a%to%&7."
discord:
enabled: true
message: "**%server%** %player% » %message%"
embed:
use: false
title: "[%server%] %player%"
message: "%message%"
color: "#FFC0CB"
use-timestamp: true
command:
no-permission: "%plugin-prefix% &cSorry, you do not have permission to run this command."
unknown: "%plugin-prefix% &cUnknown command."
must-be-player: "%plugin-prefix% &cYou must be a player to run this command."
reload: "%plugin-prefix% &aThe plugin has been successfully reloaded!"
chat-lock:
usage: "%plugin-prefix% &cCorrect usage is &a/spc-chat all lock/unlock &c or &a/spc-chat lock/unlock"
single:
locked: "%plugin-prefix% &6%server% &cwill no longer send proxy chat messages."
unlocked: "%plugin-prefix% &6%server% &awill now send proxy chat messages."
all:
locked: "%plugin-prefix% &cAll servers will no longer send proxy chat messages."
unlocked: "%plugin-prefix% &aAll servers will now send proxy chat messages."

# Discord Stuff
discord:
join:
use: true
message: "%player% has joined the network. (%server%)"
use-timestamp: true
leave:
use: true
message: "%player% has left the network. (%server%)"
use-timestamp: true
switch:
use: true
message: "%player% has switched from %from% to %to%."
use-timestamp: true
minecraft-message: "&8[&bDiscord&8] %role% &f%user% &9» &7%message%"
topic:
online: "There are %online% players online."
offline: "The proxy is offline."
proxy-status:
enabled: "✅ Proxy enabled!"
disabled: "⛔ Proxy disabled."
title: "Server Status"
message: "Status: "
online: "Online ✅"
offline: "Offline ⛔"
use-timestamp: true

# Prefix for the plugin. %plugin-prefix% usable anywhere.
plugin-prefix: "&8[<bold><rainbow>SimpleProxyChat&r&8]"
join:
enabled: true
message: "%player% has joined the network. (%server%)"
use-timestamp: true
leave:
enabled: true
message: "%player% has left the network. (%server%)"
use-timestamp: true
switch:
enabled: true
message: "%player% has switched from %from% to %to%."
use-timestamp: true
chat:
enabled: true
minecraft-message: "&8[&bDiscord&8] %role% &f%user% &9» &7%message%"
topic:
online: "There are %online% players online."
offline: "The proxy is offline."
proxy-status:
enabled: true
messages:
enabled: "✅ Proxy enabled!"
disabled: "⛔ Proxy disabled."
title: "Server Status"
message: "Status: "
online: "Online ✅"
offline: "Offline ⛔"
use-timestamp: true

# Console Stuff - Uses Minecraft Messages
console:
chat: true
join: true
leave: true
switch: true
discord-chat: true
server-status: true

# The message for any updates that are sent.
# The plugin-prefix is automatically appended to the beginning of this message.
update-message: "&7There is an update! You are on &c%old%. New version is &a%new%&7: &6%link%"

# DO NOT TOUCH THIS
file-version: 6
file-version: 7
```

---
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "com.beanbeanjuice"
version = "0.3.8"
version = "0.3.9"

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -234,6 +234,7 @@ hangarPublish {

tasks.withType<ShadowJar> {
minimize()
relocate("dev.dejvokep.boostedyaml", "com.beanbeanjuice.simpleproxychat.libs.dev.dejvokep.boostedyaml")
relocate("org.bstats", "com.beanbeanjuice.simpleproxychat.libs.org.bstats")
relocate("net.dv8tion", "com.beanbeanjuice.simpleproxychat.libs.net.dv8tion")
archiveBaseName.set(rootProject.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void onEnable() {
manager.getAllStatusStrings().forEach((string) -> this.getLogger().info(string));

if (!config.getAsBoolean(ConfigDataKey.USE_INITIAL_SERVER_STATUS)) return;
if (!config.getAsBoolean(ConfigDataKey.DISCORD_PROXY_STATUS_ENABLED)) return;
this.discordBot.sendMessageEmbed(manager.getAllStatusEmbed());
}, config.getAsInteger(ConfigDataKey.SERVER_UPDATE_INTERVAL) * 2L, TimeUnit.SECONDS);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
manager.getAllStatusStrings().forEach(this.getLogger()::info);

if (!config.getAsBoolean(ConfigDataKey.USE_INITIAL_SERVER_STATUS)) return;
if (!config.getAsBoolean(ConfigDataKey.DISCORD_PROXY_STATUS_ENABLED)) return;
discordBot.sendMessageEmbed(manager.getAllStatusEmbed());
})
.delay(config.getAsInteger(ConfigDataKey.SERVER_UPDATE_INTERVAL) * 2L, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void runProxyChatMessage(String serverName, String playerName, UUID playe
if (optionalPlayerMessage.isEmpty()) return;
playerMessage = optionalPlayerMessage.get();

String minecraftConfigString = config.getAsString(ConfigDataKey.MINECRAFT_MESSAGE);
String minecraftConfigString = config.getAsString(ConfigDataKey.MINECRAFT_CHAT_MESSAGE);
String discordConfigString = config.getAsString(ConfigDataKey.MINECRAFT_DISCORD_MESSAGE);

String aliasedServerName = Helper.convertAlias(config, serverName);
Expand All @@ -96,32 +96,34 @@ public void runProxyChatMessage(String serverName, String playerName, UUID playe
}

// Log to Console
pluginLogger.accept(minecraftMessage);
if (config.getAsBoolean(ConfigDataKey.CONSOLE_CHAT)) pluginLogger.accept(minecraftMessage);

// Log to Discord
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_DISCORD_EMBED_USE)) {
String title = Helper.replaceKeys(config.getAsString(ConfigDataKey.MINECRAFT_DISCORD_EMBED_TITLE), replacements);
String message = Helper.replaceKeys(config.getAsString(ConfigDataKey.MINECRAFT_DISCORD_EMBED_MESSAGE), replacements);
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_DISCORD_ENABLED)) {
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_DISCORD_EMBED_USE)) {
String title = Helper.replaceKeys(config.getAsString(ConfigDataKey.MINECRAFT_DISCORD_EMBED_TITLE), replacements);
String message = Helper.replaceKeys(config.getAsString(ConfigDataKey.MINECRAFT_DISCORD_EMBED_MESSAGE), replacements);

title = replacePrefixSuffix(title, playerUUID, aliasedServerName, serverName);
title = replacePrefixSuffix(title, playerUUID, aliasedServerName, serverName);

Color color = config.getAsColor(ConfigDataKey.MINECRAFT_DISCORD_EMBED_COLOR).orElse(Color.RED);
Color color = config.getAsColor(ConfigDataKey.MINECRAFT_DISCORD_EMBED_COLOR).orElse(Color.RED);

EmbedBuilder embedBuilder = new EmbedBuilder()
.setAuthor(title, null, getPlayerHeadURL(playerUUID))
.setDescription(message)
.setColor(color);
EmbedBuilder embedBuilder = new EmbedBuilder()
.setAuthor(title, null, getPlayerHeadURL(playerUUID))
.setDescription(message)
.setColor(color);

if (config.getAsBoolean(ConfigDataKey.MINECRAFT_DISCORD_EMBED_USE_TIMESTAMP))
embedBuilder.setTimestamp(epochHelper.getEpochInstant());
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_DISCORD_EMBED_USE_TIMESTAMP))
embedBuilder.setTimestamp(epochHelper.getEpochInstant());

discordBot.sendMessageEmbed(embedBuilder.build());
} else {
discordBot.sendMessage(discordMessage);
discordBot.sendMessageEmbed(embedBuilder.build());
} else {
discordBot.sendMessage(discordMessage);
}
}

// Log to Minecraft
minecraftLogger.accept(minecraftMessage);
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_CHAT_ENABLED)) minecraftLogger.accept(minecraftMessage);
}

public void runProxyLeaveMessage(String playerName, UUID playerUUID, String serverName,
Expand Down Expand Up @@ -150,17 +152,18 @@ public void runProxyLeaveMessage(String playerName, UUID playerUUID, String serv
}

// Log to Console
pluginLogger.accept(message);
if (config.getAsBoolean(ConfigDataKey.CONSOLE_LEAVE)) pluginLogger.accept(message);


// Log to Discord
if (config.getAsBoolean(ConfigDataKey.DISCORD_LEAVE_USE)) {
if (config.getAsBoolean(ConfigDataKey.DISCORD_LEAVE_ENABLED)) {
EmbedBuilder embedBuilder = simpleAuthorEmbedBuilder(playerUUID, discordMessage).setColor(Color.RED);
if (config.getAsBoolean(ConfigDataKey.DISCORD_LEAVE_USE_TIMESTAMP)) embedBuilder.setTimestamp(epochHelper.getEpochInstant());
discordBot.sendMessageEmbed(embedBuilder.build());
}

// Log to Minecraft
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_LEAVE_USE))
minecraftLogger.accept(message, Permission.READ_LEAVE_MESSAGE);
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_LEAVE_ENABLED)) minecraftLogger.accept(message, Permission.READ_LEAVE_MESSAGE);
}

public void runProxyJoinMessage(String playerName, UUID playerUUID, String serverName,
Expand Down Expand Up @@ -191,17 +194,17 @@ public void runProxyJoinMessage(String playerName, UUID playerUUID, String serve
}

// Log to Console
pluginLogger.accept(message);
if (config.getAsBoolean(ConfigDataKey.CONSOLE_JOIN)) pluginLogger.accept(message);

// Log to Discord
if (config.getAsBoolean(ConfigDataKey.DISCORD_JOIN_USE)) {
if (config.getAsBoolean(ConfigDataKey.DISCORD_JOIN_ENABLED)) {
EmbedBuilder embedBuilder = simpleAuthorEmbedBuilder(playerUUID, discordMessage).setColor(Color.GREEN);
if (config.getAsBoolean(ConfigDataKey.DISCORD_JOIN_USE_TIMESTAMP)) embedBuilder.setTimestamp(epochHelper.getEpochInstant());
discordBot.sendMessageEmbed(embedBuilder.build());
}

// Log to Minecraft
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_JOIN_USE))
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_JOIN_ENABLED))
minecraftLogger.accept(message, Permission.READ_JOIN_MESSAGE);
}

Expand Down Expand Up @@ -237,17 +240,17 @@ public void runProxySwitchMessage(String from, String to, String playerName, UUI
}

// Log to Console
pluginLogger.accept(consoleMessage);
if (config.getAsBoolean(ConfigDataKey.CONSOLE_SWITCH)) pluginLogger.accept(consoleMessage);

// Log to Discord
if (config.getAsBoolean(ConfigDataKey.DISCORD_SWITCH_USE)) {
if (config.getAsBoolean(ConfigDataKey.DISCORD_SWITCH_ENABLED)) {
EmbedBuilder embedBuilder = simpleAuthorEmbedBuilder(playerUUID, discordMessage).setColor(Color.YELLOW);
if (config.getAsBoolean(ConfigDataKey.DISCORD_SWITCH_USE_TIMESTAMP)) embedBuilder.setTimestamp(epochHelper.getEpochInstant());
discordBot.sendMessageEmbed(embedBuilder.build());
}

// Log to Minecraft
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_SWITCH_USE))
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_SWITCH_ENABLED))
minecraftLogger.accept(minecraftMessage);
}

Expand All @@ -268,7 +271,7 @@ private String getPlayerHeadURL(UUID playerUUID) {
}

public void sendFromDiscord(MessageReceivedEvent event) {
String message = config.getAsString(ConfigDataKey.DISCORD_MINECRAFT_MESSAGE);
String message = config.getAsString(ConfigDataKey.DISCORD_CHAT_MINECRAFT_MESSAGE);

if (event.getMember() == null) return;

Expand Down Expand Up @@ -297,7 +300,7 @@ public void sendFromDiscord(MessageReceivedEvent event) {
Tuple.of("plugin-prefix", config.getAsString(ConfigDataKey.PLUGIN_PREFIX))
);

globalLogger.accept(message);
if (config.getAsBoolean(ConfigDataKey.MINECRAFT_DISCORD_ENABLED)) globalLogger.accept(message);
}

private List<String> getPrefixBasedOnServerContext(User user, String... serverKeys) {
Expand Down
34 changes: 22 additions & 12 deletions src/main/java/com/beanbeanjuice/simpleproxychat/discord/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,7 @@ public void start() throws InterruptedException {
.enableIntents(GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS)
.build().awaitReady();

this.sendMessageEmbed(
new EmbedBuilder()
.setTitle(config.getAsString(ConfigDataKey.DISCORD_PROXY_ENABLED))
.setColor(Color.GREEN)
.build()
);
sendProxyStatus(true);

this.updateActivity();

Expand All @@ -166,13 +161,28 @@ public void updateActivity() {
});
}

public void sendProxyStatus(boolean isStart) {
if (!config.getAsBoolean(ConfigDataKey.DISCORD_PROXY_STATUS_ENABLED)) return;

if (isStart) {
this.sendMessageEmbed(
new EmbedBuilder()
.setTitle(config.getAsString(ConfigDataKey.DISCORD_PROXY_STATUS_MODULE_ENABLED))
.setColor(Color.GREEN)
.build()
);
} else {
this.sendMessageEmbed(
new EmbedBuilder()
.setTitle(config.getAsString(ConfigDataKey.DISCORD_PROXY_STATUS_MODULE_DISABLED))
.setColor(Color.RED)
.build()
);
}
}

public void stop() {
this.sendMessageEmbed(
new EmbedBuilder()
.setTitle(config.getAsString(ConfigDataKey.DISCORD_PROXY_DISABLED))
.setColor(Color.RED)
.build()
);
sendProxyStatus(false);

this.updateChannelTopic(config.getAsString(ConfigDataKey.DISCORD_TOPIC_OFFLINE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public DiscordChatHandler(Config config,
public void onMessageReceived(MessageReceivedEvent event) {
if (!event.getChannel().getId().equalsIgnoreCase(config.getAsString(ConfigDataKey.CHANNEL_ID))) return;
if (event.getAuthor().isBot()) return;
if (!config.getAsBoolean(ConfigDataKey.DISCORD_CHAT_ENABLED)) return;

sendFromDiscord.accept(event);
}
Expand Down
Loading
Loading