mirror of
https://github.com/md5sha256/AreaShop.git
synced 2026-11-07 01:42:34 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e18fe99161 | ||
|
|
bdc9e32c13 | ||
|
|
9a46d5ae3b | ||
|
|
6795fc43d9 | ||
|
|
dd9bd2c434 | ||
|
|
9438166180 | ||
|
|
9e06b9f268 | ||
|
|
4562bf23f6 | ||
|
|
24edb01754 | ||
|
|
2739bf6ad4 | ||
|
|
2ce84186ab | ||
|
|
279fa001ea | ||
|
|
b56d5320a6 | ||
|
|
30665908b9 | ||
|
|
0fd384833a | ||
|
|
09634de4bf | ||
|
|
7fafee82a7 | ||
|
|
2899b2978c | ||
|
|
7afcba79c9 | ||
|
|
72084b38f8 | ||
|
|
6a291feedd | ||
|
|
b85566882c | ||
|
|
c14407e14b | ||
|
|
ae9bd60d1b | ||
|
|
c689c2fae0 | ||
|
|
728cfb6dfa | ||
|
|
3abb6c06e4 | ||
|
|
51c11738af | ||
|
|
172b5a99f1 | ||
|
|
4c5d025e54 | ||
|
|
e93a2d04de | ||
|
|
af5980d555 | ||
|
|
3f7249f4a1 | ||
|
|
73c6fc858e | ||
|
|
360c3e7e21 | ||
|
|
73d0115b78 | ||
|
|
baf7eaabf1 | ||
|
|
ca8c0487a8 | ||
|
|
24156a03c4 | ||
|
|
ec677766d2 | ||
|
|
ef6c8fbf9d | ||
|
|
4f52fe9e6e | ||
|
|
3ebe5a6fa9 | ||
|
|
3cebe5d2c7 | ||
|
|
c76415c4f3 | ||
|
|
b7bc02aef3 | ||
|
|
d75094e191 | ||
|
|
4045914b48 | ||
|
|
1fac002ee0 | ||
|
|
64301e74e0 | ||
|
|
5a5a7fc5ef | ||
|
|
b928caf0c2 | ||
|
|
111f629787 | ||
|
|
718474ca95 | ||
|
|
93b9df3e54 | ||
|
|
bad983a0b8 | ||
|
|
e2c8b06b68 | ||
|
|
7249e39c02 | ||
|
|
9d9a58a170 | ||
|
|
e64e884c2a | ||
|
|
6ad4ff9deb | ||
|
|
eec9806492 | ||
|
|
43b2ae8278 | ||
|
|
6d5a92e389 | ||
|
|
7d7a62ffa0 | ||
|
|
44456d87b6 | ||
|
|
d92c710b27 | ||
|
|
3dceaf98cd | ||
|
|
33c29a3756 | ||
|
|
771734360f | ||
|
|
539e908d32 | ||
|
|
088471aa3c | ||
|
|
5a95c95670 | ||
|
|
5a5d627d51 | ||
|
|
9b5434a4b2 | ||
|
|
e13717950b |
No files matched your search
@@ -0,0 +1,23 @@
|
||||
name: Java CI with Gradle
|
||||
|
||||
on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Only run on PRs if the source branch is on someone else's repo
|
||||
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: ["ubuntu-latest", "windows-latest"]
|
||||
runs-on: "${{ matrix.os }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: gradle/wrapper-validation-action@v1.0.4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'zulu'
|
||||
cache: 'gradle'
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew clean build
|
||||
+20
-37
@@ -1,13 +1,11 @@
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/macos,windows,intellij,maven,gradle
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,windows,intellij,maven,gradle
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,maven
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,windows,intellij+all,gradle,maven
|
||||
|
||||
### Intellij ###
|
||||
### Intellij+all ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
.idea/**
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
@@ -68,6 +66,9 @@ atlassian-ide-plugin.xml
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
@@ -80,35 +81,21 @@ fabric.properties
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
### Intellij+all Patch ###
|
||||
# Ignores the whole .idea folder and all .iml files
|
||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
.idea/*
|
||||
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||
.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||
.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||
.idea/**/markdown-navigator.xml
|
||||
.idea/**/markdown-navigator-enh.xml
|
||||
.idea/**/markdown-navigator/
|
||||
|
||||
# Cache file creation bug
|
||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||
.idea/$CACHE_FILE$
|
||||
|
||||
# CodeStream plugin
|
||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||
.idea/codestream.xml
|
||||
.idea/sonarlint
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
@@ -152,7 +139,6 @@ buildNumber.properties
|
||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### Maven Patch ###
|
||||
# Eclipse m2e generated files
|
||||
# Eclipse Core
|
||||
.project
|
||||
@@ -188,6 +174,7 @@ $RECYCLE.BIN/
|
||||
### Gradle ###
|
||||
.gradle
|
||||
build/
|
||||
build-cache/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
@@ -204,8 +191,4 @@ gradle-app.setting
|
||||
### Gradle Patch ###
|
||||
**/build/
|
||||
|
||||
# Eclipse Gradle plugin generated files
|
||||
# Eclipse Core
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij,maven,gradle
|
||||
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,maven
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>BUKKIT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,108 +0,0 @@
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
plugins {
|
||||
id 'com.github.johnrengelman.shadow' version '7.1.0'
|
||||
id 'maven-publish'
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
version = "2.7.3"
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.NLthijs48:InteractiveMessenger:e7749258ca'
|
||||
implementation 'com.github.NLthijs48:BukkitDo:819d51ec2b'
|
||||
implementation 'io.papermc:paperlib:1.0.6'
|
||||
implementation 'io.github.baked-libs:dough-data:1.0.3'
|
||||
implementation ('com.google.inject:guice:5.0.1') {
|
||||
exclude group: 'com.google.guava'
|
||||
}
|
||||
implementation ('com.google.inject.extensions:guice-assistedinject:5.0.1') {
|
||||
exclude group: 'com.google.guava'
|
||||
}
|
||||
implementation project(':areashop-interface')
|
||||
implementation project(':areashop-bukkit-1_13')
|
||||
implementation project(':areashop-nms')
|
||||
runtimeOnly project(path: ':areashop-nms-1-17', configuration: 'reobf')
|
||||
runtimeOnly project(path: ':areashop-nms-1-18', configuration: 'reobf')
|
||||
implementation project(':areashop-worldedit-7')
|
||||
implementation project(':areashop-worldguard-7')
|
||||
implementation project(':areashop-fastasyncworldedit')
|
||||
compileOnly 'org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT'
|
||||
compileOnly ('com.sk89q.worldedit:worldedit-bukkit:7.2.8') {
|
||||
exclude group: 'com.google.guava'
|
||||
}
|
||||
compileOnly ('com.sk89q.worldguard:worldguard-bukkit:7.0.6') {
|
||||
exclude group: 'com.google.guava'
|
||||
}
|
||||
compileOnly ('com.github.MilkBowl:VaultAPI:1.7')
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
from (sourceSets.main.resources) {
|
||||
filter ReplaceTokens, tokens: [version: project.version]
|
||||
duplicatesStrategy(DuplicatesStrategy.INCLUDE)
|
||||
}
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(shadowJar)
|
||||
dependsOn(publishToMavenLocal)
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier.set('original')
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveClassifier.set('')
|
||||
setArchivesBaseName('AreaShop')
|
||||
String base = "me.wiefferink.areashop.libraries"
|
||||
relocate('me.wiefferink.interactivemessenger', "${base}.interactivemessenger")
|
||||
relocate('me.wiefferink.bukkitdo', "${base}.bukkitdo")
|
||||
relocate('io.papermc.lib', "${base}.paperlib")
|
||||
relocate('io.github.bakedlibs.dough', "${base}.dough")
|
||||
relocate("com.google.inject", "${base}.inject")
|
||||
relocate("org.aopalliance", "${base}.aopalliance")
|
||||
relocate("javax.inject", "${base}.javax.inject")
|
||||
include {
|
||||
include("com.google.inject")
|
||||
minimize()
|
||||
}
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
classifier('sources')
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
// ... artifact publications
|
||||
areaShop(MavenPublication) {
|
||||
from components.java
|
||||
pom {
|
||||
group = "me.wiefferink"
|
||||
artifactId = "$project.name"
|
||||
version = "$project.version"
|
||||
scm {
|
||||
connection = 'scm:git:git://github.com/md5sha256/AreaShop.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/md5sha256/AreaShop.git'
|
||||
url = "https://github.com/md5sha256/AreaShop/tree/dev/bleeding"
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name = 'GNU General Public License v3.0'
|
||||
url = "https://github.com/md5sha256/AreaShop/blob/dev/bleeding/LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
description = 'AreaShop'
|
||||
@@ -0,0 +1,97 @@
|
||||
plugins {
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
}
|
||||
|
||||
description = "AreaShop"
|
||||
|
||||
dependencies {
|
||||
// Platform
|
||||
compileOnlyApi(libs.spigot)
|
||||
compileOnlyApi(libs.worldeditCore) {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
compileOnlyApi(libs.worldeditBukkit) {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
compileOnlyApi(libs.worldguardCore) {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
compileOnlyApi(libs.worldguardBukkit) {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
compileOnlyApi("com.github.MilkBowl:VaultAPI:1.7") {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
|
||||
// 3rd party libraries
|
||||
implementation(libs.findbugs)
|
||||
implementation("io.papermc:paperlib:1.0.8")
|
||||
implementation("com.github.NLthijs48:InteractiveMessenger:e7749258ca")
|
||||
implementation("com.github.NLthijs48:BukkitDo:819d51ec2b")
|
||||
implementation("io.github.baked-libs:dough-data:1.2.0")
|
||||
implementation("com.google.inject:guice:5.1.0") {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
implementation("com.google.inject.extensions:guice-assistedinject:5.1.0") {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
|
||||
// Project submodules
|
||||
implementation(projects.areashopInterface)
|
||||
implementation(projects.areashopNms)
|
||||
implementation(projects.adapters.platform.platformInterface)
|
||||
implementation(projects.adapters.platform.paper)
|
||||
// Adapters
|
||||
runtimeOnly(projects.adapters.plugins.worldedit)
|
||||
runtimeOnly(projects.adapters.plugins.worldguard)
|
||||
runtimeOnly(projects.adapters.plugins.fastasyncworldedit)
|
||||
runtimeOnly(project(":adapters:platform:bukkit-1-17", "reobf"))
|
||||
runtimeOnly(project(":adapters:platform:bukkit-1-18", "reobf"))
|
||||
runtimeOnly(project(":adapters:platform:bukkit-1-19", "reobf"))
|
||||
runtimeOnly(project(":adapters:platform:bukkit-1-20", "reobf"))
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
filesMatching("plugin.yml") {
|
||||
expand("version" to project.version)
|
||||
}
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier.set("original")
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
val javaComponent = project.components["java"] as AdhocComponentWithVariants
|
||||
javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
|
||||
skip()
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveClassifier.set("")
|
||||
base {
|
||||
archiveBaseName.set("AreaShop")
|
||||
}
|
||||
val base = "me.wiefferink.areashop.libraries"
|
||||
relocate("me.wiefferink.interactivemessenger", "${base}.interactivemessenger")
|
||||
relocate("me.wiefferink.bukkitdo", "${base}.bukkitdo")
|
||||
relocate("io.papermc.lib", "${base}.paperlib")
|
||||
relocate("io.github.bakedlibs.dough", "${base}.dough")
|
||||
relocate("com.google.inject", "${base}.inject")
|
||||
relocate("org.aopalliance", "${base}.aopalliance")
|
||||
relocate("javax.annotation", "${base}.javax.annotation")
|
||||
relocate("javax.inject", "${base}.javax.inject")
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,11 @@ import com.google.inject.Stage;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.wiefferink.areashop.adapters.platform.MinecraftPlatform;
|
||||
import me.wiefferink.areashop.adapters.platform.paper.PaperPlatform;
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.interfaces.AreaShopInterface;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.listeners.PlayerLoginLogoutListener;
|
||||
@@ -22,9 +24,11 @@ import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
import me.wiefferink.areashop.modules.AreaShopModule;
|
||||
import me.wiefferink.areashop.modules.BukkitModule;
|
||||
import me.wiefferink.areashop.modules.DependencyModule;
|
||||
import me.wiefferink.areashop.modules.PlatformModule;
|
||||
import me.wiefferink.areashop.nms.NMS;
|
||||
import me.wiefferink.areashop.tools.GithubUpdateCheck;
|
||||
import me.wiefferink.areashop.tools.SimpleMessageBridge;
|
||||
import me.wiefferink.areashop.tools.SpigotPlatform;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.bukkitdo.Do;
|
||||
import me.wiefferink.interactivemessenger.source.LanguageManager;
|
||||
@@ -50,8 +54,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Main class for the AreaShop plugin.
|
||||
@@ -68,7 +71,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
private WorldEditPlugin worldEdit = null;
|
||||
private WorldEditInterface worldEditInterface = null;
|
||||
private NMS nms;
|
||||
private BukkitInterface bukkitInterface = null;
|
||||
private MessageBridge messageBridge;
|
||||
private IFileManager fileManager = null;
|
||||
private LanguageManager languageManager = null;
|
||||
@@ -91,7 +93,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
public static final String defaultFile = "default.yml";
|
||||
public static final String configFile = "config.yml";
|
||||
public static final String configFileHidden = "hiddenConfig.yml";
|
||||
public static final String signLogFile = "sign-errors.yml";
|
||||
public static final String signLogFile = "sign-errors.log";
|
||||
public static final String versionFile = "versions";
|
||||
|
||||
// Euro tag for in the config
|
||||
@@ -166,7 +168,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
AreaShop.instance = this;
|
||||
Do.init(this);
|
||||
managers = new HashSet<>();
|
||||
boolean error = false;
|
||||
messageBridge = new SimpleMessageBridge();
|
||||
signErrorLogger = new SignErrorLogger(new File(getDataFolder(), signLogFile));
|
||||
|
||||
@@ -175,191 +176,98 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
String[] split = rawServerVersion.split("\\.");
|
||||
String serverVersion = split[3];
|
||||
try {
|
||||
Class<?> nmsImpl = Class.forName("me.wiefferink.areashop.nms." + serverVersion + ".NMSImpl");
|
||||
Class<?> nmsImpl = Class.forName("me.wiefferink.areashop.adapters.platform." + serverVersion + ".NMSImpl");
|
||||
this.nms = nmsImpl.asSubclass(NMS.class).getConstructor().newInstance();
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace();
|
||||
getLogger().severe("Failed to initialize NMS implementation!");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
error("Failed to initialize NMS implementation!");
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
final MinecraftPlatform platform;
|
||||
if (PaperLib.isPaper()) {
|
||||
platform = new PaperPlatform(this);
|
||||
info("Detected Paper; using the PaperPlatform impl");
|
||||
} else {
|
||||
platform = new SpigotPlatform(this);
|
||||
info("Detected Spigot; using the SpigotPlatform impl");
|
||||
}
|
||||
final PlatformModule platformModule = new PlatformModule(platform, this.nms);
|
||||
|
||||
// Check if Vault is present
|
||||
if(getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
error("Vault plugin is not present or has not loaded correctly");
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
|
||||
// Find WorldEdit integration version to load
|
||||
String weHandlerVersion = null;
|
||||
String rawWeVersion = null;
|
||||
String weBeta = null;
|
||||
String weHandlerVersion;
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
boolean fawe = false;
|
||||
if(!(plugin instanceof WorldEditPlugin) || !plugin.isEnabled()) {
|
||||
error("WorldEdit plugin is not present or has not loaded correctly");
|
||||
error = true;
|
||||
return;
|
||||
} else {
|
||||
worldEdit = (WorldEditPlugin)plugin;
|
||||
rawWeVersion = worldEdit.getDescription().getVersion();
|
||||
|
||||
// Find beta version
|
||||
Pattern pattern = Pattern.compile("beta-?\\d+");
|
||||
Matcher matcher = pattern.matcher(rawWeVersion);
|
||||
if (matcher.find()) {
|
||||
weBeta = matcher.group();
|
||||
}
|
||||
|
||||
// Get correct WorldEditInterface (handles things that changed version to version)
|
||||
if(worldEdit.getDescription().getVersion().startsWith("7.")) {
|
||||
weHandlerVersion = "WorldEditHandler7";
|
||||
} else {
|
||||
// Check if FastAsyncWorldEdit is installed
|
||||
try {
|
||||
Class.forName("com.fastasyncworldedit.core.FaweAPI" );
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
throw new IllegalStateException("Unknown WE Version: " + worldEdit.getDescription().getVersion());
|
||||
}
|
||||
this.worldEdit = (WorldEditPlugin) plugin;
|
||||
Plugin fawePlugin = getServer().getPluginManager().getPlugin("FastAsyncWorldEdit");
|
||||
if (fawePlugin != null && fawePlugin.isEnabled()) {
|
||||
weHandlerVersion = "FastAsyncWorldEditHandler";
|
||||
fawe = true;
|
||||
info("Detected FastAsyncWorldEdit, using the fawe handler");
|
||||
} else {
|
||||
weHandlerVersion = "WorldEditHandler";
|
||||
}
|
||||
}
|
||||
|
||||
// Find WorldGuard integration version to load
|
||||
String wgVersion = null;
|
||||
String rawWgVersion = null;
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
int fixes = 0;
|
||||
Integer build = null;
|
||||
plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if(!(plugin instanceof WorldGuardPlugin) || !plugin.isEnabled()) {
|
||||
error("WorldGuard plugin is not present or has not loaded correctly");
|
||||
error = true;
|
||||
shutdownOnError();
|
||||
return;
|
||||
} else {
|
||||
worldGuard = (WorldGuardPlugin)plugin;
|
||||
// Get correct WorldGuardInterface (handles things that changed version to version)
|
||||
try {
|
||||
rawWgVersion = worldGuard.getDescription().getVersion();
|
||||
if(rawWgVersion.contains("-SNAPSHOT;")) {
|
||||
String buildNumber = rawWgVersion.substring(rawWgVersion.indexOf("-SNAPSHOT;") + 10);
|
||||
if(buildNumber.contains("-")) {
|
||||
buildNumber = buildNumber.substring(0, buildNumber.indexOf('-'));
|
||||
if (Utils.isNumeric(buildNumber)) {
|
||||
build = Integer.parseInt(buildNumber);
|
||||
} else {
|
||||
warn("Could not correctly parse the build of WorldGuard, raw version: " + rawWgVersion + ", buildNumber: " + buildNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Clear stuff from the version string that is not a number
|
||||
String[] versionParts = rawWgVersion.split("\\.");
|
||||
for(int i = 0; i < versionParts.length; i++) {
|
||||
Pattern pattern = Pattern.compile("^\\d+");
|
||||
Matcher matcher = pattern.matcher(versionParts[i]);
|
||||
if(matcher.find()) {
|
||||
versionParts[i] = matcher.group();
|
||||
}
|
||||
}
|
||||
// Find major, minor and fix numbers
|
||||
try {
|
||||
if(versionParts.length > 0) {
|
||||
major = Integer.parseInt(versionParts[0]);
|
||||
}
|
||||
if(versionParts.length > 1) {
|
||||
minor = Integer.parseInt(versionParts[1]);
|
||||
}
|
||||
if(versionParts.length > 2) {
|
||||
fixes = Integer.parseInt(versionParts[2]);
|
||||
}
|
||||
} catch(NumberFormatException e) {
|
||||
warn("Something went wrong while parsing WorldGuard version number: " + rawWgVersion);
|
||||
}
|
||||
|
||||
// Determine correct implementation to use
|
||||
if(rawWgVersion.startsWith("7.")) {
|
||||
wgVersion = "7";
|
||||
}
|
||||
} catch(Exception e) { // If version detection fails, at least try to load the latest version
|
||||
warn("Parsing the WorldGuard version failed, assuming version 7:", rawWgVersion);
|
||||
wgVersion = "7";
|
||||
}
|
||||
|
||||
wgVersion = "WorldGuardHandler" + wgVersion;
|
||||
this.worldGuard = (WorldGuardPlugin) plugin;
|
||||
}
|
||||
|
||||
DependencyModule dependencyModule = new DependencyModule(worldEdit, worldGuard, getEconomy(), getPermissionProvider());
|
||||
DependencyModule dependencyModule = new DependencyModule(this.worldEdit, this.worldGuard, getEconomy(), getPermissionProvider());
|
||||
|
||||
// Load WorldEdit
|
||||
try {
|
||||
Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers." + weHandlerVersion);
|
||||
// Check if we have a NMSHandler class at that location.
|
||||
Class<?> clazz = Class.forName("me.wiefferink.areashop.adapters.plugins." + weHandlerVersion);
|
||||
if(WorldEditInterface.class.isAssignableFrom(clazz)) { // Make sure it actually implements WorldEditInterface
|
||||
worldEditInterface = (WorldEditInterface)clazz.getConstructor(AreaShopInterface.class).newInstance(this); // Set our handler
|
||||
}
|
||||
} catch(Exception e) {
|
||||
error("Could not load the handler for WorldEdit (tried to load " + weHandlerVersion + "), report this problem to the author: " + ExceptionUtils.getStackTrace(e));
|
||||
error = true;
|
||||
weHandlerVersion = null;
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
|
||||
// Load WorldGuard
|
||||
try {
|
||||
Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers." + wgVersion);
|
||||
Class<?> clazz = Class.forName("me.wiefferink.areashop.adapters.plugins.WorldGuardHandler");
|
||||
// Check if we have a NMSHandler class at that location.
|
||||
if(WorldGuardInterface.class.isAssignableFrom(clazz)) { // Make sure it actually implements WorldGuardInterface
|
||||
worldGuardInterface = (WorldGuardInterface)clazz.getConstructor(AreaShopInterface.class).newInstance(this); // Set our handler
|
||||
}
|
||||
} catch(Exception e) {
|
||||
error("Could not load the handler for WorldGuard (tried to load " + wgVersion + "), report this problem to the author:" + ExceptionUtils.getStackTrace(e));
|
||||
error = true;
|
||||
wgVersion = null;
|
||||
error("Could not load the handler for WorldGuard, report this problem to the author:" + ExceptionUtils.getStackTrace(e));
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
|
||||
// Load Bukkit implementation
|
||||
String bukkitHandler;
|
||||
try {
|
||||
Class.forName("org.bukkit.block.data.type.WallSign");
|
||||
bukkitHandler = "1_13";
|
||||
} catch (ClassNotFoundException e) {
|
||||
bukkitHandler = "1_12";
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers.BukkitHandler" + bukkitHandler);
|
||||
bukkitInterface = (BukkitInterface)clazz.getConstructor(AreaShopInterface.class).newInstance(this);
|
||||
} catch (Exception e) {
|
||||
error("Could not load the Bukkit handler (used for sign updates), tried to load:", bukkitHandler + ", report this problem to the author:", ExceptionUtils.getStackTrace(e));
|
||||
error = true;
|
||||
bukkitHandler = null;
|
||||
}
|
||||
|
||||
// Check if Vault is present
|
||||
if(getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
error("Vault plugin is not present or has not loaded correctly");
|
||||
error = true;
|
||||
}
|
||||
|
||||
AreaShopModule asModule = new AreaShopModule(this, messageBridge, nms, bukkitInterface, worldEditInterface, worldGuardInterface, signErrorLogger, dependencyModule);
|
||||
AreaShopModule asModule = new AreaShopModule(this, messageBridge, nms, worldEditInterface, worldGuardInterface, signErrorLogger, platformModule, dependencyModule);
|
||||
injector = Guice.createInjector(Stage.PRODUCTION, new BukkitModule(getServer()), asModule);
|
||||
|
||||
// Load all data from files and check versions
|
||||
fileManager = injector.getInstance(IFileManager.class);
|
||||
managers.add((FileManager) fileManager);
|
||||
boolean loadFilesResult = fileManager.loadFiles(false);
|
||||
error = error || !loadFilesResult;
|
||||
|
||||
// Print loaded version of WG and WE in debug
|
||||
if(wgVersion != null) {
|
||||
AreaShop.debug("Loaded ", wgVersion, "(raw version:" + rawWgVersion + ", major:" + major + ", minor:" + minor + ", fixes:" + fixes + ", build:" + build + ", fawe:" + fawe + ")");
|
||||
}
|
||||
if(weHandlerVersion != null) {
|
||||
AreaShop.debug("Loaded ", weHandlerVersion, "(raw version:" + rawWeVersion + ", beta:" + weBeta + ")");
|
||||
}
|
||||
if(bukkitHandler != null) {
|
||||
AreaShop.debug("Loaded BukkitHandler", bukkitHandler);
|
||||
if (!loadFilesResult) {
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
|
||||
setupLanguageManager();
|
||||
|
||||
if(error) {
|
||||
error("The plugin has not started, fix the errors listed above");
|
||||
return;
|
||||
}
|
||||
featureManager = injector.getInstance(FeatureManager.class);
|
||||
featureManager.initializeFeatures(injector);
|
||||
managers.add(featureManager);
|
||||
@@ -386,7 +294,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
if(getConfig().getBoolean("checkForUpdates")) {
|
||||
githubUpdateCheck = new GithubUpdateCheck(
|
||||
this,
|
||||
"NLThijs48",
|
||||
"md5sha256",
|
||||
"AreaShop"
|
||||
).withVersionComparator((latestVersion, currentVersion) ->
|
||||
!cleanVersion(latestVersion).equals(cleanVersion(currentVersion))
|
||||
@@ -396,7 +304,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
return;
|
||||
}
|
||||
|
||||
AreaShop.info("Update from AreaShop V" + cleanVersion(result.getCurrentVersion()) + " to AreaShop V" + cleanVersion(result.getLatestVersion()) + " available, get the latest version at https://www.spigotmc.org/resources/areashop.2991/");
|
||||
AreaShop.info("Update from AreaShop V" + cleanVersion(result.getCurrentVersion()) + " to AreaShop V" + cleanVersion(result.getLatestVersion()) + " available, get the latest version at https://github.com/md5sha256/releases");
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
notifyUpdate(player);
|
||||
}
|
||||
@@ -414,6 +322,11 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
}
|
||||
}
|
||||
|
||||
private void shutdownOnError() {
|
||||
error("The plugin has not started, fix the errors listed above");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup a version number.
|
||||
* @param version Version to clean
|
||||
@@ -545,6 +458,11 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
return worldEdit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin pluginInstance() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get WorldGuardInterface for version dependent things.
|
||||
* @return WorldGuardInterface
|
||||
@@ -561,14 +479,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
return languageManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the BukkitHandler, for sign interactions.
|
||||
* @return BukkitHandler
|
||||
*/
|
||||
public BukkitInterface getBukkitHandler() {
|
||||
return this.bukkitInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the CommandManager.
|
||||
* @return the CommandManager
|
||||
@@ -795,12 +705,19 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
AreaShop.debug(StringUtils.join(message, " "));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debugI(Supplier<String> message) {
|
||||
if (debug) {
|
||||
info("Debug: " + message.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print an information message to the console.
|
||||
* @param message The message to print
|
||||
*/
|
||||
public static void info(Object... message) {
|
||||
AreaShop.getInstance().getLogger().info(StringUtils.join(message, " "));
|
||||
AreaShop.getInstance().getLogger().info(() -> StringUtils.join(message, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -808,7 +725,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
* @param message The message to print
|
||||
*/
|
||||
public static void warn(Object... message) {
|
||||
AreaShop.getInstance().getLogger().warning(StringUtils.join(message, " "));
|
||||
AreaShop.getInstance().getLogger().warning(() -> StringUtils.join(message, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -816,7 +733,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
* @param message The message to print
|
||||
*/
|
||||
public static void error(Object... message) {
|
||||
AreaShop.getInstance().getLogger().severe(StringUtils.join(message, " "));
|
||||
AreaShop.getInstance().getLogger().severe(() -> StringUtils.join(message, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -321,8 +321,7 @@ public class AddCommand extends CommandAreaShop {
|
||||
result.add("buy");
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
if(sender instanceof Player) {
|
||||
Player player = (Player)sender;
|
||||
if(sender instanceof Player player) {
|
||||
if(sender.hasPermission("areashop.createrent") || sender.hasPermission("areashop.createbuy")) {
|
||||
for(ProtectedRegion region : plugin.getRegionManager(player.getWorld()).getRegions().values()) {
|
||||
result.add(region.getId());
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -20,129 +20,123 @@ import java.util.List;
|
||||
@Singleton
|
||||
public class AddfriendCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop addfriend";
|
||||
}
|
||||
@Inject
|
||||
private OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.addfriendall") || target.hasPermission("areashop.addfriend")) {
|
||||
return "help-addFriend";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Inject
|
||||
private BukkitSchedulerExecutor executor;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) {
|
||||
messageBridge.message(sender, "addfriend-noPermission");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop addfriend";
|
||||
}
|
||||
|
||||
if(args.length < 2) {
|
||||
messageBridge.message(sender, "addfriend-help");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if (target.hasPermission("areashop.addfriendall") || target.hasPermission("areashop.addfriend")) {
|
||||
return "help-addFriend";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
GeneralRegion region;
|
||||
if(args.length <= 2) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(sender.hasPermission("areashop.addfriendall")) {
|
||||
if((region instanceof RentRegion && !((RentRegion)region).isRented())
|
||||
|| (region instanceof BuyRegion && !((BuyRegion)region).isSold())) {
|
||||
messageBridge.message(sender, "addfriend-noOwner", region);
|
||||
return;
|
||||
}
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
|
||||
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.isOwner(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "addfriend-successOther", friend.getName(), region);
|
||||
}
|
||||
} else {
|
||||
if(sender.hasPermission("areashop.addfriend") && sender instanceof Player) {
|
||||
if(region.isOwner((Player)sender)) {
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
|
||||
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.isOwner(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) {
|
||||
messageBridge.message(sender, "addfriend-noPermission");
|
||||
return;
|
||||
}
|
||||
|
||||
if(region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "addfriend-success", friend.getName(), region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "addfriend-noPermissionOther", region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "addfriend-noPermission", region);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args.length < 2) {
|
||||
messageBridge.message(sender, "addfriend-help");
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
GeneralRegion region;
|
||||
if (args.length == 2) {
|
||||
if (sender instanceof Player player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(player.getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if (regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
if (region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (sender.hasPermission("areashop.addfriendall")) {
|
||||
if ((region instanceof RentRegion rentRegion && !rentRegion.isRented())
|
||||
|| (region instanceof BuyRegion buyRegion && !buyRegion.isSold())) {
|
||||
messageBridge.message(sender, "addfriend-noOwner", region);
|
||||
return;
|
||||
}
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(friend -> {
|
||||
if (friend.hasPlayedBefore() && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
|
||||
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
|
||||
} else if (region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
|
||||
} else if (region.isOwner(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
|
||||
} else if (region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "addfriend-successOther", friend.getName(), region);
|
||||
}
|
||||
}, this.executor);
|
||||
return;
|
||||
}
|
||||
if (!sender.hasPermission("areashop.addfriend") || !(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "addfriend-noPermission", region);
|
||||
return;
|
||||
}
|
||||
if (!region.isOwner(player)) {
|
||||
messageBridge.message(sender, "addfriend-noPermissionOther", region);
|
||||
return;
|
||||
}
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(friend -> {
|
||||
if (friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
|
||||
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
|
||||
} else if (region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
|
||||
} else if (region.isOwner(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
|
||||
} else if (region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "addfriend-success", friend.getName(), region);
|
||||
}
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if (toComplete == 2) {
|
||||
for (Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if (toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ package me.wiefferink.areashop.commands;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Materials;
|
||||
import me.wiefferink.areashop.tools.SignUtils;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -33,8 +33,6 @@ public class AddsignCommand extends CommandAreaShop {
|
||||
private SignManager signManager;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
@Inject
|
||||
private BukkitInterface bukkitInterface;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -55,11 +53,10 @@ public class AddsignCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "addsign-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
|
||||
// Get the sign
|
||||
Block block = null;
|
||||
@@ -111,7 +108,7 @@ public class AddsignCommand extends CommandAreaShop {
|
||||
return;
|
||||
}
|
||||
|
||||
region.getSignsFeature().addSign(block.getLocation(), block.getType(), bukkitInterface.getSignFacing(block), profile);
|
||||
region.getSignsFeature().addSign(block.getLocation(), block.getType(), SignUtils.getSignFacing(block), profile);
|
||||
if(profile == null) {
|
||||
messageBridge.message(sender, "addsign-success", region);
|
||||
} else {
|
||||
|
||||
@@ -42,11 +42,10 @@ public class BuyCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "buy-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
if(args.length > 1 && args[1] != null) {
|
||||
BuyRegion region = fileManager.getBuy(args[1]);
|
||||
if(region == null) {
|
||||
|
||||
@@ -53,11 +53,10 @@ public class DelCommand extends CommandAreaShop {
|
||||
}
|
||||
if(args.length < 2) {
|
||||
// Only players can have a selection
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-weOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if(selection == null) {
|
||||
messageBridge.message(player, "cmd-noSelection");
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -15,116 +17,121 @@ import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class DelfriendCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop delfriend";
|
||||
}
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.delfriendall") || target.hasPermission("areashop.delfriend")) {
|
||||
return "help-delFriend";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Inject
|
||||
private OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
/**
|
||||
* Check if a person can remove friends.
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can remove friends, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if(person.hasPermission("areashop.delfriendall")) {
|
||||
return true;
|
||||
}
|
||||
if(person instanceof Player) {
|
||||
Player player = (Player)person;
|
||||
return region.isOwner(player) && player.hasPermission("areashop.delfriend");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Inject
|
||||
private BukkitSchedulerExecutor executor;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) {
|
||||
messageBridge.message(sender, "delfriend-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2) {
|
||||
messageBridge.message(sender, "delfriend-help");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region;
|
||||
if(args.length <= 2) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(sender.hasPermission("areashop.delfriendall")) {
|
||||
if((region instanceof RentRegion && !((RentRegion)region).isRented())
|
||||
|| (region instanceof BuyRegion && !((BuyRegion)region).isSold())) {
|
||||
messageBridge.message(sender, "delfriend-noOwner", region);
|
||||
return;
|
||||
}
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "delfriend-successOther", friend.getName(), region);
|
||||
}
|
||||
} else {
|
||||
if(sender.hasPermission("areashop.delfriend") && sender instanceof Player) {
|
||||
if(region.isOwner((Player)sender)) {
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "delfriend-success", friend.getName(), region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "delfriend-noPermissionOther", region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "delfriend-noPermission", region);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop delfriend";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if (target.hasPermission("areashop.delfriendall") || target.hasPermission("areashop.delfriend")) {
|
||||
return "help-delFriend";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a person can remove friends.
|
||||
*
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can remove friends, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if (person.hasPermission("areashop.delfriendall")) {
|
||||
return true;
|
||||
}
|
||||
if (person instanceof Player player) {
|
||||
return region.isOwner(player) && player.hasPermission("areashop.delfriend");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) {
|
||||
messageBridge.message(sender, "delfriend-noPermission");
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
messageBridge.message(sender, "delfriend-help");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region;
|
||||
if (args.length == 2) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(player.getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if (regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
if (region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (sender.hasPermission("areashop.delfriendall")) {
|
||||
if ((region instanceof RentRegion rentRegion && !rentRegion.isRented())
|
||||
|| (region instanceof BuyRegion buyRegion && !buyRegion.isSold())) {
|
||||
messageBridge.message(sender, "delfriend-noOwner", region);
|
||||
return;
|
||||
}
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(friend -> {
|
||||
if (!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if (region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "delfriend-successOther", friend.getName(), region);
|
||||
}
|
||||
}, this.executor);
|
||||
return;
|
||||
}
|
||||
if (!sender.hasPermission("areashop.delfriend") || !(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "delfriend-noPermission", region);
|
||||
return;
|
||||
}
|
||||
if (!region.isOwner(player)) {
|
||||
messageBridge.message(sender, "delfriend-noPermissionOther", region);
|
||||
return;
|
||||
}
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(friend -> {
|
||||
if (!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
|
||||
} else if (region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "delfriend-success", friend.getName(), region);
|
||||
}
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
|
||||
@@ -44,18 +44,17 @@ public class DelsignCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "delsign-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
|
||||
// Get the sign
|
||||
Block block = null;
|
||||
BlockIterator blockIterator = new BlockIterator(player, 100);
|
||||
while(blockIterator.hasNext() && block == null) {
|
||||
Block next = blockIterator.next();
|
||||
if(next.getType() != Material.AIR) {
|
||||
if(!next.getType().isAir()) {
|
||||
block = next;
|
||||
}
|
||||
}
|
||||
@@ -70,8 +69,9 @@ public class DelsignCommand extends CommandAreaShop {
|
||||
}
|
||||
RegionSign regionSign = optionalSign.get();
|
||||
messageBridge.message(sender, "delsign-success", regionSign.getRegion());
|
||||
signManager.removeSign(regionSign);
|
||||
regionSign.remove();
|
||||
// Sometimes the RegionSign data is corrupted. Forcefully set the block to air
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -48,7 +48,7 @@ public class FindCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "find-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
@@ -56,7 +56,6 @@ public class FindCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "find-help");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
double balance = 0.0;
|
||||
if(economy != null) {
|
||||
balance = economy.getBalance(player);
|
||||
|
||||
@@ -59,11 +59,10 @@ public class GroupaddCommand extends CommandAreaShop {
|
||||
fileManager.addGroup(group);
|
||||
}
|
||||
if(args.length == 2) {
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-weOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if(selection == null) {
|
||||
messageBridge.message(player, "cmd-noSelection");
|
||||
|
||||
@@ -59,11 +59,10 @@ public class GroupdelCommand extends CommandAreaShop {
|
||||
}
|
||||
|
||||
if(args.length == 2) {
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-weOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if(selection == null) {
|
||||
messageBridge.message(player, "cmd-noSelection");
|
||||
|
||||
@@ -43,12 +43,11 @@ public class LinksignsCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "linksigns-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player)sender;
|
||||
if(signLinkerManager.isInSignLinkMode(player)) {
|
||||
signLinkerManager.exitSignLinkMode(player);
|
||||
} else {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -26,6 +28,12 @@ public class MeCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Inject
|
||||
private OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
@Inject
|
||||
private BukkitSchedulerExecutor executor;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop me";
|
||||
@@ -55,42 +63,48 @@ public class MeCommand extends CommandAreaShop {
|
||||
player = (OfflinePlayer)sender;
|
||||
}
|
||||
if(args.length > 1) {
|
||||
player = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(!player.hasPlayedBefore()) {
|
||||
messageBridge.message(sender, "me-noPlayer", args[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!player.hasPlayedBefore()) {
|
||||
// Lookup offline players async
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(offlinePlayer -> {
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
messageBridge.message(sender, "me-noPlayer", args[1]);
|
||||
} else {
|
||||
sendMessageAboutRegions(sender, offlinePlayer);
|
||||
}
|
||||
}, this.executor);
|
||||
return;
|
||||
}
|
||||
sendMessageAboutRegions(sender, player);
|
||||
}
|
||||
|
||||
private void sendMessageAboutRegions(CommandSender sender, OfflinePlayer target) {
|
||||
// Get the regions owned by the player
|
||||
Set<RentRegion> rentRegions = new HashSet<>();
|
||||
for(RentRegion region : fileManager.getRentsRef()) {
|
||||
if(region.isOwner(player)) {
|
||||
if(region.isOwner(target)) {
|
||||
rentRegions.add(region);
|
||||
}
|
||||
}
|
||||
Set<BuyRegion> buyRegions = new HashSet<>();
|
||||
for(BuyRegion region : fileManager.getBuysRef()) {
|
||||
if(region.isOwner(player)) {
|
||||
if(region.isOwner(target)) {
|
||||
buyRegions.add(region);
|
||||
}
|
||||
}
|
||||
// Get the regions the player is added as friend
|
||||
Set<GeneralRegion> friendRegions = new HashSet<>();
|
||||
for(GeneralRegion region : fileManager.getRegionsRef()) {
|
||||
if(region.getFriendsFeature().getFriends().contains(player.getUniqueId())) {
|
||||
if(region.getFriendsFeature().getFriends().contains(target.getUniqueId())) {
|
||||
friendRegions.add(region);
|
||||
}
|
||||
}
|
||||
|
||||
// Send messages
|
||||
boolean foundSome = !rentRegions.isEmpty() || !buyRegions.isEmpty() || !friendRegions.isEmpty();
|
||||
if(foundSome) {
|
||||
messageBridge.message(sender, "me-header", player.getName());
|
||||
if(!foundSome) {
|
||||
messageBridge.message(sender, "me-nothing", target.getName());
|
||||
return;
|
||||
}
|
||||
messageBridge.message(sender, "me-header", target.getName());
|
||||
if(!rentRegions.isEmpty()) {
|
||||
for(RentRegion region : rentRegions) {
|
||||
messageBridge.messageNoPrefix(sender, "me-rentLine", region);
|
||||
@@ -106,12 +120,7 @@ public class MeCommand extends CommandAreaShop {
|
||||
messageBridge.messageNoPrefix(sender, "me-friendLine", region);
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundSome) {
|
||||
messageBridge.message(sender, "me-nothing", player.getName());
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "me-clickHint");
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "me-clickHint");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,11 +39,10 @@ public class RentCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "rent-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
if(args.length > 1 && args[1] != null) {
|
||||
RentRegion rent = fileManager.getRent(args[1]);
|
||||
if(rent == null) {
|
||||
|
||||
@@ -44,8 +44,7 @@ public class SellCommand extends CommandAreaShop {
|
||||
if(person.hasPermission("areashop.sell")) {
|
||||
return true;
|
||||
}
|
||||
if(person instanceof Player) {
|
||||
Player player = (Player)person;
|
||||
if(person instanceof Player player) {
|
||||
return region.isOwner(player) && person.hasPermission("areashop.sellown");
|
||||
}
|
||||
return false;
|
||||
@@ -59,9 +58,9 @@ public class SellCommand extends CommandAreaShop {
|
||||
}
|
||||
BuyRegion buy;
|
||||
if(args.length <= 1) {
|
||||
if(sender instanceof Player) {
|
||||
if(sender instanceof Player player) {
|
||||
// get the region by location
|
||||
List<BuyRegion> regions = Utils.getImportantBuyRegions(((Player)sender).getLocation());
|
||||
List<BuyRegion> regions = Utils.getImportantBuyRegions((player).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -17,81 +17,84 @@ import java.util.List;
|
||||
@Singleton
|
||||
public class SetlandlordCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop setlandlord";
|
||||
}
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private OfflinePlayerHelper offlinePlayerHelper;
|
||||
@Inject
|
||||
private BukkitSchedulerExecutor executor;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.setlandlord")) {
|
||||
return "help-setlandlord";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop setlandlord";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setlandlord")) {
|
||||
messageBridge.message(sender, "setlandlord-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2) {
|
||||
messageBridge.message(sender, "setlandlord-help");
|
||||
return;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
|
||||
GeneralRegion region;
|
||||
if(args.length < 3) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
}
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
String playerName = player.getName();
|
||||
if(playerName == null || playerName.isEmpty()) {
|
||||
playerName = args[1];
|
||||
}
|
||||
region.setLandlord(player.getUniqueId(), playerName);
|
||||
region.update();
|
||||
messageBridge.message(sender, "setlandlord-success", playerName, region);
|
||||
}
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if (target.hasPermission("areashop.setlandlord")) {
|
||||
return "help-setlandlord";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("areashop.setlandlord")) {
|
||||
messageBridge.message(sender, "setlandlord-noPermission");
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
messageBridge.message(sender, "setlandlord-help");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region;
|
||||
if (args.length < 3) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(player.getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if (regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
}
|
||||
if (region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(offlinePlayer -> {
|
||||
String playerName = offlinePlayer.getName();
|
||||
if (playerName == null || playerName.isEmpty()) {
|
||||
playerName = args[1];
|
||||
}
|
||||
region.setLandlord(offlinePlayer.getUniqueId(), playerName);
|
||||
region.update();
|
||||
messageBridge.message(sender, "setlandlord-success", playerName, region);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if (toComplete == 2) {
|
||||
for (Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if (toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -21,118 +23,116 @@ import java.util.UUID;
|
||||
@Singleton
|
||||
public class SetownerCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop setowner";
|
||||
}
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private OfflinePlayerHelper offlinePlayerHelper;
|
||||
@Inject
|
||||
private BukkitSchedulerExecutor executor;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.setownerrent") || target.hasPermission("areashop.setownerbuy")) {
|
||||
return "help-setowner";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop setowner";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setownerrent") && !sender.hasPermission("areashop.setownerbuy")) {
|
||||
messageBridge.message(sender, "setowner-noPermission");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region;
|
||||
if(args.length < 2) {
|
||||
messageBridge.message(sender, "setowner-help");
|
||||
return;
|
||||
}
|
||||
if(args.length == 2) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
}
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "setowner-notRegistered");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if (target.hasPermission("areashop.setownerrent") || target.hasPermission("areashop.setownerbuy")) {
|
||||
return "help-setowner";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if(region instanceof RentRegion && !sender.hasPermission("areashop.setownerrent")) {
|
||||
messageBridge.message(sender, "setowner-noPermissionRent", region);
|
||||
return;
|
||||
}
|
||||
if(region instanceof BuyRegion && !sender.hasPermission("areashop.setownerbuy")) {
|
||||
messageBridge.message(sender, "setowner-noPermissionBuy", region);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("areashop.setownerrent") && !sender.hasPermission("areashop.setownerbuy")) {
|
||||
messageBridge.message(sender, "setowner-noPermission");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region;
|
||||
if (args.length < 2) {
|
||||
messageBridge.message(sender, "setowner-help");
|
||||
return;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(player.getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if (regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
|
||||
UUID uuid = null;
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(player != null) {
|
||||
uuid = player.getUniqueId();
|
||||
}
|
||||
if(uuid == null) {
|
||||
messageBridge.message(sender, "setowner-noPlayer", args[1], region);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
}
|
||||
if (region == null) {
|
||||
messageBridge.message(sender, "setowner-notRegistered");
|
||||
return;
|
||||
}
|
||||
|
||||
if(region instanceof RentRegion) {
|
||||
RentRegion rent = (RentRegion)region;
|
||||
if(rent.isRenter(uuid)) {
|
||||
// extend
|
||||
rent.setRentedUntil(rent.getRentedUntil() + rent.getDuration());
|
||||
rent.setRenter(uuid);
|
||||
messageBridge.message(sender, "setowner-succesRentExtend", region);
|
||||
} else {
|
||||
// change
|
||||
if(!rent.isRented()) {
|
||||
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
|
||||
}
|
||||
rent.setRenter(uuid);
|
||||
messageBridge.message(sender, "setowner-succesRent", region);
|
||||
}
|
||||
}
|
||||
if(region instanceof BuyRegion) {
|
||||
BuyRegion buy = (BuyRegion)region;
|
||||
buy.setBuyer(uuid);
|
||||
messageBridge.message(sender, "setowner-succesBuy", region);
|
||||
}
|
||||
region.getFriendsFeature().deleteFriend(region.getOwner(), null);
|
||||
region.update();
|
||||
region.saveRequired();
|
||||
}
|
||||
if (region instanceof RentRegion && !sender.hasPermission("areashop.setownerrent")) {
|
||||
messageBridge.message(sender, "setowner-noPermissionRent", region);
|
||||
return;
|
||||
}
|
||||
if (region instanceof BuyRegion && !sender.hasPermission("areashop.setownerbuy")) {
|
||||
messageBridge.message(sender, "setowner-noPermissionBuy", region);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
this.offlinePlayerHelper.lookupUuidAsync(args[1]).thenAcceptAsync(optionalUuid -> {
|
||||
if (optionalUuid.isEmpty()) {
|
||||
messageBridge.message(sender, "setowner-noPlayer", args[1], region);
|
||||
return;
|
||||
}
|
||||
final UUID uuid = optionalUuid.get();
|
||||
if (region instanceof RentRegion rent) {
|
||||
if (rent.isRenter(uuid)) {
|
||||
// extend
|
||||
rent.setRentedUntil(rent.getRentedUntil() + rent.getDuration());
|
||||
rent.setRenter(uuid);
|
||||
messageBridge.message(sender, "setowner-succesRentExtend", region);
|
||||
} else {
|
||||
// change
|
||||
if (!rent.isRented()) {
|
||||
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
|
||||
}
|
||||
rent.setRenter(uuid);
|
||||
messageBridge.message(sender, "setowner-succesRent", region);
|
||||
}
|
||||
}
|
||||
if (region instanceof BuyRegion buy) {
|
||||
buy.setBuyer(uuid);
|
||||
messageBridge.message(sender, "setowner-succesBuy", region);
|
||||
}
|
||||
region.getFriendsFeature().deleteFriend(region.getOwner(), null);
|
||||
region.update();
|
||||
region.saveRequired();
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if (toComplete == 2) {
|
||||
for (Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if (toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -79,7 +81,10 @@ public class SetrestoreCommand extends CommandAreaShop {
|
||||
result.add("false");
|
||||
result.add("general");
|
||||
} else if(toComplete == 4) {
|
||||
result.addAll(plugin.getConfig().getConfigurationSection("schematicProfiles").getKeys(false));
|
||||
ConfigurationSection schemProfiles = fileManager.getConfig().getConfigurationSection("schematicProfiles");
|
||||
if (schemProfiles != null) {
|
||||
result.addAll(schemProfiles.getKeys(false));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -43,10 +43,9 @@ public class SetteleportCommand extends CommandAreaShop {
|
||||
* @return true if the person can set the teleport location, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if(!(person instanceof Player)) {
|
||||
if(!(person instanceof Player player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player)person;
|
||||
return player.hasPermission("areashop.setteleportall")
|
||||
|| region.isOwner(player) && player.hasPermission("areashop.setteleport");
|
||||
}
|
||||
@@ -57,11 +56,10 @@ public class SetteleportCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "setteleport-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
GeneralRegion region;
|
||||
if(args.length < 2) {
|
||||
// get the region by location
|
||||
|
||||
@@ -64,11 +64,10 @@ public class StackCommand extends CommandAreaShop {
|
||||
return;
|
||||
}
|
||||
// Only from ingame
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof final Player player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
final Player player = (Player)sender;
|
||||
// Specify enough arguments
|
||||
if(args.length < 5) {
|
||||
messageBridge.message(sender, "stack-help");
|
||||
|
||||
@@ -39,10 +39,9 @@ public class TeleportCommand extends CommandAreaShop {
|
||||
* @return true if the person can teleport to it, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if(!(person instanceof Player)) {
|
||||
if(!(person instanceof Player 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")
|
||||
@@ -55,7 +54,7 @@ public class TeleportCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "teleport-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
@@ -63,7 +62,6 @@ public class TeleportCommand extends CommandAreaShop {
|
||||
messageBridge.message(sender, "teleport-help");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
GeneralRegion region = fileManager.getRegion(args[1]);
|
||||
if(region == null) {
|
||||
messageBridge.message(player, "teleport-noRentOrBuy", args[1]);
|
||||
|
||||
@@ -44,8 +44,7 @@ public class UnrentCommand extends CommandAreaShop {
|
||||
if(person.hasPermission("areashop.unrent")) {
|
||||
return true;
|
||||
}
|
||||
if(person instanceof Player) {
|
||||
Player player = (Player)person;
|
||||
if(person instanceof Player player) {
|
||||
return region.isOwner(player) && person.hasPermission("areashop.unrentown");
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -6,11 +6,11 @@ import com.google.inject.assistedinject.AssistedInject;
|
||||
import io.github.bakedlibs.dough.blocks.BlockPosition;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import me.wiefferink.areashop.managers.SignErrorLogger;
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Materials;
|
||||
import me.wiefferink.areashop.tools.SignUtils;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -37,7 +37,6 @@ public class RegionSign {
|
||||
|
||||
private final BlockBehaviourHelper blockHelper;
|
||||
private final SignErrorLogger errorLogger;
|
||||
private final BukkitInterface bukkitInterface;
|
||||
|
||||
private final SignsFeature signsFeature;
|
||||
private final String key;
|
||||
@@ -47,13 +46,11 @@ public class RegionSign {
|
||||
RegionSign(
|
||||
@Nonnull BlockBehaviourHelper blockBehaviourHelper,
|
||||
@Nonnull SignErrorLogger signErrorLogger,
|
||||
@Nonnull BukkitInterface bukkitInterface,
|
||||
@Assisted @Nonnull SignsFeature signsFeature,
|
||||
@Assisted @Nonnull String key
|
||||
) {
|
||||
this.blockHelper = blockBehaviourHelper;
|
||||
this.errorLogger = signErrorLogger;
|
||||
this.bukkitInterface = bukkitInterface;
|
||||
this.signsFeature = signsFeature;
|
||||
this.key = key;
|
||||
}
|
||||
@@ -98,8 +95,11 @@ public class RegionSign {
|
||||
* Remove this sign from the region.
|
||||
*/
|
||||
public void remove() {
|
||||
getLocation().getBlock().setType(Material.AIR);
|
||||
this.signsFeature.signManager().removeSign(this);
|
||||
Location location = getLocation();
|
||||
if (location != null && location.getWorld() != null) {
|
||||
location.getBlock().setType(Material.AIR);
|
||||
this.signsFeature.signManager().removeSign(this);
|
||||
}
|
||||
getRegion().setSetting("general.signs." + key, null);
|
||||
// Remove the sign from the region's sign manager
|
||||
}
|
||||
@@ -208,7 +208,7 @@ public class RegionSign {
|
||||
getRegion().setSetting("general.signs." + key + ".signType", block.getType().name());
|
||||
}
|
||||
if(!regionConfig.isString("general.signs." + key + ".facing")) {
|
||||
BlockFace signFacing = bukkitInterface.getSignFacing(block);
|
||||
BlockFace signFacing = SignUtils.getSignFacing(block);
|
||||
getRegion().setSetting("general.signs." + key + ".facing", signFacing == null ? null : signFacing.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -40,7 +41,7 @@ public class SignCache {
|
||||
BlockPosition blockPosition = regionSign.getPosition();
|
||||
this.allSigns.put(blockPosition.getPosition(), regionSign);
|
||||
ChunkPosition chunkPosition = new ChunkPosition(blockPosition.getChunk());
|
||||
Collection<RegionSign> signs = this.signsByChunk.computeIfAbsent(chunkPosition.getPosition(), x -> new ArrayList<>());
|
||||
Collection<RegionSign> signs = this.signsByChunk.computeIfAbsent(chunkPosition.getPosition(), x -> new HashSet<>());
|
||||
signs.add(regionSign);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
@@ -17,6 +16,7 @@ import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Materials;
|
||||
import me.wiefferink.areashop.tools.SignUtils;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.bukkitdo.Do;
|
||||
import org.bukkit.Chunk;
|
||||
@@ -36,6 +36,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -47,7 +48,6 @@ public class SignListener implements Listener {
|
||||
private final MessageBridge messageBridge;
|
||||
private final SignManager signManager;
|
||||
private final SignLinkerManager signLinkerManager;
|
||||
private final BukkitInterface bukkitInterface;
|
||||
private final WorldGuardInterface worldGuardInterface;
|
||||
private final RegionFactory regionFactory;
|
||||
private final IFileManager fileManager;
|
||||
@@ -58,7 +58,6 @@ public class SignListener implements Listener {
|
||||
@Nonnull RegionFactory regionFactory,
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull SignLinkerManager signLinkerManager,
|
||||
@Nonnull BukkitInterface bukkitInterface,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface,
|
||||
@Nonnull SignManager signManager,
|
||||
@Nonnull IFileManager fileManager) {
|
||||
@@ -68,7 +67,6 @@ public class SignListener implements Listener {
|
||||
this.regionFactory = regionFactory;
|
||||
this.behaviourHelper = behaviourHelper;
|
||||
this.plugin = plugin;
|
||||
this.bukkitInterface = bukkitInterface;
|
||||
this.worldGuardInterface = worldGuardInterface;
|
||||
this.messageBridge = messageBridge;
|
||||
}
|
||||
@@ -92,7 +90,6 @@ public class SignListener implements Listener {
|
||||
if(chunkSigns.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
chunkSigns.remove(null);
|
||||
Do.forAll(chunkSigns, RegionSign::update);
|
||||
}
|
||||
|
||||
@@ -292,7 +289,7 @@ public class SignListener implements Listener {
|
||||
if(durationSet) {
|
||||
rent.setDuration(thirdLine);
|
||||
}
|
||||
rent.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), bukkitInterface.getSignFacing(event.getBlock()), null);
|
||||
rent.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), SignUtils.getSignFacing(event.getBlock()), null);
|
||||
|
||||
AddingRegionEvent addingRegionEvent = plugin.getFileManager().addRegion(rent);
|
||||
if (addingRegionEvent.isCancelled()) {
|
||||
@@ -392,7 +389,7 @@ public class SignListener implements Listener {
|
||||
if(priceSet) {
|
||||
buy.setPrice(price);
|
||||
}
|
||||
buy.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), bukkitInterface.getSignFacing(event.getBlock()), null);
|
||||
buy.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), SignUtils.getSignFacing(event.getBlock()), null);
|
||||
|
||||
AddingRegionEvent addingRegionEvent = plugin.getFileManager().addRegion(buy);
|
||||
if (addingRegionEvent.isCancelled()) {
|
||||
@@ -438,10 +435,10 @@ public class SignListener implements Listener {
|
||||
}
|
||||
|
||||
if(thirdLine == null || thirdLine.isEmpty()) {
|
||||
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), bukkitInterface.getSignFacing(event.getBlock()), null);
|
||||
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), SignUtils.getSignFacing(event.getBlock()), null);
|
||||
messageBridge.message(player, "addsign-success", region);
|
||||
} else {
|
||||
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), bukkitInterface.getSignFacing(event.getBlock()), thirdLine);
|
||||
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), SignUtils.getSignFacing(event.getBlock()), thirdLine);
|
||||
messageBridge.message(player, "addsign-successProfile", thirdLine, region);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.wiefferink.areashop.features.signs;
|
||||
|
||||
import io.github.bakedlibs.dough.blocks.BlockPosition;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.managers.Manager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -52,10 +53,17 @@ public class SignManager extends Manager {
|
||||
}
|
||||
|
||||
public void removeSign(RegionSign regionSign) {
|
||||
removeSign(regionSign.getLocation());
|
||||
Location location = regionSign.getLocation();
|
||||
if (location.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
cacheForWorld(location.getWorld()).removeSign(regionSign);
|
||||
}
|
||||
|
||||
public Optional<RegionSign> removeSign(Location location) {
|
||||
if (location == null || location.getWorld() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return getCacheForWorld(location.getWorld()).flatMap(cache -> cache.removeSign(location));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package me.wiefferink.areashop.features.signs;
|
||||
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import io.github.bakedlibs.dough.blocks.BlockPosition;
|
||||
import io.github.bakedlibs.dough.blocks.ChunkPosition;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.features.RegionFeature;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
@@ -12,6 +14,8 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SignsFeature extends RegionFeature {
|
||||
|
||||
@@ -34,17 +38,18 @@ public class SignsFeature extends RegionFeature {
|
||||
setRegion(region);
|
||||
// Setup current signs
|
||||
ConfigurationSection signSection = region.getConfig().getConfigurationSection("general.signs");
|
||||
if(signSection != null) {
|
||||
for(String signKey : signSection.getKeys(false)) {
|
||||
RegionSign sign = signFactory.createRegionSign(this, signKey);
|
||||
Location location = sign.getLocation();
|
||||
if(location == null) {
|
||||
AreaShop.warn("Sign with key " + signKey + " of region " + region.getName() + " does not have a proper location");
|
||||
continue;
|
||||
}
|
||||
this.globalSignManager.cacheForWorld(location.getWorld()).addSign(sign);
|
||||
this.internalSignManager.addSign(sign);
|
||||
if (signSection == null) {
|
||||
return;
|
||||
}
|
||||
for(String signKey : signSection.getKeys(false)) {
|
||||
RegionSign sign = signFactory.createRegionSign(this, signKey);
|
||||
Location location = sign.getLocation();
|
||||
if(location == null) {
|
||||
AreaShop.warn("Sign with key " + signKey + " of region " + region.getName() + " does not have a proper location");
|
||||
continue;
|
||||
}
|
||||
this.globalSignManager.cacheForWorld(location.getWorld()).addSign(sign);
|
||||
this.internalSignManager.addSign(sign);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.google.inject.Singleton;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
@@ -30,7 +29,6 @@ public class SignsModule extends AbstractModule {
|
||||
@Nonnull RegionFactory regionFactory,
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull SignLinkerManager signLinkerManager,
|
||||
@Nonnull BukkitInterface bukkitInterface,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface,
|
||||
@Nonnull SignManager signManager,
|
||||
@Nonnull IFileManager fileManager
|
||||
@@ -41,7 +39,6 @@ public class SignsModule extends AbstractModule {
|
||||
regionFactory,
|
||||
messageBridge,
|
||||
signLinkerManager,
|
||||
bukkitInterface,
|
||||
worldGuardInterface,
|
||||
signManager,
|
||||
fileManager
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.io.InputStreamReader;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -354,10 +355,10 @@ public class FileManager extends Manager implements IFileManager {
|
||||
}
|
||||
final String key = region.getName().toLowerCase(Locale.ENGLISH);
|
||||
regions.put(key, region);
|
||||
if (region instanceof BuyRegion) {
|
||||
buys.put(key, (BuyRegion) region);
|
||||
} else if (region instanceof RentRegion) {
|
||||
rents.put(key, (RentRegion) region);
|
||||
if (region instanceof BuyRegion buyRegion) {
|
||||
buys.put(key, buyRegion);
|
||||
} else if (region instanceof RentRegion rentRegion) {
|
||||
rents.put(key, rentRegion);
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(new AddedRegionEvent(region));
|
||||
return event;
|
||||
@@ -837,8 +838,8 @@ public class FileManager extends Manager implements IFileManager {
|
||||
}
|
||||
// Load default.yml from the plugin folder, and as backup the default one
|
||||
try(
|
||||
InputStreamReader custom = new InputStreamReader(new FileInputStream(defaultFile), Charsets.UTF_8);
|
||||
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.defaultFile), Charsets.UTF_8)
|
||||
InputStreamReader custom = new InputStreamReader(new FileInputStream(defaultFile), StandardCharsets.UTF_8);
|
||||
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.defaultFile), StandardCharsets.UTF_8)
|
||||
) {
|
||||
defaultConfig = YamlConfiguration.loadConfiguration(custom);
|
||||
if(defaultConfig.getKeys(false).isEmpty()) {
|
||||
@@ -878,9 +879,9 @@ public class FileManager extends Manager implements IFileManager {
|
||||
}
|
||||
// Load config.yml from the plugin folder
|
||||
try(
|
||||
InputStreamReader custom = new InputStreamReader(new FileInputStream(configFile), Charsets.UTF_8);
|
||||
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.configFile), Charsets.UTF_8);
|
||||
InputStreamReader hidden = new InputStreamReader(plugin.getResource(AreaShop.configFileHidden), Charsets.UTF_8)
|
||||
InputStreamReader custom = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8);
|
||||
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.configFile), StandardCharsets.UTF_8);
|
||||
InputStreamReader hidden = new InputStreamReader(plugin.getResource(AreaShop.configFileHidden), StandardCharsets.UTF_8)
|
||||
) {
|
||||
config = YamlConfiguration.loadConfiguration(custom);
|
||||
if(config.getKeys(false).isEmpty()) {
|
||||
@@ -917,7 +918,7 @@ public class FileManager extends Manager implements IFileManager {
|
||||
File groupFile = new File(groupsPath);
|
||||
if(groupFile.exists() && groupFile.isFile()) {
|
||||
try(
|
||||
InputStreamReader reader = new InputStreamReader(new FileInputStream(groupFile), Charsets.UTF_8)
|
||||
InputStreamReader reader = new InputStreamReader(new FileInputStream(groupFile), StandardCharsets.UTF_8)
|
||||
) {
|
||||
groupsConfig = YamlConfiguration.loadConfiguration(reader);
|
||||
} catch(IOException e) {
|
||||
@@ -971,7 +972,7 @@ public class FileManager extends Manager implements IFileManager {
|
||||
// Load the region file from disk in UTF8 mode
|
||||
YamlConfiguration regionConfig;
|
||||
try(
|
||||
InputStreamReader reader = new InputStreamReader(new FileInputStream(regionFile), Charsets.UTF_8)
|
||||
InputStreamReader reader = new InputStreamReader(new FileInputStream(regionFile), StandardCharsets.UTF_8)
|
||||
) {
|
||||
regionConfig = YamlConfiguration.loadConfiguration(reader);
|
||||
if(regionConfig.getKeys(false).isEmpty()) {
|
||||
|
||||
@@ -96,9 +96,9 @@ public interface IFileManager {
|
||||
Collection<RentRegion> getRents();
|
||||
|
||||
/**
|
||||
* Get all rental regions.
|
||||
* Get all rental regions (readonly)
|
||||
*
|
||||
* @return List of all rental regions
|
||||
* @return Unmodifiable collection of all rental regions
|
||||
*/
|
||||
Collection<RentRegion> getRentsRef();
|
||||
|
||||
@@ -109,6 +109,10 @@ public interface IFileManager {
|
||||
*/
|
||||
List<BuyRegion> getBuys();
|
||||
|
||||
/**
|
||||
* Get all buy regions (readonly)
|
||||
* @return Unmodifiable collection of all buy regions
|
||||
*/
|
||||
Collection<BuyRegion> getBuysRef();
|
||||
|
||||
/**
|
||||
@@ -119,9 +123,9 @@ public interface IFileManager {
|
||||
List<GeneralRegion> getRegions();
|
||||
|
||||
/**
|
||||
* Get all regions.
|
||||
* Get all regions (readonly)
|
||||
*
|
||||
* @return List of all regions (it is safe to modify the list)
|
||||
* @return Unmodifiable collection of all regions
|
||||
*/
|
||||
Collection<GeneralRegion> getRegionsRef();
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Materials;
|
||||
import me.wiefferink.areashop.tools.SignUtils;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -41,8 +41,6 @@ public class SignLinkerManager extends Manager implements Listener {
|
||||
@Inject
|
||||
private AreaShop plugin;
|
||||
@Inject
|
||||
private BukkitInterface bukkitInterface;
|
||||
@Inject
|
||||
private SignManager signManager;
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@@ -147,7 +145,7 @@ public class SignLinkerManager extends Manager implements Listener {
|
||||
messageBridge.message(player, "linksigns-alreadyRegistered", regionSign.getRegion());
|
||||
return;
|
||||
}
|
||||
linker.setSign(block.getLocation(), block.getType(), bukkitInterface.getSignFacing(block));
|
||||
linker.setSign(block.getLocation(), block.getType(), SignUtils.getSignFacing(block));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,16 +7,14 @@ import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.features.FeatureFactory;
|
||||
import me.wiefferink.areashop.features.signs.SignsModule;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.CommandManager;
|
||||
import me.wiefferink.areashop.managers.FeatureManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.SignErrorLogger;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.nms.NMS;
|
||||
import me.wiefferink.areashop.regions.ImportJobFactory;
|
||||
import me.wiefferink.areashop.regions.RegionModule;
|
||||
@@ -24,46 +22,41 @@ import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AreaShopModule extends AbstractModule {
|
||||
|
||||
private final AreaShop instance;
|
||||
private final BukkitInterface bukkitInterface;
|
||||
private final WorldGuardInterface worldGuardInterface;
|
||||
private final WorldEditInterface worldEditInterface;
|
||||
private final NMS nms;
|
||||
private final MessageBridge messageBridge;
|
||||
private final SignErrorLogger signErrorLogger;
|
||||
private final DependencyModule dependencyModule;
|
||||
private final AbstractModule[] extras;
|
||||
|
||||
public AreaShopModule(@Nonnull AreaShop instance,
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull NMS nms,
|
||||
@Nonnull BukkitInterface bukkitInterface,
|
||||
@Nonnull WorldEditInterface worldEditInterface,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface,
|
||||
@Nonnull SignErrorLogger signErrorLogger,
|
||||
@Nonnull DependencyModule dependencyModule
|
||||
@Nonnull AbstractModule... extras
|
||||
) {
|
||||
this.instance = instance;
|
||||
this.messageBridge = messageBridge;
|
||||
this.nms = nms;
|
||||
this.signErrorLogger = signErrorLogger;
|
||||
this.bukkitInterface = bukkitInterface;
|
||||
this.worldEditInterface = worldEditInterface;
|
||||
this.worldGuardInterface = worldGuardInterface;
|
||||
this.dependencyModule = dependencyModule;
|
||||
this.extras = extras;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(this.dependencyModule);
|
||||
Arrays.stream(this.extras).forEach(this::install);
|
||||
bind(Plugin.class).toInstance(this.instance);
|
||||
bind(AreaShop.class).toInstance(this.instance);
|
||||
bind(MessageBridge.class).toInstance(this.messageBridge);
|
||||
bind(NMS.class).toInstance(this.nms);
|
||||
bind(BlockBehaviourHelper.class).toInstance(this.nms.blockBehaviourHelper());
|
||||
bind(BukkitInterface.class).toInstance(this.bukkitInterface);
|
||||
bind(WorldGuardInterface.class).toInstance(this.worldGuardInterface);
|
||||
bind(WorldEditInterface.class).toInstance(this.worldEditInterface);
|
||||
bind(SignErrorLogger.class).toInstance(this.signErrorLogger);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.wiefferink.areashop.modules;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import me.wiefferink.areashop.adapters.platform.MinecraftPlatform;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.nms.NMS;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlatformModule extends AbstractModule {
|
||||
|
||||
private final MinecraftPlatform minecraftPlatform;
|
||||
private final NMS nms;
|
||||
|
||||
public PlatformModule(@NotNull MinecraftPlatform platform,
|
||||
@NotNull NMS nms) {
|
||||
this.minecraftPlatform = platform;
|
||||
this.nms = nms;
|
||||
}
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(MinecraftPlatform.class).toInstance(this.minecraftPlatform);
|
||||
bind(OfflinePlayerHelper.class).toInstance(this.minecraftPlatform.offlinePlayerHelper());
|
||||
bind(NMS.class).toInstance(this.nms);
|
||||
bind(BlockBehaviourHelper.class).toInstance(this.nms.blockBehaviourHelper());
|
||||
bind(BukkitSchedulerExecutor.class).asEagerSingleton();
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,21 @@ public class BuyRegion extends GeneralRegion {
|
||||
this.economy = economy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwner(UUID player) {
|
||||
return isBuyer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getOwner() {
|
||||
return getBuyer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(UUID player) {
|
||||
setBuyer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionType getType() {
|
||||
return RegionType.BUY;
|
||||
@@ -237,31 +252,20 @@ public class BuyRegion extends GeneralRegion {
|
||||
|
||||
@Override
|
||||
public Object provideReplacement(String variable) {
|
||||
switch(variable) {
|
||||
case AreaShop.tagPrice:
|
||||
return getFormattedPrice();
|
||||
case AreaShop.tagRawPrice:
|
||||
return getPrice();
|
||||
case AreaShop.tagPlayerName:
|
||||
return getPlayerName();
|
||||
case AreaShop.tagPlayerUUID:
|
||||
return getBuyer();
|
||||
case AreaShop.tagResellPrice:
|
||||
return getFormattedResellPrice();
|
||||
case AreaShop.tagRawResellPrice:
|
||||
return getResellPrice();
|
||||
case AreaShop.tagMoneyBackAmount:
|
||||
return getFormattedMoneyBackAmount();
|
||||
case AreaShop.tagRawMoneyBackAmount:
|
||||
return getMoneyBackAmount();
|
||||
case AreaShop.tagMoneyBackPercentage:
|
||||
return getMoneyBackPercentage() % 1.0 == 0.0 ? (int)getMoneyBackPercentage() : getMoneyBackPercentage();
|
||||
case AreaShop.tagMaxInactiveTime:
|
||||
return this.getFormattedInactiveTimeUntilSell();
|
||||
|
||||
default:
|
||||
return super.provideReplacement(variable);
|
||||
}
|
||||
return switch (variable) {
|
||||
case AreaShop.tagPrice -> getFormattedPrice();
|
||||
case AreaShop.tagRawPrice -> getPrice();
|
||||
case AreaShop.tagPlayerName -> getPlayerName();
|
||||
case AreaShop.tagPlayerUUID -> getBuyer();
|
||||
case AreaShop.tagResellPrice -> getFormattedResellPrice();
|
||||
case AreaShop.tagRawResellPrice -> getResellPrice();
|
||||
case AreaShop.tagMoneyBackAmount -> getFormattedMoneyBackAmount();
|
||||
case AreaShop.tagRawMoneyBackAmount -> getMoneyBackAmount();
|
||||
case AreaShop.tagMoneyBackPercentage ->
|
||||
getMoneyBackPercentage() % 1.0 == 0.0 ? (int) getMoneyBackPercentage() : getMoneyBackPercentage();
|
||||
case AreaShop.tagMaxInactiveTime -> this.getFormattedInactiveTimeUntilSell();
|
||||
default -> super.provideReplacement(variable);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,7 +483,7 @@ public class BuyRegion extends GeneralRegion {
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean sell(boolean giveMoneyBack, CommandSender executor) {
|
||||
boolean own = executor instanceof Player && this.isBuyer((Player)executor);
|
||||
boolean own = executor instanceof Player player && this.isBuyer(player);
|
||||
if(executor != null) {
|
||||
if(!executor.hasPermission("areashop.sell") && !own) {
|
||||
message(executor, "sell-noPermissionOther");
|
||||
@@ -534,7 +538,7 @@ public class BuyRegion extends GeneralRegion {
|
||||
|
||||
// Give back the money
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(getBuyer());
|
||||
if(player != null && !noPayBack) {
|
||||
if(player.hasPlayedBefore() && !noPayBack) {
|
||||
EconomyResponse response = null;
|
||||
boolean error = false;
|
||||
try {
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.awt.geom.Area;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -45,6 +46,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public abstract class GeneralRegion implements GeneralRegionInterface, Comparable<GeneralRegion>, ReplacementProvider {
|
||||
|
||||
@@ -433,33 +435,18 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
* @param player Player to check ownership for
|
||||
* @return true if the player currently rents or buys this region
|
||||
*/
|
||||
public boolean isOwner(UUID player) {
|
||||
return (this instanceof RentRegion && ((RentRegion)this).isRenter(player)) || (this instanceof BuyRegion && ((BuyRegion)this).isBuyer(player));
|
||||
}
|
||||
public abstract boolean isOwner(UUID player);
|
||||
|
||||
/**
|
||||
* Get the player that is currently the owner of this region (either bought or rented it).
|
||||
* @return The UUID of the owner of this region
|
||||
*/
|
||||
public UUID getOwner() {
|
||||
if(this instanceof RentRegion) {
|
||||
return ((RentRegion)this).getRenter();
|
||||
} else {
|
||||
return ((BuyRegion)this).getBuyer();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract UUID getOwner();
|
||||
/**
|
||||
* Change the owner of the region.
|
||||
* @param player The player that should be the owner
|
||||
*/
|
||||
public void setOwner(UUID player) {
|
||||
if(this instanceof RentRegion) {
|
||||
((RentRegion)this).setRenter(player);
|
||||
} else {
|
||||
((BuyRegion)this).setBuyer(player);
|
||||
}
|
||||
}
|
||||
public abstract void setOwner(UUID player);
|
||||
|
||||
/**
|
||||
* Get the landlord of this region (the player that receives any revenue from this region).
|
||||
@@ -478,7 +465,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
if(landlordName != null && !landlordName.isEmpty()) {
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(landlordName);
|
||||
if(offlinePlayer != null) {
|
||||
if(offlinePlayer.hasPlayedBefore()) {
|
||||
return offlinePlayer.getUniqueId();
|
||||
}
|
||||
}
|
||||
@@ -491,7 +478,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
*/
|
||||
public String getLandlordName() {
|
||||
String result = Utils.toName(getLandlord());
|
||||
if(result == null || result.isEmpty()) {
|
||||
if(result.isEmpty()) {
|
||||
result = config.getString("general.landlordName");
|
||||
if(result == null || result.isEmpty()) {
|
||||
result = null;
|
||||
@@ -510,7 +497,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
setSetting("general.landlord", landlord.toString());
|
||||
}
|
||||
String properName = Utils.toName(landlord);
|
||||
if(properName == null) {
|
||||
if(properName.isBlank()) {
|
||||
properName = name;
|
||||
}
|
||||
setSetting("general.landlordName", properName);
|
||||
@@ -628,86 +615,96 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
|
||||
@Override
|
||||
public Object provideReplacement(String variable) {
|
||||
switch(variable) {
|
||||
switch (variable) {
|
||||
|
||||
// Basics
|
||||
case AreaShop.tagRegionName:
|
||||
case AreaShop.tagRegionName -> {
|
||||
return getName();
|
||||
case AreaShop.tagRegionType:
|
||||
}
|
||||
case AreaShop.tagRegionType -> {
|
||||
return getType().getValue().toLowerCase();
|
||||
case AreaShop.tagWorldName:
|
||||
}
|
||||
case AreaShop.tagWorldName -> {
|
||||
return getWorldName();
|
||||
case AreaShop.tagWidth:
|
||||
}
|
||||
case AreaShop.tagWidth -> {
|
||||
return getWidth();
|
||||
case AreaShop.tagDepth:
|
||||
}
|
||||
case AreaShop.tagDepth -> {
|
||||
return getDepth();
|
||||
case AreaShop.tagHeight:
|
||||
}
|
||||
case AreaShop.tagHeight -> {
|
||||
return getHeight();
|
||||
case AreaShop.tagFriends:
|
||||
}
|
||||
case AreaShop.tagFriends -> {
|
||||
return Utils.createCommaSeparatedList(getFriendsFeature().getFriendNames());
|
||||
case AreaShop.tagFriendsUUID:
|
||||
}
|
||||
case AreaShop.tagFriendsUUID -> {
|
||||
return Utils.createCommaSeparatedList(getFriendsFeature().getFriends());
|
||||
case AreaShop.tagLandlord:
|
||||
}
|
||||
case AreaShop.tagLandlord -> {
|
||||
return getLandlordName();
|
||||
case AreaShop.tagLandlordUUID:
|
||||
}
|
||||
case AreaShop.tagLandlordUUID -> {
|
||||
return getLandlord();
|
||||
case AreaShop.tagVolume:
|
||||
}
|
||||
case AreaShop.tagVolume -> {
|
||||
return getVolume();
|
||||
}
|
||||
|
||||
// Date/time
|
||||
case AreaShop.tagEpoch:
|
||||
case AreaShop.tagEpoch -> {
|
||||
return Calendar.getInstance().getTimeInMillis();
|
||||
case AreaShop.tagMillisecond:
|
||||
}
|
||||
case AreaShop.tagMillisecond -> {
|
||||
return Calendar.getInstance().get(Calendar.MILLISECOND);
|
||||
case AreaShop.tagSecond:
|
||||
}
|
||||
case AreaShop.tagSecond -> {
|
||||
return Calendar.getInstance().get(Calendar.SECOND);
|
||||
case AreaShop.tagMinute:
|
||||
}
|
||||
case AreaShop.tagMinute -> {
|
||||
return Calendar.getInstance().get(Calendar.MINUTE);
|
||||
case AreaShop.tagHour:
|
||||
}
|
||||
case AreaShop.tagHour -> {
|
||||
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
||||
case AreaShop.tagDay:
|
||||
}
|
||||
case AreaShop.tagDay -> {
|
||||
return Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
|
||||
case AreaShop.tagMonth:
|
||||
}
|
||||
case AreaShop.tagMonth -> {
|
||||
return Calendar.getInstance().get(Calendar.MONTH) + 1;
|
||||
case AreaShop.tagYear:
|
||||
}
|
||||
case AreaShop.tagYear -> {
|
||||
return Calendar.getInstance().get(Calendar.YEAR);
|
||||
case AreaShop.tagDateTime:
|
||||
}
|
||||
case AreaShop.tagDateTime -> {
|
||||
return new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat")).format(Calendar.getInstance().getTime());
|
||||
case AreaShop.tagDateTimeShort:
|
||||
}
|
||||
case AreaShop.tagDateTimeShort -> {
|
||||
return new SimpleDateFormat(plugin.getConfig().getString("timeFormatSign")).format(Calendar.getInstance().getTime());
|
||||
}
|
||||
|
||||
// Teleport locations
|
||||
default:
|
||||
default -> {
|
||||
Location tp = getTeleportFeature().getTeleportLocation();
|
||||
if(tp == null) {
|
||||
if (tp == null) {
|
||||
return null;
|
||||
}
|
||||
switch(variable) {
|
||||
case AreaShop.tagTeleportBlockX:
|
||||
return tp.getBlockX();
|
||||
case AreaShop.tagTeleportBlockY:
|
||||
return tp.getBlockY();
|
||||
case AreaShop.tagTeleportBlockZ:
|
||||
return tp.getBlockZ();
|
||||
case AreaShop.tagTeleportX:
|
||||
return tp.getX();
|
||||
case AreaShop.tagTeleportY:
|
||||
return tp.getY();
|
||||
case AreaShop.tagTeleportZ:
|
||||
return tp.getZ();
|
||||
case AreaShop.tagTeleportPitch:
|
||||
return tp.getPitch();
|
||||
case AreaShop.tagTeleportYaw:
|
||||
return tp.getYaw();
|
||||
case AreaShop.tagTeleportPitchRound:
|
||||
return Math.round(tp.getPitch());
|
||||
case AreaShop.tagTeleportYawRound:
|
||||
return Math.round(tp.getYaw());
|
||||
case AreaShop.tagTeleportWorld:
|
||||
return tp.getWorld().getName();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch (variable) {
|
||||
case AreaShop.tagTeleportBlockX -> tp.getBlockX();
|
||||
case AreaShop.tagTeleportBlockY -> tp.getBlockY();
|
||||
case AreaShop.tagTeleportBlockZ -> tp.getBlockZ();
|
||||
case AreaShop.tagTeleportX -> tp.getX();
|
||||
case AreaShop.tagTeleportY -> tp.getY();
|
||||
case AreaShop.tagTeleportZ -> tp.getZ();
|
||||
case AreaShop.tagTeleportPitch -> tp.getPitch();
|
||||
case AreaShop.tagTeleportYaw -> tp.getYaw();
|
||||
case AreaShop.tagTeleportPitchRound -> Math.round(tp.getPitch());
|
||||
case AreaShop.tagTeleportYawRound -> Math.round(tp.getYaw());
|
||||
case AreaShop.tagTeleportWorld -> tp.getWorld().getName();
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,11 +793,9 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
File saveFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName);
|
||||
// Create parent directories
|
||||
File parent = saveFile.getParentFile();
|
||||
if(parent != null && !parent.exists()) {
|
||||
if(!parent.mkdirs()) {
|
||||
AreaShop.warn("Did not save region " + getName() + ", schematic directory could not be created: " + saveFile.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
if(parent != null && !parent.exists() && !parent.mkdirs()) {
|
||||
AreaShop.warn("Did not save region " + getName() + ", schematic directory could not be created: " + saveFile.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
boolean result = worldEditInterface.saveRegionBlocks(saveFile, this);
|
||||
if(result) {
|
||||
@@ -809,6 +804,38 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all blocks in a region for restoring later.
|
||||
* @param fileName The name of the file to save to (extension and folder will be added)
|
||||
* @return true if the region has been saved properly, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> saveRegionBlocksAsync(String fileName) {
|
||||
if (!worldEditInterface.supportsAsyncOperations()) {
|
||||
return CompletableFuture.completedFuture(saveRegionBlocks(fileName));
|
||||
}
|
||||
// Check if the region is correct
|
||||
ProtectedRegion region = getRegion();
|
||||
if(region == null) {
|
||||
AreaShop.debug("Region '" + getName() + "' does not exist in WorldGuard, save failed");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
// The path to save the schematic
|
||||
File saveFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName);
|
||||
// Create parent directories
|
||||
File parent = saveFile.getParentFile();
|
||||
if(parent != null && !parent.exists() && !parent.mkdirs()) {
|
||||
AreaShop.warn("Did not save region " + getName() + ", schematic directory could not be created: " + saveFile.getAbsolutePath());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
return worldEditInterface.saveRegionBlocksAsync(saveFile, this)
|
||||
.thenApply(result -> {
|
||||
if(Boolean.TRUE.equals(result)) {
|
||||
AreaShop.debug("Saved schematic async for region " + getName());
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore all blocks in a region for restoring later.
|
||||
* @param fileName The name of the file to save to (extension and folder will be added)
|
||||
@@ -831,6 +858,35 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore all blocks in a region for restoring later.
|
||||
* @param fileName The name of the file to save to (extension and folder will be added)
|
||||
* @return true if the region has been restored properly, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> restoreRegionBlocksAsync(String fileName) {
|
||||
if (!worldEditInterface.supportsAsyncOperations()) {
|
||||
return CompletableFuture.completedFuture(restoreRegionBlocks(fileName));
|
||||
}
|
||||
if(getRegion() == null) {
|
||||
AreaShop.debug("Region '" + getName() + "' does not exist in WorldGuard, restore failed");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
// The path to save the schematic
|
||||
File restoreFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName);
|
||||
return worldEditInterface.restoreRegionBlocksAsync(restoreFile, this)
|
||||
.thenApply(result -> {
|
||||
if(Boolean.TRUE.equals(result)) {
|
||||
AreaShop.debug("Restored schematic async for region " + getName());
|
||||
// Sync back to main
|
||||
Do.syncLater(10, getSignsFeature().signManager()::update);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reset all flags of the region.
|
||||
*/
|
||||
@@ -910,7 +966,6 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
if(found) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if(this.getFileManager().getRegionSettings().isString(path)) {
|
||||
return this.getFileManager().getRegionSettings().getString(path).equalsIgnoreCase("true");
|
||||
}
|
||||
@@ -1419,8 +1474,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
public boolean matchesLimitGroup(String group) {
|
||||
List<String> worlds = plugin.getConfig().getStringList("limitGroups." + group + ".worlds");
|
||||
List<String> groups = plugin.getConfig().getStringList("limitGroups." + group + ".groups");
|
||||
if((worlds == null || worlds.isEmpty() || worlds.contains(getWorldName()))) {
|
||||
if(groups == null || groups.isEmpty()) {
|
||||
if(worlds.isEmpty() || worlds.contains(getWorldName())) {
|
||||
if(groups.isEmpty()) {
|
||||
return true;
|
||||
} else {
|
||||
boolean inGroups = false;
|
||||
@@ -1452,14 +1507,23 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
String save = profileSection.getString(type.getValue() + ".save");
|
||||
String restore = profileSection.getString(type.getValue() + ".restore");
|
||||
// Save the region if needed
|
||||
if(save != null && !save.isEmpty()) {
|
||||
boolean async = worldEditInterface.supportsAsyncOperations();
|
||||
if(save != null && !save.isBlank()) {
|
||||
save = Message.fromString(save).replacements(this).getSingle();
|
||||
saveRegionBlocks(save);
|
||||
if (async) {
|
||||
saveRegionBlocksAsync(save);
|
||||
} else {
|
||||
saveRegionBlocks(save);
|
||||
}
|
||||
}
|
||||
// Restore the region if needed
|
||||
if(restore != null && !restore.isEmpty()) {
|
||||
if(restore != null && !restore.isBlank()) {
|
||||
restore = Message.fromString(restore).replacements(this).getSingle();
|
||||
restoreRegionBlocks(restore);
|
||||
if (async) {
|
||||
restoreRegionBlocksAsync(restore);
|
||||
} else {
|
||||
restoreRegionBlocks(restore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -393,8 +393,7 @@ public class ImportJob {
|
||||
|
||||
// Set rented until
|
||||
if(from.isLong("info.last-withdrawal")
|
||||
&& region instanceof RentRegion) {
|
||||
RentRegion rentRegion = (RentRegion)region;
|
||||
&& region instanceof RentRegion rentRegion) {
|
||||
long lastWithdrawal = from.getLong("info.last-withdrawal");
|
||||
// Because the rental duration is already imported into the region and its parents this should be correct
|
||||
rentRegion.setRentedUntil(lastWithdrawal + rentRegion.getDuration());
|
||||
@@ -445,7 +444,7 @@ public class ImportJob {
|
||||
}
|
||||
}
|
||||
|
||||
private static final List<TimeUnit> timeUnitLookup = new ArrayList<TimeUnit>() {
|
||||
private static final List<TimeUnit> timeUnitLookup = new ArrayList<>() {
|
||||
{
|
||||
add(new TimeUnit(60 * 24 * 30 * 12, "year"));
|
||||
add(new TimeUnit(60 * 24 * 30, "month"));
|
||||
|
||||
@@ -72,6 +72,22 @@ public class RentRegion extends GeneralRegion {
|
||||
this.economy = economy;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isOwner(UUID player) {
|
||||
return isRenter(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getOwner() {
|
||||
return getRenter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(UUID player) {
|
||||
setRenter(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionType getType() {
|
||||
return RegionType.RENT;
|
||||
@@ -165,43 +181,28 @@ public class RentRegion extends GeneralRegion {
|
||||
|
||||
@Override
|
||||
public Object provideReplacement(String variable) {
|
||||
switch(variable) {
|
||||
case AreaShop.tagPrice:
|
||||
return getFormattedPrice();
|
||||
case AreaShop.tagRawPrice:
|
||||
return getPrice();
|
||||
case AreaShop.tagDuration:
|
||||
return getDurationString();
|
||||
case AreaShop.tagPlayerName:
|
||||
return getPlayerName();
|
||||
case AreaShop.tagPlayerUUID:
|
||||
return getRenter();
|
||||
case AreaShop.tagRentedUntil:
|
||||
return new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat")).format(new Date(getRentedUntil()));
|
||||
case AreaShop.tagRentedUntilShort:
|
||||
return new SimpleDateFormat(plugin.getConfig().getString("timeFormatSign")).format(new Date(getRentedUntil()));
|
||||
case AreaShop.tagTimeLeft:
|
||||
return getTimeLeftString();
|
||||
case AreaShop.tagMoneyBackAmount:
|
||||
return getFormattedMoneyBackAmount();
|
||||
case AreaShop.tagRawMoneyBackAmount:
|
||||
return getMoneyBackAmount();
|
||||
case AreaShop.tagMoneyBackPercentage:
|
||||
return (getMoneyBackPercentage() % 1.0) == 0.0 ? (int)getMoneyBackPercentage() : getMoneyBackPercentage();
|
||||
case AreaShop.tagTimesExtended:
|
||||
return this.getTimesExtended();
|
||||
case AreaShop.tagMaxExtends:
|
||||
return this.getMaxExtends();
|
||||
case AreaShop.tagExtendsLeft:
|
||||
return getMaxExtends() - getTimesExtended();
|
||||
case AreaShop.tagMaxRentTime:
|
||||
return millisToHumanFormat(getMaxRentTime());
|
||||
case AreaShop.tagMaxInactiveTime:
|
||||
return this.getFormattedInactiveTimeUntilUnrent();
|
||||
|
||||
default:
|
||||
return super.provideReplacement(variable);
|
||||
}
|
||||
return switch (variable) {
|
||||
case AreaShop.tagPrice -> getFormattedPrice();
|
||||
case AreaShop.tagRawPrice -> getPrice();
|
||||
case AreaShop.tagDuration -> getDurationString();
|
||||
case AreaShop.tagPlayerName -> getPlayerName();
|
||||
case AreaShop.tagPlayerUUID -> getRenter();
|
||||
case AreaShop.tagRentedUntil ->
|
||||
new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat")).format(new Date(getRentedUntil()));
|
||||
case AreaShop.tagRentedUntilShort ->
|
||||
new SimpleDateFormat(plugin.getConfig().getString("timeFormatSign")).format(new Date(getRentedUntil()));
|
||||
case AreaShop.tagTimeLeft -> getTimeLeftString();
|
||||
case AreaShop.tagMoneyBackAmount -> getFormattedMoneyBackAmount();
|
||||
case AreaShop.tagRawMoneyBackAmount -> getMoneyBackAmount();
|
||||
case AreaShop.tagMoneyBackPercentage ->
|
||||
(getMoneyBackPercentage() % 1.0) == 0.0 ? (int) getMoneyBackPercentage() : getMoneyBackPercentage();
|
||||
case AreaShop.tagTimesExtended -> this.getTimesExtended();
|
||||
case AreaShop.tagMaxExtends -> this.getMaxExtends();
|
||||
case AreaShop.tagExtendsLeft -> getMaxExtends() - getTimesExtended();
|
||||
case AreaShop.tagMaxRentTime -> millisToHumanFormat(getMaxRentTime());
|
||||
case AreaShop.tagMaxInactiveTime -> this.getFormattedInactiveTimeUntilUnrent();
|
||||
default -> super.provideReplacement(variable);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -672,10 +673,10 @@ public class RentRegion extends GeneralRegion {
|
||||
}
|
||||
|
||||
// Broadcast and check event
|
||||
UnrentingRegionEvent event = new UnrentingRegionEvent(this);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(event.isCancelled()) {
|
||||
message(executor, "general-cancelled", event.getReason());
|
||||
UnrentingRegionEvent unrentingRegionEvent = new UnrentingRegionEvent(this);
|
||||
Bukkit.getPluginManager().callEvent(unrentingRegionEvent);
|
||||
if(unrentingRegionEvent.isCancelled()) {
|
||||
message(executor, "general-cancelled", unrentingRegionEvent.getReason());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -729,13 +730,17 @@ public class RentRegion extends GeneralRegion {
|
||||
// Remove friends, the owner and renteduntil values
|
||||
getFriendsFeature().clearFriends();
|
||||
UUID oldRenter = getRenter();
|
||||
setRenter(null);
|
||||
setRentedUntil(null);
|
||||
setTimesExtended(-1);
|
||||
removeLastActiveTime();
|
||||
|
||||
// Notify about updates
|
||||
this.notifyAndUpdate(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack)));
|
||||
Bukkit.getPluginManager().callEvent(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack)));
|
||||
// Placed here so when event is passed, the player renting can still be accessed
|
||||
setRenter(null);
|
||||
// Update world (has to be after setting renter to null)
|
||||
this.update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package me.wiefferink.areashop.tools;
|
||||
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class BukkitSchedulerExecutor implements Executor {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final BukkitScheduler scheduler;
|
||||
|
||||
@Inject
|
||||
public BukkitSchedulerExecutor(@NotNull Plugin plugin, @NotNull BukkitScheduler scheduler) {
|
||||
this.plugin = plugin;
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull Runnable command) {
|
||||
this.scheduler.runTask(this.plugin, command);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package me.wiefferink.areashop.tools;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
|
||||
/**
|
||||
* Sign Utilities class
|
||||
*/
|
||||
public final class SignUtils {
|
||||
|
||||
private SignUtils() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link BlockFace} of a sign block
|
||||
* If the passed {@link Block} is not an instance of either
|
||||
* a {@link Sign} or {@link WallSign}, this method will return <code>null</code>
|
||||
*
|
||||
* @param block The sign
|
||||
* @return Returns the {@link BlockFace} of the sign or <code>null</code>
|
||||
*/
|
||||
public static BlockFace getSignFacing(Block block) {
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockState blockState = block.getState();
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if (blockData instanceof WallSign wallSign) {
|
||||
return wallSign.getFacing();
|
||||
} else if (blockData instanceof org.bukkit.block.data.type.Sign sign) {
|
||||
return sign.getRotation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link BlockFace} in which the sign will face
|
||||
* If the passed {@link Block} is not an instance of either
|
||||
* a {@link Sign} or {@link WallSign}, this method will return <code>null</code>.
|
||||
*
|
||||
* @param block The sign block
|
||||
* @param facing The new {@link BlockFace} the sign should face
|
||||
* @return Returns <code>true</code> if the sign was successfully placed, <code>false</code> otherwise
|
||||
*/
|
||||
public static boolean setSignFacing(Block block, BlockFace facing) {
|
||||
if (block == null || facing == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockState blockState = block.getState();
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if (blockData instanceof WallSign wallSign) {
|
||||
wallSign.setFacing(facing);
|
||||
} else if (blockData instanceof org.bukkit.block.data.type.Sign sign) {
|
||||
sign.setRotation(facing);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
block.setBlockData(blockData);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Block} which a given sign is attached to.
|
||||
* This method will return <code>null</code> if the passed {@link Block}
|
||||
* is not an instance of either a {@link Sign} or {@link WallSign}.
|
||||
*
|
||||
* @param block The sign {@link Block}
|
||||
* @return Returns the block which the sign is attached to or null
|
||||
*/
|
||||
public static Block getSignAttachedTo(Block block) {
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockState blockState = block.getState();
|
||||
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if (blockData instanceof WallSign wallSign) {
|
||||
return block.getRelative(wallSign.getFacing().getOppositeFace());
|
||||
} else if (blockData instanceof Sign) {
|
||||
return block.getRelative(BlockFace.DOWN);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package me.wiefferink.areashop.tools;
|
||||
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SpigotOfflinePlayerHelper implements OfflinePlayerHelper {
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
public SpigotOfflinePlayerHelper(@NotNull Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Optional<UUID>> lookupUuidAsync(String username) {
|
||||
return lookupOfflinePlayerAsync(username).thenApply(player -> {
|
||||
if (player.hasPlayedBefore()) {
|
||||
return Optional.of(player.getUniqueId());
|
||||
}
|
||||
return Optional.empty();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<OfflinePlayer> lookupOfflinePlayerAsync(String username) {
|
||||
final CompletableFuture<OfflinePlayer> future = new CompletableFuture<>();
|
||||
final Server server = this.plugin.getServer();
|
||||
server.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer player = server.getOfflinePlayer(username);
|
||||
future.complete(player);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package me.wiefferink.areashop.tools;
|
||||
|
||||
import me.wiefferink.areashop.adapters.platform.MinecraftPlatform;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SpigotPlatform implements MinecraftPlatform {
|
||||
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
public SpigotPlatform(@NotNull Plugin plugin) {
|
||||
this.offlinePlayerHelper = new SpigotOfflinePlayerHelper(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayerHelper offlinePlayerHelper() {
|
||||
return this.offlinePlayerHelper;
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,10 @@ debug: false
|
||||
version: ${project.version}
|
||||
# Maximum number of blocks to save to or restore from a .schemetic file.
|
||||
maximumBlocks: 1000000
|
||||
# Whether to forcefully clear "hanging" entities (painting, itemframes, etc.) on region restore
|
||||
# Only enable this option if hanging entities at the destination aren't removed on restore normally
|
||||
# If set to true, there may be a performance impact when performing region restores.
|
||||
forceClearEntities: false
|
||||
# Maximum number of locations the teleport function should check to find a safe spot.
|
||||
maximumTries: 50000
|
||||
|
||||
|
||||
@@ -619,7 +619,7 @@ greeting-resale: "%region% can be bought for %resellprice% from %player%."
|
||||
|
||||
update-playerNotify:
|
||||
- "[darkgreen]Update from AreaShop V%0% to AreaShop V%1% available, get the latest version at "
|
||||
- "[bold]Spigot[/bold]"
|
||||
- " hover: %lang:action|Go to the Spigot AreaShop page|%"
|
||||
- " link: https://www.spigotmc.org/resources/areashop.2991/"
|
||||
- "[bold]Github[/bold]"
|
||||
- " hover: %lang:action|Go to the AreaShop Github Releases|%"
|
||||
- " link: https://github.com/md5sha256/releases"
|
||||
- " (and leave a review)."
|
||||
@@ -1,11 +1,11 @@
|
||||
name: AreaShop
|
||||
main: me.wiefferink.areashop.AreaShop
|
||||
version: "@version@"
|
||||
version: "${version}"
|
||||
description: "Selling and renting WorldGuard regions to your players, highly configurable."
|
||||
depend: [Vault, WorldGuard, WorldEdit]
|
||||
softdepend: [Multiverse-Core, FastAsyncWorldEdit]
|
||||
author: NLThijs48
|
||||
website: https://github.com/NLthijs48/AreaShop
|
||||
website: https://github.com/md5sha256/AreaShop
|
||||
commands:
|
||||
AreaShop:
|
||||
description: 'For all commands use /as help.'
|
||||
@@ -13,7 +13,7 @@ commands:
|
||||
aliases: [as]
|
||||
awareness:
|
||||
- !@UTF8
|
||||
api-version: 1.13
|
||||
api-version: 1.17
|
||||
permissions:
|
||||
areashop.*:
|
||||
description: Give access to all commands of AreaShop
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<br/>
|
||||
**Usage and configuration:**
|
||||
[►Download (releases)](https://github.com/NLthijs48/AreaShop/releases)
|
||||
[►Download (releases)](https://github.com/md5sha256/AreasShop/releases)
|
||||
[►Commands and Permissions](https://github.com/NLthijs48/AreaShop/wiki/Commands-and-Permissions)
|
||||
<br/>
|
||||
[►Basic regions setup](https://github.com/NLthijs48/AreaShop/wiki/Basic-regions-setup)
|
||||
@@ -14,11 +14,10 @@
|
||||
[►Frequently Asked Questions](https://github.com/NLthijs48/AreaShop/wiki/Frequently-Asked-Questions)
|
||||
[►Common errors](https://github.com/NLthijs48/AreaShop/wiki/Common-errors)<br/>
|
||||
**Support:**
|
||||
[►Request a feature, report a bug or ask support](https://github.com/NLthijs48/AreaShop/issues/new/choose)
|
||||
[►Open issues](https://github.com/NLthijs48/AreaShop/issues)<br/>
|
||||
[►Request a feature, report a bug or ask support](https://github.com/md5sha256/AreasShop/issues/new/choose)
|
||||
[►Open issues](https://github.com/md5sha256/AreasShop/issues)<br/>
|
||||
**Development:**
|
||||
[►Changelog](https://github.com/NLthijs48/AreaShop/blob/master/changelog.md)
|
||||
[►Compiling](https://github.com/NLthijs48/AreaShop/wiki/Compiling-AreaShop)
|
||||
[►Compiling](https://github.com/md5sha256/AreaShop/tree/dev/bleeding/documentation/compiling.md)
|
||||
[►Modules/classes overview](https://github.com/NLthijs48/AreaShop/wiki/Modules,-packages-and-classes-overview)
|
||||
[►Javadocs](https://wiefferink.me/AreaShop/javadocs/)
|
||||
[►Development builds](http://jenkins.wiefferink.me/job/AreaShop)<br/>
|
||||
@@ -26,7 +25,19 @@
|
||||
[►AreaShop in Spigot Resources](http://www.spigotmc.org/resources/areashop.2991/)
|
||||
[►AreaShop on BukkitDev](http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/)
|
||||
|
||||
***
|
||||
### Required dependencies
|
||||
* Java 17 or higher (latest recommended)
|
||||
* Bukkit/Spigot 1.17.2 or newer (hybrids such as Mohist are not supported)
|
||||
* [WorldGuard](http://dev.bukkit.org/bukkit-plugins/worldguard/): 7.0.7 or newer
|
||||
* [WorldEdit](http://dev.bukkit.org/bukkit-plugins/worldedit/): 7.2.12 or newer
|
||||
* [Vault](http://dev.bukkit.org/bukkit-plugins/vault/): 1.7.3 or higher
|
||||
* An economy plugin supported by Vault (check the [Vault page](http://dev.bukkit.org/bukkit-plugins/vault/) for a list of these)
|
||||
|
||||
### Optional Dependencies
|
||||
* [FastAsyncWorldEdit](https://www.spigotmc.org/resources/fastasyncworldedit.13932/) 2.4.5 or newer (Note: Use either FAWE or WE, not both together)
|
||||
* AreaShop has a separate adapter for FAWE which leverages its support for asynchronous edit operations. This adapter is used for region saving and restoring.
|
||||
* Note that schematics created by the FAWE adapter are not compatible with normal WorldEdit; however, schematics created by the normal WorldEdit adapter are compatible with FAWE
|
||||
* Due to a bug with FAWE, entities are not saved by the FAWE adapter but are saved in the normal WE adapter
|
||||
|
||||
AreaShop allows you selling and renting regions to players. It could be used to let them rent a jail in your prison server, a shop in the market of the survival server or a plot on a creative server. The player interacts with signs, making it easy to use. It also has a lot of commands to check the status of all regions, manage the renting and buying of a region and also features for admins. A lot of messages send to the player can be clicked, for immediately performing actions (buying the region, selling the region, etc.) or getting more information (for example clicking region name for region information). To setup the renting and selling of the regions exactly as you want AreaShop has a lot of options to custimize it to your liking.
|
||||
|
||||
@@ -36,7 +47,7 @@ AreaShop allows you selling and renting regions to players. It could be used to
|
||||
* 
|
||||
* Messages that can be clicked for more information and actions ([language](https://github.com/NLthijs48/AreaShop/wiki/Language-support) can be changed, as well as click/hover actions).
|
||||
* 
|
||||
* Change the of the plugin or use of of the already provided language files (check [here](https://github.com/NLthijs48/AreaShop/tree/master/AreaShop/src/main/resources/lang))
|
||||
* Change the of the plugin or use of the already provided language files (check [here](https://github.com/md5sha256/AreasShop/tree/dev/bleeding/AreaShop/src/main/resources/lang))
|
||||
* Automatically restore the region to its original state when sold: [restore](https://github.com/NLthijs48/AreaShop/wiki/Region-blocks-save-restore) the region with schematics.
|
||||
* Change which [commands](https://github.com/NLthijs48/AreaShop/wiki/Commands-and-Permissions) players can use with [permissions](https://github.com/NLthijs48/AreaShop/wiki/Commands-and-Permissions).
|
||||
* Customize the plugin by changing the [config files](https://github.com/NLthijs48/AreaShop/wiki/The-config-system).
|
||||
@@ -61,28 +72,4 @@ For a preview join 'mc.go-craft.com' and go to the Survival server, the shops ar
|
||||
**Made by [PerkulatorTime](https://www.youtube.com/user/PerkulatorTime)**<br/>
|
||||
[](https://www.youtube.com/watch?v=OQOsOG-EdNc)
|
||||
|
||||
Old video for AreaShop v1.0: [Tutorial by VariationVault](https://www.youtube.com/watch?v=k2HMCxCCOYo)
|
||||
|
||||
### Required dependencies
|
||||
* Java 7 or higher (latest recommended)
|
||||
* Bukkit/Spigot 1.7.9 or higher (modded servers often include Bukkit/Spigot support, so it should also work on that, but it is not specifically tested for it)
|
||||
* [WorldGuard](http://dev.bukkit.org/bukkit-plugins/worldguard/): 5.9 or higher (6.0+ recommended)
|
||||
* [WorldEdit](http://dev.bukkit.org/bukkit-plugins/worldedit/): 5.6.3 or higher (6.0+ recommended)
|
||||
* [Vault](http://dev.bukkit.org/bukkit-plugins/vault/): 1.4.1 or higher
|
||||
* An economy plugin supported by Vault (check the [Vault page](http://dev.bukkit.org/bukkit-plugins/vault/) for a list of these)
|
||||
|
||||
### Metrics
|
||||
This plugin utilizes Hidendra's plugin metrics system, which means that the following information is collected and sent to mcstats.org:
|
||||
|
||||
*A unique identifier, the server's version of Java, whether the server is in offline or online mode, the plugin's version, the server's version, the OS version/name and architecture, the core count for the CPU, the number of players online, the Metrics version.*
|
||||
|
||||
This information will give me an indication how much the plugin is used and encourages me to continue development. Opting out of this service can be done by setting `sendStats` in the config of this plugin to `false`, if you want to disable Metrics for any plugin go to `plugins/Plugin Metrics/config.yml` and change `opt-out` to `true`. Check graphs of the statistics at this page: [mcstats.org/plugin/AreaShop](http://mcstats.org/plugin/AreaShop)
|
||||
|
||||
### Do you want to translate AreaShop?
|
||||
Help translating the plugin into different languages and to keep the translations up to date. Go to [this page](https://github.com/NLthijs48/AreaShop/wiki/Language-support#translating-on-transifex) for more information. Translating goes through the [Transifex](https://www.transifex.com/projects/p/areashop/) website and is very easy, sending files back and forth is not needed, you can translate lines online and whenever you want. Every line you translate will be saved, no need to do it all at once (this also allows for easy collaboration).
|
||||
|
||||

|
||||
|
||||
[](https://discord.gg/84kGMCQ)
|
||||
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VEECV88NG3L5C)
|
||||
Old video for AreaShop v1.0: [Tutorial by VariationVault](https://www.youtube.com/watch?v=k2HMCxCCOYo)
|
||||
@@ -0,0 +1,22 @@
|
||||
plugins.apply("io.papermc.paperweight.userdev")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.17.1-R0.1-SNAPSHOT")
|
||||
compileOnly(projects.areashopInterface)
|
||||
compileOnly(projects.areashopNms)
|
||||
}
|
||||
|
||||
|
||||
description = "AreaShop NMS Helper 1-17"
|
||||
|
||||
tasks {
|
||||
|
||||
assemble {
|
||||
dependsOn("reobfJar")
|
||||
}
|
||||
|
||||
named("reobfJar", io.papermc.paperweight.tasks.RemapJar::class) {
|
||||
outputJar.set(file("build/libs/${project.name}-${project.version}.jar"))
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.wiefferink.areashop.nms.v1_17_R1;
|
||||
package me.wiefferink.areashop.adapters.platform.v1_17_R1;
|
||||
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.wiefferink.areashop.nms.v1_17_R1;
|
||||
package me.wiefferink.areashop.adapters.platform.v1_17_R1;
|
||||
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.nms.NMS;
|
||||
@@ -0,0 +1,21 @@
|
||||
plugins.apply("io.papermc.paperweight.userdev")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
|
||||
compileOnly(projects.areashopInterface)
|
||||
compileOnly(projects.areashopNms)
|
||||
}
|
||||
|
||||
description = "AreaShop NMS Helper 1-18"
|
||||
|
||||
tasks {
|
||||
|
||||
assemble {
|
||||
dependsOn("reobfJar")
|
||||
}
|
||||
|
||||
named("reobfJar", io.papermc.paperweight.tasks.RemapJar::class) {
|
||||
outputJar.set(file("build/libs/${project.name}-${project.version}.jar"))
|
||||
}
|
||||
|
||||
}
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package me.wiefferink.areashop.nms.v1_18_R1;
|
||||
package me.wiefferink.areashop.adapters.platform.v1_18_R2;
|
||||
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -7,10 +7,10 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.wiefferink.areashop.nms.v1_18_R1;
|
||||
package me.wiefferink.areashop.adapters.platform.v1_18_R2;
|
||||
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.nms.NMS;
|
||||
@@ -0,0 +1,21 @@
|
||||
plugins.apply("io.papermc.paperweight.userdev")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.19.4-R0.1-SNAPSHOT")
|
||||
compileOnly(projects.areashopInterface)
|
||||
compileOnly(projects.areashopNms)
|
||||
}
|
||||
|
||||
description = "AreaShop NMS Helper 1-19"
|
||||
|
||||
tasks {
|
||||
|
||||
assemble {
|
||||
dependsOn("reobfJar")
|
||||
}
|
||||
|
||||
named("reobfJar", io.papermc.paperweight.tasks.RemapJar::class) {
|
||||
outputJar.set(file("build/libs/${project.name}-${project.version}.jar"))
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package me.wiefferink.areashop.adapters.platform.v1_19_R3;
|
||||
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockBehaviourImpl implements BlockBehaviourHelper {
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Location location, BlockData blockData) {
|
||||
Objects.requireNonNull(location.getWorld(), "Null World!");
|
||||
final BlockPos blockPosition = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
final CraftWorld craftWorld = (CraftWorld) location.getWorld();
|
||||
final ServerLevel world = craftWorld.getHandle();
|
||||
final CraftBlockData craftBlockData = (CraftBlockData) blockData;
|
||||
final BlockState ibd = craftBlockData.getState();
|
||||
return ibd.canSurvive(world, blockPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockValid(Block block) {
|
||||
final CraftBlock craftBlock = (CraftBlock) block;
|
||||
final CraftWorld craftWorld = (CraftWorld) craftBlock.getWorld();
|
||||
final ServerLevel world = craftWorld.getHandle();
|
||||
final BlockState ibd = craftBlock.getNMS();
|
||||
return ibd.canSurvive(world, craftBlock.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockStateValid(org.bukkit.block.BlockState blockState) {
|
||||
final CraftBlockState craftBlockState = (CraftBlockState) blockState;
|
||||
final BlockState ibd = craftBlockState.getHandle();
|
||||
return ibd.canSurvive(craftBlockState.getBlock().getCraftWorld().getHandle(), craftBlockState.getPosition());
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package me.wiefferink.areashop.adapters.platform.v1_19_R3;
|
||||
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.nms.NMS;
|
||||
|
||||
public class NMSImpl implements NMS {
|
||||
|
||||
private final BlockBehaviourImpl blockBehaviourHelper = new BlockBehaviourImpl();
|
||||
|
||||
@Override
|
||||
public BlockBehaviourHelper blockBehaviourHelper() {
|
||||
return this.blockBehaviourHelper;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
plugins.apply("io.papermc.paperweight.userdev")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.20-R0.1-SNAPSHOT")
|
||||
compileOnly(projects.areashopInterface)
|
||||
compileOnly(projects.areashopNms)
|
||||
}
|
||||
|
||||
description = "AreaShop NMS Helper 1-19"
|
||||
|
||||
tasks {
|
||||
|
||||
assemble {
|
||||
dependsOn("reobfJar")
|
||||
}
|
||||
|
||||
named("reobfJar", io.papermc.paperweight.tasks.RemapJar::class) {
|
||||
outputJar.set(file("build/libs/${project.name}-${project.version}.jar"))
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package me.wiefferink.areashop.adapters.platform.v1_20_R1;
|
||||
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockBehaviourImpl implements BlockBehaviourHelper {
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Location location, BlockData blockData) {
|
||||
Objects.requireNonNull(location.getWorld(), "Null World!");
|
||||
final BlockPos blockPosition = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
final CraftWorld craftWorld = (CraftWorld) location.getWorld();
|
||||
final ServerLevel world = craftWorld.getHandle();
|
||||
final CraftBlockData craftBlockData = (CraftBlockData) blockData;
|
||||
final BlockState ibd = craftBlockData.getState();
|
||||
return ibd.canSurvive(world, blockPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockValid(Block block) {
|
||||
final CraftBlock craftBlock = (CraftBlock) block;
|
||||
final CraftWorld craftWorld = (CraftWorld) craftBlock.getWorld();
|
||||
final ServerLevel world = craftWorld.getHandle();
|
||||
final BlockState ibd = craftBlock.getNMS();
|
||||
return ibd.canSurvive(world, craftBlock.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockStateValid(org.bukkit.block.BlockState blockState) {
|
||||
final CraftBlockState craftBlockState = (CraftBlockState) blockState;
|
||||
final BlockState ibd = craftBlockState.getHandle();
|
||||
return ibd.canSurvive(craftBlockState.getBlock().getCraftWorld().getHandle(), craftBlockState.getPosition());
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package me.wiefferink.areashop.adapters.platform.v1_20_R1;
|
||||
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.nms.NMS;
|
||||
|
||||
public class NMSImpl implements NMS {
|
||||
|
||||
private final BlockBehaviourImpl blockBehaviourHelper = new BlockBehaviourImpl();
|
||||
|
||||
@Override
|
||||
public BlockBehaviourHelper blockBehaviourHelper() {
|
||||
return this.blockBehaviourHelper;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
description = "AreaShop Paper Helper"
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(libs.paper)
|
||||
compileOnlyApi(projects.adapters.platform.platformInterface)
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package me.wiefferink.areashop.adapters.platform.paper;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class PaperOfflinePlayerHelper implements OfflinePlayerHelper {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final Server server;
|
||||
|
||||
public PaperOfflinePlayerHelper(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.server = plugin.getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Optional<UUID>> lookupUuidAsync(String username) {
|
||||
final PlayerProfile profile = this.server.createProfile(username);
|
||||
final CompletableFuture<Optional<UUID>> future = new CompletableFuture<>();
|
||||
this.server.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
profile.complete(false);
|
||||
future.complete(Optional.ofNullable(profile.getId()));
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<OfflinePlayer> lookupOfflinePlayerAsync(String username) {
|
||||
final CompletableFuture<OfflinePlayer> future = new CompletableFuture<>();
|
||||
this.server.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(username);
|
||||
future.complete(offlinePlayer);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package me.wiefferink.areashop.adapters.platform.paper;
|
||||
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.adapters.platform.MinecraftPlatform;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PaperPlatform implements MinecraftPlatform {
|
||||
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
public PaperPlatform(@NotNull Plugin plugin) {
|
||||
this.offlinePlayerHelper = new PaperOfflinePlayerHelper(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayerHelper offlinePlayerHelper() {
|
||||
return this.offlinePlayerHelper;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
description = "AreaShop Platform Interface"
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(libs.spigot)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package me.wiefferink.areashop.adapters.platform;
|
||||
|
||||
public interface MinecraftPlatform {
|
||||
|
||||
OfflinePlayerHelper offlinePlayerHelper();
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package me.wiefferink.areashop.adapters.platform;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface OfflinePlayerHelper {
|
||||
|
||||
CompletableFuture<Optional<UUID>> lookupUuidAsync(String username);
|
||||
|
||||
CompletableFuture<OfflinePlayer> lookupOfflinePlayerAsync(String username);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
dependencies {
|
||||
compileOnly(libs.spigot)
|
||||
compileOnly(projects.areashopInterface)
|
||||
compileOnly(libs.fastasyncworldeditCore) {
|
||||
exclude("net.kyori", "adventure-text-minimessage")
|
||||
}
|
||||
compileOnly(libs.fastasyncworldeditBukkit) {
|
||||
exclude("net.kyori", "adventure-text-minimessage")
|
||||
}
|
||||
compileOnly(libs.worldguardCore)
|
||||
compileOnly(libs.worldguardBukkit)
|
||||
}
|
||||
|
||||
description = "AreaShop FastAsyncWorldEdit"
|
||||
+336
@@ -0,0 +1,336 @@
|
||||
package me.wiefferink.areashop.adapters.plugins;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
||||
import com.sk89q.worldedit.function.EntityFunction;
|
||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.visitor.EntityVisitor;
|
||||
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.world.World;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
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.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Hanging;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class FastAsyncWorldEditHandler extends WorldEditInterface {
|
||||
|
||||
public FastAsyncWorldEditHandler(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsAsyncOperations() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> restoreRegionBlocksAsync(File rawFile, GeneralRegionInterface regionInterface) {
|
||||
File targetFile = null;
|
||||
for (ClipboardFormat formatOption : ClipboardFormats.getAll()) {
|
||||
for (String extension : formatOption.getFileExtensions()) {
|
||||
File fileOption = new File(rawFile.getAbsolutePath() + "." + extension);
|
||||
if (fileOption.exists()) {
|
||||
targetFile = fileOption;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (targetFile == null || !targetFile.exists() || !targetFile.isFile()) {
|
||||
pluginInterface.getLogger().info(() -> "Not restoring region. Schematic not found: " + rawFile);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
File finalFile = targetFile;
|
||||
ClipboardFormat format = ClipboardFormats.findByFile(targetFile);
|
||||
if (format == null) {
|
||||
pluginInterface.getLogger().warning(() -> "Could not find a clipboard format for file: " + finalFile.getAbsolutePath());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
BlockVector3 min = regionInterface.getRegion().getMinimumPoint();
|
||||
final World world = BukkitAdapter.adapt(regionInterface.getWorld());
|
||||
if (world == null) {
|
||||
pluginInterface.getLogger().warning(() -> "Did not restore region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
|
||||
}
|
||||
ProtectedRegion wgRegion = regionInterface.getRegion();
|
||||
long volume = wgRegion.volume();
|
||||
Region region = new CuboidRegion(wgRegion.getMinimumPoint(), wgRegion.getMaximumPoint());
|
||||
int maxBlocks = pluginInterface.getConfig().getInt("maximumBlocks", Integer.MAX_VALUE);
|
||||
if (volume > maxBlocks) {
|
||||
pluginInterface.getLogger().warning((() -> "Region is bigger than the max allowed block change size! Volume: " + volume + " Limit: " + maxBlocks));
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
pluginInterface.debugI(() -> String.format("Attempting to restore using format: %s", format.getName()));
|
||||
// Bug in which schematic pasting doesn't clear tile entities properly
|
||||
// We manually remove tile entities in the destination before we paste the schematic
|
||||
pluginInterface.debugI(() -> "Clearing entities for region: " + regionInterface.getName());
|
||||
if (pluginInterface.getConfig().getBoolean("forceClearEntities", false) && failedClearEntities(world, region, regionInterface)) {
|
||||
pluginInterface.getLogger().warning(() -> "Failed to clear tile entities for region: " + regionInterface.getName() + ". Will attempt to past anyway");
|
||||
}
|
||||
BlockVector3 dimensions = regionInterface.computeDimensions();
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(pluginInterface.pluginInstance(), () -> {
|
||||
Clipboard clipboard;
|
||||
try (InputStream is = new FileInputStream(finalFile);
|
||||
ClipboardReader reader = format.getReader(is)) {
|
||||
clipboard = reader.read();
|
||||
if (!clipboard.getDimensions().equals(dimensions)) {
|
||||
pluginInterface.getLogger().warning(() -> "Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
|
||||
pluginInterface.debugI(() -> "schematic|region, x:" + clipboard.getDimensions().getX() + "|" + regionInterface.getWidth() + ", y:" + clipboard.getDimensions().getY() + "|" + regionInterface.getHeight() + ", z:" + clipboard.getDimensions().getZ() + "|" + regionInterface.getDepth());
|
||||
future.complete(false);
|
||||
return;
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
pluginInterface.getLogger().warning("An error occurred while restoring schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
future.complete(false);
|
||||
return;
|
||||
} catch (Exception ex) {
|
||||
pluginInterface.getLogger().warning(() -> "crashed during restore of " + regionInterface.getName());
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
future.complete(false);
|
||||
return;
|
||||
}
|
||||
final EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().newEditSessionBuilder()
|
||||
.world(world)
|
||||
.build();
|
||||
final Operation operation = new ClipboardHolder(clipboard).createPaste(editSession)
|
||||
.to(min)
|
||||
.copyEntities(false) // Don't copy entities as FAWE has bug which doesn't synchronize entity access
|
||||
.build();
|
||||
future.complete(true);
|
||||
try (editSession; clipboard) {
|
||||
Operations.complete(operation);
|
||||
future.complete(true);
|
||||
} catch (WorldEditException ex) {
|
||||
pluginInterface.getLogger().warning(() -> "An error occurred while restoring schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
future.complete(false);
|
||||
}
|
||||
});
|
||||
return future;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> saveRegionBlocksAsync(File file, GeneralRegionInterface regionInterface) {
|
||||
final ClipboardFormat format = BuiltInClipboardFormat.FAST;
|
||||
final File targetFile = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
|
||||
ProtectedRegion wgRegion = regionInterface.getRegion();
|
||||
Region region = new CuboidRegion(wgRegion.getMinimumPoint(), wgRegion.getMaximumPoint());
|
||||
final World 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);
|
||||
}
|
||||
int maxBlocks = pluginInterface.getConfig().getInt("maximumBlocks", Integer.MAX_VALUE);
|
||||
long volume = region.getVolume();
|
||||
if (volume > maxBlocks) {
|
||||
pluginInterface.getLogger().warning((() -> "Region is bigger than the max allowed block change size! Volume: " + volume + " Limit: " + maxBlocks));
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
pluginInterface.debugI(() -> String.format("Trying to save region %s to file %s with format %s", regionInterface.getName(), file.getName(), format.getName()));
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(pluginInterface.pluginInstance(), () -> {
|
||||
try (OutputStream os = new FileOutputStream(targetFile);
|
||||
ClipboardWriter writer = format.getWriter(os);
|
||||
Clipboard clipboard = new BlockArrayClipboard(region)) {
|
||||
try (EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().newEditSessionBuilder()
|
||||
.world(world)
|
||||
.build()) {
|
||||
final ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
|
||||
// Don't copy entities as FAWE has bug which doesn't synchronize entity access
|
||||
copy.setCopyingEntities(false);
|
||||
Operations.complete(copy);
|
||||
}
|
||||
writer.write(clipboard);
|
||||
future.complete(true);
|
||||
return;
|
||||
} catch (IOException | WorldEditException ex) {
|
||||
pluginInterface.getLogger().warning(() -> "An error occurred while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
} catch (Exception ex) {
|
||||
pluginInterface.getLogger().warning(() -> "crashed during save of " + regionInterface.getName());
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
future.complete(false);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restoreRegionBlocks(File rawFile, GeneralRegionInterface regionInterface) {
|
||||
File targetFile = null;
|
||||
for (ClipboardFormat formatOption : ClipboardFormats.getAll()) {
|
||||
for (String extension : formatOption.getFileExtensions()) {
|
||||
File fileOption = new File(rawFile.getAbsolutePath() + "." + extension);
|
||||
if (fileOption.exists()) {
|
||||
targetFile = fileOption;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (targetFile == null || !targetFile.exists() || !targetFile.isFile()) {
|
||||
pluginInterface.getLogger().info(() -> "Not restoring region. Schematic not found: " + rawFile);
|
||||
return false;
|
||||
}
|
||||
File finalFile = targetFile;
|
||||
ClipboardFormat format = ClipboardFormats.findByFile(targetFile);
|
||||
if (format == null) {
|
||||
pluginInterface.getLogger().warning(() -> "Could not find a clipboard format for file: " + finalFile.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
BlockVector3 min = regionInterface.getRegion().getMinimumPoint();
|
||||
final World world = BukkitAdapter.adapt(regionInterface.getWorld());
|
||||
if (world == null) {
|
||||
pluginInterface.getLogger().warning(() -> "Did not restore region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
|
||||
return false;
|
||||
|
||||
}
|
||||
long volume = regionInterface.getRegion().volume();
|
||||
int maxBlocks = pluginInterface.getConfig().getInt("maximumBlocks", Integer.MAX_VALUE);
|
||||
if (volume > maxBlocks) {
|
||||
pluginInterface.getLogger().warning((() -> "Region is bigger than the max allowed block change size! Volume: " + volume + " Limit: " + maxBlocks));
|
||||
return false;
|
||||
}
|
||||
pluginInterface.debugI(String.format("Attempting to restore using format: %s", format.getName()));
|
||||
// Bug in which schematic pasting doesn't clear tile entities properly
|
||||
// We manually remove tile entities in the destination before we paste the schematic
|
||||
pluginInterface.debugI(() -> "Clearing entities for region: " + regionInterface.getName());
|
||||
ProtectedRegion wgRegion = regionInterface.getRegion();
|
||||
Region region = new CuboidRegion(wgRegion.getMinimumPoint(), wgRegion.getMaximumPoint());
|
||||
if (pluginInterface.getConfig().getBoolean("forceClearEntities", false) && failedClearEntities(world, region, regionInterface)) {
|
||||
pluginInterface.getLogger().warning(() -> "Failed to clear tile entities for region: " + regionInterface.getName() + ". Will attempt to past anyway");
|
||||
}
|
||||
BlockVector3 dimensions = regionInterface.computeDimensions();
|
||||
try (InputStream is = new FileInputStream(finalFile);
|
||||
ClipboardReader reader = format.getReader(is)) {
|
||||
Clipboard clipboard = reader.read();
|
||||
if (!clipboard.getDimensions().equals(dimensions)) {
|
||||
pluginInterface.getLogger().warning(() -> "Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
|
||||
pluginInterface.debugI(() -> "schematic|region, x:" + clipboard.getDimensions().getX() + "|" + regionInterface.getWidth() + ", y:" + clipboard.getDimensions().getY() + "|" + regionInterface.getHeight() + ", z:" + clipboard.getDimensions().getZ() + "|" + regionInterface.getDepth());
|
||||
return false;
|
||||
}
|
||||
final Operation operation = new ClipboardHolder(clipboard).createPaste(world)
|
||||
.to(min)
|
||||
.copyEntities(false)
|
||||
.build();
|
||||
Operations.complete(operation);
|
||||
return true;
|
||||
} catch (IOException | WorldEditException ex) {
|
||||
pluginInterface.getLogger().warning(() -> "An error occurred while restoring schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
} catch (Exception ex) {
|
||||
pluginInterface.getLogger().warning(() -> "crashed during restore of " + regionInterface.getName());
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
|
||||
final ClipboardFormat format = BuiltInClipboardFormat.FAST;
|
||||
final File targetFile = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
|
||||
ProtectedRegion wgRegion = regionInterface.getRegion();
|
||||
Region region = new CuboidRegion(wgRegion.getMinimumPoint(), wgRegion.getMaximumPoint());
|
||||
final World world = BukkitAdapter.adapt(regionInterface.getWorld());
|
||||
if (world == null) {
|
||||
pluginInterface.getLogger().warning("Did not save region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
|
||||
return false;
|
||||
}
|
||||
int maxBlocks = pluginInterface.getConfig().getInt("maximumBlocks", Integer.MAX_VALUE);
|
||||
long volume = region.getVolume();
|
||||
if (volume > maxBlocks) {
|
||||
pluginInterface.getLogger().warning((() -> "Region is bigger than the max allowed block change size! Volume: " + volume + " Limit: " + maxBlocks));
|
||||
return false;
|
||||
}
|
||||
pluginInterface.debugI(() -> String.format("Trying to save region %s to file %s with format %s", regionInterface.getName(), file.getName(), format.getName()));
|
||||
try (OutputStream os = new FileOutputStream(targetFile);
|
||||
ClipboardWriter writer = format.getWriter(os);
|
||||
Clipboard clipboard = new BlockArrayClipboard(region)) {
|
||||
try (EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().newEditSessionBuilder()
|
||||
.world(world)
|
||||
.build()) {
|
||||
final ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
|
||||
copy.setCopyingEntities(true);
|
||||
Operations.complete(copy);
|
||||
}
|
||||
writer.write(clipboard);
|
||||
return true;
|
||||
} catch (IOException | WorldEditException ex) {
|
||||
pluginInterface.getLogger().warning(() -> "An error occurred while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
} catch (Exception ex) {
|
||||
pluginInterface.getLogger().warning("crashed during save of " + regionInterface.getName());
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean failedClearEntities(World world, Region region, GeneralRegionInterface regionInterface) {
|
||||
try (EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().newEditSessionBuilder()
|
||||
.world(world)
|
||||
.build()) {
|
||||
EntityFunction function = entity -> {
|
||||
EntityType entityType = entity.getType();
|
||||
if (entityType != null && (entityType.equals(EntityTypes.ITEM_FRAME)
|
||||
|| entityType.equals(EntityTypes.PAINTING)
|
||||
|| entityType.equals(EntityTypes.LEASH_KNOT)) && !entity.remove()) {
|
||||
pluginInterface.debugI("Could not remove entity: " + entityType.getName());
|
||||
}
|
||||
return false;
|
||||
};
|
||||
EntityVisitor visitor = new EntityVisitor(editSession.getEntities(region).iterator(), function);
|
||||
Operations.complete(visitor);
|
||||
return false;
|
||||
} catch (WorldEditException ex) {
|
||||
pluginInterface.getLogger().warning("crashed during save of " + regionInterface.getName());
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(ex));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
dependencies {
|
||||
compileOnly(libs.spigot)
|
||||
compileOnly(projects.areashopInterface)
|
||||
compileOnly(libs.worldeditCore)
|
||||
compileOnly(libs.worldeditBukkit)
|
||||
compileOnly(libs.worldguardCore)
|
||||
}
|
||||
|
||||
description = "AreaShop WorldEdit 7"
|
||||
+221
@@ -0,0 +1,221 @@
|
||||
package me.wiefferink.areashop.adapters.plugins;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
||||
import com.sk89q.worldedit.function.EntityFunction;
|
||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.visitor.EntityVisitor;
|
||||
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.world.World;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
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 java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WorldEditHandler extends WorldEditInterface {
|
||||
|
||||
public WorldEditHandler(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restoreRegionBlocks(File rawFile, GeneralRegionInterface regionInterface) {
|
||||
File targetFile = null;
|
||||
for (ClipboardFormat formatOption : ClipboardFormats.getAll()) {
|
||||
for (String extension : formatOption.getFileExtensions()) {
|
||||
File fileOption = new File(rawFile.getAbsolutePath() + "." + extension);
|
||||
if (fileOption.exists()) {
|
||||
targetFile = fileOption;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (targetFile == null || !targetFile.exists() || !targetFile.isFile()) {
|
||||
pluginInterface.getLogger().info(() -> "Not restoring region. Schematic not found: " + rawFile);
|
||||
return false;
|
||||
}
|
||||
File finalFile = targetFile;
|
||||
ClipboardFormat format = ClipboardFormats.findByFile(targetFile);
|
||||
if (format == null) {
|
||||
pluginInterface.getLogger().warning(() -> "Could not find a clipboard format for file: " + finalFile.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
BlockVector3 min = regionInterface.getRegion().getMinimumPoint();
|
||||
final World world = BukkitAdapter.adapt(regionInterface.getWorld());
|
||||
if (world == null) {
|
||||
pluginInterface.getLogger().warning(() -> "Did not restore region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
|
||||
return false;
|
||||
}
|
||||
long volume = regionInterface.getRegion().volume();
|
||||
int maxBlocks = pluginInterface.getConfig().getInt("maximumBlocks", Integer.MAX_VALUE);
|
||||
if (volume > maxBlocks) {
|
||||
pluginInterface.getLogger().warning((() -> "Region is bigger than the max allowed block change size! Volume: " + volume + " Limit: " + maxBlocks));
|
||||
return false;
|
||||
}
|
||||
pluginInterface.debugI(() -> String.format("Attempting to restore using format: %s", format.getName()));
|
||||
// Bug in which schematic pasting doesn't clear tile entities properly
|
||||
// We manually remove tile entities in the destination before we paste the schematic
|
||||
pluginInterface.debugI(() -> "Clearing entities for region: " + regionInterface.getName());
|
||||
ProtectedRegion wgRegion = regionInterface.getRegion();
|
||||
Region region = new CuboidRegion(wgRegion.getMinimumPoint(), wgRegion.getMaximumPoint());
|
||||
if (pluginInterface.getConfig().getBoolean("forceClearEntities", false) && failedClearEntities(world, region, regionInterface)) {
|
||||
pluginInterface.getLogger().warning(() -> "Failed to clear tile entities for region: " + regionInterface.getName() + ". Will attempt to past anyway");
|
||||
}
|
||||
BlockVector3 dimensions = regionInterface.computeDimensions();
|
||||
try (InputStream is = new FileInputStream(finalFile);
|
||||
ClipboardReader reader = format.getReader(is)) {
|
||||
Clipboard clipboard = reader.read();
|
||||
if (!clipboard.getDimensions().equals(dimensions)) {
|
||||
pluginInterface.getLogger().warning(() -> "Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
|
||||
pluginInterface.debugI("schematic|region, x:" + clipboard.getDimensions().getX() + "|" + regionInterface.getWidth() + ", y:" + clipboard.getDimensions().getY() + "|" + regionInterface.getHeight() + ", z:" + clipboard.getDimensions().getZ() + "|" + regionInterface.getDepth());
|
||||
return false;
|
||||
}
|
||||
final Operation operation = new ClipboardHolder(clipboard).createPaste(world)
|
||||
.to(min)
|
||||
.copyEntities(true)
|
||||
.build();
|
||||
Operations.complete(operation);
|
||||
return true;
|
||||
} catch (IOException | WorldEditException ex) {
|
||||
pluginInterface.getLogger().warning(() ->"An error occurred while restoring schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
} catch (Exception ex) {
|
||||
pluginInterface.getLogger().warning(() -> "crashed during restore of " + regionInterface.getName());
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
|
||||
final ClipboardFormat format = BuiltInClipboardFormat.SPONGE_SCHEMATIC;
|
||||
final File targetFile = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
|
||||
ProtectedRegion wgRegion = regionInterface.getRegion();
|
||||
Region region = new CuboidRegion(wgRegion.getMinimumPoint(), wgRegion.getMaximumPoint());
|
||||
final World world = BukkitAdapter.adapt(regionInterface.getWorld());
|
||||
if (world == null) {
|
||||
pluginInterface.getLogger().warning(() -> "Did not save region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
|
||||
return false;
|
||||
}
|
||||
int maxBlocks = pluginInterface.getConfig().getInt("maximumBlocks", Integer.MAX_VALUE);
|
||||
long volume = region.getVolume();
|
||||
if (volume > maxBlocks) {
|
||||
pluginInterface.getLogger().warning((() -> "Region is bigger than the max allowed block change size! Volume: " + volume + " Limit: " + maxBlocks));
|
||||
return false;
|
||||
}
|
||||
pluginInterface.debugI(() -> String.format("Trying to save region %s to file %s with format %s", regionInterface.getName(), file.getName(), format.getName()));
|
||||
Clipboard clipboard = new BlockArrayClipboard(region);
|
||||
final ForwardExtentCopy copy = new ForwardExtentCopy(world, region, clipboard, region.getMinimumPoint());
|
||||
copy.setCopyingEntities(true);
|
||||
try {
|
||||
Operations.complete(copy);
|
||||
} catch (WorldEditException ex) {
|
||||
pluginInterface.getLogger().warning(() -> "An error occurred while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
try (OutputStream os = new FileOutputStream(targetFile);
|
||||
ClipboardWriter writer = format.getWriter(os)) {
|
||||
writer.write(clipboard);
|
||||
return true;
|
||||
} catch (IOException ex) {
|
||||
pluginInterface.getLogger().warning(() -> "An error occurred while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
} catch (Exception ex) {
|
||||
pluginInterface.getLogger().warning(() -> "crashed during save of " + regionInterface.getName());
|
||||
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean failedClearEntities(World world, Region region, GeneralRegionInterface regionInterface) {
|
||||
try (EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().newEditSessionBuilder()
|
||||
.world(world)
|
||||
.build()) {
|
||||
EntityFunction function = entity -> {
|
||||
BaseEntity state = entity.getState();
|
||||
if (state == null) {
|
||||
return false;
|
||||
}
|
||||
EntityType entityType = state.getType();
|
||||
if ((entityType.equals(EntityTypes.ITEM_FRAME)
|
||||
|| entityType.equals(EntityTypes.PAINTING)
|
||||
|| entityType.equals(EntityTypes.LEASH_KNOT))
|
||||
&& !entity.remove()) {
|
||||
pluginInterface.debugI("Could not remove entity: " + entityType.getName());
|
||||
}
|
||||
return false;
|
||||
};
|
||||
EntityVisitor visitor = new EntityVisitor(editSession.getEntities(region).iterator(), function);
|
||||
Operations.complete(visitor);
|
||||
return false;
|
||||
} catch (WorldEditException ex) {
|
||||
pluginInterface.getLogger().warning("crashed during save of " + regionInterface.getName());
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(ex));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
dependencies {
|
||||
compileOnly(libs.spigot)
|
||||
compileOnly(projects.areashopInterface)
|
||||
compileOnly(libs.worldeditCore)
|
||||
compileOnly(libs.worldeditBukkit)
|
||||
compileOnly(libs.worldguardCore)
|
||||
}
|
||||
|
||||
description = "AreaShop WorldGuard 7"
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package me.wiefferink.areashop.handlers;
|
||||
package me.wiefferink.areashop.adapters.plugins;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
@@ -27,9 +27,9 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class WorldGuardHandler7 extends WorldGuardInterface {
|
||||
public class WorldGuardHandler extends WorldGuardInterface {
|
||||
|
||||
public WorldGuardHandler7(AreaShopInterface pluginInterface) {
|
||||
public WorldGuardHandler(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>BUKKIT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,31 +0,0 @@
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
|
||||
compileOnly project(':areashop-interface')
|
||||
}
|
||||
|
||||
description = 'AreaShop Bukkit 1.13 and higher'
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
// ... artifact publications
|
||||
areaShop(MavenPublication) {
|
||||
from components.java
|
||||
pom {
|
||||
group = "me.wiefferink"
|
||||
artifactId = "$project.name"
|
||||
version = "$project.version"
|
||||
scm {
|
||||
connection = 'scm:git:git://github.com/md5sha256/AreaShop.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/md5sha256/AreaShop.git'
|
||||
url = "https://github.com/md5sha256/AreaShop/tree/dev/bleeding"
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name = 'GNU General Public License v3.0'
|
||||
url = "https://github.com/md5sha256/AreaShop/blob/dev/bleeding/LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
package me.wiefferink.areashop.handlers;
|
||||
|
||||
import me.wiefferink.areashop.interfaces.AreaShopInterface;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
|
||||
public class BukkitHandler1_13 extends BukkitInterface {
|
||||
|
||||
public BukkitHandler1_13(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
// Uses BlockData, which does not yet exist in 1.12-
|
||||
@Override
|
||||
public BlockFace getSignFacing(Block block) {
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockState blockState = block.getState();
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if(blockData instanceof WallSign) {
|
||||
return ((WallSign) blockData).getFacing();
|
||||
} else if(blockData instanceof Sign) {
|
||||
return ((Sign) blockData).getRotation();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Uses BlockData, WallSign and Sign which don't exist in 1.12-
|
||||
@Override
|
||||
public boolean setSignFacing(Block block, BlockFace facing) {
|
||||
if (block == null || facing == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockState blockState = block.getState();
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if(blockData instanceof WallSign) {
|
||||
((WallSign) blockData).setFacing(facing);
|
||||
} else if(blockData instanceof Sign) {
|
||||
((Sign) blockData).setRotation(facing);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
block.setBlockData(blockData);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getSignAttachedTo(Block block) {
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockState blockState = block.getState();
|
||||
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if(blockData instanceof WallSign) {
|
||||
return block.getRelative(((WallSign) blockData).getFacing().getOppositeFace());
|
||||
} else if(blockData instanceof Sign) {
|
||||
return block.getRelative(BlockFace.DOWN);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>BUKKIT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,32 +0,0 @@
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.2.8'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.6'
|
||||
}
|
||||
|
||||
description = 'AreaShop Interface'
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
// ... artifact publications
|
||||
areaShop(MavenPublication) {
|
||||
from components.java
|
||||
pom {
|
||||
group = "me.wiefferink"
|
||||
artifactId = "$project.name"
|
||||
version = "$project.version"
|
||||
scm {
|
||||
connection = 'scm:git:git://github.com/md5sha256/AreaShop.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/md5sha256/AreaShop.git'
|
||||
url = "https://github.com/md5sha256/AreaShop/tree/dev/bleeding"
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name = 'GNU General Public License v3.0'
|
||||
url = "https://github.com/md5sha256/AreaShop/blob/dev/bleeding/LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
dependencies {
|
||||
compileOnly(libs.spigot)
|
||||
compileOnly(libs.worldeditCore)
|
||||
compileOnly(libs.worldeditBukkit)
|
||||
compileOnly(libs.worldguardCore)
|
||||
compileOnly(libs.worldguardBukkit)
|
||||
}
|
||||
|
||||
description = "AreaShop Interface"
|
||||
+6
@@ -3,12 +3,16 @@ package me.wiefferink.areashop.interfaces;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface AreaShopInterface {
|
||||
void debugI(Object... message);
|
||||
|
||||
void debugI(Supplier<String> message);
|
||||
|
||||
YamlConfiguration getConfig();
|
||||
|
||||
WorldGuardPlugin getWorldGuard();
|
||||
@@ -16,4 +20,6 @@ public interface AreaShopInterface {
|
||||
WorldEditPlugin getWorldEdit();
|
||||
|
||||
Logger getLogger();
|
||||
|
||||
Plugin pluginInstance();
|
||||
}
|
||||
+63
-22
@@ -2,34 +2,75 @@ package me.wiefferink.areashop.interfaces;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
|
||||
public abstract class BukkitInterface {
|
||||
protected final AreaShopInterface pluginInterface;
|
||||
/**
|
||||
* Sign handler for 1.13+
|
||||
* @deprecated Obsolete as we don't support pre-1.13 versions anyway
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class BukkitInterface {
|
||||
|
||||
public BukkitInterface(AreaShopInterface pluginInterface) {
|
||||
this.pluginInterface = pluginInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the direciton a sign is facing.
|
||||
* @param block Sign block to get the facing from
|
||||
* @return direction the sign is facing
|
||||
*/
|
||||
public abstract BlockFace getSignFacing(Block block);
|
||||
// Uses BlockData, which does not yet exist in 1.12-
|
||||
public BlockFace getSignFacing(Block block) {
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the direction a sign is facing.
|
||||
* @param block Sign block to update
|
||||
* @param facing direction to let the sign face
|
||||
* @return true when successful, otherwise false
|
||||
*/
|
||||
public abstract boolean setSignFacing(Block block, BlockFace facing);
|
||||
BlockState blockState = block.getState();
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
/**
|
||||
* Get the block a sign is attached to.
|
||||
* @param block Sign block
|
||||
* @return Block the sign is attached to, or null when not a sign or not attached
|
||||
*/
|
||||
public abstract Block getSignAttachedTo(Block block);
|
||||
if(blockData instanceof WallSign) {
|
||||
return ((WallSign) blockData).getFacing();
|
||||
} else if(blockData instanceof Sign) {
|
||||
return ((Sign) blockData).getRotation();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Uses BlockData, WallSign and Sign which don't exist in 1.12-
|
||||
public boolean setSignFacing(Block block, BlockFace facing) {
|
||||
if (block == null || facing == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockState blockState = block.getState();
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if(blockData instanceof WallSign) {
|
||||
((WallSign) blockData).setFacing(facing);
|
||||
} else if(blockData instanceof Sign) {
|
||||
((Sign) blockData).setRotation(facing);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
block.setBlockData(blockData);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Block getSignAttachedTo(Block block) {
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockState blockState = block.getState();
|
||||
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if(blockData instanceof WallSign) {
|
||||
return block.getRelative(((WallSign) blockData).getFacing().getOppositeFace());
|
||||
} else if(blockData instanceof Sign) {
|
||||
return block.getRelative(BlockFace.DOWN);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+5
@@ -1,5 +1,6 @@
|
||||
package me.wiefferink.areashop.interfaces;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.World;
|
||||
|
||||
@@ -17,4 +18,8 @@ public interface GeneralRegionInterface {
|
||||
int getDepth();
|
||||
|
||||
int getHeight();
|
||||
|
||||
default BlockVector3 computeDimensions() {
|
||||
return BlockVector3.at(getWidth(), getHeight(), getDepth());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -52,11 +52,11 @@ public class RegionAccessSet {
|
||||
* @return List of player UUIDs, first players already added by UUID, then players added by name, groups are not in the list
|
||||
*/
|
||||
public List<UUID> asUniqueIdList() {
|
||||
List<UUID> result = new ArrayList<>();
|
||||
result.addAll(playerUniqueIds);
|
||||
List<UUID> result = new ArrayList<>(playerUniqueIds);
|
||||
for(String playerName : playerNames) {
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName);
|
||||
if(offlinePlayer != null && offlinePlayer.getUniqueId() != null) {
|
||||
if(offlinePlayer.hasPlayedBefore()) {
|
||||
result.add(offlinePlayer.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -3,6 +3,7 @@ package me.wiefferink.areashop.interfaces;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public abstract class WorldEditInterface {
|
||||
protected final AreaShopInterface pluginInterface;
|
||||
@@ -11,6 +12,10 @@ public abstract class WorldEditInterface {
|
||||
this.pluginInterface = pluginInterface;
|
||||
}
|
||||
|
||||
public boolean supportsAsyncOperations() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Different way to restore blocks per implementation, newer ones support entities as well.
|
||||
* Why: the schematic api has changed between WorldEdit 5 and 6, and the schematic format changed between 6 and 7
|
||||
@@ -20,6 +25,16 @@ public abstract class WorldEditInterface {
|
||||
*/
|
||||
public abstract boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface);
|
||||
|
||||
/**
|
||||
* Different way to restore blocks per implementation, newer ones support entities as well.
|
||||
* @param file File to try restoring from to the location of the region
|
||||
* @param regionInterface Region to restore from
|
||||
* @return true when successful, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> restoreRegionBlocksAsync(File file, GeneralRegionInterface regionInterface) {
|
||||
return CompletableFuture.completedFuture(restoreRegionBlocks(file, regionInterface));
|
||||
}
|
||||
|
||||
/**
|
||||
* Different way to save blocks per implementation, newer ones support entities as well.
|
||||
* Why: the schematic api has changed between WorldEdit 5 and 6, and the schematic format changed between 6 and 7
|
||||
@@ -29,6 +44,17 @@ public abstract class WorldEditInterface {
|
||||
*/
|
||||
public abstract boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface);
|
||||
|
||||
/**
|
||||
* Different way to save blocks per implementation, newer ones support entities as well.
|
||||
* Why: the schematic api has changed between WorldEdit 5 and 6, and the schematic format changed between 6 and 7
|
||||
* @param file File to try saving the region to
|
||||
* @param regionInterface Region to restore from
|
||||
* @return true when successful, otherwise false
|
||||
*/
|
||||
public CompletableFuture<Boolean> saveRegionBlocksAsync(File file, GeneralRegionInterface regionInterface) {
|
||||
return CompletableFuture.completedFuture(saveRegionBlocks(file, regionInterface));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selection of the player.
|
||||
* Why: the underlying WorldEdit selection class has changed from interface <-> class
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
dependencies {
|
||||
compileOnly(libs.spigot)
|
||||
}
|
||||
|
||||
description = "AreaShop NMS Interface"
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,55 +0,0 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'maven-publish'
|
||||
id 'io.papermc.paperweight.userdev' version '1.3.3' apply false
|
||||
}
|
||||
|
||||
group = 'me.wiefferink'
|
||||
version = '2.7.3'
|
||||
|
||||
subprojects {
|
||||
|
||||
plugins.apply('java-library')
|
||||
plugins.apply('maven-publish')
|
||||
|
||||
version = '2.7.1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = 'oss-sonatype'
|
||||
url = uri("https://oss.sonatype.org/content/groups/public/")
|
||||
}
|
||||
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) {
|
||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
options.release.set(17)
|
||||
options.encoding = 'UTF-8'
|
||||
options.fork = true
|
||||
options.deprecation = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
plugins {
|
||||
java
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
id("io.papermc.paperweight.userdev") version "1.5.5" apply false
|
||||
idea
|
||||
eclipse
|
||||
}
|
||||
|
||||
group = "me.wiefferink"
|
||||
version = "2.7.12"
|
||||
|
||||
subprojects {
|
||||
|
||||
group = rootProject.group
|
||||
version = rootProject.version
|
||||
|
||||
apply {
|
||||
plugin<JavaPlugin>()
|
||||
plugin<JavaLibraryPlugin>()
|
||||
if (project.path.contains("platform").not()) {
|
||||
plugin<MavenPublishPlugin>()
|
||||
}
|
||||
plugin<IdeaPlugin>()
|
||||
plugin<EclipsePlugin>()
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://oss.sonatype.org/content/groups/public/")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
|
||||
maven {
|
||||
name = "jitpack"
|
||||
url = uri("https://jitpack.io")
|
||||
content {
|
||||
includeGroupByRegex("com\\.github.*")
|
||||
}
|
||||
}
|
||||
maven("https://repo.aikar.co/content/groups/aikar/")
|
||||
maven("https://maven.enginehub.org/repo/")
|
||||
}
|
||||
|
||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
|
||||
tasks {
|
||||
withType(JavaCompile::class) {
|
||||
options.release.set(17)
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.isFork = true
|
||||
options.isDeprecation = true
|
||||
}
|
||||
|
||||
withType(Javadoc::class) {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
|
||||
withType(ProcessResources::class) {
|
||||
filteringCharset = Charsets.UTF_8.name()
|
||||
}
|
||||
}
|
||||
|
||||
if (project.path.contains("platform").not()) {
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>(project.name) {
|
||||
from(components["java"])
|
||||
pom {
|
||||
scm {
|
||||
connection.set("scm:git:git://github.com/md5sha256/AreaShop.git")
|
||||
developerConnection.set("scm:git:ssh://github.com/md5sha256/AreaShop.git")
|
||||
url.set("https://github.com/md5sha256/AreaShop/tree/dev/bleeding")
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name.set("GNU General Public License v3.0")
|
||||
url.set("https://github.com/md5sha256/AreaShop/blob/dev/bleeding/LICENSE")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
# Compiling
|
||||
|
||||
## Clone the repo <br/>
|
||||
`git clone https://github.com/md5sha256/AreaShop.git`
|
||||
|
||||
## Compile a Jar
|
||||
This task may take a while as the dev environment for platform adapters in `adapters/platform` take a while to set up
|
||||
<br/>
|
||||
<strong>Compilation command:</strong> `./gradlew build` (UNIX) or `gradlew build` (Windows)
|
||||
<br/>
|
||||
The plugin jar can be found under the `AreaShop` module in `AreaShop/build/libs/`<br/>
|
||||
There are three jars, use the one which has no suffix. Ex: `AreaShop-VERSION.jar`
|
||||
|
||||
## Gradle Tasks
|
||||
The following is a simple table describing commands which may be useful for building the plugin. <br>
|
||||
For more details about gradle please view their documentation [here](https://docs.gradle.org/current/userguide/userguide.html).
|
||||
</br>
|
||||
A shorthand for the CLI [here](https://docs.gradle.org/current/userguide/command_line_interface.html).
|
||||
<br>
|
||||
|
||||
| Command | Description |
|
||||
|-------------------------------|----------------------------------------------------------------------------------------------------|
|
||||
| `gradlew build` | Compiles all modules and packages the plugin into one jar |
|
||||
| `gradlew publishToMavenLocal` | Compiles and publishes all modules except the platform adapters to `.m2` |
|
||||
| `gradlew clean` | Cleans the development workspace and clears caches. Note, you don't have to clean before you build |
|
||||
+3
-1
@@ -1 +1,3 @@
|
||||
org.gradle.parallel=true
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
org.gradle.java.installations.auto-download=false
|
||||
@@ -0,0 +1,23 @@
|
||||
[versions]
|
||||
# Platforms
|
||||
minecraft = "1.17.1-R0.1-SNAPSHOT"
|
||||
findbugs = "3.0.2"
|
||||
|
||||
# Minecraft Plugins
|
||||
worldedit = "7.2.14"
|
||||
worldguard = "7.0.8"
|
||||
fawe = "2.6.2"
|
||||
|
||||
[libraries]
|
||||
# Platform
|
||||
spigot = { group = "org.spigotmc", name = "spigot-api", version.ref = "minecraft" }
|
||||
paper = { group = "io.papermc.paper", name = "paper-api", version.ref = "minecraft" }
|
||||
findbugs = { group = "com.google.code.findbugs", name = "jsr305", version.ref = "findbugs" }
|
||||
|
||||
# Minecraft Plugins
|
||||
worldeditBukkit = { group = "com.sk89q.worldedit", name = "worldedit-bukkit", version.ref = "worldedit" }
|
||||
worldeditCore = { group = "com.sk89q.worldedit", name = "worldedit-core", version.ref = "worldedit" }
|
||||
worldguardBukkit = { group = "com.sk89q.worldguard", name = "worldguard-bukkit", version.ref = "worldguard" }
|
||||
worldguardCore = { group = "com.sk89q.worldguard", name = "worldguard-core", version.ref = "worldguard" }
|
||||
fastasyncworldeditBukkit = { group = "com.fastasyncworldedit", name = "FastAsyncWorldEdit-Bukkit", version.ref = "fawe" }
|
||||
fastasyncworldeditCore = { group = "com.fastasyncworldedit", name = "FastAsyncWorldEdit-Core", version.ref = "fawe" }
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>BUKKIT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,43 +0,0 @@
|
||||
repositories {
|
||||
maven {
|
||||
name = "S01 Sonatype Snapshots"
|
||||
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT'
|
||||
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core:2.0.0")
|
||||
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:2.0.0") {
|
||||
|
||||
}
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.6'
|
||||
compileOnly project(':areashop-interface')
|
||||
}
|
||||
|
||||
description = 'AreaShop FastAsyncWorldEdit'
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
// ... artifact publications
|
||||
areaShop(MavenPublication) {
|
||||
from components.java
|
||||
pom {
|
||||
group = "me.wiefferink"
|
||||
artifactId = "$project.name"
|
||||
version = "$project.version"
|
||||
scm {
|
||||
connection = 'scm:git:git://github.com/md5sha256/AreaShop.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/md5sha256/AreaShop.git'
|
||||
url = "https://github.com/md5sha256/AreaShop/tree/dev/bleeding"
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name = 'GNU General Public License v3.0'
|
||||
url = "https://github.com/md5sha256/AreaShop/blob/dev/bleeding/LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-298
@@ -1,298 +0,0 @@
|
||||
package me.wiefferink.areashop.handlers;
|
||||
|
||||
import com.fastasyncworldedit.core.FaweAPI;
|
||||
import com.fastasyncworldedit.core.extent.clipboard.MemoryOptimizedClipboard;
|
||||
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReader;
|
||||
import com.fastasyncworldedit.core.extent.processor.lighting.RelightMode;
|
||||
import com.fastasyncworldedit.core.limit.FaweLimit;
|
||||
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.WorldEdit;
|
||||
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 net.kyori.adventure.nbt.TagStringIO;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@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 = WorldEdit.getInstance().newEditSessionBuilder()
|
||||
.world(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((int) 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();
|
||||
}
|
||||
|
||||
|
||||
@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 = WorldEdit.getInstance().newEditSessionBuilder()
|
||||
.world(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
-165
@@ -1,165 +0,0 @@
|
||||
package me.wiefferink.areashop.handlers;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroup;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.wiefferink.areashop.interfaces.AreaShopInterface;
|
||||
import me.wiefferink.areashop.interfaces.RegionAccessSet;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* FAWE WorldGuard handler for pre 1.13
|
||||
* @deprecated FAWE no longer has a custom WG implementation.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class FastAsyncWorldEditWorldGuardHandler extends WorldGuardInterface {
|
||||
|
||||
public FastAsyncWorldEditWorldGuardHandler(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionManager getRegionManager(World world) {
|
||||
return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
|
||||
Set<ProtectedRegion> result = new HashSet<>();
|
||||
BlockVector3 vector = BlockVector3.at(location.getX(), location.getY(), location.getZ());
|
||||
for(ProtectedRegion region : getRegionManager(location.getWorld()).getRegions().values()) {
|
||||
if(region.contains(vector)) {
|
||||
result.add(region);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a DefaultDomain from a RegionAccessSet.
|
||||
* @param regionAccessSet RegionAccessSet to read
|
||||
* @return DefaultDomain containing the entities from the RegionAccessSet
|
||||
*/
|
||||
private DefaultDomain buildDomain(RegionAccessSet regionAccessSet) {
|
||||
DefaultDomain owners = new DefaultDomain();
|
||||
|
||||
for(String playerName : regionAccessSet.getPlayerNames()) {
|
||||
owners.addPlayer(playerName);
|
||||
}
|
||||
|
||||
for(UUID uuid : regionAccessSet.getPlayerUniqueIds()) {
|
||||
owners.addPlayer(uuid);
|
||||
}
|
||||
|
||||
for(String group : regionAccessSet.getGroupNames()) {
|
||||
owners.addGroup(group);
|
||||
}
|
||||
|
||||
return owners;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwners(ProtectedRegion region, RegionAccessSet regionAccessSet) {
|
||||
DefaultDomain defaultDomain = buildDomain(regionAccessSet);
|
||||
if(!region.getOwners().toUserFriendlyString().equals(defaultDomain.toUserFriendlyString())) {
|
||||
region.setOwners(defaultDomain);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMembers(ProtectedRegion region, RegionAccessSet regionAccessSet) {
|
||||
DefaultDomain defaultDomain = buildDomain(regionAccessSet);
|
||||
if(!region.getMembers().toUserFriendlyString().equals(defaultDomain.toUserFriendlyString())) {
|
||||
region.setMembers(defaultDomain);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsMember(ProtectedRegion region, UUID player) {
|
||||
return region.getMembers().contains(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsOwner(ProtectedRegion region, UUID player) {
|
||||
return region.getOwners().contains(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionAccessSet getMembers(ProtectedRegion region) {
|
||||
RegionAccessSet result = new RegionAccessSet();
|
||||
result.getGroupNames().addAll(region.getMembers().getGroups());
|
||||
result.getPlayerNames().addAll(region.getMembers().getPlayers());
|
||||
result.getPlayerUniqueIds().addAll(region.getMembers().getUniqueIds());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionAccessSet getOwners(ProtectedRegion region) {
|
||||
RegionAccessSet result = new RegionAccessSet();
|
||||
result.getGroupNames().addAll(region.getOwners().getGroups());
|
||||
result.getPlayerNames().addAll(region.getOwners().getPlayers());
|
||||
result.getPlayerUniqueIds().addAll(region.getOwners().getUniqueIds());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flag<?> fuzzyMatchFlag(String flagName) {
|
||||
return Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), flagName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
|
||||
return flag.parseInput(FlagContext.create().setInput(input).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionGroup parseFlagGroupInput(RegionGroupFlag flag, String input) throws InvalidFlagFormat {
|
||||
return flag.parseInput(FlagContext.create().setInput(input).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMinimumPoint(ProtectedRegion region) {
|
||||
BlockVector3 min = region.getMinimumPoint();
|
||||
return new Vector(min.getX(), min.getY(), min.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMaximumPoint(ProtectedRegion region) {
|
||||
BlockVector3 min = region.getMaximumPoint();
|
||||
return new Vector(min.getX(), min.getY(), min.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Vector> getRegionPoints(ProtectedRegion region) {
|
||||
List<Vector> result = new ArrayList<>();
|
||||
for (BlockVector2 point : region.getPoints()) {
|
||||
result.add(new Vector(point.getX(), 0,point.getZ()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtectedCuboidRegion createCuboidRegion(String name, Vector corner1, Vector corner2) {
|
||||
return new ProtectedCuboidRegion(name, BlockVector3.at(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ()), BlockVector3.at(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ()));
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
plugins.apply("io.papermc.paperweight.userdev")
|
||||
|
||||
dependencies {
|
||||
paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.17.1-R0.1-SNAPSHOT")
|
||||
compileOnly project(':areashop-interface')
|
||||
compileOnly project(':areashop-nms')
|
||||
}
|
||||
|
||||
reobfJar {
|
||||
outputJar.set(file("build/libs/${project.name}-${project.version}.jar"))
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
// ... artifact publications
|
||||
nmsProvider(MavenPublication) {
|
||||
pom {
|
||||
group = "me.wiefferink"
|
||||
artifactId = "$project.name"
|
||||
version = "$project.version"
|
||||
scm {
|
||||
connection = 'scm:git:git://github.com/md5sha256/AreaShop.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/md5sha256/AreaShop.git'
|
||||
url = "https://github.com/md5sha256/AreaShop/tree/dev/bleeding"
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name = 'GNU General Public License v3.0'
|
||||
url = "https://github.com/md5sha256/AreaShop/blob/dev/bleeding/LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
description = 'AreaShop NMS Helper'
|
||||
Loaded 100 of 109 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user