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

v0.5.3 Integration #192

Merged
merged 6 commits into from
Jul 18, 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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ CHANNEL-ID: "GLOBAL_CHANNEL_ID"
bot-activity:
# Valid Types: ONLINE, DO_NOT_DISTURB, IDLE, INVISIBLE
status: ONLINE
# Valid Types: PLAYING, STREAMING, LISTENING, WATCHING, COMPETING
type: "COMPETING"
text: "SimpleProxyChat by beanbeanjuice"
# Valid Types: PLAYING, STREAMING, LISTENING, WATCHING, COMPETING, CUSTOM_STATUS
type: "CUSTOM_STATUS"
# Valid placeholders are %online% and/or %max-players% (UPDATES EVERY 5 MINUTES)
text: "%online%/%max-players% - SimpleProxyChat by beanbeanjuice"

# The amount of seconds to check if a server is online/offline.
# Smaller numbers can cause errors. Beware.
Expand Down Expand Up @@ -344,6 +345,8 @@ file-version: 9
* `%message%` - The player's message.
* `%epoch%` - This get's the current time (in milliseconds). Formats can be used like [this](https://gist.github.com/LeviSnoot/d9147767abeef2f770e9ddcd91eb85aa). An example would be `<t:%epoch%>`. **Discord Only**
* `%time%` - Similar to `%epoch%`, but uses a special formatting and timezone found in `config.yml`. **Discord and Minecraft**
* `%online%` - **Discord Status Only**
* `%max-players%` - **Discord Status Online**

---

Expand Down
2 changes: 1 addition & 1 deletion projects/helper-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.0.2"
version = "0.0.3"

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down
2 changes: 1 addition & 1 deletion projects/helper-app/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ depend: [PlaceholderAPI]
authors: [beanbeanjuice]
description: A helper plugin for the SimpleProxyChat proxy plugin.
website: https://www.github.com/beanbeanjuice/SimpleProxyChat
api-version: 1.20
api-version: 1.13
5 changes: 4 additions & 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.2"
version = "0.5.3"

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -72,7 +72,10 @@ inline fun <reified C> Project.configure(name: String, configuration: C.() -> Un
}

