59 lines
1.9 KiB
Java
59 lines
1.9 KiB
Java
package com.smartcraft.notifier;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.plugin.messaging.Messenger;
|
|
|
|
public class SmartCraftNotifier extends JavaPlugin {
|
|
|
|
public static SmartCraftNotifier instance;
|
|
private GotifyClient gotifyClient;
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
instance = this;
|
|
|
|
saveDefaultConfig();
|
|
FileConfiguration config = getConfig();
|
|
|
|
this.gotifyClient = new GotifyClient(config);
|
|
|
|
if (!gotifyClient.isReady()) {
|
|
getLogger().warning("Gotify is not properly configured. Notifications will not be sent.");
|
|
} else {
|
|
getLogger().info("Gotify is ready to send messages.");
|
|
}
|
|
|
|
// Event listeners
|
|
if (config.getBoolean("events.logAdvancements", true)) {
|
|
getServer().getPluginManager().registerEvents(new AdvancementListener(), this);
|
|
}
|
|
|
|
// BungeeCord plugin messaging setup
|
|
if (config.getBoolean("bungeecord", false)) {
|
|
Messenger messenger = getServer().getMessenger();
|
|
messenger.registerOutgoingPluginChannel(this, "BungeeCord");
|
|
messenger.registerIncomingPluginChannel(this, "BungeeCord", new BungeeMessageListener());
|
|
getLogger().info("BungeeCord messaging enabled.");
|
|
}
|
|
|
|
// Register command
|
|
getCommand("gotifystatus").setExecutor((sender, command, label, args) -> {
|
|
boolean result = gotifyClient.pingServer();
|
|
sender.sendMessage("Gotify status: " + (result ? "✅ Online" : "❌ Unreachable"));
|
|
return true;
|
|
});
|
|
|
|
getLogger().info("SmartCraft Notifier has been enabled.");
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
getLogger().info("SmartCraft Notifier has been disabled.");
|
|
}
|
|
|
|
public GotifyClient getGotifyClient() {
|
|
return gotifyClient;
|
|
}
|
|
} |