Skip to content

Commit

Permalink
Added DiscordSRV Support
Browse files Browse the repository at this point in the history
For now just sending color stripped broadcast messages to Discord via DiscordSRV
Implements #37
  • Loading branch information
Dart2112 committed Feb 2, 2025
1 parent c5cd69f commit 0a3bba0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repositories {
}

dependencies {
implementation 'net.lapismc:LapisCore:1.12.18'
implementation 'net.lapismc:LapisCore:1.12.19'
implementation 'org.ocpsoft.prettytime:prettytime:5.0.8.Final'
compileOnly 'net.essentialsx:EssentialsX:2.20.1'
compileOnly 'net.luckperms:api:5.4'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/lapismc/afkplus/AFKPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class AFKPlus extends LapisCorePlugin {
@Override
public void onEnable() {
saveDefaultConfig();
registerConfiguration(new AFKPlusConfiguration(this, 18, 7));
registerConfiguration(new AFKPlusConfiguration(this, 19, 7));
registerPermissions(new AFKPlusPermissions(this));
registerLuckPermsContext();
update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.lapismc.afkplus.api.AFKStopEvent;
import net.lapismc.afkplus.util.EssentialsAFKHook;
import net.lapismc.lapiscore.compatibility.XSound;
import net.lapismc.lapiscore.utils.LapisCoreDiscordSRVHook;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue;
Expand Down Expand Up @@ -338,13 +339,20 @@ public boolean shouldBroadcastToOthers() {
*/
public void broadcastOthers(String msg) {
boolean console = plugin.getConfig().getBoolean("Broadcast.Console");
//Only send to DiscordSRV if the option is enabled and the plugin is enabled
boolean discordSrv = plugin.getConfig().getBoolean("Broadcast.DiscordSRV.Enabled") &&
Bukkit.getServer().getPluginManager().isPluginEnabled("DiscordSRV");
boolean otherPlayers = shouldBroadcastToOthers();
//Don't broadcast if the message is empty
if (!msg.isEmpty()) {
//Broadcast the message to console and other players if its enabled
if (console) {
Bukkit.getConsoleSender().sendMessage(msg);
}
if (discordSrv) {
String channelName = plugin.getConfig().getString("Broadcast.DiscordSRV.Channel", "global");
LapisCoreDiscordSRVHook.pushMessageToDiscord(channelName, msg);
}
if (otherPlayers) {
for (Player p : Bukkit.getOnlinePlayers()) {
//Skip the player represented by this class, messages to them will be handled by selfMessage
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ConfigVersion: 18
ConfigVersion: 19

#Should the plugin check for new updates, UpdateDownload will not work if this is set to false
UpdateCheck: true
Expand Down Expand Up @@ -105,6 +105,9 @@ Broadcast:
OtherPlayers: true
Self: true
Vanish: false
DiscordSRV:
Enabled: false
Channel: "global"

#Aggressive AFK Detection is an attempt to stop people using AFK farms or machines
#It does this by checking that players are moving in both look (using the mouse to look around) and transform (using wasd to move)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: AFKPlus
version: ${project.version}
main: net.lapismc.afkplus.AFKPlus
api-version: 1.18
softdepend: [ PlaceholderAPI, Essentials, LuckPerms ]
softdepend: [ PlaceholderAPI, Essentials, LuckPerms, DiscordSRV ]
authors: [Dart2112]
description: AFK for professional servers

0 comments on commit 0a3bba0

Please sign in to comment.