tasks.withType<ShadowJar> {
// relocate("net.kyori", "com.beanbeanjuice.simpleproxychat.libs.net.kyori") // check
relocate("net.dv8tion", "com.beanbeanjuice.simpleproxychat.libs.net.dv8tion")
relocate("dev.dejvokep", "com.beanbeanjuice.simpleproxychat.libs.dev.dejvokep")
relocate("org.bstats", "com.beanbeanjuice.simpleproxychat.libs.org.bstats")
relocate("joda-time", "com.beanbeanjuice.simpleproxychat.libs.joda-time") // check
relocate("org.apache.maven", "com.beanbeanjuice.simpleproxychat.libs.org.apache.maven") // check
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,20 @@ public void onEnable() {
epochHelper = new EpochHelper(config);

this.getLogger().info("Attempting to initialize Discord bot... (if enabled)");
discordBot = new Bot(this.config, this.getLogger()::warning);
discordBot = new Bot(this.config, this.getLogger()::warning, this::getOnlinePlayers, this::getMaxPlayers);

this.getProxy().getScheduler().runAsync(this, () -> {
try { discordBot.start();
} catch (Exception e) { getLogger().warning("There was an error starting the discord bot: " + e.getMessage()); }
try { discordBot.start(); }
catch (Exception e) { getLogger().warning("There was an error starting the discord bot: " + e.getMessage()); }
});

registerListeners();
hookPlugins();
registerCommands();

// Discord Topic Updater
this.getProxy().getScheduler().schedule(this, () -> {
int numPlayers = this.getProxy().getPlayers().size();

if (config.getAsBoolean(ConfigDataKey.VANISH_ENABLED))
numPlayers = (int) this.getProxy().getPlayers().stream()
.filter((player) -> !BungeeVanishAPI.isInvisible(player))
.count();

discordBot.channelUpdaterFunction(numPlayers);
}, 10, 10, TimeUnit.MINUTES);
// Discord Topic/Status Updater
this.getProxy().getScheduler().schedule(this, discordBot::channelUpdaterFunction, 10, 10, TimeUnit.MINUTES);
this.getProxy().getScheduler().schedule(this, discordBot::updateActivity, 5, 5, TimeUnit.MINUTES);

// Update Checker
startUpdateChecker();
Expand Down Expand Up @@ -207,6 +199,19 @@ private void stopPluginMessaging() {
this.getProxy().unregisterChannel("BungeeCord");
}

private int getOnlinePlayers() {
if (config.getAsBoolean(ConfigDataKey.VANISH_ENABLED))
return (int) this.getProxy().getPlayers().stream()
.filter((player) -> !BungeeVanishAPI.isInvisible(player))
.count();

return this.getProxy().getOnlineCount();
}

private int getMaxPlayers() {
return this.getProxy().getConfig().getPlayerLimit();
}

@Override
public void onDisable() {
this.getLogger().info("The plugin is shutting down...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,21 @@ public SimpleProxyChatVelocity(ProxyServer proxyServer, Logger logger, @DataDire
public void onProxyInitialization(ProxyInitializeEvent event) {
// Initialize discord bot.
this.getLogger().info("Attempting to initialize Discord bot... (if enabled)");
discordBot = new Bot(this.config, this.getLogger()::warn);
discordBot = new Bot(this.config, this.getLogger()::warn, this::getOnlinePlayers, this::getMaxPlayers);

// Bot ready.
this.proxyServer.getScheduler().buildTask(this, () -> {
try { discordBot.start();
} catch (Exception e) { this.getLogger().warn("There was an error starting the discord bot: {}", e.getMessage()); }
try { discordBot.start(); }
catch (Exception e) { this.getLogger().warn("There was an error starting the discord bot: {}", e.getMessage()); }
}).schedule();

hookPlugins();
registerListeners();
registerCommands();

// Start Channel Topic Updater
this.proxyServer.getScheduler()
.buildTask(this, () -> {
int numPlayers = proxyServer.getPlayerCount();

if (config.getAsBoolean(ConfigDataKey.VANISH_ENABLED))
numPlayers = (int) proxyServer.getAllPlayers().stream()
.filter((player) -> !VelocityVanishAPI.isInvisible(player))
.count();

discordBot.channelUpdaterFunction(numPlayers);
})
.delay(10, TimeUnit.MINUTES)
.repeat(10, TimeUnit.MINUTES)
.schedule();
this.proxyServer.getScheduler().buildTask(this, discordBot::channelUpdaterFunction).delay(10, TimeUnit.MINUTES).repeat(10, TimeUnit.MINUTES).schedule();
this.proxyServer.getScheduler().buildTask(this, discordBot::updateActivity).delay(5, TimeUnit.MINUTES).repeat(5, TimeUnit.MINUTES).schedule();

// Start Update Checker
startUpdateChecker();
Expand Down Expand Up @@ -274,6 +262,19 @@ private void registerCommands() {
}
}

private int getOnlinePlayers() {
if (config.getAsBoolean(ConfigDataKey.VANISH_ENABLED))
return (int) proxyServer.getAllPlayers().stream()
.filter((player) -> !VelocityVanishAPI.isInvisible(player))
.count();

return this.getProxyServer().getPlayerCount();
}

private int getMaxPlayers() {
return this.getProxyServer().getConfiguration().getShowMaxPlayers();
}

@Subscribe(order = PostOrder.LAST)
public void onProxyShutdown(ProxyShutdownEvent event) {
this.getLogger().info("The plugin is shutting down...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class Bot {
Expand All @@ -28,11 +29,18 @@ public class Bot {
private final Consumer<String> errorLogger;
private JDA bot;

private final Supplier<Integer> getOnlinePlayers;
private final Supplier<Integer> getMaxPlayers;

private final Queue<Runnable> runnables;

public Bot(final Config config, final Consumer<String> errorLogger) {
public Bot(final Config config, final Consumer<String> errorLogger, final Supplier<Integer> getOnlinePlayers, final Supplier<Integer> getMaxPlayers) {
this.config = config;
this.errorLogger = errorLogger;

this.getOnlinePlayers = getOnlinePlayers;
this.getMaxPlayers = getMaxPlayers;

runnables = new ConcurrentLinkedQueue<>();

if (!config.getAsBoolean(ConfigDataKey.USE_DISCORD)) {
Expand Down Expand Up @@ -135,9 +143,9 @@ public void updateChannelTopic(final String topic) {
);
}

public void channelUpdaterFunction(final int players) {
public void channelUpdaterFunction() {
if (bot == null) return;
String topicMessage = config.getAsString(ConfigDataKey.DISCORD_TOPIC_ONLINE).replace("%online%", String.valueOf(players));
String topicMessage = config.getAsString(ConfigDataKey.DISCORD_TOPIC_ONLINE).replace("%online%", String.valueOf(getOnlinePlayers.get()));
this.updateChannelTopic(topicMessage);
}

Expand Down Expand Up @@ -172,6 +180,9 @@ public void start() throws InterruptedException {

public void updateActivity() {
this.getJDA().ifPresent((jda) -> {
int onlinePlayers = getOnlinePlayers.get();
int maxPlayers = getMaxPlayers.get();

Activity.ActivityType type;
String text;

Expand All @@ -182,6 +193,9 @@ public void updateActivity() {
type = Activity.ActivityType.WATCHING;
text = "CONFIG ERROR";
}

text = text.replace("%online%", String.valueOf(onlinePlayers))
.replace("%max-players%", String.valueOf(maxPlayers));
jda.getPresence().setActivity(Activity.of(type, text));
});
}
Expand Down Expand Up @@ -220,6 +234,7 @@ public void sendProxyStatus(final boolean isStart) {
}

public void stop() {
if (bot == null) return;
sendProxyStatus(false);

this.updateChannelTopic(config.getAsString(ConfigDataKey.DISCORD_TOPIC_OFFLINE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class BungeeChatMessageData extends ChatMessageData {

private final SimpleProxyChatBungee plugin;
private final SimpleProxyChatBungee plugin;
@Getter private final ServerInfo serverInfo;

public BungeeChatMessageData(SimpleProxyChatBungee plugin, MessageType type, ServerInfo serverInfo,
Expand Down Expand Up @@ -59,8 +59,10 @@ public void chatSendToAllOtherPlayers(String parsedMessage) {
plugin.getProxy().getPlayers().stream()
.filter((streamPlayer) -> !blacklistedPlayers.contains(streamPlayer))
.filter((streamPlayer) -> {
for (ProxiedPlayer blacklistedPlayer : blacklistedPlayers)
if (blacklistedPlayer.getName().equals(streamPlayer.getName())) return false;
if (blacklistedPlayers.contains(streamPlayer)) return false;
if (blacklistedPlayers.stream().map(ProxiedPlayer::getName).toList().contains(streamPlayer.getName())) return false;
if (blacklistedPlayers.stream().map(ProxiedPlayer::getUniqueId).toList().contains(streamPlayer.getUniqueId())) return false;

return true;
})
.filter((streamPlayer) -> {
Expand Down
7 changes: 4 additions & 3 deletions projects/main-app/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ CHANNEL-ID: "GLOBAL_CHANNEL_ID"
bot-activity:
# Valid Types: ONLINE, DO_NOT_DISTURB, IDLE, INVISIBLE
status: ONLINE
# Valid Types: PLAYING, STREAMING, LISTENING, WATCHING, COMPETING
type: "COMPETING"
text: "SimpleProxyChat by beanbeanjuice"
# Valid Types: PLAYING, STREAMING, LISTENING, WATCHING, COMPETING, CUSTOM_STATUS
type: "CUSTOM_STATUS"
# Valid placeholders are %online% and/or %max-players% (UPDATES EVERY 5 MINUTES)
text: "%online%/%max-players% - SimpleProxyChat by beanbeanjuice"

# The amount of seconds to check if a server is online/offline.
# Smaller numbers can cause errors. Beware.
Expand Down
Loading