Skip to content

Commit

Permalink
Merge pull request #222 from beanbeanjuice/development
Browse files Browse the repository at this point in the history
  • Loading branch information
beanbeanjuice authored Aug 31, 2024
2 parents c85a22c + 6725017 commit 005e7a4
Show file tree
Hide file tree
Showing 40 changed files with 614 additions and 526 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,28 @@ send-previous-messages-on-switch:

# These require a restart in order to take place.
commands:
reload-aliases:
- "spcreload"
chat-toggle-aliases:
- "chattoggle"
ban-aliases:
- "spcban"
unban-aliases:
- "spcunban"
whisper-aliases:
- "spc-msg"
reply-aliases:
- "spc-r"
broadcast-aliases:
- "spc-bc"
- "broadcast"

# Disable servers from sending/receiving proxy messages.
disabled-servers:
- example1

# DO NOT TOUCH THIS
file-version: 13
file-version: 15
```
**messages.yml**
Expand Down Expand Up @@ -245,14 +260,20 @@ discord:
enabled: true
message: "%player% has joined the network. (%server%)"
use-timestamp: true
# Incompatible with use-timestamp.
use-embed: true
leave:
enabled: true
message: "%player% has left the network. (%server%)"
use-timestamp: true
# Incompatible with use-timestamp.
use-embed: true
switch:
enabled: true
message: "%player% has switched from %from% to %to%."
use-timestamp: true
# Incompatible with use-timestamp.
use-embed: true
chat:
enabled: true
minecraft-message: "&8[&bDiscord&8] %role% &f%user% &9» &7%message%"
Expand Down Expand Up @@ -284,7 +305,7 @@ console:
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: 9
file-version: 10
```
---
Expand Down Expand Up @@ -335,6 +356,7 @@ file-version: 9
* `%from%` - The server the player just disconnected from. Uses the alias if one is specified.
* `%original_from%` - Same as `%from%`, but does not use the alias.
* `%player%` - The player's Minecraft username.
* `%escaped_player%` - The escaped player's Minecraft username. (Adds '\\' before the '_' to prevent italics.)
* `%sender%` - The person sending the private message. **Private Messaging Only**
* `%receiver%` - The person receiving the private message. **Private Messaging Only**
* `%user%` - The player's Discord username.
Expand Down
2 changes: 1 addition & 1 deletion projects/main-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

version = "0.5.6"
version = "0.5.7"

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.beanbeanjuice.simpleproxychat.discord.Bot;
import com.beanbeanjuice.simpleproxychat.utility.UpdateChecker;
import com.beanbeanjuice.simpleproxychat.utility.config.Config;
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigDataKey;
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigKey;
import com.beanbeanjuice.simpleproxychat.utility.status.ServerStatusManager;
import de.myzelyam.api.vanish.BungeeVanishAPI;
import litebans.api.Database;
Expand All @@ -28,12 +28,10 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager;
import nl.chimpgamer.networkmanager.api.NetworkManagerPlugin;
import nl.chimpgamer.networkmanager.api.NetworkManagerProvider;
import org.bstats.bungeecord.Metrics;

Expand All @@ -43,6 +41,7 @@

public final class SimpleProxyChatBungee extends Plugin implements ISimpleProxyChat {

@Getter private boolean pluginStarting = true;
@Getter private Config config;
@Getter private EpochHelper epochHelper;
@Getter private Bot discordBot;
Expand Down Expand Up @@ -92,15 +91,15 @@ public void onEnable() {
// Send Initial Server Status
discordBot.addRunnableToQueue(() -> {
this.getProxy().getScheduler().schedule(this, () -> {
this.config.overwrite(ConfigDataKey.PLUGIN_STARTING, false);
this.pluginStarting = false;

ServerStatusManager manager = serverListener.getServerStatusManager();
manager.getAllStatusStrings().forEach((string) -> this.getLogger().info(string));
manager.getAllStatusStrings().stream().map(Helper::sanitize).forEach((string) -> this.getLogger().info(string));

if (!config.getAsBoolean(ConfigDataKey.USE_INITIAL_SERVER_STATUS)) return;
if (!config.getAsBoolean(ConfigDataKey.DISCORD_PROXY_STATUS_ENABLED)) return;
if (!config.get(ConfigKey.USE_INITIAL_SERVER_STATUS).asBoolean()) return;
if (!config.get(ConfigKey.DISCORD_PROXY_STATUS_ENABLED).asBoolean()) return;
this.discordBot.sendMessageEmbed(manager.getAllStatusEmbed());
}, config.getAsInteger(ConfigDataKey.SERVER_UPDATE_INTERVAL) * 2L, TimeUnit.SECONDS);
}, config.get(ConfigKey.SERVER_UPDATE_INTERVAL).asInt() * 2L, TimeUnit.SECONDS);
});
}

