From 93fc2918931cae897848221b875c2aa7a90dc3e7 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 12 Jan 2019 11:43:47 +0300 Subject: [PATCH] Release 1.0 --- .gitignore | 18 ++ README.md | 31 +++- build.gradle | 28 +++ build/version/1.0/RandomTeleport.jar | Bin 0 -> 7290 bytes gradle.properties | 2 + gradlew | 172 ++++++++++++++++++ gradlew.bat | 84 +++++++++ .../zendal/randomteleport/RandomTeleport.java | 19 ++ .../config/ConfigurationRandomTeleport.java | 19 ++ .../config/FileConfigurationWrapper.java | 87 +++++++++ .../event/SignRandomTeleport.java | 89 +++++++++ .../randomteleport/util/LocationFinder.java | 59 ++++++ src/main/resources/plugin.yml | 5 + 13 files changed, 612 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 build.gradle create mode 100644 build/version/1.0/RandomTeleport.jar create mode 100644 gradle.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 src/main/java/ru/zendal/randomteleport/RandomTeleport.java create mode 100644 src/main/java/ru/zendal/randomteleport/config/ConfigurationRandomTeleport.java create mode 100644 src/main/java/ru/zendal/randomteleport/config/FileConfigurationWrapper.java create mode 100644 src/main/java/ru/zendal/randomteleport/event/SignRandomTeleport.java create mode 100644 src/main/java/ru/zendal/randomteleport/util/LocationFinder.java create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba19071 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ + +build/classes/ + +build/libs/ + +build/resources/ + +build/tmp/ + +\.gradle/ + +\.idea/ + +gradle/ + + + +build/\.DS_Store diff --git a/README.md b/README.md index bc0a908..c9cd9b4 100644 --- a/README.md +++ b/README.md @@ -1 +1,30 @@ -RandomTeleport +#RandomTeleport + +### Plugin for Bukkit/Spigot core. + +> Testing only on 1.13.2 + + +## Features +* Only sign +* Black list blocks available + + +```yaml +settings: + sign: + name: + pretty: §l§b[§4RandomTP§b] #Name after create sign for Random TP + raw: '[rtp]' # What need write for create RandomTP sign + teleport: + max: + x: 3000 # at -3000 to 3000 X Teleport. Point location sign + z: 3000 # at -3000 to 3000 Z Teleport. Point location sign + block: + blackList: + - LAVA + - WATER + - CACTUS + - CACTUS_GREEN + +``` diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..b617290 --- /dev/null +++ b/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'java' + +group = pluginGroup +version = pluginVersion + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +repositories { + mavenCentral() + maven { + name = 'spigotmc-repo' + url = 'https://hub.spigotmc.org/nexus/content/groups/public/' + } +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' + compile 'org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT' +} + +import org.apache.tools.ant.filters.ReplaceTokens + +processResources { + from(sourceSets.main.resources.srcDirs) { + filter ReplaceTokens, tokens: [version: version] + } +} diff --git a/build/version/1.0/RandomTeleport.jar b/build/version/1.0/RandomTeleport.jar new file mode 100644 index 0000000000000000000000000000000000000000..04888b1450cf7a5622a0ac5f090b6418eb8012fe GIT binary patch literal 7290 zcma)B1yodP*CwR9K~fk>xVGqCTC=EDK10|gzh)r2UW7k0sz|6R$jWGHv8%`)stoiiE3vVUVkxoR9~v00 z(%}5Sv$(pvif{|;TK;dXh}X}~ZvWEvGt0HPH!PkYdkZtWe{d$;dW9S7esDUQ*;_b3 zTtRjqM+axu-wM+FPSD)J-qObEU-EdVSGz>;aBwx(OX7c!m-++7&DqS=#=&0W58Jf< zV;j4$*xm>QV+x19Qi=?zVCoF5=fq z6hBdYYzXDvKynX=Vp*gSH1}>0%Nsxg?65w6XR?H$q@j@ETP09zcO=^t0<=&kO!m!m z9Mx?GK%N{)))6GqLd94quiztj)`>EpGFc%}F}YLLV{y@2Yh_20>03{Bu9B;24WP}l zViFHLJTz@q-W|G-hAv%owT!JBse$_795<||KM|38#~ZH z{I2V4=I97={?p-UIv-sKv`N213{oHsY!E-4`@k3k1w=Gcs1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?;it$pT&MPFt}m9p-*nxhM&dB3)tx&9*XKflZ^qyB^TkDm9ha?{)DZa3C{s4Ktz20wiFYjwYGv)|TrgZ33JKOP_?>Hq)$ literal 0 HcmV?d00001 diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..04f7d2e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +pluginGroup=ru.zendal +pluginVersion=1.0-SNAPSHOT diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/ru/zendal/randomteleport/RandomTeleport.java b/src/main/java/ru/zendal/randomteleport/RandomTeleport.java new file mode 100644 index 0000000..a9554a2 --- /dev/null +++ b/src/main/java/ru/zendal/randomteleport/RandomTeleport.java @@ -0,0 +1,19 @@ +package ru.zendal.randomteleport; + +import org.bukkit.plugin.java.JavaPlugin; +import ru.zendal.randomteleport.config.FileConfigurationWrapper; +import ru.zendal.randomteleport.event.SignRandomTeleport; + +public final class RandomTeleport extends JavaPlugin { + + @Override + public void onEnable() { + this.getServer().getPluginManager().registerEvents(new SignRandomTeleport(new FileConfigurationWrapper(this.getConfig())), this); + this.saveConfig(); + + } + + @Override + public void onDisable() { + } +} diff --git a/src/main/java/ru/zendal/randomteleport/config/ConfigurationRandomTeleport.java b/src/main/java/ru/zendal/randomteleport/config/ConfigurationRandomTeleport.java new file mode 100644 index 0000000..e5b9b6c --- /dev/null +++ b/src/main/java/ru/zendal/randomteleport/config/ConfigurationRandomTeleport.java @@ -0,0 +1,19 @@ +package ru.zendal.randomteleport.config; + +import org.bukkit.Material; +import org.bukkit.block.Block; + +import java.util.List; + +public interface ConfigurationRandomTeleport { + + String getPrettySignTitle(); + + String getRawSignTitle(); + + Integer getMaxXAtLocation(); + + Integer getMaxZAtLocation(); + + List getBlockBlackList(); +} diff --git a/src/main/java/ru/zendal/randomteleport/config/FileConfigurationWrapper.java b/src/main/java/ru/zendal/randomteleport/config/FileConfigurationWrapper.java new file mode 100644 index 0000000..1ce624b --- /dev/null +++ b/src/main/java/ru/zendal/randomteleport/config/FileConfigurationWrapper.java @@ -0,0 +1,87 @@ +package ru.zendal.randomteleport.config; + +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; + +import java.util.ArrayList; +import java.util.List; + +/** + * Wrapper of FileConfiguration + */ +public class FileConfigurationWrapper implements ConfigurationRandomTeleport { + + + private FileConfiguration source; + + /** + * Instantiates a new File configuration wrapper. + * + * @param fileConfiguration the file configuration + */ + public FileConfigurationWrapper(FileConfiguration fileConfiguration) { + this.source = fileConfiguration; + this.initialize(); + } + + + private void initialize() { + + if (!this.source.contains("settings.sign.name.pretty")) { + this.source.set("settings.sign.name.pretty", "§l§b[§4RandomTP§b]"); + } + + if (!this.source.contains("settings.sign.name.raw")) { + this.source.set("settings.sign.name.raw", "[RandomTP]"); + } + + if (!this.source.contains("settings.teleport.max.x")) { + this.source.set("settings.teleport.max.x", 3000); + } + + if (!this.source.contains("settings.teleport.max.z")) { + this.source.set("settings.teleport.max.z", 3000); + } + + if (!this.source.contains("settings.teleport.block.blackList")) { + List blockBlackList = new ArrayList<>(); + blockBlackList.add("LAVA"); + blockBlackList.add("WATER"); + blockBlackList.add("CACTUS"); + blockBlackList.add("CACTUS_GREEN"); + this.source.set("settings.teleport.block.blackList", blockBlackList); + } + + } + + @Override + public String getPrettySignTitle() { + return this.source.getString("settings.sign.name.pretty"); + } + + @Override + public String getRawSignTitle() { + return this.source.getString("settings.sign.name.raw"); + } + + @Override + public Integer getMaxXAtLocation() { + return this.source.getInt("settings.teleport.max.x"); + } + + @Override + public Integer getMaxZAtLocation() { + return this.source.getInt("settings.teleport.max.z"); + } + + @Override + public List getBlockBlackList() { + List rawBlockBlackList = this.source.getStringList("settings.teleport.block.blackList"); + List blockBlackList = new ArrayList<>(); + + rawBlockBlackList.forEach(rawBlockBlack -> { + blockBlackList.add(Material.getMaterial(rawBlockBlack)); + }); + return blockBlackList; + } +} diff --git a/src/main/java/ru/zendal/randomteleport/event/SignRandomTeleport.java b/src/main/java/ru/zendal/randomteleport/event/SignRandomTeleport.java new file mode 100644 index 0000000..0489f24 --- /dev/null +++ b/src/main/java/ru/zendal/randomteleport/event/SignRandomTeleport.java @@ -0,0 +1,89 @@ +package ru.zendal.randomteleport.event; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import ru.zendal.randomteleport.config.ConfigurationRandomTeleport; +import ru.zendal.randomteleport.util.LocationFinder; + +/** + * The type Sign random teleport. + */ +public class SignRandomTeleport implements Listener { + + /** + * Configuration of plugin + */ + private ConfigurationRandomTeleport configuration; + + /** + * Instantiates a new Sign random teleport. + * + * @param configuration the configuration + */ + public SignRandomTeleport(ConfigurationRandomTeleport configuration) { + this.configuration = configuration; + } + + /** + * On sign call. + * + * @param event the event + */ + @EventHandler + public void onSignCall(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) { + return; + } + if (event.getClickedBlock() == null) { + return; + } + + Block block = event.getClickedBlock(); + if (block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN && block.getState() instanceof Sign) { + Sign sign = (Sign) block.getState(); + if (sign.getLine(0).equals(this.preparePrettySignTitle(configuration.getPrettySignTitle()))) { + event.getPlayer().teleport(LocationFinder.getRandomLocation(sign.getLocation(), configuration.getMaxXAtLocation(), configuration.getMaxZAtLocation(), configuration.getBlockBlackList())); + } + } + } + + /** + * Prepare title for compare + * + * @param prettySignTitle title in config + * @return prepare title + */ + private String preparePrettySignTitle(String prettySignTitle) { + return prettySignTitle.replaceAll("§l", ""); + } + + /** + * On sign create. + * + * @param event the event + */ + @EventHandler + public void onSignCreate(SignChangeEvent event) { + if (!this.isServiceSign(event) || !event.getPlayer().hasPermission("randomteleport.sign.create")) { + return; + } + event.setLine(0, configuration.getPrettySignTitle()); + } + + /** + * Check is sign service + * + * @param event sing change event + * @return {@code true} if service sign else {@code false} + */ + private boolean isServiceSign(SignChangeEvent event) { + return event.getLine(0).toLowerCase().equals(configuration.getRawSignTitle().toLowerCase()); + } + +} diff --git a/src/main/java/ru/zendal/randomteleport/util/LocationFinder.java b/src/main/java/ru/zendal/randomteleport/util/LocationFinder.java new file mode 100644 index 0000000..d6a5b15 --- /dev/null +++ b/src/main/java/ru/zendal/randomteleport/util/LocationFinder.java @@ -0,0 +1,59 @@ +package ru.zendal.randomteleport.util; + +import org.bukkit.Location; +import org.bukkit.Material; + +import java.util.Collection; +import java.util.Random; + +/** + * The type Location finder. + */ +public class LocationFinder { + + /** + * Gets random location. + * + * @param pointLocation the point location + * @param maxX the max x + * @param maxZ the max z + * @param blackListBlock the black list block + * @return the random location + */ + public static Location getRandomLocation(Location pointLocation, int maxX, int maxZ, Collection blackListBlock) { + Location result; + do { + Location randomLocation = LocationFinder.getRandomLocation(pointLocation, maxX, maxZ); + result = LocationFinder.getLocationForTeleport(randomLocation, blackListBlock); + } while (result == null); + return result; + } + + + private static Location getRandomLocation(Location center, int maxX, int maxZ) { + int newX = LocationFinder.getRandomInteger(maxX * -1, maxX); + int newZ = LocationFinder.getRandomInteger(maxZ * -1, maxZ); + return new Location(center.getWorld(), newX, center.getWorld().getMaxHeight(), newZ); + } + + + private static int getRandomInteger(int min, int max) { + Random random = new Random(); + return min + random.nextInt(max - min + 1); + } + + private static Location getLocationForTeleport(Location location, Collection blackListBlock) { + while (location.getBlockY() != 0) { + location.setY(location.getY() - 1); + if (location.getBlock().getType() == Material.AIR) { + continue; + } + if (blackListBlock.stream().anyMatch(material -> material == location.getBlock().getType())) { + return null; + } + location.setY(location.getY() + 2); + return location; + } + return null; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..df20ba8 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: RandomTeleport +version: @version@ +main: ru.zendal.randomteleport.RandomTeleport +api-version: 1.13 +authors: [BigTows]