Compare commits

6 Commits

25 changed files with 265 additions and 257 deletions
+2 -2
View File
@@ -32,7 +32,7 @@ server:
entry_message: Welcome to @servername, @playername!
webhooks:
notify: default-ns
broadcast: defeault-ns
broadcast: default-ns
log: true
firstrun: 0
```
@@ -40,7 +40,7 @@ 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 afterward:
or over the `default-ns` text. The configuration should look like this afterwards:
```yml
+1 -1
View File
@@ -3,7 +3,7 @@ plugins {
}
group 'moe.sob'
version '1.2.0'
version '1.3.0'
repositories {
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
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (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.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +82,12 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -133,22 +134,29 @@ location of your Java installation."
fi
else
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
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
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 ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | 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" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# 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 -- \
"-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 limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@@ -26,6 +28,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -42,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
@@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
-1
View File
@@ -1 +0,0 @@
rootProject.name = 'notifyonstart'
+8 -4
View File
@@ -2,9 +2,9 @@ package moe.sob;
import javax.net.ssl.HttpsURLConnection;
import java.awt.*;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.net.URI;
import java.net.URL;
import java.util.List;
import java.util.*;
@@ -50,7 +50,8 @@ public class DiscordWebhook {
this.embeds.add(embed);
}
public void execute() throws IOException {
public void execute() throws Exception {
try {
if (this.content == null && this.embeds.isEmpty()) {
throw new IllegalArgumentException("Set content or add at least one EmbedObject");
}
@@ -136,7 +137,7 @@ public class DiscordWebhook {
json.put("embeds", embedObjects.toArray());
}
URL url = new URL(this.url);
URL url = new URI(this.url).toURL();
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_");
@@ -148,8 +149,11 @@ public class DiscordWebhook {
stream.flush();
stream.close();
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();
} catch (Exception e) {
throw new Exception();
}
}
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.world.WorldLoad;
import moe.sob.events.world.WorldUnload;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -20,20 +18,19 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.awt.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.Objects;
public class Main extends JavaPlugin {
private static Main mainSmall;
public static Main mainSmall;
private static boolean webhooksAreValidUrls;
public static boolean hdc;
public static File config;
public static FileConfiguration configR;
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
public void onDisable() {
@@ -45,7 +42,7 @@ public class Main extends JavaPlugin {
notify.addEmbed(embedObject);
try {
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -76,7 +73,7 @@ public class Main extends JavaPlugin {
}
// 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
try {
Objects.requireNonNull(this.getCommand("info")).setExecutor(new InfoCommand());
@@ -110,7 +107,7 @@ public class Main extends JavaPlugin {
return false;
}
URL url = new URL(getPublicMessageWebhook());
URL url = new URI(getPublicMessageWebhook()).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
@@ -121,8 +118,8 @@ public class Main extends JavaPlugin {
return false;
}
} 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)");
System.out.printf("Exception: %s%n", e);
mainSmall.getLogger().severe("Invalid webhook URL provide for your public messages. Please provide the correct webhook and check for any typos. (Caught exception)");
//mainSmall.getLogger().severe(String.format("Exception: %s%n", e));
return false;
}
}
@@ -134,7 +131,7 @@ public class Main extends JavaPlugin {
return false;
}
URL url = new URL(getNotifyWebhook());
URL url = new URI(getNotifyWebhook()).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
@@ -145,7 +142,7 @@ public class Main extends JavaPlugin {
return false;
}
} 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;
}
}
@@ -188,16 +185,18 @@ public class Main extends JavaPlugin {
public void registerEvents() {
PlayerChat playerChat = new PlayerChat();
PlayerCommandPreprocess playerCommandPreprocess = new PlayerCommandPreprocess();
PlayerBedEnter playerBedEnter = new PlayerBedEnter();
PlayerBedLeave playerBedLeave = new PlayerBedLeave();
//PlayerCommandPreprocess playerCommandPreprocess = new PlayerCommandPreprocess();
//PlayerBedEnter playerBedEnter = new PlayerBedEnter();
//PlayerBedLeave playerBedLeave = new PlayerBedLeave(); // Redundant event
WorldLoad worldLoad = new WorldLoad();
WorldUnload worldUnload = new WorldUnload();
PlayerDeath playerDeath = new PlayerDeath();
getServer().getPluginManager().registerEvents(playerChat, this);
getServer().getPluginManager().registerEvents(playerCommandPreprocess, this);
getServer().getPluginManager().registerEvents(playerBedEnter, this);
getServer().getPluginManager().registerEvents(playerBedLeave, this);
//getServer().getPluginManager().registerEvents(playerCommandPreprocess, this);
//getServer().getPluginManager().registerEvents(playerBedEnter, this);
//getServer().getPluginManager().registerEvents(playerBedLeave, this);
getServer().getPluginManager().registerEvents(worldLoad, 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 webhook_notify = Main.getNotifyWebhook();
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) {
try {
@@ -19,19 +19,19 @@ public class ServerUtils {
Socket s = new Socket();
s.connect(new InetSocketAddress(serverAddress, Integer.parseInt(serverPort.toString())), 15);
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;
} catch (Exception e) {
System.out.println("Server is inactive. Pinging fallback address...");
Main.mainSmall.getLogger().warning("Server is inactive. Pinging fallback address...");
try {
Server server = Bukkit.getServer();
Socket s = new Socket();
s.connect(new InetSocketAddress(address_fallback, Integer.parseInt(serverPort.toString())), 15);
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;
} 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;
}
+3 -2
View File
@@ -7,6 +7,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
public class Utils {
@@ -29,11 +30,11 @@ public class Utils {
public static String getServerHostPublicIP() {
String urlString = "http://myexternalip.com/raw";
try {
URL url = new URL(urlString);
URL url = new URI(urlString).toURL();
try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
return br.readLine();
}
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -7,10 +7,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class SendMessageCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@@ -28,7 +24,7 @@ public class SendMessageCommand implements CommandExecutor {
discordWebhook.execute();
sender.sendMessage("Sent public message.");
return true;
} catch (IOException e) {
} catch (Exception e) {
sender.sendMessage("An error occurred while sending your message...");
throw new RuntimeException(e);
}
@@ -1,7 +1,6 @@
package moe.sob.commands;
import moe.sob.Main;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -14,7 +13,7 @@ public class SetGreetMessageCommand implements CommandExecutor {
} else {
try {
String greetMessage = String.join(" ", args);
Main.configR.set("server.greet_message", greetMessage);
Main.configR.set("server.entry_message", greetMessage);
Main.configR.save(Main.config);
sender.sendMessage("Changed greet message successfully.");
@@ -1,7 +1,6 @@
package moe.sob.commands;
import moe.sob.Main;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -3,21 +3,19 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook;
import moe.sob.Main;
import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedEnterEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class PlayerBedEnter implements Listener {
@EventHandler
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("Player entered a bed.");
Main.mainSmall.getLogger().info("Player entered a bed.");
Player player = event.getPlayer();
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle(player.getName() + " is now sleeping...")
@@ -27,7 +25,7 @@ public class PlayerBedEnter implements Listener {
notify.addEmbed(embedObject);
try {
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -3,31 +3,30 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook;
import moe.sob.Main;
import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class PlayerBedLeave implements Listener {
@EventHandler
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("Player left a bed");
Player player = event.getPlayer();
Main.mainSmall.getLogger().info("Player left a bed");
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("Player name", player.getName(), true)
.setColor(Color.BLUE);
notify.addEmbed(embedObject);
try {
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -3,16 +3,10 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook;
import moe.sob.Main;
import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class PlayerChat implements Listener {
public PlayerChat() {
}
@@ -20,16 +14,14 @@ public class PlayerChat implements Listener {
@EventHandler
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
if (!Main.configR.getBoolean("log")) {
if (Main.configR.getBoolean("log")) {
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("A message was sent by " + event.getPlayer().getName())
.addField("Send date", new Date().toString(), false)
.addField("Message content", event.getMessage(), true)
.setColor(Color.BLUE);
notify.addEmbed(embedObject);
notify.setUsername(event.getPlayer().getName());
notify.setContent(event.getMessage());
//notify.setAvatarUrl(String.format("https://minotar.net/avatar/%s.png", event.getPlayer().getName()));
try {
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -3,14 +3,12 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook;
import moe.sob.Main;
import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.awt.*;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
@@ -18,7 +16,7 @@ public class PlayerCommandPreprocess implements Listener {
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
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();
String[] command = event.getMessage().split(" "); // get the command name
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
@@ -30,7 +28,7 @@ public class PlayerCommandPreprocess implements Listener {
notify.addEmbed(embedObject);
try {
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -45,7 +43,7 @@ public class PlayerCommandPreprocess implements Listener {
ntf.addEmbed(embed);
try {
ntf.execute();
} catch (IOException e) {
} catch (Exception 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.Main;
import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class PlayerJoin implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("A player has joined the server.");
Player player = event.getPlayer();
event.setJoinMessage(Main.getGreetMessage(player));
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("A player has joined the server.")
.addField("Triggered at", new Date().toString(), false)
.addField("Player name", player.getName(), true)
.setColor(Color.BLUE);
notify.addEmbed(embedObject);
notify.setUsername(player.getName());
notify.setContent(String.format("**%s** joined the server.", player.getName()));
try {
Bukkit.broadcastMessage(Main.getGreetMessage(player));
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -3,30 +3,20 @@ package moe.sob.events.player;
import moe.sob.DiscordWebhook;
import moe.sob.Main;
import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class PlayerQuit implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
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);
notify.addEmbed(embedObject);
notify.setUsername(event.getPlayer().getName());
notify.setContent(String.format("**%s** left the server.", event.getPlayer().getName()));
try {
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -2,7 +2,6 @@ package moe.sob.events.server;
import moe.sob.DiscordWebhook;
import moe.sob.Main;
import moe.sob.ServerUtils;
import moe.sob.Utils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
@@ -10,25 +9,29 @@ import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerLoadEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
import moe.sob.DiscordWebhook.EmbedObject;
import static moe.sob.ServerUtils.address;
public class ServerLoad implements Listener {
public static int timesCalled = 0;
//public static int timesCalled = 0;
@EventHandler
public void onServerStart(ServerLoadEvent event) {
Bukkit.getConsoleSender().sendMessage("Triggered ServerLoad event.");
if (timesCalled < 1) {
Bukkit.getConsoleSender().sendMessage("Checking if server is up on " + ServerUtils.address + " with port " + Bukkit.getServer().getPort() + "...");
if (ServerUtils.serverIsUp(address, Bukkit.getServer().getPort())) {
Main.mainSmall.getLogger().info("Triggered ServerLoad event.");
/*
* if (timesCalled < 1) {
* 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_notify);
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)
.setColor(Color.GREEN);
if (!Main.configR.getBoolean("log"))
@@ -36,17 +39,20 @@ public class ServerLoad implements Listener {
notify.addEmbed(embedObject);
try {
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
timesCalled++;
} else {
Bukkit.getConsoleSender().sendMessage("OnServerStart was called, but the server is currently offline... This may trigger more than once.");
/*
* } else {
* Main.mainSmall.getLogger().
* info("OnServerStart was called, but the server is currently offline... This may trigger more than once."
* );
* }
* } else {
* Main.mainSmall.getLogger().
* info("(debug) server start event was called more than 1 time");
* }
*/
}
} else {
Bukkit.getConsoleSender().sendMessage("(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.Main;
import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class WorldLoad implements Listener {
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
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.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("World loaded")
.addField("Time", new Date().toString(), false)
@@ -25,7 +23,7 @@ public class WorldLoad implements Listener {
notify.addEmbed(embedObject);
try {
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -3,20 +3,18 @@ package moe.sob.events.world;
import moe.sob.DiscordWebhook;
import moe.sob.Main;
import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldUnloadEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
public class WorldUnload implements Listener {
@EventHandler
public void onWorldUnload(WorldUnloadEvent event) {
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.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("WorldUnload").setDescription("A world was unloaded...")
.addField("Time", new Date().toString(), false)
@@ -25,7 +23,7 @@ public class WorldUnload implements Listener {
notify.addEmbed(embedObject);
try {
notify.execute();
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+4 -2
View File
@@ -1,5 +1,5 @@
main: moe.sob.Main
version: 1.2.0
version: 1.3.0
name: notifyOnStart
description: A logging plugin.
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)
usage: /set-logging <true|false>
permission: op
permission-message: Only operators can use this command.
permission-message: Only server operators can use this command.
aliases: [sl]
ping-server:
description: Gets the server ping.
usage: /ping-server
aliases: [ping]
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.
usage: /set-greet-message <msg>
aliases: [sgm]