Expand All @@ -111,11 +110,11 @@ private void startUpdateChecker() {
config,
currentVersion,
(message) -> {
if (!config.getAsBoolean(ConfigDataKey.UPDATE_NOTIFICATIONS)) return;
if (!config.get(ConfigKey.UPDATE_NOTIFICATIONS).asBoolean()) return;

this.getLogger().info(Helper.sanitize(message));

Component minimessage = MiniMessage.miniMessage().deserialize(config.getAsString(ConfigDataKey.PLUGIN_PREFIX) + message);
Component minimessage = MiniMessage.miniMessage().deserialize(config.get(ConfigKey.PLUGIN_PREFIX).asString() + message);
this.getProxy().getPlayers()
.stream()
.filter((player) -> player.hasPermission(Permission.READ_UPDATE_NOTIFICATION.getPermissionNode()))
Expand Down Expand Up @@ -156,12 +155,12 @@ private void hookPlugins() {
}

// Registering the Simple Ban System
if (!this.isLiteBansEnabled() && !this.isAdvancedBanEnabled() && config.getAsBoolean(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM)) {
if (!this.isLiteBansEnabled() && !this.isAdvancedBanEnabled() && config.get(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM).asBoolean()) {
getLogger().info("LiteBans and AdvancedBan not found. Using the built-in banning system for SimpleProxyChat...");
banHelper = new BanHelper(this.getDataFolder());
banHelper.initialize();
} else {
config.overwrite(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM, false);
config.overwrite(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM, false);
}
}

Expand All @@ -176,16 +175,16 @@ private void registerListeners() {
}

private void registerCommands() {
this.getProxy().getPluginManager().registerCommand(this, new BungeeReloadCommand(this, config.getAsArrayList(ConfigDataKey.RELOAD_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeChatToggleCommand(this, config.getAsArrayList(ConfigDataKey.CHAT_TOGGLE_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeWhisperCommand(this, config.getAsArrayList(ConfigDataKey.WHISPER_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeReplyCommand(this, config.getAsArrayList(ConfigDataKey.REPLY_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeBroadcastCommand(this, config.getAsArrayList(ConfigDataKey.BROADCAST_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeReloadCommand(this, config.get(ConfigKey.RELOAD_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeChatToggleCommand(this, config.get(ConfigKey.CHAT_TOGGLE_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeWhisperCommand(this, config.get(ConfigKey.WHISPER_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeReplyCommand(this, config.get(ConfigKey.REPLY_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeBroadcastCommand(this, config.get(ConfigKey.BROADCAST_ALIASES).asList().toArray(new String[0])));

// Only enable when needed.
if (config.getAsBoolean(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM)) {
this.getProxy().getPluginManager().registerCommand(this, new BungeeBanCommand(this, config.getAsArrayList(ConfigDataKey.BAN_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeUnbanCommand(this, config.getAsArrayList(ConfigDataKey.UNBAN_ALIASES).toArray(new String[0])));
if (config.get(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM).asBoolean()) {
this.getProxy().getPluginManager().registerCommand(this, new BungeeBanCommand(this, config.get(ConfigKey.BAN_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeUnbanCommand(this, config.get(ConfigKey.UNBAN_ALIASES).asList().toArray(new String[0])));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.beanbeanjuice.simpleproxychat.discord.Bot;
import com.beanbeanjuice.simpleproxychat.utility.helper.Helper;
import com.beanbeanjuice.simpleproxychat.utility.config.Config;
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigDataKey;
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigKey;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.event.PostOrder;
Expand All @@ -38,9 +38,7 @@
import me.leoko.advancedban.manager.UUIDManager;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import nl.chimpgamer.networkmanager.api.NetworkManagerPlugin;
import nl.chimpgamer.networkmanager.api.NetworkManagerProvider;
import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
Expand All @@ -54,6 +52,8 @@ public class SimpleProxyChatVelocity implements ISimpleProxyChat {

private final Metrics.Factory metricsFactory;

@Getter private boolean pluginStarting = true;

@Getter private final ProxyServer proxyServer;
@Getter private final Logger logger;
@Getter private final Config config;
Expand Down Expand Up @@ -118,16 +118,16 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
// Send initial server status.
discordBot.addRunnableToQueue(() -> {
this.getProxyServer().getScheduler().buildTask(this, () -> {
this.config.overwrite(ConfigDataKey.PLUGIN_STARTING, false);
this.pluginStarting = false;

ServerStatusManager manager = serverListener.getServerStatusManager();
manager.getAllStatusStrings().forEach(this.getLogger()::info);
manager.getAllStatusStrings().stream().map(Helper::sanitize).forEach(this.getLogger()::info);

if (!config.getAsBoolean(ConfigDataKey.USE_INITIAL_SERVER_STATUS)) return;
if (!config.getAsBoolean(ConfigDataKey.DISCORD_PROXY_STATUS_ENABLED)) return;
if (!config.get(ConfigKey.USE_INITIAL_SERVER_STATUS).asBoolean()) return;
if (!config.get(ConfigKey.DISCORD_PROXY_STATUS_ENABLED).asBoolean()) return;
discordBot.sendMessageEmbed(manager.getAllStatusEmbed());
})
.delay(config.getAsInteger(ConfigDataKey.SERVER_UPDATE_INTERVAL) * 2L, TimeUnit.SECONDS)
.delay(config.get(ConfigKey.SERVER_UPDATE_INTERVAL).asInt() * 2L, TimeUnit.SECONDS)
.schedule();
});
}
Expand All @@ -141,12 +141,12 @@ private void startUpdateChecker() {
config,
currentVersion,
(message) -> {
if (!config.getAsBoolean(ConfigDataKey.UPDATE_NOTIFICATIONS)) return;
if (!config.get(ConfigKey.UPDATE_NOTIFICATIONS).asBoolean()) return;
this.getLogger().info(Helper.sanitize(message));
this.proxyServer.getAllPlayers()
.stream()
.filter((player) -> player.hasPermission(Permission.READ_UPDATE_NOTIFICATION.getPermissionNode()))
.forEach((player) -> player.sendMessage(Helper.stringToComponent(config.getAsString(ConfigDataKey.PLUGIN_PREFIX) + message)));
.forEach((player) -> player.sendMessage(Helper.stringToComponent(config.get(ConfigKey.PLUGIN_PREFIX).asString() + message)));
}
);

Expand Down Expand Up @@ -185,12 +185,12 @@ private void hookPlugins() {
}

// Registering the Simple Banning System
if (!this.isLiteBansEnabled() && !this.isAdvancedBanEnabled() && config.getAsBoolean(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM)) {
if (!this.isLiteBansEnabled() && !this.isAdvancedBanEnabled() && config.get(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM).asBoolean()) {
getLogger().info("LiteBans and AdvancedBan not found. Using the built-in banning system for SimpleProxyChat...");
banHelper = new BanHelper(dataDirectory);
banHelper.initialize();
} else {
config.overwrite(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM, false);
config.overwrite(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM, false);
}
}

Expand All @@ -211,37 +211,37 @@ private void registerCommands() {
CommandManager commandManager = proxyServer.getCommandManager();

CommandMeta reloadCommand = commandManager.metaBuilder("spc-reload")
.aliases(config.getAsArrayList(ConfigDataKey.RELOAD_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.RELOAD_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta chatToggleCommand = commandManager.metaBuilder("spc-chat")
.aliases(config.getAsArrayList(ConfigDataKey.CHAT_TOGGLE_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.CHAT_TOGGLE_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta whisperCommand = commandManager.metaBuilder("spc-whisper")
.aliases(config.getAsArrayList(ConfigDataKey.WHISPER_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.WHISPER_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta replyCommand = commandManager.metaBuilder("spc-reply")
.aliases(config.getAsArrayList(ConfigDataKey.REPLY_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.REPLY_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta banCommand = commandManager.metaBuilder("spc-ban")
.aliases(config.getAsArrayList(ConfigDataKey.BAN_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.BAN_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta unbanCommand = commandManager.metaBuilder("spc-unban")
.aliases(config.getAsArrayList(ConfigDataKey.UNBAN_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.UNBAN_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta broadcastCommand = commandManager.metaBuilder("spc-broadcast")
.aliases(config.getAsArrayList(ConfigDataKey.BROADCAST_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.BROADCAST_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

Expand All @@ -252,7 +252,7 @@ private void registerCommands() {
commandManager.register(broadcastCommand, new VelocityBroadcastCommand(this));

// Only enable if the Simple Banning System is enabled.
if (config.getAsBoolean(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM)) {
if (config.get(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM).asBoolean()) {
commandManager.register(banCommand, new VelocityBanCommand(this));
commandManager.register(unbanCommand, new VelocityUnbanCommand(this));
}
Expand Down
Loading

0 comments on commit 005e7a4

Please sign in to comment.