mirror of
https://github.com/md5sha256/AreaShop.git
synced 2026-11-06 17:32:43 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f04efb3e8 | ||
|
|
5872af7466 | ||
|
|
a8315e627b | ||
|
|
35361308a8 | ||
|
|
0c359cdfdf | ||
|
|
2a03e7612a | ||
|
|
aaf4e07053 | ||
|
|
fa91016613 | ||
|
|
f4bd4ee6c6 | ||
|
|
44fd7deea5 |
No files matched your search
+27
-33
@@ -1,38 +1,32 @@
|
||||
name : "build"
|
||||
# This workflow will build a Java project with Maven
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
on : [ "pull_request", "push" ]
|
||||
name: Java CI with Maven
|
||||
|
||||
jobs :
|
||||
build :
|
||||
strategy :
|
||||
matrix :
|
||||
java : [ 16 ]
|
||||
# java: ["1.8", "11"]
|
||||
os : [ "ubuntu-18.04" ]
|
||||
runs-on : "${{ matrix.os }}"
|
||||
steps :
|
||||
- name : "Checkout Repository"
|
||||
uses : "actions/checkout@v2.3.4"
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
- name : "Checkout submodules"
|
||||
uses : "srt32/git-actions@v0.0.3"
|
||||
with :
|
||||
args : "git submodule update --init --recursive"
|
||||
jobs:
|
||||
build:
|
||||
|
||||
- name : "Restore Gradle cache"
|
||||
uses : "actions/cache@v2"
|
||||
with :
|
||||
path : "~/.gradle/caches"
|
||||
key : "${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}"
|
||||
restore-keys : |
|
||||
${{ runner.os }}-gradle-
|
||||
- name : "Setup JDK ${{ matrix.java }}"
|
||||
uses : "actions/setup-java@v1.4.3"
|
||||
with :
|
||||
java-version : "${{ matrix.java }}"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
- name : "Grant execute permission for gradlew"
|
||||
run : "chmod +x gradlew"
|
||||
|
||||
- name : "Build with Gradle"
|
||||
run : "./gradlew clean build"
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Cache local Maven repository
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
|
||||
+3
-22
@@ -1,4 +1,4 @@
|
||||
### Maven ###
|
||||
# Maven stuff
|
||||
target
|
||||
|
||||
.project
|
||||
@@ -14,31 +14,12 @@ local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
### Locally stored "Eclipse launch configurations" ###
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
# IntelliJ IDEA
|
||||
*.iml
|
||||
.idea
|
||||
dependency-reduced-pom.xml
|
||||
|
||||
desktop.ini
|
||||
|
||||
### Gradle ###
|
||||
.gradle
|
||||
build/
|
||||
|
||||
# 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/
|
||||
@@ -1,60 +0,0 @@
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'com.github.johnrengelman.shadow' version '7.0.0'
|
||||
}
|
||||
|
||||
description = 'AreaShop'
|
||||
version = '2.6.3'
|
||||
|
||||
dependencies {
|
||||
// Spigot api
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
|
||||
// Libs
|
||||
implementation 'com.github.NLthijs48:InteractiveMessenger:e7749258ca'
|
||||
implementation 'co.aikar:taskchain-bukkit:3.7.2'
|
||||
implementation 'io.papermc:paperlib:1.0.6'
|
||||
|
||||
// Hooks
|
||||
implementation project(':areashop-interface')
|
||||
implementation project(':areashop-worldguard-7')
|
||||
implementation project(':areashop-worldedit-7')
|
||||
implementation project(':areashop-fawe-1-16')
|
||||
implementation project(':areashop-fawe-1-17')
|
||||
implementation project(':areashop-nms-1-16-5')
|
||||
implementation project(':areashop-nms-1-17')
|
||||
|
||||
// Runtime plugins
|
||||
compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.2.5'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.5'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
from (sourceSets.main.resources) {
|
||||
filter ReplaceTokens, tokens: [version: project.version]
|
||||
duplicatesStrategy(DuplicatesStrategy.INCLUDE)
|
||||
}
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveBaseName.set('AreaShop')
|
||||
classifier('original')
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveBaseName.set('AreaShop')
|
||||
String relocationBase = 'me.wiefferink.areashop.shaded'
|
||||
classifier('')
|
||||
relocate('co.aikar.taskchain', "${relocationBase}.taskchain")
|
||||
relocate('me.wiefferink.interactivemessenger', "${relocationBase}.interactivemessenger")
|
||||
relocate('org.bstats', "${relocationBase}.bstats")
|
||||
relocate('io.papermc', "${relocationBase}.papermc")
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>areashop</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop</name>
|
||||
<version>2.7</version> <!-- Main plugin version -->
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>aikar</id>
|
||||
<url>https://repo.aikar.co/content/groups/aikar/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- Bukkit, AreaShop aims to support 1.16.5+ -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- InteractiveMessenger library -->
|
||||
<dependency>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>interactivemessenger</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- TaskChain library -->
|
||||
<dependency>
|
||||
<groupId>co.aikar</groupId>
|
||||
<artifactId>taskchain-bukkit</artifactId>
|
||||
<version>3.7.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- WorldEdit/WorldGuard -->
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.1.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Interfaces that specific WorldGuard and WorldEdit versions are built against -->
|
||||
<dependency>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<version>latest</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- WorldGuard implementations -->
|
||||
<dependency>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-worldguard-7</artifactId>
|
||||
<version>latest</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- WorldEdit implementations -->
|
||||
<dependency>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-worldedit-7</artifactId>
|
||||
<version>latest</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- FAWE compat -->
|
||||
<dependency>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-fawe-1-15</artifactId>
|
||||
<version>latest</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Vault -->
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- bStats -->
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<!-- Copy the jar file to a test server, activate by using -DcopyResult="/path/to/test/server" -->
|
||||
<profile>
|
||||
<id>test-locally</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>copyResult</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.8</version>
|
||||
<configuration>
|
||||
<target>
|
||||
<copy file="./target/${project.build.finalName}.jar"
|
||||
tofile="${copyResult}\${project.build.finalName}.jar"/>
|
||||
</target>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<!-- Package the source files in a jar, activate by using -Dsources -->
|
||||
<profile>
|
||||
<id>package-sources</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>sources</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<!-- Produce javadoc files, activate by using -Djavadoc -->
|
||||
<profile>
|
||||
<id>generate-javadoc</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>javadoc</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<excludePackageNames>me.wiefferink.areashop.lib</excludePackageNames>
|
||||
<destDir>${javadoc}</destDir>
|
||||
<links>
|
||||
<link>https://hub.spigotmc.org/javadocs/bukkit/</link>
|
||||
<link>http://docs.sk89q.com/worldedit/apidocs/</link>
|
||||
<link>http://docs.sk89q.com/worldguard/apidocs/</link>
|
||||
</links>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<directory>target</directory>
|
||||
<finalName>AreaShop</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
<include>config.yml</include>
|
||||
<include>hiddenConfig.yml</include>
|
||||
<include>default.yml</include>
|
||||
<include>README.md</include>
|
||||
<include>lang/*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<!-- Relocate TaskChain -->
|
||||
<relocation>
|
||||
<pattern>co.aikar.taskchain</pattern>
|
||||
<shadedPattern>me.wiefferink.areashop.shaded.taskchain</shadedPattern>
|
||||
</relocation>
|
||||
<!-- Relocate messaging framework -->
|
||||
<relocation>
|
||||
<pattern>me.wiefferink.interactivemessenger</pattern>
|
||||
<shadedPattern>me.wiefferink.areashop.shaded.interactivemessenger</shadedPattern>
|
||||
</relocation>
|
||||
<!-- Relocate bstats -->
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>me.wiefferink.areashop.shaded.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>io.papermc</pattern>
|
||||
<shadedPattern>me.wiefferink.areashop.shaded.paperlib</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -5,11 +5,11 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import me.wiefferink.areashop.interfaces.AreaShopInterface;
|
||||
import me.wiefferink.areashop.interfaces.NMS;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.listeners.PlayerLoginLogoutListener;
|
||||
import me.wiefferink.areashop.managers.*;
|
||||
import me.wiefferink.areashop.tools.Analytics;
|
||||
import me.wiefferink.areashop.tools.GithubUpdateCheck;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
@@ -29,9 +29,11 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -49,6 +51,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
public static final String groupsFile = "groups.yml";
|
||||
public static final String defaultFile = "default.yml";
|
||||
public static final String configFile = "config.yml";
|
||||
public static final String signLogFile = "signErrors.yml";
|
||||
public static final String configFileHidden = "hiddenConfig.yml";
|
||||
public static final String versionFile = "versions";
|
||||
// Euro tag for in the config
|
||||
@@ -129,7 +132,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
private List<String> chatprefix = null;
|
||||
private boolean ready = false;
|
||||
private GithubUpdateCheck githubUpdateCheck = null;
|
||||
private NMS nms;
|
||||
private SignErrorLogger signErrorLogger;
|
||||
|
||||
public static AreaShop getInstance() {
|
||||
@@ -266,14 +268,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
this.chatprefix = chatprefix;
|
||||
}
|
||||
|
||||
public NMS getNMSHelper() {
|
||||
return this.nms;
|
||||
}
|
||||
|
||||
public SignErrorLogger getSignErrorLogger() {
|
||||
return this.signErrorLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get WorldGuardInterface for version dependent things.
|
||||
*
|
||||
@@ -429,6 +423,12 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
* Register all required tasks.
|
||||
*/
|
||||
private void setupTasks() {
|
||||
long signLogTicks = Utils.millisToTicks(TimeUnit.MINUTES.toMillis(5));
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this,
|
||||
() -> signErrorLogger.saveIfDirty(),
|
||||
signLogTicks,
|
||||
signLogTicks
|
||||
);
|
||||
// Rent expiration timer
|
||||
long expirationCheck =
|
||||
Utils.millisToTicks(Utils.getDurationFromSecondsOrString("expiration.delay"));
|
||||
@@ -573,22 +573,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
private void setupNMS() throws IllegalStateException {
|
||||
final String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
final String[] split = packageName.split("\\.");
|
||||
final String nmsRevision = split[3];
|
||||
try {
|
||||
Class<?> rawClazz = Class.forName("me.wiefferink.areashop.nms." + nmsRevision + ".NMSImpl");
|
||||
if (!NMS.class.isAssignableFrom(rawClazz)) {
|
||||
throw new IllegalStateException("Invalid NMS Impl: " + rawClazz.getCanonicalName() + " does not implement the NMS!");
|
||||
}
|
||||
Class<? extends NMS> casted = rawClazz.asSubclass(NMS.class);
|
||||
this.nms = casted.getConstructor().newInstance();
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new IllegalStateException("Failed to instantiate the NMS Helper!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on start or reload of the server.
|
||||
*/
|
||||
@@ -604,10 +588,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
error("Vault plugin is not present or has not loaded correctly");
|
||||
error = true;
|
||||
}
|
||||
|
||||
// Setup the NMS helper
|
||||
setupNMS();
|
||||
|
||||
signErrorLogger = new SignErrorLogger(new File(signLogFile));
|
||||
// Load all data from files and check versions
|
||||
fileManager = new FileManager();
|
||||
managers.add(fileManager);
|
||||
@@ -636,6 +617,11 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
signLinkerManager = new SignLinkerManager();
|
||||
managers.add(signLinkerManager);
|
||||
|
||||
// Enable Metrics if config allows it
|
||||
if (getConfig().getBoolean("sendStats")) {
|
||||
Analytics.start();
|
||||
}
|
||||
|
||||
// Register dynamic permission (things declared in config)
|
||||
registerDynamicPermissions();
|
||||
|
||||
@@ -708,20 +694,10 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
final Plugin fawe = getServer().getPluginManager().getPlugin("FastAsyncWorldEdit");
|
||||
if (fawe != null && fawe.isEnabled()) {
|
||||
final String version = fawe.getDescription().getVersion();
|
||||
if (version.startsWith("1.16")) {
|
||||
if (version.startsWith("1.15") || version.startsWith("1.16")) {
|
||||
try {
|
||||
this.worldEditInterface = (WorldEditInterface) Class.forName(packageName + "fawe.v1_16.FastAsyncWorldEditHandler")
|
||||
.getDeclaredConstructor(AreaShopInterface.class)
|
||||
.newInstance(this);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
getLogger().log(Level.SEVERE, "Failed to hook into FAWE!");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else if (version.startsWith("1.17")) {
|
||||
try {
|
||||
this.worldEditInterface = (WorldEditInterface) Class.forName(packageName + "fawe.v1_17.FastAsyncWorldEditHandler")
|
||||
.getDeclaredConstructor(AreaShopInterface.class)
|
||||
.newInstance(this);
|
||||
this.worldEditInterface = (WorldEditInterface) Class.forName(packageName + "fawe.v1_15.FastAsyncWorldEditHandler")
|
||||
.getDeclaredConstructor(AreaShopInterface.class).newInstance(this);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
getLogger().log(Level.SEVERE, "Failed to hook into FAWE!");
|
||||
ex.printStackTrace();
|
||||
@@ -806,6 +782,10 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
return worldEdit;
|
||||
}
|
||||
|
||||
public SignErrorLogger getSignErrorLogger() {
|
||||
return signErrorLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload all files of the plugin and update all regions.
|
||||
*
|
||||
@@ -829,3 +809,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ public class AddCommand extends CommandAreaShop {
|
||||
TreeSet<String> namesNoPermission = new TreeSet<>();
|
||||
TreeSet<String> namesAddCancelled = new TreeSet<>(); // Denied by an event listener
|
||||
Utils.runAsBatches(regions.entrySet(),
|
||||
Math.min(plugin.getConfig().getInt("adding.regionsPerTick"), 1),
|
||||
plugin.getConfig().getInt("adding.regionsPerTick"),
|
||||
(regionEntry) -> {
|
||||
String regionName = regionEntry.getKey();
|
||||
ProtectedRegion region = regionEntry.getValue();
|
||||
|
||||
@@ -28,11 +28,12 @@ public abstract class CommandAreaShop {
|
||||
* @return true if it can execute the command, false otherwise
|
||||
*/
|
||||
public boolean canExecute(Command command, String[] args) {
|
||||
String commandString = command.getName() + " " + StringUtils.join(args, " ");
|
||||
if(commandString.length() > getCommandStart().length()) {
|
||||
return commandString.toLowerCase().startsWith(getCommandStart().toLowerCase() + " ");
|
||||
String commandString = command.getName() + " " + StringUtils.join(args, " ").toLowerCase();
|
||||
final String start = getCommandStart().toLowerCase();
|
||||
if(commandString.length() > start.length()) {
|
||||
return commandString.startsWith(start + " ");
|
||||
}
|
||||
return commandString.toLowerCase().startsWith(getCommandStart().toLowerCase());
|
||||
return commandString.startsWith(start);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.bukkit.entity.Player;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class DelCommand extends CommandAreaShop {
|
||||
|
||||
@@ -52,7 +51,7 @@ public class DelCommand extends CommandAreaShop {
|
||||
return;
|
||||
}
|
||||
List<GeneralRegion> regions = Utils.getRegionsInSelection(selection);
|
||||
if(regions.isEmpty()) {
|
||||
if(regions == null || regions.isEmpty()) {
|
||||
plugin.message(player, "cmd-noRegionsFound");
|
||||
return;
|
||||
}
|
||||
@@ -93,41 +92,37 @@ public class DelCommand extends CommandAreaShop {
|
||||
plugin.message(sender, "del-cancelled", Utils.combinedMessage(regionsCancelled, "region"));
|
||||
}
|
||||
} else {
|
||||
CompletableFuture<GeneralRegion> future = plugin.getFileManager().getRegionUnsafe(args[1]);
|
||||
Utils.newChain()
|
||||
.future(future)
|
||||
.syncLast(region -> {
|
||||
if(region == null) {
|
||||
plugin.message(sender, "cmd-notRegistered", args[1]);
|
||||
return;
|
||||
}
|
||||
boolean isLandlord = sender instanceof Player && region.isLandlord(((Player)sender).getUniqueId());
|
||||
if(region instanceof RentRegion) {
|
||||
// Remove the rent if the player has permission
|
||||
if(sender.hasPermission("areashop.destroyrent") || (isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
|
||||
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
plugin.message(sender, "general-cancelled", event.getReason());
|
||||
} else {
|
||||
plugin.message(sender, "destroy-successRent", region);
|
||||
}
|
||||
} else {
|
||||
plugin.message(sender, "destroy-noPermissionRent", region);
|
||||
}
|
||||
} else if(region instanceof BuyRegion) {
|
||||
// Remove the buy if the player has permission
|
||||
if(sender.hasPermission("areashop.destroybuy") || (isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
|
||||
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
plugin.message(sender, "general-cancelled", event.getReason());
|
||||
} else {
|
||||
plugin.message(sender, "destroy-successBuy", region);
|
||||
}
|
||||
} else {
|
||||
plugin.message(sender, "destroy-noPermissionBuy", region);
|
||||
}
|
||||
}
|
||||
}).execute();
|
||||
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
|
||||
if(region == null) {
|
||||
plugin.message(sender, "cmd-notRegistered", args[1]);
|
||||
return;
|
||||
}
|
||||
boolean isLandlord = sender instanceof Player && region.isLandlord(((Player)sender).getUniqueId());
|
||||
if(region instanceof RentRegion) {
|
||||
// Remove the rent if the player has permission
|
||||
if(sender.hasPermission("areashop.destroyrent") || (isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
|
||||
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
plugin.message(sender, "general-cancelled", event.getReason());
|
||||
} else {
|
||||
plugin.message(sender, "destroy-successRent", region);
|
||||
}
|
||||
} else {
|
||||
plugin.message(sender, "destroy-noPermissionRent", region);
|
||||
}
|
||||
} else if(region instanceof BuyRegion) {
|
||||
// Remove the buy if the player has permission
|
||||
if(sender.hasPermission("areashop.destroybuy") || (isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
|
||||
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
plugin.message(sender, "general-cancelled", event.getReason());
|
||||
} else {
|
||||
plugin.message(sender, "destroy-successBuy", region);
|
||||
}
|
||||
} else {
|
||||
plugin.message(sender, "destroy-noPermissionBuy", region);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,78 +5,79 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TeleportCommand extends CommandAreaShop {
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop tp";
|
||||
}
|
||||
/**
|
||||
* Check if a person can teleport to the region (assuming he is not teleporting to a sign).
|
||||
*
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can teleport to it, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if (!(person instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) person;
|
||||
return player.hasPermission("areashop.teleportall")
|
||||
|| region.isOwner(player) && player.hasPermission("areashop.teleport")
|
||||
|| region.isAvailable() && player.hasPermission("areashop.teleportavailable")
|
||||
|| region.getFriendsFeature().getFriends().contains(player.getUniqueId()) && player.hasPermission("areashop.teleportfriend");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.teleportall") || target.hasPermission("areashop.teleport")) {
|
||||
return "help-teleport";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop tp";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a person can teleport to the region (assuming he is not teleporting to a sign).
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can teleport to it, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if(!(person instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player)person;
|
||||
return player.hasPermission("areashop.teleportall")
|
||||
|| region.isOwner(player) && player.hasPermission("areashop.teleport")
|
||||
|| region.isAvailable() && player.hasPermission("areashop.teleportavailable")
|
||||
|| region.getFriendsFeature().getFriends().contains(player.getUniqueId()) && player.hasPermission("areashop.teleportfriend");
|
||||
}
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if (target.hasPermission("areashop.teleportall") || target.hasPermission("areashop.teleport")) {
|
||||
return "help-teleport";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.teleport") && !sender.hasPermission("areashop.teleportall") && !sender.hasPermission("areashop.teleportavailable") && !sender.hasPermission("areashop.teleportavailablesign") && !sender.hasPermission("areashop.teleportsign") && !sender.hasPermission("areashop.teleportsignall") && !sender.hasPermission("areashop.teleportfriend") && !sender.hasPermission("teleportfriendsign")) {
|
||||
plugin.message(sender, "teleport-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
plugin.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
if(args.length <= 1 || args[1] == null) {
|
||||
plugin.message(sender, "teleport-help");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
|
||||
if(region == null) {
|
||||
plugin.message(player, "teleport-noRentOrBuy", args[1]);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("areashop.teleport") && !sender.hasPermission("areashop.teleportall") && !sender.hasPermission("areashop.teleportavailable") && !sender.hasPermission("areashop.teleportavailablesign") && !sender.hasPermission("areashop.teleportsign") && !sender.hasPermission("areashop.teleportsignall") && !sender.hasPermission("areashop.teleportfriend") && !sender.hasPermission("teleportfriendsign")) {
|
||||
plugin.message(sender, "teleport-noPermission");
|
||||
return;
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
plugin.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
if (args.length <= 1 || args[1] == null) {
|
||||
plugin.message(sender, "teleport-help");
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
|
||||
if (region == null) {
|
||||
plugin.message(player, "teleport-noRentOrBuy", args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean toSign = args.length >= 3 && (
|
||||
args[2].equalsIgnoreCase("sign")
|
||||
|| args[2].equalsIgnoreCase("yes")
|
||||
|| args[2].equalsIgnoreCase("true")
|
||||
);
|
||||
region.getTeleportFeature().teleportPlayer(player, toSign, true);
|
||||
}
|
||||
boolean toSign = args.length >= 3 && (
|
||||
args[2].equalsIgnoreCase("sign")
|
||||
|| args[2].equalsIgnoreCase("yes")
|
||||
|| args[2].equalsIgnoreCase("true")
|
||||
);
|
||||
region.getTeleportFeature().teleportPlayer(player, toSign, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result.addAll(plugin.getFileManager().getRegionNames());
|
||||
} else if(toComplete == 3) {
|
||||
result.add("sign");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
if (toComplete == 2) {
|
||||
return plugin.getFileManager().getRegionNames();
|
||||
} else if (toComplete == 3) {
|
||||
return Collections.singletonList("sign");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class FriendsFeature extends RegionFeature {
|
||||
HashSet<String> result = new HashSet<>();
|
||||
for(UUID friend : getFriends()) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(friend);
|
||||
if(player.hasPlayedBefore() && player.getName() != null) {
|
||||
if(player != null && player.getName() != null) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,625 +0,0 @@
|
||||
package me.wiefferink.areashop.features;
|
||||
|
||||
import co.aikar.taskchain.TaskChain;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.areashop.tools.Value;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TeleportFeature extends RegionFeature {
|
||||
|
||||
public TeleportFeature() {
|
||||
}
|
||||
|
||||
public TeleportFeature(GeneralRegion region) {
|
||||
setRegion(region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a certain location is safe to teleport to.
|
||||
*
|
||||
* @param location The location to check
|
||||
* @return true if it is safe, otherwise false
|
||||
*/
|
||||
private static boolean isSafe(Location location) {
|
||||
Block feet = location.getBlock();
|
||||
BlockState head = PaperLib.getBlockState(feet.getRelative(BlockFace.UP), false).getState();
|
||||
BlockState below = PaperLib.getBlockState(feet.getRelative(BlockFace.DOWN), false).getState();
|
||||
BlockState above = PaperLib.getBlockState(head.getBlock().getRelative(BlockFace.UP), false).getState();
|
||||
|
||||
// Check the block at the feet and head of the player
|
||||
if ((feet.getType().isSolid() && !canSpawnIn(feet.getType())) || feet.isLiquid()) {
|
||||
return false;
|
||||
} else if ((head.getType().isSolid() && !canSpawnIn(head.getType())) || head.getBlock().isLiquid()) {
|
||||
return false;
|
||||
} else if (!below.getType().isSolid() || cannotSpawnOn(below.getType()) || below.getBlock().isLiquid()) {
|
||||
return false;
|
||||
} else if (above.getBlock().isLiquid() || cannotSpawnBeside(above.getType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get all blocks around the player (below foot level, foot level, head level and above head level)
|
||||
Set<Material> around = new HashSet<>();
|
||||
for (int y = 0; y <= 3; y++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
// Skip blocks in the column of the player
|
||||
if (x == 0 && z == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
around.add(PaperLib.getBlockState(below.getBlock().getRelative(x, y, z), false).getState().getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check the blocks around the player
|
||||
for (Material material : around) {
|
||||
if (cannotSpawnBeside(material)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player can spawn in here.
|
||||
*
|
||||
* @param material Material to check (assumed that this is at the feet or head level)
|
||||
* @return true when it is safe to spawn inside, otherwise false
|
||||
*/
|
||||
private static boolean canSpawnIn(Material material) {
|
||||
String name = material.name();
|
||||
return name.contains("DOOR")
|
||||
|| name.contains("SIGN")
|
||||
|| name.contains("PLATE") // Redstone plates
|
||||
|| name.equals("DRAGON_EGG");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player can spawn on here.
|
||||
*
|
||||
* @param material Material to check (assumed that this is below the feet)
|
||||
* @return true when it is safe to spawn on top of, otherwise false
|
||||
*/
|
||||
private static boolean cannotSpawnOn(Material material) {
|
||||
return switch (material) {
|
||||
case CACTUS, DRAGON_EGG, MAGMA_BLOCK -> false;
|
||||
default -> !Tag.SIGNS.isTagged(material)
|
||||
&& !Tag.FENCES.isTagged(material)
|
||||
&& !Tag.FENCE_GATES.isTagged(material)
|
||||
&& !Tag.WALL_SIGNS.isTagged(material)
|
||||
&& !Tag.DOORS.isTagged(material);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player can spawn next to it.
|
||||
*
|
||||
* @param material Material to check (assumed that this is somewhere around the player)
|
||||
* @return true when it is safe to spawn next to, otherwise false
|
||||
*/
|
||||
private static boolean cannotSpawnBeside(Material material) {
|
||||
return switch (material) {
|
||||
case LAVA, CACTUS, FIRE, MAGMA_BLOCK -> false;
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the teleportlocation set for this region.
|
||||
*
|
||||
* @return The teleport location, or null if not set
|
||||
*/
|
||||
public Location getTeleportLocation() {
|
||||
return Utils.configToLocation(getRegion().getConfigurationSectionSetting("general.teleportLocation"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the region has a teleportLocation specified.
|
||||
*
|
||||
* @return true if the region has a teleportlocation, false otherwise
|
||||
*/
|
||||
public boolean hasTeleportLocation() {
|
||||
return getRegion().getConfigurationSectionSetting("general.teleportLocation") != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the teleport location of this region.
|
||||
*
|
||||
* @param location The location to set as teleport location
|
||||
*/
|
||||
public void setTeleport(Location location) {
|
||||
if (location == null) {
|
||||
getRegion().setSetting("general.teleportLocation", null);
|
||||
} else {
|
||||
getRegion().setSetting("general.teleportLocation", Utils.locationToConfig(location, true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to the region or sign.
|
||||
*
|
||||
* @param player Player that should be teleported
|
||||
* @param toSign true to teleport to the first sign of the region, false for teleporting to the region itself
|
||||
* @param checkRestrictions Set to true if teleport permissions should be checked, false otherwise, also toggles cross-world check
|
||||
* @return true if the teleport succeeded, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> teleportPlayer(Player player, boolean toSign, boolean checkRestrictions) {
|
||||
|
||||
// Check basics
|
||||
if (getRegion().getWorld() == null) {
|
||||
getRegion().message(player, "general-noWorld");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
if (getRegion().getRegion() == null) {
|
||||
getRegion().message(player, "general-noRegion");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
if (checkRestrictions) {
|
||||
// Check correct world
|
||||
if (!getRegion().getBooleanSetting("general.teleportCrossWorld") && !player.getWorld().equals(getRegion().getWorld())) {
|
||||
getRegion().message(player, "teleport-wrongWorld", player.getWorld().getName());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
boolean owner = player.getUniqueId().equals(getRegion().getOwner());
|
||||
boolean friend = getRegion().getFriendsFeature().getFriends().contains(player.getUniqueId());
|
||||
boolean available = getRegion().isAvailable();
|
||||
// Teleport to sign instead if they dont have permission for teleporting to region
|
||||
if ((!toSign && owner && !player.hasPermission("areashop.teleport") && player.hasPermission("areashop.teleportsign")
|
||||
|| !toSign && !owner && !friend && !player.hasPermission("areashop.teleportall") && player.hasPermission("areashop.teleportsignall")
|
||||
|| !toSign && !owner && friend && !player.hasPermission("areashop.teleportfriend") && player.hasPermission("areashop.teleportfriendsign")
|
||||
|| !toSign && !owner && !friend && available && !player.hasPermission("areashop.teleportavailable") && player.hasPermission("areashop.teleportavailablesign"))) {
|
||||
getRegion().message(player, "teleport-changedToSign");
|
||||
toSign = true;
|
||||
}
|
||||
// Check permissions
|
||||
if (owner && !available && !player.hasPermission("areashop.teleport") && !toSign) {
|
||||
getRegion().message(player, "teleport-noPermission");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (!owner && !available && !player.hasPermission("areashop.teleportall") && !toSign && !friend) {
|
||||
getRegion().message(player, "teleport-noPermissionOther");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (!owner && !available && !player.hasPermission("areashop.teleportfriend") && !toSign && friend) {
|
||||
getRegion().message(player, "teleport-noPermissionFriend");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (available && !player.hasPermission("areashop.teleportavailable") && !toSign) {
|
||||
getRegion().message(player, "teleport-noPermissionAvailable");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (owner && !available && !player.hasPermission("areashop.teleportsign") && toSign) {
|
||||
getRegion().message(player, "teleport-noPermissionSign");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (!owner && !available && !player.hasPermission("areashop.teleportsignall") && toSign && !friend) {
|
||||
getRegion().message(player, "teleport-noPermissionOtherSign");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (!owner && !available && !player.hasPermission("areashop.teleportfriendsign") && toSign && friend) {
|
||||
getRegion().message(player, "teleport-noPermissionFriendSign");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (available && !player.hasPermission("areashop.teleportavailablesign") && toSign) {
|
||||
getRegion().message(player, "teleport-noPermissionAvailableSign");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the starting location
|
||||
Value<Boolean> toSignRef = new Value<>(toSign);
|
||||
Location startLocation = getStartLocation(player, toSignRef);
|
||||
toSign = toSignRef.get();
|
||||
|
||||
boolean insideRegion;
|
||||
if (toSign) {
|
||||
insideRegion = getRegion().getBooleanSetting("general.teleportToSignIntoRegion");
|
||||
} else {
|
||||
insideRegion = getRegion().getBooleanSetting("general.teleportIntoRegion");
|
||||
}
|
||||
|
||||
// Check locations starting from startLocation and then a cube that increases
|
||||
// radius around that (until no block in the region is found at all cube sides)
|
||||
ProtectedRegion worldguardRegion = getRegion().getRegion();
|
||||
boolean blocksInRegion = worldguardRegion.contains(startLocation.getBlockX(), startLocation.getBlockY(), startLocation.getBlockZ());
|
||||
if (!blocksInRegion && insideRegion) {
|
||||
getRegion().message(player, "teleport-blocked");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
// Tracking of which sides to continue the search
|
||||
final World world = getRegion().getWorld();
|
||||
BlockVector3 min = worldguardRegion.getMinimumPoint();
|
||||
BlockVector3 max = worldguardRegion.getMaximumPoint();
|
||||
|
||||
final Collection<int[]> collection = new HashSet<>();
|
||||
for (int x = min.getX(); x < max.getX(); x += 16) {
|
||||
for (int z = min.getZ(); z < max.getZ(); z += 16) {
|
||||
collection.add(new int[]{x, z});
|
||||
}
|
||||
}
|
||||
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
final boolean finalToSign = toSign;
|
||||
TaskChain<?> chain = Utils.newChain();
|
||||
if (collection.size() < 64) {
|
||||
chain = chain.future(Utils.runAsBatches(collection, 16, (arr) -> PaperLib.getChunkAtAsync(world, arr[0], arr[1]), false));
|
||||
}
|
||||
chain.delay(3).syncLast((unused) -> {
|
||||
boolean blocksInRegionCopy = blocksInRegion;
|
||||
Location safeLocation = startLocation;
|
||||
// Tries limit tracking
|
||||
int radius = 1;
|
||||
int checked = 1;
|
||||
int maxTries = plugin.getConfig().getInt("maximumTries");
|
||||
|
||||
// Tracking of which sides to continue the search
|
||||
boolean done = isSafe(safeLocation);
|
||||
boolean northDone = false, eastDone = false, southDone = false, westDone = false, topDone = false, bottomDone = false;
|
||||
boolean continueThisDirection;
|
||||
|
||||
while ((blocksInRegionCopy || !insideRegion) && !done) {
|
||||
blocksInRegionCopy = false;
|
||||
|
||||
// North side
|
||||
continueThisDirection = false;
|
||||
for (int x = -radius + 1; x <= radius && !done && !northDone; x++) {
|
||||
for (int y = -radius + 1; y < radius && !done; y++) {
|
||||
safeLocation = startLocation.clone().add(x, y, -radius);
|
||||
if (safeLocation.getBlockY() > 256 || safeLocation.getBlockY() < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
northDone = northDone || !continueThisDirection;
|
||||
|
||||
// East side
|
||||
continueThisDirection = false;
|
||||
for (int z = -radius + 1; z <= radius && !done && !eastDone; z++) {
|
||||
for (int y = -radius + 1; y < radius && !done; y++) {
|
||||
safeLocation = startLocation.clone().add(radius, y, z);
|
||||
if (safeLocation.getBlockY() > 256 || safeLocation.getBlockY() < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
eastDone = eastDone || !continueThisDirection;
|
||||
|
||||
// South side
|
||||
continueThisDirection = false;
|
||||
for (int x = radius - 1; x >= -radius && !done && !southDone; x--) {
|
||||
for (int y = -radius + 1; y < radius && !done; y++) {
|
||||
safeLocation = startLocation.clone().add(x, y, radius);
|
||||
if (safeLocation.getBlockY() > 256 || safeLocation.getBlockY() < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
southDone = southDone || !continueThisDirection;
|
||||
|
||||
// West side
|
||||
continueThisDirection = false;
|
||||
for (int z = radius - 1; z >= -radius && !done && !westDone; z--) {
|
||||
for (int y = -radius + 1; y < radius && !done; y++) {
|
||||
safeLocation = startLocation.clone().add(-radius, y, z);
|
||||
if (safeLocation.getBlockY() > 256 || safeLocation.getBlockY() < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
westDone = westDone || !continueThisDirection;
|
||||
|
||||
// Top side
|
||||
continueThisDirection = false;
|
||||
// Middle block of the top
|
||||
if ((startLocation.getBlockY() + radius) > 256) {
|
||||
topDone = true;
|
||||
}
|
||||
if (!done && !topDone) {
|
||||
safeLocation = startLocation.clone().add(0, radius, 0);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
for (int r = 1; r <= radius && !done && !topDone; r++) {
|
||||
// North
|
||||
for (int x = -r + 1; x <= r && !done; x++) {
|
||||
safeLocation = startLocation.clone().add(x, radius, -r);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
// East
|
||||
for (int z = -r + 1; z <= r && !done; z++) {
|
||||
safeLocation = startLocation.clone().add(r, radius, z);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
// South side
|
||||
for (int x = r - 1; x >= -r && !done; x--) {
|
||||
safeLocation = startLocation.clone().add(x, radius, r);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
// West side
|
||||
for (int z = r - 1; z >= -r && !done; z--) {
|
||||
safeLocation = startLocation.clone().add(-r, radius, z);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
topDone = topDone || !continueThisDirection;
|
||||
|
||||
// Bottom side
|
||||
continueThisDirection = false;
|
||||
// Middle block of the bottom
|
||||
if (startLocation.getBlockY() - radius < 0) {
|
||||
bottomDone = true;
|
||||
}
|
||||
if (!done && !bottomDone) {
|
||||
safeLocation = startLocation.clone().add(0, -radius, 0);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
for (int r = 1; r <= radius && !done && !bottomDone; r++) {
|
||||
// North
|
||||
for (int x = -r + 1; x <= r && !done; x++) {
|
||||
safeLocation = startLocation.clone().add(x, -radius, -r);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
// East
|
||||
for (int z = -r + 1; z <= r && !done; z++) {
|
||||
safeLocation = startLocation.clone().add(r, -radius, z);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
// South side
|
||||
for (int x = r - 1; x >= -r && !done; x--) {
|
||||
safeLocation = startLocation.clone().add(x, -radius, r);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
// West side
|
||||
for (int z = r - 1; z >= -r && !done; z--) {
|
||||
safeLocation = startLocation.clone().add(-r, -radius, z);
|
||||
if (!insideRegion || worldguardRegion.contains(safeLocation.getBlockX(),
|
||||
safeLocation.getBlockY(),
|
||||
safeLocation.getBlockZ())) {
|
||||
checked++;
|
||||
done = isSafe(safeLocation) || checked > maxTries;
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
bottomDone = bottomDone || !continueThisDirection;
|
||||
|
||||
// Increase cube radius
|
||||
radius++;
|
||||
}
|
||||
|
||||
if (done && isSafe(safeLocation)) {
|
||||
if (finalToSign) {
|
||||
getRegion().message(player, "teleport-successSign");
|
||||
|
||||
// Let the player look at the sign
|
||||
Vector playerVector = safeLocation.toVector();
|
||||
playerVector.setY(playerVector.getY() + player.getEyeHeight(true));
|
||||
Vector signVector = getRegion().getSignsFeature().getSigns().get(0).getLocation().toVector().add(new Vector(0.5, 0.5, 0.5));
|
||||
Vector direction = playerVector.clone().subtract(signVector).normalize();
|
||||
safeLocation.setYaw(180 - (float) Math.toDegrees(Math.atan2(direction.getX(), direction.getZ())));
|
||||
safeLocation.setPitch(90 - (float) Math.toDegrees(Math.acos(direction.getY())));
|
||||
} else {
|
||||
getRegion().message(player, "teleport-success");
|
||||
}
|
||||
|
||||
AreaShop.debug("Found location: " + safeLocation.toString() + " Tries: " + checked);
|
||||
PaperLib.teleportAsync(player, safeLocation).thenAccept(future::complete);
|
||||
} else {
|
||||
getRegion().message(player, "teleport-noSafe", checked, maxTries);
|
||||
AreaShop.debug("No location found, checked " + checked + " spots of max " + maxTries);
|
||||
future.complete(false);
|
||||
}
|
||||
}).execute();
|
||||
return future;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to the region or sign when he has permissions for it.
|
||||
*
|
||||
* @param player Player that should be teleported
|
||||
* @param toSign true to teleport to the first sign of the region, false for teleporting to the region itself
|
||||
* @return true if the teleport succeeded, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> teleportPlayer(Player player, boolean toSign) {
|
||||
return teleportPlayer(player, toSign, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to the region when he has permissions for it.
|
||||
*
|
||||
* @param player Player that should be teleported
|
||||
* @return true if the teleport succeeded, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> teleportPlayer(Player player) {
|
||||
return teleportPlayer(player, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start location of a safe teleport search.
|
||||
*
|
||||
* @param player The player to get it for
|
||||
* @param toSign true to try teleporting to the first sign, false for teleporting to the region
|
||||
* @return The start location
|
||||
*/
|
||||
private Location getStartLocation(Player player, Value<Boolean> toSign) {
|
||||
Location startLocation = null;
|
||||
ProtectedRegion worldguardRegion = getRegion().getRegion();
|
||||
|
||||
// Try to get sign location
|
||||
List<RegionSign> signs = getRegion().getSignsFeature().getSigns();
|
||||
boolean signAvailable = !signs.isEmpty();
|
||||
if (toSign.get()) {
|
||||
if (signAvailable) {
|
||||
// Use the location 1 below the sign to prevent weird spawing above the sign
|
||||
startLocation = signs.get(0).getLocation(); //.subtract(0.0, 1.0, 0.0);
|
||||
startLocation.setPitch(player.getLocation().getPitch());
|
||||
startLocation.setYaw(player.getLocation().getYaw());
|
||||
|
||||
// Move player x blocks away from the sign
|
||||
double distance = getRegion().getDoubleSetting("general.teleportSignDistance");
|
||||
if (distance > 0) {
|
||||
BlockFace facing = getRegion().getSignsFeature().getSigns().get(0).getFacing();
|
||||
Vector facingVector = new Vector(facing.getModX(), facing.getModY(), facing.getModZ())
|
||||
.normalize()
|
||||
.multiply(distance);
|
||||
startLocation.setX(startLocation.getBlockX() + 0.5);
|
||||
startLocation.setZ(startLocation.getBlockZ() + 0.5);
|
||||
startLocation.add(facingVector);
|
||||
}
|
||||
} else {
|
||||
// No sign available
|
||||
getRegion().message(player, "teleport-changedToNoSign");
|
||||
toSign.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Use teleportation location that is set for the region
|
||||
if (startLocation == null && hasTeleportLocation()) {
|
||||
startLocation = getTeleportLocation();
|
||||
}
|
||||
|
||||
// Calculate a default location
|
||||
if (startLocation == null) {
|
||||
// Set to block in the middle, y configured in the config
|
||||
Vector regionMin = AreaShop.getInstance().getWorldGuardHandler().getMinimumPoint(worldguardRegion);
|
||||
Vector regionMax = AreaShop.getInstance().getWorldGuardHandler().getMaximumPoint(worldguardRegion);
|
||||
Vector middle = regionMin.clone().midpoint(regionMax);
|
||||
String configSetting = getRegion().getStringSetting("general.teleportLocationY");
|
||||
if ("bottom".equalsIgnoreCase(configSetting)) {
|
||||
middle = middle.setY(regionMin.getBlockY());
|
||||
} else if ("top".equalsIgnoreCase(configSetting)) {
|
||||
middle = middle.setY(regionMax.getBlockY());
|
||||
} else if ("middle".equalsIgnoreCase(configSetting)) {
|
||||
middle = middle.setY(middle.getBlockY());
|
||||
} else {
|
||||
try {
|
||||
int vertical = Integer.parseInt(configSetting);
|
||||
middle = middle.setY(vertical);
|
||||
} catch (NumberFormatException e) {
|
||||
AreaShop.warn("Could not parse general.teleportLocationY: '" + configSetting + "'");
|
||||
}
|
||||
}
|
||||
startLocation = middle.toLocation(getRegion().getWorld(), player.getLocation().getYaw(), player.getLocation().getPitch());
|
||||
}
|
||||
|
||||
// Set location in the center of the block
|
||||
startLocation.setX(startLocation.getBlockX() + 0.5);
|
||||
startLocation.setZ(startLocation.getBlockZ() + 0.5);
|
||||
|
||||
return startLocation;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -255,7 +255,7 @@ public class WorldGuardRegionFlagsFeature extends RegionFeature {
|
||||
result = result.replace("&1", "&B");
|
||||
result = result.replace("&d", "&p");
|
||||
result = result.replace("&5", "&P");
|
||||
//result = result.replace("&0", "&0");
|
||||
result = result.replace("&0", "&0");
|
||||
result = result.replace("&8", "&1");
|
||||
result = result.replace("&7", "&2");
|
||||
result = result.replace("&f", "&w");
|
||||
|
||||
@@ -5,7 +5,6 @@ import io.papermc.lib.PaperLib;
|
||||
import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.managers.SignErrorLogger;
|
||||
import me.wiefferink.areashop.interfaces.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Materials;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
@@ -26,51 +25,12 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Sign that is connected to a region to display information and interact with the region.
|
||||
*/
|
||||
public class RegionSign {
|
||||
|
||||
|
||||
public static final BlockBehaviourHelper behaviourHelper = AreaShop.getInstance().getNMSHelper().behaviourHelper();
|
||||
public static Level invalidSignLogLevel;
|
||||
public static boolean removeInvalidSigns;
|
||||
|
||||
static {
|
||||
YamlConfiguration configuration = AreaShop.getInstance().getConfig();
|
||||
removeInvalidSigns = configuration.getBoolean("signs.removeInvalid");
|
||||
final String rawLogLevel = configuration.getString("signs.invalidSignLogLevel", "WARNING");
|
||||
try {
|
||||
assert rawLogLevel != null;
|
||||
invalidSignLogLevel = Level.parse(rawLogLevel);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
AreaShop.warn("Invalid Logging Level: " + rawLogLevel);
|
||||
invalidSignLogLevel = Level.WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean canLogSignError() {
|
||||
return AreaShop.getInstance().getLogger().isLoggable(invalidSignLogLevel);
|
||||
}
|
||||
|
||||
private static void logSignError(String... messages) {
|
||||
if (invalidSignLogLevel == Level.OFF) {
|
||||
return;
|
||||
}
|
||||
if (invalidSignLogLevel == Level.SEVERE) {
|
||||
AreaShop.error((Object) messages);
|
||||
} else if (invalidSignLogLevel == Level.WARNING) {
|
||||
AreaShop.warn((Object) messages);
|
||||
} else if (invalidSignLogLevel.intValue() >= Level.FINE.intValue()) {
|
||||
AreaShop.debug((Object) messages);
|
||||
} else {
|
||||
AreaShop.info((Object) messages);
|
||||
}
|
||||
}
|
||||
|
||||
private final SignsFeature signsFeature;
|
||||
private final String key;
|
||||
|
||||
@@ -151,7 +111,7 @@ public class RegionSign {
|
||||
/**
|
||||
* Get the material of the sign as saved in the config.
|
||||
*
|
||||
* @return Material of the sign, usually, a sign or {@link Material#AIR} if none.
|
||||
* @return Material of the sign, usually or one of the other wood types (different result for 1.13-), Material.AIR if none.
|
||||
*/
|
||||
public Material getMaterial() {
|
||||
String name = getRegion().getConfig().getString("general.signs." + key + ".signType");
|
||||
@@ -165,6 +125,7 @@ public class RegionSign {
|
||||
* @return true if the update was successful, otherwise false
|
||||
*/
|
||||
public boolean update() {
|
||||
|
||||
// Ignore updates of signs in chunks that are not loaded
|
||||
Location signLocation = getLocation();
|
||||
if (signLocation == null
|
||||
@@ -173,20 +134,23 @@ public class RegionSign {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getRegion().isDeleted()) {
|
||||
final GeneralRegion region = getRegion();
|
||||
|
||||
if (region.isDeleted()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
YamlConfiguration regionConfig = getRegion().getConfig();
|
||||
YamlConfiguration regionConfig = region.getConfig();
|
||||
ConfigurationSection signConfig = getProfile();
|
||||
Block block = signLocation.getBlock();
|
||||
if (signConfig == null || !signConfig.isSet(getRegion().getState().getValue())) {
|
||||
final String value = region.getState().getValue();
|
||||
if (signConfig == null || !signConfig.isSet(value)) {
|
||||
block.setType(Material.AIR);
|
||||
return true;
|
||||
}
|
||||
|
||||
ConfigurationSection stateConfig = signConfig.getConfigurationSection(getRegion().getState().getValue());
|
||||
assert stateConfig != null;
|
||||
ConfigurationSection stateConfig = signConfig.getConfigurationSection(value);
|
||||
|
||||
// Get the lines
|
||||
String[] signLines = new String[4];
|
||||
boolean signEmpty = true;
|
||||
@@ -198,13 +162,14 @@ public class RegionSign {
|
||||
block.setType(Material.AIR);
|
||||
return true;
|
||||
}
|
||||
|
||||
final BlockStateSnapshotResult snapshot = PaperLib.getBlockState(block, false);
|
||||
final BlockState blockState = snapshot.getState();
|
||||
final BlockData blockData = blockState.getBlockData();
|
||||
final SignErrorLogger errorLogger = AreaShop.getInstance().getSignErrorLogger();
|
||||
Material signType = getMaterial();
|
||||
// Place the sign back (with proper rotation and type) after it has been hidden or (indirectly) destroyed
|
||||
if (!Materials.isSign(blockState.getType())) {
|
||||
if (!Tag.SIGNS.isTagged(blockState.getType())) {
|
||||
// Don't do physics here, we first need to update the direction
|
||||
blockState.setType(signType);
|
||||
if (blockData instanceof WallSign) {
|
||||
@@ -216,34 +181,33 @@ public class RegionSign {
|
||||
blockState.update(false, true);
|
||||
// Check if the sign has popped
|
||||
if (!Materials.isSign(block.getType())) {
|
||||
final String message = String.format("Setting sign of $1%s of region $2%s failed, could not set sign block back", key, getRegion().getName());
|
||||
final String message = String.format("Setting sign of $1%s of region $2%s failed, could not set sign block back", key, region.getName());
|
||||
errorLogger.submitWarning(message);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
final String message = "Setting sign $1%s of region $2%s failed, RegionSign material was: $3%s";
|
||||
errorLogger.submitWarning(String.format(message, key, getRegion().getName(), signType.name()));
|
||||
errorLogger.submitWarning(String.format(message, key, region.getName(), signType.name()));
|
||||
}
|
||||
|
||||
// Save current rotation and type
|
||||
if (!regionConfig.isString("general.signs." + key + ".signType")) {
|
||||
getRegion().setSetting("general.signs." + key + ".signType", block.getType().name());
|
||||
region.setSetting("general.signs." + key + ".signType", blockState.getType().name());
|
||||
}
|
||||
if (!regionConfig.isString("general.signs." + key + ".facing")) {
|
||||
final BlockFace rotation;
|
||||
if (Materials.isSign(block.getType())) {
|
||||
BlockData data = blockState.getBlockData();
|
||||
if (data instanceof org.bukkit.block.data.type.Sign) {
|
||||
rotation = ((org.bukkit.block.data.type.Sign) block.getBlockData()).getRotation();
|
||||
} else if (data instanceof WallSign) {
|
||||
rotation = ((WallSign) data).getFacing();
|
||||
if (blockData instanceof org.bukkit.block.data.type.Sign) {
|
||||
rotation = ((org.bukkit.block.data.type.Sign) blockData).getRotation();
|
||||
} else if (blockData instanceof WallSign) {
|
||||
rotation = ((WallSign) blockData).getFacing();
|
||||
} else {
|
||||
rotation = null;
|
||||
}
|
||||
} else {
|
||||
rotation = null;
|
||||
}
|
||||
getRegion().setSetting("general.signs." + key + ".facing", rotation == null ? null : rotation.toString());
|
||||
region.setSetting("general.signs." + key + ".facing", rotation == null ? null : rotation.toString());
|
||||
}
|
||||
|
||||
// Apply replacements and color and then set it on the sign
|
||||
@@ -258,7 +222,8 @@ public class RegionSign {
|
||||
signState.setLine(i, signLines[i]);
|
||||
}
|
||||
// BlockState#update *should* return true here.
|
||||
return blockState.update(true, false);
|
||||
blockState.update(false, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,7 +264,8 @@ public class RegionSign {
|
||||
if (signConfig == null) {
|
||||
return false;
|
||||
}
|
||||
ConfigurationSection stateConfig = signConfig.getConfigurationSection(getRegion().getState().getValue().toLowerCase());
|
||||
final GeneralRegion region = getRegion();
|
||||
ConfigurationSection stateConfig = signConfig.getConfigurationSection(region.getState().getValue().toLowerCase());
|
||||
|
||||
// Run player commands if specified
|
||||
List<String> playerCommands = new ArrayList<>();
|
||||
@@ -307,14 +273,14 @@ public class RegionSign {
|
||||
// TODO move variable checking code to InteractiveMessenger?
|
||||
playerCommands.add(command.replace(Message.VARIABLE_START + AreaShop.tagClicker + Message.VARIABLE_END, clicker.getName()));
|
||||
}
|
||||
getRegion().runCommands(clicker, playerCommands);
|
||||
region.runCommands(clicker, playerCommands);
|
||||
|
||||
// Run console commands if specified
|
||||
List<String> consoleCommands = new ArrayList<>();
|
||||
for (String command : stateConfig.getStringList(clickType.getValue() + "Console")) {
|
||||
consoleCommands.add(command.replace(Message.VARIABLE_START + AreaShop.tagClicker + Message.VARIABLE_END, clicker.getName()));
|
||||
}
|
||||
getRegion().runCommands(Bukkit.getConsoleSender(), consoleCommands);
|
||||
region.runCommands(Bukkit.getConsoleSender(), consoleCommands);
|
||||
|
||||
return !playerCommands.isEmpty() || !consoleCommands.isEmpty();
|
||||
}
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
package me.wiefferink.areashop.features.signs;
|
||||
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SignCache implements Listener {
|
||||
|
||||
private final Map<String, RegionSign> allSigns = new HashMap<>();
|
||||
private final Map<String, List<RegionSign>> signsByChunk = new HashMap<>();
|
||||
|
||||
public void registerListeners() {
|
||||
Bukkit.getPluginManager().registerEvents(this, AreaShop.getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a location to a string to use as map key.
|
||||
*
|
||||
* @param location The location to get the key for
|
||||
* @return A string to use in a map for a location
|
||||
*/
|
||||
public static String locationToString(Location location) {
|
||||
return location.getWorld().getName() + ";" + location.getBlockX() + ";" + location.getBlockY() + ";" + location.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a chunk to a string to use as map key.
|
||||
*
|
||||
* @param location The location to get the key for
|
||||
* @return A string to use in a map for a chunk
|
||||
*/
|
||||
public static String chunkToString(Location location) {
|
||||
return location.getWorld().getName() + ";" + (location.getBlockX() >> 4) + ";" + (location.getBlockZ() >> 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a chunk to a string to use as map key.
|
||||
* Use a Location argument to prevent chunk loading!
|
||||
*
|
||||
* @param chunk The location to get the key for
|
||||
* @return A string to use in a map for a chunk
|
||||
*/
|
||||
public static String chunkToString(Chunk chunk) {
|
||||
return chunk.getWorld().getName() + ";" + chunk.getX() + ";" + chunk.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sign by a location.
|
||||
*
|
||||
* @param location The location to get the sign for
|
||||
* @return The RegionSign that is at the location, or null if none
|
||||
*/
|
||||
public RegionSign getSignByLocation(Location location) {
|
||||
return allSigns.get(locationToString(location));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map with all signs.
|
||||
*
|
||||
* @return Map with all signs: locationString -> RegionSign
|
||||
*/
|
||||
public Map<String, RegionSign> getAllSigns() {
|
||||
return allSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map with signs by chunk.
|
||||
*
|
||||
* @return Map with signs by chunk: chunkString -> List<RegionSign>
|
||||
*/
|
||||
public Map<String, List<RegionSign>> getSignsByChunk() {
|
||||
return signsByChunk;
|
||||
}
|
||||
|
||||
public void addSign(RegionSign regionSign) {
|
||||
signsByChunk.computeIfAbsent(regionSign.getStringChunk(), (unused) -> new ArrayList<>()).add(regionSign);
|
||||
}
|
||||
|
||||
public void removeSign(RegionSign regionSign) {
|
||||
final List<RegionSign> signs = signsByChunk.get(regionSign.getStringChunk());
|
||||
if (signs != null) {
|
||||
signs.remove(regionSign);
|
||||
}
|
||||
allSigns.remove(regionSign.getStringLocation());
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
HandlerList.unregisterAll(this);
|
||||
signsByChunk.clear();
|
||||
allSigns.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void regionUpdate(UpdateRegionEvent event) {
|
||||
event.getRegion().getSignsFeature().update();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
List<RegionSign> chunkSigns = signsByChunk.get(chunkToString(event.getChunk()));
|
||||
if (chunkSigns == null) {
|
||||
return;
|
||||
}
|
||||
int batchSize = Math.max(chunkSigns.size() / 10, 10);
|
||||
Utils.runAsBatches(chunkSigns, batchSize, RegionSign::update, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
|
||||
import me.wiefferink.areashop.features.RegionFeature;
|
||||
import me.wiefferink.areashop.interfaces.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.SignErrorLogger;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
@@ -23,7 +23,6 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -32,22 +31,14 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SignsFeature extends RegionFeature {
|
||||
|
||||
public static final SignCache signCache = new SignCache();
|
||||
|
||||
private static final BlockBehaviourHelper behaviourHelper = AreaShop.getInstance().getNMSHelper().behaviourHelper();
|
||||
|
||||
static {
|
||||
signCache.registerListeners();
|
||||
}
|
||||
|
||||
public static void shutdownGlobalState() {
|
||||
signCache.shutdown();
|
||||
}
|
||||
private static final Map<String, RegionSign> allSigns = Collections.synchronizedMap(new HashMap<>());
|
||||
private static final Map<String, List<RegionSign>> signsByChunk = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
private Map<String, RegionSign> signs;
|
||||
|
||||
@@ -76,8 +67,10 @@ public class SignsFeature extends RegionFeature {
|
||||
continue;
|
||||
}
|
||||
signs.put(sign.getStringLocation(), sign);
|
||||
signCache.addSign(sign);
|
||||
signsByChunk.computeIfAbsent(sign.getStringChunk(), key -> new ArrayList<>())
|
||||
.add(sign);
|
||||
}
|
||||
allSigns.putAll(signs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +112,7 @@ public class SignsFeature extends RegionFeature {
|
||||
* @return The RegionSign that is at the location, or null if none
|
||||
*/
|
||||
public static RegionSign getSignByLocation(Location location) {
|
||||
return signCache.getSignByLocation(location);
|
||||
return allSigns.get(locationToString(location));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +121,7 @@ public class SignsFeature extends RegionFeature {
|
||||
* @return Map with all signs: locationString -> RegionSign
|
||||
*/
|
||||
public static Map<String, RegionSign> getAllSigns() {
|
||||
return signCache.getAllSigns();
|
||||
return allSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +130,7 @@ public class SignsFeature extends RegionFeature {
|
||||
* @return Map with signs by chunk: chunkString -> List<RegionSign>
|
||||
*/
|
||||
public static Map<String, List<RegionSign>> getSignsByChunk() {
|
||||
return signCache.getSignsByChunk();
|
||||
return signsByChunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,15 +138,16 @@ public class SignsFeature extends RegionFeature {
|
||||
// Deregister signs from the registry
|
||||
if (signs != null) {
|
||||
for (Map.Entry<String, RegionSign> entry : signs.entrySet()) {
|
||||
signCache.removeSign(entry.getValue());
|
||||
allSigns.remove(entry.getKey());
|
||||
signsByChunk.get(entry.getValue().getStringChunk()).remove(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onSignBreak(BlockBreakEvent event) {
|
||||
if (getRegion().invalidated()) {
|
||||
AreaShop.warn("SignsFeature: Sign feature for an invalidated region is still active!");
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
// Check if it is a sign
|
||||
@@ -163,9 +157,6 @@ public class SignsFeature extends RegionFeature {
|
||||
if (regionSign == null) {
|
||||
return;
|
||||
}
|
||||
if (regionSign.getRegion().invalidated()) {
|
||||
AreaShop.warn("SignsFeature: Sign feature for an invalidated region object is still active!");
|
||||
}
|
||||
// Remove the sign of the rental region if the player has permission
|
||||
if (event.getPlayer().hasPermission("areashop.delsign")) {
|
||||
regionSign.remove();
|
||||
@@ -179,24 +170,32 @@ public class SignsFeature extends RegionFeature {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onIndirectSignBreak(BlockPhysicsEvent event) {
|
||||
if (getRegion().invalidated()) {
|
||||
AreaShop.warn("SignsFeature: Sign feature for an invalidated region is still active!");
|
||||
}
|
||||
// Check if the block is a sign
|
||||
if (!Materials.isSign(event.getBlock().getType())) {
|
||||
return;
|
||||
}
|
||||
final Block block = event.getBlock();
|
||||
final BlockData blockData = block.getBlockData();
|
||||
final Block attachedBlock;
|
||||
if (blockData instanceof WallSign) {
|
||||
attachedBlock = block.getRelative(((WallSign) blockData).getFacing().getOppositeFace());
|
||||
} else if (blockData instanceof Sign) {
|
||||
attachedBlock = block.getRelative(BlockFace.DOWN);
|
||||
} else {
|
||||
attachedBlock = null;
|
||||
}
|
||||
|
||||
// Check if still attached to a block
|
||||
// TODO: signs cannot be placed on all blocks, improve this check to isSolid()?
|
||||
if (attachedBlock == null || attachedBlock.getType() != Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the sign is really the same as a saved rent
|
||||
RegionSign regionSign = SignsFeature.getSignByLocation(event.getBlock().getLocation());
|
||||
if (regionSign == null) {
|
||||
return;
|
||||
}
|
||||
// If the block is in an invalid position then we remove the sign
|
||||
if (!behaviourHelper.isBlockValid(block)) {
|
||||
regionSign.remove();
|
||||
}
|
||||
|
||||
// Remove the sign so that it does not fall on the floor as an item (next region update will place it back when possible)
|
||||
AreaShop.debug("onIndirectSignBreak: Removed block of sign for", regionSign.getRegion().getName(), "at", regionSign.getStringLocation());
|
||||
@@ -206,9 +205,6 @@ public class SignsFeature extends RegionFeature {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onSignClick(PlayerInteractEvent event) {
|
||||
if (getRegion().invalidated()) {
|
||||
AreaShop.warn("SignsFeature: Sign feature for an invalidated region is still active!");
|
||||
}
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) {
|
||||
return;
|
||||
@@ -254,10 +250,10 @@ public class SignsFeature extends RegionFeature {
|
||||
event.setCancelled(ran);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
if (getRegion().invalidated()) {
|
||||
AreaShop.warn("SignsFeature: Sign feature for an invalidated region is still active!");
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
if (!plugin.isReady()) {
|
||||
@@ -538,6 +534,21 @@ public class SignsFeature extends RegionFeature {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void regionUpdate(UpdateRegionEvent event) {
|
||||
event.getRegion().getSignsFeature().update();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
List<RegionSign> chunkSigns = signsByChunk.get(chunkToString(event.getChunk()));
|
||||
if (chunkSigns == null) {
|
||||
return;
|
||||
}
|
||||
int batchSize = Math.max(chunkSigns.size() / 10, 10);
|
||||
Utils.runAsBatches(chunkSigns, batchSize, RegionSign::update, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all signs connected to this region.
|
||||
*
|
||||
@@ -589,7 +600,7 @@ public class SignsFeature extends RegionFeature {
|
||||
* @return A List with all sign locations
|
||||
*/
|
||||
public List<Location> getSignLocations() {
|
||||
List<Location> result = new ArrayList<>(signs.size());
|
||||
List<Location> result = new ArrayList<>();
|
||||
for (RegionSign sign : signs.values()) {
|
||||
result.add(sign.getLocation());
|
||||
}
|
||||
@@ -606,21 +617,23 @@ public class SignsFeature extends RegionFeature {
|
||||
*/
|
||||
public void addSign(Location location, Material signType, BlockFace facing, String profile) {
|
||||
int i = 0;
|
||||
final YamlConfiguration configuration = getRegion().getConfig();
|
||||
while (configuration.isSet("general.signs." + i)) {
|
||||
while (getRegion().getConfig().isSet("general.signs." + i)) {
|
||||
i++;
|
||||
}
|
||||
String signPath = "general.signs." + i + ".";
|
||||
getRegion().setSetting(signPath + "location", Utils.locationToConfig(location));
|
||||
getRegion().setSetting(signPath + "facing", facing != null ? facing.name() : null);
|
||||
getRegion().setSetting(signPath + "signType", signType != null ? signType.name() : null);
|
||||
final GeneralRegion region = getRegion();
|
||||
region.setSetting(signPath + "location", Utils.locationToConfig(location));
|
||||
region.setSetting(signPath + "facing", facing != null ? facing.name() : null);
|
||||
region.setSetting(signPath + "signType", signType != null ? signType.name() : null);
|
||||
if (profile != null && !profile.isEmpty()) {
|
||||
getRegion().setSetting(signPath + "profile", profile);
|
||||
region.setSetting(signPath + "profile", profile);
|
||||
}
|
||||
// Add to the map
|
||||
RegionSign sign = new RegionSign(this, i + "");
|
||||
RegionSign sign = new RegionSign(this, String.valueOf(i));
|
||||
signs.put(sign.getStringLocation(), sign);
|
||||
signCache.addSign(sign);
|
||||
allSigns.put(sign.getStringLocation(), sign);
|
||||
signsByChunk.computeIfAbsent(sign.getStringChunk(), key -> new ArrayList<>())
|
||||
.add(sign);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
package me.wiefferink.areashop.features.teleport;
|
||||
|
||||
import co.aikar.taskchain.TaskChain;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.features.RegionFeature;
|
||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.areashop.tools.Value;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TeleportFeature extends RegionFeature {
|
||||
|
||||
public TeleportFeature() {
|
||||
}
|
||||
|
||||
public TeleportFeature(GeneralRegion region) {
|
||||
setRegion(region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a certain location is safe to teleport to.
|
||||
*
|
||||
* @param location The location to check
|
||||
* @return true if it is safe, otherwise false
|
||||
*/
|
||||
static boolean isSafe(Location location) {
|
||||
Block feet = location.getBlock();
|
||||
Block head = feet.getRelative(BlockFace.UP);
|
||||
Block below = feet.getRelative(BlockFace.DOWN);
|
||||
Block above = head.getRelative(BlockFace.UP);
|
||||
|
||||
// Check the block at the feet and head of the player
|
||||
if ((feet.getType().isSolid() && !canSpawnIn(feet.getType())) || feet.isLiquid()) {
|
||||
return false;
|
||||
} else if ((head.getType().isSolid() && !canSpawnIn(head.getType())) || head.isLiquid()) {
|
||||
return false;
|
||||
} else if (!below.getType().isSolid() || cannotSpawnOn(below.getType()) || below.isLiquid()) {
|
||||
return false;
|
||||
} else if (above.isLiquid() || cannotSpawnBeside(above.getType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get all blocks around the player (below foot level, foot level, head level and above head level)
|
||||
Set<Material> around = new HashSet<>();
|
||||
for (int y = 0; y <= 3; y++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
// Skip blocks in the column of the player
|
||||
if (x == 0 && z == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
around.add(below.getRelative(x, y, z).getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check the blocks around the player
|
||||
for (Material material : around) {
|
||||
if (cannotSpawnBeside(material)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player can spawn in here.
|
||||
*
|
||||
* @param material Material to check (assumed that this is at the feet or head level)
|
||||
* @return true when it is safe to spawn inside, otherwise false
|
||||
*/
|
||||
private static boolean canSpawnIn(Material material) {
|
||||
String name = material.name();
|
||||
return name.contains("DOOR")
|
||||
|| name.contains("SIGN")
|
||||
|| name.contains("PLATE") // Redstone plates
|
||||
|| name.equals("DRAGON_EGG");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player can spawn on here.
|
||||
*
|
||||
* @param material Material to check (assumed that this is below the feet)
|
||||
* @return true when it is safe to spawn on top of, otherwise false
|
||||
*/
|
||||
private static boolean cannotSpawnOn(Material material) {
|
||||
String name = material.name();
|
||||
return name.equals("CACTUS")
|
||||
|| name.contains("PISTON")
|
||||
|| name.contains("SIGN")
|
||||
|| name.contains("DOOR")
|
||||
|| name.contains("PLATE")
|
||||
|| name.contains("REDSTONE_LAMP")
|
||||
|| name.contains("FENCE")
|
||||
|| name.contains("GLASS_PANE") || name.contains("THIN_GLASS")
|
||||
|| name.equals("DRAGON_EGG")
|
||||
|| name.contains("MAGMA");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player can spawn next to it.
|
||||
*
|
||||
* @param material Material to check (assumed that this is somewhere around the player)
|
||||
* @return true when it is safe to spawn next to, otherwise false
|
||||
*/
|
||||
private static boolean cannotSpawnBeside(Material material) {
|
||||
String name = material.name();
|
||||
return name.contains("LAVA")
|
||||
|| name.contains("CACTUS")
|
||||
|| name.equals("FIRE")
|
||||
|| name.contains("MAGMA");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the teleportlocation set for this region.
|
||||
*
|
||||
* @return The teleport location, or null if not set
|
||||
*/
|
||||
public Location getTeleportLocation() {
|
||||
return Utils.configToLocation(getRegion().getConfigurationSectionSetting("general.teleportLocation"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the region has a teleportLocation specified.
|
||||
*
|
||||
* @return true if the region has a teleportlocation, false otherwise
|
||||
*/
|
||||
public boolean hasTeleportLocation() {
|
||||
return getRegion().getConfigurationSectionSetting("general.teleportLocation") != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the teleport location of this region.
|
||||
*
|
||||
* @param location The location to set as teleport location
|
||||
*/
|
||||
public void setTeleport(Location location) {
|
||||
if (location == null) {
|
||||
getRegion().setSetting("general.teleportLocation", null);
|
||||
} else {
|
||||
getRegion().setSetting("general.teleportLocation", Utils.locationToConfig(location, true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to the region or sign.
|
||||
*
|
||||
* @param player Player that should be teleported
|
||||
* @param toSign true to teleport to the first sign of the region, false for teleporting to the region itself
|
||||
* @param checkRestrictions Set to true if teleport permissions should be checked, false otherwise, also toggles cross-world check
|
||||
* @return true if the teleport succeeded, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> teleportPlayer(Player player, boolean toSign, boolean checkRestrictions) {
|
||||
return new TeleportJob(this, plugin).executeTeleport(player, toSign, checkRestrictions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to the region or sign when he has permissions for it.
|
||||
*
|
||||
* @param player Player that should be teleported
|
||||
* @param toSign true to teleport to the first sign of the region, false for teleporting to the region itself
|
||||
* @return true if the teleport succeeded, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> teleportPlayer(Player player, boolean toSign) {
|
||||
return teleportPlayer(player, toSign, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to the region when he has permissions for it.
|
||||
*
|
||||
* @param player Player that should be teleported
|
||||
* @return true if the teleport succeeded, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> teleportPlayer(Player player) {
|
||||
return teleportPlayer(player, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start location of a safe teleport search.
|
||||
*
|
||||
* @param player The player to get it for
|
||||
* @param toSign true to try teleporting to the first sign, false for teleporting to the region
|
||||
* @return The start location
|
||||
*/
|
||||
Location getStartLocation(Player player, Value<Boolean> toSign) {
|
||||
Location startLocation = null;
|
||||
ProtectedRegion worldguardRegion = getRegion().getRegion();
|
||||
|
||||
// Try to get sign location
|
||||
List<RegionSign> signs = getRegion().getSignsFeature().getSigns();
|
||||
boolean signAvailable = !signs.isEmpty();
|
||||
if (toSign.get()) {
|
||||
if (signAvailable) {
|
||||
// Use the location 1 below the sign to prevent weird spawing above the sign
|
||||
startLocation = signs.get(0).getLocation(); //.subtract(0.0, 1.0, 0.0);
|
||||
startLocation.setPitch(player.getLocation().getPitch());
|
||||
startLocation.setYaw(player.getLocation().getYaw());
|
||||
|
||||
// Move player x blocks away from the sign
|
||||
double distance = getRegion().getDoubleSetting("general.teleportSignDistance");
|
||||
if (distance > 0) {
|
||||
BlockFace facing = getRegion().getSignsFeature().getSigns().get(0).getFacing();
|
||||
Vector facingVector = new Vector(facing.getModX(), facing.getModY(), facing.getModZ())
|
||||
.normalize()
|
||||
.multiply(distance);
|
||||
startLocation.setX(startLocation.getBlockX() + 0.5);
|
||||
startLocation.setZ(startLocation.getBlockZ() + 0.5);
|
||||
startLocation.add(facingVector);
|
||||
}
|
||||
} else {
|
||||
// No sign available
|
||||
getRegion().message(player, "teleport-changedToNoSign");
|
||||
toSign.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Use teleportation location that is set for the region
|
||||
if (startLocation == null && hasTeleportLocation()) {
|
||||
startLocation = getTeleportLocation();
|
||||
}
|
||||
|
||||
// Calculate a default location
|
||||
if (startLocation == null) {
|
||||
// Set to block in the middle, y configured in the config
|
||||
Vector regionMin = AreaShop.getInstance().getWorldGuardHandler().getMinimumPoint(worldguardRegion);
|
||||
Vector regionMax = AreaShop.getInstance().getWorldGuardHandler().getMaximumPoint(worldguardRegion);
|
||||
Vector middle = regionMin.clone().midpoint(regionMax);
|
||||
String configSetting = getRegion().getStringSetting("general.teleportLocationY");
|
||||
if ("bottom".equalsIgnoreCase(configSetting)) {
|
||||
middle = middle.setY(regionMin.getBlockY());
|
||||
} else if ("top".equalsIgnoreCase(configSetting)) {
|
||||
middle = middle.setY(regionMax.getBlockY());
|
||||
} else if ("middle".equalsIgnoreCase(configSetting)) {
|
||||
middle = middle.setY(middle.getBlockY());
|
||||
} else {
|
||||
try {
|
||||
int vertical = Integer.parseInt(configSetting);
|
||||
middle = middle.setY(vertical);
|
||||
} catch (NumberFormatException e) {
|
||||
AreaShop.warn("Could not parse general.teleportLocationY: '" + configSetting + "'");
|
||||
}
|
||||
}
|
||||
startLocation = new Location(getRegion().getWorld(), middle.getX(), middle.getY(), middle.getZ(), player.getLocation().getYaw(), player.getLocation().getPitch());
|
||||
}
|
||||
|
||||
// Set location in the center of the block
|
||||
startLocation.setX(startLocation.getBlockX() + 0.5);
|
||||
startLocation.setZ(startLocation.getBlockZ() + 0.5);
|
||||
|
||||
return startLocation;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,639 @@
|
||||
package me.wiefferink.areashop.features.teleport;
|
||||
|
||||
import co.aikar.taskchain.TaskChain;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.areashop.tools.Value;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
class TeleportJob {
|
||||
|
||||
private final AreaShop plugin;
|
||||
private final GeneralRegion region;
|
||||
private final TeleportFeature feature;
|
||||
private BukkitTask notifierTask;
|
||||
|
||||
private boolean running;
|
||||
private int checked;
|
||||
private boolean done;
|
||||
private boolean blocksInRegionCopy;
|
||||
private boolean northDone = false, eastDone = false, southDone = false, westDone = false, topDone = false, bottomDone = false;
|
||||
private boolean continueThisDirection;
|
||||
private int radius = 1;
|
||||
|
||||
public TeleportJob(final TeleportFeature region, final AreaShop plugin) {
|
||||
this.feature = region;
|
||||
this.region = region.getRegion();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private static Function<double[], Boolean> generateContainsFunction(final ProtectedRegion worldguardRegion) {
|
||||
final BlockVector3 min = worldguardRegion.getMinimumPoint(), max = worldguardRegion.getMaximumPoint();
|
||||
if (worldguardRegion instanceof GlobalProtectedRegion) {
|
||||
return (unused) -> true;
|
||||
} else if (worldguardRegion instanceof ProtectedCuboidRegion) {
|
||||
return coords -> {
|
||||
final double x = coords[0];
|
||||
final double y = coords[1];
|
||||
final double z = coords[2];
|
||||
return x >= min.getBlockX() && x < max.getBlockX() + 1
|
||||
&& y >= min.getBlockY() && y < max.getBlockY() + 1
|
||||
&& z >= min.getBlockZ() && z < max.getBlockZ() + 1;
|
||||
};
|
||||
} else if (worldguardRegion instanceof ProtectedPolygonalRegion) {
|
||||
final int minY = min.getY(), maxY = max.getY();
|
||||
final List<BlockVector2> points = worldguardRegion.getPoints();
|
||||
return coords -> {
|
||||
|
||||
int targetX = (int) Math.round(coords[0]); // Width
|
||||
int targetY = (int) Math.round(coords[1]); // Height
|
||||
int targetZ = (int) Math.round(coords[2]); // Depth
|
||||
|
||||
if (targetY < minY || targetY > maxY) {
|
||||
return false;
|
||||
}
|
||||
//Quick and dirty check.
|
||||
if (targetX < min.getBlockX() || targetX > max.getBlockX() || targetZ < min.getBlockZ() || targetZ > max.getBlockZ()) {
|
||||
return false;
|
||||
}
|
||||
boolean inside = false;
|
||||
int npoints = points.size();
|
||||
int xNew, zNew;
|
||||
int xOld, zOld;
|
||||
int x1, z1;
|
||||
int x2, z2;
|
||||
long crossproduct;
|
||||
int i;
|
||||
|
||||
xOld = points.get(npoints - 1).getBlockX();
|
||||
zOld = points.get(npoints - 1).getBlockZ();
|
||||
|
||||
for (i = 0; i < npoints; i++) {
|
||||
xNew = points.get(i).getBlockX();
|
||||
zNew = points.get(i).getBlockZ();
|
||||
//Check for corner
|
||||
if (xNew == targetX && zNew == targetZ) {
|
||||
return true;
|
||||
}
|
||||
if (xNew > xOld) {
|
||||
x1 = xOld;
|
||||
x2 = xNew;
|
||||
z1 = zOld;
|
||||
z2 = zNew;
|
||||
} else {
|
||||
x1 = xNew;
|
||||
x2 = xOld;
|
||||
z1 = zNew;
|
||||
z2 = zOld;
|
||||
}
|
||||
if (x1 <= targetX && targetX <= x2) {
|
||||
crossproduct = ((long) targetZ - (long) z1) * (long) (x2 - x1)
|
||||
- ((long) z2 - (long) z1) * (long) (targetX - x1);
|
||||
if (crossproduct == 0) {
|
||||
if ((z1 <= targetZ) == (targetZ <= z2)) return true; // on edge
|
||||
} else if (crossproduct < 0 && (x1 != targetX)) {
|
||||
inside = !inside;
|
||||
}
|
||||
}
|
||||
xOld = xNew;
|
||||
zOld = zNew;
|
||||
}
|
||||
|
||||
return inside;
|
||||
};
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unknown region type: " + worldguardRegion.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> executeTeleport(final Player player, boolean toSign, boolean checkRestrictions) {
|
||||
|
||||
if (running) {
|
||||
throw new IllegalStateException("Task is already running!");
|
||||
}
|
||||
running = true;
|
||||
// Check basics
|
||||
if (feature == null) {
|
||||
region.message(player, "general-noRegion");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
if (region.getWorld() == null) {
|
||||
region.message(player, "general-noWorld");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
if (checkRestrictions) {
|
||||
// Check correct world
|
||||
if (!region.getBooleanSetting("general.teleportCrossWorld") && !player.getWorld().equals(region.getWorld())) {
|
||||
region.message(player, "teleport-wrongWorld", player.getWorld().getName());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
boolean owner = player.getUniqueId().equals(region.getOwner());
|
||||
boolean friend = region.getFriendsFeature().getFriends().contains(player.getUniqueId());
|
||||
boolean available = region.isAvailable();
|
||||
// Teleport to sign instead if they dont have permission for teleporting to region
|
||||
if ((!toSign && owner && !player.hasPermission("areashop.teleport") && player.hasPermission("areashop.teleportsign")
|
||||
|| !toSign && !owner && !friend && !player.hasPermission("areashop.teleportall") && player.hasPermission("areashop.teleportsignall")
|
||||
|| !toSign && !owner && friend && !player.hasPermission("areashop.teleportfriend") && player.hasPermission("areashop.teleportfriendsign")
|
||||
|| !toSign && !owner && !friend && available && !player.hasPermission("areashop.teleportavailable") && player.hasPermission("areashop.teleportavailablesign"))) {
|
||||
region.message(player, "teleport-changedToSign");
|
||||
toSign = true;
|
||||
}
|
||||
// Check permissions
|
||||
if (owner && !available && !player.hasPermission("areashop.teleport") && !toSign) {
|
||||
region.message(player, "teleport-noPermission");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (!owner && !available && !player.hasPermission("areashop.teleportall") && !toSign && !friend) {
|
||||
region.message(player, "teleport-noPermissionOther");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (!owner && !available && !player.hasPermission("areashop.teleportfriend") && !toSign && friend) {
|
||||
region.message(player, "teleport-noPermissionFriend");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (available && !player.hasPermission("areashop.teleportavailable") && !toSign) {
|
||||
region.message(player, "teleport-noPermissionAvailable");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (owner && !available && !player.hasPermission("areashop.teleportsign") && toSign) {
|
||||
region.message(player, "teleport-noPermissionSign");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (!owner && !available && !player.hasPermission("areashop.teleportsignall") && toSign && !friend) {
|
||||
region.message(player, "teleport-noPermissionOtherSign");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (!owner && !available && !player.hasPermission("areashop.teleportfriendsign") && toSign && friend) {
|
||||
region.message(player, "teleport-noPermissionFriendSign");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else if (available && !player.hasPermission("areashop.teleportavailablesign") && toSign) {
|
||||
region.message(player, "teleport-noPermissionAvailableSign");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the starting location
|
||||
Value<Boolean> toSignRef = new Value<>(toSign);
|
||||
Location startLocation = feature.getStartLocation(player, toSignRef);
|
||||
toSign = toSignRef.get();
|
||||
|
||||
boolean insideRegion;
|
||||
if (toSign) {
|
||||
insideRegion = region.getBooleanSetting("general.teleportToSignIntoRegion");
|
||||
} else {
|
||||
insideRegion = region.getBooleanSetting("general.teleportIntoRegion");
|
||||
}
|
||||
|
||||
// Check locations starting from startLocation and then a cube that increases
|
||||
// radius around that (until no block in the region is found at all cube sides)
|
||||
|
||||
ProtectedRegion worldguardRegion = region.getRegion();
|
||||
final Function<double[], Boolean> regionContains = generateContainsFunction(worldguardRegion);
|
||||
|
||||
boolean blocksInRegion = worldguardRegion.contains(startLocation.getBlockX(), startLocation.getBlockY(), startLocation.getBlockZ());
|
||||
if (!blocksInRegion && insideRegion) {
|
||||
region.message(player, "teleport-blocked");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
// Tracking of which sides to continue the search
|
||||
final World world = region.getWorld();
|
||||
BlockVector3 min = worldguardRegion.getMinimumPoint();
|
||||
BlockVector3 max = worldguardRegion.getMaximumPoint();
|
||||
|
||||
final Collection<Chunk> collection = ConcurrentHashMap.newKeySet();
|
||||
final List<CompletableFuture<Object>> futures = new ArrayList<>();
|
||||
final Collection<int[]> coords = new HashSet<>();
|
||||
for (int x = min.getX(); x < max.getX(); x += 16) {
|
||||
for (int z = min.getZ(); z < max.getZ(); z += 16) {
|
||||
coords.add(new int[]{x, z});
|
||||
}
|
||||
}
|
||||
final CompletableFuture<?> schedulingFuture;
|
||||
if (coords.size() < 128) {
|
||||
schedulingFuture = Utils.runAsBatches(coords, 32,
|
||||
coord -> futures.add(PaperLib.getChunkAtAsync(world, coord[0], coord[1]).thenApply(chunk -> {
|
||||
chunk.setForceLoaded(true);
|
||||
collection.add(chunk);
|
||||
return chunk;
|
||||
})), false);
|
||||
} else {
|
||||
schedulingFuture = null;
|
||||
}
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
final boolean finalToSign = toSign;
|
||||
|
||||
final Runnable task = () -> {
|
||||
blocksInRegionCopy = blocksInRegion;
|
||||
int safeY = startLocation.getBlockY();
|
||||
int safeX = startLocation.getBlockX();
|
||||
int safeZ = startLocation.getBlockZ();
|
||||
final Location temp = new Location(world, 0, 0, 0);
|
||||
// Tries limit tracking
|
||||
|
||||
int maxTries = plugin.getConfig().getInt("maximumTries");
|
||||
|
||||
// Tracking of which sides to continue the search
|
||||
try {
|
||||
this.done = Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(startLocation)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
Utils.newChain().async(() -> {
|
||||
while ((blocksInRegionCopy || !insideRegion) && !done) {
|
||||
blocksInRegionCopy = false;
|
||||
|
||||
// North side
|
||||
continueThisDirection = false;
|
||||
temp.setX(-radius + 1);
|
||||
temp.setY(-radius + 1);
|
||||
temp.setZ(-radius);
|
||||
for (int x = -radius + 1; x <= radius && !done && !northDone; x++) {
|
||||
for (int y = -radius + 1; y < radius && !done; y++) {
|
||||
if (y + safeY > 256 || y + safeY < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!insideRegion || regionContains.apply(new double[]{x + safeX, y + safeY, safeZ - radius})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(0, 1, 0);
|
||||
}
|
||||
temp.add(1, 0, 0);
|
||||
}
|
||||
northDone = northDone || !continueThisDirection;
|
||||
}
|
||||
}).abortIf((var0) -> done).async(() -> {
|
||||
// South side
|
||||
continueThisDirection = false;
|
||||
temp.setX(radius - 1);
|
||||
temp.setY(-radius + 1);
|
||||
temp.setZ(-radius);
|
||||
for (int x = radius - 1; x >= -radius && !done && !southDone; x--) {
|
||||
for (int y = -radius + 1; y < radius && !done; y++) {
|
||||
if (y + safeY > 256 || y + safeY < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY + y, safeZ - radius})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(0, 1, 0);
|
||||
}
|
||||
temp.add(-1, 0, 0);
|
||||
}
|
||||
southDone = southDone || !continueThisDirection;
|
||||
}).abortIf((var0) -> done).async(() -> {
|
||||
// East side
|
||||
continueThisDirection = false;
|
||||
temp.setX(-radius + 1);
|
||||
temp.setY(-radius + 1);
|
||||
temp.setZ(0);
|
||||
for (int z = -radius + 1; z <= radius && !done && !eastDone; z++) {
|
||||
for (int y = -radius + 1; y < radius && !done; y++) {
|
||||
if (y + safeY > 256 || y + safeY < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX + radius, y + safeY, z + safeZ})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(0, 1, 0);
|
||||
}
|
||||
temp.add(0, 0, 1);
|
||||
}
|
||||
eastDone = eastDone || !continueThisDirection;
|
||||
}).abortIf((var0) -> done).async(() -> {
|
||||
// West side
|
||||
continueThisDirection = false;
|
||||
temp.setX(-radius);
|
||||
temp.setY(-radius);
|
||||
temp.setZ(radius - 1);
|
||||
for (int z = radius - 1; z >= -radius && !done && !westDone; z--) {
|
||||
for (int y = -radius + 1; y < radius && !done; y++) {
|
||||
if (y + safeY > 256 || y + safeY < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX - radius, safeY + y, safeZ + z})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(0, 1, 0);
|
||||
}
|
||||
temp.add(0, 0, -1);
|
||||
}
|
||||
westDone = westDone || !continueThisDirection;
|
||||
}).abortIf((var0) -> done).async(() -> {
|
||||
// Top side
|
||||
continueThisDirection = false;
|
||||
// Middle block of the top
|
||||
if ((safeY + radius) > 256) {
|
||||
topDone = true;
|
||||
}
|
||||
if (!done && !topDone) {
|
||||
temp.setX(0);
|
||||
temp.setY(radius);
|
||||
temp.setZ(0);
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX, safeY + radius, safeZ})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
|
||||
temp.setY(radius);
|
||||
for (int r = 1; r <= radius && !done && !topDone; r++) {
|
||||
temp.setX(-r + 1);
|
||||
temp.setZ(-r);
|
||||
for (int x = -r + 1; x <= r && !done; x++) {
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY + radius, safeZ - r})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(1, 0, 0);
|
||||
}
|
||||
// East
|
||||
temp.setX(r);
|
||||
temp.setZ(-r + 1);
|
||||
for (int z = -r + 1; z <= r && !done; z++) {
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX + r, safeY + radius, safeZ + z})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(0, 0, z);
|
||||
}
|
||||
// South side
|
||||
temp.setX(r - 1);
|
||||
temp.setZ(r);
|
||||
for (int x = r - 1; x >= -r && !done; x--) {
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY + radius, safeZ + r})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(-1, 0, 0);
|
||||
}
|
||||
// West side
|
||||
temp.setX(-r);
|
||||
temp.setZ(r - 1);
|
||||
for (int z = r - 1; z >= -r && !done; z--) {
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX - r, safeY + radius, safeZ + z})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(0, 0, -1);
|
||||
}
|
||||
}
|
||||
topDone = topDone || !continueThisDirection;
|
||||
}).abortIf(var0 -> done).async(() -> {
|
||||
// Bottom side
|
||||
continueThisDirection = false;
|
||||
// Middle block of the bottom
|
||||
if (safeY - radius < 0) {
|
||||
bottomDone = true;
|
||||
}
|
||||
if (!done && !bottomDone) {
|
||||
temp.setX(0);
|
||||
temp.setY(-radius);
|
||||
temp.setZ(0);
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX, safeY - radius, safeZ})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
}
|
||||
temp.setY(-radius);
|
||||
for (int r = 1; r <= radius && !done && !bottomDone; r++) {
|
||||
// North
|
||||
temp.setX(-r + 1);
|
||||
temp.setZ(-r);
|
||||
for (int x = -r + 1; x <= r && !done; x++) {
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY - radius, safeZ - r})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(1, 0, 0);
|
||||
}
|
||||
// East
|
||||
temp.setX(0);
|
||||
temp.setZ(-r + 1);
|
||||
for (int z = -r + 1; z <= r && !done; z++) {
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX + r, safeY - radius, safeZ + z})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(0, 0, 1);
|
||||
}
|
||||
// South side
|
||||
temp.setX(r - 1);
|
||||
temp.setZ(r);
|
||||
for (int x = r - 1; x >= -r && !done; x--) {
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY - radius, safeZ + r})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(-1, 0, 0);
|
||||
}
|
||||
// West side
|
||||
temp.setX(-r);
|
||||
temp.setZ(r - 1);
|
||||
for (int z = r - 1; z >= -r && !done; z--) {
|
||||
if (!insideRegion || regionContains.apply(new double[]{safeX - r, safeY - radius, safeZ + z})) {
|
||||
checked++;
|
||||
try {
|
||||
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
|
||||
ex.printStackTrace();
|
||||
this.done = false;
|
||||
}
|
||||
blocksInRegionCopy = true;
|
||||
continueThisDirection = true;
|
||||
}
|
||||
temp.add(0, 0, -1);
|
||||
}
|
||||
}
|
||||
bottomDone = bottomDone || !continueThisDirection;
|
||||
|
||||
// Increase cube radius
|
||||
radius++;
|
||||
startLocation.add(temp);
|
||||
}).execute(() -> Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (done && TeleportFeature.isSafe(startLocation)) {
|
||||
if (finalToSign) {
|
||||
region.message(player, "teleport-successSign");
|
||||
|
||||
// Let the player look at the sign
|
||||
Vector playerVector = startLocation.toVector();
|
||||
playerVector.setY(playerVector.getY() + player.getEyeHeight(true));
|
||||
Vector signVector = region.getSignsFeature().getSigns().get(0).getLocation().toVector().add(new Vector(0.5, 0.5, 0.5));
|
||||
Vector direction = playerVector.clone().subtract(signVector).normalize();
|
||||
startLocation.setYaw(180 - (float) Math.toDegrees(Math.atan2(direction.getX(), direction.getZ())));
|
||||
startLocation.setPitch(90 - (float) Math.toDegrees(Math.acos(direction.getY())));
|
||||
} else {
|
||||
region.message(player, "teleport-success");
|
||||
}
|
||||
|
||||
AreaShop.debug("Found location: " + startLocation.toString() + " Tries: " + checked);
|
||||
PaperLib.teleportAsync(player, startLocation).thenAccept(future::complete);
|
||||
} else {
|
||||
region.message(player, "teleport-noSafe", checked, maxTries);
|
||||
AreaShop.debug("No location found, checked " + checked + " spots of max " + maxTries);
|
||||
future.complete(false);
|
||||
}
|
||||
}));
|
||||
};
|
||||
// Start notifying the player, the one issue is that checked/max is 0 is if chunk loading takes up >= ~3s
|
||||
doNotifications(player.getUniqueId());
|
||||
TaskChain<?> chain = Utils.newChain();
|
||||
if (schedulingFuture != null) {
|
||||
// If there aren't too many chunks, pre-load them. Max will take 10 ticks ~ 500-600ms
|
||||
chain = chain.asyncFirstFuture(() -> schedulingFuture).asyncFutures((unused) -> futures);
|
||||
}
|
||||
// Run the calculation task async
|
||||
chain.async(task::run).execute();
|
||||
// Don't keep chunks force-loaded once the teleportation has been completed.
|
||||
return future.thenApply((unused0) -> {
|
||||
for (Chunk chunk : collection) {
|
||||
chunk.setForceLoaded(false); // Should be fine to call async(?)
|
||||
}
|
||||
running = false;
|
||||
return unused0;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the task which notifies player of teleport progress.
|
||||
*
|
||||
* @return Returns the task, may be null.
|
||||
*/
|
||||
public BukkitTask getNotifierTask() {
|
||||
return notifierTask;
|
||||
}
|
||||
|
||||
private void doNotifications(final UUID player0) {
|
||||
final int maxTries = plugin.getConfig().getInt("maximumTries");
|
||||
this.notifierTask = new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final Player player = Bukkit.getPlayer(player0);
|
||||
if (TeleportJob.this.done || player == null) {
|
||||
this.cancel();
|
||||
TeleportJob.this.notifierTask = null;
|
||||
return;
|
||||
}
|
||||
region.message(player, "teleport-calculation-progress", "%done%", String.valueOf(checked), "%max%", String.valueOf(maxTries));
|
||||
}
|
||||
|
||||
}.runTaskTimer(plugin, Utils.millisToTicks(3000), Utils.millisToTicks(3000));
|
||||
}
|
||||
}
|
||||
@@ -34,18 +34,20 @@ import me.wiefferink.areashop.commands.StackCommand;
|
||||
import me.wiefferink.areashop.commands.StopresellCommand;
|
||||
import me.wiefferink.areashop.commands.TeleportCommand;
|
||||
import me.wiefferink.areashop.commands.UnrentCommand;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CommandManager extends Manager implements TabExecutor {
|
||||
private final ArrayList<CommandAreaShop> commands;
|
||||
public class CommandManager extends Manager implements CommandExecutor, TabCompleter {
|
||||
private final List<CommandAreaShop> commands = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public CommandManager() {
|
||||
commands = new ArrayList<>();
|
||||
commands.add(new HelpCommand());
|
||||
commands.add(new RentCommand());
|
||||
commands.add(new UnrentCommand());
|
||||
@@ -82,6 +84,7 @@ public class CommandManager extends Manager implements TabExecutor {
|
||||
|
||||
// Register commands in bukkit
|
||||
plugin.getCommand("AreaShop").setExecutor(this);
|
||||
plugin.getCommand("AreaShop").setTabCompleter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +92,8 @@ public class CommandManager extends Manager implements TabExecutor {
|
||||
* @return The list with AreaShop commands
|
||||
*/
|
||||
public List<CommandAreaShop> getCommands() {
|
||||
return commands;
|
||||
// Return a cloned array
|
||||
return new ArrayList<>(commands);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +106,7 @@ public class CommandManager extends Manager implements TabExecutor {
|
||||
return;
|
||||
}
|
||||
// Add all messages to a list
|
||||
ArrayList<String> messages = new ArrayList<>();
|
||||
List<String> messages = new ArrayList<>(commands.size());
|
||||
plugin.message(target, "help-header");
|
||||
plugin.message(target, "help-alias");
|
||||
for(CommandAreaShop command : commands) {
|
||||
@@ -125,18 +129,21 @@ public class CommandManager extends Manager implements TabExecutor {
|
||||
}
|
||||
|
||||
// Redirect `/as info player <player>` to `/as me <player>`
|
||||
if(args.length == 3 && "info".equals(args[0]) && "player".equals(args[1])) {
|
||||
if(args.length == 3 && "info".equalsIgnoreCase(args[0]) && "player".equalsIgnoreCase(args[1])) {
|
||||
args[0] = "me";
|
||||
args[1] = args[2];
|
||||
}
|
||||
|
||||
// Execute command
|
||||
boolean executed = false;
|
||||
for(int i = 0; i < commands.size() && !executed; i++) {
|
||||
if(commands.get(i).canExecute(command, args)) {
|
||||
commands.get(i).execute(sender, args);
|
||||
for (final CommandAreaShop cmd : commands) {
|
||||
if (cmd.canExecute(command, args)) {
|
||||
cmd.execute(sender, args);
|
||||
executed = true;
|
||||
// Can't have two commands with same label
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Show help
|
||||
@@ -177,6 +184,7 @@ public class CommandManager extends Manager implements TabExecutor {
|
||||
for(CommandAreaShop c : commands) {
|
||||
if(c.canExecute(command, args)) {
|
||||
result = c.getTabCompleteList(toCompleteNumber, start, sender);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,8 +196,7 @@ public class CommandManager extends Manager implements TabExecutor {
|
||||
set.add(suggestion);
|
||||
}
|
||||
}
|
||||
result.clear();
|
||||
result.addAll(set);
|
||||
return new ArrayList<>(set);
|
||||
}
|
||||
//AreaShop.debug("Tabcomplete #" + toCompleteNumber + ", prefix="+ toCompletePrefix + ", result=" + result.toString());
|
||||
return result;
|
||||
|
||||
@@ -5,7 +5,7 @@ import me.wiefferink.areashop.features.CommandsFeature;
|
||||
import me.wiefferink.areashop.features.DebugFeature;
|
||||
import me.wiefferink.areashop.features.FriendsFeature;
|
||||
import me.wiefferink.areashop.features.RegionFeature;
|
||||
import me.wiefferink.areashop.features.TeleportFeature;
|
||||
import me.wiefferink.areashop.features.teleport.TeleportFeature;
|
||||
import me.wiefferink.areashop.features.WorldGuardRegionFlagsFeature;
|
||||
import me.wiefferink.areashop.features.signs.SignsFeature;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
@@ -57,7 +57,7 @@ public class FeatureManager extends Manager {
|
||||
for(Class<? extends RegionFeature> clazz : featureClasses) {
|
||||
try {
|
||||
regionFeatureConstructors.put(clazz, clazz.getConstructor(GeneralRegion.class));
|
||||
} catch(NoSuchMethodException | IllegalArgumentException e) {
|
||||
} catch(NoSuchMethodException | IllegalArgumentException ignored) {
|
||||
// The feature does not have a region specific part
|
||||
}
|
||||
}
|
||||
@@ -68,12 +68,10 @@ public class FeatureManager extends Manager {
|
||||
for(RegionFeature feature : globalFeatures) {
|
||||
feature.shutdown();
|
||||
}
|
||||
// FIXME make this system less hacky!
|
||||
SignsFeature.shutdownGlobalState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instanciate a feature for a certain region.
|
||||
* Instantiate a feature for a certain region.
|
||||
* @param region The region to create a feature for
|
||||
* @param featureClazz The class of the feature to create
|
||||
* @return The feature class
|
||||
|
||||
@@ -30,16 +30,15 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FileManager extends Manager {
|
||||
|
||||
private final Set<String> worldRegionsRequireSaving;
|
||||
|
||||
private final Map<String, BuyRegion> buyRegions = new HashMap<>();
|
||||
private final Map<String, RentRegion> rentRegions = new HashMap<>();
|
||||
private final Map<String, GeneralRegion> allRegions = new HashMap<>();
|
||||
private final Map<String, BuyRegion> buyRegions;
|
||||
private final Map<String, RentRegion> rentRegions;
|
||||
private final String regionsPath;
|
||||
private final HashMap<String, RegionGroup> groups;
|
||||
private final Map<String, RegionGroup> groups;
|
||||
private final String configPath;
|
||||
private YamlConfiguration config = null;
|
||||
private final String groupsPath;
|
||||
@@ -48,7 +47,7 @@ public class FileManager extends Manager {
|
||||
private YamlConfiguration defaultConfig = null;
|
||||
private YamlConfiguration defaultConfigFallback = null;
|
||||
private boolean saveGroupsRequired = false;
|
||||
private HashMap<String, Integer> versions = null;
|
||||
private Map<String, Integer> versions = null;
|
||||
private final String versionPath;
|
||||
private final String schemFolder;
|
||||
|
||||
@@ -56,6 +55,8 @@ public class FileManager extends Manager {
|
||||
* Constructor, initialize variabeles.
|
||||
*/
|
||||
public FileManager() {
|
||||
buyRegions = new HashMap<>();
|
||||
rentRegions = new HashMap<>();
|
||||
regionsPath = plugin.getDataFolder() + File.separator + AreaShop.regionsFolder;
|
||||
configPath = plugin.getDataFolder() + File.separator + "config.yml";
|
||||
groups = new HashMap<>();
|
||||
@@ -151,26 +152,8 @@ public class FileManager extends Manager {
|
||||
* @return The region if found, otherwise null
|
||||
*/
|
||||
public GeneralRegion getRegion(String name) {
|
||||
return allRegions.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
public CompletableFuture<GeneralRegion> getRegionUnsafe(String name) {
|
||||
final GeneralRegion cached = allRegions.get(name);
|
||||
if (cached != null) {
|
||||
return CompletableFuture.completedFuture(cached);
|
||||
}
|
||||
final File file = new File(regionsPath, name + ".yml");
|
||||
if (!file.exists()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
CompletableFuture<GeneralRegion> completableFuture = new CompletableFuture<>();
|
||||
Utils.newChain()
|
||||
.async(() -> {
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||
completableFuture.complete(loadRegion(configuration));
|
||||
})
|
||||
.execute();
|
||||
return completableFuture;
|
||||
GeneralRegion region = buyRegions.get(name.toLowerCase());
|
||||
return region == null ? rentRegions.get(name.toLowerCase()) : region;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,9 +200,10 @@ public class FileManager extends Manager {
|
||||
* @return List of all regions (it is safe to modify the list)
|
||||
*/
|
||||
public List<GeneralRegion> getRegions() {
|
||||
final List<GeneralRegion> list = new ArrayList<>(allRegions.size());
|
||||
list.addAll(allRegions.values());
|
||||
return list;
|
||||
List<GeneralRegion> regions = new ArrayList<>(buyRegions.size() + rentRegions.size());
|
||||
regions.addAll(buyRegions.values());
|
||||
regions.addAll(rentRegions.values());
|
||||
return regions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,11 +212,7 @@ public class FileManager extends Manager {
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
public List<String> getBuyNames() {
|
||||
final List<String> list = new ArrayList<>(buyRegions.size());
|
||||
for (GeneralRegion region : buyRegions.values()) {
|
||||
list.add(region.getName());
|
||||
}
|
||||
return list;
|
||||
return new ArrayList<>(buyRegions.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,11 +221,7 @@ public class FileManager extends Manager {
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
public List<String> getRentNames() {
|
||||
final List<String> list = new ArrayList<>(rentRegions.size());
|
||||
for (GeneralRegion region : rentRegions.values()) {
|
||||
list.add(region.getName());
|
||||
}
|
||||
return list;
|
||||
return new ArrayList<>(rentRegions.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,10 +230,8 @@ public class FileManager extends Manager {
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
public List<String> getRegionNames() {
|
||||
final List<String> list = new ArrayList<>(allRegions.size());
|
||||
for (GeneralRegion region : rentRegions.values()) {
|
||||
list.add(region.getName());
|
||||
}
|
||||
final List<String> list = getRentNames();
|
||||
list.addAll(getBuyNames());
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -267,11 +241,11 @@ public class FileManager extends Manager {
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
public List<String> getGroupNames() {
|
||||
final List<String> names = new ArrayList<>(groups.size());
|
||||
for (RegionGroup group : groups.values()) {
|
||||
names.add(group.getName());
|
||||
final List<String> list = new ArrayList<>(groups.size());
|
||||
for (final RegionGroup group : groups.values()) {
|
||||
list.add(group.getName());
|
||||
}
|
||||
return names;
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,22 +281,11 @@ public class FileManager extends Manager {
|
||||
if (event.isCancelled()) {
|
||||
return event;
|
||||
}
|
||||
final String name = region.getName().toLowerCase();
|
||||
// Forcefully remove regions from cache.
|
||||
buyRegions.remove(name);
|
||||
rentRegions.remove(name);
|
||||
final GeneralRegion existing;
|
||||
if (region instanceof BuyRegion) {
|
||||
existing = buyRegions.put(region.getName().toLowerCase(), (BuyRegion) region);
|
||||
buyRegions.put(region.getName().toLowerCase(), (BuyRegion) region);
|
||||
} else if (region instanceof RentRegion) {
|
||||
existing = rentRegions.put(region.getName().toLowerCase(), (RentRegion) region);
|
||||
} else {
|
||||
existing = null;
|
||||
rentRegions.put(region.getName().toLowerCase(), (RentRegion) region);
|
||||
}
|
||||
if (existing != null) {
|
||||
AreaShop.debug("FileManager: Region ", existing.getName(), " was overwritten.");
|
||||
}
|
||||
allRegions.put(region.getName().toLowerCase(), region);
|
||||
Bukkit.getPluginManager().callEvent(new AddedRegionEvent(region));
|
||||
return event;
|
||||
}
|
||||
@@ -436,9 +399,9 @@ public class FileManager extends Manager {
|
||||
}
|
||||
|
||||
region.resetRegionFlags();
|
||||
rentRegions.remove(region.getLowerCaseName());
|
||||
buyRegions.remove(region.getLowerCaseName());
|
||||
allRegions.remove(region.getLowerCaseName());
|
||||
rentRegions.remove(region.getLowerCaseName());
|
||||
|
||||
// Remove file
|
||||
File file = new File(plugin.getDataFolder() + File.separator + AreaShop.regionsFolder + File.separator + region.getLowerCaseName() + ".yml");
|
||||
if (file.exists()) {
|
||||
@@ -586,12 +549,12 @@ public class FileManager extends Manager {
|
||||
this.saveWorldGuardRegions();
|
||||
|
||||
final AtomicInteger processed = new AtomicInteger();
|
||||
for (GeneralRegion region : allRegions.values()) {
|
||||
for (GeneralRegion region : getRegions()) {
|
||||
if (region.isSaveRequired()) {
|
||||
region.saveNowAsync().thenAccept((unused) -> processed.getAndIncrement());
|
||||
}
|
||||
}
|
||||
final int finalCount = allRegions.size();
|
||||
final int finalCount = getRegions().size();
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
@@ -613,7 +576,7 @@ public class FileManager extends Manager {
|
||||
if (isSaveGroupsRequired()) {
|
||||
saveGroupsNow();
|
||||
}
|
||||
for (GeneralRegion region : allRegions.values()) {
|
||||
for (GeneralRegion region : getRegions()) {
|
||||
if (region.isSaveRequired()) {
|
||||
region.saveNow();
|
||||
}
|
||||
@@ -866,6 +829,7 @@ public class FileManager extends Manager {
|
||||
* @return true if succeeded, otherwise false
|
||||
*/
|
||||
public boolean loadGroupsFile() {
|
||||
boolean result = true;
|
||||
File groupFile = new File(groupsPath);
|
||||
if (groupFile.exists() && groupFile.isFile()) {
|
||||
try (
|
||||
@@ -883,19 +847,15 @@ public class FileManager extends Manager {
|
||||
RegionGroup group = new RegionGroup(plugin, groupName);
|
||||
groups.put(groupName, group);
|
||||
}
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all region files.
|
||||
*/
|
||||
public void loadRegionFiles() {
|
||||
buyRegions.values().forEach(GeneralRegion::invalidate);
|
||||
buyRegions.clear();
|
||||
rentRegions.values().forEach(GeneralRegion::invalidate);
|
||||
rentRegions.clear();
|
||||
buyRegions.clear();
|
||||
allRegions.clear();
|
||||
final File file = new File(regionsPath);
|
||||
if (!file.exists()) {
|
||||
if (!file.mkdirs()) {
|
||||
@@ -908,20 +868,6 @@ public class FileManager extends Manager {
|
||||
}
|
||||
}
|
||||
|
||||
private GeneralRegion loadRegion(YamlConfiguration config) {
|
||||
// Construct the correct type of region
|
||||
String type = config.getString("general.type");
|
||||
GeneralRegion region;
|
||||
if (RegionType.RENT.getValue().equals(type)) {
|
||||
region = new RentRegion(config);
|
||||
} else if (RegionType.BUY.getValue().equals(type)) {
|
||||
region = new BuyRegion(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return region;
|
||||
}
|
||||
|
||||
private void loadRegionFilesNow() {
|
||||
File file = new File(regionsPath);
|
||||
File[] regionFiles = file.listFiles();
|
||||
@@ -953,11 +899,17 @@ public class FileManager extends Manager {
|
||||
}
|
||||
|
||||
// Construct the correct type of region
|
||||
GeneralRegion region = loadRegion(regionConfig);
|
||||
if (region == null) {
|
||||
String type = regionConfig.getString("general.type");
|
||||
GeneralRegion region;
|
||||
if (RegionType.RENT.getValue().equals(type)) {
|
||||
region = new RentRegion(regionConfig);
|
||||
} else if (RegionType.BUY.getValue().equals(type)) {
|
||||
region = new BuyRegion(regionConfig);
|
||||
} else {
|
||||
noRegionType.add(regionFile.getPath());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check consistency
|
||||
boolean added = false;
|
||||
if (region.getName() == null) {
|
||||
@@ -998,7 +950,7 @@ public class FileManager extends Manager {
|
||||
|
||||
boolean noWorldRegions = !noWorld.isEmpty();
|
||||
while (!noWorld.isEmpty()) {
|
||||
List<GeneralRegion> toDisplay = new ArrayList<>(noWorld.size());
|
||||
List<GeneralRegion> toDisplay = new ArrayList<>();
|
||||
String missingWorld = noWorld.get(0).getWorldName();
|
||||
toDisplay.add(noWorld.get(0));
|
||||
for (int i = 1; i < noWorld.size(); i++) {
|
||||
@@ -1018,7 +970,7 @@ public class FileManager extends Manager {
|
||||
}
|
||||
|
||||
if (!incorrectDuration.isEmpty()) {
|
||||
List<String> incorrectDurationNames = new ArrayList<>(incorrectDuration.size());
|
||||
List<String> incorrectDurationNames = new ArrayList<>();
|
||||
for (GeneralRegion region : incorrectDuration) {
|
||||
incorrectDurationNames.add(region.getName());
|
||||
}
|
||||
@@ -1326,7 +1278,7 @@ public class FileManager extends Manager {
|
||||
|
||||
// Add 'general.lastActive' to rented/bought regions (initialize at current time)
|
||||
if (fileStatus == null || fileStatus < 3) {
|
||||
for (GeneralRegion region : allRegions.values()) {
|
||||
for (GeneralRegion region : getRegions()) {
|
||||
region.updateLastActiveTime();
|
||||
}
|
||||
// Update versions file to 3
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SignLinkerManager extends Manager implements Listener {
|
||||
@Override
|
||||
public void shutdown() {
|
||||
for(UUID uuid : signLinkers.keySet()) {
|
||||
exitSignLinkMode(Bukkit.getPlayer(uuid));
|
||||
exitSignLinkMode(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,18 @@ public class SignLinkerManager extends Manager implements Listener {
|
||||
plugin.message(player, "linksigns-stopped");
|
||||
}
|
||||
|
||||
private void exitSignLinkMode(UUID player) {
|
||||
signLinkers.remove(player);
|
||||
if(eventsRegistered && signLinkers.isEmpty()) {
|
||||
eventsRegistered = false;
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
final Player online = Bukkit.getPlayer(player);
|
||||
if (online != null) {
|
||||
plugin.message(player, "linksigns-stopped");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player is in sign linking mode.
|
||||
* @param player The player to check
|
||||
|
||||
@@ -366,7 +366,7 @@ public class BuyRegion extends GeneralRegion {
|
||||
r = null;
|
||||
OfflinePlayer oldOwnerPlayer = Bukkit.getOfflinePlayer(oldOwner);
|
||||
String oldOwnerName = getPlayerName();
|
||||
if(oldOwnerPlayer.hasPlayedBefore() && oldOwnerPlayer.getName() != null) {
|
||||
if(oldOwnerPlayer != null && oldOwnerPlayer.getName() != null) {
|
||||
r = plugin.getEconomy().depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice());
|
||||
oldOwnerName = oldOwnerPlayer.getName();
|
||||
} else if(oldOwnerName != null) {
|
||||
@@ -551,10 +551,11 @@ public class BuyRegion extends GeneralRegion {
|
||||
return false;
|
||||
}
|
||||
long lastPlayed = getLastActiveTime();
|
||||
long now = System.currentTimeMillis();
|
||||
//AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis()-player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
|
||||
if(Calendar.getInstance().getTimeInMillis() > (lastPlayed + inactiveSetting)) {
|
||||
if(now > (lastPlayed + inactiveSetting)) {
|
||||
AreaShop.info("Region " + getName() + " unrented because of inactivity for player " + getPlayerName());
|
||||
AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis() - player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
|
||||
AreaShop.debug("currentTime=" + now + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (now - player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
|
||||
return this.sell(true, null);
|
||||
}
|
||||
return false;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -721,10 +721,11 @@ public class RentRegion extends GeneralRegion {
|
||||
return false;
|
||||
}
|
||||
long lastPlayed = getLastActiveTime();
|
||||
final long now = System.currentTimeMillis();
|
||||
//AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis()-player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
|
||||
if(Calendar.getInstance().getTimeInMillis() > (lastPlayed + inactiveSetting)) {
|
||||
if(now > (lastPlayed + inactiveSetting)) {
|
||||
AreaShop.info("Region " + getName() + " unrented because of inactivity for player " + getPlayerName());
|
||||
AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis() - player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
|
||||
AreaShop.debug("currentTime=" + now + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (now - player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
|
||||
return this.unRent(true, null);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package me.wiefferink.areashop.tools;
|
||||
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import org.bstats.Metrics;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Analytics {
|
||||
|
||||
private Analytics() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Start analytics tracking.
|
||||
*/
|
||||
public static void start() {
|
||||
// bStats statistics
|
||||
try {
|
||||
Metrics metrics = new Metrics(AreaShop.getInstance());
|
||||
|
||||
// Number of regions
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("region_count") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return AreaShop.getInstance().getFileManager().getRegions().size();
|
||||
}
|
||||
});
|
||||
|
||||
// Number of rental regions
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("rental_region_count") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return AreaShop.getInstance().getFileManager().getRents().size();
|
||||
}
|
||||
});
|
||||
|
||||
// Number of buy regions
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("buy_region_count") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return AreaShop.getInstance().getFileManager().getBuys().size();
|
||||
}
|
||||
});
|
||||
|
||||
// Language
|
||||
metrics.addCustomChart(new Metrics.SimplePie("language") {
|
||||
@Override
|
||||
public String getValue() {
|
||||
return AreaShop.getInstance().getConfig().getString("language");
|
||||
}
|
||||
});
|
||||
|
||||
// Pie with region states
|
||||
metrics.addCustomChart(new Metrics.AdvancedPie("region_state") {
|
||||
@Override
|
||||
public HashMap<String, Integer> getValues(HashMap<String, Integer> result) {
|
||||
RegionStateStats stats = getStateStats();
|
||||
result.put("For Rent", stats.forrent);
|
||||
result.put("Rented", stats.rented);
|
||||
result.put("For Sale", stats.forsale);
|
||||
result.put("Sold", stats.sold);
|
||||
result.put("Reselling", stats.reselling);
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
// Time series of each region state
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("forrent_region_count") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return getStateStats().forrent;
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("rented_region_count") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return getStateStats().rented;
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("forsale_region_count") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return getStateStats().forsale;
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("sold_region_count") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return getStateStats().sold;
|
||||
}
|
||||
});
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("reselling_region_count") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return getStateStats().reselling;
|
||||
}
|
||||
});
|
||||
|
||||
// TODO track rent/buy/unrent/sell/resell actions (so that it can be reported per collection interval)
|
||||
|
||||
AreaShop.debug("Started bstats.org statistics service");
|
||||
} catch(Exception e) {
|
||||
AreaShop.debug("Could not start bstats.org statistics service");
|
||||
}
|
||||
}
|
||||
|
||||
private static class RegionStateStats {
|
||||
int forrent = 0;
|
||||
int forsale = 0;
|
||||
int rented = 0;
|
||||
int sold = 0;
|
||||
int reselling = 0;
|
||||
}
|
||||
|
||||
private static RegionStateStats getStateStats() {
|
||||
RegionStateStats result = new RegionStateStats();
|
||||
for(GeneralRegion region : AreaShop.getInstance().getFileManager().getRegions()) {
|
||||
if(region instanceof RentRegion) {
|
||||
RentRegion rent = (RentRegion)region;
|
||||
if(rent.isAvailable()) {
|
||||
result.forrent++;
|
||||
} else {
|
||||
result.rented++;
|
||||
}
|
||||
} else if(region instanceof BuyRegion) {
|
||||
BuyRegion buy = (BuyRegion)region;
|
||||
if(buy.isAvailable()) {
|
||||
result.forsale++;
|
||||
} else if(buy.isInResellingMode()) {
|
||||
result.reselling++;
|
||||
} else {
|
||||
result.sold++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package me.wiefferink.areashop.tools;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@@ -18,242 +18,234 @@ import java.util.logging.Logger;
|
||||
|
||||
public class GithubUpdateCheck {
|
||||
|
||||
public static final String API_HOST = "https://api.github.com/repos";
|
||||
public static final String API_LATEST_RELEASE = "releases/latest";
|
||||
public static final String USER_AGENT = "GithubUpdateCheck by NLThijs48";
|
||||
public static final boolean DEBUG = false;
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
public static final String API_HOST = "https://api.github.com/repos";
|
||||
public static final String API_LATEST_RELEASE = "releases/latest";
|
||||
public static final String USER_AGENT = "GithubUpdateCheck by NLThijs48";
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
private final String author;
|
||||
private final String repository;
|
||||
private final Plugin plugin;
|
||||
private final Logger logger;
|
||||
private final String currentVersion;
|
||||
private URL url;
|
||||
private VersionComparator versionComparator;
|
||||
// Status
|
||||
private boolean checking;
|
||||
private boolean error;
|
||||
private boolean hasUpdate;
|
||||
private String latestVersion;
|
||||
private final String author;
|
||||
private final String repository;
|
||||
private final Plugin plugin;
|
||||
private final Logger logger;
|
||||
private URL url;
|
||||
private VersionComparator versionComparator;
|
||||
|
||||
/**
|
||||
* Create a new GithubUpdateCheck with the required information.
|
||||
*
|
||||
* @param plugin The plugin to create it for (used for logging and checking version)
|
||||
* @param author The author of the plugin as used on Github
|
||||
* @param repository The repository name of the plugin on Github
|
||||
*/
|
||||
public GithubUpdateCheck(Plugin plugin, String author, String repository) {
|
||||
this.plugin = plugin;
|
||||
this.logger = plugin.getLogger();
|
||||
this.author = author;
|
||||
this.repository = repository;
|
||||
this.currentVersion = plugin.getDescription().getVersion();
|
||||
this.versionComparator = (latest, current) ->
|
||||
!latest.equalsIgnoreCase(current);
|
||||
// Status
|
||||
private boolean checking;
|
||||
private boolean error;
|
||||
private boolean hasUpdate;
|
||||
private String latestVersion;
|
||||
private final String currentVersion;
|
||||
|
||||
this.checking = false;
|
||||
this.error = false;
|
||||
this.hasUpdate = false;
|
||||
}
|
||||
/**
|
||||
* Create a new GithubUpdateCheck with the required information.
|
||||
* @param plugin The plugin to create it for (used for logging and checking version)
|
||||
* @param author The author of the plugin as used on Github
|
||||
* @param repository The repository name of the plugin on Github
|
||||
*/
|
||||
public GithubUpdateCheck(Plugin plugin, String author, String repository) {
|
||||
this.plugin = plugin;
|
||||
this.logger = plugin.getLogger();
|
||||
this.author = author;
|
||||
this.repository = repository;
|
||||
this.currentVersion = plugin.getDescription().getVersion();
|
||||
this.versionComparator = (latest, current) ->
|
||||
!latest.equalsIgnoreCase(current);
|
||||
|
||||
/**
|
||||
* Change the version comparator.
|
||||
*
|
||||
* @param versionComparator VersionComparator to use for checking if one version is newer than the other
|
||||
* @return this
|
||||
*/
|
||||
public GithubUpdateCheck withVersionComparator(VersionComparator versionComparator) {
|
||||
this.versionComparator = versionComparator;
|
||||
return this;
|
||||
}
|
||||
this.checking = false;
|
||||
this.error = false;
|
||||
this.hasUpdate = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an update is available.
|
||||
*/
|
||||
public void checkUpdate() {
|
||||
checkUpdate(null);
|
||||
}
|
||||
/**
|
||||
* Change the version comparator.
|
||||
* @param versionComparator VersionComparator to use for checking if one version is newer than the other
|
||||
* @return this
|
||||
*/
|
||||
public GithubUpdateCheck withVersionComparator(VersionComparator versionComparator) {
|
||||
this.versionComparator = versionComparator;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an update is available.
|
||||
*
|
||||
* @param callback Callback to execute when the update check is done
|
||||
* @return GithubUpdateCheck containing the status of the check
|
||||
*/
|
||||
public GithubUpdateCheck checkUpdate(UpdateCallback callback) {
|
||||
checking = true;
|
||||
final GithubUpdateCheck self = this;
|
||||
// Check for update on async thread
|
||||
Utils.newChain()
|
||||
.async(() -> {
|
||||
try {
|
||||
try {
|
||||
String rawUrl = API_HOST + "/" + author + "/" + repository + "/" + API_LATEST_RELEASE;
|
||||
url = new URL(rawUrl);
|
||||
} catch (MalformedURLException e) {
|
||||
logger.severe("Invalid url: '" + url + "', are the author '" + author + "' and repository '" + repository + "' correct?");
|
||||
error = true;
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Check if an update is available.
|
||||
*/
|
||||
public void checkUpdate() {
|
||||
checkUpdate(null);
|
||||
}
|
||||
|
||||
try {
|
||||
URLConnection conn = url.openConnection();
|
||||
// Give up after 15 seconds
|
||||
conn.setConnectTimeout(15000);
|
||||
// Identify ourselves
|
||||
conn.addRequestProperty("User-Agent", USER_AGENT);
|
||||
// Make sure we access the correct api version
|
||||
conn.addRequestProperty("Accept", "application/vnd.github.v3+json");
|
||||
// We want to read the result
|
||||
conn.setDoOutput(true);
|
||||
// Open connection
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
|
||||
String response = reader.readLine();
|
||||
debug("Response:", response);
|
||||
/**
|
||||
* Check if an update is available.
|
||||
* @param callback Callback to execute when the update check is done
|
||||
* @return GithubUpdateCheck containing the status of the check
|
||||
*/
|
||||
public GithubUpdateCheck checkUpdate(UpdateCallback callback) {
|
||||
checking = true;
|
||||
final GithubUpdateCheck self = this;
|
||||
// Check for update on asyn thread
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
try {
|
||||
String rawUrl = API_HOST + "/" + author + "/" + repository + "/" + API_LATEST_RELEASE;
|
||||
url = new URL(rawUrl);
|
||||
} catch(MalformedURLException e) {
|
||||
logger.severe("Invalid url: '" + url + "', are the author '" + author + "' and repository '" + repository + "' correct?");
|
||||
error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
JsonObject latestRelease = GSON.fromJson(response, JsonObject.class);
|
||||
try {
|
||||
URLConnection conn = url.openConnection();
|
||||
// Give up after 15 seconds
|
||||
conn.setConnectTimeout(15000);
|
||||
// Identify ourselves
|
||||
conn.addRequestProperty("User-Agent", USER_AGENT);
|
||||
// Make sure we access the correct api version
|
||||
conn.addRequestProperty("Accept", "application/vnd.github.v3+json");
|
||||
// We want to read the result
|
||||
conn.setDoOutput(true);
|
||||
// Open connection
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
|
||||
String response = reader.readLine();
|
||||
debug("Response:", response);
|
||||
|
||||
if (latestRelease.isJsonNull()) {
|
||||
logger.warning("Failed to get api response from " + url);
|
||||
error = true;
|
||||
return;
|
||||
}
|
||||
debug("json: " + latestRelease.getAsString());
|
||||
JSONObject latestRelease = (JSONObject)JSONValue.parse(response);
|
||||
|
||||
// Latest version
|
||||
latestVersion = latestRelease.get("tag_name").getAsString();
|
||||
debug("Tag name:", latestVersion);
|
||||
if(latestRelease.isEmpty()) {
|
||||
logger.warning("Failed to get api response from " + url);
|
||||
error = true;
|
||||
return;
|
||||
}
|
||||
debug("json: " + latestRelease.toJSONString());
|
||||
|
||||
// Current version
|
||||
debug("Plugin version:", currentVersion);
|
||||
// Latest version
|
||||
latestVersion = (String)latestRelease.get("tag_name");
|
||||
debug("Tag name:", latestVersion);
|
||||
|
||||
// Compare version
|
||||
hasUpdate = versionComparator.isNewer(latestVersion, currentVersion);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.severe("Failed to get latest release:" + ExceptionUtils
|
||||
.getStackTrace(e));
|
||||
error = true;
|
||||
} catch (ClassCastException e) {
|
||||
logger.info("Unexpected structure of the result, failed to parse it");
|
||||
error = true;
|
||||
}
|
||||
} finally {
|
||||
checking = false;
|
||||
debug("result:", self);
|
||||
}
|
||||
}
|
||||
).syncLast(x -> {
|
||||
if (callback != null) {
|
||||
callback.run(this);
|
||||
}
|
||||
}).execute();
|
||||
return this;
|
||||
}
|
||||
// Current version
|
||||
debug("Plugin version:", currentVersion);
|
||||
|
||||
/**
|
||||
* Check if an update check is running.
|
||||
*
|
||||
* @return true if an update check is running
|
||||
*/
|
||||
public boolean isChecking() {
|
||||
return checking;
|
||||
}
|
||||
// Compare version
|
||||
hasUpdate = versionComparator.isNewer(latestVersion, currentVersion);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
logger.severe("Failed to get latest release:" + ExceptionUtils.getStackTrace(e));
|
||||
error = true;
|
||||
} catch(ClassCastException e) {
|
||||
logger.info("Unexpected structure of the result, failed to parse it");
|
||||
error = true;
|
||||
}
|
||||
} finally {
|
||||
checking = false;
|
||||
debug("result:", self);
|
||||
if(callback != null) {
|
||||
// Switch back to main thread and call the callback
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callback.run(self);
|
||||
}
|
||||
}.runTask(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the update check failed.
|
||||
*
|
||||
* @return true if the update check failed (an error message has been logged)
|
||||
*/
|
||||
public boolean hasFailed() {
|
||||
return error;
|
||||
}
|
||||
/**
|
||||
* Check if an update check is running.
|
||||
* @return true if an update check is running
|
||||
*/
|
||||
public boolean isChecking() {
|
||||
return checking;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an update has been found.
|
||||
*
|
||||
* @return true if an update has been found
|
||||
*/
|
||||
public boolean hasUpdate() {
|
||||
return hasUpdate;
|
||||
}
|
||||
/**
|
||||
* Check if the update check failed.
|
||||
* @return true if the update check failed (an error message has been logged)
|
||||
*/
|
||||
public boolean hasFailed() {
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the repository that this update checker is checking.
|
||||
*
|
||||
* @return Used repository
|
||||
*/
|
||||
public String getRepository() {
|
||||
return repository;
|
||||
}
|
||||
/**
|
||||
* Check if an update has been found.
|
||||
* @return true if an update has been found
|
||||
*/
|
||||
public boolean hasUpdate() {
|
||||
return hasUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the author that this update checker is checking.
|
||||
*
|
||||
* @return Used author
|
||||
*/
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
/**
|
||||
* Get the repository that this update checker is checking.
|
||||
* @return Used repository
|
||||
*/
|
||||
public String getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current version.
|
||||
*
|
||||
* @return Current version of the plugin
|
||||
*/
|
||||
public String getCurrentVersion() {
|
||||
return currentVersion;
|
||||
}
|
||||
/**
|
||||
* Get the author that this update checker is checking.
|
||||
* @return Used author
|
||||
*/
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version.
|
||||
*
|
||||
* @return Latest version of the plugin (if checking is complete)
|
||||
*/
|
||||
public String getLatestVersion() {
|
||||
return latestVersion;
|
||||
}
|
||||
/**
|
||||
* Get the current version.
|
||||
* @return Current version of the plugin
|
||||
*/
|
||||
public String getCurrentVersion() {
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a debug message if DEBUG is enabled.
|
||||
*
|
||||
* @param message Message to print
|
||||
*/
|
||||
private void debug(Object... message) {
|
||||
if (DEBUG) {
|
||||
logger.info("[" + this.getClass().getSimpleName() + "] [DEBUG] " + StringUtils
|
||||
.join(message, " "));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the latest version.
|
||||
* @return Latest version of the plugin (if checking is complete)
|
||||
*/
|
||||
public String getLatestVersion() {
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GithubUpdateCheck(" + StringUtils.join(Arrays.asList(
|
||||
"author=" + author,
|
||||
"repository=" + repository,
|
||||
"plugin=" + plugin.getName(),
|
||||
"checking=" + checking,
|
||||
"hasUpdate=" + hasUpdate,
|
||||
"error=" + error,
|
||||
"currentVersion=" + currentVersion,
|
||||
"latestVersion=" + latestVersion
|
||||
), ", ") + ")";
|
||||
}
|
||||
public interface VersionComparator {
|
||||
/**
|
||||
* Check if a version should be considered 'newer' than another.
|
||||
* @param latestVersion Version that is available on Github
|
||||
* @param currentVersion Version of the current plugin
|
||||
* @return true if the latestVersion is newer than the localVersion, otherwise false
|
||||
*/
|
||||
boolean isNewer(String latestVersion, String currentVersion);
|
||||
}
|
||||
|
||||
public interface VersionComparator {
|
||||
/**
|
||||
* Check if a version should be considered 'newer' than another.
|
||||
*
|
||||
* @param latestVersion Version that is available on Github
|
||||
* @param currentVersion Version of the current plugin
|
||||
* @return true if the latestVersion is newer than the localVersion, otherwise false
|
||||
*/
|
||||
boolean isNewer(String latestVersion, String currentVersion);
|
||||
}
|
||||
public interface UpdateCallback {
|
||||
void run(GithubUpdateCheck result);
|
||||
}
|
||||
|
||||
public interface UpdateCallback {
|
||||
void run(GithubUpdateCheck result);
|
||||
}
|
||||
/**
|
||||
* Print a debug message if DEBUG is enabled.
|
||||
* @param message Message to print
|
||||
*/
|
||||
private void debug(Object... message) {
|
||||
if(DEBUG) {
|
||||
logger.info("[" + this.getClass().getSimpleName() + "] [DEBUG] " + StringUtils.join(message, " "));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GithubUpdateCheck(" + StringUtils.join(Arrays.asList(
|
||||
"author=" + author,
|
||||
"repository=" + repository,
|
||||
"plugin=" + plugin.getName(),
|
||||
"checking=" + checking,
|
||||
"hasUpdate=" + hasUpdate,
|
||||
"error=" + error,
|
||||
"currentVersion=" + currentVersion,
|
||||
"latestVersion=" + latestVersion
|
||||
), ", ") + ")";
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package me.wiefferink.areashop.tools;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -12,6 +11,52 @@ import java.util.List;
|
||||
public class Materials {
|
||||
|
||||
private Materials() {
|
||||
|
||||
}
|
||||
|
||||
private static final HashSet<String> WALL_SIGN_TYPES = new HashSet<>(Arrays.asList(
|
||||
// 1.14+ types
|
||||
"ACACIA_WALL_SIGN",
|
||||
"BIRCH_WALL_SIGN",
|
||||
"DARK_OAK_WALL_SIGN",
|
||||
"JUNGLE_WALL_SIGN",
|
||||
"OAK_WALL_SIGN",
|
||||
"SPRUCE_WALL_SIGN",
|
||||
|
||||
// Legacy types
|
||||
"LEGACY_WALL_SIGN",
|
||||
"WALL_SIGN"
|
||||
));
|
||||
private static final HashSet<String> FLOOR_SIGN_TYPES = new HashSet<>(Arrays.asList(
|
||||
// 1.14+ types
|
||||
"ACACIA_SIGN",
|
||||
"BIRCH_SIGN",
|
||||
"DARK_OAK_SIGN",
|
||||
"JUNGLE_SIGN",
|
||||
"OAK_SIGN",
|
||||
"SPRUCE_SIGN",
|
||||
|
||||
// Legacy types
|
||||
"LEGACY_SIGN",
|
||||
"LEGACY_SIGN_POST",
|
||||
"SIGN",
|
||||
"SIGN_POST"
|
||||
));
|
||||
|
||||
private static boolean legacyMaterials = false;
|
||||
|
||||
static {
|
||||
List<String> legacyMaterialVersions = Arrays.asList("1.7", "1.8", "1.9", "1.10", "1.11", "1.12");
|
||||
for(String legacyMaterialVersion : legacyMaterialVersions) {
|
||||
String version = Bukkit.getBukkitVersion();
|
||||
// Detects '1.8', '1.8.3', '1.8-pre1' style versions
|
||||
if(version.equals(legacyMaterialVersion)
|
||||
|| version.startsWith(legacyMaterialVersion + ".")
|
||||
|| version.startsWith(legacyMaterialVersion + "-")) {
|
||||
legacyMaterials = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,12 +69,46 @@ public class Materials {
|
||||
if (!isSign(name)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Material.matchMaterial(name);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
AreaShop.debug("Materials.get() null result:", name);
|
||||
return null;
|
||||
|
||||
Material result = null;
|
||||
if (legacyMaterials) {
|
||||
// 1.12 and lower just know SIGN_POST, WALL_SIGN and SIGN
|
||||
if (FLOOR_SIGN_TYPES.contains(name)) {
|
||||
result = Material.getMaterial("SIGN_POST");
|
||||
} else if (WALL_SIGN_TYPES.contains(name)) {
|
||||
result = Material.getMaterial("WALL_SIGN");
|
||||
if (result == null) {
|
||||
result = Material.getMaterial("SIGN");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Try saved name (works for wood types on 1.14, regular types for below)
|
||||
result = Material.getMaterial(name);
|
||||
if (result == null) {
|
||||
// Cases for 1.13, which don't know wood types, but need new materials
|
||||
if (FLOOR_SIGN_TYPES.contains(name)) {
|
||||
// SIGN -> OAK_SIGN for 1.14
|
||||
result = Material.getMaterial("OAK_SIGN");
|
||||
// Fallback for 1.13
|
||||
if (result == null) {
|
||||
result = Material.getMaterial("SIGN");
|
||||
}
|
||||
} else if (WALL_SIGN_TYPES.contains(name)) {
|
||||
// WALL_SIGN -> OAK_WALL_SIGN for 1.14
|
||||
result = Material.getMaterial("OAK_WALL_SIGN");
|
||||
// Fallback for 1.13
|
||||
if (result == null) {
|
||||
result = Material.getMaterial("WALL_SIGN");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
AreaShop.debug("Materials.get() null result:", name, "legacyMaterials:", legacyMaterials);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +117,7 @@ public class Materials {
|
||||
* @return true if the given material is a sign
|
||||
*/
|
||||
public static boolean isSign(Material material) {
|
||||
return Tag.SIGNS.isTagged(material) || Tag.WALL_SIGNS.isTagged(material);
|
||||
return isSign(material.name());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,12 +126,7 @@ public class Materials {
|
||||
* @return true if the given material is a sign
|
||||
*/
|
||||
public static boolean isSign(String name) {
|
||||
try {
|
||||
return isSign(Material.matchMaterial(name));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
AreaShop.debug("Invalid Material: " + name + " passed when performing sign check.");
|
||||
return false;
|
||||
}
|
||||
return name != null && (FLOOR_SIGN_TYPES.contains(name) || WALL_SIGN_TYPES.contains(name));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -156,8 +156,19 @@ public class Utils {
|
||||
*
|
||||
* @return Online players
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Collection<? extends Player> getOnlinePlayers() {
|
||||
return Bukkit.getOnlinePlayers();
|
||||
try {
|
||||
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
|
||||
if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
|
||||
return ((Collection<? extends Player>) onlinePlayerMethod.invoke(Bukkit.getServer()));
|
||||
} else {
|
||||
return Arrays.asList((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer()));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
AreaShop.debug("getOnlinePlayers error: " + ex.getMessage());
|
||||
}
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -723,7 +734,6 @@ public class Utils {
|
||||
* @param input The input to check
|
||||
* @return true if the input is numeric, otherwise false
|
||||
*/
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static boolean isNumeric(String input) {
|
||||
try {
|
||||
Integer.parseInt(input);
|
||||
@@ -739,7 +749,6 @@ public class Utils {
|
||||
* @param input The input
|
||||
* @return true if the input is a double, otherwise false
|
||||
*/
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static boolean isDouble(String input) {
|
||||
try {
|
||||
Double.parseDouble(input);
|
||||
@@ -817,15 +826,13 @@ public class Utils {
|
||||
* @return the name of the player
|
||||
*/
|
||||
public static String toName(UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return "";
|
||||
} else {
|
||||
if (uuid != null) {
|
||||
String name = Bukkit.getOfflinePlayer(uuid).getName();
|
||||
if (name != null) {
|
||||
return name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -854,20 +861,23 @@ public class Utils {
|
||||
|
||||
public static <E> CompletableFuture<?> runAsBatches(final Collection<E> objects, final int batchSize, final Consumer<E> task, final boolean async) {
|
||||
if (batchSize < 1) {
|
||||
throw new IllegalArgumentException("Invalid batch size!");
|
||||
throw new IllegalArgumentException("Invalid batch size: " + batchSize);
|
||||
}
|
||||
final Queue<E> cloned = new LinkedList<>(objects);
|
||||
final List<E> cloned = new ArrayList<>(objects);
|
||||
final CompletableFuture<Object> future = new CompletableFuture<>();
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
int lastIndex;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (cloned.isEmpty()) {
|
||||
future.complete(true);
|
||||
if (lastIndex >= cloned.size() - 1) {
|
||||
cancel();
|
||||
future.complete(true);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < batchSize && !cloned.isEmpty(); i++) {
|
||||
task.accept(cloned.remove());
|
||||
int index = Math.min(lastIndex + batchSize, cloned.size() - 1);
|
||||
for (; lastIndex < index; lastIndex++) {
|
||||
task.accept(cloned.get(lastIndex));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -343,6 +343,7 @@ destroy-successRent: "%lang:region% successfully deregistered as rental region."
|
||||
destroy-successBuy: "%lang:region% successfully deregistered as buy region."
|
||||
|
||||
teleport-help: "/as tp <region> [sign]."
|
||||
teleport-calculation-progress: "Teleport in progress, finding safe location %done%/%max% scans complete."
|
||||
teleport-noRentOrBuy: "The specified region is not registered: %0%."
|
||||
teleport-noPermission: "You don't have permission to teleport to your region."
|
||||
teleport-noPermissionOther: "You don't have permission to teleport to regions you do not own."
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: AreaShop
|
||||
main: me.wiefferink.areashop.AreaShop
|
||||
version: "@version@"
|
||||
version: "${project.version}"
|
||||
description: "Selling and renting WorldGuard regions to your players, highly configurable."
|
||||
depend: [Vault, WorldGuard, WorldEdit]
|
||||
softdepend: [Multiverse-Core, FastAsyncWorldEdit]
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = "me.wiefferink.areashop"
|
||||
version = '2.6.3'
|
||||
|
||||
subprojects {
|
||||
|
||||
plugins.apply('java')
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = 'paper-repo'
|
||||
url = uri('https://papermc.io/repo/repository/maven-public/')
|
||||
}
|
||||
maven {
|
||||
name = 'spigot-repo'
|
||||
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
|
||||
}
|
||||
maven {
|
||||
name = 'jitpack'
|
||||
url = uri('https://jitpack.io')
|
||||
content {
|
||||
includeGroupByRegex("com\\.github.*")
|
||||
}
|
||||
}
|
||||
maven {
|
||||
name = 'aikar-repo'
|
||||
url = uri('https://repo.aikar.co/content/groups/aikar/')
|
||||
}
|
||||
maven {
|
||||
name = 'enginehub-repo'
|
||||
url = uri('https://maven.enginehub.org/repo/')
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
tasks.withType(JavaCompile) {
|
||||
javaToolchains.compilerFor {
|
||||
JavaLanguageVersion.of(16)
|
||||
}
|
||||
options.release.set(16)
|
||||
options.encoding = 'UTF-8'
|
||||
options.fork = true
|
||||
options.deprecation = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
org.gradle.parallel=true
|
||||
org.gradle.java.installations.auto-download=false
|
||||
Vendored
BIN
Binary file not shown.
-5
@@ -1,5 +0,0 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -1,185 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## 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" "-Xms64m"'
|
||||
|
||||
# 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 or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; 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=`expr $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"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
-89
@@ -1,89 +0,0 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@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 Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@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" "-Xms64m"
|
||||
|
||||
@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 execute
|
||||
|
||||
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 execute
|
||||
|
||||
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
|
||||
|
||||
: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 %*
|
||||
|
||||
: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
|
||||
@@ -0,0 +1,53 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-fawe-1-15</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop FastAsyncWorldEdit 1.14+</name>
|
||||
<version>latest</version>
|
||||
|
||||
<parent>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>1.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>IS-Repo</id>
|
||||
<url>https://mvn.intellectualsites.com/content/repositories/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14.4-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.intellectualsites.fawe</groupId>
|
||||
<artifactId>FAWE-Bukkit</artifactId>
|
||||
<version>1.16-380</version> <!-- Equivalent to WE 7.0.2? -->
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<version>latest</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
+18
-24
@@ -1,10 +1,9 @@
|
||||
package me.wiefferink.areashop.handlers.fawe.v1_16;
|
||||
package me.wiefferink.areashop.handlers.fawe.v1_15;
|
||||
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.object.FaweLimit;
|
||||
import com.boydti.fawe.object.RelightMode;
|
||||
import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard;
|
||||
import com.boydti.fawe.util.EditSessionBuilder;
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
@@ -35,12 +34,7 @@ import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
@@ -97,11 +91,11 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
}
|
||||
if (file == null) {
|
||||
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName()
|
||||
+ ", schematic file does not exist: " + rawFile.getAbsolutePath());
|
||||
+ ", schematic file does not exist: " + rawFile.getAbsolutePath());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
pluginInterface.debugI("Trying to restore region", regionInterface.getName(), " from file",
|
||||
file.getAbsolutePath(), "with format", format.getName());
|
||||
file.getAbsolutePath(), "with format", format.getName());
|
||||
|
||||
com.sk89q.worldedit.world.World world = null;
|
||||
if (regionInterface.getName() != null) {
|
||||
@@ -116,14 +110,14 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
final CompletableFuture<Boolean> completableFuture = new CompletableFuture<>();
|
||||
final FaweLimit limit = new FaweLimit();
|
||||
limit.MAX_CHANGES = pluginInterface.getConfig().getInt("maximumBlocks");
|
||||
EditSession editSession = new EditSessionBuilder(world).limit(limit).relightMode(RelightMode.OPTIMAL).build();
|
||||
EditSession editSession = FaweAPI.getEditSessionBuilder(world).limit(limit).relightMode(RelightMode.OPTIMAL).build();
|
||||
editSession.setReorderMode(EditSession.ReorderMode.MULTI_STAGE);
|
||||
ProtectedRegion region = regionInterface.getRegion();
|
||||
final RegionType regionType = region.getType();
|
||||
// Get the origin and size of the region
|
||||
final BlockVector3 origin = BlockVector3
|
||||
.at(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(),
|
||||
region.getMinimumPoint().getBlockZ());
|
||||
region.getMinimumPoint().getBlockZ());
|
||||
final RegionBoundMask mask = new RegionBoundMask(region);
|
||||
final File finalFile = file;
|
||||
final String regionName = regionInterface.getName();
|
||||
@@ -149,7 +143,7 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
"schematic|region, x:" + clipboard.getDimensions().getX() + "|"
|
||||
+ regionWidth + ", y:" + clipboard.getDimensions().getY()
|
||||
+ "|" + regionHeight + ", z:" + clipboard.getDimensions()
|
||||
.getZ() + "|" + regionDepth);
|
||||
.getZ() + "|" + regionDepth);
|
||||
}
|
||||
clipboard.setOrigin(clipboard.getMinimumPoint());
|
||||
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard);
|
||||
@@ -161,7 +155,7 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
BlockTransformExtent extent = new BlockTransformExtent(clipboard);
|
||||
ForwardExtentCopy copy =
|
||||
new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(),
|
||||
editSession, origin);
|
||||
editSession, origin);
|
||||
copy.setTransform(clipboardHolder.getTransform());
|
||||
// Mask to region (for polygon and other weird shaped regions)
|
||||
// TODO make this more efficient (especially for polygon regions)
|
||||
@@ -183,7 +177,7 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
CompletableFuture.completedFuture(false);
|
||||
} catch (Exception e) {
|
||||
pluginInterface.getLogger()
|
||||
.warning("crashed during restore of " + regionInterface.getName());
|
||||
.warning("crashed during restore of " + regionInterface.getName());
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
|
||||
CompletableFuture.completedFuture(false);
|
||||
}
|
||||
@@ -207,7 +201,7 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
|
||||
file = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
|
||||
pluginInterface.debugI("Trying to save region", regionInterface.getName(), " to file",
|
||||
file.getAbsolutePath(), "with format", format.getName());
|
||||
file.getAbsolutePath(), "with format", format.getName());
|
||||
com.sk89q.worldedit.world.World world = null;
|
||||
if (regionInterface.getWorld() != null) {
|
||||
world = BukkitAdapter.adapt(regionInterface.getWorld());
|
||||
@@ -220,7 +214,7 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
}
|
||||
final FaweLimit limit = new FaweLimit();
|
||||
limit.MAX_CHANGES = pluginInterface.getConfig().getInt("maximumBlocks");
|
||||
EditSession editSession = new EditSessionBuilder(world).relightMode(RelightMode.OPTIMAL).limit(limit).build();
|
||||
EditSession editSession = FaweAPI.getEditSessionBuilder(world).relightMode(RelightMode.OPTIMAL).limit(limit).build();
|
||||
|
||||
final ProtectedRegion region = regionInterface.getRegion();
|
||||
final BlockVector3 min = region.getMinimumPoint(), max = region.getMaximumPoint();
|
||||
@@ -235,8 +229,8 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
Clipboard clipboard = new MemoryOptimizedClipboard(selection);
|
||||
clipboard.setOrigin(min);
|
||||
ForwardExtentCopy copy = new ForwardExtentCopy(editSession,
|
||||
selection.clone(), clipboard,
|
||||
min);
|
||||
selection.clone(), clipboard,
|
||||
min);
|
||||
try {
|
||||
Operations.completeLegacy(copy);
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
@@ -260,9 +254,9 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
completableFuture.complete(false);
|
||||
} catch (Exception e) {
|
||||
pluginInterface.getLogger()
|
||||
.warning("Crashed during save of " + regionName);
|
||||
.warning("Crashed during save of " + regionName);
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
|
||||
completableFuture.complete(false);
|
||||
completableFuture.complete(false);
|
||||
}
|
||||
completableFuture.complete(true);
|
||||
});
|
||||
@@ -278,10 +272,10 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
public WorldEditSelection getPlayerSelection(Player player) {
|
||||
try {
|
||||
Region region = pluginInterface.getWorldEdit().getSession(player)
|
||||
.getSelection(BukkitAdapter.adapt(player.getWorld()));
|
||||
.getSelection(BukkitAdapter.adapt(player.getWorld()));
|
||||
return new WorldEditSelection(player.getWorld(),
|
||||
BukkitAdapter.adapt(player.getWorld(), region.getMinimumPoint()),
|
||||
BukkitAdapter.adapt(player.getWorld(), region.getMaximumPoint()));
|
||||
BukkitAdapter.adapt(player.getWorld(), region.getMinimumPoint()),
|
||||
BukkitAdapter.adapt(player.getWorld(), region.getMaximumPoint()));
|
||||
} catch (IncompleteRegionException e) {
|
||||
return null;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
repositories {
|
||||
maven {
|
||||
name = 'IS-Repo'
|
||||
url = uri('https://mvn.intellectualsites.com/content/repositories/releases/')
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly project(':areashop-interface')
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly ('com.intellectualsites.fawe:FAWE-Core:1.16-725')
|
||||
compileOnly ('com.intellectualsites.fawe:FAWE-Bukkit:1.16-725')
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.5'
|
||||
}
|
||||
|
||||
description = 'AreaShop FastAsyncWorldEdit 1.16'
|
||||
@@ -1,16 +0,0 @@
|
||||
repositories {
|
||||
maven {
|
||||
name = 'IS-Repo'
|
||||
url = uri('https://mvn.intellectualsites.com/content/repositories/releases/')
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly project(':areashop-interface')
|
||||
compileOnly('org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT')
|
||||
compileOnly("com.fastasyncworldedit:FAWE-Core:1.17-5")
|
||||
compileOnly("com.fastasyncworldedit:FAWE-Bukkit:1.17-5")
|
||||
compileOnly('com.sk89q.worldguard:worldguard-bukkit:7.0.5')
|
||||
}
|
||||
|
||||
description = 'AreaShop FastAsyncWorldEdit 1.17'
|
||||
-289
@@ -1,289 +0,0 @@
|
||||
package me.wiefferink.areashop.handlers.fawe.v1_17;
|
||||
|
||||
import com.fastasyncworldedit.core.FaweAPI;
|
||||
import com.fastasyncworldedit.core.object.FaweLimit;
|
||||
import com.fastasyncworldedit.core.object.RelightMode;
|
||||
import com.fastasyncworldedit.core.object.clipboard.MemoryOptimizedClipboard;
|
||||
import com.fastasyncworldedit.core.util.EditSessionBuilder;
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.*;
|
||||
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Mask2D;
|
||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.util.io.Closer;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionType;
|
||||
import me.wiefferink.areashop.interfaces.AreaShopInterface;
|
||||
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
// Future: this class could use the schematic save/paste api of FAWE: https://github.com/boy0001/FastAsyncWorldedit/wiki/Pasting-a-schematic
|
||||
// This would not allow for shaping the schematic to a polygon region though
|
||||
public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
|
||||
public FastAsyncWorldEditHandler(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
private static class RegionBoundMask implements Mask {
|
||||
|
||||
private final BoundingBox boundingBox;
|
||||
|
||||
public RegionBoundMask(final ProtectedRegion region) {
|
||||
final BlockVector3 min = region.getMinimumPoint(), max = region.getMaximumPoint();
|
||||
this.boundingBox = new BoundingBox(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ());
|
||||
}
|
||||
|
||||
public RegionBoundMask(final BoundingBox boundingBox) {
|
||||
this.boundingBox = boundingBox.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return boundingBox.contains(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask copy() {
|
||||
return new RegionBoundMask(boundingBox);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Beta
|
||||
public CompletableFuture<Boolean> restoreRegionBlocksAsync(File rawFile, GeneralRegionInterface regionInterface) {
|
||||
File file = null;
|
||||
ClipboardFormat format = null;
|
||||
for (ClipboardFormat formatOption : BuiltInClipboardFormat.values()) {
|
||||
if (new File(rawFile.getAbsolutePath() + "." + formatOption.getPrimaryFileExtension())
|
||||
.exists()) {
|
||||
file = new File(
|
||||
rawFile.getAbsolutePath() + "." + formatOption.getPrimaryFileExtension());
|
||||
format = formatOption;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (file == null) {
|
||||
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName()
|
||||
+ ", schematic file does not exist: " + rawFile.getAbsolutePath());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
pluginInterface.debugI("Trying to restore region", regionInterface.getName(), " from file",
|
||||
file.getAbsolutePath(), "with format", format.getName());
|
||||
|
||||
com.sk89q.worldedit.world.World world = null;
|
||||
if (regionInterface.getName() != null) {
|
||||
world = BukkitAdapter.adapt(regionInterface.getWorld());
|
||||
}
|
||||
if (world == null) {
|
||||
pluginInterface.getLogger().info(
|
||||
"Did not restore region " + regionInterface.getName() + ", world not found: "
|
||||
+ regionInterface.getWorldName());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
final CompletableFuture<Boolean> completableFuture = new CompletableFuture<>();
|
||||
final FaweLimit limit = new FaweLimit();
|
||||
limit.MAX_CHANGES = pluginInterface.getConfig().getInt("maximumBlocks");
|
||||
EditSession editSession = new EditSessionBuilder(world).limit(limit).relightMode(RelightMode.OPTIMAL).build();
|
||||
editSession.setReorderMode(EditSession.ReorderMode.MULTI_STAGE);
|
||||
ProtectedRegion region = regionInterface.getRegion();
|
||||
final RegionType regionType = region.getType();
|
||||
// Get the origin and size of the region
|
||||
final BlockVector3 origin = BlockVector3
|
||||
.at(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(),
|
||||
region.getMinimumPoint().getBlockZ());
|
||||
final RegionBoundMask mask = new RegionBoundMask(region);
|
||||
final File finalFile = file;
|
||||
final String regionName = regionInterface.getName();
|
||||
final double regionWidth = regionInterface.getWidth(), regionHeight = regionInterface.getHeight(), regionDepth = regionInterface.getDepth();
|
||||
final LocalSession session =
|
||||
new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
|
||||
FaweAPI.getTaskManager().async(() -> {
|
||||
// Read the schematic and paste it into the world
|
||||
try (Closer closer = Closer.create()) {
|
||||
FileInputStream fis = closer.register(new FileInputStream(finalFile));
|
||||
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
|
||||
NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(bis));
|
||||
ClipboardReader reader = new FastSchematicReader(nbtStream);
|
||||
|
||||
Clipboard clipboard = reader.read();
|
||||
if (clipboard.getDimensions().getY() != regionHeight
|
||||
|| clipboard.getDimensions().getX() != regionWidth
|
||||
|| clipboard.getDimensions().getZ() != regionDepth) {
|
||||
pluginInterface.getLogger().warning(
|
||||
"Size of the region " + regionName
|
||||
+ " is not the same as the schematic to restore!");
|
||||
pluginInterface.debugI(
|
||||
"schematic|region, x:" + clipboard.getDimensions().getX() + "|"
|
||||
+ regionWidth + ", y:" + clipboard.getDimensions().getY()
|
||||
+ "|" + regionHeight + ", z:" + clipboard.getDimensions()
|
||||
.getZ() + "|" + regionDepth);
|
||||
}
|
||||
clipboard.setOrigin(clipboard.getMinimumPoint());
|
||||
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard);
|
||||
session.setBlockChangeLimit(limit.MAX_CHANGES);
|
||||
session.setClipboard(clipboardHolder);
|
||||
|
||||
// Build operation
|
||||
|
||||
BlockTransformExtent extent = new BlockTransformExtent(clipboard);
|
||||
ForwardExtentCopy copy =
|
||||
new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(),
|
||||
editSession, origin);
|
||||
copy.setTransform(clipboardHolder.getTransform());
|
||||
// Mask to region (for polygon and other weird shaped regions)
|
||||
// TODO make this more efficient (especially for polygon regions)
|
||||
if (regionType != RegionType.CUBOID) {
|
||||
copy.setSourceMask(mask);
|
||||
}
|
||||
Operations.completeLegacy(copy);
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
pluginInterface.getLogger().warning(
|
||||
"exceeded the block limit while restoring schematic of " + regionInterface.getName()
|
||||
+ ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: "
|
||||
+ pluginInterface.getConfig().getInt("maximumBlocks"));
|
||||
CompletableFuture.completedFuture(false);
|
||||
} catch (IOException e) {
|
||||
pluginInterface.getLogger().warning(
|
||||
"An error occured while restoring schematic of " + regionInterface.getName()
|
||||
+ ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
|
||||
CompletableFuture.completedFuture(false);
|
||||
} catch (Exception e) {
|
||||
pluginInterface.getLogger()
|
||||
.warning("crashed during restore of " + regionInterface.getName());
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
|
||||
CompletableFuture.completedFuture(false);
|
||||
}
|
||||
editSession.flushQueue();
|
||||
CompletableFuture.completedFuture(true);
|
||||
});
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restoreRegionBlocks(File rawFile, GeneralRegionInterface regionInterface) {
|
||||
return restoreRegionBlocksAsync(rawFile, regionInterface).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Beta
|
||||
public CompletableFuture<Boolean> saveRegionBlocksAsync(File file, GeneralRegionInterface regionInterface) {
|
||||
// TODO implement using the FastAsyncWorldEdit api to save async
|
||||
ClipboardFormat format = BuiltInClipboardFormat.MINECRAFT_STRUCTURE;
|
||||
// TODO allow selecting FAWE format in the config? (when enabled you cannot go back to vanilla WorldEdit easily)
|
||||
|
||||
file = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
|
||||
pluginInterface.debugI("Trying to save region", regionInterface.getName(), " to file",
|
||||
file.getAbsolutePath(), "with format", format.getName());
|
||||
com.sk89q.worldedit.world.World world = null;
|
||||
if (regionInterface.getWorld() != null) {
|
||||
world = BukkitAdapter.adapt(regionInterface.getWorld());
|
||||
}
|
||||
if (world == null) {
|
||||
pluginInterface.getLogger().warning(
|
||||
"Did not save region " + regionInterface.getName() + ", world not found: "
|
||||
+ regionInterface.getWorldName());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
final FaweLimit limit = new FaweLimit();
|
||||
limit.MAX_CHANGES = pluginInterface.getConfig().getInt("maximumBlocks");
|
||||
EditSession editSession = new EditSessionBuilder(world).relightMode(RelightMode.OPTIMAL).limit(limit).build();
|
||||
|
||||
final ProtectedRegion region = regionInterface.getRegion();
|
||||
final BlockVector3 min = region.getMinimumPoint(), max = region.getMaximumPoint();
|
||||
final String regionName = regionInterface.getName();
|
||||
final World finalWorld = world;
|
||||
final CompletableFuture<Boolean> completableFuture = new CompletableFuture<>();
|
||||
final File finalFile = file;
|
||||
FaweAPI.getTaskManager().async(() -> {
|
||||
// Create a clipboard
|
||||
CuboidRegion selection =
|
||||
new CuboidRegion(finalWorld, min, max);
|
||||
Clipboard clipboard = new MemoryOptimizedClipboard(selection);
|
||||
clipboard.setOrigin(min);
|
||||
ForwardExtentCopy copy = new ForwardExtentCopy(editSession,
|
||||
selection.clone(), clipboard,
|
||||
min);
|
||||
try {
|
||||
Operations.completeLegacy(copy);
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
pluginInterface.getLogger().warning(
|
||||
"Exceeded the block limit while saving schematic of " + regionName
|
||||
+ ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: "
|
||||
+ pluginInterface.getConfig().getInt("maximumBlocks"));
|
||||
completableFuture.complete(false);
|
||||
}
|
||||
|
||||
try (Closer closer = Closer.create()) {
|
||||
FileOutputStream fos = closer.register(new FileOutputStream(finalFile));
|
||||
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
|
||||
ClipboardWriter writer = closer.register(format.getWriter(bos));
|
||||
writer.write(clipboard);
|
||||
} catch (IOException e) {
|
||||
pluginInterface.getLogger().warning(
|
||||
"An error occured while saving schematic of " + regionName
|
||||
+ ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
|
||||
completableFuture.complete(false);
|
||||
} catch (Exception e) {
|
||||
pluginInterface.getLogger()
|
||||
.warning("Crashed during save of " + regionName);
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
|
||||
completableFuture.complete(false);
|
||||
}
|
||||
completableFuture.complete(true);
|
||||
});
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
|
||||
return saveRegionBlocksAsync(file, regionInterface).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldEditSelection getPlayerSelection(Player player) {
|
||||
try {
|
||||
Region region = pluginInterface.getWorldEdit().getSession(player)
|
||||
.getSelection(BukkitAdapter.adapt(player.getWorld()));
|
||||
return new WorldEditSelection(player.getWorld(),
|
||||
BukkitAdapter.adapt(player.getWorld(), region.getMinimumPoint()),
|
||||
BukkitAdapter.adapt(player.getWorld(), region.getMaximumPoint()));
|
||||
} catch (IncompleteRegionException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.2.5-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.5'
|
||||
}
|
||||
|
||||
description = 'AreaShop Interface'
|
||||
@@ -0,0 +1,38 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop Interface</name>
|
||||
<version>latest</version>
|
||||
|
||||
<parent>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>1.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.1.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package me.wiefferink.areashop.interfaces;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public interface BlockBehaviourHelper {
|
||||
|
||||
default boolean canPlace(Location location, Material material) {
|
||||
return canPlace(location, material.createBlockData());
|
||||
}
|
||||
|
||||
boolean canPlace(Location location, BlockData blockData);
|
||||
|
||||
/**
|
||||
* Check if a sign is valid.
|
||||
*
|
||||
* @param block The block
|
||||
* @return Returns true if the sign can exist in that location, false otherwise.
|
||||
*/
|
||||
boolean isBlockValid(Block block);
|
||||
|
||||
boolean isBlockStateValid(BlockState blockState);
|
||||
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package me.wiefferink.areashop.interfaces;
|
||||
|
||||
public interface NMS {
|
||||
|
||||
BlockBehaviourHelper behaviourHelper();
|
||||
|
||||
}
|
||||
+2
-2
@@ -51,9 +51,9 @@ public class RegionAccessSet {
|
||||
* Get this access set as a list of player UUIDs.
|
||||
* @return List of player UUIDs, first players already added by UUID, then players added by name, groups are not in the list
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public List<UUID> asUniqueIdList() {
|
||||
List<UUID> result = new ArrayList<>(playerUniqueIds);
|
||||
List<UUID> result = new ArrayList<>();
|
||||
result.addAll(playerUniqueIds);
|
||||
for(String playerName : playerNames) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName);
|
||||
if (offlinePlayer.hasPlayedBefore()) {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ public class WorldEditSelection {
|
||||
private final Location maximum;
|
||||
|
||||
/**
|
||||
* Create a WorldEditSelection.
|
||||
* Craete a WorldEditSelection.
|
||||
* @param world World the selection is in
|
||||
* @param a Primary selection location
|
||||
* @param b Secondary selection location
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly project(':areashop-interface')
|
||||
compileOnly 'org.spigotmc:spigot:1.16.5-R0.1-SNAPSHOT'
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package me.wiefferink.areashop.nms.v1_16_R3;
|
||||
|
||||
import me.wiefferink.areashop.interfaces.BlockBehaviourHelper;
|
||||
import net.minecraft.server.v1_16_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_16_R3.IBlockData;
|
||||
import net.minecraft.server.v1_16_R3.World;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockBehaviourHelperImpl implements BlockBehaviourHelper {
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Location location, BlockData blockData) {
|
||||
Objects.requireNonNull(location.getWorld(), "Null World!");
|
||||
final BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
|
||||
final CraftWorld craftWorld = (CraftWorld) location.getWorld();
|
||||
final World world = craftWorld.getHandle();
|
||||
final CraftBlockData craftBlockData = (CraftBlockData) blockData;
|
||||
final IBlockData ibd = craftBlockData.getState();
|
||||
return ibd.canPlace(world, blockPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockValid(Block block) {
|
||||
final CraftBlock craftBlock = (CraftBlock) block;
|
||||
final CraftWorld craftWorld = (CraftWorld) craftBlock.getWorld();
|
||||
final World world = craftWorld.getHandle();
|
||||
final IBlockData ibd = craftBlock.getNMS();
|
||||
return ibd.canPlace(world, craftBlock.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockStateValid(BlockState blockState) {
|
||||
final CraftBlockState craftBlockState = (CraftBlockState) blockState;
|
||||
final IBlockData ibd = craftBlockState.getHandle();
|
||||
return ibd.canPlace(craftBlockState.getBlock().getCraftWorld().getHandle(), craftBlockState.getPosition());
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package me.wiefferink.areashop.nms.v1_16_R3;
|
||||
|
||||
import me.wiefferink.areashop.interfaces.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.interfaces.NMS;
|
||||
|
||||
public final class NMSImpl implements NMS {
|
||||
|
||||
private BlockBehaviourHelper signHelper = new BlockBehaviourHelperImpl();
|
||||
|
||||
@Override
|
||||
public BlockBehaviourHelper behaviourHelper() {
|
||||
return this.signHelper;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly project(':areashop-interface')
|
||||
compileOnly 'org.spigotmc:spigot:1.17-R0.1-SNAPSHOT'
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package me.wiefferink.areashop.nms.v1_17_R1;
|
||||
|
||||
import me.wiefferink.areashop.interfaces.BlockBehaviourHelper;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockBehaviourHelperImpl implements BlockBehaviourHelper {
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Location location, BlockData blockData) {
|
||||
Objects.requireNonNull(location.getWorld(), "Null World!");
|
||||
final BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
|
||||
final CraftWorld craftWorld = (CraftWorld) location.getWorld();
|
||||
final World world = craftWorld.getHandle();
|
||||
final CraftBlockData craftBlockData = (CraftBlockData) blockData;
|
||||
final IBlockData ibd = craftBlockData.getState();
|
||||
return ibd.canPlace(world, blockPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockValid(Block block) {
|
||||
final CraftBlock craftBlock = (CraftBlock) block;
|
||||
final CraftWorld craftWorld = (CraftWorld) craftBlock.getWorld();
|
||||
final World world = craftWorld.getHandle();
|
||||
final IBlockData ibd = craftBlock.getNMS();
|
||||
return ibd.canPlace(world, craftBlock.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockStateValid(BlockState blockState) {
|
||||
final CraftBlockState craftBlockState = (CraftBlockState) blockState;
|
||||
final IBlockData ibd = craftBlockState.getHandle();
|
||||
return ibd.canPlace(craftBlockState.getBlock().getCraftWorld().getHandle(), craftBlockState.getPosition());
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package me.wiefferink.areashop.nms.v1_17_R1;
|
||||
|
||||
import me.wiefferink.areashop.interfaces.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.interfaces.NMS;
|
||||
|
||||
public final class NMSImpl implements NMS {
|
||||
|
||||
private BlockBehaviourHelper signHelper = new BlockBehaviourHelperImpl();
|
||||
|
||||
@Override
|
||||
public BlockBehaviourHelper behaviourHelper() {
|
||||
return this.signHelper;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
dependencies {
|
||||
implementation project(':areashop-interface')
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.2.5'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.5'
|
||||
}
|
||||
|
||||
description = 'AreaShop WorldEdit 7'
|
||||
@@ -0,0 +1,52 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-worldedit-7</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop WorldEdit 7</name>
|
||||
<version>latest</version>
|
||||
|
||||
<description>
|
||||
World Edit compatibility handler
|
||||
- Deprecated usages on 7.2.0
|
||||
- Compiles against 7.0.1, 7.1.0-SNAPSHOT, 7.2.0-SNAPSHOT
|
||||
</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>1.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.4-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<version>latest</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+12
-24
@@ -46,14 +46,7 @@ public class WorldEditHandler extends WorldEditInterface {
|
||||
@Override
|
||||
public WorldEditSelection getPlayerSelection(Player player) {
|
||||
try {
|
||||
final LocalSession session = pluginInterface.getWorldEdit().getSession(player);
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
Region region = session.getSelection(BukkitAdapter.adapt(player.getWorld()));
|
||||
if (region == null) {
|
||||
return null;
|
||||
}
|
||||
Region region = pluginInterface.getWorldEdit().getSession(player).getSelection(BukkitAdapter.adapt(player.getWorld()));
|
||||
return new WorldEditSelection(
|
||||
player.getWorld(),
|
||||
BukkitAdapter.adapt(player.getWorld(), region.getMinimumPoint()),
|
||||
@@ -91,21 +84,18 @@ public class WorldEditHandler extends WorldEditInterface {
|
||||
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
|
||||
return false;
|
||||
}
|
||||
EditSession editSession = pluginInterface.getWorldEdit()
|
||||
.getWorldEdit()
|
||||
.newEditSessionBuilder()
|
||||
.world(world)
|
||||
.maxBlocks(pluginInterface.getConfig().getInt("maximumBlocks"))
|
||||
.build();
|
||||
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit() // WARNING Deprecated in 7.2.0!
|
||||
.getEditSessionFactory()
|
||||
.getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
|
||||
ProtectedRegion region = regionInterface.getRegion();
|
||||
// Get the origin and size of the region
|
||||
BlockVector3 origin = BlockVector3.at(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
|
||||
|
||||
// Read the schematic and paste it into the world
|
||||
try(Closer closer = Closer.create();
|
||||
try(Closer closer = Closer.create()) {
|
||||
FileInputStream fis = closer.register(new FileInputStream(file));
|
||||
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
|
||||
ClipboardReader reader = format.getReader(bis)) {
|
||||
ClipboardReader reader = format.getReader(bis);
|
||||
|
||||
//WorldData worldData = world.getWorldData();
|
||||
LocalSession session = new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
|
||||
@@ -182,12 +172,9 @@ public class WorldEditHandler extends WorldEditInterface {
|
||||
pluginInterface.getLogger().warning("Did not save region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
|
||||
return false;
|
||||
}
|
||||
EditSession editSession = pluginInterface.getWorldEdit()
|
||||
.getWorldEdit()
|
||||
.newEditSessionBuilder()
|
||||
.world(world)
|
||||
.maxBlocks(pluginInterface.getConfig().getInt("maximumBlocks"))
|
||||
.build();
|
||||
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit() // WARNING Deprecated in 7.2.0!
|
||||
.getEditSessionFactory()
|
||||
.getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
|
||||
|
||||
// Create a clipboard
|
||||
CuboidRegion selection = new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint());
|
||||
@@ -201,9 +188,10 @@ public class WorldEditHandler extends WorldEditInterface {
|
||||
return false;
|
||||
}
|
||||
|
||||
try(Closer closer = Closer.create(); FileOutputStream fos = closer.register(new FileOutputStream(file));
|
||||
try(Closer closer = Closer.create()) {
|
||||
FileOutputStream fos = closer.register(new FileOutputStream(file));
|
||||
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
|
||||
ClipboardWriter writer = closer.register(format.getWriter(bos));) {
|
||||
ClipboardWriter writer = closer.register(format.getWriter(bos));
|
||||
writer.write(clipboard);
|
||||
} catch(IOException e) {
|
||||
pluginInterface.getLogger().warning("An error occured while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
dependencies {
|
||||
implementation project(':areashop-interface')
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.2.5'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.5'
|
||||
}
|
||||
|
||||
description = 'AreaShop WorldGuard 7'
|
||||
@@ -0,0 +1,47 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-worldguard-7</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop WorldGuard 7</name>
|
||||
<version>latest</version>
|
||||
|
||||
<parent>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>1.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<scope>provided</scope>
|
||||
<version>7.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.4-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<version>latest</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.wiefferink</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0</version>
|
||||
<name>AreaShop Parent</name>
|
||||
<url>https://github.com/NLthijs48/AreaShop</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU General Public License v3.0</name>
|
||||
<url>https://www.gnu.org/licenses/gpl-3.0.en.html</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<issueManagement>
|
||||
<url>https://github.com/NLthijs48/AreaShop/issues</url>
|
||||
<system>GitHub Issues</system>
|
||||
</issueManagement>
|
||||
|
||||
<ciManagement>
|
||||
<system>Jenkins</system>
|
||||
<url>http://jenkins.wiefferink.me/job/AreaShop</url>
|
||||
</ciManagement>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>wiefferink-repo</id>
|
||||
<url>http://maven.wiefferink.me</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bstats-repo</id>
|
||||
<url>http://repo.bstats.org/content/repositories/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>mvn-repo</id>
|
||||
<url>https://mvnrepository.com/artifact/org.bstats/bstats-bukkit</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<!--build.number>#CUSTOM</build.number-->
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>hooks/areashop-interface</module>
|
||||
|
||||
<!-- FAWE Compat -->
|
||||
<module>hooks/areashop-fawe-1-15</module>
|
||||
|
||||
<!-- World Edit Compat -->
|
||||
<module>hooks/areashop-worldedit-7</module>
|
||||
|
||||
|
||||
<!-- World Guard Compat -->
|
||||
<module>hooks/areashop-worldguard-7</module>
|
||||
|
||||
<module>AreaShop</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<!--plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.puppycrawl.tools</groupId>
|
||||
<artifactId>checkstyle</artifactId>
|
||||
<version>8.29</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>validate</id>
|
||||
<phase>validate</phase>
|
||||
<configuration>
|
||||
<configLocation>config/checkstyle.xml</configLocation>
|
||||
<suppressionsLocation>config/checkstyle-suppressions.xml</suppressionsLocation>
|
||||
<suppressionsFileExpression>config/checkstyle.suppressions.file
|
||||
</suppressionsFileExpression>
|
||||
<encoding>UTF-8</encoding>
|
||||
<consoleOutput>true</consoleOutput>
|
||||
<failsOnError>true</failsOnError>
|
||||
<violationSeverity>error</violationSeverity>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins-->
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,17 +0,0 @@
|
||||
rootProject.name = 'areashop-parent'
|
||||
include(':areashop-worldguard-7')
|
||||
include(':areashop-interface')
|
||||
include(':areashop-fawe-1-16')
|
||||
include(':areashop-fawe-1-17')
|
||||
include(':areashop-worldedit-7')
|
||||
include(':areashop-nms-1-16-5')
|
||||
include(':areashop-nms-1-17')
|
||||
include(':areashop')
|
||||
project(":areashop-worldguard-7").projectDir = file('hooks/areashop-worldguard-7')
|
||||
project(":areashop-interface").projectDir = file('hooks/areashop-interface')
|
||||
project(":areashop-fawe-1-16").projectDir = file('hooks/areashop-fawe-1-16')
|
||||
project(":areashop-fawe-1-17").projectDir = file('hooks/areashop-fawe-1-17')
|
||||
project(":areashop-worldedit-7").projectDir = file('hooks/areashop-worldedit-7')
|
||||
project(":areashop-nms-1-16-5").projectDir = file('hooks/areashop-nms-1-16-5')
|
||||
project(":areashop-nms-1-17").projectDir = file('hooks/areashop-nms-1-17')
|
||||
project(":areashop").projectDir = file('AreaShop')
|
||||
Reference in new issue
Block a user