Compare commits

8 Commits

25 changed files with 320 additions and 292 deletions
+32 -12
View File
@@ -6,7 +6,7 @@ it was made to notify a discord server whenever a event occurred in a minecraft
# Prerequisites # Prerequisites
Before using this plugin, you must: Before using this plugin, you must:
* Get Spigot * Get Spigot
* Get a JAR file from [the releases](https://git.sob.moe/sobrooms/notify-on-start/-/releases) or [Google Drive](https://drive.google.com/drive/folders/11wMPjOh2b8oRzpeJOrOI4ZAkImOlr93u?usp=sharing) (the drive folder is frequently updated) * Get a JAR file from [the releases](https://rrryfoo.sob.moe/rrryfoo/notify-on-start/releases)
# Webhook creation # Webhook creation
If you already know how to make a webhook, disregard this section of the readme. If you already know how to make a webhook, disregard this section of the readme.
@@ -21,17 +21,37 @@ To make a webhook:
7. Copy the webhook link. 7. Copy the webhook link.
# Usage # Usage
To use this plugin, simply obtain a release and place the binary on the `plugins` folder of your Spigot/Paper/Bukkit server. To use this plugin, obtain a release and place the binary on the `plugins` folder of your Spigot/Paper/Bukkit server.
On the first run, it will make a folder in the server's directory, containing the plugin's configuration file named `config_webhook.json` Once the plugin is used for the first time, it will make a YAML configuration file in the plugin's directory named `notifyOnStart.`\
It should look like this:
The configuration file should have two fields with the value `default-ns`. Paste the webhook links in the space following the key name (such as `url_notify`), ```yml
or over the `default-ns` text. The configuration should look like this afterward: server:
name: Minecraft Server
entry_message: Welcome to @servername, @playername!
```json webhooks:
{ notify: default-ns
"url_notify": "https://discord.com/webhooks/webhook_for_notifications", broadcast: default-ns
"url_publicmsg": "https://discord.com/webhooks/webhook_for_player_broadcasts" log: true
} firstrun: 0
``` ```
You can also make a configuration file without starting the server up; copy the config above, make the plugin directory yourself, make a file named `config.yml`, and paste the text into it. You can then change the settings, as long as the `firstrun` field exists.
The configuration file should have two fields with the value `default-ns`. Paste the webhook links in the space following the key name (such as `notify`),
or over the `default-ns` text. The configuration should look like this afterwards:
```yml
server:
name: Minecraft Server
entry_message: Welcome to @servername, @playername!
webhooks:
notify: https://discord.com/webhooks/webhook_for_notifications
broadcast: ttps://discord.com/webhooks/webhook_for_player_broadcasts
log: true
firstrun: 0
```
You may use two variables in the entry message field, namely `@servername` and `@playername`. If you do not want an entry message to be sent, leave the field blank.
+1 -1
View File
@@ -3,7 +3,7 @@ plugins {
} }
group 'moe.sob' group 'moe.sob'
version '1.2.0' version '1.3.0'
repositories { repositories {
mavenCentral() mavenCentral()
Binary file not shown.
-5
View File
@@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
vendored
+25 -13
View File
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# SPDX-License-Identifier: Apache-2.0
#
############################################################################## ##############################################################################
# #
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +82,12 @@ do
esac esac
done done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # This is normally unused
# shellcheck disable=SC2034
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' ' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@@ -133,22 +134,29 @@ location of your Java installation."
fi fi
else else
JAVACMD=java JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi fi
fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #( case $MAX_FD in #(
max*) max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) || MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit" warn "Could not query maximum file descriptor limit"
esac esac
case $MAX_FD in #( case $MAX_FD in #(
'' | soft) :;; #( '' | soft) :;; #(
*) *)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" || ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD" warn "Could not set maximum file descriptor limit to $MAX_FD"
esac esac
@@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then
done done
fi fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
# shell script including quotes and variable substitutions, so put them in DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded. # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
vendored
+13 -10
View File
@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@@ -26,6 +28,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=. if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@@ -42,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute if %ERRORLEVEL% equ 0 goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail
@@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail
-1
View File
@@ -1 +0,0 @@
rootProject.name = 'notifyonstart'
+7 -3
View File
@@ -2,9 +2,9 @@ package moe.sob;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import java.awt.*; import java.awt.*;
import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
@@ -50,7 +50,8 @@ public class DiscordWebhook {
this.embeds.add(embed); this.embeds.add(embed);
} }
public void execute() throws IOException { public void execute() throws Exception {
try {
if (this.content == null && this.embeds.isEmpty()) { if (this.content == null && this.embeds.isEmpty()) {
throw new IllegalArgumentException("Set content or add at least one EmbedObject"); throw new IllegalArgumentException("Set content or add at least one EmbedObject");
} }
@@ -136,7 +137,7 @@ public class DiscordWebhook {
json.put("embeds", embedObjects.toArray()); json.put("embeds", embedObjects.toArray());
} }
URL url = new URL(this.url); URL url = new URI(this.url).toURL();
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.addRequestProperty("Content-Type", "application/json"); connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_"); connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_");
@@ -150,6 +151,9 @@ public class DiscordWebhook {
connection.getInputStream().close(); // I'm not sure why but it doesn't work without getting the InputStream connection.getInputStream().close(); // I'm not sure why but it doesn't work without getting the InputStream
connection.disconnect(); connection.disconnect();
} catch (Exception e) {
throw new Exception();
}
} }
public static class EmbedObject { public static class EmbedObject {
+18 -19
View File
@@ -9,8 +9,6 @@ import moe.sob.events.player.*;
import moe.sob.events.server.ServerLoad; import moe.sob.events.server.ServerLoad;
import moe.sob.events.world.WorldLoad; import moe.sob.events.world.WorldLoad;
import moe.sob.events.world.WorldUnload; import moe.sob.events.world.WorldUnload;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@@ -20,20 +18,19 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.awt.*; import java.awt.*;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
public class Main extends JavaPlugin { public class Main extends JavaPlugin {
private static Main mainSmall; public static Main mainSmall;
private static boolean webhooksAreValidUrls; private static boolean webhooksAreValidUrls;
public static boolean hdc; public static boolean hdc;
public static File config; public static File config;
public static FileConfiguration configR; public static FileConfiguration configR;
public static void main(String... args) { public static void main(String... args) {
System.out.printf("Initializing using server address: %s...%n", ServerUtils.address); mainSmall.getLogger().info(String.format("Initializing using server address: %s...%n", ServerUtils.address));
} }
@Override @Override
public void onDisable() { public void onDisable() {
@@ -45,7 +42,7 @@ public class Main extends JavaPlugin {
notify.addEmbed(embedObject); notify.addEmbed(embedObject);
try { try {
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -76,7 +73,7 @@ public class Main extends JavaPlugin {
} }
// such cap // such cap
//Bukkit.getConsoleSender().sendMessage("Note: This Spigot/Bukkit plugin is highly verbose, so it will log a lot of events..."); //Main.mainSmall.getLogger().info("Note: This Spigot/Bukkit plugin is highly verbose, so it will log a lot of events...");
// register commands // register commands
try { try {
Objects.requireNonNull(this.getCommand("info")).setExecutor(new InfoCommand()); Objects.requireNonNull(this.getCommand("info")).setExecutor(new InfoCommand());
@@ -110,7 +107,7 @@ public class Main extends JavaPlugin {
return false; return false;
} }
URL url = new URL(getPublicMessageWebhook()); URL url = new URI(getPublicMessageWebhook()).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET"); connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode(); int responseCode = connection.getResponseCode();
@@ -121,8 +118,8 @@ public class Main extends JavaPlugin {
return false; return false;
} }
} catch (Exception e) { } catch (Exception e) {
mainSmall.getLogger().warning("Invalid webhook URL provide for your public messages. Please provide the correct webhook and check for any typos. (Caught exception)"); mainSmall.getLogger().severe("Invalid webhook URL provide for your public messages. Please provide the correct webhook and check for any typos. (Caught exception)");
System.out.printf("Exception: %s%n", e); //mainSmall.getLogger().severe(String.format("Exception: %s%n", e));
return false; return false;
} }
} }
@@ -134,7 +131,7 @@ public class Main extends JavaPlugin {
return false; return false;
} }
URL url = new URL(getNotifyWebhook()); URL url = new URI(getNotifyWebhook()).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET"); connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode(); int responseCode = connection.getResponseCode();
@@ -145,7 +142,7 @@ public class Main extends JavaPlugin {
return false; return false;
} }
} catch (Exception e) { } catch (Exception e) {
mainSmall.getLogger().warning("Invalid webhook URL provided for the event logs. Please provide the correct webhook and check for any typos. (Caught exception)"); mainSmall.getLogger().severe("Invalid webhook URL provided for the event logs. Please provide the correct webhook and check for any typos. (Caught exception)");
return false; return false;
} }
} }
@@ -188,16 +185,18 @@ public class Main extends JavaPlugin {
public void registerEvents() { public void registerEvents() {
PlayerChat playerChat = new PlayerChat(); PlayerChat playerChat = new PlayerChat();
PlayerCommandPreprocess playerCommandPreprocess = new PlayerCommandPreprocess(); //PlayerCommandPreprocess playerCommandPreprocess = new PlayerCommandPreprocess();
PlayerBedEnter playerBedEnter = new PlayerBedEnter(); //PlayerBedEnter playerBedEnter = new PlayerBedEnter();
PlayerBedLeave playerBedLeave = new PlayerBedLeave(); //PlayerBedLeave playerBedLeave = new PlayerBedLeave(); // Redundant event
WorldLoad worldLoad = new WorldLoad(); WorldLoad worldLoad = new WorldLoad();
WorldUnload worldUnload = new WorldUnload(); WorldUnload worldUnload = new WorldUnload();
PlayerDeath playerDeath = new PlayerDeath();
getServer().getPluginManager().registerEvents(playerChat, this); getServer().getPluginManager().registerEvents(playerChat, this);
getServer().getPluginManager().registerEvents(playerCommandPreprocess, this); //getServer().getPluginManager().registerEvents(playerCommandPreprocess, this);
getServer().getPluginManager().registerEvents(playerBedEnter, this); //getServer().getPluginManager().registerEvents(playerBedEnter, this);
getServer().getPluginManager().registerEvents(playerBedLeave, this); //getServer().getPluginManager().registerEvents(playerBedLeave, this);
getServer().getPluginManager().registerEvents(worldLoad, this); getServer().getPluginManager().registerEvents(worldLoad, this);
getServer().getPluginManager().registerEvents(worldUnload, this); getServer().getPluginManager().registerEvents(worldUnload, this);
getServer().getPluginManager().registerEvents(playerDeath, this);
} }
} }
+5 -5
View File
@@ -11,7 +11,7 @@ public class ServerUtils {
public static String address_fallback = "localhost"; public static String address_fallback = "localhost";
public static String webhook_notify = Main.getNotifyWebhook(); public static String webhook_notify = Main.getNotifyWebhook();
public static String webhook_messages = Main.getPublicMessageWebhook(); public static String webhook_messages = Main.getPublicMessageWebhook();
public static String address = Utils.getServerHostPublicIP(); public static String address = "localhost";
public static boolean serverIsUp(String serverAddress, Integer serverPort) { public static boolean serverIsUp(String serverAddress, Integer serverPort) {
try { try {
@@ -19,19 +19,19 @@ public class ServerUtils {
Socket s = new Socket(); Socket s = new Socket();
s.connect(new InetSocketAddress(serverAddress, Integer.parseInt(serverPort.toString())), 15); s.connect(new InetSocketAddress(serverAddress, Integer.parseInt(serverPort.toString())), 15);
s.close(); s.close();
System.out.println("Server is online. Test notifying by sending a message to your webhook... (Pinged " + serverAddress + ":" + server.getPort() + ")"); Main.mainSmall.getLogger().info("Server is online. Test notifying by sending a message to your webhook... (Pinged " + serverAddress + ":" + server.getPort() + ")");
return true; return true;
} catch (Exception e) { } catch (Exception e) {
System.out.println("Server is inactive. Pinging fallback address..."); Main.mainSmall.getLogger().warning("Server is inactive. Pinging fallback address...");
try { try {
Server server = Bukkit.getServer(); Server server = Bukkit.getServer();
Socket s = new Socket(); Socket s = new Socket();
s.connect(new InetSocketAddress(address_fallback, Integer.parseInt(serverPort.toString())), 15); s.connect(new InetSocketAddress(address_fallback, Integer.parseInt(serverPort.toString())), 15);
s.close(); s.close();
System.out.println("Server is online. Sending message to webhook_notify... (Pinged " + Utils.getServerHostPublicIP() + ":" + server.getPort() + ")"); Main.mainSmall.getLogger().info("Server is online. Sending message to webhook_notify... (Pinged " + Utils.getServerHostPublicIP() + ":" + server.getPort() + ")");
return true; return true;
} catch (Exception err) { } catch (Exception err) {
System.out.println("Fallback address is inactive. No longer pinging..."); Main.mainSmall.getLogger().info("Fallback address is inactive. No longer pinging...");
} }
return false; return false;
} }
+3 -2
View File
@@ -7,6 +7,7 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI;
import java.net.URL; import java.net.URL;
public class Utils { public class Utils {
@@ -29,11 +30,11 @@ public class Utils {
public static String getServerHostPublicIP() { public static String getServerHostPublicIP() {
String urlString = "http://myexternalip.com/raw"; String urlString = "http://myexternalip.com/raw";
try { try {
URL url = new URL(urlString); URL url = new URI(urlString).toURL();
try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) { try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
return br.readLine(); return br.readLine();
} }
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -7,10 +7,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class SendMessageCommand implements CommandExecutor { public class SendMessageCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@@ -28,7 +24,7 @@ public class SendMessageCommand implements CommandExecutor {
discordWebhook.execute(); discordWebhook.execute();
sender.sendMessage("Sent public message."); sender.sendMessage("Sent public message.");
return true; return true;
} catch (IOException e) { } catch (Exception e) {
sender.sendMessage("An error occurred while sending your message..."); sender.sendMessage("An error occurred while sending your message...");
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -1,7 +1,6 @@
package moe.sob.commands; package moe.sob.commands;
import moe.sob.Main; import moe.sob.Main;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -14,7 +13,7 @@ public class SetGreetMessageCommand implements CommandExecutor {
} else { } else {
try { try {
String greetMessage = String.join(" ", args); String greetMessage = String.join(" ", args);
Main.configR.set("server.greet_message", greetMessage); Main.configR.set("server.entry_message", greetMessage);
Main.configR.save(Main.config); Main.configR.save(Main.config);
sender.sendMessage("Changed greet message successfully."); sender.sendMessage("Changed greet message successfully.");
@@ -1,7 +1,6 @@
package moe.sob.commands; package moe.sob.commands;
import moe.sob.Main; import moe.sob.Main;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -3,21 +3,19 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook; import moe.sob.DiscordWebhook;
import moe.sob.Main; import moe.sob.Main;
import moe.sob.ServerUtils; import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedEnterEvent; import org.bukkit.event.player.PlayerBedEnterEvent;
import java.awt.*; import java.awt.*;
import java.io.IOException;
import java.util.Date; import java.util.Date;
public class PlayerBedEnter implements Listener { public class PlayerBedEnter implements Listener {
@EventHandler @EventHandler
public void onPlayerBedEnter(PlayerBedEnterEvent event) { public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (Main.configR.getBoolean("log")) { if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("Player entered a bed."); Main.mainSmall.getLogger().info("Player entered a bed.");
Player player = event.getPlayer(); Player player = event.getPlayer();
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify); DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle(player.getName() + " is now sleeping...") DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle(player.getName() + " is now sleeping...")
@@ -27,7 +25,7 @@ public class PlayerBedEnter implements Listener {
notify.addEmbed(embedObject); notify.addEmbed(embedObject);
try { try {
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -3,31 +3,30 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook; import moe.sob.DiscordWebhook;
import moe.sob.Main; import moe.sob.Main;
import moe.sob.ServerUtils; import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedLeaveEvent; import org.bukkit.event.player.PlayerBedLeaveEvent;
import java.awt.*; import java.awt.*;
import java.io.IOException;
import java.util.Date; import java.util.Date;
public class PlayerBedLeave implements Listener { public class PlayerBedLeave implements Listener {
@EventHandler @EventHandler
public void onPlayerBedLeave(PlayerBedLeaveEvent event) { public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
if (Main.configR.getBoolean("log")) { if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("Player left a bed");
Player player = event.getPlayer(); Player player = event.getPlayer();
Main.mainSmall.getLogger().info("Player left a bed");
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify); DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle(player.getName() + " is no longer sleeping.") DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject()
.setTitle(player.getName() + " is no longer sleeping.")
.addField("Time", new Date().toString(), false) .addField("Time", new Date().toString(), false)
.addField("Player name", player.getName(), true) .addField("Player name", player.getName(), true)
.setColor(Color.BLUE); .setColor(Color.BLUE);
notify.addEmbed(embedObject); notify.addEmbed(embedObject);
try { try {
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -3,16 +3,10 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook; import moe.sob.DiscordWebhook;
import moe.sob.Main; import moe.sob.Main;
import moe.sob.ServerUtils; import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class PlayerChat implements Listener { public class PlayerChat implements Listener {
public PlayerChat() { public PlayerChat() {
} }
@@ -20,16 +14,14 @@ public class PlayerChat implements Listener {
@EventHandler @EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
// Bukkit.getConsoleSender().sendMessage("A message was sent by " + event.getPlayer().getName()); // kind of redundant considering the fact that we see chats in the console too // Bukkit.getConsoleSender().sendMessage("A message was sent by " + event.getPlayer().getName()); // kind of redundant considering the fact that we see chats in the console too
if (!Main.configR.getBoolean("log")) { if (Main.configR.getBoolean("log")) {
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify); DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("A message was sent by " + event.getPlayer().getName()) notify.setUsername(event.getPlayer().getName());
.addField("Send date", new Date().toString(), false) notify.setContent(event.getMessage());
.addField("Message content", event.getMessage(), true) //notify.setAvatarUrl(String.format("https://minotar.net/avatar/%s.png", event.getPlayer().getName()));
.setColor(Color.BLUE);
notify.addEmbed(embedObject);
try { try {
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -3,14 +3,12 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook; import moe.sob.DiscordWebhook;
import moe.sob.Main; import moe.sob.Main;
import moe.sob.ServerUtils; import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.awt.*; import java.awt.*;
import java.io.IOException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Date; import java.util.Date;
@@ -18,7 +16,7 @@ public class PlayerCommandPreprocess implements Listener {
@EventHandler @EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (Main.configR.getBoolean("log")) { if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("%s used a command".formatted(event.getPlayer().getName())); Main.mainSmall.getLogger().info("%s used a command".formatted(event.getPlayer().getName()));
Player player = event.getPlayer(); Player player = event.getPlayer();
String[] command = event.getMessage().split(" "); // get the command name String[] command = event.getMessage().split(" "); // get the command name
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify); DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
@@ -30,7 +28,7 @@ public class PlayerCommandPreprocess implements Listener {
notify.addEmbed(embedObject); notify.addEmbed(embedObject);
try { try {
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -45,7 +43,7 @@ public class PlayerCommandPreprocess implements Listener {
ntf.addEmbed(embed); ntf.addEmbed(embed);
try { try {
ntf.execute(); ntf.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -0,0 +1,29 @@
package moe.sob.events.player;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import moe.sob.DiscordWebhook;
import moe.sob.Main;
import moe.sob.ServerUtils;
// technically belongs to a /entity folder but it concerns a player anyways
public class PlayerDeath implements Listener {
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
if (Main.configR.getBoolean("log")) {
String playerName = event.getEntity().getName();
String deathMessage = event.getDeathMessage();
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
notify.setContent(deathMessage.replace(playerName, String.format("**%s**", playerName)));
notify.setUsername(playerName);
try {
notify.execute();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
@@ -3,33 +3,24 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook; import moe.sob.DiscordWebhook;
import moe.sob.Main; import moe.sob.Main;
import moe.sob.ServerUtils; import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class PlayerJoin implements Listener { public class PlayerJoin implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
if (Main.configR.getBoolean("log")) { if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("A player has joined the server.");
Player player = event.getPlayer(); Player player = event.getPlayer();
event.setJoinMessage(Main.getGreetMessage(player));
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify); DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("A player has joined the server.") notify.setUsername(player.getName());
.addField("Triggered at", new Date().toString(), false) notify.setContent(String.format("**%s** joined the server.", player.getName()));
.addField("Player name", player.getName(), true)
.setColor(Color.BLUE);
notify.addEmbed(embedObject);
try { try {
Bukkit.broadcastMessage(Main.getGreetMessage(player));
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -3,30 +3,20 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook; import moe.sob.DiscordWebhook;
import moe.sob.Main; import moe.sob.Main;
import moe.sob.ServerUtils; import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class PlayerQuit implements Listener { public class PlayerQuit implements Listener {
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
if (Main.configR.getBoolean("log")) { if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("A player has left the server.");
Player player = event.getPlayer();
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("A player has left the server.")
.addField("Date of exit", new Date().toString(), false)
.addField("Player name", event.getPlayer().getName(), true)
.setColor(Color.BLUE);
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify); DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
notify.addEmbed(embedObject); notify.setUsername(event.getPlayer().getName());
notify.setContent(String.format("**%s** left the server.", event.getPlayer().getName()));
try { try {
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -2,7 +2,6 @@ package moe.sob.events.server;
import moe.sob.DiscordWebhook; import moe.sob.DiscordWebhook;
import moe.sob.Main; import moe.sob.Main;
import moe.sob.ServerUtils;
import moe.sob.Utils; import moe.sob.Utils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -10,25 +9,29 @@ import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerLoadEvent; import org.bukkit.event.server.ServerLoadEvent;
import java.awt.*; import java.awt.*;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import moe.sob.DiscordWebhook.EmbedObject; import moe.sob.DiscordWebhook.EmbedObject;
import static moe.sob.ServerUtils.address;
public class ServerLoad implements Listener { public class ServerLoad implements Listener {
public static int timesCalled = 0; //public static int timesCalled = 0;
@EventHandler @EventHandler
public void onServerStart(ServerLoadEvent event) { public void onServerStart(ServerLoadEvent event) {
Bukkit.getConsoleSender().sendMessage("Triggered ServerLoad event."); Main.mainSmall.getLogger().info("Triggered ServerLoad event.");
if (timesCalled < 1) { /*
Bukkit.getConsoleSender().sendMessage("Checking if server is up on " + ServerUtils.address + " with port " + Bukkit.getServer().getPort() + "..."); * if (timesCalled < 1) {
if (ServerUtils.serverIsUp(address, Bukkit.getServer().getPort())) { * Main.mainSmall.getLogger().info("Checking if server is up on " +
* ServerUtils.address + " with port " + Bukkit.getServer().getPort() + "...");
* if (ServerUtils.serverIsUp(address, Bukkit.getServer().getPort())) {
*/
// System.out.println(ServerUtils.webhook_messages); // What the fuck!! // System.out.println(ServerUtils.webhook_messages); // What the fuck!!
// System.out.println(ServerUtils.webhook_notify); // System.out.println(ServerUtils.webhook_notify);
DiscordWebhook notify = new DiscordWebhook(Main.getNotifyWebhook()); DiscordWebhook notify = new DiscordWebhook(Main.getNotifyWebhook());
EmbedObject embedObject = new EmbedObject().setTitle("Server started up successfully").setDescription(String.format("The server at %s:%d has started successfully.", Utils.getServerHostPublicIP(), Bukkit.getServer().getPort())) EmbedObject embedObject = new EmbedObject().setTitle("Server started up successfully")
.setDescription(String.format("The server at %s:%d has started successfully.",
Utils.getServerHostPublicIP(), Bukkit.getServer().getPort()))
.addField("Date of start", new Date().toString(), false) .addField("Date of start", new Date().toString(), false)
.setColor(Color.GREEN); .setColor(Color.GREEN);
if (!Main.configR.getBoolean("log")) if (!Main.configR.getBoolean("log"))
@@ -36,17 +39,20 @@ public class ServerLoad implements Listener {
notify.addEmbed(embedObject); notify.addEmbed(embedObject);
try { try {
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
timesCalled++; /*
} else { * } else {
Bukkit.getConsoleSender().sendMessage("OnServerStart was called, but the server is currently offline... This may trigger more than once."); * Main.mainSmall.getLogger().
} * info("OnServerStart was called, but the server is currently offline... This may trigger more than once."
} else { * );
Bukkit.getConsoleSender().sendMessage("(debug) server start event was called more than 1 time"); * }
} * } else {
* Main.mainSmall.getLogger().
* info("(debug) server start event was called more than 1 time");
* }
*/
} }
} }
@@ -3,20 +3,18 @@ package moe.sob.events.world;
import moe.sob.DiscordWebhook; import moe.sob.DiscordWebhook;
import moe.sob.Main; import moe.sob.Main;
import moe.sob.ServerUtils; import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
import java.awt.*; import java.awt.*;
import java.io.IOException;
import java.util.Date; import java.util.Date;
public class WorldLoad implements Listener { public class WorldLoad implements Listener {
@EventHandler @EventHandler
public void onWorldLoad(WorldLoadEvent event) { public void onWorldLoad(WorldLoadEvent event) {
if (Main.configR.getBoolean("log")) { if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("Triggered WorldLoad event."); Main.mainSmall.getLogger().info("Triggered WorldLoad event.");
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify); DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("World loaded") DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("World loaded")
.addField("Time", new Date().toString(), false) .addField("Time", new Date().toString(), false)
@@ -25,7 +23,7 @@ public class WorldLoad implements Listener {
notify.addEmbed(embedObject); notify.addEmbed(embedObject);
try { try {
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -3,20 +3,18 @@ package moe.sob.events.world;
import moe.sob.DiscordWebhook; import moe.sob.DiscordWebhook;
import moe.sob.Main; import moe.sob.Main;
import moe.sob.ServerUtils; import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.event.world.WorldUnloadEvent;
import java.awt.*; import java.awt.*;
import java.io.IOException;
import java.util.Date; import java.util.Date;
public class WorldUnload implements Listener { public class WorldUnload implements Listener {
@EventHandler @EventHandler
public void onWorldUnload(WorldUnloadEvent event) { public void onWorldUnload(WorldUnloadEvent event) {
if (Main.configR.getBoolean("log")) { if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("Triggered WorldUnload event."); Main.mainSmall.getLogger().info("Triggered WorldUnload event.");
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify); DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("WorldUnload").setDescription("A world was unloaded...") DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("WorldUnload").setDescription("A world was unloaded...")
.addField("Time", new Date().toString(), false) .addField("Time", new Date().toString(), false)
@@ -25,7 +23,7 @@ public class WorldUnload implements Listener {
notify.addEmbed(embedObject); notify.addEmbed(embedObject);
try { try {
notify.execute(); notify.execute();
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
+4 -2
View File
@@ -1,5 +1,5 @@
main: moe.sob.Main main: moe.sob.Main
version: 1.2.0 version: 1.3.0
name: notifyOnStart name: notifyOnStart
description: A logging plugin. description: A logging plugin.
api-version: 1.19 api-version: 1.19
@@ -17,13 +17,15 @@ commands:
description: Enables or disables event logging. Server performance is enhanced while logs are disabled. (Depending on server speed) description: Enables or disables event logging. Server performance is enhanced while logs are disabled. (Depending on server speed)
usage: /set-logging <true|false> usage: /set-logging <true|false>
permission: op permission: op
permission-message: Only operators can use this command. permission-message: Only server operators can use this command.
aliases: [sl] aliases: [sl]
ping-server: ping-server:
description: Gets the server ping. description: Gets the server ping.
usage: /ping-server usage: /ping-server
aliases: [ping] aliases: [ping]
set-greet-message: set-greet-message:
permission: op
permission-message: Only server operators can use this command.
description: Change the message sent to players whenever they join the server. description: Change the message sent to players whenever they join the server.
usage: /set-greet-message <msg> usage: /set-greet-message <msg>
aliases: [sgm] aliases: [sgm]