master upload

This commit is contained in:
minster586
2025-06-24 03:06:30 -04:00
parent d14824f12d
commit 95ee183b38
11 changed files with 390 additions and 2 deletions

View File

@@ -1,3 +1,47 @@
# sc-ntfy-plugin # NTFYNotifier
This is a minecraft plugin for the use with ntfy server for notifications A lightweight Minecraft plugin that sends real-time alerts to [ntfy.sh](https://ntfy.sh) when players join, leave, or run specific commands. Designed for Paper/Spigot servers on Minecraft 1.14+, this plugin helps admins stay in-the-know wherever they are.
---
## 🔔 Features
- 🔹 Join and Quit Notifications
- 🔹 Command Watcher (customizable)
- 🔹 `%player%` and `%server%` placeholder support
- 🔹 Fully configurable messages and settings
- 🔹 ntfy.sh API integration (with optional basic auth)
---
## 🛠 Installation
1. Place the compiled `NTFYNotifier-1.0.0.jar` in your servers `plugins/` folder.
2. Start the server to generate `config.yml` and `msg.yml`.
3. Customize configuration and messages to your liking.
---
## ⚙ Configuration
### `config.yml`
```yaml
server-name: "NTFYCraft"
ntfy:
server: "https://ntfy.sh"
topic: "minecraft-events"
auth:
enabled: false
username: "user"
password: "pass"
notifications:
join: true
quit: true
commands:
enabled: true
watch:
- "stop"
- "ban"
- "kick"

15
build.bat Normal file
View File

@@ -0,0 +1,15 @@
@echo off
REM === Run Maven clean and package ===
echo Building NTFYNotifier with Maven...
mvn clean package
REM === Check if the build succeeded ===
IF EXIST target\NTFYNotifier-1.0.jar (
echo.
echo ✅ Build successful! JAR created at: target\NTFYNotifier-1.0.jar
) ELSE (
echo.
echo ❌ Build failed. Please check for compilation errors.
)
pause

58
pom.xml Normal file
View File

@@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.minster586</groupId>
<artifactId>NTFYNotifier</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>NTFYNotifier</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,41 @@
package com.minster586.ntfyplugin;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.List;
public class CommandMonitor implements Listener {
private final FileConfiguration config;
private final MessageManager messageManager;
private final NTFYNotifier notifier;
public CommandMonitor(Main plugin) {
this.config = plugin.getConfig();
this.messageManager = new MessageManager(plugin);
this.notifier = new NTFYNotifier(plugin);
}
@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
if (!config.getBoolean("notifications.commands.enabled", true)) return;
String commandLine = event.getMessage().toLowerCase().trim();
CommandSender sender = event.getPlayer();
List<String> watched = config.getStringList("notifications.commands.watch");
for (String keyword : watched) {
if (commandLine.startsWith("/" + keyword.toLowerCase())) {
String title = messageManager.getMessage(keyword + ".title");
String message = messageManager.formatMessage(keyword + ".message", (sender instanceof Player) ? (Player) sender : null);
notifier.sendNotification(title, message);
break;
}
}
}
}

View File

@@ -0,0 +1,41 @@
package com.minster586.ntfyplugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public class Main extends JavaPlugin {
private static Main instance;
@Override
public void onEnable() {
instance = this;
// Save default config.yml (Bukkit handles this automatically)
saveDefaultConfig();
// Save msg.yml if it doesn't exist
File msgFile = new File(getDataFolder(), "msg.yml");
if (!msgFile.exists()) {
saveResource("msg.yml", false);
}
// Register listeners
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new PlayerEventListener(this), this);
pm.registerEvents(new CommandMonitor(this), this);
getLogger().info("NTFYNotifier has been enabled.");
}
@Override
public void onDisable() {
getLogger().info("NTFYNotifier has been disabled.");
}
public static Main getInstance() {
return instance;
}
}

View File

@@ -0,0 +1,35 @@
package com.minster586.ntfyplugin;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
public class MessageManager {
private final Main plugin;
private final YamlConfiguration messages;
public MessageManager(Main plugin) {
this.plugin = plugin;
File msgFile = new File(plugin.getDataFolder(), "msg.yml");
this.messages = YamlConfiguration.loadConfiguration(msgFile);
}
public String getMessage(String path) {
return messages.getString("messages." + path, "");
}
public String formatMessage(String path, Player player) {
String message = getMessage(path);
if (player != null) {
message = message.replace("%player%", player.getName());
}
String serverName = plugin.getConfig().getString("server-name", "Minecraft Server");
message = message.replace("%server%", serverName);
return message;
}
}

View File

@@ -0,0 +1,56 @@
package com.minster586.ntfyplugin;
import org.bukkit.configuration.file.FileConfiguration;
import javax.net.ssl.HttpsURLConnection;
import java.io.OutputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class NTFYNotifier {
private final FileConfiguration config;
public NTFYNotifier(Main plugin) {
this.config = plugin.getConfig();
}
public void sendNotification(String title, String message) {
try {
String server = config.getString("ntfy.server", "https://ntfy.sh");
String topic = config.getString("ntfy.topic", "minecraft-events");
String urlString = server.endsWith("/") ? server + topic : server + "/" + topic;
URL url = new URL(urlString);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Title", title);
conn.setRequestProperty("Content-Type", "text/plain");
// Optional Basic Auth
if (config.getBoolean("ntfy.auth.enabled", false)) {
String username = config.getString("ntfy.auth.username");
String password = config.getString("ntfy.auth.password");
if (username != null && password != null) {
String auth = username + ":" + password;
String encoded = Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8));
conn.setRequestProperty("Authorization", "Basic " + encoded);
}
}
// Send body
try (OutputStream os = conn.getOutputStream()) {
byte[] input = message.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// Close connection to complete POST
conn.getInputStream().close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,43 @@
package com.minster586.ntfyplugin;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerEventListener implements Listener {
private final Main plugin;
private final FileConfiguration config;
private final MessageManager messageManager;
private final NTFYNotifier notifier;
public PlayerEventListener(Main plugin) {
this.plugin = plugin;
this.config = plugin.getConfig();
this.messageManager = new MessageManager(plugin);
this.notifier = new NTFYNotifier(plugin);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (config.getBoolean("notifications.join", true)) {
Player player = event.getPlayer();
String title = messageManager.getMessage("join.title");
String message = messageManager.formatMessage("join.message", player);
notifier.sendNotification(title, message);
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
if (config.getBoolean("notifications.quit", true)) {
Player player = event.getPlayer();
String title = messageManager.getMessage("quit.title");
String message = messageManager.formatMessage("quit.message", player);
notifier.sendNotification(title, message);
}
}
}

View File

@@ -0,0 +1,22 @@
ntfy:
server: "https://ntfy.sh" # Default public ntfy.sh server
topic: "minecraft-events"
auth:
enabled: false
username: "user"
password: "pass"
server-name: "NTFYCraft" # Custom variable used in message placeholders
notifications:
join: true
quit: true
commands:
enabled: true
watch:
- "stop"
- "ban"
- "kick"
- "mute"
- "warn"
- "op"

View File

@@ -0,0 +1,25 @@
messages:
join:
title: "Player Joined"
message: "%player% has joined the server."
quit:
title: "Player Left"
message: "%player% has left the server."
stop:
title: "Server Stop"
message: "%player% issued /stop"
ban:
title: "Player Banned"
message: "%player% used /ban"
kick:
title: "Player Kicked"
message: "%player% used /kick"
mute:
title: "Player Muted"
message: "%player% used /mute"
warn:
title: "Player Warned"
message: "%player% used /warn"
op:
title: "Player Opped"
message: "%player% used /op"

View File

@@ -0,0 +1,8 @@
name: NTFYNotifier
version: 1.0.0
main: com.minster586.ntfyplugin.Main
api-version: 1.14
author: minster586
description: Sends customizable join, quit, and command notifications to an ntfy.sh server.
commands: {}
permissions: {}