Merge remote-tracking branch 'origin/dev'
This commit is contained in:
commit
ef17e13e87
|
@ -1,14 +1,16 @@
|
|||
*.class
|
||||
.*
|
||||
/build/
|
||||
/target/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
*.iml
|
||||
|
||||
*.iws
|
||||
|
||||
*.ipr
|
||||
|
||||
logs/
|
||||
classes/
|
||||
run/
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
language: java
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.m2
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
42
build.gradle
42
build.gradle
|
@ -1,3 +1,12 @@
|
|||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url "http://repo.maven.apache.org/maven2" }
|
||||
}
|
||||
dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'idea'
|
||||
|
@ -12,15 +21,42 @@ sourceCompatibility = 1.8
|
|||
targetCompatibility = 1.8
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = 'UTF-8'
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
|
||||
configurations {
|
||||
// configuration that holds jars to copy into lib
|
||||
includeLibs
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url "http://repo.maven.apache.org/maven2" }
|
||||
maven { url "http://repo.maven.apache.org/maven2" }
|
||||
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
|
||||
}
|
||||
|
||||
// includeLibs just says to include the library in the final jar
|
||||
dependencies {
|
||||
includeLibs group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
|
||||
compile group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
|
||||
includeLibs group: 'com.google.inject', name: 'guice', version:'4.0'
|
||||
compile group: 'com.google.inject', name: 'guice', version:'4.0'
|
||||
compile "org.bukkit:bukkit:1.13-R0.1-SNAPSHOT"
|
||||
}
|
||||
|
||||
jar {
|
||||
from configurations.includeLibs.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
|
||||
// Set SPIGOT_LOC to the location of your server and SPIGOT_JAR as the name of the jar file in the server you want to run
|
||||
// DIReallyKnowWhatIAmDoingISwear is to remove the stupid pause spigot has at the start
|
||||
task runJar() {
|
||||
doLast {
|
||||
javaexec {
|
||||
main "-jar"
|
||||
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"
|
||||
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"]
|
||||
workingDir "${System.env.MC_SERVER_LOC}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
z# https://docs.gradle.org/current/userguide/build_environment.html
|
||||
# Disable with --no-build-cache
|
||||
org.gradle.caching=true
|
Binary file not shown.
|
@ -0,0 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
|
@ -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" "$@"
|
|
@ -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
|
|
@ -1,60 +1,68 @@
|
|||
package com.sekwah.advancedportals.core;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.api.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.api.managers.DestinationManager;
|
||||
import com.sekwah.advancedportals.core.api.managers.PortalManager;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.api.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.api.registry.WarpEffectRegistry;
|
||||
import com.sekwah.advancedportals.core.api.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.api.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.api.services.PortalTempDataServices;
|
||||
import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.desti.CreateDestiSubCommand;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.portal.*;
|
||||
import com.sekwah.advancedportals.core.config.Config;
|
||||
import com.sekwah.advancedportals.core.config.RepositoryModule;
|
||||
import com.sekwah.advancedportals.core.data.DataStorage;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.ConnectorDataCollector;
|
||||
import com.sekwah.advancedportals.coreconnector.command.CommandRegister;
|
||||
import com.sekwah.advancedportals.coreconnector.info.DataCollector;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class AdvancedPortalsCore {
|
||||
|
||||
private static AdvancedPortalsCore instance;
|
||||
private final CommandRegister commandRegister;
|
||||
private final DataStorage dataStorage;
|
||||
|
||||
private final InfoLogger infoLogger;
|
||||
private final int mcMinorVer;
|
||||
private final ConnectorDataCollector dataCollector;
|
||||
private final DataCollector dataCollector;
|
||||
|
||||
private WarpEffectRegistry warpEffectRegistry;
|
||||
private Injector injector = Guice.createInjector(new RepositoryModule(this));
|
||||
|
||||
private WarpEffectRegistry warpEffectRegistry = injector.getInstance(WarpEffectRegistry.class);
|
||||
private TagRegistry<AdvancedPortal> portalTagRegistry;
|
||||
private TagRegistry<Destination> destiTagRegistry;
|
||||
|
||||
private CoreListeners coreListeners;
|
||||
private CoreListeners coreListeners = injector.getInstance(CoreListeners.class);
|
||||
|
||||
private Config config;
|
||||
private final DataStorage dataStorage;
|
||||
|
||||
private CommandWithSubCommands portalCommand;
|
||||
private CommandWithSubCommands destiCommand;
|
||||
|
||||
private PortalManager portalManager;
|
||||
private DestinationManager destiManager;
|
||||
private PortalServices portalServices = injector.getInstance(PortalServices.class);
|
||||
private DestinationServices destiServices = injector.getInstance(DestinationServices.class);
|
||||
private PortalTempDataServices portalTempDataServices = injector.getInstance(PortalTempDataServices.class);
|
||||
|
||||
private ConfigRepository configRepository = injector.getInstance(ConfigRepository.class);
|
||||
|
||||
public static final String version = "1.0.0";
|
||||
public static final String lastTranslationUpdate = "1.0.0";
|
||||
|
||||
/**
|
||||
* @param dataStorage - The implementation of data storage for the specific platform
|
||||
* @param dataStorageLoc - Where the files will be located
|
||||
* @param infoLogger - The implementation of the logger for the specific platform
|
||||
* @param commandRegister - Handles the command registry, different on each platform
|
||||
* @param mcVer Minecraft version e.g. 1.12.2
|
||||
*/
|
||||
public AdvancedPortalsCore(DataStorage dataStorage, InfoLogger infoLogger, CommandRegister commandRegister,
|
||||
ConnectorDataCollector dataCollector, int[] mcVer) {
|
||||
this.dataStorage = dataStorage;
|
||||
public AdvancedPortalsCore(File dataStorageLoc, InfoLogger infoLogger,
|
||||
DataCollector dataCollector, int[] mcVer) {
|
||||
this.dataStorage = new DataStorage(dataStorageLoc);
|
||||
this.infoLogger = infoLogger;
|
||||
this.instance = this;
|
||||
this.commandRegister = commandRegister;
|
||||
instance = this;
|
||||
this.dataCollector = dataCollector;
|
||||
this.mcMinorVer = this.checkMcVer(mcVer);
|
||||
|
||||
|
@ -62,8 +70,8 @@ public class AdvancedPortalsCore {
|
|||
}
|
||||
|
||||
private int checkMcVer(int[] mcVer) {
|
||||
int maxSupportedVer = 12;
|
||||
int minSupportedVer = 8;
|
||||
int maxSupportedVer = 13;
|
||||
int minSupportedVer = 13;
|
||||
if(mcVer.length == 2 || mcVer.length == 3) {
|
||||
if(mcVer[0] == 1) {
|
||||
if(mcVer[1] < minSupportedVer) {
|
||||
|
@ -79,8 +87,8 @@ public class AdvancedPortalsCore {
|
|||
}
|
||||
}
|
||||
else {
|
||||
this.infoLogger.logWarning("It seems you are using a very strange version of minecraft or something is " +
|
||||
"seriously wrong with the plugin for getting the version of minecraft.");
|
||||
this.infoLogger.logWarning("It seems you are using a very strange version of Minecraft or something is " +
|
||||
"seriously wrong with the plugin for getting the version of Minecraft.");
|
||||
return maxSupportedVer;
|
||||
}
|
||||
}
|
||||
|
@ -98,54 +106,57 @@ public class AdvancedPortalsCore {
|
|||
|
||||
|
||||
public static String getTranslationName() {
|
||||
return instance.config.getTranslation();
|
||||
return instance.configRepository.getTranslation();
|
||||
}
|
||||
|
||||
private void onEnable() {
|
||||
this.coreListeners = new CoreListeners(this);
|
||||
this.portalManager = new PortalManager(this);
|
||||
this.destiManager = new DestinationManager(this);
|
||||
this.warpEffectRegistry = new WarpEffectRegistry();
|
||||
this.portalTagRegistry = new TagRegistry<>();
|
||||
this.destiTagRegistry = new TagRegistry<>();
|
||||
|
||||
this.dataStorage.copyDefaultFile("lang/en_GB.lang", false);
|
||||
|
||||
this.loadPortalConfig();
|
||||
Lang.loadLanguage(config.getTranslation());
|
||||
|
||||
this.registerPortalCommand();
|
||||
this.registerDestinationCommand();
|
||||
Lang.loadLanguage(configRepository.getTranslation());
|
||||
|
||||
this.portalManager.loadPortals();
|
||||
this.portalServices.loadPortals();
|
||||
|
||||
this.destiManager.loadDestinations();
|
||||
this.destiServices.loadDestinations();
|
||||
|
||||
this.infoLogger.log(Lang.translate("logger.pluginenable"));
|
||||
}
|
||||
|
||||
private void registerPortalCommand() {
|
||||
/**
|
||||
*
|
||||
* @param commandRegister - Handles the command registry, different on each platform
|
||||
*/
|
||||
public void registerCommands(CommandRegister commandRegister) {
|
||||
this.registerPortalCommand(commandRegister);
|
||||
this.registerDestinationCommand(commandRegister);
|
||||
}
|
||||
|
||||
private void registerPortalCommand(CommandRegister commandRegister) {
|
||||
this.portalCommand = new CommandWithSubCommands();
|
||||
|
||||
this.portalCommand.registerSubCommand("version", new VersionSubCommand());
|
||||
this.portalCommand.registerSubCommand("transupdate", new TransUpdateSubCommand(this));
|
||||
this.portalCommand.registerSubCommand("reload", new ReloadSubCommand(this));
|
||||
this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(this), "wand");
|
||||
this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand(this));
|
||||
this.portalCommand.registerSubCommand("endportalblock", new EndPortalBlockSubCommand(this));
|
||||
this.portalCommand.registerSubCommand("endgatewayblock", new EndGatewayBlockSubCommand(this));
|
||||
this.portalCommand.registerSubCommand("transupdate", new TransUpdateSubCommand());
|
||||
this.portalCommand.registerSubCommand("reload", new ReloadSubCommand());
|
||||
this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(), "wand");
|
||||
this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand());
|
||||
this.portalCommand.registerSubCommand("endportalblock", new EndPortalBlockSubCommand());
|
||||
this.portalCommand.registerSubCommand("endgatewayblock", new EndGatewayBlockSubCommand());
|
||||
this.portalCommand.registerSubCommand("create", new CreatePortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("remove", new RemoveSubCommand());
|
||||
|
||||
this.commandRegister.registerCommand("portal", this.portalCommand);
|
||||
commandRegister.registerCommand("portal", this.portalCommand);
|
||||
}
|
||||
|
||||
private void registerDestinationCommand() {
|
||||
private void registerDestinationCommand(CommandRegister commandRegister) {
|
||||
this.destiCommand = new CommandWithSubCommands();
|
||||
|
||||
this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand());
|
||||
|
||||
this.commandRegister.registerCommand("destination", this.destiCommand);
|
||||
commandRegister.registerCommand("destination", this.destiCommand);
|
||||
}
|
||||
|
||||
public static boolean registerDestiSubCommand(String arg, SubCommand subCommand) {
|
||||
|
@ -161,8 +172,8 @@ public class AdvancedPortalsCore {
|
|||
* (basically if values are missing or whatever)
|
||||
*/
|
||||
public void loadPortalConfig() {
|
||||
this.config = this.dataStorage.loadJson(Config.class, "config.json");
|
||||
this.dataStorage.storeJson(this.config, "config.json");
|
||||
this.configRepository.loadConfig(this.dataStorage);
|
||||
this.dataStorage.storeJson(this.configRepository, "config.json");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,32 +187,36 @@ public class AdvancedPortalsCore {
|
|||
return instance;
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return this.config;
|
||||
public ConfigRepository getConfigRepo() {
|
||||
return this.configRepository;
|
||||
}
|
||||
|
||||
public DataStorage getDataStorage() {
|
||||
return this.dataStorage;
|
||||
}
|
||||
|
||||
public static InfoLogger getInfoLogger() {
|
||||
return instance.infoLogger;
|
||||
public InfoLogger getInfoLogger() {
|
||||
return this.infoLogger;
|
||||
}
|
||||
|
||||
public static ConnectorDataCollector getDataCollector() {
|
||||
return instance.dataCollector;
|
||||
public DataCollector getDataCollector() {
|
||||
return this.dataCollector;
|
||||
}
|
||||
|
||||
public static CoreListeners getCoreListeners() {
|
||||
return instance.coreListeners;
|
||||
public CoreListeners getCoreListeners() {
|
||||
return this.coreListeners;
|
||||
}
|
||||
|
||||
public static PortalManager getPortalManager() {
|
||||
return instance.portalManager;
|
||||
public static PortalServices getPortalServices() {
|
||||
return instance.portalServices;
|
||||
}
|
||||
|
||||
public static DestinationManager getDestinationManager() {
|
||||
return instance.destiManager;
|
||||
public static DestinationServices getDestinationServices() {
|
||||
return instance.destiServices;
|
||||
}
|
||||
|
||||
public PortalTempDataServices getPortalTempDataServices() {
|
||||
return instance.portalTempDataServices;
|
||||
}
|
||||
|
||||
public static TagRegistry<AdvancedPortal> getPortalTagRegistry() {
|
||||
|
|
|
@ -1,21 +1,27 @@
|
|||
package com.sekwah.advancedportals.core;
|
||||
|
||||
import com.sekwah.advancedportals.core.data.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.data.PortalLocation;
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.api.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.api.services.PortalTempDataServices;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
import com.sekwah.advancedportals.coreconnector.container.WorldContainer;
|
||||
|
||||
public class CoreListeners {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
@Inject
|
||||
private PortalTempDataServices portalTempDataServices;
|
||||
|
||||
public CoreListeners(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
@Inject
|
||||
private PortalServices portalServices;
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
public void playerJoin(PlayerContainer player) {
|
||||
AdvancedPortalsCore.getPortalManager().activateCooldown(player);
|
||||
this.portalTempDataServices.activateCooldown(player);
|
||||
if(player.isOp()) {
|
||||
if(!Lang.translate("translatedata.lastchange").equals(AdvancedPortalsCore.lastTranslationUpdate)) {
|
||||
player.sendMessage(Lang.translateColor("messageprefix.negative")
|
||||
|
@ -27,11 +33,11 @@ public class CoreListeners {
|
|||
}
|
||||
|
||||
public void teleportEvent(PlayerContainer player) {
|
||||
AdvancedPortalsCore.getPortalManager().activateCooldown(player);
|
||||
this.portalTempDataServices.activateCooldown(player);
|
||||
}
|
||||
|
||||
public void playerLeave(PlayerContainer player) {
|
||||
AdvancedPortalsCore.getPortalManager().playerLeave(player);
|
||||
this.portalTempDataServices.playerLeave(player);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +45,7 @@ public class CoreListeners {
|
|||
* @return if the entity is allowed to spawn
|
||||
*/
|
||||
public boolean mobSpawn(PlayerLocation loc) {
|
||||
return !AdvancedPortalsCore.getPortalManager().inPortalRegion(loc);
|
||||
return !this.portalServices.inPortalRegion(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +55,7 @@ public class CoreListeners {
|
|||
* @return if the player is allowed to move
|
||||
*/
|
||||
public boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
|
||||
return AdvancedPortalsCore.getPortalManager().playerMove(player, fromLoc, toLoc);
|
||||
return this.portalServices.playerMove(player, fromLoc, toLoc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,9 +122,9 @@ public class CoreListeners {
|
|||
public boolean playerInteractWithBlock(PlayerContainer player, String materialName, String itemName,
|
||||
PortalLocation blockLoc, boolean leftClick) {
|
||||
if(itemName != null && (player.isOp() || player.hasPermission("advancedportals.createportal")) &&
|
||||
materialName.equalsIgnoreCase(this.portalsCore.getConfig().getSelectorMaterial())
|
||||
&& (!this.portalsCore.getConfig().getUseOnlySpecialAxe() || itemName.equals("\u00A7ePortal Region Selector"))) {
|
||||
AdvancedPortalsCore.getPortalManager().playerSelectorActivate(player, blockLoc, leftClick);
|
||||
materialName.equalsIgnoreCase(this.portalsCore.getConfigRepo().getSelectorMaterial())
|
||||
&& (!this.portalsCore.getConfigRepo().getUseOnlySpecialAxe() || itemName.equals("\u00A7ePortal Region Selector"))) {
|
||||
this.portalTempDataServices.playerSelectorActivate(player, blockLoc, leftClick);
|
||||
return false;
|
||||
}
|
||||
else if(itemName != null && leftClick && itemName.equals("\u00A75Portal Block Placer") && player.hasPermission("advancedportals.build")) {
|
||||
|
|
|
@ -2,12 +2,11 @@ package com.sekwah.advancedportals.core.api.destination;
|
|||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.api.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.api.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
|
||||
import com.sekwah.advancedportals.core.data.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -56,17 +55,12 @@ public class Destination {
|
|||
|
||||
public boolean activate(PlayerContainer player) {
|
||||
ActivationData data = new ActivationData();
|
||||
try {
|
||||
this.portalActivate(player, data);
|
||||
} catch (PortalException e) {
|
||||
// TODO add portal error message
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.portalActivate(player, data);
|
||||
this.postActivate(player, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean portalActivate(PlayerContainer player, ActivationData data) throws PortalException {
|
||||
public boolean portalActivate(PlayerContainer player, ActivationData data) {
|
||||
TagRegistry<Destination> tagRegistry = AdvancedPortalsCore.getDestinationTagRegistry();
|
||||
DataTag[] destiTags = new DataTag[args.size()];
|
||||
int i = 0;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.sekwah.advancedportals.core.api.effect;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.data.PortalLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
/**
|
||||
|
@ -9,7 +9,7 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
|||
*/
|
||||
public class TestEffect extends WarpEffect {
|
||||
@Override
|
||||
void onWarp(PlayerContainer player, PortalLocation loc, Action action, Type type, AdvancedPortal portal) {
|
||||
protected void onWarp(PlayerContainer player, PortalLocation loc, Action action, Type type, AdvancedPortal portal) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.sekwah.advancedportals.core.api.effect;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.data.PortalLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
|||
*/
|
||||
public abstract class WarpEffect {
|
||||
|
||||
abstract void onWarp(PlayerContainer player, PortalLocation loc, Action action, Type type, AdvancedPortal portal);
|
||||
protected abstract void onWarp(PlayerContainer player, PortalLocation loc, Action action, Type type, AdvancedPortal portal);
|
||||
|
||||
public enum Action {
|
||||
ENTER,
|
||||
|
|
|
@ -1,252 +0,0 @@
|
|||
package com.sekwah.advancedportals.core.api.managers;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
|
||||
import com.sekwah.advancedportals.core.data.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.data.PortalLocation;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* When a player leaves the server any data stored on them is removed to free memory.
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class PortalManager {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
|
||||
/**
|
||||
* Store data of when the player last entered the portal
|
||||
*/
|
||||
private HashMap<String, Long> lastAttempt = new HashMap();
|
||||
|
||||
/**
|
||||
* Tracks the name of portal a player has selected
|
||||
*/
|
||||
private HashMap<String, String> selectedPortal = new HashMap<>();
|
||||
|
||||
private HashMap<String, PortalLocation> portalSelectorLeftClick = new HashMap<>();
|
||||
private HashMap<String, PortalLocation> portalSelectorRightClick = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Contains all the data for the portals
|
||||
*/
|
||||
private HashMap<String, AdvancedPortal> portalHashMap;
|
||||
|
||||
private AdvancedPortal[] portals;
|
||||
|
||||
public PortalManager(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
|
||||
/**
|
||||
* A player has left the server
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public void playerLeave(PlayerContainer player) {
|
||||
this.lastAttempt.remove(player.getUUID().toString());
|
||||
this.selectedPortal.remove(player.getUUID().toString());
|
||||
this.portalSelectorLeftClick.remove(player.getUUID().toString());
|
||||
this.portalSelectorRightClick.remove(player.getUUID().toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the default data into the portals.
|
||||
*/
|
||||
public void loadPortals() {
|
||||
Type type = new TypeToken<HashMap<String, AdvancedPortal>>() {
|
||||
}.getType();
|
||||
this.portalHashMap = this.portalsCore.getDataStorage().loadJson(type, "portals.json");
|
||||
this.savePortals();
|
||||
this.updatePortalArray();
|
||||
}
|
||||
|
||||
public void savePortals() {
|
||||
if (this.portalHashMap == null) {
|
||||
this.portalHashMap = new HashMap<>();
|
||||
}
|
||||
this.portalsCore.getDataStorage().storeJson(this.portalHashMap, "portals.json");
|
||||
}
|
||||
|
||||
public void activateCooldown(PlayerContainer player) {
|
||||
this.lastAttempt.put(player.getUUID().toString(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void playerSelectorActivate(PlayerContainer player, PortalLocation blockLoc, boolean leftClick) {
|
||||
int side = leftClick ? 1 : 2;
|
||||
if(leftClick) {
|
||||
this.portalSelectorLeftClick.put(player.getUUID().toString(), blockLoc);
|
||||
}
|
||||
else {
|
||||
this.portalSelectorRightClick.put(player.getUUID().toString(), blockLoc);
|
||||
}
|
||||
player.sendMessage(Lang.translateInsertVariablesColor("portal.selector.poschange", side, blockLoc.posX,
|
||||
blockLoc.posY, blockLoc.posZ));
|
||||
}
|
||||
|
||||
public boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public AdvancedPortal createPortal(String name, PlayerContainer player, ArrayList<DataTag> tags) throws PortalException {
|
||||
if (this.portalSelectorLeftClick.containsKey(player.getUUID().toString())
|
||||
&& this.portalSelectorRightClick.containsKey(player.getUUID().toString())) {
|
||||
return this.createPortal(name, player, this.portalSelectorLeftClick.get(player.getUUID().toString()),
|
||||
this.portalSelectorRightClick.get(player.getUUID().toString()), tags);
|
||||
} else {
|
||||
throw new PortalException("portal.error.invalidselection");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param loc1
|
||||
* @param loc2
|
||||
* @param tags
|
||||
* @return
|
||||
* @throws PortalException
|
||||
*/
|
||||
public void createPortal(String name, PortalLocation loc1, PortalLocation loc2, ArrayList<DataTag> tags) throws PortalException {
|
||||
createPortal(name, null, loc1, loc2, tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Maybe add detection for overlapping however thats not a major issue for now and portals may overlap inside
|
||||
* solid blocks
|
||||
*
|
||||
* @param player null if no player
|
||||
* @param loc1
|
||||
* @param loc2
|
||||
* @param tags
|
||||
* @throws PortalException
|
||||
*/
|
||||
public AdvancedPortal createPortal(String name, PlayerContainer player, PortalLocation loc1, PortalLocation loc2, ArrayList<DataTag> tags) throws PortalException {
|
||||
|
||||
int maxX = Math.max(loc1.posX, loc2.posX);
|
||||
int maxY = Math.max(loc1.posY, loc2.posY);
|
||||
int maxZ = Math.max(loc1.posZ, loc2.posZ);
|
||||
int minX = Math.min(loc1.posX, loc2.posX);
|
||||
int minY = Math.min(loc1.posY, loc2.posY);
|
||||
int minZ = Math.min(loc1.posZ, loc2.posZ);
|
||||
|
||||
if(!loc1.worldName.equalsIgnoreCase(loc2.worldName)) {
|
||||
throw new PortalException("portal.error.selection.differentworlds");
|
||||
}
|
||||
|
||||
PortalLocation maxLoc = new PortalLocation(loc1.worldName, maxX, maxY, maxZ);
|
||||
PortalLocation minLoc = new PortalLocation(loc1.worldName, minX, minY, minZ);
|
||||
|
||||
if(name == null || name.equals("")) {
|
||||
throw new PortalException("portal.error.noname");
|
||||
}
|
||||
else if(this.portalHashMap.containsKey(name)) {
|
||||
throw new PortalException("portal.error.takenname");
|
||||
}
|
||||
|
||||
AdvancedPortal portal = new AdvancedPortal(maxLoc, minLoc);
|
||||
for(DataTag portalTag : tags) {
|
||||
if(portalTag.NAME.equalsIgnoreCase("triggerblock")) {
|
||||
ArrayList<String> triggers = new ArrayList<>();
|
||||
for(String trigger : portalTag.VALUE.split(",")) {
|
||||
if(AdvancedPortalsCore.getDataCollector().materialExists(trigger)) {
|
||||
triggers.add(trigger.toLowerCase());
|
||||
}
|
||||
}
|
||||
if(triggers.size() != 0) {
|
||||
portal.setTriggerBlocks(triggers.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
portal.setArg(portalTag);
|
||||
}
|
||||
}
|
||||
for(DataTag portalTag : tags) {
|
||||
TagHandler.Creation<AdvancedPortal> creation = AdvancedPortalsCore.getPortalTagRegistry().getCreationHandler(portalTag.NAME);
|
||||
if(creation != null) {
|
||||
creation.created(portal, player, portalTag.VALUE);
|
||||
}
|
||||
}
|
||||
this.portalHashMap.put(name, portal);
|
||||
this.updatePortalArray();
|
||||
AdvancedPortalsCore.getPortalManager().savePortals();
|
||||
return portal;
|
||||
}
|
||||
|
||||
private void updatePortalArray() {
|
||||
Collection<AdvancedPortal> portalValues = this.portalHashMap.values();
|
||||
this.portals = portalValues.toArray(new AdvancedPortal[0]);
|
||||
}
|
||||
|
||||
public void removePlayerSelection(PlayerContainer player) throws PortalException {
|
||||
String portal = this.selectedPortal.get(player.getUUID().toString());
|
||||
if(portal != null) {
|
||||
try {
|
||||
this.removePortal(portal, player);
|
||||
}
|
||||
catch(PortalException e) {
|
||||
if(e.getMessage().equals("command.remove.noname")) {
|
||||
this.selectedPortal.remove(player.getUUID().toString());
|
||||
throw new PortalException("command.remove.invalidselection");
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new PortalException("command.remove.noselection");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param portalName name of portal
|
||||
* @param player null if a player didnt send it
|
||||
* @throws PortalException
|
||||
*/
|
||||
public void removePortal(String portalName, PlayerContainer player) throws PortalException {
|
||||
AdvancedPortal portal = this.getPortal(portalName);
|
||||
if(portal == null) {
|
||||
throw new PortalException("command.remove.noname");
|
||||
}
|
||||
|
||||
for(DataTag portalTag : portal.getArgs()) {
|
||||
TagHandler.Creation<AdvancedPortal> creation = AdvancedPortalsCore.getPortalTagRegistry().getCreationHandler(portalTag.NAME);
|
||||
if(creation != null) {
|
||||
creation.destroyed(portal, player, portalTag.VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
this.portalHashMap.remove(portalName);
|
||||
AdvancedPortalsCore.getPortalManager().savePortals();
|
||||
}
|
||||
|
||||
private AdvancedPortal getPortal(String portalName) {
|
||||
return this.portalHashMap.get(portalName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of portals without a reference to the main array
|
||||
* @return
|
||||
*/
|
||||
public Set<Map.Entry<String, AdvancedPortal>> getPortals() {
|
||||
return this.portalHashMap.entrySet();
|
||||
}
|
||||
|
||||
public boolean inPortalRegion(PlayerLocation loc) {
|
||||
return this.inPortalRegion(loc, 0);
|
||||
}
|
||||
|
||||
private boolean inPortalRegion(PlayerLocation loc, int additionalArea) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,8 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
|||
import com.sekwah.advancedportals.core.api.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.api.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
|
||||
import com.sekwah.advancedportals.core.data.PortalLocation;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -71,23 +72,18 @@ public class AdvancedPortal {
|
|||
for(Map.Entry<String, String> entry : args.entrySet()) {
|
||||
portalTags[i++] = new DataTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
try {
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if(activationHandler != null) {
|
||||
activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME));
|
||||
}
|
||||
}
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if(activationHandler != null) {
|
||||
activationHandler.activated(this, player, data, this.getArg(portalTag.NAME));
|
||||
}
|
||||
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if(activationHandler != null) {
|
||||
activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME));
|
||||
}
|
||||
}
|
||||
catch(PortalException e) {
|
||||
// TODO add portal error message
|
||||
e.printStackTrace();
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if(activationHandler != null) {
|
||||
activationHandler.activated(this, player, data, this.getArg(portalTag.NAME));
|
||||
}
|
||||
}
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package com.sekwah.advancedportals.core.api.portal;
|
||||
|
||||
/**
|
||||
* Returns a message saying what went wrong with the portal or the action was blocked for a reason.
|
||||
*/
|
||||
public class PortalException extends Exception {
|
||||
public PortalException(String reason) {
|
||||
super(reason);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.sekwah.advancedportals.core.api.registry;
|
|||
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -24,6 +25,8 @@ public class SubCommandRegistry {
|
|||
*/
|
||||
protected ArrayList<String> subCommands = new ArrayList<>();
|
||||
|
||||
private InfoLogger infoLogger = AdvancedPortalsCore.getInstance().getInfoLogger();
|
||||
|
||||
/**
|
||||
* @param arg argument needed to activate
|
||||
* @param subCommand
|
||||
|
@ -32,12 +35,12 @@ public class SubCommandRegistry {
|
|||
public boolean registerSubCommand(String arg, SubCommand subCommand) {
|
||||
|
||||
if (subCommand == null) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("The subcommand '" + arg + "' cannot be null.");
|
||||
this.infoLogger.logWarning("The subcommand '" + arg + "' cannot be null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(this.subCommandMap.containsKey(arg)){
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("The subcommand '" + arg + "' already exists.");
|
||||
this.infoLogger.logWarning("The subcommand '" + arg + "' already exists.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sekwah.advancedportals.core.api.registry;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
|
||||
|
||||
|
@ -16,6 +17,9 @@ import java.util.Map;
|
|||
*/
|
||||
public class TagRegistry<T> {
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
/**
|
||||
* List of tag names which should be in order alphabetically
|
||||
*/
|
||||
|
@ -79,12 +83,12 @@ public class TagRegistry<T> {
|
|||
*/
|
||||
public boolean registerTag(String tag) {
|
||||
if (tag.contains(" ")) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("The tag '"
|
||||
this.portalsCore.getInfoLogger().logWarning("The tag '"
|
||||
+ tag + "' is invalid as it contains spaces.");
|
||||
return false;
|
||||
}
|
||||
if (this.tags.contains(tag)) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("The tag "
|
||||
this.portalsCore.getInfoLogger().logWarning("The tag "
|
||||
+ tag + " has already been registered.");
|
||||
return false;
|
||||
}
|
||||
|
@ -129,7 +133,7 @@ public class TagRegistry<T> {
|
|||
public boolean registerTag(String tag, Object tagHandler) {
|
||||
|
||||
if (tag == null) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("A tag cannot be null.");
|
||||
this.portalsCore.getInfoLogger().logWarning("A tag cannot be null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sekwah.advancedportals.core.api.registry;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.effect.WarpEffect;
|
||||
|
||||
|
@ -16,6 +17,9 @@ public class WarpEffectRegistry {
|
|||
|
||||
private Map<String, WarpEffect> soundEffects = new HashMap();
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
/**
|
||||
* Register a new warp effect.
|
||||
*
|
||||
|
@ -36,7 +40,7 @@ public class WarpEffectRegistry {
|
|||
list = this.visualEffects;
|
||||
break;
|
||||
default:
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning(type.toString()
|
||||
this.portalsCore.getInfoLogger().logWarning(type.toString()
|
||||
+ " effect type not recognised");
|
||||
return false;
|
||||
}
|
||||
|
@ -57,7 +61,7 @@ public class WarpEffectRegistry {
|
|||
list = this.visualEffects;
|
||||
break;
|
||||
default:
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning(type.toString()
|
||||
this.portalsCore.getInfoLogger().logWarning(type.toString()
|
||||
+ " effect type not recognised");
|
||||
return null;
|
||||
}
|
||||
|
@ -65,7 +69,7 @@ public class WarpEffectRegistry {
|
|||
return list.get(name);
|
||||
}
|
||||
else{
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("No effect of type:"
|
||||
this.portalsCore.getInfoLogger().logWarning("No effect of type:"
|
||||
+ type.toString() + " was registered with the name: " + name);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.sekwah.advancedportals.core.api.services;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.ArrayList; /**
|
||||
* https://github.com/sekwah41/Advanced-Portals/blob/24175610892152828e21f4ff824eb1589ccb0338/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java
|
||||
* Based off the old manager with the data storage and handling moved to {@link com.sekwah.advancedportals.core.repository.DestinationRepository}
|
||||
*/
|
||||
public final class DestinationServices {
|
||||
|
||||
/**
|
||||
*/
|
||||
public void loadDestinations() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param player
|
||||
* @param loc
|
||||
* @param destiTags
|
||||
* @return null if not created
|
||||
*/
|
||||
public Destination createDesti(String name, PlayerContainer player, PlayerLocation loc, ArrayList<DataTag> destiTags) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.sekwah.advancedportals.core.api.services;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* https://github.com/sekwah41/Advanced-Portals/blob/24175610892152828e21f4ff824eb1589ccb0338/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java
|
||||
*
|
||||
* Based off the old manager with the data storage and handling moved to {@link com.sekwah.advancedportals.core.repository.PortalRepository}
|
||||
*
|
||||
* Excluding the temp data like selections
|
||||
*/
|
||||
public final class PortalServices {
|
||||
|
||||
|
||||
|
||||
public void loadPortals() {
|
||||
|
||||
}
|
||||
|
||||
public boolean inPortalRegion(PlayerLocation loc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImmutableList<? extends Map.Entry<String, AdvancedPortal>> getPortals() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean removePortal(String name, PlayerContainer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public AdvancedPortal createPortal(String name, PlayerContainer player, ArrayList<DataTag> portalTags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean removePlayerSelection(PlayerContainer player) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.sekwah.advancedportals.core.api.services;
|
||||
|
||||
import com.sekwah.advancedportals.core.entities.PlayerTempData;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PortalTempDataServices {
|
||||
|
||||
/**
|
||||
* Possibly change to the cache map Aztec was talking about
|
||||
*/
|
||||
private Map<UUID, PlayerTempData> tempDataMap = new HashMap<>();
|
||||
|
||||
public void activateCooldown(PlayerContainer player) {
|
||||
}
|
||||
|
||||
public void playerLeave(PlayerContainer player) {
|
||||
}
|
||||
|
||||
public void playerSelectorActivate(PlayerContainer player, PortalLocation blockLoc, boolean leftClick) {
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.sekwah.advancedportals.core.api.warphandler;
|
||||
|
||||
|
||||
import com.sekwah.advancedportals.core.data.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
|
||||
/**
|
||||
* Created by on 30/07/2016.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.sekwah.advancedportals.core.api.warphandler;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
/**
|
||||
|
@ -27,18 +26,16 @@ public interface TagHandler {
|
|||
*
|
||||
* @param player if null then created by the server or a plugin
|
||||
* @param argData
|
||||
* @throws PortalException message given is the reason the portal (or destination) cannot be made
|
||||
*/
|
||||
void created(T target, PlayerContainer player, String argData) throws PortalException;
|
||||
void created(T target, PlayerContainer player, String argData);
|
||||
|
||||
/**
|
||||
* Example if the player does not have access to remove the portal or destination.
|
||||
*
|
||||
* @param player if null then removed by the server or a plugin
|
||||
* @param argData
|
||||
* @throws PortalException message given is the reason the portal cant be removed
|
||||
*/
|
||||
void destroyed(T target, PlayerContainer player, String argData) throws PortalException;
|
||||
void destroyed(T target, PlayerContainer player, String argData);
|
||||
|
||||
}
|
||||
|
||||
|
@ -68,11 +65,13 @@ public interface TagHandler {
|
|||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
*
|
||||
* @return If the tag has allowed the warp
|
||||
*/
|
||||
void preActivated(T target, PlayerContainer player, ActivationData activeData, String argData) throws PortalException;
|
||||
boolean preActivated(T target, PlayerContainer player, ActivationData activeData, String argData);
|
||||
|
||||
/**
|
||||
* Activates after activation
|
||||
* Activates after activation, should be used for actions such as removing money for a teleport.
|
||||
*
|
||||
* Any actions to do with player location should be done in activate
|
||||
*
|
||||
|
@ -88,11 +87,15 @@ public interface TagHandler {
|
|||
* You should do some second checks if it can be dependent on the preActivate, the destination tags will also be
|
||||
* triggered here if a desti is listed.
|
||||
*
|
||||
* (You can still cancel here but it is advised to check properly in preActive)
|
||||
*
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
*
|
||||
* @return If the tag has allowed the warp
|
||||
*/
|
||||
void activated(T target, PlayerContainer player, ActivationData activeData, String argData) throws PortalException;
|
||||
boolean activated(T target, PlayerContainer player, ActivationData activeData, String argData);
|
||||
|
||||
}
|
||||
|
||||
|
@ -105,7 +108,7 @@ public interface TagHandler {
|
|||
* @param argData
|
||||
* @return if the tag will be added.
|
||||
*/
|
||||
boolean tagAdded(T target, PlayerContainer player, String argData) throws PortalException;
|
||||
boolean tagAdded(T target, PlayerContainer player, String argData);
|
||||
|
||||
/**
|
||||
* If the user has access to remove the tag (this does not include being added on destruction)
|
||||
|
@ -114,7 +117,7 @@ public interface TagHandler {
|
|||
* @param argData
|
||||
* @return if the tag will be removed.
|
||||
*/
|
||||
boolean tagRemoved(T target, PlayerContainer player, String argData) throws PortalException;
|
||||
boolean tagRemoved(T target, PlayerContainer player, String argData);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -144,6 +144,9 @@ public class CommandWithSubCommands implements CommandTemplate {
|
|||
}
|
||||
|
||||
public List<String> filterTabResults(List<String> tabList, String lastArg) {
|
||||
if(tabList == null) {
|
||||
return null;
|
||||
}
|
||||
for(String arg : tabList.toArray(new String[0])) {
|
||||
if(!arg.startsWith(lastArg.toLowerCase())) {
|
||||
tabList.remove(arg);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.sekwah.advancedportals.core.commands.subcommands;
|
||||
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
|
@ -3,9 +3,8 @@ package com.sekwah.advancedportals.core.commands.subcommands.desti;
|
|||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.api.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.CreateSubCommand;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
@ -24,24 +23,22 @@ public class CreateDestiSubCommand extends CreateSubCommand implements SubComman
|
|||
return;
|
||||
}
|
||||
ArrayList<DataTag> destiTags = this.getTagsFromArgs(args);
|
||||
try {
|
||||
Destination desti = AdvancedPortalsCore.getDestinationManager().createDesti(args[1], player, player.getLoc(), destiTags);
|
||||
if(desti != null) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.createdesti.complete"));
|
||||
sender.sendMessage(Lang.translateColor("command.create.tags"));
|
||||
ArrayList<DataTag> destiArgs = desti.getArgs();
|
||||
if(destiArgs.size() == 0) {
|
||||
sender.sendMessage(Lang.translateColor("desti.info.noargs"));
|
||||
}
|
||||
else {
|
||||
for (DataTag tag : destiArgs) {
|
||||
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUE);
|
||||
}
|
||||
Destination desti = AdvancedPortalsCore.getDestinationServices().createDesti(args[1], player, player.getLoc(), destiTags);
|
||||
if(desti != null) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.createdesti.complete"));
|
||||
sender.sendMessage(Lang.translateColor("command.create.tags"));
|
||||
ArrayList<DataTag> destiArgs = desti.getArgs();
|
||||
if(destiArgs.size() == 0) {
|
||||
sender.sendMessage(Lang.translateColor("desti.info.noargs"));
|
||||
}
|
||||
else {
|
||||
for (DataTag tag : destiArgs) {
|
||||
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUE);
|
||||
}
|
||||
}
|
||||
} catch (PortalException portalTagExeption) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.createdesti.error") + " "
|
||||
+ Lang.translate(portalTagExeption.getMessage()));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.createdesti.error"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -3,9 +3,8 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
|||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.CreateSubCommand;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
@ -25,21 +24,17 @@ public class CreatePortalSubCommand extends CreateSubCommand implements SubComma
|
|||
return;
|
||||
}
|
||||
ArrayList<DataTag> portalTags = this.getTagsFromArgs(args);
|
||||
try {
|
||||
System.out.println(Arrays.toString(portalTags.toArray()));
|
||||
AdvancedPortal portal = AdvancedPortalsCore.getPortalManager().createPortal(args[1], player, portalTags);
|
||||
if(portal != null) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.create.complete"));
|
||||
sender.sendMessage(Lang.translateColor("command.create.tags"));
|
||||
sender.sendMessage("\u00A7a" + "triggerBlock\u00A77:\u00A7e" + Arrays.toString(portal.getTriggerBlocks()));
|
||||
for (DataTag tag: portal.getArgs()) {
|
||||
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUE);
|
||||
}
|
||||
|
||||
AdvancedPortal portal = AdvancedPortalsCore.getPortalServices().createPortal(args[1], player, portalTags);
|
||||
if(portal != null) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.create.complete"));
|
||||
sender.sendMessage(Lang.translateColor("command.create.tags"));
|
||||
sender.sendMessage("\u00A7a" + "triggerBlock\u00A77:\u00A7e" + Arrays.toString(portal.getTriggerBlocks()));
|
||||
for (DataTag tag: portal.getArgs()) {
|
||||
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUE);
|
||||
}
|
||||
} catch (PortalException portalTagExeption) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " "
|
||||
+ Lang.translate(portalTagExeption.getMessage()));
|
||||
}
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error"));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.error.noname"));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
@ -10,11 +11,8 @@ import java.util.List;
|
|||
|
||||
public class EndGatewayBlockSubCommand implements SubCommand {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
|
||||
public EndGatewayBlockSubCommand(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
@ -10,11 +11,8 @@ import java.util.List;
|
|||
|
||||
public class EndPortalBlockSubCommand implements SubCommand {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
|
||||
public EndPortalBlockSubCommand(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
@ -10,11 +11,9 @@ import java.util.List;
|
|||
|
||||
public class PortalBlockSubCommand implements SubCommand {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
public PortalBlockSubCommand(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
@ -9,17 +10,14 @@ import java.util.List;
|
|||
|
||||
public class ReloadSubCommand implements SubCommand {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
|
||||
public ReloadSubCommand(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
portalsCore.loadPortalConfig();
|
||||
portalsCore.getPortalManager().loadPortals();
|
||||
portalsCore.getDestinationManager().loadDestinations();
|
||||
portalsCore.getPortalServices().loadPortals();
|
||||
portalsCore.getDestinationServices().loadDestinations();
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded"));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
|||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
@ -18,12 +17,12 @@ public class RemoveSubCommand implements SubCommand {
|
|||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if(args.length > 1) {
|
||||
try {
|
||||
AdvancedPortalsCore.getPortalManager().removePortal(args[1], sender.getPlayerContainer());
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.remove.complete"));
|
||||
} catch (PortalException portalTagExeption) {
|
||||
if(AdvancedPortalsCore.getPortalServices().removePortal(args[1], sender.getPlayerContainer())) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.remove.complete"));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative")
|
||||
+ Lang.translateColor("command.remove.error") + " " + Lang.translate(portalTagExeption.getMessage()));
|
||||
+ Lang.translateColor("command.remove.error"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -32,12 +31,14 @@ public class RemoveSubCommand implements SubCommand {
|
|||
sender.sendMessage(Lang.translate("command.remove.noname"));
|
||||
}
|
||||
else {
|
||||
try {
|
||||
AdvancedPortalsCore.getPortalManager().removePlayerSelection(player);
|
||||
} catch (PortalException portalTagExeption) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative")
|
||||
+ Lang.translateColor("command.remove.error") + " " + Lang.translate(portalTagExeption.getMessage()));
|
||||
if(AdvancedPortalsCore.getPortalServices().removePlayerSelection(player)) {
|
||||
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative")
|
||||
+ Lang.translateColor("command.remove.error"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +51,7 @@ public class RemoveSubCommand implements SubCommand {
|
|||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
List<String> portalNames = new ArrayList<>();
|
||||
for(Map.Entry<String, AdvancedPortal> portal : AdvancedPortalsCore.getPortalManager().getPortals()) {
|
||||
for(Map.Entry<String, AdvancedPortal> portal : AdvancedPortalsCore.getPortalServices().getPortals()) {
|
||||
portalNames.add(portal.getKey());
|
||||
}
|
||||
Collections.sort(portalNames);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
@ -10,11 +11,8 @@ import java.util.List;
|
|||
|
||||
public class SelectorSubCommand implements SubCommand {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
|
||||
public SelectorSubCommand(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
|
@ -23,7 +21,7 @@ public class SelectorSubCommand implements SubCommand {
|
|||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.playeronly"));
|
||||
}
|
||||
else {
|
||||
player.giveItem(this.portalsCore.getConfig().getSelectorMaterial(), "\u00A7ePortal Region Selector"
|
||||
player.giveItem(this.portalsCore.getConfigRepo().getSelectorMaterial(), "\u00A7ePortal Region Selector"
|
||||
, "\u00A7rThis wand with has the power to help", "\u00A7r create portals bistowed upon it!");
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("command.selector"));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
@ -9,10 +10,10 @@ import java.util.List;
|
|||
|
||||
public class TransUpdateSubCommand implements SubCommand {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
public TransUpdateSubCommand(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
public TransUpdateSubCommand() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,45 +5,30 @@ package com.sekwah.advancedportals.core.config;
|
|||
*/
|
||||
public class Config {
|
||||
|
||||
private boolean useOnlySpecialAxe = true;
|
||||
public boolean useOnlySpecialAxe = true;
|
||||
|
||||
private String selectorMaterial = "IRON_AXE";
|
||||
public String selectorMaterial = "IRON_AXE";
|
||||
|
||||
private boolean portalProtection = true;
|
||||
public boolean portalProtection = true;
|
||||
|
||||
private int portalProtectionRaduis = 5;
|
||||
public int portalProtectionRaduis = 5;
|
||||
|
||||
private String defaultTriggerBlock = "PORTAL";
|
||||
public String defaultTriggerBlock = "PORTAL";
|
||||
|
||||
private boolean stopWaterFlow = true;
|
||||
public boolean stopWaterFlow = true;
|
||||
|
||||
private int portalCooldown = 5;
|
||||
public int portalCooldown = 5;
|
||||
|
||||
private String warpParticles = "ENDER";
|
||||
public String warpParticles = "ENDER";
|
||||
|
||||
private String warpSound = "ENDER";
|
||||
public String warpSound = "ENDER";
|
||||
|
||||
private String selectionBlock_BELOW_1_13 = "STAINED_GLASS";
|
||||
public String selectionBlock_BELOW_1_13 = "STAINED_GLASS";
|
||||
|
||||
private String selectionBlock = "RED_STAINED_GLASS";
|
||||
public String selectionBlock = "RED_STAINED_GLASS";
|
||||
|
||||
private String translationFile = "en_GB";
|
||||
public String translationFile = "en_GB";
|
||||
|
||||
private int selectionSubID_BELOW_1_13 = 14;
|
||||
public int selectionSubID_BELOW_1_13 = 14;
|
||||
|
||||
public boolean getUseOnlySpecialAxe() {
|
||||
return useOnlySpecialAxe;
|
||||
}
|
||||
|
||||
public void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe) {
|
||||
useOnlySpecialAxe = useOnlyServerMadeAxe;
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
return translationFile;
|
||||
}
|
||||
|
||||
public String getSelectorMaterial() {
|
||||
return selectorMaterial;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package com.sekwah.advancedportals.core.config;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.repository.*;
|
||||
|
||||
public class RepositoryModule extends AbstractModule {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
|
||||
public RepositoryModule(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(PortalRepository.class).to(PortalRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(DestinationRepository.class).to(DestinationRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(PortalTempDataRepository.class).to(PortalTempDataRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(ConfigRepository.class).to(ConfigRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
@Provides
|
||||
AdvancedPortalsCore providePortalsCore() {
|
||||
return this.portalsCore;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.sekwah.advancedportals.core.data;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -9,13 +10,15 @@ import java.lang.reflect.Type;
|
|||
|
||||
public class DataStorage {
|
||||
|
||||
private Gson gson;
|
||||
private Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private File dataFolder;
|
||||
|
||||
public DataStorage(File dataFolder) {
|
||||
this.dataFolder = dataFolder;
|
||||
gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
public DataStorage(File dataStorageLoc) {
|
||||
this.dataFolder = dataStorageLoc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +86,7 @@ public class DataStorage {
|
|||
}
|
||||
if (!outFile.exists() || overwrite) {
|
||||
try {
|
||||
InputStream inputStream = DataStorage.class.getResourceAsStream(fileLoc);
|
||||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(fileLoc);
|
||||
if(inputStream == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -99,15 +102,15 @@ public class DataStorage {
|
|||
outStream.close();
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("Could not load " + fileLoc + ". The file does" +
|
||||
this.portalsCore.getInfoLogger().logWarning("Could not load " + fileLoc + ". The file does" +
|
||||
"not exist or there has been an error reading the file.");
|
||||
return false;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("Could not create " + fileLoc);
|
||||
this.portalsCore.getInfoLogger().logWarning("Could not create " + fileLoc);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("File error reading " + fileLoc);
|
||||
this.portalsCore.getInfoLogger().logWarning("File error reading " + fileLoc);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -116,8 +119,6 @@ public class DataStorage {
|
|||
/**
|
||||
* A method to try to grab the files from the plugin and if its in the plugin folder load from there instead.
|
||||
* <p>
|
||||
* TODO add loading from the plugin folder first rather than straight from the plugin.
|
||||
*
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
|
@ -136,7 +137,7 @@ public class DataStorage {
|
|||
return this.getClass().getClassLoader().getResourceAsStream(location);
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("Could not load " + location + ". The file does" +
|
||||
this.portalsCore.getInfoLogger().logWarning("Could not load " + location + ". The file does" +
|
||||
"not exist or there has been an error reading the file.");
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.sekwah.advancedportals.core.api.portal;
|
||||
package com.sekwah.advancedportals.core.entities;
|
||||
|
||||
public class DataTag {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.sekwah.advancedportals.core.data;
|
||||
package com.sekwah.advancedportals.core.entities;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.sekwah.advancedportals.core.entities;
|
||||
|
||||
public class PlayerTempData {
|
||||
|
||||
private PortalLocation pos1;
|
||||
|
||||
private PortalLocation pos2;
|
||||
|
||||
private long lastAttempt;
|
||||
|
||||
private String selectedPortal;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.sekwah.advancedportals.core.data;
|
||||
package com.sekwah.advancedportals.core.entities;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.sekwah.advancedportals.core.data.DataStorage;
|
||||
|
||||
public interface ConfigRepository {
|
||||
|
||||
boolean getUseOnlySpecialAxe();
|
||||
|
||||
void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe);
|
||||
|
||||
String getTranslation();
|
||||
|
||||
String getSelectorMaterial();
|
||||
|
||||
void loadConfig(DataStorage dataStorage);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.config.Config;
|
||||
import com.sekwah.advancedportals.core.data.DataStorage;
|
||||
|
||||
@Singleton
|
||||
public class ConfigRepositoryImpl implements ConfigRepository {
|
||||
|
||||
private Config config;
|
||||
|
||||
public boolean getUseOnlySpecialAxe() {
|
||||
return this.config.useOnlySpecialAxe;
|
||||
}
|
||||
|
||||
public void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe) {
|
||||
this.config.useOnlySpecialAxe = useOnlyServerMadeAxe;
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
return this.config.translationFile;
|
||||
}
|
||||
|
||||
public String getSelectorMaterial() {
|
||||
return this.config.selectorMaterial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig(DataStorage dataStorage) {
|
||||
this.config = dataStorage.loadJson(Config.class, "config.json");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.sekwah.advancedportals.core.api.destination.Destination;
|
||||
|
||||
public interface DestinationRepository {
|
||||
void create(String name, Destination destination);
|
||||
|
||||
void delete(String name);
|
||||
|
||||
ImmutableMap<String, Destination> getDestinations();
|
||||
|
||||
void loadDestinations();
|
||||
}
|
|
@ -1,39 +1,54 @@
|
|||
package com.sekwah.advancedportals.core.api.managers;
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
|
||||
import com.sekwah.advancedportals.core.data.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.entities.DataTag;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class DestinationManager {
|
||||
@Singleton
|
||||
public class DestinationRepositoryImpl implements DestinationRepository {
|
||||
private Map<String, Destination> destiHashMap = new HashMap<>();
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
/**
|
||||
* Contains all the data for the destinations
|
||||
*/
|
||||
private HashMap<String, Destination> destiHashMap = new HashMap<>();
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
public DestinationManager(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
@Override
|
||||
public void create(String name, Destination destination) {
|
||||
destiHashMap.put(name, destination);
|
||||
}
|
||||
|
||||
public Destination createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> tags) throws PortalException {
|
||||
@Override
|
||||
public void delete(String name) {
|
||||
destiHashMap.remove(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, Destination> getDestinations() {
|
||||
return ImmutableMap.copyOf(destiHashMap);
|
||||
}
|
||||
|
||||
|
||||
public Destination createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> tags) {
|
||||
// TODO change to write messages
|
||||
if(name == null || name.equals("")) {
|
||||
throw new PortalException("desti.error.noname");
|
||||
player.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("desti.error.noname"));
|
||||
return null;
|
||||
}
|
||||
else if(this.destiHashMap.containsKey(name)) {
|
||||
throw new PortalException("desti.error.takenname");
|
||||
player.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translate("desti.error.takenname"));
|
||||
return null;
|
||||
}
|
||||
|
||||
Destination desti = new Destination(playerLocation);
|
||||
|
@ -47,12 +62,10 @@ public class DestinationManager {
|
|||
}
|
||||
}
|
||||
this.destiHashMap.put(name, desti);
|
||||
AdvancedPortalsCore.getDestinationManager().saveDestinations();
|
||||
this.saveDestinations();
|
||||
return desti;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void loadDestinations() {
|
||||
Type type = new TypeToken<HashMap<String, Destination>>() {
|
||||
}.getType();
|
|
@ -0,0 +1,13 @@
|
|||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
public interface PortalRepository {
|
||||
|
||||
void loadPortals();
|
||||
|
||||
void savePortals();
|
||||
|
||||
boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
@Singleton
|
||||
public class PortalRepositoryImpl implements PortalRepository {
|
||||
@Override
|
||||
public void loadPortals() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePortals() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface PortalTempDataRepository {
|
||||
void addSelectedPortal(UUID selectedPlayer, String portal);
|
||||
|
||||
void removeSelectedPortal(UUID uuid);
|
||||
|
||||
void addSelectedPosition(UUID uuid, boolean isPos1, PortalLocation portalLocation);
|
||||
|
||||
void removeSelectedPosition(UUID uuid, boolean isPos1);
|
||||
|
||||
void removeAllSelectedHand(UUID uuid);
|
||||
|
||||
void activateCooldown(PlayerContainer player);
|
||||
|
||||
void playerLeave(PlayerContainer player);
|
||||
|
||||
boolean inPortalRegion(PlayerLocation loc);
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table;
|
||||
import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Singleton
|
||||
public class PortalTempDataRepositoryImpl implements PortalTempDataRepository {
|
||||
Cache<UUID, String> selectedPortal = CacheBuilder.newBuilder()
|
||||
.concurrencyLevel(4)
|
||||
.expireAfterAccess(30, TimeUnit.DAYS)
|
||||
.build();
|
||||
|
||||
Table<UUID, Boolean, PortalLocation> selectedPositions = HashBasedTable.create();
|
||||
|
||||
@Override
|
||||
public void addSelectedPortal(UUID selectedPlayer, String portal) {
|
||||
selectedPortal.put(selectedPlayer, portal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSelectedPortal(UUID uuid) {
|
||||
selectedPortal.invalidate(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSelectedPosition(UUID uuid, boolean isPos1, PortalLocation portalLocation) {
|
||||
selectedPositions.put(uuid, isPos1, portalLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSelectedPosition(UUID uuid, boolean isPos1) {
|
||||
selectedPositions.remove(uuid, isPos1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllSelectedHand(UUID uuid) {
|
||||
selectedPositions.remove(uuid, true);
|
||||
selectedPositions.remove(uuid, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateCooldown(PlayerContainer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerLeave(PlayerContainer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inPortalRegion(PlayerLocation loc) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -76,7 +76,7 @@ public class Lang {
|
|||
}
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("Could not load " + fileName + ".lang The file does" +
|
||||
AdvancedPortalsCore.getInstance().getInfoLogger().logWarning("Could not load " + fileName + ".lang The file does" +
|
||||
"not exist or there has been an error reading the file. Canceled loading language file.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package com.sekwah.advancedportals.coreconnector;
|
||||
|
||||
/**
|
||||
* Gets info from the specific implementation
|
||||
*/
|
||||
public class ConnectorDataCollector {
|
||||
public boolean materialExists(String materialName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.sekwah.advancedportals.coreconnector.command;
|
||||
|
||||
|
||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||
|
||||
public abstract class CommandHandler {
|
||||
|
||||
|
||||
private final CommandTemplate commandExecutor;
|
||||
|
||||
public CommandHandler(CommandTemplate commandExecutor) {
|
||||
this.commandExecutor = commandExecutor;
|
||||
}
|
||||
}
|
|
@ -2,17 +2,13 @@ package com.sekwah.advancedportals.coreconnector.command;
|
|||
|
||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||
|
||||
/**
|
||||
* Register the CommandTemplate files to the appropriate system
|
||||
*/
|
||||
public class CommandRegister {
|
||||
public interface CommandRegister {
|
||||
|
||||
/**
|
||||
* Registers the command to the appropriate system
|
||||
* @param commandName
|
||||
* @param commandExecutor
|
||||
*/
|
||||
public void registerCommand(String commandName, CommandTemplate commandExecutor) {
|
||||
void registerCommand(String commandName, CommandTemplate commandExecutor);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
package com.sekwah.advancedportals.coreconnector.container;
|
||||
|
||||
public class CommandSenderContainer {
|
||||
public void sendMessage(String message) {
|
||||
}
|
||||
public interface CommandSenderContainer {
|
||||
|
||||
public boolean isOp() {
|
||||
return false;
|
||||
}
|
||||
void sendMessage(String message);
|
||||
|
||||
boolean isOp();
|
||||
|
||||
/**
|
||||
* @return null if there isnt a player e.g. the console
|
||||
*/
|
||||
public PlayerContainer getPlayerContainer() {
|
||||
return null;
|
||||
}
|
||||
PlayerContainer getPlayerContainer();
|
||||
|
||||
boolean hasPermission(String permission);
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,48 +1,36 @@
|
|||
package com.sekwah.advancedportals.coreconnector.container;
|
||||
|
||||
import com.sekwah.advancedportals.core.data.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.data.PortalLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Just a temporary container for whenever advanced portals needs to get data from a player
|
||||
*/
|
||||
public class PlayerContainer {
|
||||
public interface PlayerContainer {
|
||||
|
||||
public UUID getUUID() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {}
|
||||
UUID getUUID();
|
||||
|
||||
public boolean isOp() {
|
||||
return false;
|
||||
}
|
||||
public void sendMessage(String message);
|
||||
|
||||
public PlayerLocation getLoc() {
|
||||
return null;
|
||||
}
|
||||
boolean isOp();
|
||||
|
||||
public double getEyeHeight() {
|
||||
return 0;
|
||||
}
|
||||
PlayerLocation getLoc();
|
||||
|
||||
public void teleport(PlayerLocation location) {}
|
||||
double getEyeHeight();
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return false;
|
||||
}
|
||||
void teleport(PlayerLocation location);
|
||||
|
||||
public WorldContainer getWorld() {return null;}
|
||||
boolean hasPermission(String permission);
|
||||
|
||||
WorldContainer getWorld();
|
||||
|
||||
/**
|
||||
* @param blockPos
|
||||
* @param material
|
||||
*/
|
||||
public void sendFakeBlock(PortalLocation blockPos, String material) {
|
||||
|
||||
}
|
||||
void sendFakeBlock(PortalLocation blockPos, String material);
|
||||
|
||||
/**
|
||||
* Only 1.12 and below supported
|
||||
|
@ -50,11 +38,9 @@ public class PlayerContainer {
|
|||
* @param material
|
||||
* @param data
|
||||
*/
|
||||
public void sendFakeBlockWithData(PortalLocation blockPos, String material, byte data) {
|
||||
void sendFakeBlockWithData(PortalLocation blockPos, String material, byte data);
|
||||
|
||||
}
|
||||
void giveWool(String dyeColor, String itemName, String... itemDescription);
|
||||
|
||||
public void giveItem(String material, String itemName, String... itemDescription) {}
|
||||
|
||||
public void giveWool(String dyeColor, String itemName, String... itemDescription) {}
|
||||
void giveItem(String material, String itemName, String... itemDescription);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.sekwah.advancedportals.coreconnector.container;
|
||||
|
||||
public interface ServerContainer {
|
||||
|
||||
WorldContainer getWorld(String name);
|
||||
|
||||
}
|
|
@ -1,20 +1,14 @@
|
|||
package com.sekwah.advancedportals.coreconnector.container;
|
||||
|
||||
import com.sekwah.advancedportals.core.data.PortalLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
|
||||
public class WorldContainer {
|
||||
public interface WorldContainer {
|
||||
|
||||
public void setBlock(PortalLocation location, String material) {
|
||||
}
|
||||
void setBlock(PortalLocation location, String material);
|
||||
|
||||
public void setBlockData(PortalLocation location, byte data) {
|
||||
}
|
||||
void setBlockData(PortalLocation location, byte data);
|
||||
|
||||
public String getBlock(PortalLocation location) {
|
||||
return "";
|
||||
}
|
||||
String getBlock(PortalLocation location);
|
||||
|
||||
public byte getBlockData(PortalLocation location) {
|
||||
return 0;
|
||||
}
|
||||
byte getBlockData(PortalLocation location);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.sekwah.advancedportals.coreconnector.info;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Gets info from the specific implementation
|
||||
*/
|
||||
public interface DataCollector {
|
||||
|
||||
boolean materialExists(String materialName);
|
||||
|
||||
List<String> getMaterials();
|
||||
|
||||
}
|
|
@ -0,0 +1,661 @@
|
|||
package com.sekwah.advancedportals.metrics;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
*
|
||||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
public class Metrics {
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
||||
final String defaultPackage = new String(
|
||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
// The plugin
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
// A list with all custom charts
|
||||
private final List<CustomChart> charts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param plugin The plugin which stats should be submitted.
|
||||
*/
|
||||
public Metrics(JavaPlugin plugin) {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
|
||||
// Get the config file
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
// Check if the config file exists
|
||||
if (!config.isSet("serverUuid")) {
|
||||
|
||||
// Add default values
|
||||
config.addDefault("enabled", true);
|
||||
// Every server gets it's unique random id.
|
||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||
// Should failed request be logged?
|
||||
config.addDefault("logFailedRequests", false);
|
||||
|
||||
// Inform the server owners about bStats
|
||||
config.options().header(
|
||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
||||
"To honor their work, you should not disable it.\n" +
|
||||
"This has nearly no effect on the server performance!\n" +
|
||||
"Check out https://bStats.org/ to learn more :)"
|
||||
).copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
// Load the data
|
||||
serverUUID = config.getString("serverUuid");
|
||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||
if (config.getBoolean("enabled", true)) {
|
||||
boolean found = false;
|
||||
// Search for all other bStats Metrics classes to see if we are the first one
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
found = true; // We aren't the first
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
// Register our service
|
||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
||||
if (!found) {
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
if (chart == null) {
|
||||
throw new IllegalArgumentException("Chart cannot be null!");
|
||||
}
|
||||
charts.add(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Scheduler which submits our data every 30 minutes.
|
||||
*/
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
submitData();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 1000*60*5, 1000*60*30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin specific data.
|
||||
* This method is called using Reflection.
|
||||
*
|
||||
* @return The plugin specific data.
|
||||
*/
|
||||
public JSONObject getPluginData() {
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
String pluginName = plugin.getDescription().getName();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
JSONArray customCharts = new JSONArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
JSONObject chart = customChart.getRequestJsonObject();
|
||||
if (chart == null) { // If the chart is null, we skip it
|
||||
continue;
|
||||
}
|
||||
customCharts.add(chart);
|
||||
}
|
||||
data.put("customCharts", customCharts);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server specific data.
|
||||
*
|
||||
* @return The server specific data.
|
||||
*/
|
||||
private JSONObject getServerData() {
|
||||
// Minecraft specific data
|
||||
int playerAmount;
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
||||
}
|
||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||
String bukkitVersion = org.bukkit.Bukkit.getVersion();
|
||||
bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1);
|
||||
|
||||
// OS/Java specific data
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
String osName = System.getProperty("os.name");
|
||||
String osArch = System.getProperty("os.arch");
|
||||
String osVersion = System.getProperty("os.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
data.put("serverUUID", serverUUID);
|
||||
|
||||
data.put("playerAmount", playerAmount);
|
||||
data.put("onlineMode", onlineMode);
|
||||
data.put("bukkitVersion", bukkitVersion);
|
||||
|
||||
data.put("javaVersion", javaVersion);
|
||||
data.put("osName", osName);
|
||||
data.put("osArch", osArch);
|
||||
data.put("osVersion", osVersion);
|
||||
data.put("coreCount", coreCount);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JSONObject data = getServerData();
|
||||
|
||||
JSONArray pluginData = new JSONArray();
|
||||
// Search for all other bStats Metrics classes to get their plugin data
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
|
||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
||||
try {
|
||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
||||
}
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
|
||||
data.put("plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(JSONObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
||||
outputStream.write(compressedData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
connection.getInputStream().close(); // We don't care about the response - Just send our data :)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
|
||||
gzip.write(str.getBytes("UTF-8"));
|
||||
gzip.close();
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
public static abstract class CustomChart {
|
||||
|
||||
// The id of the chart
|
||||
final String chartId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
CustomChart(String chartId) {
|
||||
if (chartId == null || chartId.isEmpty()) {
|
||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
private JSONObject getRequestJsonObject() {
|
||||
JSONObject chart = new JSONObject();
|
||||
chart.put("chartId", chartId);
|
||||
try {
|
||||
JSONObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
chart.put("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
protected abstract JSONObject getChartData() throws Exception;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple pie.
|
||||
*/
|
||||
public static class SimplePie extends CustomChart {
|
||||
|
||||
private final Callable<String> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimplePie(String chartId, Callable<String> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced pie.
|
||||
*/
|
||||
public static class AdvancedPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom drilldown pie.
|
||||
*/
|
||||
public static class DrilldownPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JSONObject value = new JSONObject();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
value.put(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
values.put(entryValues.getKey(), value);
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom single line chart.
|
||||
*/
|
||||
public static class SingleLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Integer> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom multi line chart.
|
||||
*/
|
||||
public static class MultiLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple bar chart.
|
||||
*/
|
||||
public static class SimpleBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
categoryValues.add(entry.getValue());
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced bar chart.
|
||||
*/
|
||||
public static class AdvancedBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, int[]>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||
if (entry.getValue().length == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
for (int categoryValue : entry.getValue()) {
|
||||
categoryValues.add(categoryValue);
|
||||
}
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.sekwah.advancedportals.spigot;
|
||||
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.spigot.coreconnector.command.SpigotCommandRegister;
|
||||
import com.sekwah.advancedportals.spigot.coreconnector.info.SpigotDataCollector;
|
||||
import com.sekwah.advancedportals.metrics.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AdvancedPortalsPlugin extends JavaPlugin {
|
||||
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
/**
|
||||
* Readd this when the injector is actually needed.
|
||||
*/
|
||||
//private Injector injector;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
Metrics metrics = new Metrics(this);
|
||||
|
||||
Pattern p = Pattern.compile("\\(MC:\\s([0-9].[0-9]+.?[0-9]+)\\)");
|
||||
Matcher m = p.matcher(Bukkit.getVersion());
|
||||
if(m.find()) {
|
||||
String version = m.group(1);
|
||||
String[] versionNums = version.split("\\.");
|
||||
int[] versionInts = new int[versionNums.length];
|
||||
for(int i=0;i <versionNums.length; i++) {
|
||||
versionInts[i] = Integer.parseInt(versionNums[i]);
|
||||
}
|
||||
this.portalsCore = new AdvancedPortalsCore(this.getDataFolder(),
|
||||
new SpigotInfoLogger(this), new SpigotDataCollector(), versionInts);
|
||||
this.portalsCore.registerCommands(new SpigotCommandRegister(this));
|
||||
}
|
||||
else {
|
||||
this.getLogger().warning("Could not parse mc version from: " + Bukkit.getVersion());
|
||||
this.setEnabled(false);
|
||||
}
|
||||
//injector = Guice.createInjector(new RepositoryModule(this.portalsCore));
|
||||
this.getServer().getPluginManager().registerEvents(new Listeners(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.portalsCore.onDisable();
|
||||
}
|
||||
|
||||
public AdvancedPortalsCore getPortalsCore() {
|
||||
return portalsCore;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.sekwah.advancedportals.spigot;
|
||||
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.CoreListeners;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.spigot.coreconnector.container.SpigotPlayerContainer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class Listeners implements Listener {
|
||||
|
||||
private CoreListeners coreListeners = AdvancedPortalsCore.getInstance().getCoreListeners();
|
||||
|
||||
@EventHandler
|
||||
public void onJoinEvent(PlayerJoinEvent event) {
|
||||
coreListeners.playerJoin(new SpigotPlayerContainer(event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoinEvent(PlayerQuitEvent event) {
|
||||
coreListeners.playerLeave(new SpigotPlayerContainer(event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
Location blockloc = event.getBlock().getLocation();
|
||||
this.coreListeners.blockPlace(new SpigotPlayerContainer(event.getPlayer()),
|
||||
new PortalLocation(blockloc.getWorld().getName(), blockloc.getBlockX(), blockloc.getBlockY(), blockloc.getBlockZ()), event.getBlockPlaced().getType().toString(),
|
||||
event.getItemInHand().getType().toString(), event.getItemInHand().getItemMeta().getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemInteract(PlayerInteractEvent event) {
|
||||
if (!event.isCancelled() && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getItem() != null) {
|
||||
Location blockloc = event.getClickedBlock().getLocation();
|
||||
boolean allowEvent = this.coreListeners.playerInteractWithBlock(new SpigotPlayerContainer(event.getPlayer()), event.getMaterial().toString(),
|
||||
event.getItem().getItemMeta().getDisplayName(),
|
||||
new PortalLocation(blockloc.getWorld().getName(), blockloc.getBlockX(), blockloc.getBlockY(), blockloc.getBlockZ()),
|
||||
event.getAction() == Action.LEFT_CLICK_BLOCK);
|
||||
event.setCancelled(!allowEvent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.sekwah.advancedportals.spigot;
|
||||
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
|
||||
public class SpigotInfoLogger extends InfoLogger {
|
||||
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
public SpigotInfoLogger(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String s) {
|
||||
plugin.getLogger().warning(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String s) {
|
||||
plugin.getLogger().info(s);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.sekwah.advancedportals.spigot.convertolddata;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ConfigAccessor {
|
||||
private final String fileName;
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
private File configFile;
|
||||
private FileConfiguration fileConfiguration;
|
||||
|
||||
public ConfigAccessor(JavaPlugin plugin, String fileName) {
|
||||
this.plugin = plugin;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
|
||||
public void reloadConfig() {
|
||||
if (configFile == null) {
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
if (dataFolder == null)
|
||||
throw new IllegalStateException();
|
||||
configFile = new File(dataFolder, fileName);
|
||||
}
|
||||
fileConfiguration = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(new File(this.getClass()
|
||||
.getClassLoader().getResource(fileName).getPath()));
|
||||
fileConfiguration.setDefaults(defConfig);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (fileConfiguration == null) {
|
||||
this.reloadConfig();
|
||||
}
|
||||
return fileConfiguration;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (fileConfiguration == null || configFile == null) {
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
getConfig().save(configFile);
|
||||
} catch (IOException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (configFile == null) {
|
||||
configFile = new File(plugin.getDataFolder(), fileName);
|
||||
}
|
||||
if (!configFile.exists()) {
|
||||
plugin.saveResource(fileName, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.sekwah.advancedportals.spigot.convertolddata;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO this is for spigot only for a few releases
|
||||
*/
|
||||
public class ConvertOldSubCommand implements SubCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Old portal data found."));
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Old portal data successfully converted."));
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Old desti data found."));
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Old desti data successfully converted."));
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Those were just sample outputs, it doesnt work yet."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasicHelpText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDetailedHelpText() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.sekwah.advancedportals.spigot.coreconnector.command;
|
||||
|
||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||
import com.sekwah.advancedportals.coreconnector.command.CommandHandler;
|
||||
import com.sekwah.advancedportals.spigot.coreconnector.container.SpigotCommandSenderContainer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpigotCommandHandler implements CommandExecutor, TabCompleter {
|
||||
|
||||
private final CommandTemplate commandExecutor;
|
||||
|
||||
public SpigotCommandHandler(CommandTemplate commandExecutor) {
|
||||
this.commandExecutor = commandExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
|
||||
this.commandExecutor.onCommand(new SpigotCommandSenderContainer(commandSender), command.getName(), args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
|
||||
return this.commandExecutor.onTabComplete(new SpigotCommandSenderContainer(commandSender), args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.sekwah.advancedportals.spigot.coreconnector.command;
|
||||
|
||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||
import com.sekwah.advancedportals.coreconnector.command.CommandRegister;
|
||||
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
||||
|
||||
/**
|
||||
* Register the CommandTemplate files to the appropriate system
|
||||
*/
|
||||
public class SpigotCommandRegister implements CommandRegister {
|
||||
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
public SpigotCommandRegister(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the command to the appropriate system
|
||||
* @param commandName
|
||||
* @param commandExecutor
|
||||
*/
|
||||
public void registerCommand(String commandName, CommandTemplate commandExecutor) {
|
||||
this.plugin.getCommand(commandName).setExecutor(new SpigotCommandHandler(commandExecutor));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.sekwah.advancedportals.spigot.coreconnector.container;
|
||||
|
||||
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SpigotCommandSenderContainer implements CommandSenderContainer {
|
||||
|
||||
private final CommandSender sender;
|
||||
|
||||
public SpigotCommandSenderContainer(CommandSender commandSender) {
|
||||
this.sender = commandSender;
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
public boolean isOp() {
|
||||
return sender.isOp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null if there isnt a player e.g. the console
|
||||
*/
|
||||
public SpigotPlayerContainer getPlayerContainer() {
|
||||
if (sender instanceof Player) {
|
||||
return new SpigotPlayerContainer((Player) sender);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package com.sekwah.advancedportals.spigot.coreconnector.container;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.entities.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
import com.sekwah.advancedportals.coreconnector.container.WorldContainer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.material.Wool;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Just a temporary container for whenever advanced portals needs to get data from a player
|
||||
*/
|
||||
public class SpigotPlayerContainer implements PlayerContainer {
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
private final Player player;
|
||||
|
||||
public SpigotPlayerContainer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
public boolean isOp() {
|
||||
return this.player.isOp();
|
||||
}
|
||||
|
||||
public PlayerLocation getLoc() {
|
||||
Location loc = this.player.getLocation();
|
||||
return new PlayerLocation(loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
public double getEyeHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void teleport(PlayerLocation location) {
|
||||
this.player.teleport(new Location(Bukkit.getWorld(location.worldName), location.posX, location.posY, location.posZ));
|
||||
}
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return this.player.hasPermission(permission);
|
||||
}
|
||||
|
||||
public WorldContainer getWorld() {
|
||||
return new SpigotWorldContainer(this.player.getWorld());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param blockPos
|
||||
* @param material
|
||||
*/
|
||||
public void sendFakeBlock(PortalLocation blockPos, String material) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Only 1.12 and below supported
|
||||
* @param blockPos
|
||||
* @param material
|
||||
* @param data
|
||||
*/
|
||||
public void sendFakeBlockWithData(PortalLocation blockPos, String material, byte data) {
|
||||
|
||||
}
|
||||
|
||||
public void giveWool(String dyeColor, String itemName, String... itemDescription) {
|
||||
ItemStack regionselector = new Wool(DyeColor.valueOf(dyeColor)).toItemStack(1);
|
||||
ItemMeta selectorname = regionselector.getItemMeta();
|
||||
selectorname.setDisplayName(itemName);
|
||||
selectorname.setLore(Arrays.asList(itemDescription));
|
||||
regionselector.setItemMeta(selectorname);
|
||||
this.player.getInventory().addItem(regionselector);
|
||||
}
|
||||
|
||||
public void giveItem(String material, String itemName, String... itemDescription) {
|
||||
ItemStack regionselector = new ItemStack(Material.getMaterial(material));
|
||||
ItemMeta selectorname = regionselector.getItemMeta();
|
||||
selectorname.setDisplayName(itemName);
|
||||
selectorname.setLore(Arrays.asList(itemDescription));
|
||||
regionselector.setItemMeta(selectorname);
|
||||
this.player.getInventory().addItem(regionselector);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.sekwah.advancedportals.spigot.coreconnector.container;
|
||||
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.WorldContainer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.material.Directional;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
public class SpigotWorldContainer implements WorldContainer {
|
||||
|
||||
private final World world;
|
||||
|
||||
public SpigotWorldContainer(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public void setBlock(PortalLocation location, String material) {
|
||||
this.world.getBlockAt(location.posX, location.posY, location.posZ).setType(Material.getMaterial(material));
|
||||
}
|
||||
|
||||
public void setBlockData(PortalLocation location, byte data) {
|
||||
MaterialData matData = world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData();
|
||||
if(matData instanceof Directional) {
|
||||
Directional dir = (Directional) world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData();
|
||||
dir.setFacingDirection(BlockFace.NORTH);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getBlock(PortalLocation location) {
|
||||
return this.world.getBlockAt(location.posX, location.posY, location.posZ).getType().toString();
|
||||
}
|
||||
|
||||
public byte getBlockData(PortalLocation location) {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.sekwah.advancedportals.spigot.coreconnector.info;
|
||||
|
||||
import com.sekwah.advancedportals.coreconnector.info.DataCollector;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpigotDataCollector implements DataCollector {
|
||||
|
||||
private final List<String> blockMaterialList = new ArrayList<>();
|
||||
|
||||
public SpigotDataCollector() {
|
||||
for(Material material : Material.values()) {
|
||||
this.blockMaterialList.add(material.name());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean materialExists(String materialName) {
|
||||
String sameCase = materialName.toUpperCase();
|
||||
return Material.getMaterial(sameCase) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMaterials() {
|
||||
return blockMaterialList;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.sekwah.advancedportals.spigot.effect;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.effect.WarpEffect;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.entities.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
public class WarpEffectEnder extends WarpEffect {
|
||||
@Override
|
||||
protected void onWarp(PlayerContainer player, PortalLocation loc, Action action, Type type, AdvancedPortal portal) {
|
||||
|
||||
}
|
||||
}
|
|
@ -62,13 +62,9 @@ command.create.complete= The portal has been successfully created.
|
|||
|
||||
command.createdesti.help=Creates destinations
|
||||
command.createdesti.error= There was an error making the destination
|
||||
command.createdesti.console= You cannot create a destination using the
|
||||
console.
|
||||
command.createdesti.detailedhelp=Format is /desti create (name)
|
||||
[tag:tagvalue] List tags after create in the format tag:value, if your
|
||||
value needs spaces use the format tag:"value with spaces"
|
||||
command.createdesti.complete= The destination has been successfully
|
||||
created.
|
||||
command.createdesti.console= You cannot create a destination using the console.
|
||||
command.createdesti.detailedhelp=Format is /desti create (name) [tag:tagvalue] List tags after create in the format tag:value, if your value needs spaces use the format tag:"value with spaces"
|
||||
command.createdesti.complete= The destination has been successfully created.
|
||||
|
||||
command.create.tags=\u00A7aTags:
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ command.create.detailedhelp=A formátum /portal create (név) [tag:tagvalue] Meg
|
|||
command.create.complete= A portál sikeresen létrehozva.
|
||||
|
||||
command.createdesti.help=Célállomások létrehozása
|
||||
command.createdesti.error= Hiba történt a célállomásnál:
|
||||
command.createdesti.error= Hiba történt a célállomásnál
|
||||
command.createdesti.console= Nem hozhatsz létre célállomást a konzol segítségével.
|
||||
command.createdesti.detailedhelp=A formátum /desti create (név) [tag:tagvalue] Megadja a címkéket a létrehozás után a formátum tag:calue, ha az értéknek szóközre van szüksége, használja a formátum tag:"érték a szóközökkel"
|
||||
command.createdesti.complete= A célállomás sikeresen létrehozva.
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
[
|
||||
{
|
||||
"modid": "advancedportals",
|
||||
"name": "Advanced Portals",
|
||||
"description": "A server side mod for portals",
|
||||
"version": "${version}",
|
||||
"mcversion": "${mcversion}",
|
||||
"url": "https://www.spigotmc.org/resources/advanced-portals.14356/",
|
||||
"updateUrl": "",
|
||||
"authorList": ["sekwah41"],
|
||||
"credits": "",
|
||||
"logoFile": "",
|
||||
"screenshots": [],
|
||||
"dependencies": []
|
||||
}
|
||||
]
|
|
@ -0,0 +1,51 @@
|
|||
main: com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin
|
||||
name: AdvancedPortals
|
||||
version: 1.0.0
|
||||
author: sekwah41
|
||||
description: An advanced portals plugin for bukkit.
|
||||
commands:
|
||||
portal:
|
||||
description: The main command for the advanced portals
|
||||
aliases: [portals, aportals, advancedportals]
|
||||
usage: /<command>
|
||||
destination:
|
||||
description: Can be used to access portal destinations.
|
||||
aliases: [desti]
|
||||
usage: /<command>
|
||||
permissions:
|
||||
advancedportals.*:
|
||||
description: Gives access to all commands
|
||||
default: op
|
||||
children:
|
||||
advancedportals.createportal: true
|
||||
advancedportals.portal: true
|
||||
advancedportals.build: true
|
||||
advancedportals.desti: true
|
||||
advancedportals.createportal:
|
||||
description: Allows you to create portals
|
||||
default: op
|
||||
advancedportals.createportal.commandlevel.*:
|
||||
description: Gives access to all level raisers
|
||||
default: false
|
||||
children:
|
||||
advancedportals.createportal.commandlevel.op: true
|
||||
advancedportals.createportal.commandlevel.perms: true
|
||||
advancedportals.createportal.commandlevel.console: true
|
||||
advancedportals.createportal.commandlevel.op:
|
||||
description: Allows you to increase the users level temporaily to op
|
||||
default: false
|
||||
advancedportals.createportal.commandlevel.perms:
|
||||
description: Allows you to increase the users level temporaily to have all perms
|
||||
default: false
|
||||
advancedportals.createportal.commandlevel.console:
|
||||
description: Executes command in the console
|
||||
default: false
|
||||
advancedportals.portal:
|
||||
description: Allows use of portal commands
|
||||
default: op
|
||||
advancedportals.build:
|
||||
description: Allows you to build in the portal regions
|
||||
default: op
|
||||
advancedportals.desti:
|
||||
description: Gives access to all desti commands
|
||||
default: op
|
Loading…
Reference in New Issue