From c052408c0aa8cf981fd5f08d56ffefeebc5a5bf4 Mon Sep 17 00:00:00 2001 From: Esophose Date: Mon, 15 Apr 2019 10:49:26 +0000 Subject: [PATCH 01/11] Update to use gradle, make island level scanning segmented --- .gitignore | 206 +----------------- .gitlab-ci.yml | 24 +- LICENSE | 2 +- build.gradle | 44 ++++ gradle/wrapper/gradle-wrapper.properties | 5 + gradlew | 172 +++++++++++++++ gradlew.bat | 84 +++++++ pom.xml | 63 ------ settings.gradle | 1 + .../goodandevil/skyblock/levelling/Chunk.java | 189 +++++++++++----- .../skyblock/levelling/LevellingManager.java | 105 +++++---- src/main/resources/LICENSE | 9 - src/main/resources/language.yml | 5 + src/main/resources/plugin.yml | 2 +- 14 files changed, 525 insertions(+), 386 deletions(-) create mode 100644 build.gradle create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat delete mode 100644 pom.xml create mode 100644 settings.gradle delete mode 100644 src/main/resources/LICENSE diff --git a/.gitignore b/.gitignore index 7284919e..5819bfd4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,157 +1,3 @@ - -# Created by https://www.gitignore.io/api/java,maven,gradle,eclipse,netbeans,intellij -# Edit at https://www.gitignore.io/?templates=java,maven,gradle,eclipse,netbeans,intellij - -### Eclipse ### - -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# CDT- autotools -.autotools - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - -# Annotation Processing -.apt_generated/ - -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - -### Eclipse Patch ### -# Eclipse Core -.project - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Annotation Processing -.apt_generated - -.sts4-cache/ - -### Intellij ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/modules.xml -# .idea/*.iml -# .idea/modules - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### Intellij Patch ### -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 - -# *.iml -# modules.xml -# .idea/misc.xml -# *.ipr - -# Sonarlint plugin -.idea/sonarlint - -### Java ### # Compiled class file *.class @@ -168,6 +14,7 @@ fabric.properties *.jar *.war *.nar +*.settings *.ear *.zip *.tar.gz @@ -175,49 +22,8 @@ fabric.properties # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* - -### Maven ### -target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -.mvn/wrapper/maven-wrapper.jar - -### NetBeans ### -**/nbproject/private/ -**/nbproject/Makefile-*.mk -**/nbproject/Package-*.bash -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ - -### Gradle ### -.gradle - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties - -### Gradle Patch ### -**/build/ - -# End of https://www.gitignore.io/api/java,maven,gradle,eclipse,netbeans,intellij - -.idea/ -FabledSkyBlock.iml -gradle* \ No newline at end of file +/.gradle/ +/.settings/ +/.idea/ +/build/ +/bin/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 09acf950..259460db 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,21 +1,19 @@ +image: gradle:alpine + +variables: + path: "/builds/$CI_PROJECT_PATH" + +before_script: + - export GRADLE_USER_HOME=`pwd`/.gradle + stages: - build -variables: - name: "FabledSkyBlock" - path: "/builds/$CI_PROJECT_PATH" - version: "Build-73" - build: stage: build - image: maven:3.5.3-jdk-8 script: - - find $path/ -type f -name "*.xml" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g - - find $path/ -type f -name "*.yml" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g - - mvn clean package - - find $path/ -depth -path '*original*' -delete - - mv $path/target/*.jar $path/ + - gradle build + - mv $path/build/libs/*.jar $path/ artifacts: - name: $name-$version paths: - - "$path/*.jar" + - $path/*.jar diff --git a/LICENSE b/LICENSE index d429552d..7ecbbf10 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2018 Brianna O’Keefe +Copyright (c) 2019 Brianna O’Keefe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software with minimal restriction, including the rights to use, copy, modify or merge while excluding the rights to publish, (re)distribute, sub-license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..904a046e --- /dev/null +++ b/build.gradle @@ -0,0 +1,44 @@ +import org.apache.tools.ant.filters.ReplaceTokens +apply plugin: 'java' + +group 'com.songoda.fabledskyblock' +version 'Build-73' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() + jcenter() + + maven { + url 'http://repo.songoda.com/artifactory/private/' + } +} + +dependencies { + // PlaceholderAPI + implementation (group: 'be.maximvdw', name: 'placeholderapi', version: '2.5.1') + implementation (group: 'me.clip', name: 'placeholderapi', version: '2.9.2') + + // Vault + implementation (group: 'net.milkbowl', name: 'vault', version: '1.7.1') + + // Leaderheads + implementation (group: 'me.robin', name: 'leaderheads', version: '1.0') + + // EpicSpawners + implementation (group: 'com.songoda', name: 'epicspawners', version: '5.7.1') + + // WildStacker + implementation (group: 'com.bgsoftware', name: 'wildstacker-api', version: 'b14') + + // Spigot + implementation (group: 'org.spigotmc', name: 'spigot', version: '1.13.2') +} + +processResources { + filter ReplaceTokens, tokens: ["version": project.property("version")] + from (sourceSets.main.resources.srcDirs) { + include '**/*.yml' + } +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..44e7c4d1 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 00000000..af6708ff --- /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='"-Xmx64m"' + +# 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 00000000..6d57edc7 --- /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="-Xmx64m" + +@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/pom.xml b/pom.xml deleted file mode 100644 index 834df6a7..00000000 --- a/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - com.songoda - FabledSkyBlock - 4.0.0 - maven-version-number - - clean package - - - 3.6.1 - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - - - - private - http://repo.songoda.com/artifactory/private/ - - - - - be.maximvdw - placeholderapi - 2.5.1 - - - me.clip - placeholderapi - 2.9.2 - - - net.milkbowl - vault - 1.7.1 - - - me.robin - leaderheads - 1.0 - - - com.songoda - epicspawners - 5.7.1 - - - com.bgsoftware - wildstacker-api - b14 - - - org.spigotmc - spigot - 1.13.2 - - - \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..4b64804c --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'FabledSkyBlock' diff --git a/src/main/java/me/goodandevil/skyblock/levelling/Chunk.java b/src/main/java/me/goodandevil/skyblock/levelling/Chunk.java index d8be70d3..4de54f8c 100644 --- a/src/main/java/me/goodandevil/skyblock/levelling/Chunk.java +++ b/src/main/java/me/goodandevil/skyblock/levelling/Chunk.java @@ -1,84 +1,169 @@ package me.goodandevil.skyblock.levelling; import java.io.File; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.ChunkSnapshot; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.scheduler.BukkitRunnable; import me.goodandevil.skyblock.SkyBlock; import me.goodandevil.skyblock.island.Island; import me.goodandevil.skyblock.island.IslandEnvironment; import me.goodandevil.skyblock.island.IslandWorld; +import org.bukkit.entity.Player; public class Chunk { + private static final int MAX_CHUNKS = 150; private final SkyBlock skyblock; private Island island; - private List chunkSnapshots = new ArrayList<>(); - private boolean complete; + private int initialNumberOfChunks = -1; + private Set chunkPositions = new HashSet<>(); + private Set chunkSnapshots = new HashSet<>(); + private boolean isReady = false; + private boolean isFinished = false; public Chunk(SkyBlock skyblock, Island island) { this.skyblock = skyblock; this.island = island; - - complete = false; } - public void prepare() { - new BukkitRunnable() { - @Override - public void run() { - prepareChunkSnapshots(); - } - }.runTask(skyblock); - } + public void prepareInitial() { + Bukkit.getScheduler().runTask(this.skyblock, () -> { + FileConfiguration config = this.skyblock.getFileManager().getConfig(new File(this.skyblock.getDataFolder(), "config.yml")).getFileConfiguration(); + FileConfiguration islandData = this.skyblock.getFileManager().getConfig(new File(new File(this.skyblock.getDataFolder().toString() + "/island-data"), this.island.getOwnerUUID().toString() + ".yml")).getFileConfiguration(); - public List getChunkSnapshots() { - return chunkSnapshots; - } + boolean hasNether = config.getBoolean("Island.World.Nether.Enable") && islandData.getBoolean("Unlocked.Nether", false); + boolean hasEnd = config.getBoolean("Island.World.End.Enable") && islandData.getBoolean("Unlocked.End", false); - public boolean isComplete() { - return complete; - } - - private void prepareChunkSnapshots() { - FileConfiguration config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration(); - FileConfiguration islandData = skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), island.getOwnerUUID().toString() + ".yml")).getFileConfiguration(); - boolean hasNormal = true; - boolean hasNether = config.getBoolean("Island.World.Nether.Enable") && islandData.getBoolean("Unlocked.Nether", false); - boolean hasEnd = config.getBoolean("Island.World.End.Enable") && islandData.getBoolean("Unlocked.End", false); - - for (IslandWorld iWorld : IslandWorld.values()) { - if ((iWorld == IslandWorld.Normal && hasNormal) || (iWorld == IslandWorld.Nether && hasNether) || (iWorld == IslandWorld.End && hasEnd)) { - Location islandLocation = island.getLocation(iWorld, IslandEnvironment.Island); - - Location minLocation = new Location(islandLocation.getWorld(), - islandLocation.getBlockX() - island.getRadius(), 0, - islandLocation.getBlockZ() - island.getRadius()); - Location maxLocation = new Location(islandLocation.getWorld(), - islandLocation.getBlockX() + island.getRadius(), islandLocation.getWorld().getMaxHeight(), - islandLocation.getBlockZ() + island.getRadius()); - - int MinX = Math.min(maxLocation.getBlockX(), minLocation.getBlockX()); - int MinZ = Math.min(maxLocation.getBlockZ(), minLocation.getBlockZ()); - - int MaxX = Math.max(maxLocation.getBlockX(), minLocation.getBlockX()); - int MaxZ = Math.max(maxLocation.getBlockZ(), minLocation.getBlockZ()); - - for (int x = MinX - 16; x <= MaxX + 16; x += 16) { - for (int z = MinZ - 16; z <= MaxZ + 16; z += 16) { - org.bukkit.Chunk chunk = islandLocation.getWorld().getBlockAt(x, 0, z).getChunk(); - chunkSnapshots.add(chunk.getChunkSnapshot()); - } + for (IslandWorld islandWorld : IslandWorld.values()) { + if (islandWorld == IslandWorld.Normal || (islandWorld == IslandWorld.Nether && hasNether) || (islandWorld == IslandWorld.End && hasEnd)) { + this.getChunksToScan(islandWorld); } } + + this.initialNumberOfChunks = this.chunkPositions.size(); + + this.prepareNextChunkSnapshots(); + }); + } + + public boolean isReadyToScan() { + return this.isReady; + } + + public Set getAvailableChunkSnapshots() { + this.isReady = false; + return this.chunkSnapshots; + } + + public boolean isFinished() { + return this.isFinished; + } + + public void prepareNextChunkSnapshots() { + Bukkit.getScheduler().runTask(this.skyblock, () -> { + this.chunkSnapshots.clear(); + + Iterator it = this.chunkPositions.iterator(); + if (!it.hasNext()) { + this.isReady = true; + this.isFinished = true; + this.sendFinishedMessage(); + return; + } + + int percentComplete = (int)((1 - ((double)this.chunkPositions.size() / this.initialNumberOfChunks)) * 100); + this.sendPercentMessage(percentComplete); + + while (it.hasNext() && this.chunkSnapshots.size() < MAX_CHUNKS) { + ChunkPosition chunkPosition = it.next(); + World world = chunkPosition.getWorld(); + int x = chunkPosition.getX(); + int z = chunkPosition.getZ(); + if (!world.isChunkLoaded(x, z)) { + world.loadChunk(x, z); + this.chunkSnapshots.add(world.getChunkAt(x, z).getChunkSnapshot()); + world.unloadChunk(x, z); + } else { + this.chunkSnapshots.add(world.getChunkAt(x, z).getChunkSnapshot()); + } + it.remove(); + } + + this.isReady = true; + }); + } + + private void sendPercentMessage(int percent) { + String message = ChatColor.translateAlternateColorCodes('&', + this.skyblock.getFileManager() + .getConfig(new File(this.skyblock.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Command.Island.Level.Scanning.Progress.Message") + .replace("%percent", String.valueOf(percent))); + for (Player player : this.skyblock.getIslandManager().getPlayersAtIsland(this.island)) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); + } + } + + private void sendFinishedMessage() { + String message = ChatColor.translateAlternateColorCodes('&', this.skyblock.getFileManager() + .getConfig(new File(this.skyblock.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Command.Island.Level.Scanning.Finished.Message")); + for (Player player : this.skyblock.getIslandManager().getPlayersAtIsland(this.island)) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); + } + } + + private void getChunksToScan(IslandWorld islandWorld) { + Location islandLocation = this.island.getLocation(islandWorld, IslandEnvironment.Island); + World world = islandLocation.getWorld(); + + Location minLocation = new Location(world, islandLocation.getBlockX() - this.island.getRadius(), 0, islandLocation.getBlockZ() - this.island.getRadius()); + Location maxLocation = new Location(world, islandLocation.getBlockX() + this.island.getRadius(), world.getMaxHeight(), islandLocation.getBlockZ() + this.island.getRadius()); + + int minX = Math.min(maxLocation.getBlockX(), minLocation.getBlockX()); + int minZ = Math.min(maxLocation.getBlockZ(), minLocation.getBlockZ()); + + int maxX = Math.max(maxLocation.getBlockX(), minLocation.getBlockX()); + int maxZ = Math.max(maxLocation.getBlockZ(), minLocation.getBlockZ()); + + for (int x = minX; x < maxX + 16; x += 16) { + for (int z = minZ; z < maxZ + 16; z += 16) { + this.chunkPositions.add(new ChunkPosition(world, x >> 4, z >> 4)); + } + } + } + + private class ChunkPosition { + private World world; + private int x, z; + + public ChunkPosition(World world, int x, int z) { + this.world = world; + this.x = x; + this.z = z; } - complete = true; + public World getWorld() { + return this.world; + } + + public int getX() { + return this.x; + } + + public int getZ() { + return this.z; + } } } diff --git a/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java b/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java index b9b739a0..9f901255 100644 --- a/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java +++ b/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java @@ -42,37 +42,44 @@ public class LevellingManager { StackableManager stackableManager = skyblock.getStackableManager(); Chunk chunk = new Chunk(skyblock, island); - chunk.prepare(); + chunk.prepareInitial(); int NMSVersion = NMSUtil.getVersionNumber(); + int height = 0; + + for (IslandWorld worldList : IslandWorld.values()) { + org.bukkit.World world = worldManager.getWorld(worldList); + + if (height == 0 || height > world.getMaxHeight()) { + height = world.getMaxHeight(); + } + } + + int worldMaxHeight = height; + + boolean isEpicSpawnersEnabled = Bukkit.getPluginManager().isPluginEnabled("EpicSpawners"); + boolean isWildStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker"); + + Map levellingData = new HashMap<>(); + new BukkitRunnable() { @Override public void run() { - if (!chunk.isComplete()) return; - cancel(); + if (!chunk.isReadyToScan()) return; + + if (chunk.isFinished()) { + finalizeMaterials(levellingData, player, island); + cancel(); + return; + } Method getBlockTypeMethod = null; Method getBlockTypeIdMethod = null; Method getBlockTypeDataMethod = null; Method getMaterialMethod = null; - int worldMaxHeight = 0; - - for (IslandWorld worldList : IslandWorld.values()) { - org.bukkit.World world = worldManager.getWorld(worldList); - - if (worldMaxHeight == 0 || worldMaxHeight > world.getMaxHeight()) { - worldMaxHeight = world.getMaxHeight(); - } - } - - boolean isEpicSpawnersEnabled = Bukkit.getPluginManager().isPluginEnabled("EpicSpawners"); - boolean isWildStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker"); - - Map levellingData = new HashMap<>(); - - for (ChunkSnapshot chunkSnapshotList : chunk.getChunkSnapshots()) { + for (ChunkSnapshot chunkSnapshotList : chunk.getAvailableChunkSnapshots()) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < worldMaxHeight; y++) { @@ -175,38 +182,42 @@ public class LevellingManager { } } - Map materials = new HashMap<>(); - for (LevellingData data : levellingData.keySet()) { - long amount = levellingData.get(data); - if (data.getMaterials() != null) { - materials.put(data.getMaterials().name(), amount); - } - } - - if (materials.size() == 0) { - if (player != null) { - skyblock.getMessageManager().sendMessage(player, skyblock.getFileManager() - .getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Command.Island.Level.Materials.Message")); - skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F); - } - } else { - IslandLevel level = island.getLevel(); - level.setLastCalculatedPoints(level.getPoints()); - level.setLastCalculatedLevel(level.getLevel()); - level.setMaterials(materials); - - Bukkit.getServer().getPluginManager().callEvent( - new IslandLevelChangeEvent(island.getAPIWrapper(), island.getAPIWrapper().getLevel())); - - if (player != null) { - me.goodandevil.skyblock.menus.Levelling.getInstance().open(player); - } - } + chunk.prepareNextChunkSnapshots(); } }.runTaskTimerAsynchronously(skyblock, 0L, 1L); } + private void finalizeMaterials(Map levellingData, Player player, Island island) { + Map materials = new HashMap<>(); + for (LevellingData data : levellingData.keySet()) { + long amount = levellingData.get(data); + if (data.getMaterials() != null) { + materials.put(data.getMaterials().name(), amount); + } + } + + if (materials.size() == 0) { + if (player != null) { + skyblock.getMessageManager().sendMessage(player, skyblock.getFileManager() + .getConfig(new File(skyblock.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Command.Island.Level.Materials.Message")); + skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F); + } + } else { + IslandLevel level = island.getLevel(); + level.setLastCalculatedPoints(level.getPoints()); + level.setLastCalculatedLevel(level.getLevel()); + level.setMaterials(materials); + + Bukkit.getServer().getPluginManager().callEvent( + new IslandLevelChangeEvent(island.getAPIWrapper(), island.getAPIWrapper().getLevel())); + + if (player != null) { + me.goodandevil.skyblock.menus.Levelling.getInstance().open(player); + } + } + } + public void registerMaterials() { Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "levelling.yml")); FileConfiguration configLoad = config.getFileConfiguration(); diff --git a/src/main/resources/LICENSE b/src/main/resources/LICENSE deleted file mode 100644 index d429552d..00000000 --- a/src/main/resources/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -Copyright (c) 2018 Brianna O’Keefe - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software with minimal restriction, including the rights to use, copy, modify or merge while excluding the rights to publish, (re)distribute, sub-license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The same distribution rights and limitations above shall similarly apply to any and all source code, and other means that can be used to emulate this work. - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 8d2a3d07..f980ffa8 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -458,6 +458,11 @@ Command: Message: "&bSkyBlock &8| &aInfo&8: &7&oProcessing Island level request... Please wait!" Loading: Message: "&bSkyBlock &8| &aInfo&8: &7&oLoading Island Materials... Please wait!" + Scanning: + Progress: + Message: "&eScanning island level: &b%percent%" + Finished: + Message: "&aIsland level scan complete!" Owner: Yourself: Message: "&bSkyBlock &8| &cError&8: &eYou are not an Island owner." diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8f878b3f..a0abcbf6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: FabledSkyBlock main: me.goodandevil.skyblock.SkyBlock -version: maven-version-number +version: @version@ api-version: 1.13 description: A unique SkyBlock plugin author: Songoda From 753f1a9c5ec556e19c8738b05a85b77a53c44008 Mon Sep 17 00:00:00 2001 From: Esophose Date: Tue, 13 Aug 2019 00:35:24 -0600 Subject: [PATCH 02/11] Queue level scans --- .../skyblock/levelling/LevellingManager.java | 227 +++++++++++------- .../Core/src/main/resources/language.yml | 6 + 2 files changed, 143 insertions(+), 90 deletions(-) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java index d020d5fb..caeb2e94 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java @@ -7,6 +7,7 @@ import me.goodandevil.skyblock.island.Island; import me.goodandevil.skyblock.island.IslandLevel; import me.goodandevil.skyblock.island.IslandManager; import me.goodandevil.skyblock.island.IslandWorld; +import me.goodandevil.skyblock.message.MessageManager; import me.goodandevil.skyblock.stackable.Stackable; import me.goodandevil.skyblock.stackable.StackableManager; import me.goodandevil.skyblock.utils.version.Materials; @@ -31,9 +32,11 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Queue; import java.util.Set; import java.util.logging.Level; @@ -41,7 +44,8 @@ public class LevellingManager { private final SkyBlock skyblock; - private Set activeIslandScans = new HashSet<>(); + private Island activelyScanningIsland = null; + private Queue islandsInQueue = new LinkedList<>(); private List materialStorage = new ArrayList<>(); public LevellingManager(SkyBlock skyblock) { @@ -53,17 +57,29 @@ public class LevellingManager { public void calculatePoints(Player player, Island island) { IslandManager islandManager = skyblock.getIslandManager(); WorldManager worldManager = skyblock.getWorldManager(); + MessageManager messageManager = skyblock.getMessageManager(); StackableManager stackableManager = skyblock.getStackableManager(); - if (player != null && islandManager.getIslandPlayerAt(player) != island) { - String message = ChatColor.translateAlternateColorCodes('&', this.skyblock.getFileManager() - .getConfig(new File(this.skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Command.Island.Level.Scanning.NotOnIsland.Message")); - player.sendMessage(message); + FileConfiguration languageConfig = this.skyblock.getFileManager().getConfig(new File(this.skyblock.getDataFolder(), "language.yml")).getFileConfiguration(); + + if (!this.isIslandLevelBeingScanned(island) && player != null && islandManager.getIslandPlayerAt(player) != island) { + messageManager.sendMessage(player, languageConfig.getString("Command.Island.Level.Scanning.NotOnIsland.Message")); return; } - this.activeIslandScans.add(island); + if (this.activelyScanningIsland != null) { + this.islandsInQueue.add(new QueuedIsland(player, island)); + + String queuedMessage = languageConfig.getString("Command.Island.Level.Scanning.Queued.Message"); + islandManager.getPlayersAtIsland(island).forEach(x -> messageManager.sendMessage(x, queuedMessage)); + + return; + } + + this.activelyScanningIsland = island; + + String nowScanningMessage = languageConfig.getString("Command.Island.Level.Scanning.Started.Message"); + islandManager.getPlayersAtIsland(island).forEach(x -> messageManager.sendMessage(x, nowScanningMessage)); Chunk chunk = new Chunk(skyblock, island); chunk.prepareInitial(); @@ -100,111 +116,116 @@ public class LevellingManager { new BukkitRunnable() { @Override public void run() { - if (!chunk.isReadyToScan()) return; - - if (chunk.isFinished()) { - Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> finalizeMaterials(levellingData, spawnerLocations, epicSpawnerLocations, ultimateStackerSpawnerLocations, player, island), 1); - cancel(); + if (!chunk.isReadyToScan()) return; - } - for (LevelChunkSnapshotWrapper chunkSnapshotList : chunk.getAvailableChunkSnapshots()) { - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - for (int y = 0; y < worldMaxHeight; y++) { - ChunkSnapshot chunkSnapshot = chunkSnapshotList.getChunkSnapshot(); + try { + if (chunk.isFinished()) { + Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> finalizeMaterials(levellingData, spawnerLocations, epicSpawnerLocations, ultimateStackerSpawnerLocations, player, island), 1); + cancel(); + return; + } - try { - org.bukkit.Material blockMaterial; - int blockData = 0; - EntityType spawnerType = null; + for (LevelChunkSnapshotWrapper chunkSnapshotList : chunk.getAvailableChunkSnapshots()) { + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + for (int y = 0; y < worldMaxHeight; y++) { + ChunkSnapshot chunkSnapshot = chunkSnapshotList.getChunkSnapshot(); - if (NMSVersion > 12) { - blockMaterial = chunkSnapshot.getBlockType(x, y, z); - } else { - LegacyChunkSnapshotData data = LegacyChunkSnapshotFetcher.fetch(chunkSnapshot, x, y, z); + try { + org.bukkit.Material blockMaterial; + int blockData = 0; + EntityType spawnerType = null; - blockMaterial = data.getMaterial(); - blockData = data.getData(); - } + if (NMSVersion > 12) { + blockMaterial = chunkSnapshot.getBlockType(x, y, z); + } else { + LegacyChunkSnapshotData data = LegacyChunkSnapshotFetcher.fetch(chunkSnapshot, x, y, z); - if (blacklistedMaterials.contains(blockMaterial)) - continue; + blockMaterial = data.getMaterial(); + blockData = data.getData(); + } - long amount = 1; + if (blacklistedMaterials.contains(blockMaterial)) + continue; - if (blockMaterial == Materials.SPAWNER.parseMaterial()) { - World world = Bukkit.getWorld(chunkSnapshot.getWorldName()); - Location location = new Location(world, chunkSnapshot.getX() * 16 + x, y, chunkSnapshot.getZ() * 16 + z); + long amount = 1; - if (isEpicSpawnersEnabled) { - com.songoda.epicspawners.EpicSpawners epicSpawners = com.songoda.epicspawners.EpicSpawners.getInstance(); - if (epicSpawners.getSpawnerManager().isSpawner(location)) { - com.songoda.epicspawners.spawners.spawner.Spawner spawner = epicSpawners.getSpawnerManager().getSpawnerFromWorld(location); - if (spawner != null) - epicSpawnerLocations.add(location); + if (blockMaterial == Materials.SPAWNER.parseMaterial()) { + World world = Bukkit.getWorld(chunkSnapshot.getWorldName()); + Location location = new Location(world, chunkSnapshot.getX() * 16 + x, y, chunkSnapshot.getZ() * 16 + z); + + if (isEpicSpawnersEnabled) { + com.songoda.epicspawners.EpicSpawners epicSpawners = com.songoda.epicspawners.EpicSpawners.getInstance(); + if (epicSpawners.getSpawnerManager().isSpawner(location)) { + com.songoda.epicspawners.spawners.spawner.Spawner spawner = epicSpawners.getSpawnerManager().getSpawnerFromWorld(location); + if (spawner != null) + epicSpawnerLocations.add(location); + continue; + } + } else if (isUltimateStackerEnabled) { + com.songoda.ultimatestacker.spawner.SpawnerStack spawnerStack = com.songoda.ultimatestacker.UltimateStacker.getInstance().getSpawnerStackManager().getSpawner(location); + if (spawnerStack != null) + ultimateStackerSpawnerLocations.add(location); continue; } - } else if (isUltimateStackerEnabled) { - com.songoda.ultimatestacker.spawner.SpawnerStack spawnerStack = com.songoda.ultimatestacker.UltimateStacker.getInstance().getSpawnerStackManager().getSpawner(location); - if (spawnerStack != null) - ultimateStackerSpawnerLocations.add(location); - continue; - } - if (chunkSnapshotList.hasWildStackerData()) { - com.bgsoftware.wildstacker.api.objects.StackedSnapshot snapshot = ((WildStackerChunkSnapshotWrapper)chunkSnapshotList).getStackedSnapshot(); - if (snapshot.isStackedSpawner(location)) { - Map.Entry spawnerData = snapshot.getStackedSpawner(location); - amount = spawnerData.getKey(); - spawnerType = spawnerData.getValue(); + if (chunkSnapshotList.hasWildStackerData()) { + com.bgsoftware.wildstacker.api.objects.StackedSnapshot snapshot = ((WildStackerChunkSnapshotWrapper) chunkSnapshotList).getStackedSnapshot(); + if (snapshot.isStackedSpawner(location)) { + Map.Entry spawnerData = snapshot.getStackedSpawner(location); + amount = spawnerData.getKey(); + spawnerType = spawnerData.getValue(); + } } - } - if (spawnerType == null) { - spawnerLocations.add(location); - continue; - } - } else { - if (chunkSnapshotList.hasWildStackerData()) { - com.bgsoftware.wildstacker.api.objects.StackedSnapshot snapshot = ((WildStackerChunkSnapshotWrapper)chunkSnapshotList).getStackedSnapshot(); - World world = Bukkit.getWorld(chunkSnapshot.getWorldName()); - Location location = new Location(world, chunkSnapshot.getX() * 16 + x, y, chunkSnapshot.getZ() * 16 + z); - if (snapshot.isStackedBarrel(location)) { - Map.Entry barrelData = snapshot.getStackedBarrel(location); - amount = barrelData.getKey(); - blockMaterial = barrelData.getValue(); - if (NMSUtil.getVersionNumber() > 12 && blockMaterial.name().startsWith("LEGACY_")) { - blockMaterial = Material.matchMaterial(blockMaterial.name().replace("LEGACY_", "")); + if (spawnerType == null) { + spawnerLocations.add(location); + continue; + } + } else { + if (chunkSnapshotList.hasWildStackerData()) { + com.bgsoftware.wildstacker.api.objects.StackedSnapshot snapshot = ((WildStackerChunkSnapshotWrapper) chunkSnapshotList).getStackedSnapshot(); + World world = Bukkit.getWorld(chunkSnapshot.getWorldName()); + Location location = new Location(world, chunkSnapshot.getX() * 16 + x, y, chunkSnapshot.getZ() * 16 + z); + if (snapshot.isStackedBarrel(location)) { + Map.Entry barrelData = snapshot.getStackedBarrel(location); + amount = barrelData.getKey(); + blockMaterial = barrelData.getValue(); + if (NMSUtil.getVersionNumber() > 12 && blockMaterial.name().startsWith("LEGACY_")) { + blockMaterial = Material.matchMaterial(blockMaterial.name().replace("LEGACY_", "")); + } + } + } + + if (stackableManager != null && stackableManager.getStackableMaterials().contains(blockMaterial) && amount == 1) { + World world = Bukkit.getWorld(chunkSnapshot.getWorldName()); + Location location = new Location(world, chunkSnapshot.getX() * 16 + x, y, chunkSnapshot.getZ() * 16 + z); + if (stackableManager.isStacked(location)) { + Stackable stackable = stackableManager.getStack(location, blockMaterial); + if (stackable != null) { + amount = stackable.getSize(); + } } } } - if (stackableManager != null && stackableManager.getStackableMaterials().contains(blockMaterial) && amount == 1) { - World world = Bukkit.getWorld(chunkSnapshot.getWorldName()); - Location location = new Location(world, chunkSnapshot.getX() * 16 + x, y, chunkSnapshot.getZ() * 16 + z); - if (stackableManager.isStacked(location)) { - Stackable stackable = stackableManager.getStack(location, blockMaterial); - if (stackable != null) { - amount = stackable.getSize(); - } - } - } + LevellingData data = new LevellingData(blockMaterial, (byte) blockData, spawnerType); + Long totalAmountInteger = levellingData.get(data); + long totalAmount = totalAmountInteger == null ? amount : totalAmountInteger + amount; + levellingData.put(data, totalAmount); + } catch (Exception e) { + e.printStackTrace(); } - - LevellingData data = new LevellingData(blockMaterial, (byte) blockData, spawnerType); - Long totalAmountInteger = levellingData.get(data); - long totalAmount = totalAmountInteger == null ? amount : totalAmountInteger + amount; - levellingData.put(data, totalAmount); - } catch (Exception e) { - e.printStackTrace(); } } } } - } - chunk.prepareNextChunkSnapshots(); + chunk.prepareNextChunkSnapshots(); + } catch (Exception ex) { + skyblock.getLogger().severe("An error occurred while scanning an island. This is a severe error."); + } } }.runTaskTimerAsynchronously(skyblock, 0L, 1L); } @@ -282,7 +303,15 @@ public class LevellingManager { } } - this.activeIslandScans.remove(island); + MessageManager messageManager = skyblock.getMessageManager(); + FileConfiguration languageConfig = this.skyblock.getFileManager().getConfig(new File(this.skyblock.getDataFolder(), "language.yml")).getFileConfiguration(); + String nowScanningMessage = languageConfig.getString("Command.Island.Level.Scanning.Done.Message"); + skyblock.getIslandManager().getPlayersAtIsland(island).forEach(x -> messageManager.sendMessage(x, nowScanningMessage)); + + this.activelyScanningIsland = null; + QueuedIsland nextInQueue = this.islandsInQueue.poll(); + if (nextInQueue != null) + this.calculatePoints(nextInQueue.getPlayer(), nextInQueue.getIsland()); } public void registerMaterials() { @@ -307,7 +336,7 @@ public class LevellingManager { } public boolean isIslandLevelBeingScanned(Island island) { - return this.activeIslandScans.contains(island); + return this.islandsInQueue.stream().anyMatch(x -> x.getIsland() == island) || this.activelyScanningIsland == island; } public void unregisterMaterials() { @@ -385,4 +414,22 @@ public class LevellingManager { return Materials.getMaterials(this.material, this.data); } } + + private class QueuedIsland { + private final Player player; + private final Island island; + + public QueuedIsland(Player player, Island island) { + this.player = player; + this.island = island; + } + + public Player getPlayer() { + return this.player; + } + + public Island getIsland() { + return this.island; + } + } } diff --git a/FabledSkyBlock/Core/src/main/resources/language.yml b/FabledSkyBlock/Core/src/main/resources/language.yml index 99d79564..ff2e0f20 100644 --- a/FabledSkyBlock/Core/src/main/resources/language.yml +++ b/FabledSkyBlock/Core/src/main/resources/language.yml @@ -84,6 +84,12 @@ Command: Message: '&bSkyBlock &8| &cError&8: &eYou cannot initiate an Island level scan without being on your Island.' BlockPlacing: Message: '&bSkyBlock &8 | &cError:&8: &eYou cannot place blocks during an Island level scan. Please wait for the scan to finish.' + Started: + Message: '&bSkyBlock &8| &aInfo&8: &eA level scan has started on this island.' + Queued: + Message: '&bSkyBlock &8| &aInfo&8: &eA level scan has been &aqueued&e for this island. The scan will start as soon as all other queued scans are complete.' + Done: + Message: '&bSkyBlock &8| &aInfo&8: &eThe scan has completed.' Cooldown: Word: Minute: minute(s) From 3265fcc15caf0977f4badaaa9ad91d00b3b15556 Mon Sep 17 00:00:00 2001 From: Esophose Date: Tue, 13 Aug 2019 01:12:47 -0600 Subject: [PATCH 03/11] build.gradle updates for WildStackerAPI --- FabledSkyBlock/Core/build.gradle | 2 +- build.gradle | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/FabledSkyBlock/Core/build.gradle b/FabledSkyBlock/Core/build.gradle index b5de158c..12e33b7d 100644 --- a/FabledSkyBlock/Core/build.gradle +++ b/FabledSkyBlock/Core/build.gradle @@ -28,7 +28,7 @@ dependencies { compileOnly (group: 'com.songoda', name: 'ultimatestacker', version: '1.3.1') // WildStacker - compileOnly (group: 'com.bgsoftware', name: 'wildstacker-api', version: 'b15') + compileOnly (group: 'com.github.OmerBenGera', name: 'WildStackerAPI', version: 'b15') // WorldEdit compileOnly (group: 'com.sk89q', name: 'worldedit', version: '7.0.0') diff --git a/build.gradle b/build.gradle index 8cca8ecd..f8bf008e 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,10 @@ subprojects { maven { url = 'http://repo.songoda.com/artifactory/private' } + + maven { + url = 'https://jitpack.io' + } } } From b281f61eefd900bd4acb94bb84a17578d803dfbb Mon Sep 17 00:00:00 2001 From: Esophose Date: Tue, 13 Aug 2019 11:35:28 -0600 Subject: [PATCH 04/11] Stackable consistency, ender pearls not working, lava/water check fixes --- .../skyblock/generator/GeneratorManager.java | 120 +----------------- .../skyblock/listeners/Teleport.java | 2 +- .../skyblock/stackable/Stackable.java | 23 ++-- 3 files changed, 13 insertions(+), 132 deletions(-) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/generator/GeneratorManager.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/generator/GeneratorManager.java index 14525c02..3aed87ba 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/generator/GeneratorManager.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/generator/GeneratorManager.java @@ -75,11 +75,11 @@ public class GeneratorManager { } private boolean isLava(Block block) { - return block.getType().equals(Materials.LAVA.parseMaterial()) || block.getType().equals(Materials.LEGACY_STATIONARY_LAVA.parseMaterial()); + return block.getType().name().contains("LAVA"); } private boolean isWater(Block block) { - return block.getType().equals(Materials.WATER.parseMaterial()) || block.getType().equals(Materials.LEGACY_STATIONARY_WATER.parseMaterial()); + return block.getType().name().contains("WATER"); } public boolean isGenerator(Block block) { @@ -98,122 +98,6 @@ public class GeneratorManager { } return false; - - //region GoodAndEvil his old code (garbage) - /* - if (block.getRelative(BlockFace.UP).getType() != Materials.LEGACY_STATIONARY_WATER.getPostMaterial() - && block.getRelative(BlockFace.UP).getType() != Materials.WATER.parseMaterial()) { - Block flowBlock = null; - - if ((block.getRelative(BlockFace.EAST).getType() == Materials.LEGACY_STATIONARY_WATER.getPostMaterial() - || block.getRelative(BlockFace.EAST).getType() == Materials.WATER.parseMaterial()) - && (block.getRelative(BlockFace.WEST).getType() == Materials.LEGACY_STATIONARY_LAVA - .getPostMaterial() - || block.getRelative(BlockFace.WEST).getType() == Materials.LAVA.parseMaterial()) - && (block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock().getRelative(BlockFace.EAST) - .getType() == Material.AIR - || block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock() - .getRelative(BlockFace.EAST) - .getType() == Materials.LEGACY_STATIONARY_WATER.getPostMaterial())) { - if (!isFlowingTowardsBlock(block, BlockFace.NORTH, BlockFace.SOUTH)) { - return false; - } else if (!isFlowingTowardsBlock(block, BlockFace.SOUTH, BlockFace.NORTH)) { - return false; - } - - flowBlock = block.getRelative(BlockFace.EAST); - } else if ((block.getRelative(BlockFace.EAST).getType() == Materials.LEGACY_STATIONARY_LAVA - .getPostMaterial() || block.getRelative(BlockFace.EAST).getType() == Materials.LAVA.parseMaterial()) - && (block.getRelative(BlockFace.WEST).getType() == Materials.LEGACY_STATIONARY_WATER - .getPostMaterial() - || block.getRelative(BlockFace.WEST).getType() == Materials.WATER.parseMaterial()) - && (block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock().getRelative(BlockFace.WEST) - .getType() == Material.AIR - || block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock() - .getRelative(BlockFace.WEST) - .getType() == Materials.LEGACY_STATIONARY_WATER.getPostMaterial())) { - if (!isFlowingTowardsBlock(block, BlockFace.NORTH, BlockFace.SOUTH)) { - return false; - } else if (!isFlowingTowardsBlock(block, BlockFace.SOUTH, BlockFace.NORTH)) { - return false; - } - - flowBlock = block.getRelative(BlockFace.WEST); - } else if (((block.getRelative(BlockFace.NORTH).getType() == Materials.LEGACY_STATIONARY_WATER - .getPostMaterial() - || block.getRelative(BlockFace.NORTH).getType() == Materials.WATER.parseMaterial())) - && (block.getRelative(BlockFace.SOUTH).getType() == Materials.LEGACY_STATIONARY_LAVA - .getPostMaterial() - || block.getRelative(BlockFace.SOUTH).getType() == Materials.LAVA.parseMaterial()) - && (block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock().getRelative(BlockFace.NORTH) - .getType() == Material.AIR - || block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock() - .getRelative(BlockFace.NORTH) - .getType() == Materials.LEGACY_STATIONARY_WATER.getPostMaterial())) { - if (!isFlowingTowardsBlock(block, BlockFace.WEST, BlockFace.EAST)) { - return false; - } else if (!isFlowingTowardsBlock(block, BlockFace.EAST, BlockFace.WEST)) { - return false; - } - - flowBlock = block.getRelative(BlockFace.NORTH); - } else if (((block.getRelative(BlockFace.NORTH).getType() == Materials.LEGACY_STATIONARY_LAVA - .getPostMaterial() - || block.getRelative(BlockFace.NORTH).getType() == Materials.LAVA.parseMaterial())) - && (block.getRelative(BlockFace.SOUTH).getType() == Materials.LEGACY_STATIONARY_WATER - .getPostMaterial() - || block.getRelative(BlockFace.SOUTH).getType() == Materials.WATER.parseMaterial()) - && (block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock().getRelative(BlockFace.SOUTH) - .getType() == Material.AIR - || block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock() - .getRelative(BlockFace.SOUTH) - .getType() == Materials.LEGACY_STATIONARY_WATER.getPostMaterial())) { - if (!isFlowingTowardsBlock(block, BlockFace.WEST, BlockFace.EAST)) { - return false; - } else if (!isFlowingTowardsBlock(block, BlockFace.EAST, BlockFace.WEST)) { - return false; - } - - flowBlock = block.getRelative(BlockFace.SOUTH); - } - - if (flowBlock != null) { - return isFlowingBlock(flowBlock); - } - } - - return false; - } - - private boolean isFlowingTowardsBlock(Block block, BlockFace blockFace1, BlockFace blockFace2) { - if (block.getRelative(blockFace1).getType() == Materials.LEGACY_STATIONARY_WATER.getPostMaterial() - || block.getRelative(blockFace1).getType() == Materials.WATER.parseMaterial()) { - if (isFlowingBlock(block.getRelative(blockFace1)) && (block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D) - .getBlock().getRelative(blockFace1).getType() == Materials.LEGACY_STATIONARY_WATER.getPostMaterial() - || block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock().getRelative(blockFace1) - .getType() == Materials.WATER.parseMaterial())) { - if (block.getRelative(blockFace2).getType() == Materials.LEGACY_STATIONARY_WATER.getPostMaterial() - || block.getRelative(blockFace2).getType() == Materials.WATER.parseMaterial()) { - if (isFlowingBlock(block.getRelative(blockFace2)) && (block.getLocation().clone() - .subtract(0.0D, 1.0D, 0.0D).getBlock().getRelative(blockFace2) - .getType() == Materials.LEGACY_STATIONARY_WATER.getPostMaterial() - || block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock().getRelative(blockFace2) - .getType() == Materials.WATER.parseMaterial())) { - return true; - } else { - return false; - } - } else { - return true; - } - } else { - return false; - } - } - - return true; - */ - //endregion } @SuppressWarnings("deprecation") diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Teleport.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Teleport.java index 4c73eb0a..7d4a8a21 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Teleport.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Teleport.java @@ -77,7 +77,7 @@ public class Teleport implements Listener { return; } - if (isCause) { + if (isCause && event.getCause() != TeleportCause.ENDER_PEARL) { event.setCancelled(true); return; } diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/stackable/Stackable.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/stackable/Stackable.java index 1e1bcaac..b158a86a 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/stackable/Stackable.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/stackable/Stackable.java @@ -31,7 +31,7 @@ public class Stackable { public Stackable(Location location, Material material) { this.uuid = UUID.randomUUID(); - this.location = location; + this.location = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ()); this.material = material; this.updateDisplay(); SkyBlock.getInstance().getSoundManager().playSound(location, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); @@ -40,7 +40,7 @@ public class Stackable { public Stackable(UUID uuid, Location location, Material material, int size) { this.uuid = uuid; - this.location = location; + this.location = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ()); this.material = material; this.size = size; this.updateDisplay(); @@ -78,14 +78,14 @@ public class Stackable { } public void addOne() { - this.size ++; + this.size++; this.updateDisplay(); SkyBlock.getInstance().getSoundManager().playSound(this.location, Sounds.LEVEL_UP.bukkitSound(), 1.0F, 1.0F); this.save(); } public void takeOne() { - this.size --; + this.size--; this.updateDisplay(); SkyBlock.getInstance().getSoundManager().playSound(this.location, Sounds.ARROW_HIT.bukkitSound(), 1.0F, 1.0F); this.save(); @@ -93,7 +93,6 @@ public class Stackable { private void updateDisplay() { if (this.size > 1) { - this.removeDisplay(); this.createDisplay(); this.display.setCustomName(this.getCustomName()); this.display.setCustomNameVisible(true); @@ -101,10 +100,10 @@ public class Stackable { this.removeDisplay(); } } - + private void createDisplay() { this.removeDisplay(); - + Location dropLocation = this.location.clone().add(0.5, 1, 0.5); ArmorStand as = (ArmorStand) this.location.getWorld().spawnEntity(dropLocation, EntityType.ARMOR_STAND); as.setVisible(false); @@ -124,13 +123,11 @@ public class Stackable { if (this.display != null) { this.display.remove(); } - + // Find any stragglers - for (Entity entity : this.location.getWorld().getNearbyEntities(this.location.clone().add(0.5, 0.55, 0.5), 0.1, 0.5, 0.1)) { - if (entity instanceof ArmorStand && entity.isValid()) { + for (Entity entity : this.location.getWorld().getNearbyEntities(this.location.clone().add(0.5, 0.55, 0.5), 0.1, 0.5, 0.1)) + if (entity instanceof ArmorStand) entity.remove(); - } - } } private void save() { @@ -138,7 +135,7 @@ public class Stackable { FileManager.Config config = SkyBlock.getInstance().getFileManager().getConfig(new File(configFile, SkyBlock.getInstance().getIslandManager().getIslandAtLocation(this.location).getOwnerUUID() + ".yml")); FileConfiguration configLoad = config.getFileConfiguration(); - + if (this.getSize() == 0) { configLoad.set("Stackables." + this.getUuid().toString(), null); } else { From b8d17f466d8df07a2b6e8c0ba7a0d74f6733fe37 Mon Sep 17 00:00:00 2001 From: Esophose Date: Wed, 14 Aug 2019 22:03:37 -0600 Subject: [PATCH 05/11] Fix stackable displays sometimes endlessly stacking up armor stands --- .../java/me/goodandevil/skyblock/stackable/Stackable.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/stackable/Stackable.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/stackable/Stackable.java index b158a86a..e93b7749 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/stackable/Stackable.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/stackable/Stackable.java @@ -5,6 +5,7 @@ import java.util.UUID; import me.goodandevil.skyblock.utils.NumberUtil; import org.apache.commons.lang3.text.WordUtils; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -92,6 +93,10 @@ public class Stackable { } private void updateDisplay() { + // The chunk needs to be loaded otherwise the getNearbyEntities() in removeDisplay() won't find anything + if (!this.location.getWorld().isChunkLoaded(this.location.getBlockX() >> 4, this.location.getBlockZ() >> 4)) + this.location.getChunk().load(); + if (this.size > 1) { this.createDisplay(); this.display.setCustomName(this.getCustomName()); @@ -125,7 +130,7 @@ public class Stackable { } // Find any stragglers - for (Entity entity : this.location.getWorld().getNearbyEntities(this.location.clone().add(0.5, 0.55, 0.5), 0.1, 0.5, 0.1)) + for (Entity entity : this.location.getWorld().getNearbyEntities(this.location.clone().add(0.5, 0.55, 0.5), 0.25, 0.5, 0.25)) if (entity instanceof ArmorStand) entity.remove(); } From cb0e3ee2815398de79d0fd6ea999b0bf012ed8af Mon Sep 17 00:00:00 2001 From: Esophose Date: Wed, 14 Aug 2019 22:03:44 -0600 Subject: [PATCH 06/11] Cache the materials... duh --- .../skyblock/utils/version/Materials.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java index d9ead1ea..2f1c3726 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java @@ -1059,6 +1059,7 @@ public enum Materials { String old12Mat; int data; boolean is13Plusonly; + private Material cachedMaterial; Materials(String old13Mat, String old12Mat, int data) { this(old13Mat, old12Mat, data, false); @@ -1236,20 +1237,30 @@ public enum Materials { } public Material parseMaterial() { - if (this.isSpawner() && this != Materials.SPAWNER) - return Materials.SPAWNER.parseMaterial(); + if (this.cachedMaterial != null) + return this.cachedMaterial; + + if (this.isSpawner() && this != Materials.SPAWNER) { + this.cachedMaterial = Materials.SPAWNER.parseMaterial(); + return this.cachedMaterial; + } Material mat = Material.matchMaterial(this.toString()); - if (mat != null) - return mat; + if (mat != null) { + this.cachedMaterial = mat; + return this.cachedMaterial; + } if (old13Mat != null) { mat = Material.matchMaterial(old13Mat); - if (mat != null) - return mat; + if (mat != null) { + this.cachedMaterial = mat; + return this.cachedMaterial; + } } - return Material.matchMaterial(old12Mat); + this.cachedMaterial = Material.matchMaterial(old12Mat); + return this.cachedMaterial; } public Material getPostMaterial() { From 6bb498c6071eff6861f1ba35f3c3a078924ab82f Mon Sep 17 00:00:00 2001 From: Esophose Date: Wed, 14 Aug 2019 22:26:47 -0600 Subject: [PATCH 07/11] Potential ban fixes --- .../Core/src/main/java/me/goodandevil/skyblock/ban/Ban.java | 2 +- .../Core/src/main/java/me/goodandevil/skyblock/menus/Bans.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/ban/Ban.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/ban/Ban.java index bc80d1a5..0ff1740c 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/ban/Ban.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/ban/Ban.java @@ -58,7 +58,7 @@ public class Ban { skyblock.getIslandManager().getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)) .getAPIWrapper(), Bukkit.getServer().getOfflinePlayer(issuer), Bukkit.getServer().getOfflinePlayer(banned)); - Bukkit.getScheduler().runTask(skyblock, () -> Bukkit.getServer().getPluginManager().callEvent(islandBanEvent)); + Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> Bukkit.getServer().getPluginManager().callEvent(islandBanEvent)); if (!islandBanEvent.isCancelled()) { List islandBans = new ArrayList<>(); diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/menus/Bans.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/menus/Bans.java index b0266fff..fa550028 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/menus/Bans.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/menus/Bans.java @@ -223,7 +223,7 @@ public class Bans { nInv.createItem(SkullUtil.create(targetPlayerTexture[0], targetPlayerTexture[1]), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menu.Bans.Item.Ban.Displayname") - .replace("%player", targetPlayerName)), + .replace("%player", targetPlayerName == null ? "" : targetPlayerName)), configLoad.getStringList("Menu.Bans.Item.Ban.Lore"), null, null, null), inventorySlot); } From 2c8c6190eeb173422aa96901d637832a36a47206 Mon Sep 17 00:00:00 2001 From: Esophose Date: Wed, 14 Aug 2019 23:23:31 -0600 Subject: [PATCH 08/11] Added support for Reserve economy --- FabledSkyBlock/Core/build.gradle | 3 + .../skyblock/economy/EconomyManager.java | 61 ++++++++++++++----- .../skyblock/utils/version/Materials.java | 4 +- .../Core/src/main/resources/plugin.yml | 2 +- build.gradle | 2 +- 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/FabledSkyBlock/Core/build.gradle b/FabledSkyBlock/Core/build.gradle index 12e33b7d..f2cd67c5 100644 --- a/FabledSkyBlock/Core/build.gradle +++ b/FabledSkyBlock/Core/build.gradle @@ -15,6 +15,9 @@ dependencies { // Vault compileOnly (group: 'net.milkbowl', name: 'vault', version: '1.7.1') + // Reserve + compileOnly (group: 'net.tnemc', name: 'Reserve', version: '0.1.3.0') + // Leaderheads compileOnly (group: 'me.robin', name: 'leaderheads', version: '1.0') diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/economy/EconomyManager.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/economy/EconomyManager.java index 8838fc50..e13373a1 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/economy/EconomyManager.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/economy/EconomyManager.java @@ -3,16 +3,25 @@ package me.goodandevil.skyblock.economy; import me.goodandevil.skyblock.api.event.player.PlayerWithdrawMoneyEvent; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; +import net.tnemc.core.Reserve; +import net.tnemc.core.economy.EconomyAPI; +import net.tnemc.core.permissions.PermissionsAPI; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; +import java.math.BigDecimal; + public class EconomyManager { - private Economy economy = null; - private Permission permission = null; + // Vault + private Economy vaultEconomy = null; + private Permission vaultPermission = null; + + // Reserve + private EconomyAPI reserveEconomy = null; +// private PermissionsAPI reservePermission = null; public EconomyManager() { setup(); @@ -23,48 +32,68 @@ public class EconomyManager { RegisteredServiceProvider economyRsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); if (economyRsp != null) - economy = economyRsp.getProvider(); + this.vaultEconomy = economyRsp.getProvider(); RegisteredServiceProvider permissionRsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class); if (permissionRsp != null) - permission = permissionRsp.getProvider(); + this.vaultPermission = permissionRsp.getProvider(); + } else if (Bukkit.getServer().getPluginManager().getPlugin("Reserve") != null) { + if (Reserve.instance().economyProvided()) + this.reserveEconomy = Reserve.instance().economy(); + +// if (Reserve.instance().permissionsProvided()) +// this.reservePermission = Reserve.instance().permissions(); } } public double getBalance(Player player) { - return economy == null ? 0.0D : economy.getBalance(player); + if (this.vaultEconomy != null) + return this.vaultEconomy.getBalance(player); + + if (this.reserveEconomy != null) + return this.reserveEconomy.getHoldings(player.getUniqueId()).doubleValue(); + + return 0; } public boolean hasBalance(Player player, double money) { - return getBalance(player) >= money; + return this.getBalance(player) >= money; } public void withdraw(Player player, double money) { - if (economy != null) - economy.withdrawPlayer(player, money); + if (this.vaultEconomy != null) + this.vaultEconomy.withdrawPlayer(player, money); + else if (this.reserveEconomy != null) + this.reserveEconomy.removeHoldings(player.getUniqueId(), new BigDecimal(money)); Bukkit.getServer().getPluginManager().callEvent(new PlayerWithdrawMoneyEvent(player, money)); } public void deposit(Player player, double money) { - if (economy != null) { - economy.depositPlayer(player, money); - } + if (this.vaultEconomy != null) + this.vaultEconomy.depositPlayer(player, money); + else if (this.reserveEconomy != null) + this.reserveEconomy.addHoldings(player.getUniqueId(), new BigDecimal(money)); Bukkit.getServer().getPluginManager().callEvent(new PlayerWithdrawMoneyEvent(player, money)); } public boolean hasPermission(String world, OfflinePlayer offlinePlayer, String perm) { - if (permission != null) - return permission.playerHas(world, offlinePlayer, perm); + if (this.vaultPermission != null) + return this.vaultPermission.playerHas(world, offlinePlayer, perm); + +// if (this.reservePermission != null) { +// // TODO +// } + return false; } public boolean isEconomy() { - return economy != null; + return this.vaultEconomy != null || this.reserveEconomy != null; } public boolean isPermission() { - return permission != null; + return this.vaultPermission != null/* || this.reservePermission != null*/; } } diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java index 2f1c3726..abb4b230 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java @@ -1060,6 +1060,7 @@ public enum Materials { int data; boolean is13Plusonly; private Material cachedMaterial; + private boolean isMaterialParsed = false; Materials(String old13Mat, String old12Mat, int data) { this(old13Mat, old12Mat, data, false); @@ -1237,7 +1238,7 @@ public enum Materials { } public Material parseMaterial() { - if (this.cachedMaterial != null) + if (this.cachedMaterial != null || this.isMaterialParsed) return this.cachedMaterial; if (this.isSpawner() && this != Materials.SPAWNER) { @@ -1260,6 +1261,7 @@ public enum Materials { } this.cachedMaterial = Material.matchMaterial(old12Mat); + this.isMaterialParsed = true; return this.cachedMaterial; } diff --git a/FabledSkyBlock/Core/src/main/resources/plugin.yml b/FabledSkyBlock/Core/src/main/resources/plugin.yml index 41196861..06c2d9fb 100644 --- a/FabledSkyBlock/Core/src/main/resources/plugin.yml +++ b/FabledSkyBlock/Core/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ version: @version@ api-version: 1.13 description: A unique SkyBlock plugin author: Songoda -softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, LeaderHeads, EpicSpawners, WildStacker, UltimateStacker, WorldEdit] +softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, Reserve, LeaderHeads, EpicSpawners, WildStacker, UltimateStacker, WorldEdit] loadbefore: [Multiverse-Core] commands: island: diff --git a/build.gradle b/build.gradle index f8bf008e..e3497f10 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ allprojects { apply plugin: 'java' group = 'com.goodandevil.skyblock' - version = 'Build-78' + version = 'Build-78.3' } subprojects { From 33d589387f219bb504a9879bb04e8ddeb8062338 Mon Sep 17 00:00:00 2001 From: Esophose Date: Thu, 15 Aug 2019 00:36:06 -0600 Subject: [PATCH 09/11] Visitor spawn protection --- .../skyblock/generator/GeneratorManager.java | 2 +- .../goodandevil/skyblock/listeners/Block.java | 29 +++++++++---------- .../skyblock/listeners/Bucket.java | 3 +- .../skyblock/listeners/Entity.java | 6 ++-- .../skyblock/utils/world/LocationUtil.java | 9 +++++- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/generator/GeneratorManager.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/generator/GeneratorManager.java index 3aed87ba..a97a9ef5 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/generator/GeneratorManager.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/generator/GeneratorManager.java @@ -140,7 +140,7 @@ public class GeneratorManager { } public Materials getRandomMaterials(Generator generator) { - if (generator.getGeneratorMaterials() != null && generator.getGeneratorMaterials().size() != 0) { + if (generator.getGeneratorMaterials() != null && generator.getGeneratorMaterials().stream().anyMatch(x -> x.getChance() > 0)) { List weightedList = new ArrayList<>(); for (GeneratorMaterial generatorMaterial : generator.getGeneratorMaterials()) for (int i = 0; i < generatorMaterial.getChance() * 30; i++) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Block.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Block.java index b8cd8749..c3c2e7f7 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Block.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Block.java @@ -228,7 +228,7 @@ public class Block implements Listener { if (configLoad.getBoolean("Island.Spawn.Protection")) { boolean isObstructing = false; // Directly on the block - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main))) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) { isObstructing = true; } @@ -236,7 +236,7 @@ public class Block implements Listener { if (!isObstructing && event.getBlock().getState().getData() instanceof org.bukkit.material.Bed) { BlockFace bedDirection = ((org.bukkit.material.Bed) event.getBlock().getState().getData()).getFacing(); org.bukkit.block.Block bedBlock = block.getRelative(bedDirection); - if (LocationUtil.isLocationAffectingLocation(bedBlock.getLocation(), island.getLocation(world, IslandEnvironment.Main))) + if (LocationUtil.isLocationAffectingIslandSpawn(bedBlock.getLocation(), island, world)) isObstructing = true; } @@ -319,7 +319,7 @@ public class Block implements Listener { } // Protect spawn - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main)) && configLoad.getBoolean("Island.Spawn.Protection")) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world) && configLoad.getBoolean("Island.Spawn.Protection")) { event.setCancelled(true); return; } @@ -391,13 +391,13 @@ public class Block implements Listener { if (configLoad.getBoolean("Island.Spawn.Protection")) { // Check exact block - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main))) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) { event.setCancelled(true); return; } // Check block in direction - if (LocationUtil.isLocationAffectingLocation(block.getRelative(event.getDirection()).getLocation(), island.getLocation(world, IslandEnvironment.Main))) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getRelative(event.getDirection()).getLocation(), island, world)) { event.setCancelled(true); return; } @@ -413,7 +413,7 @@ public class Block implements Listener { // Check piston head if (configLoad.getBoolean("Island.Spawn.Protection")) { - if (LocationUtil.isLocationAffectingLocation(event.getBlock().getRelative(event.getDirection()).getLocation(), island.getLocation(world, IslandEnvironment.Main))) { + if (LocationUtil.isLocationAffectingIslandSpawn(event.getBlock().getRelative(event.getDirection()).getLocation(), island, world)) { event.setCancelled(true); } } @@ -445,7 +445,7 @@ public class Block implements Listener { return; } - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main)) && configLoad.getBoolean("Island.Spawn.Protection")) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world) && configLoad.getBoolean("Island.Spawn.Protection")) { event.setCancelled(true); return; } @@ -482,7 +482,7 @@ public class Block implements Listener { // Check spawn block protection IslandWorld world = worldManager.getIslandWorld(event.getBlock().getWorld()); - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main))) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) { if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) { event.setCancelled(true); return; @@ -586,7 +586,7 @@ public class Block implements Listener { // Check spawn block protection IslandWorld world = worldManager.getIslandWorld(event.getBlock().getWorld()); - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main))) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) { if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) { event.setCancelled(true); return; @@ -660,7 +660,7 @@ public class Block implements Listener { Location islandLocation = island.getLocation(world, IslandEnvironment.Main); for (org.bukkit.block.BlockState block : event.getBlocks()) { - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) { event.setCancelled(true); return; } @@ -687,10 +687,9 @@ public class Block implements Listener { // Check spawn block protection IslandWorld world = worldManager.getIslandWorld(event.getBlocks().get(0).getWorld()); - Location islandLocation = island.getLocation(world, IslandEnvironment.Main); for (BlockState block : blocks) { - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) { event.setCancelled(true); return; } @@ -708,10 +707,9 @@ public class Block implements Listener { // Check spawn block protection IslandWorld world = worldManager.getIslandWorld(blocks.get(0).getWorld()); - Location islandLocation = island.getLocation(world, IslandEnvironment.Main); for (org.bukkit.block.Block block : blocks) { - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) { event.setCancelled(true); return; } @@ -739,9 +737,8 @@ public class Block implements Listener { // Check spawn block protection IslandWorld world = worldManager.getIslandWorld(placeLocation.getWorld()); - Location islandLocation = island.getLocation(world, IslandEnvironment.Main); - if (LocationUtil.isLocationAffectingLocation(placeLocation.getLocation(), islandLocation)) { + if (LocationUtil.isLocationAffectingIslandSpawn(placeLocation.getLocation(), island, world)) { event.setCancelled(true); } } diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Bucket.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Bucket.java index 48ac617b..ee974752 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Bucket.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Bucket.java @@ -77,8 +77,7 @@ public class Bucket implements Listener { // Check spawn block protection IslandWorld world = worldManager.getIslandWorld(block.getWorld()); - Location islandLocation = island.getLocation(world, IslandEnvironment.Main); - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) { + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world)) { event.setCancelled(true); skyblock.getMessageManager().sendMessage(player, skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Entity.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Entity.java index 6738ff14..b6cb143e 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Entity.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Entity.java @@ -418,8 +418,8 @@ public class Entity implements Listener { org.bukkit.block.Block block = event.getBlock(); // Check spawn block falling, this can be a bit glitchy, but it's better than nothing - Location islandLocation = island.getLocation(world, IslandEnvironment.Main); - if (LocationUtil.isLocationLocation(block.getLocation(), islandLocation.clone().subtract(0, 1, 0)) && + if ((LocationUtil.isLocationLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main).clone().subtract(0, 1, 0)) + || LocationUtil.isLocationLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Visitor).clone().subtract(0, 1, 0))) && skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) { event.setCancelled(true); return; @@ -451,7 +451,7 @@ public class Entity implements Listener { return; // Check entities interacting with spawn - if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation) && + if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world) && skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) { event.setCancelled(true); return; diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/world/LocationUtil.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/world/LocationUtil.java index 12c77231..bd9671f3 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/world/LocationUtil.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/world/LocationUtil.java @@ -4,7 +4,9 @@ import me.goodandevil.skyblock.SkyBlock; import me.goodandevil.skyblock.config.FileManager; import me.goodandevil.skyblock.config.FileManager.Config; import me.goodandevil.skyblock.island.Island; +import me.goodandevil.skyblock.island.IslandEnvironment; import me.goodandevil.skyblock.island.IslandManager; +import me.goodandevil.skyblock.island.IslandWorld; import me.goodandevil.skyblock.utils.math.VectorUtil; import me.goodandevil.skyblock.utils.version.Materials; import me.goodandevil.skyblock.utils.world.block.BlockDegreesType; @@ -32,7 +34,12 @@ public final class LocationUtil { return false; } - public static boolean isLocationAffectingLocation(Location location1, Location location2) { + public static boolean isLocationAffectingIslandSpawn(Location location, Island island, IslandWorld world) { + return isLocationAffectingLocation(location, island.getLocation(world, IslandEnvironment.Main)) + || isLocationAffectingLocation(location, island.getLocation(world, IslandEnvironment.Visitor)); + } + + private static boolean isLocationAffectingLocation(Location location1, Location location2) { Location headHeight = location2.clone().add(0, 1, 0); Location feetHeight = location2.clone(); Location groundHeight = location2.clone().add(0, -1, 0); From 55c5dcbd054443063b03d5b37c24e8a59eb66c42 Mon Sep 17 00:00:00 2001 From: Esophose Date: Thu, 15 Aug 2019 00:36:17 -0600 Subject: [PATCH 10/11] Better material checking in 1.12- --- .../skyblock/utils/version/Materials.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java index abb4b230..488fce3f 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java @@ -1131,24 +1131,37 @@ public enum Materials { Materials pmat = null; + // Try 1.13+ names for (Materials mat : Materials.values()) { - if (name.equalsIgnoreCase(mat.old12Mat)) { + if (name.equalsIgnoreCase(mat.name())) { if (pmat == null) { pmat = mat; } if (((byte) mat.data) == data) { - cachedSearch.put(mat.old12Mat + "," + data, mat); + cachedSearch.put(mat.name() + "," + data, mat); return mat; } } } - if (pmat != null) { - return pmat; + // Try 1.12- names + for (Materials mat : Materials.values()) { + if (name.equalsIgnoreCase(mat.name())) + + if (name.equalsIgnoreCase(mat.old12Mat)) { + if (pmat == null) { + pmat = mat; + } + + if (((byte) mat.data) == data) { + cachedSearch.put(mat.old12Mat + "," + data, mat); + return mat; + } + } } - return null; + return pmat; } public boolean isSpawner() { @@ -1233,7 +1246,7 @@ public enum Materials { case "CHESTPLATE": return true; default: - return false; + return false; } } From aae24ab1a04aeac94641c021099792959d5236f7 Mon Sep 17 00:00:00 2001 From: Esophose Date: Thu, 15 Aug 2019 00:36:26 -0600 Subject: [PATCH 11/11] Spawn egg permission check for 1.12- --- .../main/java/me/goodandevil/skyblock/listeners/Interact.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Interact.java b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Interact.java index eb6419ac..dda91f15 100644 --- a/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Interact.java +++ b/FabledSkyBlock/Core/src/main/java/me/goodandevil/skyblock/listeners/Interact.java @@ -587,7 +587,7 @@ public class Interact implements Listener { player.updateInventory(); } } - } else if (event.getItem().getType().name().contains("SPAWN_EGG")) { + } else if (event.getItem().getType().name().contains("SPAWN_EGG") || event.getItem().getType().name().equals("MONSTER_EGG")) { if (!islandManager.hasPermission(player, block.getLocation(), "SpawnEgg")) { event.setCancelled(true);