Made a crap ton of changes
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.smartcraft.notifier</groupId>
|
<groupId>com.smartcraft.notifier</groupId>
|
||||||
<artifactId>SmartCraftNotifier</artifactId>
|
<artifactId>SmartCraftNotifier</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.1.0</version>
|
||||||
<name>SmartCraftNotifier</name>
|
<name>SmartCraftNotifier</name>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@@ -1,23 +0,0 @@
|
|||||||
package com.smartcraft.notifier;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
|
|
||||||
|
|
||||||
public class AdvancementListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onAdvancement(PlayerAdvancementDoneEvent event) {
|
|
||||||
String advancementKey = event.getAdvancement().getKey().getKey();
|
|
||||||
String playerName = event.getPlayer().getName();
|
|
||||||
|
|
||||||
// Filter out root advancements or hidden criteria
|
|
||||||
if (advancementKey.contains("root") || advancementKey.contains("recipes")) return;
|
|
||||||
|
|
||||||
SmartCraftNotifier.instance.getGotifyClient().sendMessage(
|
|
||||||
"📜 Advancement Unlocked!",
|
|
||||||
playerName + " has earned: " + advancementKey,
|
|
||||||
5
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,75 +0,0 @@
|
|||||||
package com.smartcraft.notifier;
|
|
||||||
|
|
||||||
import okhttp3.*;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class GotifyClient {
|
|
||||||
|
|
||||||
private final String serverUrl;
|
|
||||||
private final String appToken;
|
|
||||||
private final boolean enabled;
|
|
||||||
private final OkHttpClient http;
|
|
||||||
|
|
||||||
public GotifyClient(FileConfiguration config) {
|
|
||||||
this.enabled = config.getBoolean("gotify.enabled", false);
|
|
||||||
this.serverUrl = config.getString("gotify.serverUrl", "").trim();
|
|
||||||
this.appToken = config.getString("gotify.appToken", "").trim();
|
|
||||||
this.http = new OkHttpClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isReady() {
|
|
||||||
return enabled && !serverUrl.isEmpty() && !appToken.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(String title, String message, int priority) {
|
|
||||||
if (!isReady()) return;
|
|
||||||
|
|
||||||
HttpUrl url = HttpUrl.parse(serverUrl + "/message");
|
|
||||||
if (url == null) return;
|
|
||||||
|
|
||||||
RequestBody body = new FormBody.Builder()
|
|
||||||
.add("title", title)
|
|
||||||
.add("message", message)
|
|
||||||
.add("priority", String.valueOf(priority))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
|
||||||
.url(url)
|
|
||||||
.addHeader("X-Gotify-Key", appToken)
|
|
||||||
.post(body)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
http.newCall(request).enqueue(new Callback() {
|
|
||||||
@Override
|
|
||||||
public void onFailure(Call call, IOException e) {
|
|
||||||
Bukkit.getLogger().warning("[SmartCraftNotifier] Failed to send Gotify message: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(Call call, Response response) {
|
|
||||||
response.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean pingServer() {
|
|
||||||
if (!isReady()) return false;
|
|
||||||
|
|
||||||
HttpUrl url = HttpUrl.parse(serverUrl + "/application");
|
|
||||||
if (url == null) return false;
|
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
|
||||||
.url(url)
|
|
||||||
.addHeader("X-Gotify-Key", appToken)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try (Response response = http.newCall(request).execute()) {
|
|
||||||
return response.isSuccessful();
|
|
||||||
} catch (IOException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,13 +1,20 @@
|
|||||||
package com.smartcraft.notifier;
|
package com.smartcraft.notifier;
|
||||||
|
|
||||||
|
import com.smartcraft.notifier.commands.GotifyStatusCommand;
|
||||||
|
import com.smartcraft.notifier.config.ConfigManager;
|
||||||
|
import com.smartcraft.notifier.gotify.GotifyClient;
|
||||||
|
import com.smartcraft.notifier.listeners.core.JoinQuitListener;
|
||||||
|
import com.smartcraft.notifier.listeners.core.AdvancementListener;
|
||||||
|
import com.smartcraft.notifier.listeners.litebans.PunishmentListener;
|
||||||
|
import com.smartcraft.notifier.listeners.bungee.ServerSwitchListener;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.plugin.messaging.Messenger;
|
|
||||||
|
|
||||||
public class SmartCraftNotifier extends JavaPlugin {
|
public class SmartCraftNotifier extends JavaPlugin {
|
||||||
|
|
||||||
public static SmartCraftNotifier instance;
|
public static SmartCraftNotifier instance;
|
||||||
|
private ConfigManager configManager;
|
||||||
private GotifyClient gotifyClient;
|
private GotifyClient gotifyClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -15,45 +22,59 @@ public class SmartCraftNotifier extends JavaPlugin {
|
|||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
FileConfiguration config = getConfig();
|
this.configManager = new ConfigManager(this);
|
||||||
|
this.gotifyClient = new GotifyClient(configManager);
|
||||||
|
|
||||||
this.gotifyClient = new GotifyClient(config);
|
if (configManager.isDebugMode()) {
|
||||||
|
getLogger().info("[Debug] Debug mode is enabled.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!gotifyClient.isReady()) {
|
if (configManager.isGotifyEnabled()) {
|
||||||
getLogger().warning("Gotify is not properly configured. Notifications will not be sent.");
|
|
||||||
} else {
|
|
||||||
getLogger().info("Gotify is ready to send messages.");
|
getLogger().info("Gotify is ready to send messages.");
|
||||||
|
getLogger().info("Connected to Gotify server: " + configManager.getGotifyUrl());
|
||||||
|
} else {
|
||||||
|
getLogger().warning("Gotify is disabled in the config.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event listeners
|
getCommand("gotifystatus").setExecutor(new GotifyStatusCommand(this));
|
||||||
if (config.getBoolean("events.logAdvancements", true)) {
|
|
||||||
getServer().getPluginManager().registerEvents(new AdvancementListener(), this);
|
Bukkit.getPluginManager().registerEvents(new JoinQuitListener(this), this);
|
||||||
|
Bukkit.getPluginManager().registerEvents(new AdvancementListener(this), this);
|
||||||
|
|
||||||
|
if (configManager.isLiteBansEnabled()) {
|
||||||
|
try {
|
||||||
|
Bukkit.getPluginManager().registerEvents(new PunishmentListener(this), this);
|
||||||
|
getLogger().info("LiteBans integration enabled.");
|
||||||
|
} catch (Throwable t) {
|
||||||
|
getLogger().warning("LiteBans not found or failed to initialize.");
|
||||||
|
if (configManager.isDebugMode()) t.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BungeeCord plugin messaging setup
|
if (configManager.isBungeeCordEnabled()) {
|
||||||
if (config.getBoolean("bungeecord", false)) {
|
try {
|
||||||
Messenger messenger = getServer().getMessenger();
|
Bukkit.getPluginManager().registerEvents(new ServerSwitchListener(this), this);
|
||||||
messenger.registerOutgoingPluginChannel(this, "BungeeCord");
|
getLogger().info("BungeeCord server switch tracking is enabled.");
|
||||||
messenger.registerIncomingPluginChannel(this, "BungeeCord", new BungeeMessageListener());
|
} catch (Throwable t) {
|
||||||
getLogger().info("BungeeCord messaging enabled.");
|
getLogger().warning("Failed to register BungeeCord listener.");
|
||||||
|
if (configManager.isDebugMode()) t.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getLogger().info("BungeeCord integration is disabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.");
|
getLogger().info("SmartCraft Notifier has been enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public ConfigManager getConfigManager() {
|
||||||
public void onDisable() {
|
return configManager;
|
||||||
getLogger().info("SmartCraft Notifier has been disabled.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GotifyClient getGotifyClient() {
|
public GotifyClient getGotifyClient() {
|
||||||
return gotifyClient;
|
return gotifyClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SmartCraftNotifier getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
package com.smartcraft.notifier.commands;
|
||||||
|
|
||||||
|
import com.smartcraft.notifier.SmartCraftNotifier;
|
||||||
|
import com.smartcraft.notifier.config.ConfigManager;
|
||||||
|
import com.smartcraft.notifier.gotify.GotifyClient;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class GotifyStatusCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
private final SmartCraftNotifier plugin;
|
||||||
|
private final ConfigManager config;
|
||||||
|
private final GotifyClient gotify;
|
||||||
|
|
||||||
|
public GotifyStatusCommand(SmartCraftNotifier plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.config = plugin.getConfigManager();
|
||||||
|
this.gotify = plugin.getGotifyClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (!sender.hasPermission("smartcraftnotifier.command.status")) {
|
||||||
|
sender.sendMessage("§cYou do not have permission to use this command.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String subcommand = (args.length == 0) ? "ping" : args[0].toLowerCase();
|
||||||
|
|
||||||
|
switch (subcommand) {
|
||||||
|
case "ping":
|
||||||
|
if (!sender.hasPermission("smartcraftnotifier.command.status.ping")) {
|
||||||
|
sender.sendMessage("§cYou do not have permission to ping Gotify.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
boolean reachable = gotify.ping();
|
||||||
|
sender.sendMessage(reachable
|
||||||
|
? "§a✅ Gotify is reachable."
|
||||||
|
: "§c❌ Could not reach Gotify server.");
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case "server":
|
||||||
|
if (!sender.hasPermission("smartcraftnotifier.command.status.server")) {
|
||||||
|
sender.sendMessage("§cYou do not have permission to view Gotify server info.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String url = config.getGotifyUrl();
|
||||||
|
sender.sendMessage("§7🌐 Gotify server: §e" + url);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
sender.sendMessage("§7Usage: §f/gotifystatus §8[ping|server]");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
101
src/main/java/com/smartcraft/notifier/config/ConfigManager.java
Normal file
101
src/main/java/com/smartcraft/notifier/config/ConfigManager.java
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
package com.smartcraft.notifier.config;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class ConfigManager {
|
||||||
|
|
||||||
|
private final Plugin plugin;
|
||||||
|
private final FileConfiguration config;
|
||||||
|
private FileConfiguration messageConfig;
|
||||||
|
|
||||||
|
public ConfigManager(Plugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.config = plugin.getConfig();
|
||||||
|
loadMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadMessages() {
|
||||||
|
File messageFile = new File(plugin.getDataFolder(), "messages.yml");
|
||||||
|
if (!messageFile.exists()) {
|
||||||
|
plugin.saveResource("messages.yml", false);
|
||||||
|
}
|
||||||
|
this.messageConfig = YamlConfiguration.loadConfiguration(messageFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🧠 Global settings
|
||||||
|
public boolean isDebugMode() {
|
||||||
|
return config.getBoolean("debug", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBungeeCordEnabled() {
|
||||||
|
return config.getBoolean("bungeecord.enabled", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ Gotify settings
|
||||||
|
public boolean isGotifyEnabled() {
|
||||||
|
return config.getBoolean("gotify.enabled", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGotifyUrl() {
|
||||||
|
return config.getString("gotify.serverUrl", "NOT SET");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGotifyToken() {
|
||||||
|
return config.getString("gotify.appToken", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDefaultPriority() {
|
||||||
|
return config.getInt("gotify.defaultPriority", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 📢 Core Event toggles
|
||||||
|
public boolean logJoins() {
|
||||||
|
return config.getBoolean("events.logJoins", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean logLeaves() {
|
||||||
|
return config.getBoolean("events.logLeaves", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean logAdvancements() {
|
||||||
|
return config.getBoolean("events.logAdvancements", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean logServerSwitches() {
|
||||||
|
return config.getBoolean("events.logServerSwitch", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEventMessage(String key) {
|
||||||
|
return messageConfig.getString("events." + key, "{player} triggered " + key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔨 LiteBans Integration
|
||||||
|
public boolean isLiteBansEnabled() {
|
||||||
|
return config.getBoolean("litebans.enabled", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean logBans() {
|
||||||
|
return config.getBoolean("litebans.logBans", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean logMutes() {
|
||||||
|
return config.getBoolean("litebans.logMutes", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean logKicks() {
|
||||||
|
return config.getBoolean("litebans.logKicks", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean logWarns() {
|
||||||
|
return config.getBoolean("litebans.logWarns", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLiteBansMessage(String type) {
|
||||||
|
return messageConfig.getString("litebans." + type,
|
||||||
|
"🔔 {player} received a " + type + ": {reason}");
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,82 @@
|
|||||||
|
package com.smartcraft.notifier.gotify;
|
||||||
|
|
||||||
|
import com.smartcraft.notifier.SmartCraftNotifier;
|
||||||
|
import com.smartcraft.notifier.config.ConfigManager;
|
||||||
|
import okhttp3.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class GotifyClient {
|
||||||
|
|
||||||
|
private final OkHttpClient httpClient = new OkHttpClient();
|
||||||
|
private final ConfigManager config;
|
||||||
|
|
||||||
|
public GotifyClient(ConfigManager config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String title, String message, int priority) {
|
||||||
|
if (!config.isGotifyEnabled()) return;
|
||||||
|
|
||||||
|
String serverUrl = config.getGotifyUrl();
|
||||||
|
String token = config.getGotifyToken();
|
||||||
|
|
||||||
|
if (serverUrl == null || token == null || serverUrl.isEmpty() || token.isEmpty()) {
|
||||||
|
log("❌ Gotify server URL or App Token is missing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = serverUrl + "/message?token=" + token;
|
||||||
|
|
||||||
|
RequestBody body = new FormBody.Builder()
|
||||||
|
.add("title", title)
|
||||||
|
.add("message", message)
|
||||||
|
.add("priority", String.valueOf(priority))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.post(body)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
httpClient.newCall(request).enqueue(new Callback() {
|
||||||
|
@Override public void onFailure(Call call, IOException e) {
|
||||||
|
log("❌ Failed to send Gotify message: " + e.getMessage());
|
||||||
|
if (config.isDebugMode()) e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onResponse(Call call, Response response) {
|
||||||
|
if (!response.isSuccessful() && config.isDebugMode()) {
|
||||||
|
log("⚠️ Gotify responded with status code: " + response.code());
|
||||||
|
}
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (config.isDebugMode()) {
|
||||||
|
log("[Debug] Gotify message sent: " + title + " | " + message + " (Priority " + priority + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean ping() {
|
||||||
|
if (!config.isGotifyEnabled()) return false;
|
||||||
|
|
||||||
|
String pingUrl = config.getGotifyUrl() + "/application";
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(pingUrl)
|
||||||
|
.header("X-Gotify-Key", config.getGotifyToken())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Response response = httpClient.newCall(request).execute()) {
|
||||||
|
return response.isSuccessful();
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (config.isDebugMode()) e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void log(String msg) {
|
||||||
|
SmartCraftNotifier.getInstance().getLogger().warning(msg);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,42 @@
|
|||||||
|
package com.smartcraft.notifier.listeners.bungee;
|
||||||
|
|
||||||
|
import com.smartcraft.notifier.SmartCraftNotifier;
|
||||||
|
import com.smartcraft.notifier.config.ConfigManager;
|
||||||
|
import com.smartcraft.notifier.gotify.GotifyClient;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
public class ServerSwitchListener implements Listener {
|
||||||
|
|
||||||
|
private final SmartCraftNotifier plugin;
|
||||||
|
private final ConfigManager config;
|
||||||
|
private final GotifyClient gotify;
|
||||||
|
|
||||||
|
public ServerSwitchListener(SmartCraftNotifier plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.config = plugin.getConfigManager();
|
||||||
|
this.gotify = plugin.getGotifyClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerSwitch(ServerSwitchEvent event) {
|
||||||
|
if (!config.logServerSwitches()) return;
|
||||||
|
|
||||||
|
ProxiedPlayer player = event.getPlayer();
|
||||||
|
String serverName = (player.getServer() != null)
|
||||||
|
? player.getServer().getInfo().getName()
|
||||||
|
: "Unknown";
|
||||||
|
|
||||||
|
String message = config.getEventMessage("serverSwitch")
|
||||||
|
.replace("{player}", player.getName())
|
||||||
|
.replace("{server}", serverName);
|
||||||
|
|
||||||
|
gotify.sendMessage("Server Switched", message, config.getDefaultPriority());
|
||||||
|
|
||||||
|
if (config.isDebugMode()) {
|
||||||
|
plugin.getLogger().info("[Debug] " + player.getName() + " switched to " + serverName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,45 @@
|
|||||||
|
package com.smartcraft.notifier.listeners.core;
|
||||||
|
|
||||||
|
import com.smartcraft.notifier.SmartCraftNotifier;
|
||||||
|
import com.smartcraft.notifier.config.ConfigManager;
|
||||||
|
import com.smartcraft.notifier.gotify.GotifyClient;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.advancement.Advancement;
|
||||||
|
import org.bukkit.advancement.AdvancementDisplay;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
|
||||||
|
|
||||||
|
public class AdvancementListener implements Listener {
|
||||||
|
|
||||||
|
private final SmartCraftNotifier plugin;
|
||||||
|
private final ConfigManager config;
|
||||||
|
private final GotifyClient gotify;
|
||||||
|
|
||||||
|
public AdvancementListener(SmartCraftNotifier plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.config = plugin.getConfigManager();
|
||||||
|
this.gotify = plugin.getGotifyClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onAdvancement(PlayerAdvancementDoneEvent event) {
|
||||||
|
if (!config.logAdvancements()) return;
|
||||||
|
|
||||||
|
Advancement adv = event.getAdvancement();
|
||||||
|
AdvancementDisplay display = adv.getDisplay();
|
||||||
|
if (display == null || !display.shouldAnnounceToChat()) return;
|
||||||
|
|
||||||
|
String player = event.getPlayer().getName();
|
||||||
|
String title = display.getTitle();
|
||||||
|
String message = config.getEventMessage("advancement")
|
||||||
|
.replace("{player}", player)
|
||||||
|
.replace("{advancement}", title);
|
||||||
|
|
||||||
|
gotify.sendMessage("Advancement Unlocked", message, config.getDefaultPriority());
|
||||||
|
|
||||||
|
if (config.isDebugMode()) {
|
||||||
|
Bukkit.getLogger().info("[Debug] Advancement event triggered for " + player + ": " + title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,51 @@
|
|||||||
|
package com.smartcraft.notifier.listeners.core;
|
||||||
|
|
||||||
|
import com.smartcraft.notifier.SmartCraftNotifier;
|
||||||
|
import com.smartcraft.notifier.config.ConfigManager;
|
||||||
|
import com.smartcraft.notifier.gotify.GotifyClient;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
public class JoinQuitListener implements Listener {
|
||||||
|
|
||||||
|
private final SmartCraftNotifier plugin;
|
||||||
|
private final ConfigManager config;
|
||||||
|
private final GotifyClient gotify;
|
||||||
|
|
||||||
|
public JoinQuitListener(SmartCraftNotifier plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.config = plugin.getConfigManager();
|
||||||
|
this.gotify = plugin.getGotifyClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
|
if (!config.logJoins()) return;
|
||||||
|
|
||||||
|
String player = event.getPlayer().getName();
|
||||||
|
String message = config.getEventMessage("join").replace("{player}", player);
|
||||||
|
|
||||||
|
gotify.sendMessage("Player Joined", message, config.getDefaultPriority());
|
||||||
|
|
||||||
|
if (config.isDebugMode()) {
|
||||||
|
Bukkit.getLogger().info("[Debug] Join event triggered for " + player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent event) {
|
||||||
|
if (!config.logLeaves()) return;
|
||||||
|
|
||||||
|
String player = event.getPlayer().getName();
|
||||||
|
String message = config.getEventMessage("leave").replace("{player}", player);
|
||||||
|
|
||||||
|
gotify.sendMessage("Player Left", message, config.getDefaultPriority());
|
||||||
|
|
||||||
|
if (config.isDebugMode()) {
|
||||||
|
Bukkit.getLogger().info("[Debug] Quit event triggered for " + player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,71 @@
|
|||||||
|
package com.smartcraft.notifier.listeners.litebans;
|
||||||
|
|
||||||
|
import com.smartcraft.notifier.SmartCraftNotifier;
|
||||||
|
import com.smartcraft.notifier.config.ConfigManager;
|
||||||
|
import com.smartcraft.notifier.gotify.GotifyClient;
|
||||||
|
import litebans.api.Punishment;
|
||||||
|
import litebans.api.events.PunishmentExecuteEvent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class PunishmentListener implements Listener {
|
||||||
|
|
||||||
|
private final SmartCraftNotifier plugin;
|
||||||
|
private final ConfigManager config;
|
||||||
|
private final GotifyClient gotify;
|
||||||
|
|
||||||
|
public PunishmentListener(SmartCraftNotifier plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.config = plugin.getConfigManager();
|
||||||
|
this.gotify = plugin.getGotifyClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPunishment(PunishmentExecuteEvent event) {
|
||||||
|
if (!config.isLiteBansEnabled()) return;
|
||||||
|
|
||||||
|
Punishment punishment = event.getPunishment();
|
||||||
|
String type = punishment.getType(); // "ban", "mute", "kick", "warn"
|
||||||
|
String playerName = punishment.getName(); // not UUID
|
||||||
|
String reason = punishment.getReason();
|
||||||
|
|
||||||
|
// Check if this type is allowed in config
|
||||||
|
switch (type.toLowerCase()) {
|
||||||
|
case "ban":
|
||||||
|
if (!config.logBans()) return;
|
||||||
|
break;
|
||||||
|
case "mute":
|
||||||
|
if (!config.logMutes()) return;
|
||||||
|
break;
|
||||||
|
case "kick":
|
||||||
|
if (!config.logKicks()) return;
|
||||||
|
break;
|
||||||
|
case "warn":
|
||||||
|
if (!config.logWarns()) return;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return; // Unknown type
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build message from template
|
||||||
|
String template = config.getLiteBansMessage(type.toLowerCase());
|
||||||
|
String message = template
|
||||||
|
.replace("{player}", playerName)
|
||||||
|
.replace("{reason}", (reason != null && !reason.isEmpty()) ? reason : "No reason provided");
|
||||||
|
|
||||||
|
String title = switch (type.toLowerCase()) {
|
||||||
|
case "ban" -> "🔨 Player Banned";
|
||||||
|
case "mute" -> "🔇 Player Muted";
|
||||||
|
case "kick" -> "👢 Player Kicked";
|
||||||
|
case "warn" -> "⚠️ Player Warned";
|
||||||
|
default -> "⚔️ Punishment Issued";
|
||||||
|
};
|
||||||
|
|
||||||
|
gotify.sendMessage(title, message, config.getDefaultPriority());
|
||||||
|
|
||||||
|
if (config.isDebugMode()) {
|
||||||
|
Bukkit.getLogger().info("[Debug] LiteBans " + type + " issued to " + playerName + ": " + reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,12 +1,31 @@
|
|||||||
bungeecord: false
|
debug: false
|
||||||
|
|
||||||
gotify:
|
gotify:
|
||||||
enabled: true
|
enabled: true
|
||||||
serverUrl: "https://your.gotify.server"
|
serverUrl: "https://your.gotify.instance" # Replace with your Gotify server
|
||||||
appToken: "YOUR_SECRET_TOKEN"
|
appToken: "your_app_token_here" # Replace with your Gotify app token
|
||||||
|
defaultPriority: 4 # Use -2 (silent) to 10 (urgent)
|
||||||
|
|
||||||
events:
|
events:
|
||||||
logJoins: true
|
logJoins: true
|
||||||
logLeaves: true
|
logLeaves: true
|
||||||
logServerSwitch: true
|
logServerSwitch: true
|
||||||
logAdvancements: true
|
logAdvancements: true
|
||||||
|
|
||||||
|
messages:
|
||||||
|
join: "👤 {player} has joined the server!"
|
||||||
|
leave: "🚪 {player} has left the server."
|
||||||
|
advancement: "📜 {player} unlocked: {advancement}"
|
||||||
|
|
||||||
|
litebans:
|
||||||
|
enabled: true
|
||||||
|
logBans: true
|
||||||
|
logMutes: true
|
||||||
|
logKicks: true
|
||||||
|
logWarns: true
|
||||||
|
|
||||||
|
messages:
|
||||||
|
ban: "🔨 {player} was banned for: {reason}"
|
||||||
|
mute: "🔇 {player} was muted for: {reason}"
|
||||||
|
kick: "👢 {player} was kicked for: {reason}"
|
||||||
|
warn: "⚠️ {player} was warned: {reason}"
|
11
src/main/resources/messages.yml
Normal file
11
src/main/resources/messages.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
events:
|
||||||
|
join: "👤 {player} has joined the server!"
|
||||||
|
leave: "🚪 {player} has left the server."
|
||||||
|
advancement: "📜 {player} unlocked: {advancement}"
|
||||||
|
serverSwitch: "🔁 {player} switched to: {server}"
|
||||||
|
|
||||||
|
litebans:
|
||||||
|
ban: "🔨 {player} was banned for: {reason}"
|
||||||
|
mute: "🔇 {player} was muted for: {reason}"
|
||||||
|
kick: "👢 {player} was kicked for: {reason}"
|
||||||
|
warn: "⚠️ {player} was warned: {reason}"
|
@@ -1,14 +1,15 @@
|
|||||||
name: SmartCraftNotifier
|
name: SmartCraftNotifier
|
||||||
version: 1.0.1
|
version: 1.1.0
|
||||||
main: com.smartcraft.notifier.SmartCraftNotifier
|
main: com.smartcraft.notifier.SmartCraftNotifier
|
||||||
api-version: 1.20
|
api-version: 1.20
|
||||||
description: Sends player events to Gotify and supports optional BungeeCord messaging.
|
description: Notifies your Gotify server on key in-game events: joins, advancements, bans, and more.
|
||||||
|
authors: minster586
|
||||||
commands:
|
commands:
|
||||||
gotifystatus:
|
gotifystatus:
|
||||||
description: Check if Gotify is reachable.
|
description: Ping the Gotify server to check connectivity.
|
||||||
usage: /gotifystatus
|
usage: /gotifystatus
|
||||||
permission: smartcraftnotifier.status
|
permission: smartcraftnotifier.command.status
|
||||||
permissions:
|
permissions:
|
||||||
smartcraftnotifier.status:
|
smartcraftnotifier.command.status:
|
||||||
description: Allows use of /gotifystatus command
|
description: Allows access to the /gotifystatus command
|
||||||
default: op
|
default: true
|
Reference in New Issue
Block a user