diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0bd8d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# ---> Java +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# IntelliJ IDEA +*.iml +.idea/ + +# Maven +target/ +dependency-reduced-pom.xml + +# Gradle +!gradle-wrapper.jar +.gradle/ +build/ +*/build/ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..71c8dfc --- /dev/null +++ b/build.gradle @@ -0,0 +1,73 @@ +buildscript { + repositories { + mavenCentral() + maven { url "https://plugins.gradle.org/m2/" } + jcenter() + } + dependencies { + classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: kotlin_version + classpath group: 'gradle.plugin.net.minecrell', name: 'licenser', version: minecrell_licenser_version + } +} + +apply plugin: 'java' +apply plugin: 'kotlin' +apply plugin: 'net.minecrell.licenser' + +group = pluginGroup +version = pluginVersion + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +repositories { + mavenLocal() + mavenCentral() + maven { + name = 'destroystokyo-repo' + url = 'https://repo.destroystokyo.com/repository/maven-public/' + } + + maven { + name = 'sonatype' + url = 'https://oss.sonatype.org/content/groups/public/' + } + + maven { + name = 'mikroskeem-repo' + url = 'https://repo.wut.ee/repository/mikroskeem-repo' + } +} + +// Plugin/mod dependencies +dependencies { + compileOnly group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jre8', version: kotlin_version + compileOnly group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.12-R0.1-SNAPSHOT' + compileOnly group: 'com.destroystokyo.paper', name: 'paper', version: '1.12-R0.1-SNAPSHOT' + compileOnly group: 'eu.mikroskeem', name: 'orion.api', version: '0.0.1' +} + + +// Plugin resource processing +processResources { + from(sourceSets.main.resources.srcDirs) { + filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [ + version: pluginVersion, + description: description, + website: website + ] + } +} + +// Licenser task +license { + header = rootProject.file('etc/HEADER') + ignoreFailures = false + include "**/*.java" +} + +// Wrapper task +task wrapper(type: Wrapper) { + gradleVersion = gradle_version + distributionUrl = "https://services.gradle.org/distributions/gradle-$gradle_version-all.zip" +} diff --git a/etc/HEADER b/etc/HEADER new file mode 100644 index 0000000..a582f59 --- /dev/null +++ b/etc/HEADER @@ -0,0 +1,22 @@ +This file is part of project Helios, licensed under the MIT License (MIT). + +Copyright (c) 2017 Mark Vainomaa +Copyright (c) Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..036eec0 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,10 @@ +# Plugin/mod information +pluginGroup=eu.mikroskeem +pluginVersion=0.0.1-SNAPSHOT +description=Helios Mod API for Paper +website=https://github.com/OrionMinecraft/Helios + +# Gradle & its plugins +gradle_version=4.0 +kotlin_version=1.1.3-2 +minecrell_licenser_version=0.3 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..a185284 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..eb349b8 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jul 14 20:27:38 EEST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/eu/mikroskeem/helios/api/entity/Player.java b/src/main/java/eu/mikroskeem/helios/api/entity/Player.java new file mode 100644 index 0000000..81b33e7 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/entity/Player.java @@ -0,0 +1,48 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.api.entity; + +/** + * Helios Player + * + * @author Mark Vainomaa + */ +public interface Player extends org.bukkit.entity.Player { + /** + * Gets the last time when player was active + * + * @return Seconds from Unix epoch + */ + long getLastActiveTime(); + + /** + * Shows if player is away or not, value is set by comparing + * value in {@link Configuration.PlayerConfiguration#getMillisecondsUntilToMarkPlayerAway()} + * + * @return Whether player is away or not + */ + boolean isAway(); +} diff --git a/src/main/java/eu/mikroskeem/helios/api/events/package-info.java b/src/main/java/eu/mikroskeem/helios/api/events/package-info.java new file mode 100644 index 0000000..028177e --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/events/package-info.java @@ -0,0 +1,29 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * @author Mark Vainomaa + */ +package eu.mikroskeem.helios.api.events; \ No newline at end of file diff --git a/src/main/java/eu/mikroskeem/helios/api/events/player/chat/PlayerPluginSendMessageEvent.java b/src/main/java/eu/mikroskeem/helios/api/events/player/chat/PlayerPluginSendMessageEvent.java new file mode 100644 index 0000000..2d1400f --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/events/player/chat/PlayerPluginSendMessageEvent.java @@ -0,0 +1,91 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.api.events.player.chat; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +/** + * This event gets fired when ${@link Player#sendMessage(String)} and friends is invoked + * + * @author Mark Vainomaa + */ +public final class PlayerPluginSendMessageEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + + private boolean cancelled = false; + private String message; + + /** + * Constructs {@link PlayerPluginSendMessageEvent} + * + * @param player Player who'll receive the message + * @param message Message + */ + public PlayerPluginSendMessageEvent(Player player, String message) { + super(player); + this.message = message; + } + + /** + * Gets message what player will receive + * + * @return Message + */ + public String getMessage() { + return message; + } + + /** + * Sets message what player will receive + * + * @param message Message + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isCancelled() { + return cancelled; + } + + /** + * {@inheritDoc} + */ + @Override + public void setCancelled(boolean value) { + cancelled = value; + } + + public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } +} diff --git a/src/main/java/eu/mikroskeem/helios/api/events/player/idle/PlayerActiveEvent.java b/src/main/java/eu/mikroskeem/helios/api/events/player/idle/PlayerActiveEvent.java new file mode 100644 index 0000000..5ea2058 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/events/player/idle/PlayerActiveEvent.java @@ -0,0 +1,65 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.api.events.player.idle; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + + +/** + * This event gets fired when player comes back from idle + * + * @author Mark Vainomaa + */ +public final class PlayerActiveEvent extends PlayerEvent { + private static final HandlerList handlers = new HandlerList(); + + private final long timestamp; + + /** + * Constructs {@link PlayerActiveEvent} + * + * @param player Player who was marked active + * @param timestamp Timestamp when player was marked active + */ + public PlayerActiveEvent(Player player, long timestamp) { + super(player); + this.timestamp = timestamp; + } + + /** + * Gets timestamp of time when player was marked active + * + * @return Seconds from Unix time epoch + */ + public long getTimestamp() { + return timestamp; + } + + public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } +} diff --git a/src/main/java/eu/mikroskeem/helios/api/events/player/idle/PlayerIdleEvent.java b/src/main/java/eu/mikroskeem/helios/api/events/player/idle/PlayerIdleEvent.java new file mode 100644 index 0000000..290955c --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/events/player/idle/PlayerIdleEvent.java @@ -0,0 +1,65 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.api.events.player.idle; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + + +/** + * This event gets fired when player goes idle + * + * @author Mark Vainomaa + */ +public final class PlayerIdleEvent extends PlayerEvent { + private static final HandlerList handlers = new HandlerList(); + + private final long timestamp; + + /** + * Constructs {@link PlayerIdleEvent} + * + * @param player Player who was marked idle + * @param timestamp Timestamp when player was marked idle + */ + public PlayerIdleEvent(Player player, long timestamp) { + super(player); + this.timestamp = timestamp; + } + + /** + * Gets timestamp of time when player was marked idle + * + * @return Seconds from Unix time epoch + */ + public long getTimestamp() { + return timestamp; + } + + public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } +} diff --git a/src/main/java/eu/mikroskeem/helios/api/events/player/package-info.java b/src/main/java/eu/mikroskeem/helios/api/events/player/package-info.java new file mode 100644 index 0000000..80806c3 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/events/player/package-info.java @@ -0,0 +1,29 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * @author Mark Vainomaa + */ +package eu.mikroskeem.helios.api.events.player; \ No newline at end of file diff --git a/src/main/java/eu/mikroskeem/helios/api/events/server/ServerStartedEvent.java b/src/main/java/eu/mikroskeem/helios/api/events/server/ServerStartedEvent.java new file mode 100644 index 0000000..f752576 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/events/server/ServerStartedEvent.java @@ -0,0 +1,43 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.api.events.server; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + + +/** + * This event gets fired when server is fully initialized + * + * @author Mark Vainomaa + */ +public final class ServerStartedEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + + public ServerStartedEvent() { super(); } + public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } +} diff --git a/src/main/java/eu/mikroskeem/helios/api/events/server/ServerStoppingEvent.java b/src/main/java/eu/mikroskeem/helios/api/events/server/ServerStoppingEvent.java new file mode 100644 index 0000000..be6cf59 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/events/server/ServerStoppingEvent.java @@ -0,0 +1,43 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.api.events.server; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + + +/** + * This event gets fired when server is stopping + * + * @author Mark Vainomaa + */ +public final class ServerStoppingEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + + public ServerStoppingEvent() { super(); } + public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } +} diff --git a/src/main/java/eu/mikroskeem/helios/api/inventory/HeliosItemStack.java b/src/main/java/eu/mikroskeem/helios/api/inventory/HeliosItemStack.java new file mode 100644 index 0000000..72935bb --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/inventory/HeliosItemStack.java @@ -0,0 +1,68 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.api.inventory; + +import org.bukkit.Material; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + + +/** + * Missing & extra ItemStack methods + * + * @author Mark Vainomaa + */ +public interface HeliosItemStack { + /** + * Sets list of material what given tool can break + * + * @param materials List of materials. Use null to clear + */ + void setCanDestroy(@Nullable Collection materials); + + /** + * Gets list of material what given tool can break + * + * @return List of materials + */ + @NotNull Collection getCanDestroy(); + + /** + * Sets list of material where given block can be placed + * + * @param materials List of materials. Use null to clear + */ + void setCanPlaceOn(@Nullable Collection materials); + + /** + * Gets list of material where given block can be placed + * + * @return List of materials + */ + @NotNull Collection getCanPlaceOn(); +} diff --git a/src/main/java/eu/mikroskeem/helios/api/package-info.java b/src/main/java/eu/mikroskeem/helios/api/package-info.java new file mode 100644 index 0000000..99c04fb --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/package-info.java @@ -0,0 +1,29 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * @author Mark Vainomaa + */ +package eu.mikroskeem.helios.api; \ No newline at end of file diff --git a/src/main/java/eu/mikroskeem/helios/api/plugin/HeliosPluginManager.java b/src/main/java/eu/mikroskeem/helios/api/plugin/HeliosPluginManager.java new file mode 100644 index 0000000..abd899e --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/plugin/HeliosPluginManager.java @@ -0,0 +1,45 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.api.plugin; + +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.jetbrains.annotations.NotNull; + + +/** + * Plugin manager with extra functionality + * + * @author Mark Vainomaa + */ +public interface HeliosPluginManager extends PluginManager { + /** + * Unloads {@link Plugin} + * + * @param plugin Plugin to unload + */ + void unloadPlugin(@NotNull Plugin plugin); +} diff --git a/src/main/java/eu/mikroskeem/helios/api/world/World.java b/src/main/java/eu/mikroskeem/helios/api/world/World.java new file mode 100644 index 0000000..94c4907 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/api/world/World.java @@ -0,0 +1,68 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.api.world; + +import org.bukkit.Location; + + +/** + * Helios World wrapper + * + * @author Mark Vainomaa + */ +public interface World extends org.bukkit.World { + /** + * {@inheritDoc} + * @deprecated Use {@link World#setSpawnLocation(Location)} or + * {@link World#setSpawnLocation(double, double, double, float, float)} + */ + @Override + @Deprecated + boolean setSpawnLocation(int x, int y, int z); + + /** + * Set world spawn location + * + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @param yaw Yaw + * @param pitch Pitch + * @return True, if spawn location was successfully set + */ + default boolean setSpawnLocation(double x, double y, double z, float yaw, float pitch) { + return setSpawnLocation(new Location(null, x, y, z, yaw, pitch)); + } + + /** + * Set world spawn location + * + * @param location Location object + * @return True, if spawn location was successfully set + * @see org.bukkit.World + */ + boolean setSpawnLocation(Location location); +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/HeliosMod.java b/src/main/java/eu/mikroskeem/helios/mod/HeliosMod.java new file mode 100644 index 0000000..efb9040 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/HeliosMod.java @@ -0,0 +1,107 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod; + +import com.google.common.eventbus.Subscribe; +import eu.mikroskeem.helios.mod.configuration.Configuration; +import eu.mikroskeem.orion.api.Orion; +import eu.mikroskeem.orion.api.annotations.OrionMod; +import eu.mikroskeem.orion.api.events.ModConstructEvent; +import eu.mikroskeem.orion.api.events.ModLoadEvent; +import eu.mikroskeem.shuriken.common.SneakyThrow; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import org.apache.logging.log4j.Logger; + +import javax.inject.Inject; + + +/** + * The Helios Mod + * + * @author Mark Vainomaa + */ +@OrionMod(id = "helios") +public final class HeliosMod { + public static HeliosMod INSTANCE; + + @Inject public Logger logger; + @Inject private Orion orion; + @Inject private ConfigurationLoader configurationLoader; + private Configuration configuration; + + @Subscribe + public void on(ModConstructEvent e) throws Exception { + INSTANCE = this; + logger.info("Loading Helios..."); + + /* Register Kotlin library */ + logger.info("Setting up Kotlin"); + orion.registerLibrary("org.jetbrains.kotlin:kotlin-stdlib:1.1.3-2"); + orion.registerLibrary("org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3-2"); + orion.registerLibrary("org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.3-2"); + + /* Register AT */ + logger.info("Setting up ATs..."); + orion.registerAT(HeliosMod.class.getResource("/helios_at.cfg")); + + /* Register Mixins */ + logger.info("Setting up core mixins..."); + orion.registerMixinConfig("mixins.helios.core.json"); + orion.registerMixinConfig("mixins.helios.event.json"); + orion.registerMixinConfig("mixins.helios.inventory.json"); + orion.registerMixinConfig("mixins.helios.player.json"); + orion.registerMixinConfig("mixins.helios.world.json"); + } + + @Subscribe + public void on(ModLoadEvent e) throws Exception { + logger.info("Loading configuration..."); + configuration = new Configuration(configurationLoader); + loadConfiguration(); + saveConfiguration(); + } + + public void loadConfiguration() { + try { + configuration.load(); + } catch (Exception e) { + SneakyThrow.throwException(e); + } + } + + public void saveConfiguration() { + try { + configuration.save(); + } catch (Exception e) { + SneakyThrow.throwException(e); + } + } + + public Configuration getConfigurationWrapper() { + return configuration; + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/configuration/Configuration.java b/src/main/java/eu/mikroskeem/helios/mod/configuration/Configuration.java new file mode 100644 index 0000000..2ed8753 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/configuration/Configuration.java @@ -0,0 +1,69 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.configuration; + +import eu.mikroskeem.helios.mod.configuration.categories.HeliosConfiguration; +import eu.mikroskeem.shuriken.common.SneakyThrow; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import ninja.leaping.configurate.objectmapping.ObjectMapper; + + +/** + * Helios configuration wrapper + * + * @author Mark Vainomaa + */ +public final class Configuration { + private final ConfigurationLoader configurationLoader; + private ObjectMapper.BoundInstance configurationMapper; + private CommentedConfigurationNode baseNode; + private HeliosConfiguration heliosConfigurationInstance; + + public Configuration(ConfigurationLoader configurationLoader) { + this.configurationLoader = configurationLoader; + try { + configurationMapper = ObjectMapper.forClass(HeliosConfiguration.class).bindToNew(); + heliosConfigurationInstance = configurationMapper.getInstance(); + } catch (Exception e) { + SneakyThrow.throwException(e); + } + } + + public void load() throws Exception { + baseNode = configurationLoader.load(); + heliosConfigurationInstance = configurationMapper.populate(baseNode.getNode("helios")); + } + + public void save() throws Exception { + configurationMapper.serialize(baseNode.getNode("helios")); + configurationLoader.save(baseNode); + } + + public HeliosConfiguration getConfiguration() { + return heliosConfigurationInstance; + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/OrionCoreAccessor.java b/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/OrionCoreAccessor.java new file mode 100644 index 0000000..5313642 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/OrionCoreAccessor.java @@ -0,0 +1,55 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.interfaces.orion; + +import eu.mikroskeem.shuriken.instrumentation.methodreflector.MethodReflector; +import eu.mikroskeem.shuriken.instrumentation.methodreflector.TargetFieldGetter; +import eu.mikroskeem.shuriken.instrumentation.methodreflector.TargetMethod; +import eu.mikroskeem.shuriken.reflect.Reflect; + +import java.util.List; +import java.util.stream.Collectors; + + +/** + * Accesses Orion internals via reflection + * + * TODO: expose mod/mixin configurations + * + * @author Mark Vainomaa + */ +public interface OrionCoreAccessor { + @TargetFieldGetter("mixinConfigurations") List getMixinConfigurations(); + @TargetFieldGetter("mods") List gm(); + + @TargetMethod("_INVALID_getMods") + default List getMods() { + return gm().stream() + .map(Reflect::wrapInstance) + .map(wi -> MethodReflector.newInstance(wi, OrionModContainer.class).getReflector()) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/OrionModContainer.java b/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/OrionModContainer.java new file mode 100644 index 0000000..9892a3f --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/OrionModContainer.java @@ -0,0 +1,44 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.interfaces.orion; + +import eu.mikroskeem.shuriken.instrumentation.methodreflector.MethodReflector; +import eu.mikroskeem.shuriken.instrumentation.methodreflector.TargetMethod; +import eu.mikroskeem.shuriken.reflect.Reflect; + + +/** + * Orion Mod container accessor + * + * @author Mark Vainomaa + */ +public interface OrionModContainer { + @TargetMethod(value = "getModInfo", desc = "()Leu/mikroskeem/orion/core/mod/ModInfo;") Object gmi(); + + default OrionModInfo getModInfo() { + return MethodReflector.newInstance(Reflect.wrapInstance(gmi()), OrionModInfo.class).getReflector(); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/OrionModInfo.java b/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/OrionModInfo.java new file mode 100644 index 0000000..62c0751 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/OrionModInfo.java @@ -0,0 +1,40 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.interfaces.orion; + +import java.util.List; + + +/** + * Orion Mod info accessor + * + * @author Mark Vainomaa + */ +public interface OrionModInfo { + String getId(); + String getClassName(); + List getDependencies(); +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/package-info.java b/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/package-info.java new file mode 100644 index 0000000..b579ecf --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/interfaces/orion/package-info.java @@ -0,0 +1,31 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * Accessor interfaces used with {@link eu.mikroskeem.shuriken.instrumentation.methodreflector.MethodReflector} + * + * @author Mark Vainomaa + */ +package eu.mikroskeem.helios.mod.interfaces.orion; \ No newline at end of file diff --git a/src/main/java/eu/mikroskeem/helios/mod/interfaces/plugin/HeliosJavaPluginLoader.java b/src/main/java/eu/mikroskeem/helios/mod/interfaces/plugin/HeliosJavaPluginLoader.java new file mode 100644 index 0000000..0463a7c --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/interfaces/plugin/HeliosJavaPluginLoader.java @@ -0,0 +1,44 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.interfaces.plugin; + +import org.bukkit.plugin.java.JavaPluginLoader; +import org.bukkit.plugin.java.PluginClassLoader; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + + +/** + * JavaPluginLoader accessor + * + * @author Mark Vainomaa + */ +@Mixin(value = JavaPluginLoader.class, remap = false) +public interface HeliosJavaPluginLoader { + @Accessor List getLoaders(); +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/interfaces/world/HeliosWorldData.java b/src/main/java/eu/mikroskeem/helios/mod/interfaces/world/HeliosWorldData.java new file mode 100644 index 0000000..0443a31 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/interfaces/world/HeliosWorldData.java @@ -0,0 +1,51 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.interfaces.world; + +import org.bukkit.Location; + + +/** + * Interface sitting on top of NMS WorldData + * + * @author Mark Vainomaa + */ +public interface HeliosWorldData { + double getSpawnpointX(); + double getSpawnpointY(); + double getSpawnpointZ(); + float getSpawnpointYaw(); + float getSpawnpointPitch(); + + void setSpawnpointX(double value); + void setSpawnpointY(double value); + void setSpawnpointZ(double value); + void setSpawnpointYaw(float value); + void setSpawnpointPitch(float value); + + Location getSpawnpoint(); + void setSpawnpoint(Location location); +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinCommand.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinCommand.java new file mode 100644 index 0000000..896a61b --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinCommand.java @@ -0,0 +1,72 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import eu.mikroskeem.helios.mod.HeliosMod; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + + +/** + * Mixin to modify command system behaviour + * + * @author Mark Vainomaa + */ +@Mixin(value = Command.class, remap = false) +public abstract class MixinCommand { + @Shadow private String permissionMessage; + @Shadow private String permission; + @Shadow private String name; + @Shadow public abstract boolean testPermissionSilent(CommandSender target); + + public boolean testPermission(CommandSender target) { + if(testPermissionSilent(target)) + return true; + + /* Send permission message */ + boolean shouldOverride = HeliosMod.INSTANCE.getConfigurationWrapper() + .getConfiguration() + .getCommandConfiguration() + .getOverridePluginCommandPermissionDeniedMessage(); + + String overrideMessage = HeliosMod.INSTANCE.getConfigurationWrapper() + .getConfiguration() + .getCommandConfiguration() + .getPermissionDeniedMessage(); + + /* Pick correct message and send it to target */ + String[] messages = (shouldOverride ? overrideMessage : (permissionMessage != null ? permissionMessage : overrideMessage)) + .replace("", permission) // Retain legacy placeholder + .replace("%permission%", permission) + .replace("%command%", name) + .split("\n"); + + target.sendMessage(messages); + return false; + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinCraftServer.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinCraftServer.java new file mode 100644 index 0000000..e40eda6 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinCraftServer.java @@ -0,0 +1,54 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import net.minecraft.server.v1_12_R1.MinecraftServer; +import org.bukkit.craftbukkit.v1_12_R1.CraftServer; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + + +/** + * Cosmetical CraftServer mixin + * + * @author Mark Vainomaa + */ +@Mixin(value = CraftServer.class, remap = false) +public abstract class MixinCraftServer { + @Shadow @Final private String serverVersion; + + @Shadow @Final protected MinecraftServer console; + + public String getName() { + return "Helios/Paper"; + } + + public String toString() { + return "CraftServer{serverName=" + getName() + ",serverVersion=" + this.serverVersion + + ",minecraftVersion=" + this.console.getVersion() + '}'; + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinCrashReport.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinCrashReport.java new file mode 100644 index 0000000..145567f --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinCrashReport.java @@ -0,0 +1,105 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import eu.mikroskeem.helios.mod.interfaces.orion.OrionCoreAccessor; +import eu.mikroskeem.helios.mod.interfaces.orion.OrionModContainer; +import eu.mikroskeem.orion.api.OrionAPI; +import eu.mikroskeem.shuriken.instrumentation.methodreflector.MethodReflector; +import eu.mikroskeem.shuriken.reflect.ClassWrapper; +import eu.mikroskeem.shuriken.reflect.Reflect; +import net.minecraft.server.v1_12_R1.CrashReport; +import net.minecraft.server.v1_12_R1.CrashReportSystemDetails; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + + +/** + * Mixin to inject Orion/Helios info into crash report + * + * @author Mark Vainomaa + */ +@Mixin(value = CrashReport.class, remap = false) +public abstract class MixinCrashReport { + @Shadow @Final private CrashReportSystemDetails d; + + @Inject(method = "h", at = @At("RETURN")) + public void onPopulateEnvironment(CallbackInfo cb) { + /* TODO: Expose given information in Orion */ + ClassWrapper orionCoreClass = Reflect.getClassThrows("eu.mikroskeem.orion.core.OrionCore"); + Object orionCoreInstance = orionCoreClass.getField("INSTANCE", orionCoreClass.getWrappedClass()) + .orElseThrow(() -> new RuntimeException("Could not get Orion Core instance!")) + .read(); + orionCoreClass.setClassInstance(orionCoreInstance); + OrionCoreAccessor orionCore = MethodReflector.newInstance(orionCoreClass, OrionCoreAccessor.class) + .getReflector(); + + this.d.a("Orion & Helios - What are those?", () -> { + StringBuilder result = new StringBuilder(64); + result + .append('\n') + .append("\t\tOrion is a Paper server coremod framework, written using SpongeMixin library\n") + .append("\t\tHelios is modification collection for Paper\n\n") + .append("\t\tSteps to do before reporting an issue:\n") + .append("\t\t- First try to figure out whether issue is caused by a coremod or not,\n") + .append("\t\t\tand then report issue to coremod developer\n") + .append("\t\t- Do old school method - disable coremods one-by-one, and find the bastard who caused this crash\n") + .append("\t\t- Disable Helios, and for last Orion, and see if server keeps crashing\n") + .append("\t\t- If issue is caused by Helios, report issue to https://github.com/OrionMinecraft/Helios\n") + .append("\t\t- If issue is caused by Orion, report issue to https://github.com/OrionMinecraft/Orion\n") + .append("\t\t- If issue is caused by Paper, report issue to https://github.com/PaperMC/Paper\n") + .append("\t\tThank you for your cooperation and reading :-)"); + return result.toString(); + }); + + this.d.a("Orion coremods", () -> { + StringBuilder result = new StringBuilder(64); + for (OrionModContainer modContainer : orionCore.getMods()) + result.append("\n\t\t").append(modContainer.getModInfo().getId()); + return result.toString(); + }); + + /* TODO: Look into Mixin files and point out potential problem cause */ + this.d.a("Orion registered mixins", () -> { + StringBuilder result = new StringBuilder(64); + for(String mixinConfig: orionCore.getMixinConfigurations()) { + result.append("\n\t\t").append(mixinConfig); + } + return result.toString(); + }); + + this.d.a("Orion downloaded libraries", () -> { + StringBuilder result = new StringBuilder(64); + for(String library : OrionAPI.getInstance().getRegisteredLibraries()) + result.append("\n\t\t").append(library); + return result.toString(); + }); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinDedicatedServer.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinDedicatedServer.java new file mode 100644 index 0000000..e55749d --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinDedicatedServer.java @@ -0,0 +1,48 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import eu.mikroskeem.helios.api.events.server.ServerStartedEvent; +import net.minecraft.server.v1_12_R1.DedicatedServer; +import org.bukkit.Bukkit; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + + +/** + * Mixin to detect complete server startup + * + * @author Mark Vainomaa + */ +@Mixin(value = DedicatedServer.class, remap = false) +public abstract class MixinDedicatedServer { + @Inject(method = "init", at = @At("TAIL")) + public void onDone(CallbackInfoReturnable cb) { + Bukkit.getPluginManager().callEvent(new ServerStartedEvent()); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinJavaPluginLoader.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinJavaPluginLoader.java new file mode 100644 index 0000000..acc08ee --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinJavaPluginLoader.java @@ -0,0 +1,37 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import eu.mikroskeem.helios.mod.interfaces.plugin.HeliosJavaPluginLoader; +import org.bukkit.plugin.java.JavaPluginLoader; +import org.spongepowered.asm.mixin.Mixin; + + +/** + * @author Mark Vainomaa + */ +@Mixin(value = JavaPluginLoader.class, remap = false) +public abstract class MixinJavaPluginLoader implements HeliosJavaPluginLoader {} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinMain.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinMain.java new file mode 100644 index 0000000..c76212d --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinMain.java @@ -0,0 +1,58 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bukkit.craftbukkit.Main; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.io.PrintStream; + + +/** + * Cosmetical Mixin for CraftBukkit Main to replace System.out/err with Log4j :) + * + * @author Mark Vainomaa + */ +@Mixin(value = Main.class, remap = false) +public abstract class MixinMain { + private final static Logger logger = LogManager.getLogger(Main.class.getName()); + + @Redirect(method = "main", at = @At( + value = "INVOKE", + target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V" + )) + private static void onPrintln(PrintStream printStream, String text) { + if(printStream.equals(System.err)) { + logger.error(text); + } else { + logger.info(text); + } + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinMinecraftServer.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinMinecraftServer.java new file mode 100644 index 0000000..38871c5 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinMinecraftServer.java @@ -0,0 +1,58 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import eu.mikroskeem.helios.api.events.server.ServerStoppingEvent; +import net.minecraft.server.v1_12_R1.MinecraftServer; +import org.bukkit.Bukkit; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + + +/** + * Mixin to detect server stop and change brand + * + * @author Mark Vainomaa + */ +@Mixin(value = MinecraftServer.class, remap = false) +public abstract class MixinMinecraftServer { + private final static String LOG_INFO = "Lorg/apache/logging/log4j/Logger;info(Ljava/lang/String;)V"; + + @Inject(method = "stop", at = @At( + value = "INVOKE", target = LOG_INFO, + ordinal = 0, shift = At.Shift.AFTER + )) + private void callServerStopping(CallbackInfo ci) { + Bukkit.getPluginManager().callEvent(new ServerStoppingEvent()); + } + + /* Replace server mod name */ + public String getServerModName() { + return "Helios/Paper"; + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinSimpleCommandMap.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinSimpleCommandMap.java new file mode 100644 index 0000000..a704d27 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinSimpleCommandMap.java @@ -0,0 +1,50 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import org.bukkit.command.Command; +import org.bukkit.command.SimpleCommandMap; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + + +/** + * Mixin to add Helios command to server + * + * @author Mark Vainomaa + */ +@Mixin(value = SimpleCommandMap.class, remap = false) +public abstract class MixinSimpleCommandMap { + @Shadow public abstract boolean register(String fallbackPrefix, Command command); + + @Inject(method = "setDefaultCommands()V", at = @At("HEAD")) + public void onSetDefaultCommands(CallbackInfo callbackInfo) { + /* TODO: Commands */ + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinSimplePluginManager.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinSimplePluginManager.java new file mode 100644 index 0000000..2f1def3 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinSimplePluginManager.java @@ -0,0 +1,101 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import eu.mikroskeem.helios.api.plugin.HeliosPluginManager; +import eu.mikroskeem.helios.mod.interfaces.plugin.HeliosJavaPluginLoader; +import eu.mikroskeem.shuriken.common.Ensure; +import eu.mikroskeem.shuriken.common.SneakyThrow; +import org.bukkit.command.PluginCommand; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.event.HandlerList; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.SimplePluginManager; +import org.bukkit.plugin.java.JavaPluginLoader; +import org.bukkit.plugin.java.PluginClassLoader; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.io.IOException; +import java.net.URLClassLoader; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + + +/** + * @author Mark Vainomaa + */ +@Mixin(value = SimplePluginManager.class, remap = false) +public abstract class MixinSimplePluginManager implements HeliosPluginManager { + @Shadow @Final private Map lookupNames; + @Shadow @Final private List plugins; + @Shadow @Final private SimpleCommandMap commandMap; + @Shadow public abstract void disablePlugin(Plugin plugin); + + @Override + public void unloadPlugin(@NotNull Plugin plugin){ + Ensure.notNull(plugin, "Plugin should not be null!"); + String pluginName = plugin.getName().toLowerCase(Locale.ENGLISH); + + /* Disable */ + disablePlugin(plugin); + + /* Remove from lists */ + lookupNames.remove(pluginName, plugin); + plugins.remove(plugin); + + /* Unregister commands */ + new HashMap<>(commandMap.getKnownCommands()).values().stream() + .filter(c -> c instanceof PluginCommand) + .map(c -> (PluginCommand) c) + .filter(c -> c.getPlugin().getName().toLowerCase(Locale.ENGLISH).equals(pluginName)) + .forEach(c -> { + c.unregister(commandMap); + commandMap.getKnownCommands().remove(c.getName(), c); + commandMap.getKnownCommands().remove(pluginName + ":" + c.getName()); + }); + + /* Unregister listeners for sure */ + HandlerList.unregisterAll(plugin); + + /* Close classloader */ + ClassLoader classLoader = plugin.getClass().getClassLoader(); + if(plugin.getPluginLoader() instanceof JavaPluginLoader) { + HeliosJavaPluginLoader jpl = (HeliosJavaPluginLoader) plugin.getPluginLoader(); + PluginClassLoader pcl = (PluginClassLoader) classLoader; + if(jpl.getLoaders().contains(pcl)) + jpl.getLoaders().remove(pcl); + } + try { + if(classLoader instanceof URLClassLoader) ((URLClassLoader) classLoader).close(); + } + catch (IOException e) { SneakyThrow.throwException(e); } + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinVersionCommand.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinVersionCommand.java new file mode 100644 index 0000000..96086ad --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/core/MixinVersionCommand.java @@ -0,0 +1,55 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.core; + +import org.bukkit.command.CommandSender; +import org.bukkit.command.defaults.VersionCommand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + + +/** + * Injects Helios version information to {@link VersionCommand} + * + * @author Mark Vainomaa + */ +@Mixin(value = VersionCommand.class, remap = false) +public abstract class MixinVersionCommand { + private final static String EXECUTE = "execute(Lorg/bukkit/command/CommandSender;" + + "Ljava/lang/String;[Ljava/lang/String;)Z"; + private final static String SEND_VERSION = "Lorg/bukkit/command/defaults/VersionCommand;" + + "sendVersion(Lorg/bukkit/command/CommandSender;)V"; + + @Shadow protected abstract void sendVersion(CommandSender sender); + + @Redirect(method = EXECUTE, at = @At(value = "INVOKE", target = SEND_VERSION)) + public void proxySendVersion(VersionCommand versionCommand, CommandSender sender) { + sendVersion(sender); + sender.sendMessage("§7Server uses §6Helios§7, made with §c\u2764 §7by §c§lmikroskeem"); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/event/MixinEvent.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/event/MixinEvent.java new file mode 100644 index 0000000..c89833d --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/event/MixinEvent.java @@ -0,0 +1,44 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.event; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.bukkit.event.Event; +import org.spongepowered.asm.mixin.Mixin; + + +/** + * {@link Event} mixin + * + * @author Mark Vainomaa + */ +@Mixin(value = Event.class, remap = false) +public abstract class MixinEvent { + @Override + public String toString(){ + return ReflectionToStringBuilder.toString(this); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/inventory/MixinCraftItemStack.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/inventory/MixinCraftItemStack.java new file mode 100644 index 0000000..803c0f5 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/inventory/MixinCraftItemStack.java @@ -0,0 +1,152 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.inventory; + +import eu.mikroskeem.helios.api.inventory.HeliosItemStack; +import net.minecraft.server.v1_12_R1.*; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_12_R1.util.CraftMagicNumbers; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.*; +import java.util.stream.Collectors; + + +/** + * Mixin to implement methods in {@link HeliosItemStack} + * + * @author Mark Vainomaa + */ +@Mixin(value = CraftItemStack.class, remap = false) +public abstract class MixinCraftItemStack implements HeliosItemStack { + @Shadow net.minecraft.server.v1_12_R1.ItemStack handle; + + @Override + public void setCanDestroy(@Nullable Collection materials) { + /* Get tag */ + NBTTagCompound tag; + if((tag = handle.getTag()) == null) { + /* Do not create new tag, if materials is null */ + if(materials == null) return; + + /* Create new tag */ + tag = new NBTTagCompound(); + } + + /* Set 'CanDestroy' list */ + if(materials != null) { + NBTTagList canDestroy = new NBTTagList(); + new HashSet<>(materials).stream() + .map(this::helios$getItemId) + .map(NBTTagString::new) + .forEach(canDestroy::add); + tag.set("CanDestroy", canDestroy); + } else { + if(tag.getList("CanDestroy", (byte) 8) != null) + tag.remove("CanDestroy"); + } + + /* Apply tag */ + handle.setTag(tag); + } + + @Override + public @NotNull Collection getCanDestroy() { + /* Get tag, or return empty set */ + NBTTagCompound tag; + if((tag = handle.getTag()) == null) + return Collections.emptySet(); + + /* Try to get list 'canDestroy' */ + NBTTagList canDestroy = tag.getList("CanDestroy", (byte) 8); + if(canDestroy == null || canDestroy.isEmpty()) + return Collections.emptySet(); + + /* Convert NBT String array */ + return helios$convertItemsToSet(canDestroy.list); + } + + @Override + public void setCanPlaceOn(@Nullable Collection materials) { + /* Get tag */ + NBTTagCompound tag; + if((tag = handle.getTag()) == null) { + /* Do not create new tag, if materials is null */ + if(materials == null) return; + + /* Create new tag */ + tag = new NBTTagCompound(); + } + + if(materials != null) { + NBTTagList canPlaceOn = new NBTTagList(); + new HashSet<>(materials).stream() + .map(this::helios$getItemId) + .map(NBTTagString::new) + .forEach(canPlaceOn::add); + tag.set("CanPlaceOn", canPlaceOn); + } else { + if(tag.getList("CanPlaceOn", (byte) 8) != null) + tag.remove("CanPlaceOn"); + } + + /* Apply tag */ + handle.setTag(tag); + } + + @Override + public @NotNull Collection getCanPlaceOn() { + /* Get tag, or return empty set */ + NBTTagCompound tag; + if((tag = handle.getTag()) == null) + return Collections.emptySet(); + + /* Try to get list 'CanPlaceOn' */ + NBTTagList canPlaceOn = tag.getList("CanPlaceOn", (byte) 8); + if(canPlaceOn == null || canPlaceOn.isEmpty()) + return Collections.emptySet(); + + /* Convert NBT String array */ + return helios$convertItemsToSet(canPlaceOn.list); + } + + /* Material.DIAMOND_ORE -> minecraft:diamond_ore */ + private String helios$getItemId(Material material) { + return Block.REGISTRY.b(CraftMagicNumbers.getBlock(material)).toString(); + } + + private Set helios$convertItemsToSet(List nbtStringList) { + return nbtStringList.stream() + .map(nbtBase -> (NBTTagString) nbtBase) + .map(NBTTagString::c_) + .map(CraftMagicNumbers.INSTANCE::getMaterialFromInternalName) + .collect(Collectors.toSet()); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/package-info.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/package-info.java new file mode 100644 index 0000000..a6c09c4 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/package-info.java @@ -0,0 +1,29 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * @author Mark Vainomaa + */ +package eu.mikroskeem.helios.mod.mixins; \ No newline at end of file diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/player/MixinCraftPlayer.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/player/MixinCraftPlayer.java new file mode 100644 index 0000000..665e476 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/player/MixinCraftPlayer.java @@ -0,0 +1,71 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.player; + +import eu.mikroskeem.helios.api.entity.Player; +import eu.mikroskeem.helios.api.events.player.chat.PlayerPluginSendMessageEvent; +import eu.mikroskeem.helios.mod.HeliosMod; +import net.minecraft.server.v1_12_R1.EntityPlayer; +import net.minecraft.server.v1_12_R1.MinecraftServer; +import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.spongepowered.asm.mixin.*; + + +/** + * CraftPlayer Mixin, to provide implementation for {@link Player} + * + * @author Mark Vainomaa + */ +@Mixin(value = CraftPlayer.class, remap = false) +@Implements(@Interface(iface = CommandSender.class, prefix = "helios$")) +public abstract class MixinCraftPlayer implements Player { + @Shadow public abstract EntityPlayer getHandle(); + + @Override + public long getLastActiveTime() { + return this.getHandle().J(); + } + + @Override + public boolean isAway() { + long configuredAwayTime = HeliosMod.INSTANCE.getConfigurationWrapper() + .getConfiguration() + .getPlayerConfiguration() + .getMillisecondsUntilToMarkPlayerAway(); + long currentTime = MinecraftServer.aw(); + return (currentTime - this.getLastActiveTime()) >= configuredAwayTime; + } + + @Intrinsic(displace = true) + public void helios$sendMessage(String message) { + PlayerPluginSendMessageEvent event = new PlayerPluginSendMessageEvent(this, message); + getServer().getPluginManager().callEvent(event); + if(!event.isCancelled()) { + sendMessage(message); + } + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/player/MixinPlayerConnection.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/player/MixinPlayerConnection.java new file mode 100644 index 0000000..b6eacfd --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/player/MixinPlayerConnection.java @@ -0,0 +1,69 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.player; + +import eu.mikroskeem.helios.api.entity.Player; +import eu.mikroskeem.helios.api.events.player.idle.PlayerActiveEvent; +import eu.mikroskeem.helios.api.events.player.idle.PlayerIdleEvent; +import net.minecraft.server.v1_12_R1.MinecraftServer; +import net.minecraft.server.v1_12_R1.PlayerConnection; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + + +/** + * Handles player idle/active events and + * + * @author Mark Vainomaa + */ +@Mixin(value = PlayerConnection.class, remap = false) +public abstract class MixinPlayerConnection { + @Shadow public abstract CraftPlayer getPlayer(); + + private int helios$awayTicks = 0; + + @Inject(method = "e", at = @At("TAIL")) + public void onUpdate(CallbackInfo cb) { + Player player = (Player) getPlayer(); + if(player.isAway()) { + if(helios$awayTicks == 0) { + getPlayer().getServer().getPluginManager() + .callEvent(new PlayerIdleEvent(player, MinecraftServer.aw())); + } + helios$awayTicks++; + } else { + if(helios$awayTicks > 0) { + helios$awayTicks = 0; + getPlayer().getServer().getPluginManager() + .callEvent(new PlayerActiveEvent(player, MinecraftServer.aw())); + } + } + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinCraftWorld.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinCraftWorld.java new file mode 100644 index 0000000..4fdc524 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinCraftWorld.java @@ -0,0 +1,69 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.world; + +import eu.mikroskeem.helios.api.world.World; +import eu.mikroskeem.helios.mod.interfaces.world.HeliosWorldData; +import net.minecraft.server.v1_12_R1.WorldServer; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + + +/** + * Mixin to modify spawn location setter/getter behaviour + * + * @author Mark Vainomaa + */ +@Mixin(value = CraftWorld.class, remap = false) +public abstract class MixinCraftWorld implements World { + @Shadow @Final private WorldServer world; + + @Override + public Location getSpawnLocation() { + HeliosWorldData worldData = (HeliosWorldData) this.world.worldData; + return worldData.getSpawnpoint(); + } + + @Override + public boolean setSpawnLocation(Location location) { + HeliosWorldData worldData = (HeliosWorldData) this.world.worldData; + worldData.setSpawnpoint(location); + return true; + } + + @Override + public boolean setSpawnLocation(int x, int y, int z) { + return setSpawnLocation(new Location(null, x, y, z, 0, 0)); + } + + @Override + public String toString() { + return "HeliosWorld{name=" + this.getName() + '}'; + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinDedicatedServer.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinDedicatedServer.java new file mode 100644 index 0000000..5647a02 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinDedicatedServer.java @@ -0,0 +1,54 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.world; + +import eu.mikroskeem.helios.mod.HeliosMod; +import net.minecraft.server.v1_12_R1.DedicatedServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + + +/** + * Mixin to disable UUID conversion + * + * @author Mark Vainomaa + */ +@Mixin(value = DedicatedServer.class, remap = false) +public abstract class MixinDedicatedServer { + @Inject(method = "aS", cancellable = true, at = @At("HEAD")) + public void onUUIDMigrate(CallbackInfoReturnable ci) { + boolean disable = HeliosMod.INSTANCE.getConfigurationWrapper() + .getConfiguration() + .getWorldConfiguration() + .getDisableUUIDConversion(); + if(disable) { + ci.cancel(); + ci.setReturnValue(true); + } + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinEntityPlayer.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinEntityPlayer.java new file mode 100644 index 0000000..ac93a80 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinEntityPlayer.java @@ -0,0 +1,100 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.world; + +import eu.mikroskeem.helios.mod.interfaces.world.HeliosWorldData; +import net.minecraft.server.v1_12_R1.*; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * Mixin to inject more precise spawnpoint into game + * + * @author Mark Vainomaa + */ +@Mixin(value = EntityPlayer.class, remap = false) +public abstract class MixinEntityPlayer extends Entity { + private final static String GET_SPAWN_WS = "Lnet/minecraft/server/v1_12_R1/WorldServer;" + + "getSpawn()Lnet/minecraft/server/v1_12_R1/BlockPosition;"; + private final static String GET_SPAWN_W = "Lnet/minecraft/server/v1_12_R1/World;getSpawn()" + + "Lnet/minecraft/server/v1_12_R1/BlockPosition;"; + private final static String SET_POS = "Lnet/minecraft/server/v1_12_R1/EntityPlayer;setPosition(DDD)V"; + private final static String SET_POS_ROT = "Lnet/minecraft/server/v1_12_R1/EntityPlayer;" + + "setPositionRotation(Lnet/minecraft/server/v1_12_R1/BlockPosition;FF)V"; + + public MixinEntityPlayer() { super(null); } + + @Shadow public abstract CraftPlayer getBukkitEntity(); + + /* Flag which indicates that player spawn location should be redirected */ + private boolean helios$redirectWorldSpawn = false; + + @Redirect(method = "", at = @At(value = "INVOKE", target = GET_SPAWN_WS)) + public BlockPosition getSpawnProxy_ctor(WorldServer worldServer) { + helios$redirectWorldSpawn = true; + return worldServer.getSpawn(); + } + + @Redirect(method = "spawnIn", at = @At(value = "INVOKE", target = GET_SPAWN_W)) + public BlockPosition getSpawnProxy_spawnIn(World world) { + helios$redirectWorldSpawn = true; + return world.getSpawn(); + } + + @Redirect(method = "spawnIn", at = @At(value = "INVOKE", target = SET_POS)) + public void setPosition_spawnIn(EntityPlayer entityPlayer, double x, double y, double z) { + if(helios$redirectWorldSpawn) { + Location spawnpoint = ((HeliosWorldData) world.worldData).getSpawnpoint(); + setPositionRotation( + spawnpoint.getX(), + spawnpoint.getY(), + spawnpoint.getZ(), + spawnpoint.getYaw(), + spawnpoint.getPitch() + ); + helios$redirectWorldSpawn = false; + } + } + + @Redirect(method = "", at = @At(value = "INVOKE", target = SET_POS_ROT)) + public void setPositionRotation_ctor(EntityPlayer entity, BlockPosition blockposition, float yaw, float pitch) { + if(helios$redirectWorldSpawn) { + Location spawnpoint = ((HeliosWorldData) world.worldData).getSpawnpoint(); + setPositionRotation( + spawnpoint.getX(), + spawnpoint.getY(), + spawnpoint.getZ(), + spawnpoint.getYaw(), + spawnpoint.getPitch() + ); + helios$redirectWorldSpawn = false; + } + } +} \ No newline at end of file diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinPlayerList.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinPlayerList.java new file mode 100644 index 0000000..ae61c53 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinPlayerList.java @@ -0,0 +1,57 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.world; + + +import eu.mikroskeem.helios.mod.interfaces.world.HeliosWorldData; +import net.minecraft.server.v1_12_R1.PlayerList; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * Mixin to inject more precise spawnpoint into game + * + * @author Mark Vainomaa + */ +@Mixin(value = PlayerList.class, remap = false) +public abstract class MixinPlayerList { + private final static String MOVE_TO_WORLD = "moveToWorld(Lnet/minecraft/server/v1_12_R1/EntityPlayer;IZ" + + "Lorg/bukkit/Location;Z)Lnet/minecraft/server/v1_12_R1/EntityPlayer;"; + + @Redirect(method = MOVE_TO_WORLD, + at = @At(value = "NEW", + target = "(Lorg/bukkit/World;DDD)Lorg/bukkit/Location;", + ordinal = 1, + args = "class=org/bukkit/Location" + )) + public Location newLocation(World world, double x, double y, double z) { + return ((HeliosWorldData) ((CraftWorld) world).getHandle().worldData).getSpawnpoint(); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorld.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorld.java new file mode 100644 index 0000000..32d81cf --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorld.java @@ -0,0 +1,52 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.world; + +import net.minecraft.server.v1_12_R1.BlockPosition; +import net.minecraft.server.v1_12_R1.World; +import net.minecraft.server.v1_12_R1.WorldData; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + + +/** + * Mixin class to report World#setSpawn() usage + * + * @author Mark Vainomaa + */ +@Mixin(value = World.class, remap = false) +public abstract class MixinWorld { + @Shadow public WorldData worldData; + + @Inject(method = "A", cancellable = true, at = @At("HEAD")) + public void onSetSpawn(BlockPosition blockposition, CallbackInfo cb) { + new Throwable("Helios: World -> setSpawn(). Please report this to @mikroskeem").printStackTrace(); + cb.cancel(); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorldData.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorldData.java new file mode 100644 index 0000000..4703ea9 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorldData.java @@ -0,0 +1,131 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.world; + +import eu.mikroskeem.helios.mod.interfaces.world.HeliosWorldData; +import net.minecraft.server.v1_12_R1.BlockPosition; +import net.minecraft.server.v1_12_R1.NBTTagCompound; +import net.minecraft.server.v1_12_R1.WorldData; +import net.minecraft.server.v1_12_R1.WorldServer; +import org.bukkit.Location; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * Mixin to inject more precise spawnpoint location into world data + * + * Note: priority is 1001 to apply it after {@link MixinWorldDataAccessors} + * + * @author Mark Vainomaa + */ +@Mixin(value = WorldData.class, priority = 1001, remap = false) +public abstract class MixinWorldData implements HeliosWorldData { + private final static String NBT_BASE = "helios.spawnpoint"; + + @Shadow public WorldServer world; + @Shadow public abstract int b(); // MCP - getSpawnX + @Shadow public abstract int c(); // MCP - getSpawnY + @Shadow public abstract int d(); // MCP - getSpawnZ + @Shadow private int h; // MCP - spawnX + @Shadow private int j; // MCP - spawnY + @Shadow private int i; // MCP - spawnZ + + @Override + public Location getSpawnpoint() { + return new Location( + this.world.getWorld(), + getSpawnpointX(), + getSpawnpointY(), + getSpawnpointZ(), + getSpawnpointYaw(), + getSpawnpointPitch() + ); + } + + @Override + public void setSpawnpoint(Location location) { + setSpawnpointX(location.getX()); + setSpawnpointY(location.getY()); + setSpawnpointZ(location.getZ()); + setSpawnpointYaw(location.getYaw()); + setSpawnpointPitch(location.getPitch()); + + /* Sigh... */ + this.h = location.getBlockX(); + this.i = location.getBlockY(); + this.j = location.getBlockZ(); + } + + /* updateTagCompound - in MCP */ + @Inject(method = "a(Lnet/minecraft/server/v1_12_R1/NBTTagCompound;" + + "Lnet/minecraft/server/v1_12_R1/NBTTagCompound;)V", at = @At("HEAD")) + public void onUpdateTagCompound(NBTTagCompound nbt, NBTTagCompound playerNbt, CallbackInfo cb) { + NBTTagCompound heliosSpawn = new NBTTagCompound(); + heliosSpawn.setDouble("x", getSpawnpointX()); + heliosSpawn.setDouble("y", getSpawnpointY()); + heliosSpawn.setDouble("z", getSpawnpointZ()); + heliosSpawn.setFloat("yaw", getSpawnpointYaw()); + heliosSpawn.setFloat("pitch", getSpawnpointPitch()); + nbt.set(NBT_BASE, heliosSpawn); + } + + @Inject(method = "(Lnet/minecraft/server/v1_12_R1/NBTTagCompound;)V", at = @At("RETURN")) + public void onConstructUsingNBT(NBTTagCompound nbt, CallbackInfo cb) { + setSpawnpointX(this.b()); + setSpawnpointY(this.c()); + setSpawnpointZ(this.d()); + setSpawnpointYaw(0); + setSpawnpointPitch(0); + if(nbt.hasKeyOfType(NBT_BASE, 10)) { + NBTTagCompound spawnpoint = nbt.getCompound(NBT_BASE); + setSpawnpointX(spawnpoint.getDouble("x")); + setSpawnpointY(spawnpoint.getDouble("y")); + setSpawnpointZ(spawnpoint.getDouble("z")); + setSpawnpointYaw(spawnpoint.getFloat("yaw")); + setSpawnpointPitch(spawnpoint.getFloat("pitch")); + } + } + + @Inject(method = "(Lnet/minecraft/server/v1_12_R1/WorldData;)V", at = @At("RETURN")) + public void onConstructUsingOtherWorldData(WorldData worldData, CallbackInfo cb) { + HeliosWorldData heliosWorldData = ((HeliosWorldData) worldData); + setSpawnpointX(heliosWorldData.getSpawnpointX()); + setSpawnpointY(heliosWorldData.getSpawnpointY()); + setSpawnpointZ(heliosWorldData.getSpawnpointZ()); + setSpawnpointYaw(heliosWorldData.getSpawnpointYaw()); + setSpawnpointPitch(heliosWorldData.getSpawnpointPitch()); + } + + /* Cancel spawn setting from internal NMS code */ + @Inject(method = "setSpawn", cancellable = true, at = @At("HEAD")) + public void onSetSpawn(BlockPosition blockPosition, CallbackInfo cb) { + new Throwable("Helios: WorldData -> setSpawn(). Please report this to @mikroskeem").printStackTrace(); + cb.cancel(); + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorldDataAccessors.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorldDataAccessors.java new file mode 100644 index 0000000..3573b86 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorldDataAccessors.java @@ -0,0 +1,95 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.world; + +import eu.mikroskeem.helios.mod.interfaces.world.HeliosWorldData; +import net.minecraft.server.v1_12_R1.WorldData; +import org.spongepowered.asm.mixin.Mixin; + + +/** + * Mixin to add new fields to WorldData class + * + * @author Mark Vainomaa + */ +@Mixin(value = WorldData.class, remap = false) +public abstract class MixinWorldDataAccessors implements HeliosWorldData { + private double spawnpointX; + private double spawnpointY; + private double spawnpointZ; + private float spawnpointYaw; + private float spawnpointPitch; + + @Override + public double getSpawnpointX() { + return spawnpointX; + } + + @Override + public double getSpawnpointY() { + return spawnpointY; + } + + @Override + public double getSpawnpointZ() { + return spawnpointZ; + } + + @Override + public float getSpawnpointYaw() { + return spawnpointYaw; + } + + @Override + public float getSpawnpointPitch() { + return spawnpointPitch; + } + + @Override + public void setSpawnpointX(double spawnpointX) { + this.spawnpointX = spawnpointX; + } + + @Override + public void setSpawnpointY(double spawnpointY) { + this.spawnpointY = spawnpointY; + } + + @Override + public void setSpawnpointZ(double spawnpointZ) { + this.spawnpointZ = spawnpointZ; + } + + @Override + public void setSpawnpointYaw(float spawnpointYaw) { + this.spawnpointYaw = spawnpointYaw; + } + + @Override + public void setSpawnpointPitch(float spawnpointPitch) { + this.spawnpointPitch = spawnpointPitch; + } +} diff --git a/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorldNBTStorage.java b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorldNBTStorage.java new file mode 100644 index 0000000..d085bb8 --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/mod/mixins/world/MixinWorldNBTStorage.java @@ -0,0 +1,77 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.mod.mixins.world; + +import eu.mikroskeem.helios.mod.HeliosMod; +import net.minecraft.server.v1_12_R1.EntityHuman; +import net.minecraft.server.v1_12_R1.IPlayerFileData; +import net.minecraft.server.v1_12_R1.NBTTagCompound; +import net.minecraft.server.v1_12_R1.WorldNBTStorage; +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + + +/** + * Mixin which allows/disallows player data saving + * + * @author Mark Vainomaa + */ +@Mixin(value = WorldNBTStorage.class, remap = false) +@Implements(@Interface(iface = IPlayerFileData.class, prefix = "pfd$")) +public abstract class MixinWorldNBTStorage { + private final static String[] EMPTY_STRING_ARRAY = new String[0]; + + @Shadow public abstract String[] getSeenPlayers(); + + @Inject(method = "save", cancellable = true, at = @At("HEAD")) + public void onSave(EntityHuman e, CallbackInfo cb) { + if(helios$isSavingDisabled()) + cb.cancel(); + } + + @Inject(method = "load", cancellable = true, at = @At("HEAD")) + public void load(EntityHuman e, CallbackInfoReturnable cb) { + if(helios$isSavingDisabled()) + cb.setReturnValue(null); + } + + @Intrinsic(displace = true) + public String[] pfd$getSeenPlayers() { + if(helios$isSavingDisabled()) + return EMPTY_STRING_ARRAY; + return this.getSeenPlayers(); + } + + private boolean helios$isSavingDisabled() { + return HeliosMod.INSTANCE.getConfigurationWrapper() + .getConfiguration() + .getPlayerConfiguration() + .getPlayerDataSavingDisabled(); + } +} \ No newline at end of file diff --git a/src/main/java/eu/mikroskeem/helios/plugin/HeliosPlugin.java b/src/main/java/eu/mikroskeem/helios/plugin/HeliosPlugin.java new file mode 100644 index 0000000..a6a3adf --- /dev/null +++ b/src/main/java/eu/mikroskeem/helios/plugin/HeliosPlugin.java @@ -0,0 +1,41 @@ +/* + * This file is part of project Helios, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 Mark Vainomaa + * Copyright (c) Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package eu.mikroskeem.helios.plugin; + +import org.bukkit.plugin.java.JavaPlugin; + + +/** + * The Helios plugin + * + * @author Mark Vainomaa + */ +public final class HeliosPlugin extends JavaPlugin { + @Override + public void onEnable() { + + } +} diff --git a/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/CommandConfiguration.kt b/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/CommandConfiguration.kt new file mode 100644 index 0000000..e9e6d7f --- /dev/null +++ b/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/CommandConfiguration.kt @@ -0,0 +1,24 @@ +package eu.mikroskeem.helios.mod.configuration.categories + +import ninja.leaping.configurate.objectmapping.Setting +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable + +/** + * Command system sub-configuration + * + * @author Mark Vainomaa + */ +@ConfigSerializable +class CommandConfiguration { + @Setting(value = "override-plugin-command-permission-denied-message", + comment = "Should Helios override plugin's command permission denied message, regardless if it" + + "is defined in plugin's plugin.yml or not?") + var overridePluginCommandPermissionDeniedMessage = true + private set + + @Setting(value = "permission-denied-message", + comment = "Command permission denied message. Defaults to Bukkit's default") + var permissionDeniedMessage = "§cI'm sorry, but you do not have permission to perform this command. " + + "Please contact the server administrators if you believe that this is in error." + private set +} \ No newline at end of file diff --git a/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/HeliosConfiguration.kt b/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/HeliosConfiguration.kt new file mode 100644 index 0000000..fce1f3a --- /dev/null +++ b/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/HeliosConfiguration.kt @@ -0,0 +1,24 @@ +package eu.mikroskeem.helios.mod.configuration.categories + +import ninja.leaping.configurate.objectmapping.Setting +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable + +/** + * Helios configuration + * + * @author Mark Vainomaa + */ +@ConfigSerializable +class HeliosConfiguration { + @Setting(value = "player", comment = "Player configuration") + var playerConfiguration = PlayerConfiguration() + private set + + @Setting(value = "world", comment = "World configuration") + var worldConfiguration = WorldConfiguration() + private set + + @Setting(value = "command", comment = "Command system configuration") + var commandConfiguration = CommandConfiguration() + private set +} \ No newline at end of file diff --git a/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/PlayerConfiguration.kt b/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/PlayerConfiguration.kt new file mode 100644 index 0000000..6798c67 --- /dev/null +++ b/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/PlayerConfiguration.kt @@ -0,0 +1,21 @@ +package eu.mikroskeem.helios.mod.configuration.categories + +import ninja.leaping.configurate.objectmapping.Setting +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable + +/** + * Player sub-configuration + * + * @author Mark Vainomaa + */ +@ConfigSerializable +class PlayerConfiguration { + @Setting(value = "milliseconds-until-to-mark-player-away", + comment = "Time how long should player be idle to mark one away") + var millisecondsUntilToMarkPlayerAway: Long = 120 * 1000 + private set + @Setting(value = "player-data-saving-disabled", + comment = "Disables player data saving to disk. Useful for Lobby servers") + var playerDataSavingDisabled = false + private set +} \ No newline at end of file diff --git a/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/WorldConfiguration.kt b/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/WorldConfiguration.kt new file mode 100644 index 0000000..259088e --- /dev/null +++ b/src/main/kotlin/eu/mikroskeem/helios/mod/configuration/categories/WorldConfiguration.kt @@ -0,0 +1,17 @@ +package eu.mikroskeem.helios.mod.configuration.categories + +import ninja.leaping.configurate.objectmapping.Setting +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable + +/** + * World sub-configuration + * + * @author Mark Vainomaa + */ +@ConfigSerializable +class WorldConfiguration { + @Setting(value = "disable-uuid-conversion", comment = "Disables UUID conversion on startup, useful if server " + + "does *certainly* not need to migrate legacy data") + var disableUUIDConversion = false + private set +} \ No newline at end of file diff --git a/src/main/resources/helios_at.cfg b/src/main/resources/helios_at.cfg new file mode 100644 index 0000000..4a0ec7d --- /dev/null +++ b/src/main/resources/helios_at.cfg @@ -0,0 +1 @@ +public-f org.bukkit.plugin.java.PluginClassLoader \ No newline at end of file diff --git a/src/main/resources/mixins.helios.core.json b/src/main/resources/mixins.helios.core.json new file mode 100644 index 0000000..308836a --- /dev/null +++ b/src/main/resources/mixins.helios.core.json @@ -0,0 +1,19 @@ +{ + "required": true, + "minVersion": "0.6.15", + "package": "eu.mikroskeem.helios.mod.mixins.core", + "target": "@env(DEFAULT)", + "compatibilityLevel": "JAVA_8", + "server": [ + "MixinCommand", + "MixinCraftServer", + "MixinCrashReport", + "MixinDedicatedServer", + "MixinJavaPluginLoader", + "MixinMain", + "MixinMinecraftServer", + "MixinSimpleCommandMap", + "MixinSimplePluginManager", + "MixinVersionCommand" + ] +} \ No newline at end of file diff --git a/src/main/resources/mixins.helios.event.json b/src/main/resources/mixins.helios.event.json new file mode 100644 index 0000000..3bceb30 --- /dev/null +++ b/src/main/resources/mixins.helios.event.json @@ -0,0 +1,10 @@ +{ + "required": true, + "minVersion": "0.6.15", + "package": "eu.mikroskeem.helios.mod.mixins.event", + "target": "@env(DEFAULT)", + "compatibilityLevel": "JAVA_8", + "server": [ + "MixinEvent" + ] +} \ No newline at end of file diff --git a/src/main/resources/mixins.helios.inventory.json b/src/main/resources/mixins.helios.inventory.json new file mode 100644 index 0000000..9c7a999 --- /dev/null +++ b/src/main/resources/mixins.helios.inventory.json @@ -0,0 +1,10 @@ +{ + "required": true, + "minVersion": "0.6.15", + "package": "eu.mikroskeem.helios.mod.mixins.inventory", + "target": "@env(DEFAULT)", + "compatibilityLevel": "JAVA_8", + "server": [ + "MixinCraftItemStack" + ] +} \ No newline at end of file diff --git a/src/main/resources/mixins.helios.player.json b/src/main/resources/mixins.helios.player.json new file mode 100644 index 0000000..24be7f9 --- /dev/null +++ b/src/main/resources/mixins.helios.player.json @@ -0,0 +1,11 @@ +{ + "required": true, + "minVersion": "0.6.15", + "package": "eu.mikroskeem.helios.mod.mixins.player", + "target": "@env(DEFAULT)", + "compatibilityLevel": "JAVA_8", + "server": [ + "MixinCraftPlayer", + "MixinPlayerConnection" + ] +} \ No newline at end of file diff --git a/src/main/resources/mixins.helios.world.json b/src/main/resources/mixins.helios.world.json new file mode 100644 index 0000000..aa56ddc --- /dev/null +++ b/src/main/resources/mixins.helios.world.json @@ -0,0 +1,17 @@ +{ + "required": true, + "minVersion": "0.6.15", + "package": "eu.mikroskeem.helios.mod.mixins.world", + "target": "@env(DEFAULT)", + "compatibilityLevel": "JAVA_8", + "server": [ + "MixinCraftWorld", + "MixinDedicatedServer", + "MixinEntityPlayer", + "MixinPlayerList", + "MixinWorld", + "MixinWorldData", + "MixinWorldDataAccessors", + "MixinWorldNBTStorage" + ] +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..9685193 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,7 @@ +name: Helios +version: @version@ +main: eu.mikroskeem.helios.plugin.HeliosPlugin +description: @description@ +website: @website@ +authors: +- mikroskeem