Compare commits
11 Commits
6b463cf5b3
..
1.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 346d93d209 | |||
| 533d25cbce | |||
| 535fbf103e | |||
| e560b9fc74 | |||
| 23b2a548e9 | |||
| 033e751c9a | |||
| 3a3cdd8c2c | |||
| 6635b7aff4 | |||
| d5ea4135ac | |||
| 02f73ad13e | |||
| eabb5a69c1 |
generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CompilerConfiguration">
|
<component name="CompilerConfiguration">
|
||||||
<bytecodeTargetLevel target="18" />
|
<bytecodeTargetLevel target="17" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
generated
+1
-1
@@ -6,5 +6,5 @@
|
|||||||
</list>
|
</list>
|
||||||
</component>
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
||||||
generated
-8
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/notifyonstart.main.iml" filepath="$PROJECT_DIR$/.idea/modules/notifyonstart.main.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
generated
+54
-20
@@ -4,7 +4,7 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="ce97b9f5-6785-4670-b350-12f90ab9ea27" name="Changes" comment="dunno if it works (2)" />
|
<list default="true" id="ce97b9f5-6785-4670-b350-12f90ab9ea27" name="Changes" comment="1.2.0: Remove unnecessary events, use yml as a config, implement log disabling" />
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
@@ -46,24 +46,29 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"Downloaded.Files.Path.Enabled": "false",
|
"Downloaded.Files.Path.Enabled": "false",
|
||||||
"Gradle.notify-on-start [build].executor": "Run",
|
"Gradle.notify-on-start [build].executor": "Run",
|
||||||
"Repository.Attach.Annotations": "false",
|
"Repository.Attach.Annotations": "false",
|
||||||
"Repository.Attach.JavaDocs": "false",
|
"Repository.Attach.JavaDocs": "false",
|
||||||
"Repository.Attach.Sources": "false",
|
"Repository.Attach.Sources": "false",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"last_opened_file_path": "G:/java/notify-on-start",
|
"last_opened_file_path": "G:/java/notify-on-start",
|
||||||
"project.structure.last.edited": "Libraries",
|
"project.structure.last.edited": "Libraries",
|
||||||
"project.structure.proportion": "0.0",
|
"project.structure.proportion": "0.0",
|
||||||
"project.structure.side.proportion": "0.2",
|
"project.structure.side.proportion": "0.2",
|
||||||
"settings.editor.selected.configurable": "reference.settingsdialog.project.gradle"
|
"settings.editor.selected.configurable": "reference.settingsdialog.project.gradle"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
|
<component name="RecentsManager">
|
||||||
|
<key name="CopyClassDialog.RECENTS_KEY">
|
||||||
|
<recent name="moe.sob.commands" />
|
||||||
|
</key>
|
||||||
|
</component>
|
||||||
<component name="RunManager" selected="Gradle.notify-on-start [build]">
|
<component name="RunManager" selected="Gradle.notify-on-start [build]">
|
||||||
<configuration name="notify-on-start [build]" type="GradleRunConfiguration" factoryName="Gradle" nameIsGenerated="true">
|
<configuration name="notify-on-start [build]" type="GradleRunConfiguration" factoryName="Gradle" nameIsGenerated="true">
|
||||||
<ExternalSystemSettings>
|
<ExternalSystemSettings>
|
||||||
@@ -177,15 +182,44 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1699768015200</updated>
|
<updated>1699768015200</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="6" />
|
<task id="LOCAL-00006" summary="1.2.0: Remove unnecessary events, use yml as a config">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1760533930115</created>
|
||||||
|
<option name="number" value="00006" />
|
||||||
|
<option name="presentableId" value="LOCAL-00006" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1760533930115</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00007" summary="1.2.0: Remove unnecessary events, use yml as a config, implement log disabling">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1764083460575</created>
|
||||||
|
<option name="number" value="00007" />
|
||||||
|
<option name="presentableId" value="LOCAL-00007" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1764083460575</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="8" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State />
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="hmmm" />
|
<MESSAGE value="hmmm" />
|
||||||
<MESSAGE value="fix stuff and add more functionality (definitely) (hi again)" />
|
<MESSAGE value="fix stuff and add more functionality (definitely) (hi again)" />
|
||||||
<MESSAGE value="wrong version number" />
|
<MESSAGE value="wrong version number" />
|
||||||
<MESSAGE value="dunno if it works" />
|
<MESSAGE value="dunno if it works" />
|
||||||
<MESSAGE value="dunno if it works (2)" />
|
<MESSAGE value="dunno if it works (2)" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="dunno if it works (2)" />
|
<MESSAGE value="1.2.0: Remove unnecessary events, use yml as a config" />
|
||||||
|
<MESSAGE value="1.2.0: Remove unnecessary events, use yml as a config, implement log disabling" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="1.2.0: Remove unnecessary events, use yml as a config, implement log disabling" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,59 +1,57 @@
|
|||||||
# notify-on-start
|
# notify-on-start
|
||||||
|
*(maki, 4/20/25)*
|
||||||
this project is made to just send messages to Discord webhooks when events trigger
|
this is a personal project, there are DEFINITELY better alternatives; this plugin is mostly server-exclusive.
|
||||||
|
it was made to notify a discord server whenever a event occurred in a minecraft server.
|
||||||
this was just made to remember whatever goofy things we did in a minecraft server, in discord
|
|
||||||
|
# Prerequisites
|
||||||
or, you know, notify us when the server starts and ends (and other things...)
|
Before using this plugin, you must:
|
||||||
|
* Get Spigot
|
||||||
*(maki, 4/20/25)*
|
* Get a JAR file from [the releases](https://rrryfoo.sob.moe/rrryfoo/notify-on-start/releases)
|
||||||
this is a personal project, there are DEFINITELY better alternatives; this plugin is mostly server-exclusive
|
|
||||||
# Prerequisites
|
# Webhook creation
|
||||||
Before using this plugin, you must:
|
If you already know how to make a webhook, disregard this section of the readme.
|
||||||
* 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)
|
To make a webhook:
|
||||||
# making webhooks
|
1. Go to your Discord server.
|
||||||
If you already know how, you can skip this step.
|
2. Edit a channel.
|
||||||
|
3. Go to "Integrations" and then "Webhooks"
|
||||||
To make a webhook:
|
4. Click "New Webhook"
|
||||||
1. Go to a Discord server.\
|
5. Give the webhook a name. As an example, we will use `notify` as the webhook name.
|
||||||
You can make a new channel or use an existing one.
|
6. You may change the channel where it is associated/linked to, change the webhook name, and set a picture for the webhook.
|
||||||
2. Right-click on the channel.
|
7. Copy the webhook link.
|
||||||
3. Click "Edit Channel".
|
|
||||||
4. Click "Integrations" and click "Webhooks".
|
# Usage
|
||||||
5. Click "New Webhook".
|
To use this plugin, obtain a release and place the binary on the `plugins` folder of your Spigot/Paper/Bukkit server.
|
||||||
6. Give the webhook a name. As an example, we will use `notify` as the webhook name.
|
|
||||||
7. You may change the channel where it is associated/linked to, change the webhook name, and set a picture for the webhook.
|
Once the plugin is used for the first time, it will make a YAML configuration file in the plugin's directory named `notifyOnStart.`\
|
||||||
8. Copy the webhook link.
|
It should look like this:
|
||||||
|
|
||||||
|
```yml
|
||||||
# using this thing
|
server:
|
||||||
Of course, you must get a release first, as said in the prerequisites. After you get a jar, put it in the `plugins` folder
|
name: Minecraft Server
|
||||||
|
entry_message: Welcome to @servername, @playername!
|
||||||
On first run, it will make a directory in the server's base directory.\
|
webhooks:
|
||||||
In it, there will be one important file:\
|
notify: default-ns
|
||||||
This file will be `NoS/config_webhook.json`.
|
broadcast: default-ns
|
||||||
|
log: true
|
||||||
Of course, put the webhook URL of where the events should be logged in the `url_notify` field.
|
firstrun: 0
|
||||||
|
```
|
||||||
The `url_publicmsg` field is for a command named `/send-message`. This will simply send text to the webhook containing provided text.\
|
|
||||||
Put the webhook link in it.
|
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.
|
||||||
|
|
||||||
An example of what the file's content should be:
|
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:
|
||||||
```json
|
|
||||||
{
|
|
||||||
"url_notify": "<get the webhook link from earlier and paste>",
|
```yml
|
||||||
"url_publicmsg": "<same as earlier>"
|
server:
|
||||||
}
|
name: Minecraft Server
|
||||||
```
|
entry_message: Welcome to @servername, @playername!
|
||||||
|
webhooks:
|
||||||
If you change this value, you have to restart the server to apply changes.
|
notify: https://discord.com/webhooks/webhook_for_notifications
|
||||||
|
broadcast: ttps://discord.com/webhooks/webhook_for_player_broadcasts
|
||||||
By default, its value is:
|
log: true
|
||||||
```json
|
firstrun: 0
|
||||||
{
|
```
|
||||||
"url_notify": "default-ns",
|
|
||||||
"url_publicmsg": "default-ns"
|
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.
|
||||||
}
|
|
||||||
```
|
|
||||||
+3
-3
@@ -2,8 +2,8 @@ plugins {
|
|||||||
id 'java'
|
id 'java'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'cf.sobrooms'
|
group 'moe.sob'
|
||||||
version '1.1.4'
|
version '1.3.0'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -25,6 +25,6 @@ test {
|
|||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes 'Main-Class': 'cf.sobrooms.Main'
|
attributes 'Main-Class': 'moe.sob.Main'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vendored
BIN
Binary file not shown.
-5
@@ -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
|
|
||||||
@@ -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
@@ -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 +0,0 @@
|
|||||||
rootProject.name = 'notifyonstart'
|
|
||||||
@@ -1,281 +0,0 @@
|
|||||||
package cf.sobrooms;
|
|
||||||
|
|
||||||
import cf.sobrooms.commands.InfoCommand;
|
|
||||||
import cf.sobrooms.commands.PingCommand;
|
|
||||||
import cf.sobrooms.commands.SendMessageCommand;
|
|
||||||
import cf.sobrooms.commands.SetLoggingModeCommand;
|
|
||||||
import cf.sobrooms.events.enchantment.EnchantItem;
|
|
||||||
import cf.sobrooms.events.enchantment.PrepareItemEnchant;
|
|
||||||
import cf.sobrooms.events.player.*;
|
|
||||||
import cf.sobrooms.events.server.ServerLoad;
|
|
||||||
import cf.sobrooms.events.vehicle.VehicleEnter;
|
|
||||||
import cf.sobrooms.events.vehicle.VehicleExit;
|
|
||||||
import cf.sobrooms.events.weather.LightningStrike;
|
|
||||||
import cf.sobrooms.events.weather.ThunderChange;
|
|
||||||
import cf.sobrooms.events.weather.WeatherChange;
|
|
||||||
import cf.sobrooms.events.world.WorldInit;
|
|
||||||
import cf.sobrooms.events.world.WorldLoad;
|
|
||||||
import cf.sobrooms.events.world.WorldUnload;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Main extends JavaPlugin {
|
|
||||||
public static File isLoggingConfig;
|
|
||||||
public static File webhookConfig;
|
|
||||||
private static boolean webhooksAreValidUrls;
|
|
||||||
public static boolean hdc;
|
|
||||||
public static File greetConfig;
|
|
||||||
public static void main(String... args) {
|
|
||||||
System.out.printf("Initializing using server address: %s...%n", ServerUtils.address);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
if (Main.webhooksAreValidUrls) {
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(Main.getNotifyWebhook());
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("The server has been disabled.").setDescription(String.format("The server at %s:%d is now shutting down.", Utils.getServerHostPublicIP(), Bukkit.getServer().getPort()))
|
|
||||||
.addField("Date occurred (as a local timestamp)", new Date().toString(), false)
|
|
||||||
.setColor(Color.DARK_GRAY);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
String loggingDir = "./NoS";
|
|
||||||
File directory = new File(loggingDir);
|
|
||||||
if (!directory.exists()) {
|
|
||||||
if (directory.mkdir()) {
|
|
||||||
System.out.println("Config dir created: " + loggingDir);
|
|
||||||
} else {
|
|
||||||
System.out.println("Failed to create config directory: " + loggingDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isLoggingConfig = new File("./NoS/willLogEvents");
|
|
||||||
greetConfig = new File("./NoS/greetText.txt");
|
|
||||||
webhookConfig = new File("./NoS/config_webhook.json");
|
|
||||||
try {
|
|
||||||
if (isLoggingConfig.createNewFile()) {
|
|
||||||
System.out.println("Configuration file created: " + isLoggingConfig.getName());
|
|
||||||
//FileWriter notifyWebhookConfigWriter = new FileWriter(notifyWebhookConfig);
|
|
||||||
//FileWriter pubMessageWebhookConfigWriter = new FileWriter(pubMessageWebhookConfig);
|
|
||||||
//notifyWebhookConfigWriter.write("{\"url_notify\": \"default-ns\"}");
|
|
||||||
FileWriter linkConfigWriter = new FileWriter(webhookConfig);
|
|
||||||
FileWriter greetConfigWriter = new FileWriter(greetConfig);
|
|
||||||
greetConfigWriter.write("Welcome to $servername, $playername!");
|
|
||||||
linkConfigWriter.write("""
|
|
||||||
{"servername": "Nilou-PNK", "url_publicmsg": "default-ns", "url_notify": "default-ns", "entryMessage": "Welcome to @servername, @playername!"}
|
|
||||||
""");
|
|
||||||
linkConfigWriter.close();
|
|
||||||
greetConfigWriter.close();
|
|
||||||
//notifyWebhookConfigWriter.close();
|
|
||||||
} else {
|
|
||||||
System.out.println("Tried to create config even while it already exists, skipping step...");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
// such cap
|
|
||||||
//Bukkit.getConsoleSender().sendMessage("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());
|
|
||||||
Objects.requireNonNull(this.getCommand("send-message")).setExecutor(new SendMessageCommand());
|
|
||||||
Objects.requireNonNull(this.getCommand("set-logging")).setExecutor(new SetLoggingModeCommand());
|
|
||||||
Objects.requireNonNull(this.getCommand("ping-server")).setExecutor(new PingCommand());
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
webhooksAreValidUrls = validateWebhook_Ntfy();
|
|
||||||
hdc = validateWebhook_Pub();
|
|
||||||
// register events
|
|
||||||
if (getLoggingConfig().equals("true") && webhooksAreValidUrls)
|
|
||||||
registerEvents();
|
|
||||||
if (webhooksAreValidUrls) {
|
|
||||||
ServerLoad serverStart = new ServerLoad();
|
|
||||||
getServer().getPluginManager().registerEvents(serverStart, this);
|
|
||||||
PlayerJoin playerJoin = new PlayerJoin();
|
|
||||||
PlayerQuit playerQuit = new PlayerQuit();
|
|
||||||
getServer().getPluginManager().registerEvents(playerJoin, this);
|
|
||||||
getServer().getPluginManager().registerEvents(playerQuit, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean validateWebhook_Pub() {
|
|
||||||
try {
|
|
||||||
if (getPublicMessageWebhook().equals("default-ns") || !getPublicMessageWebhook().contains("https://")) {
|
|
||||||
System.out.println("There was no webhook set for the public messages function. The send-message command cannot be used until you do.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
URL url = new URL(getPublicMessageWebhook());
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
int responseCode = connection.getResponseCode();
|
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
System.out.println("Invalid webhook URL provided for your public messages. Please provide the correct webhook and check for any typos.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("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);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static boolean validateWebhook_Ntfy() {
|
|
||||||
try {
|
|
||||||
URL url = new URL(getNotifyWebhook());
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
int responseCode = connection.getResponseCode();
|
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
System.out.println("Invalid webhook URL provided for the event logs. Please provide the correct webhook and check for any typos.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("Invalid webhook URL provided for the event logs. Please provide the correct webhook and check for any typos. (Caught exception)");
|
|
||||||
System.out.println("Exception: %s".formatted(e));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static String getPublicMessageWebhook() {
|
|
||||||
try {
|
|
||||||
BufferedReader brfmsg = new BufferedReader(new FileReader(webhookConfig));
|
|
||||||
JsonParser jsonReader = new JsonParser();
|
|
||||||
JsonElement MsgParse = jsonReader.parse(brfmsg.readLine());
|
|
||||||
String lineMsg = MsgParse.getAsJsonObject().get("url_publicmsg").getAsString();
|
|
||||||
|
|
||||||
brfmsg.close();
|
|
||||||
if (lineMsg.startsWith("https://") || lineMsg.startsWith("http://")) {
|
|
||||||
webhooksAreValidUrls = true;
|
|
||||||
return lineMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "default-ns";
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static String getServerName() {
|
|
||||||
try {
|
|
||||||
BufferedReader brfmsg = new BufferedReader(new FileReader(webhookConfig));
|
|
||||||
JsonParser jsonReader = new JsonParser();
|
|
||||||
JsonElement MsgParse = jsonReader.parse(brfmsg.readLine());
|
|
||||||
String serverName = MsgParse.getAsJsonObject().get("servername").getAsString();
|
|
||||||
|
|
||||||
brfmsg.close();
|
|
||||||
|
|
||||||
return serverName;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static String getGreetMessage(Player player) {
|
|
||||||
try {
|
|
||||||
BufferedReader brfmsg = new BufferedReader(new FileReader(webhookConfig));
|
|
||||||
JsonParser jsonReader = new JsonParser();
|
|
||||||
JsonElement MsgParse = jsonReader.parse(brfmsg.readLine());
|
|
||||||
String entryMessage = MsgParse.getAsJsonObject().get("entryMessage").getAsString();
|
|
||||||
String serverName = getServerName();
|
|
||||||
String playername = player.getName();
|
|
||||||
brfmsg.close();
|
|
||||||
String finalOut = "";
|
|
||||||
finalOut = entryMessage.replaceAll("@servername", serverName).replaceAll("@playername", playername);
|
|
||||||
|
|
||||||
return finalOut;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getNotifyWebhook() {
|
|
||||||
try {
|
|
||||||
BufferedReader brfntfy = new BufferedReader(new FileReader(webhookConfig));
|
|
||||||
JsonParser jsonReader = new JsonParser();
|
|
||||||
JsonElement NtfyParse = jsonReader.parse(brfntfy.readLine());
|
|
||||||
String lineNtfy = NtfyParse.getAsJsonObject().get("url_notify").getAsString();
|
|
||||||
|
|
||||||
brfntfy.close();
|
|
||||||
if (lineNtfy.equals("default-ns")) {
|
|
||||||
System.out.printf("Please set the webhook URL in %s and restart the server", webhookConfig.getAbsolutePath());
|
|
||||||
webhooksAreValidUrls = false;
|
|
||||||
return lineNtfy;
|
|
||||||
} else if (lineNtfy.startsWith("https://") || lineNtfy.startsWith("http://")) {
|
|
||||||
webhooksAreValidUrls = true;
|
|
||||||
return lineNtfy;
|
|
||||||
} else {
|
|
||||||
System.out.printf("Please set the webhook URL in %s and restart the server", webhookConfig.getAbsolutePath());
|
|
||||||
webhooksAreValidUrls = false;
|
|
||||||
return lineNtfy;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static String getLoggingConfig() {
|
|
||||||
try {
|
|
||||||
File file = new File("./NoS/willLogEvents");
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
if (line.equals("true") || line.equals("false"))
|
|
||||||
return line;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("An error occurred while reading the configuration file.");
|
|
||||||
e.printStackTrace();
|
|
||||||
return "err";
|
|
||||||
}
|
|
||||||
return "err";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerEvents() {
|
|
||||||
PlayerChat playerChat = new PlayerChat();
|
|
||||||
PlayerCommandPreprocess playerCommandPreprocess = new PlayerCommandPreprocess();
|
|
||||||
EnchantItem enchantItemEvent = new EnchantItem();
|
|
||||||
PrepareItemEnchant prepareItemEnchant = new PrepareItemEnchant();
|
|
||||||
PlayerBedEnter playerBedEnter = new PlayerBedEnter();
|
|
||||||
PlayerBedLeave playerBedLeave = new PlayerBedLeave();
|
|
||||||
LightningStrike lightningStrike = new LightningStrike();
|
|
||||||
ThunderChange thunderChange = new ThunderChange();
|
|
||||||
WeatherChange weatherChange = new WeatherChange();
|
|
||||||
WorldInit worldInit = new WorldInit();
|
|
||||||
WorldLoad worldLoad = new WorldLoad();
|
|
||||||
WorldUnload worldUnload = new WorldUnload();
|
|
||||||
VehicleEnter vehicleEnter = new VehicleEnter();
|
|
||||||
VehicleExit vehicleExit = new VehicleExit();
|
|
||||||
getServer().getPluginManager().registerEvents(playerChat, this);
|
|
||||||
getServer().getPluginManager().registerEvents(playerCommandPreprocess, this);
|
|
||||||
getServer().getPluginManager().registerEvents(enchantItemEvent, this);
|
|
||||||
getServer().getPluginManager().registerEvents(prepareItemEnchant, this);
|
|
||||||
getServer().getPluginManager().registerEvents(playerBedEnter, this);
|
|
||||||
getServer().getPluginManager().registerEvents(playerBedLeave, this);
|
|
||||||
getServer().getPluginManager().registerEvents(lightningStrike, this);
|
|
||||||
getServer().getPluginManager().registerEvents(thunderChange, this);
|
|
||||||
getServer().getPluginManager().registerEvents(weatherChange, this);
|
|
||||||
getServer().getPluginManager().registerEvents(worldInit, this);
|
|
||||||
getServer().getPluginManager().registerEvents(worldLoad, this);
|
|
||||||
getServer().getPluginManager().registerEvents(worldUnload, this);
|
|
||||||
getServer().getPluginManager().registerEvents(vehicleEnter, this);
|
|
||||||
getServer().getPluginManager().registerEvents(vehicleExit, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package cf.sobrooms.events.enchantment;
|
|
||||||
|
|
||||||
import cf.sobrooms.ServerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.enchantment.EnchantItemEvent;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class EnchantItem implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onEnchantItem(EnchantItemEvent event) {
|
|
||||||
Player player = event.getEnchanter();
|
|
||||||
Bukkit.getConsoleSender().sendMessage("Triggered EnchantItem event");
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("Enchant item").setDescription("A player has enchanted an item...")
|
|
||||||
.addField("Datetime", new Date().toString(), false)
|
|
||||||
.addField("Player name", player.getName(), true)
|
|
||||||
.addField("Enchantment", event.getEnchantsToAdd().toString(), true)
|
|
||||||
.addField("Item name", event.getItem().toString(), true)
|
|
||||||
.addField("Amount", String.valueOf(event.getItem().getAmount()), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
/*try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package cf.sobrooms.events.enchantment;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.ServerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class PrepareItemEnchant implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onPrepareItemEnchant(PrepareItemEnchantEvent event) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("Triggered PrepareItemEnchant event.");
|
|
||||||
Player player = event.getEnchanter();
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("Enchantment prepare").setDescription("A player is about to enchant an item...")
|
|
||||||
.addField("Date of preparation", new Date().toString(), false)
|
|
||||||
.addField("Player name", player.getName(), true)
|
|
||||||
.addField("Item to be enchanted", event.getItem().toString(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
/*try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package cf.sobrooms.events.player;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.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) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("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...")
|
|
||||||
.addField("Time", new Date().toString(), false)
|
|
||||||
.addField("Player name", player.getName(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package cf.sobrooms.events.player;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.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) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("Player left a bed");
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
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) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package cf.sobrooms.events.player;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("A message was sent by " + event.getPlayer().getName());
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("A message was sent by " + event.getPlayer().getName())
|
|
||||||
.addField("Date of message", new Date().toString(), false)
|
|
||||||
.addField("Message content", event.getMessage(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package cf.sobrooms.events.player;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.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;
|
|
||||||
|
|
||||||
public class PlayerCommandPreprocess implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("%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);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("Command used").setDescription("A player has used a command.")
|
|
||||||
.addField("Date of usage", new Date().toString(), false)
|
|
||||||
.addField("Player name", player.getName(), false)
|
|
||||||
.addField("Command", command[0], true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// temp: log on /stop
|
|
||||||
if (command[0].equals("/stop")) {
|
|
||||||
DiscordWebhook ntf = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()
|
|
||||||
.setTitle("Server stopped")
|
|
||||||
.setDescription("The server was stopped using the `/stop` command.")
|
|
||||||
.addField("Date", "<t:%n:R>".formatted(new Timestamp(System.currentTimeMillis()).getTime()), true)
|
|
||||||
.addField("Player name", player.getName(), true);
|
|
||||||
ntf.addEmbed(embed);
|
|
||||||
try {
|
|
||||||
ntf.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package cf.sobrooms.events.player;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.Main;
|
|
||||||
import cf.sobrooms.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) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("A player has joined the server.");
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("A player has joined the server.")
|
|
||||||
.addField("Date of join", new Date().toString(), false)
|
|
||||||
.addField("Player name", player.getName(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
Bukkit.broadcastMessage(Main.getGreetMessage(player));
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package cf.sobrooms.events.player;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.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) {
|
|
||||||
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);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package cf.sobrooms.events.server;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.Main;
|
|
||||||
import cf.sobrooms.ServerUtils;
|
|
||||||
import cf.sobrooms.Utils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.server.ServerLoadEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook.EmbedObject;
|
|
||||||
|
|
||||||
import static cf.sobrooms.ServerUtils.address;
|
|
||||||
|
|
||||||
public class ServerLoad implements Listener {
|
|
||||||
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())) {
|
|
||||||
System.out.println(ServerUtils.webhook_messages);
|
|
||||||
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()))
|
|
||||||
.addField("Date of start", new Date().toString(), false)
|
|
||||||
.setColor(Color.GREEN);
|
|
||||||
if (Main.getLoggingConfig().equals("false"))
|
|
||||||
embedObject.addField("Extra notes", "The server will not try to log any events.", false);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException 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 {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("(debug) server start event was called more than 1 time");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package cf.sobrooms.events.vehicle;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.ServerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class VehicleEnter implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicleEnter(VehicleEnterEvent event) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("%s rode a vehicle.".formatted(event.getEntered().getName()));
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("Vehicle Enter").setDescription("On a ridable animal")
|
|
||||||
.addField("Time", new Date().toString(), false)
|
|
||||||
.addField("Triggered by", event.getEntered().getName(), true)
|
|
||||||
.addField("Vehicle name", event.getVehicle().getName(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package cf.sobrooms.events.vehicle;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.ServerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class VehicleExit implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicleExit(VehicleExitEvent event) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("%s left a vehicle.".formatted(event.getExited().getName()));
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("Vehicle Exit").setDescription("Off a ridable animal")
|
|
||||||
.addField("Time", new Date().toString(), false)
|
|
||||||
.addField("Triggered by", event.getExited().getName(), true)
|
|
||||||
.addField("Vehicle name", event.getVehicle().getName(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package cf.sobrooms.events.weather;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.ServerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.weather.LightningStrikeEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class LightningStrike implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onLightningStrike(LightningStrikeEvent event) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("Triggered LightningStrike event.");
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("LightningStrike").setDescription("lightning striked")
|
|
||||||
.addField("Time", new Date().toString(), false)
|
|
||||||
.addField("World in which event was triggered in", event.getWorld().getName(), true)
|
|
||||||
.addField("Cause of strike", event.getCause().name(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
/*try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package cf.sobrooms.events.weather;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.ServerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.weather.ThunderChangeEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class ThunderChange implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onThunderChange(ThunderChangeEvent event) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("Triggered ThunderChange event.");
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("ThunderChange").setDescription("Tf is this")
|
|
||||||
.addField("Time", new Date().toString(), false)
|
|
||||||
.addField("Occurred in world", event.getWorld().getName(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
/*try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package cf.sobrooms.events.weather;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.ServerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class WeatherChange implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onWeatherChange(WeatherChangeEvent event) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("Triggered WeatherChange event.");
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("WeatherChange").setDescription("Weather was changed")
|
|
||||||
.addField("Time", new Date().toString(), false)
|
|
||||||
.addField("Occurred in world", event.getWorld().getName(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
/*try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package cf.sobrooms.events.world;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.ServerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.world.WorldInitEvent;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class WorldInit implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onWorldInit(WorldInitEvent event) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("Triggered WorldInit event.");
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("WorldInit").setDescription("World initialized")
|
|
||||||
.addField("Time", new Date().toString(), false)
|
|
||||||
.addField("World name", event.getWorld().getName(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package cf.sobrooms.events.world;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.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) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("Triggered WorldLoad event.");
|
|
||||||
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("WorldLoad").setDescription("World in server was loaded")
|
|
||||||
.addField("Time", new Date().toString(), false)
|
|
||||||
.addField("World name", event.getWorld().getName(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package cf.sobrooms.events.world;
|
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
|
||||||
import cf.sobrooms.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) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("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)
|
|
||||||
.addField("World name", event.getWorld().getName(), true)
|
|
||||||
.setColor(Color.BLUE);
|
|
||||||
notify.addEmbed(embedObject);
|
|
||||||
try {
|
|
||||||
notify.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+103
-99
@@ -1,10 +1,10 @@
|
|||||||
package cf.sobrooms;
|
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,106 +50,110 @@ public class DiscordWebhook {
|
|||||||
this.embeds.add(embed);
|
this.embeds.add(embed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute() throws IOException {
|
public void execute() throws Exception {
|
||||||
if (this.content == null && this.embeds.isEmpty()) {
|
try {
|
||||||
throw new IllegalArgumentException("Set content or add at least one EmbedObject");
|
if (this.content == null && this.embeds.isEmpty()) {
|
||||||
}
|
throw new IllegalArgumentException("Set content or add at least one EmbedObject");
|
||||||
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
|
|
||||||
json.put("content", this.content);
|
|
||||||
json.put("username", this.username);
|
|
||||||
json.put("avatar_url", this.avatarUrl);
|
|
||||||
json.put("tts", this.tts);
|
|
||||||
|
|
||||||
if (!this.embeds.isEmpty()) {
|
|
||||||
List<JSONObject> embedObjects = new ArrayList<>();
|
|
||||||
|
|
||||||
for (EmbedObject embed : this.embeds) {
|
|
||||||
JSONObject jsonEmbed = new JSONObject();
|
|
||||||
|
|
||||||
jsonEmbed.put("title", embed.getTitle());
|
|
||||||
jsonEmbed.put("description", embed.getDescription());
|
|
||||||
jsonEmbed.put("url", embed.getUrl());
|
|
||||||
|
|
||||||
if (embed.getColor() != null) {
|
|
||||||
Color color = embed.getColor();
|
|
||||||
int rgb = color.getRed();
|
|
||||||
rgb = (rgb << 8) + color.getGreen();
|
|
||||||
rgb = (rgb << 8) + color.getBlue();
|
|
||||||
|
|
||||||
jsonEmbed.put("color", rgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
EmbedObject.Footer footer = embed.getFooter();
|
|
||||||
EmbedObject.Image image = embed.getImage();
|
|
||||||
EmbedObject.Thumbnail thumbnail = embed.getThumbnail();
|
|
||||||
EmbedObject.Author author = embed.getAuthor();
|
|
||||||
List<EmbedObject.Field> fields = embed.getFields();
|
|
||||||
|
|
||||||
if (footer != null) {
|
|
||||||
JSONObject jsonFooter = new JSONObject();
|
|
||||||
|
|
||||||
jsonFooter.put("text", footer.getText());
|
|
||||||
jsonFooter.put("icon_url", footer.getIconUrl());
|
|
||||||
jsonEmbed.put("footer", jsonFooter);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (image != null) {
|
|
||||||
JSONObject jsonImage = new JSONObject();
|
|
||||||
|
|
||||||
jsonImage.put("url", image.getUrl());
|
|
||||||
jsonEmbed.put("image", jsonImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (thumbnail != null) {
|
|
||||||
JSONObject jsonThumbnail = new JSONObject();
|
|
||||||
|
|
||||||
jsonThumbnail.put("url", thumbnail.getUrl());
|
|
||||||
jsonEmbed.put("thumbnail", jsonThumbnail);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (author != null) {
|
|
||||||
JSONObject jsonAuthor = new JSONObject();
|
|
||||||
|
|
||||||
jsonAuthor.put("name", author.getName());
|
|
||||||
jsonAuthor.put("url", author.getUrl());
|
|
||||||
jsonAuthor.put("icon_url", author.getIconUrl());
|
|
||||||
jsonEmbed.put("author", jsonAuthor);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<JSONObject> jsonFields = new ArrayList<>();
|
|
||||||
for (EmbedObject.Field field : fields) {
|
|
||||||
JSONObject jsonField = new JSONObject();
|
|
||||||
|
|
||||||
jsonField.put("name", field.getName());
|
|
||||||
jsonField.put("value", field.getValue());
|
|
||||||
jsonField.put("inline", field.isInline());
|
|
||||||
|
|
||||||
jsonFields.add(jsonField);
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonEmbed.put("fields", jsonFields.toArray());
|
|
||||||
embedObjects.add(jsonEmbed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json.put("embeds", embedObjects.toArray());
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
|
json.put("content", this.content);
|
||||||
|
json.put("username", this.username);
|
||||||
|
json.put("avatar_url", this.avatarUrl);
|
||||||
|
json.put("tts", this.tts);
|
||||||
|
|
||||||
|
if (!this.embeds.isEmpty()) {
|
||||||
|
List<JSONObject> embedObjects = new ArrayList<>();
|
||||||
|
|
||||||
|
for (EmbedObject embed : this.embeds) {
|
||||||
|
JSONObject jsonEmbed = new JSONObject();
|
||||||
|
|
||||||
|
jsonEmbed.put("title", embed.getTitle());
|
||||||
|
jsonEmbed.put("description", embed.getDescription());
|
||||||
|
jsonEmbed.put("url", embed.getUrl());
|
||||||
|
|
||||||
|
if (embed.getColor() != null) {
|
||||||
|
Color color = embed.getColor();
|
||||||
|
int rgb = color.getRed();
|
||||||
|
rgb = (rgb << 8) + color.getGreen();
|
||||||
|
rgb = (rgb << 8) + color.getBlue();
|
||||||
|
|
||||||
|
jsonEmbed.put("color", rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
EmbedObject.Footer footer = embed.getFooter();
|
||||||
|
EmbedObject.Image image = embed.getImage();
|
||||||
|
EmbedObject.Thumbnail thumbnail = embed.getThumbnail();
|
||||||
|
EmbedObject.Author author = embed.getAuthor();
|
||||||
|
List<EmbedObject.Field> fields = embed.getFields();
|
||||||
|
|
||||||
|
if (footer != null) {
|
||||||
|
JSONObject jsonFooter = new JSONObject();
|
||||||
|
|
||||||
|
jsonFooter.put("text", footer.getText());
|
||||||
|
jsonFooter.put("icon_url", footer.getIconUrl());
|
||||||
|
jsonEmbed.put("footer", jsonFooter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (image != null) {
|
||||||
|
JSONObject jsonImage = new JSONObject();
|
||||||
|
|
||||||
|
jsonImage.put("url", image.getUrl());
|
||||||
|
jsonEmbed.put("image", jsonImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thumbnail != null) {
|
||||||
|
JSONObject jsonThumbnail = new JSONObject();
|
||||||
|
|
||||||
|
jsonThumbnail.put("url", thumbnail.getUrl());
|
||||||
|
jsonEmbed.put("thumbnail", jsonThumbnail);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (author != null) {
|
||||||
|
JSONObject jsonAuthor = new JSONObject();
|
||||||
|
|
||||||
|
jsonAuthor.put("name", author.getName());
|
||||||
|
jsonAuthor.put("url", author.getUrl());
|
||||||
|
jsonAuthor.put("icon_url", author.getIconUrl());
|
||||||
|
jsonEmbed.put("author", jsonAuthor);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<JSONObject> jsonFields = new ArrayList<>();
|
||||||
|
for (EmbedObject.Field field : fields) {
|
||||||
|
JSONObject jsonField = new JSONObject();
|
||||||
|
|
||||||
|
jsonField.put("name", field.getName());
|
||||||
|
jsonField.put("value", field.getValue());
|
||||||
|
jsonField.put("inline", field.isInline());
|
||||||
|
|
||||||
|
jsonFields.add(jsonField);
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonEmbed.put("fields", jsonFields.toArray());
|
||||||
|
embedObjects.add(jsonEmbed);
|
||||||
|
}
|
||||||
|
|
||||||
|
json.put("embeds", embedObjects.toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
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_");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
|
||||||
|
OutputStream stream = connection.getOutputStream();
|
||||||
|
stream.write(json.toString().getBytes());
|
||||||
|
stream.flush();
|
||||||
|
stream.close();
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
URL url = new URL(this.url);
|
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
||||||
connection.addRequestProperty("Content-Type", "application/json");
|
|
||||||
connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_");
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
|
|
||||||
OutputStream stream = connection.getOutputStream();
|
|
||||||
stream.write(json.toString().getBytes());
|
|
||||||
stream.flush();
|
|
||||||
stream.close();
|
|
||||||
|
|
||||||
connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream
|
|
||||||
connection.disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EmbedObject {
|
public static class EmbedObject {
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
package moe.sob;
|
||||||
|
|
||||||
|
import moe.sob.commands.InfoCommand;
|
||||||
|
import moe.sob.commands.PingCommand;
|
||||||
|
import moe.sob.commands.SendMessageCommand;
|
||||||
|
import moe.sob.commands.SetLoggingModeCommand;
|
||||||
|
import moe.sob.commands.SetGreetMessageCommand;
|
||||||
|
import moe.sob.events.player.*;
|
||||||
|
import moe.sob.events.server.ServerLoad;
|
||||||
|
import moe.sob.events.world.WorldLoad;
|
||||||
|
import moe.sob.events.world.WorldUnload;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
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.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Main extends JavaPlugin {
|
||||||
|
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) {
|
||||||
|
mainSmall.getLogger().info(String.format("Initializing using server address: %s...%n", ServerUtils.address));
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
if (Main.webhooksAreValidUrls) {
|
||||||
|
DiscordWebhook notify = new DiscordWebhook(Main.getNotifyWebhook());
|
||||||
|
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("The server has been disabled.").setDescription(String.format("The server at %s:%d is now shutting down.", Utils.getServerHostPublicIP(), Bukkit.getServer().getPort()))
|
||||||
|
.addField("Date occurred (as a local timestamp)", new Date().toString(), false)
|
||||||
|
.setColor(Color.DARK_GRAY);
|
||||||
|
notify.addEmbed(embedObject);
|
||||||
|
try {
|
||||||
|
notify.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
mainSmall = this;
|
||||||
|
config = new File(getDataFolder(), "config.yml");
|
||||||
|
/*if (!config.exists()) {
|
||||||
|
saveResource("config.yml", false);
|
||||||
|
}*/
|
||||||
|
configR = getConfig();
|
||||||
|
configR = YamlConfiguration.loadConfiguration(config);
|
||||||
|
if (!configR.contains("firstrun")) {
|
||||||
|
configR.set("server.name", "Minecraft Server");
|
||||||
|
configR.set("server.entry_message", "Welcome to @servername, @playername!");
|
||||||
|
configR.set("server.webhooks.notify", "default-ns");
|
||||||
|
configR.set("server.webhooks.broadcast", "default-ns");
|
||||||
|
|
||||||
|
configR.set("log", true);
|
||||||
|
configR.set("firstrun", 0);
|
||||||
|
|
||||||
|
try {
|
||||||
|
configR.save(config);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// such cap
|
||||||
|
//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());
|
||||||
|
Objects.requireNonNull(this.getCommand("send-message")).setExecutor(new SendMessageCommand());
|
||||||
|
Objects.requireNonNull(this.getCommand("set-logging")).setExecutor(new SetLoggingModeCommand());
|
||||||
|
Objects.requireNonNull(this.getCommand("ping-server")).setExecutor(new PingCommand());
|
||||||
|
Objects.requireNonNull(this.getCommand("set-greet-message")).setExecutor(new SetGreetMessageCommand());
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
webhooksAreValidUrls = validateWebhook_Ntfy();
|
||||||
|
hdc = validateWebhook_Pub();
|
||||||
|
// register events
|
||||||
|
if (webhooksAreValidUrls)
|
||||||
|
registerEvents();
|
||||||
|
if (webhooksAreValidUrls) {
|
||||||
|
ServerLoad serverStart = new ServerLoad();
|
||||||
|
getServer().getPluginManager().registerEvents(serverStart, this);
|
||||||
|
PlayerJoin playerJoin = new PlayerJoin();
|
||||||
|
PlayerQuit playerQuit = new PlayerQuit();
|
||||||
|
getServer().getPluginManager().registerEvents(playerJoin, this);
|
||||||
|
getServer().getPluginManager().registerEvents(playerQuit, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean validateWebhook_Pub() {
|
||||||
|
try {
|
||||||
|
if (getPublicMessageWebhook().equals("default-ns")) {
|
||||||
|
mainSmall.getLogger().warning("There is no webhook set for the public messages function. The send-message command cannot be used.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
URL url = new URI(getPublicMessageWebhook()).toURL();
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
mainSmall.getLogger().warning("Invalid webhook URL provided for your public messages. Please provide the correct webhook and check for any typos.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (Exception 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean validateWebhook_Ntfy() {
|
||||||
|
try {
|
||||||
|
if (getNotifyWebhook().equals("default-ns")) {
|
||||||
|
mainSmall.getLogger().warning("There is no webhook set for the notify function. No events will be logged.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
URL url = new URI(getNotifyWebhook()).toURL();
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
mainSmall.getLogger().warning("Invalid webhook URL provided for the event logs. Please provide the correct webhook and check for any typos.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static String getPublicMessageWebhook() {
|
||||||
|
String webhook = configR.getString("server.webhooks.broadcast");
|
||||||
|
if (webhook.startsWith("https://") || webhook.startsWith("http://")) {
|
||||||
|
webhooksAreValidUrls = true;
|
||||||
|
return webhook;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "default-ns";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getServerName() {
|
||||||
|
return configR.getString("server.name");
|
||||||
|
}
|
||||||
|
public static String getGreetMessage(Player player) {
|
||||||
|
try {
|
||||||
|
String entryMessage = configR.getString("server.entry_message");
|
||||||
|
String serverName = getServerName();
|
||||||
|
String playername = player.getName();
|
||||||
|
String finalOut = "";
|
||||||
|
finalOut = entryMessage.replaceAll("@servername", serverName).replaceAll("@playername", playername);
|
||||||
|
|
||||||
|
return finalOut;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getNotifyWebhook() {
|
||||||
|
String webhook = configR.getString("server.webhooks.notify");
|
||||||
|
if (webhook.startsWith("https://") || webhook.startsWith("http://")) {
|
||||||
|
webhooksAreValidUrls = true;
|
||||||
|
return webhook;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "default-ns";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerEvents() {
|
||||||
|
PlayerChat playerChat = new PlayerChat();
|
||||||
|
//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(worldLoad, this);
|
||||||
|
getServer().getPluginManager().registerEvents(worldUnload, this);
|
||||||
|
getServer().getPluginManager().registerEvents(playerDeath, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cf.sobrooms;
|
package moe.sob;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@@ -8,10 +8,10 @@ import java.net.Socket;
|
|||||||
|
|
||||||
public class ServerUtils {
|
public class ServerUtils {
|
||||||
public static int port = 25565;
|
public static int port = 25565;
|
||||||
public static String address_fallback = Utils.getServerHostPublicIP();
|
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;
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cf.sobrooms;
|
package moe.sob;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
package cf.sobrooms.commands;
|
package moe.sob.commands;
|
||||||
|
|
||||||
|
|
||||||
import cf.sobrooms.Main;
|
import moe.sob.Main;
|
||||||
import cf.sobrooms.Utils;
|
import moe.sob.Utils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@@ -17,7 +17,7 @@ public class InfoCommand implements CommandExecutor {
|
|||||||
Server Info
|
Server Info
|
||||||
|
|
||||||
""" + ChatColor.WHITE +
|
""" + ChatColor.WHITE +
|
||||||
"""
|
"""
|
||||||
Server name: %s
|
Server name: %s
|
||||||
Server IP: %s
|
Server IP: %s
|
||||||
Server Port: %s
|
Server Port: %s
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
package cf.sobrooms.commands;
|
package moe.sob.commands;
|
||||||
|
|
||||||
import cf.sobrooms.Utils;
|
import moe.sob.Utils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
+6
-16
@@ -1,16 +1,12 @@
|
|||||||
package cf.sobrooms.commands;
|
package moe.sob.commands;
|
||||||
|
|
||||||
import cf.sobrooms.DiscordWebhook;
|
import moe.sob.DiscordWebhook;
|
||||||
import cf.sobrooms.Main;
|
import moe.sob.Main;
|
||||||
import cf.sobrooms.ServerUtils;
|
import moe.sob.ServerUtils;
|
||||||
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;
|
||||||
|
|
||||||
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) {
|
||||||
@@ -23,18 +19,12 @@ public class SendMessageCommand implements CommandExecutor {
|
|||||||
DiscordWebhook discordWebhook = new DiscordWebhook(ServerUtils.webhook_messages);
|
DiscordWebhook discordWebhook = new DiscordWebhook(ServerUtils.webhook_messages);
|
||||||
discordWebhook.setUsername("Public Messages");
|
discordWebhook.setUsername("Public Messages");
|
||||||
String message = String.join(" ", args);
|
String message = String.join(" ", args);
|
||||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject()
|
discordWebhook.setContent(String.format("**%s**: %s", sender.getName(), message));
|
||||||
.setTitle("New public message")
|
|
||||||
.setDescription(message)
|
|
||||||
.setAuthor(sender.getName(), "", "")
|
|
||||||
.setFooter(new Date().toString(), "")
|
|
||||||
.setColor(Color.darkGray);
|
|
||||||
discordWebhook.addEmbed(embedObject);
|
|
||||||
try {
|
try {
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package moe.sob.commands;
|
||||||
|
|
||||||
|
import moe.sob.Main;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class SetGreetMessageCommand implements CommandExecutor {
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args[0].isBlank()) {
|
||||||
|
sender.sendMessage("Insufficient arguments.");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
String greetMessage = String.join(" ", args);
|
||||||
|
Main.configR.set("server.entry_message", greetMessage);
|
||||||
|
Main.configR.save(Main.config);
|
||||||
|
|
||||||
|
sender.sendMessage("Changed greet message successfully.");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-15
@@ -1,15 +1,11 @@
|
|||||||
package cf.sobrooms.commands;
|
package moe.sob.commands;
|
||||||
|
|
||||||
import cf.sobrooms.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;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class SetLoggingModeCommand implements CommandExecutor {
|
public class SetLoggingModeCommand implements CommandExecutor {
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (args[0].isBlank()) {
|
if (args[0].isBlank()) {
|
||||||
@@ -18,20 +14,16 @@ public class SetLoggingModeCommand implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
if (args[0].equals("true") || args[0].equals("false")) {
|
if (args[0].equals("true") || args[0].equals("false")) {
|
||||||
try {
|
try {
|
||||||
|
Main.configR.set("log", args[0].equals("true"));
|
||||||
FileWriter writer = new FileWriter(Main.isLoggingConfig);
|
Main.configR.save(Main.config);
|
||||||
writer.write(args[0]);
|
|
||||||
writer.close();
|
|
||||||
System.out.println("Wrote to config, closing writer...");
|
|
||||||
sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Changes will only apply once the server has restarted.");
|
|
||||||
String status = "";
|
String status = "";
|
||||||
if (args[0].equals("true"))
|
if (args[0].equals("true"))
|
||||||
status = "enabled";
|
status = "enabled";
|
||||||
else if (args[0].equals("false"))
|
else if (args[0].equals("false"))
|
||||||
status = "disabled";
|
status = "disabled";
|
||||||
Bukkit.broadcastMessage(ChatColor.ITALIC + "%s %s server logging.".formatted(sender.getName(), status));
|
sender.sendMessage(ChatColor.ITALIC + "%s %s server logging.".formatted(sender.getName(), status));
|
||||||
Bukkit.broadcastMessage(ChatColor.ITALIC + "Changes will only apply once the server has restarted.");
|
sender.sendMessage(ChatColor.ITALIC + "Changes will only apply once the server has restarted.");
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package moe.sob.events.player;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook;
|
||||||
|
import moe.sob.Main;
|
||||||
|
import moe.sob.ServerUtils;
|
||||||
|
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.util.Date;
|
||||||
|
|
||||||
|
public class PlayerBedEnter implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
||||||
|
if (Main.configR.getBoolean("log")) {
|
||||||
|
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...")
|
||||||
|
.addField("Time", new Date().toString(), false)
|
||||||
|
.addField("Player name", player.getName(), true)
|
||||||
|
.setColor(Color.BLUE);
|
||||||
|
notify.addEmbed(embedObject);
|
||||||
|
try {
|
||||||
|
notify.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package moe.sob.events.player;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook;
|
||||||
|
import moe.sob.Main;
|
||||||
|
import moe.sob.ServerUtils;
|
||||||
|
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.util.Date;
|
||||||
|
|
||||||
|
public class PlayerBedLeave implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
|
||||||
|
if (Main.configR.getBoolean("log")) {
|
||||||
|
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.")
|
||||||
|
.addField("Time", new Date().toString(), false)
|
||||||
|
.addField("Player name", player.getName(), true)
|
||||||
|
.setColor(Color.BLUE);
|
||||||
|
notify.addEmbed(embedObject);
|
||||||
|
try {
|
||||||
|
notify.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package moe.sob.events.player;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook;
|
||||||
|
import moe.sob.Main;
|
||||||
|
import moe.sob.ServerUtils;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
|
||||||
|
public class PlayerChat implements Listener {
|
||||||
|
public PlayerChat() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@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")) {
|
||||||
|
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
||||||
|
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 (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package moe.sob.events.player;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook;
|
||||||
|
import moe.sob.Main;
|
||||||
|
import moe.sob.ServerUtils;
|
||||||
|
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.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class PlayerCommandPreprocess implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||||
|
if (Main.configR.getBoolean("log")) {
|
||||||
|
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);
|
||||||
|
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("Command used")
|
||||||
|
.addField("Date of usage", new Date().toString(), false)
|
||||||
|
.addField("Player name", player.getName(), false)
|
||||||
|
.addField("Command", command[0], true)
|
||||||
|
.setColor(Color.BLUE);
|
||||||
|
notify.addEmbed(embedObject);
|
||||||
|
try {
|
||||||
|
notify.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// temp: log on /stop
|
||||||
|
if (command[0].equals("/stop")) {
|
||||||
|
DiscordWebhook ntf = new DiscordWebhook(ServerUtils.webhook_notify);
|
||||||
|
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()
|
||||||
|
.setTitle("Server stopped")
|
||||||
|
.setDescription("The server was stopped using the `/stop` command.")
|
||||||
|
.addField("Date", "<t:%n:R>".formatted(new Timestamp(System.currentTimeMillis()).getTime()), true)
|
||||||
|
.addField("Player name", player.getName(), true);
|
||||||
|
ntf.addEmbed(embed);
|
||||||
|
try {
|
||||||
|
ntf.execute();
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package moe.sob.events.player;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook;
|
||||||
|
import moe.sob.Main;
|
||||||
|
import moe.sob.ServerUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
public class PlayerJoin implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
if (Main.configR.getBoolean("log")) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
event.setJoinMessage(Main.getGreetMessage(player));
|
||||||
|
|
||||||
|
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
||||||
|
notify.setUsername(player.getName());
|
||||||
|
notify.setContent(String.format("**%s** joined the server.", player.getName()));
|
||||||
|
try {
|
||||||
|
notify.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package moe.sob.events.player;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook;
|
||||||
|
import moe.sob.Main;
|
||||||
|
import moe.sob.ServerUtils;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
public class PlayerQuit implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
if (Main.configR.getBoolean("log")) {
|
||||||
|
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
||||||
|
notify.setUsername(event.getPlayer().getName());
|
||||||
|
notify.setContent(String.format("**%s** left the server.", event.getPlayer().getName()));
|
||||||
|
try {
|
||||||
|
notify.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package moe.sob.events.server;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook;
|
||||||
|
import moe.sob.Main;
|
||||||
|
import moe.sob.Utils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.server.ServerLoadEvent;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook.EmbedObject;
|
||||||
|
|
||||||
|
|
||||||
|
public class ServerLoad implements Listener {
|
||||||
|
//public static int timesCalled = 0;
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerStart(ServerLoadEvent event) {
|
||||||
|
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()))
|
||||||
|
.addField("Date of start", new Date().toString(), false)
|
||||||
|
.setColor(Color.GREEN);
|
||||||
|
if (!Main.configR.getBoolean("log"))
|
||||||
|
embedObject.addField("Extra notes", "The server will not try to log any events.", false);
|
||||||
|
notify.addEmbed(embedObject);
|
||||||
|
try {
|
||||||
|
notify.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* } 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");
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package moe.sob.events.world;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook;
|
||||||
|
import moe.sob.Main;
|
||||||
|
import moe.sob.ServerUtils;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class WorldLoad implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onWorldLoad(WorldLoadEvent event) {
|
||||||
|
if (Main.configR.getBoolean("log")) {
|
||||||
|
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)
|
||||||
|
.addField("World name", event.getWorld().getName(), true)
|
||||||
|
.setColor(Color.BLUE);
|
||||||
|
notify.addEmbed(embedObject);
|
||||||
|
try {
|
||||||
|
notify.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package moe.sob.events.world;
|
||||||
|
|
||||||
|
import moe.sob.DiscordWebhook;
|
||||||
|
import moe.sob.Main;
|
||||||
|
import moe.sob.ServerUtils;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.world.WorldUnloadEvent;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class WorldUnload implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onWorldUnload(WorldUnloadEvent event) {
|
||||||
|
if (Main.configR.getBoolean("log")) {
|
||||||
|
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)
|
||||||
|
.addField("World name", event.getWorld().getName(), true)
|
||||||
|
.setColor(Color.BLUE);
|
||||||
|
notify.addEmbed(embedObject);
|
||||||
|
try {
|
||||||
|
notify.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
main: cf.sobrooms.Main
|
main: moe.sob.Main
|
||||||
version: 1.1.4
|
version: 1.3.0
|
||||||
name: notifyOnStart
|
name: notifyOnStart
|
||||||
description: Sends webhook_notify to sobrooms when the server starts successfully
|
description: A logging plugin.
|
||||||
api-version: 1.19
|
api-version: 1.19
|
||||||
authors: [rrryfoo, sobrooms]
|
authors: [rrryfoo, sobrooms]
|
||||||
commands:
|
commands:
|
||||||
@@ -10,15 +10,22 @@ commands:
|
|||||||
usage: /info
|
usage: /info
|
||||||
aliases: [i]
|
aliases: [i]
|
||||||
send-message:
|
send-message:
|
||||||
description: Sends a message to the Discord server. (If any was set)
|
description: Broadcast text onto this server's Discord server.
|
||||||
usage: /send-message <message content>
|
usage: /send-message <message>
|
||||||
aliases: [sms]
|
aliases: [sms]
|
||||||
set-logging:
|
set-logging:
|
||||||
description: Enables or disables event logging in the server, performance and events can occur faster with this off. (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 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:
|
||||||
|
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]
|
||||||
Reference in New Issue
Block a user