mirror of
https://github.com/md5sha256/AreaShop.git
synced 2026-11-07 01:42:34 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
03ed2803bd | ||
|
|
b3f1225934 | ||
|
|
68651899b7 | ||
|
|
4a7a4ca4ee | ||
|
|
0d272c8fe9 | ||
|
|
6b2c905939 | ||
|
|
7ab782799b | ||
|
|
bea82eae88 | ||
|
|
4ac0e045bd | ||
|
|
e5061b218e | ||
|
|
40fdfba47d | ||
|
|
e9260cede6 | ||
|
|
bb297c9ff1 | ||
|
|
666742ad56 | ||
|
|
36eb8c3a5e | ||
|
|
06a9f7b28e | ||
|
|
e101780420 | ||
|
|
6abe99e807 | ||
|
|
a1d18521ee |
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,76 +0,0 @@
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
plugins {
|
||||
id 'com.github.johnrengelman.shadow' version '7.1.0'
|
||||
}
|
||||
|
||||
version = "2.7.0-SNAPSHOT"
|
||||
|
||||
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')
|
||||
implementation project(':areashop-nms-1-17')
|
||||
implementation project(':areashop-worldedit-7')
|
||||
implementation project(':areashop-worldguard-7')
|
||||
implementation project(':areashop-fastasyncworldedit')
|
||||
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
|
||||
compileOnly ('com.sk89q.worldedit:worldedit-bukkit:7.2.5') {
|
||||
exclude group: 'com.google.guava'
|
||||
}
|
||||
compileOnly ('com.sk89q.worldguard:worldguard-bukkit:7.0.5') {
|
||||
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)
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier.set('original')
|
||||
}
|
||||
|
||||
compileJava {
|
||||
javaToolchains.compilerFor {
|
||||
JavaLanguageVersion.of(16)
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
description = 'AreaShop'
|
||||
@@ -0,0 +1,96 @@
|
||||
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.7")
|
||||
implementation("com.github.NLthijs48:InteractiveMessenger:e7749258ca")
|
||||
implementation("com.github.NLthijs48:BukkitDo:819d51ec2b")
|
||||
implementation("io.github.baked-libs:dough-data:1.0.3")
|
||||
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"))
|
||||
}
|
||||
|
||||
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,14 +6,17 @@ 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;
|
||||
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.Manager;
|
||||
import me.wiefferink.areashop.managers.SignErrorLogger;
|
||||
@@ -21,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;
|
||||
@@ -49,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.
|
||||
@@ -67,9 +71,8 @@ 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 FileManager fileManager = null;
|
||||
private IFileManager fileManager = null;
|
||||
private LanguageManager languageManager = null;
|
||||
private CommandManager commandManager = null;
|
||||
private SignLinkerManager signLinkerManager = null;
|
||||
@@ -90,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
|
||||
@@ -165,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));
|
||||
|
||||
@@ -174,197 +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 weVersion = null;
|
||||
String rawWeVersion = null;
|
||||
String weBeta = null;
|
||||
String weHandlerVersion;
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
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.")) {
|
||||
weVersion = "7";
|
||||
this.worldEdit = (WorldEditPlugin) plugin;
|
||||
Plugin fawePlugin = getServer().getPluginManager().getPlugin("FastAsyncWorldEdit");
|
||||
if (fawePlugin != null && fawePlugin.isEnabled()) {
|
||||
weHandlerVersion = "FastAsyncWorldEditHandler";
|
||||
info("Detected FastAsyncWorldEdit, using the fawe handler");
|
||||
} else {
|
||||
throw new IllegalStateException("Unknown WE Version: " + worldEdit.getDescription().getVersion());
|
||||
weHandlerVersion = "WorldEditHandler";
|
||||
}
|
||||
weVersion = "WorldEditHandler" + weVersion;
|
||||
}
|
||||
|
||||
// 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());
|
||||
|
||||
// Check if FastAsyncWorldEdit is installed
|
||||
boolean fawe;
|
||||
try {
|
||||
Class.forName("com.fastasyncworldedit.core.FaweAPI" );
|
||||
fawe = true;
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
fawe = false;
|
||||
}
|
||||
|
||||
if (fawe) {
|
||||
weVersion = "FastAsyncWorldEditHandler";
|
||||
}
|
||||
DependencyModule dependencyModule = new DependencyModule(this.worldEdit, this.worldGuard, getEconomy(), getPermissionProvider());
|
||||
|
||||
// Load WorldEdit
|
||||
try {
|
||||
Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers." + weVersion);
|
||||
// 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 " + weVersion + "), report this problem to the author: " + ExceptionUtils.getStackTrace(e));
|
||||
error = true;
|
||||
weVersion = null;
|
||||
error("Could not load the handler for WorldEdit (tried to load " + weHandlerVersion + "), report this problem to the author: " + ExceptionUtils.getStackTrace(e));
|
||||
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(FileManager.class);
|
||||
managers.add(fileManager);
|
||||
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(weVersion != null) {
|
||||
AreaShop.debug("Loaded ", weVersion, "(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);
|
||||
@@ -391,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))
|
||||
@@ -401,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);
|
||||
}
|
||||
@@ -419,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
|
||||
@@ -550,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
|
||||
@@ -566,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
|
||||
@@ -660,7 +565,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
* Method to get the FileManager (loads/save regions and can be used to get regions).
|
||||
* @return The fileManager
|
||||
*/
|
||||
public FileManager getFileManager() {
|
||||
public IFileManager getFileManager() {
|
||||
return fileManager;
|
||||
}
|
||||
|
||||
@@ -800,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, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -813,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, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -821,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, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ import me.wiefferink.areashop.events.notify.RentedRegionEvent;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
@@ -164,14 +164,14 @@ public class AddCommand extends CommandAreaShop {
|
||||
} else {
|
||||
type = "buy";
|
||||
}
|
||||
FileManager.AddResult result = plugin.getFileManager().checkRegionAdd(sender, region, world, isRent ? GeneralRegion.RegionType.RENT : GeneralRegion.RegionType.BUY);
|
||||
if(result == FileManager.AddResult.ALREADYADDED) {
|
||||
IFileManager.AddResult result = plugin.getFileManager().checkRegionAdd(sender, region, world, isRent ? GeneralRegion.RegionType.RENT : GeneralRegion.RegionType.BUY);
|
||||
if(result == IFileManager.AddResult.ALREADYADDED) {
|
||||
regionsAlready.add(plugin.getFileManager().getRegion(regionName));
|
||||
} else if(result == FileManager.AddResult.ALREADYADDEDOTHERWORLD) {
|
||||
} else if(result == IFileManager.AddResult.ALREADYADDEDOTHERWORLD) {
|
||||
regionsAlreadyOtherWorld.add(plugin.getFileManager().getRegion(regionName));
|
||||
} else if(result == FileManager.AddResult.BLACKLISTED) {
|
||||
} else if(result == IFileManager.AddResult.BLACKLISTED) {
|
||||
namesBlacklisted.add(regionName);
|
||||
} else if(result == FileManager.AddResult.NOPERMISSION) {
|
||||
} else if(result == IFileManager.AddResult.NOPERMISSION) {
|
||||
namesNoPermission.add(regionName);
|
||||
} else {
|
||||
// Check if the player should be landlord
|
||||
@@ -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.managers.FileManager;
|
||||
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 FileManager 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.FileManager;
|
||||
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;
|
||||
@@ -28,13 +28,11 @@ public class AddsignCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
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 {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -21,7 +21,7 @@ public class BuyCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -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) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
@@ -26,7 +26,7 @@ public class DelCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private WorldEditInterface worldEditInterface;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -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.managers.FileManager;
|
||||
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 FileManager 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
@@ -27,7 +27,7 @@ public class FindCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private Economy economy;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -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);
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.wiefferink.areashop.commands;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
@@ -23,7 +23,7 @@ public class GroupaddCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private RegionFactory regionFactory;
|
||||
@Inject
|
||||
@@ -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");
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.wiefferink.areashop.commands;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
@@ -23,7 +23,7 @@ public class GroupdelCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private RegionFactory regionFactory;
|
||||
@Inject
|
||||
@@ -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");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -18,7 +18,7 @@ public class GroupinfoCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class GrouplistCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
|
||||
@@ -2,14 +2,13 @@ package me.wiefferink.areashop.commands;
|
||||
|
||||
import io.github.bakedlibs.dough.blocks.BlockPosition;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -17,7 +16,6 @@ import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -30,7 +28,7 @@ public class InfoCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
|
||||
@@ -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.managers.FileManager;
|
||||
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;
|
||||
@@ -24,7 +26,13 @@ public class MeCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Inject
|
||||
private OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
@Inject
|
||||
private BukkitSchedulerExecutor executor;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -55,11 +63,13 @@ 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;
|
||||
}
|
||||
// Lookup offline players async
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(offlinePlayer -> {
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
messageBridge.message(sender, "me-noPlayer", args[1]);
|
||||
}
|
||||
}, this.executor);
|
||||
return;
|
||||
}
|
||||
if(!player.hasPlayedBefore()) {
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -18,7 +18,7 @@ public class RentCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -18,7 +18,7 @@ public class ResellCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
@@ -20,7 +20,7 @@ public class SchematiceventCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
@@ -19,7 +19,7 @@ public class SellCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -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,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -19,7 +19,7 @@ public class SetdurationCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
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 FileManager 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.managers.FileManager;
|
||||
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 FileManager 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,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
@@ -20,7 +20,7 @@ public class SetpriceCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
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;
|
||||
@@ -17,7 +19,7 @@ public class SetrestoreCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
@@ -21,7 +21,7 @@ public class SetteleportCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -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
|
||||
|
||||
@@ -8,7 +8,7 @@ import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
@@ -33,7 +33,7 @@ public class StackCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private WorldEditInterface worldEditInterface;
|
||||
@Inject
|
||||
@@ -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");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -18,7 +18,7 @@ public class StopresellCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -17,7 +17,7 @@ public class TeleportCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -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]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
@@ -19,7 +19,7 @@ public class UnrentCommand extends CommandAreaShop {
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private FileManager fileManager;
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
@@ -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
|
||||
}
|
||||
@@ -177,7 +177,9 @@ public class RegionSign {
|
||||
if(!Materials.isSign(block.getType())) {
|
||||
Material signType = getMaterial();
|
||||
if (!blockHelper.canPlace(block.getLocation(), Bukkit.createBlockData(signType))) {
|
||||
AreaShop.warn("Setting sign", key, "of region", getRegion().getName(), "failed, could not set sign block back");
|
||||
errorLogger.submitWarning("Setting sign" + key + "of region" + getRegion().getName() + "failed, could not set sign block back");
|
||||
this.remove();
|
||||
return false;
|
||||
}
|
||||
// Don't do physics here, we first need to update the direction
|
||||
block.setType(signType, false);
|
||||
@@ -190,7 +192,7 @@ public class RegionSign {
|
||||
} else if(blockData instanceof org.bukkit.block.data.type.Sign) {
|
||||
((org.bukkit.block.data.type.Sign) blockData).setRotation(getFacing());
|
||||
} else {
|
||||
AreaShop.warn("Failed to update the facing direction of the sign at", getStringLocation(), "to ", getFacing(), ", region:", getRegion().getName());
|
||||
errorLogger.submitWarning("Failed to update the facing direction of the sign at" + getStringLocation() + "to " + getFacing() + ", region:" + getRegion().getName());
|
||||
return false;
|
||||
}
|
||||
block.setBlockData(blockData);
|
||||
@@ -206,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,9 +7,8 @@ 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.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
@@ -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,10 +48,9 @@ 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 FileManager fileManager;
|
||||
private final IFileManager fileManager;
|
||||
|
||||
public SignListener(
|
||||
@Nonnull AreaShop plugin,
|
||||
@@ -58,17 +58,15 @@ public class SignListener implements Listener {
|
||||
@Nonnull RegionFactory regionFactory,
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull SignLinkerManager signLinkerManager,
|
||||
@Nonnull BukkitInterface bukkitInterface,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface,
|
||||
@Nonnull SignManager signManager,
|
||||
@Nonnull FileManager fileManager) {
|
||||
@Nonnull IFileManager fileManager) {
|
||||
this.fileManager = fileManager;
|
||||
this.signManager = signManager;
|
||||
this.signLinkerManager = signLinkerManager;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -252,14 +249,14 @@ public class SignListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
FileManager.AddResult addResult = fileManager.checkRegionAdd(player, regionManager.getRegion(secondLine), event.getPlayer().getWorld(), GeneralRegion.RegionType.RENT);
|
||||
if(addResult == FileManager.AddResult.BLACKLISTED) {
|
||||
IFileManager.AddResult addResult = fileManager.checkRegionAdd(player, regionManager.getRegion(secondLine), event.getPlayer().getWorld(), GeneralRegion.RegionType.RENT);
|
||||
if(addResult == IFileManager.AddResult.BLACKLISTED) {
|
||||
messageBridge.message(player, "setup-blacklisted", secondLine);
|
||||
} else if(addResult == FileManager.AddResult.ALREADYADDED) {
|
||||
} else if(addResult == IFileManager.AddResult.ALREADYADDED) {
|
||||
messageBridge.message(player, "setup-alreadyRentSign");
|
||||
} else if(addResult == FileManager.AddResult.ALREADYADDEDOTHERWORLD) {
|
||||
} else if(addResult == IFileManager.AddResult.ALREADYADDEDOTHERWORLD) {
|
||||
messageBridge.message(player, "setup-alreadyOtherWorld");
|
||||
} else if(addResult == FileManager.AddResult.NOPERMISSION) {
|
||||
} else if(addResult == IFileManager.AddResult.NOPERMISSION) {
|
||||
messageBridge.message(player, "setup-noPermission", secondLine);
|
||||
} else if(thirdLine != null && !thirdLine.isEmpty() && !Utils.checkTimeFormat(thirdLine)) {
|
||||
messageBridge.message(player, "setup-wrongDuration");
|
||||
@@ -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()) {
|
||||
@@ -357,14 +354,14 @@ public class SignListener implements Listener {
|
||||
messageBridge.message(player, "cmd-noRegion", secondLine);
|
||||
return;
|
||||
}
|
||||
FileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, region, event.getPlayer().getWorld(), GeneralRegion.RegionType.BUY);
|
||||
if(addResult == FileManager.AddResult.BLACKLISTED) {
|
||||
IFileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, region, event.getPlayer().getWorld(), GeneralRegion.RegionType.BUY);
|
||||
if(addResult == IFileManager.AddResult.BLACKLISTED) {
|
||||
messageBridge.message(player, "setup-blacklisted", secondLine);
|
||||
} else if(addResult == FileManager.AddResult.ALREADYADDED) {
|
||||
} else if(addResult == IFileManager.AddResult.ALREADYADDED) {
|
||||
messageBridge.message(player, "setup-alreadyRentSign");
|
||||
} else if(addResult == FileManager.AddResult.ALREADYADDEDOTHERWORLD) {
|
||||
} else if(addResult == IFileManager.AddResult.ALREADYADDEDOTHERWORLD) {
|
||||
messageBridge.message(player, "setup-alreadyOtherWorld");
|
||||
} else if(addResult == FileManager.AddResult.NOPERMISSION) {
|
||||
} else if(addResult == IFileManager.AddResult.NOPERMISSION) {
|
||||
messageBridge.message(player, "setup-noPermission", secondLine);
|
||||
} else {
|
||||
double price = 0.0;
|
||||
@@ -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,9 +6,8 @@ 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.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
@@ -30,10 +29,9 @@ public class SignsModule extends AbstractModule {
|
||||
@Nonnull RegionFactory regionFactory,
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull SignLinkerManager signLinkerManager,
|
||||
@Nonnull BukkitInterface bukkitInterface,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface,
|
||||
@Nonnull SignManager signManager,
|
||||
@Nonnull FileManager fileManager
|
||||
@Nonnull IFileManager fileManager
|
||||
) {
|
||||
final SignListener signListener = new SignListener(
|
||||
plugin,
|
||||
@@ -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;
|
||||
@@ -56,7 +57,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Singleton
|
||||
public class FileManager extends Manager {
|
||||
public class FileManager extends Manager implements IFileManager {
|
||||
|
||||
private final AreaShop plugin;
|
||||
private final Map<String, GeneralRegion> regions;
|
||||
@@ -81,25 +82,6 @@ public class FileManager extends Manager {
|
||||
private final MessageBridge messageBridge;
|
||||
private final RegionFactory regionFactory;
|
||||
|
||||
// Enum for region types
|
||||
public enum AddResult {
|
||||
BLACKLISTED("blacklisted"),
|
||||
NOPERMISSION("nopermission"),
|
||||
ALREADYADDED("alreadyadded"),
|
||||
ALREADYADDEDOTHERWORLD("alreadyaddedotherworld"),
|
||||
SUCCESS("success");
|
||||
|
||||
private final String value;
|
||||
|
||||
AddResult(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor, initialize variabeles.
|
||||
*/
|
||||
@@ -154,6 +136,7 @@ public class FileManager extends Manager {
|
||||
* Get the folder where schematics are stored.
|
||||
* @return The folder where schematics are stored
|
||||
*/
|
||||
@Override
|
||||
public String getSchematicFolder() {
|
||||
return schemFolder;
|
||||
}
|
||||
@@ -163,6 +146,7 @@ public class FileManager extends Manager {
|
||||
* @param name The name of the group to get (will be normalized)
|
||||
* @return The group if found, otherwise null
|
||||
*/
|
||||
@Override
|
||||
public RegionGroup getGroup(String name) {
|
||||
return groups.get(name.toLowerCase());
|
||||
}
|
||||
@@ -171,6 +155,7 @@ public class FileManager extends Manager {
|
||||
* Get all groups.
|
||||
* @return Collection with all groups (safe to modify)
|
||||
*/
|
||||
@Override
|
||||
public Collection<RegionGroup> getGroups() {
|
||||
return groups.values();
|
||||
}
|
||||
@@ -179,6 +164,7 @@ public class FileManager extends Manager {
|
||||
* Get the default region settings as provided by the user (default.yml).
|
||||
* @return YamlConfiguration with the settings (might miss settings, which should be filled in with {@link #getFallbackRegionSettings()})
|
||||
*/
|
||||
@Override
|
||||
public YamlConfiguration getRegionSettings() {
|
||||
return defaultConfig;
|
||||
}
|
||||
@@ -187,6 +173,7 @@ public class FileManager extends Manager {
|
||||
* Get the default regions settings as provided by AreaShop (default.yml).
|
||||
* @return YamlConfiguration with the default settings
|
||||
*/
|
||||
@Override
|
||||
public YamlConfiguration getFallbackRegionSettings() {
|
||||
return defaultConfigFallback;
|
||||
}
|
||||
@@ -195,6 +182,7 @@ public class FileManager extends Manager {
|
||||
* Get the config file (config.yml).
|
||||
* @return YamlConfiguration with the settings of users, with fallback to the settings provided by AreaShop
|
||||
*/
|
||||
@Override
|
||||
public YamlConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
@@ -204,6 +192,7 @@ public class FileManager extends Manager {
|
||||
* @param name The name of the region to get (will be normalized)
|
||||
* @return The region if found, otherwise null
|
||||
*/
|
||||
@Override
|
||||
public @Nullable GeneralRegion getRegion(String name) {
|
||||
return regions.get(name.toLowerCase());
|
||||
}
|
||||
@@ -213,6 +202,7 @@ public class FileManager extends Manager {
|
||||
* @param name The name of the rental region (will be normalized)
|
||||
* @return RentRegion if it could be found, otherwise null
|
||||
*/
|
||||
@Override
|
||||
public @Nullable RentRegion getRent(String name) {
|
||||
return rents.get(name.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
@@ -222,6 +212,7 @@ public class FileManager extends Manager {
|
||||
* @param name The name of the buy region (will be normalized)
|
||||
* @return BuyRegion if it could be found, otherwise null
|
||||
*/
|
||||
@Override
|
||||
public @Nullable BuyRegion getBuy(String name) {
|
||||
return buys.get(name.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
@@ -230,6 +221,7 @@ public class FileManager extends Manager {
|
||||
* Get all rental regions.
|
||||
* @return List of all rental regions
|
||||
*/
|
||||
@Override
|
||||
public Collection<RentRegion> getRents() {
|
||||
return new ArrayList<>(rents.values());
|
||||
}
|
||||
@@ -238,6 +230,7 @@ public class FileManager extends Manager {
|
||||
* Get all rental regions.
|
||||
* @return List of all rental regions
|
||||
*/
|
||||
@Override
|
||||
public Collection<RentRegion> getRentsRef() {
|
||||
return Collections.unmodifiableCollection(rents.values());
|
||||
}
|
||||
@@ -246,10 +239,12 @@ public class FileManager extends Manager {
|
||||
* Get all buy regions.
|
||||
* @return List of all buy regions
|
||||
*/
|
||||
@Override
|
||||
public List<BuyRegion> getBuys() {
|
||||
return new ArrayList<>(buys.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<BuyRegion> getBuysRef() {
|
||||
return Collections.unmodifiableCollection(buys.values());
|
||||
}
|
||||
@@ -259,6 +254,7 @@ public class FileManager extends Manager {
|
||||
* Get all regions.
|
||||
* @return List of all regions (it is safe to modify the list)
|
||||
*/
|
||||
@Override
|
||||
public List<GeneralRegion> getRegions() {
|
||||
return new ArrayList<>(regions.values());
|
||||
}
|
||||
@@ -267,6 +263,7 @@ public class FileManager extends Manager {
|
||||
* Get all regions.
|
||||
* @return List of all regions (it is safe to modify the list)
|
||||
*/
|
||||
@Override
|
||||
public Collection<GeneralRegion> getRegionsRef() {
|
||||
return Collections.unmodifiableCollection(regions.values());
|
||||
}
|
||||
@@ -275,6 +272,7 @@ public class FileManager extends Manager {
|
||||
* Get a list of names of all buy regions.
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
@Override
|
||||
public List<String> getBuyNames() {
|
||||
ArrayList<String> result = new ArrayList<>(buys.size());
|
||||
for(BuyRegion region : buys.values()) {
|
||||
@@ -287,6 +285,7 @@ public class FileManager extends Manager {
|
||||
* Get a list of names of all rent regions.
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
@Override
|
||||
public List<String> getRentNames() {
|
||||
ArrayList<String> result = new ArrayList<>(rents.size());
|
||||
for(RentRegion region : rents.values()) {
|
||||
@@ -299,6 +298,7 @@ public class FileManager extends Manager {
|
||||
* Get a list of names of all regions.
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
@Override
|
||||
public List<String> getRegionNames() {
|
||||
ArrayList<String> result = new ArrayList<>(regions.size());
|
||||
for(GeneralRegion region : regions.values()) {
|
||||
@@ -311,6 +311,7 @@ public class FileManager extends Manager {
|
||||
* Get a list of names of all groups.
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
@Override
|
||||
public List<String> getGroupNames() {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
for(RegionGroup group : groups.values()) {
|
||||
@@ -324,6 +325,7 @@ public class FileManager extends Manager {
|
||||
* @param region Then region to add
|
||||
* @return true when successful, otherwise false (denied by an event listener)
|
||||
*/
|
||||
@Override
|
||||
public AddingRegionEvent addRegion(GeneralRegion region) {
|
||||
AddingRegionEvent event = addRegionNoSave(region);
|
||||
if (event.isCancelled()) {
|
||||
@@ -339,6 +341,7 @@ public class FileManager extends Manager {
|
||||
* @param region The region to add
|
||||
* @return true when successful, otherwise false (denied by an event listener)
|
||||
*/
|
||||
@Override
|
||||
public AddingRegionEvent addRegionNoSave(GeneralRegion region) {
|
||||
AddingRegionEvent event = new AddingRegionEvent(region);
|
||||
if(region == null) {
|
||||
@@ -352,10 +355,10 @@ public class FileManager extends Manager {
|
||||
}
|
||||
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;
|
||||
@@ -364,6 +367,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Mark all RegionGroups that they should regenerate regions.
|
||||
*/
|
||||
@Override
|
||||
public void markGroupsAutoDirty() {
|
||||
for(RegionGroup group : getGroups()) {
|
||||
group.autoDirty();
|
||||
@@ -374,6 +378,7 @@ public class FileManager extends Manager {
|
||||
* Add a RegionGroup.
|
||||
* @param group The RegionGroup to add
|
||||
*/
|
||||
@Override
|
||||
public void addGroup(RegionGroup group) {
|
||||
groups.put(group.getName().toLowerCase(), group);
|
||||
String lowGroup = group.getName().toLowerCase();
|
||||
@@ -390,7 +395,11 @@ public class FileManager extends Manager {
|
||||
* @param type The type the region should have in AreaShop
|
||||
* @return The result if a player would want to add this region
|
||||
*/
|
||||
public AddResult checkRegionAdd(CommandSender sender, ProtectedRegion region, World world, RegionType type) {
|
||||
@Override
|
||||
public AddResult checkRegionAdd(CommandSender sender,
|
||||
ProtectedRegion region,
|
||||
World world,
|
||||
RegionType type) {
|
||||
Player player = null;
|
||||
if(sender instanceof Player) {
|
||||
player = (Player)sender;
|
||||
@@ -432,6 +441,7 @@ public class FileManager extends Manager {
|
||||
* @param giveMoneyBack use true to give money back to the player if someone is currently holding this region, otherwise false
|
||||
* @return true if the region has been removed, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public DeletingRegionEvent deleteRegion(GeneralRegion region, boolean giveMoneyBack) {
|
||||
DeletingRegionEvent event = new DeletingRegionEvent(region);
|
||||
if(region == null) {
|
||||
@@ -496,6 +506,7 @@ public class FileManager extends Manager {
|
||||
* Remove a group.
|
||||
* @param group Group to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeGroup(RegionGroup group) {
|
||||
groups.remove(group.getLowerCaseName());
|
||||
groupsConfig.set(group.getLowerCaseName(), null);
|
||||
@@ -505,6 +516,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Update all signs that need periodic updating.
|
||||
*/
|
||||
@Override
|
||||
public void performPeriodicSignUpdate() {
|
||||
Do.forAll(
|
||||
plugin.getConfig().getInt("signs.regionsPerTick"),
|
||||
@@ -520,6 +532,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Send out rent expire warnings.
|
||||
*/
|
||||
@Override
|
||||
public void sendRentExpireWarnings() {
|
||||
Do.forAll(
|
||||
plugin.getConfig().getInt("expireWarning.regionsPerTick"),
|
||||
@@ -533,7 +546,9 @@ public class FileManager extends Manager {
|
||||
* @param regions Regions to update
|
||||
* @param confirmationReceiver The CommandSender that should be notified at completion
|
||||
*/
|
||||
public void updateRegions(final Collection<GeneralRegion> regions, final CommandSender confirmationReceiver) {
|
||||
@Override
|
||||
public void updateRegions(final Collection<GeneralRegion> regions,
|
||||
final CommandSender confirmationReceiver) {
|
||||
final int regionsPerTick = plugin.getConfig().getInt("update.regionsPerTick");
|
||||
if(confirmationReceiver != null) {
|
||||
messageBridge.message(confirmationReceiver, "reload-updateStart", regions.size(), regionsPerTick * 20);
|
||||
@@ -554,6 +569,7 @@ public class FileManager extends Manager {
|
||||
* Update a list of regions.
|
||||
* @param regions The list of regions to update.
|
||||
*/
|
||||
@Override
|
||||
public void updateRegions(Collection<GeneralRegion> regions) {
|
||||
updateRegions(regions, null);
|
||||
}
|
||||
@@ -561,6 +577,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Update all regions, happens in a task to minimize lag.
|
||||
*/
|
||||
@Override
|
||||
public void updateAllRegions() {
|
||||
updateRegions(getRegionsRef(), null);
|
||||
}
|
||||
@@ -569,6 +586,7 @@ public class FileManager extends Manager {
|
||||
* Update all regions.
|
||||
* @param confirmationReceiver Optional CommandSender that should receive progress messages
|
||||
*/
|
||||
@Override
|
||||
public void updateAllRegions(CommandSender confirmationReceiver) {
|
||||
updateRegions(getRegionsRef(), confirmationReceiver);
|
||||
}
|
||||
@@ -577,6 +595,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Save the group file to disk.
|
||||
*/
|
||||
@Override
|
||||
public void saveGroupsIsRequired() {
|
||||
saveGroupsRequired = true;
|
||||
}
|
||||
@@ -585,6 +604,7 @@ public class FileManager extends Manager {
|
||||
* Check if saving the groups file is required.
|
||||
* @return true if changes are made and saving is required, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isSaveGroupsRequired() {
|
||||
return saveGroupsRequired;
|
||||
}
|
||||
@@ -592,6 +612,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Save the groups file to disk synchronously.
|
||||
*/
|
||||
@Override
|
||||
public void saveGroupsNow() {
|
||||
AreaShop.debug("saveGroupsNow() done");
|
||||
saveGroupsRequired = false;
|
||||
@@ -606,6 +627,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Save all region related files spread over time (low load).
|
||||
*/
|
||||
@Override
|
||||
public void saveRequiredFiles() {
|
||||
if(isSaveGroupsRequired()) {
|
||||
saveGroupsNow();
|
||||
@@ -626,6 +648,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Save all region related files directly (only for cases like onDisable()).
|
||||
*/
|
||||
@Override
|
||||
public void saveRequiredFilesAtOnce() {
|
||||
if(isSaveGroupsRequired()) {
|
||||
saveGroupsNow();
|
||||
@@ -642,6 +665,7 @@ public class FileManager extends Manager {
|
||||
* Indicates that a/multiple WorldGuard regions need to be saved.
|
||||
* @param worldName The world where the regions that should be saved is in
|
||||
*/
|
||||
@Override
|
||||
public void saveIsRequiredForRegionWorld(String worldName) {
|
||||
worldRegionsRequireSaving.add(worldName);
|
||||
}
|
||||
@@ -649,6 +673,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Save all worldGuard regions that need saving.
|
||||
*/
|
||||
@Override
|
||||
public void saveWorldGuardRegions() {
|
||||
for(String world : worldRegionsRequireSaving) {
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
@@ -669,6 +694,7 @@ public class FileManager extends Manager {
|
||||
* Get the folder the region files are located in.
|
||||
* @return The folder where the region.yml files are in
|
||||
*/
|
||||
@Override
|
||||
public String getRegionFolder() {
|
||||
return regionsPath;
|
||||
}
|
||||
@@ -678,6 +704,7 @@ public class FileManager extends Manager {
|
||||
* @param region The region name to check
|
||||
* @return true if the region may not be added, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlacklisted(String region) {
|
||||
for(String line : plugin.getConfig().getStringList("blacklist")) {
|
||||
Pattern pattern = Pattern.compile(line, Pattern.CASE_INSENSITIVE);
|
||||
@@ -692,6 +719,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Unrent regions that have no time left, regions to check per tick is in the config.
|
||||
*/
|
||||
@Override
|
||||
public void checkRents() {
|
||||
Do.forAll(
|
||||
plugin.getConfig().getInt("expiration.regionsPerTick"),
|
||||
@@ -703,6 +731,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Check all regions and unrent/sell them if the player is inactive for too long.
|
||||
*/
|
||||
@Override
|
||||
public void checkForInactiveRegions() {
|
||||
Do.forAll(
|
||||
plugin.getConfig().getInt("inactive.regionsPerTick"),
|
||||
@@ -715,6 +744,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Load the file with the versions, used to check if the other files need conversion.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadVersions() {
|
||||
File file = new File(versionPath);
|
||||
@@ -737,6 +767,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Save the versions file to disk.
|
||||
*/
|
||||
@Override
|
||||
public void saveVersions() {
|
||||
if(!(new File(versionPath).exists())) {
|
||||
AreaShop.debug("versions file created, this should happen only after installing or upgrading the plugin");
|
||||
@@ -753,6 +784,7 @@ public class FileManager extends Manager {
|
||||
* @param thisTick Load files in the current tick or a tick later
|
||||
* @return true if the files are loaded correctly, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean loadFiles(boolean thisTick) {
|
||||
// Load config.yml + add defaults from .jar
|
||||
boolean result = loadConfigFile();
|
||||
@@ -784,6 +816,7 @@ public class FileManager extends Manager {
|
||||
* Load the default.yml file
|
||||
* @return true if it has been loaded successfully, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean loadDefaultFile() {
|
||||
boolean result = true;
|
||||
File defaultFile = new File(defaultPath);
|
||||
@@ -805,8 +838,8 @@ public class FileManager extends Manager {
|
||||
}
|
||||
// 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()) {
|
||||
@@ -824,6 +857,7 @@ public class FileManager extends Manager {
|
||||
* Load the default.yml file
|
||||
* @return true if it has been loaded successfully, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean loadConfigFile() {
|
||||
boolean result = true;
|
||||
File configFile = new File(configPath);
|
||||
@@ -845,9 +879,9 @@ public class FileManager extends Manager {
|
||||
}
|
||||
// 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()) {
|
||||
@@ -878,12 +912,13 @@ public class FileManager extends Manager {
|
||||
* Load the groups.yml file from disk
|
||||
* @return true if succeeded, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean loadGroupsFile() {
|
||||
boolean result = true;
|
||||
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) {
|
||||
@@ -903,6 +938,7 @@ public class FileManager extends Manager {
|
||||
/**
|
||||
* Load all region files.
|
||||
*/
|
||||
@Override
|
||||
public void loadRegionFiles() {
|
||||
regions.clear();
|
||||
final File file = new File(regionsPath);
|
||||
@@ -928,7 +964,7 @@ public class FileManager extends Manager {
|
||||
List<String> noRegionType = new ArrayList<>();
|
||||
List<String> noNamePaths = new ArrayList<>();
|
||||
List<GeneralRegion> noWorld = new ArrayList<>();
|
||||
List<GeneralRegion> noRegion = new ArrayList<>();
|
||||
Map<GeneralRegion, File> noRegion = new HashMap<>();
|
||||
List<GeneralRegion> incorrectDuration = new ArrayList<>();
|
||||
for(File regionFile : regionFiles) {
|
||||
if(regionFile.exists() && regionFile.isFile() && !regionFile.isHidden()) {
|
||||
@@ -936,11 +972,13 @@ public class FileManager extends Manager {
|
||||
// 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()) {
|
||||
AreaShop.warn("Region file '" + regionFile.getName() + "' is empty, check for errors in the log.");
|
||||
regionFile.delete();
|
||||
continue;
|
||||
}
|
||||
} catch(IOException e) {
|
||||
AreaShop.warn("Something went wrong reading region file: " + regionFile.getAbsolutePath());
|
||||
@@ -966,7 +1004,7 @@ public class FileManager extends Manager {
|
||||
} else if(region.getWorld() == null) {
|
||||
noWorld.add(region);
|
||||
} else if(region.getRegion() == null) {
|
||||
noRegion.add(region);
|
||||
noRegion.put(region, regionFile);
|
||||
} else if(region instanceof RentRegion && !Utils.checkTimeFormat(((RentRegion)region).getDurationString())) {
|
||||
incorrectDuration.add(region);
|
||||
} else {
|
||||
@@ -990,11 +1028,11 @@ public class FileManager extends Manager {
|
||||
|
||||
if(!noRegion.isEmpty()) {
|
||||
List<String> noRegionNames = new ArrayList<>();
|
||||
for(GeneralRegion region : noRegion) {
|
||||
noRegionNames.add(region.getName());
|
||||
for(Map.Entry<GeneralRegion, File> regionMap : noRegion.entrySet()) {
|
||||
noRegionNames.add(regionMap.getKey().getName());
|
||||
regionMap.getValue().delete();
|
||||
}
|
||||
AreaShop.warn("AreaShop regions that are missing their WorldGuard region: " + Utils.createCommaSeparatedList(noRegionNames));
|
||||
AreaShop.warn("Remove these regions from AreaShop with '/as del' or recreate their regions in WorldGuard.");
|
||||
AreaShop.warn("AreaShop regions that are missing their WorldGuard region are now being deleted: " + Utils.createCommaSeparatedList(noRegionNames));
|
||||
}
|
||||
|
||||
boolean noWorldRegions = !noWorld.isEmpty();
|
||||
@@ -1345,6 +1383,7 @@ public class FileManager extends Manager {
|
||||
* @param groupName Name of the group to get the settings from
|
||||
* @return The settings of the group
|
||||
*/
|
||||
@Override
|
||||
public ConfigurationSection getGroupSettings(String groupName) {
|
||||
return groupsConfig.getConfigurationSection(groupName.toLowerCase());
|
||||
}
|
||||
@@ -1355,6 +1394,7 @@ public class FileManager extends Manager {
|
||||
* @param path The path to set
|
||||
* @param setting The value to set
|
||||
*/
|
||||
@Override
|
||||
public void setGroupSetting(RegionGroup group, String path, Object setting) {
|
||||
groupsConfig.set(group.getName().toLowerCase() + "." + path, setting);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
package me.wiefferink.areashop.managers;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface IFileManager {
|
||||
|
||||
/**
|
||||
* Get the folder where schematics are stored.
|
||||
*
|
||||
* @return The folder where schematics are stored
|
||||
*/
|
||||
String getSchematicFolder();
|
||||
|
||||
/**
|
||||
* Get a group.
|
||||
*
|
||||
* @param name The name of the group to get (will be normalized)
|
||||
* @return The group if found, otherwise null
|
||||
*/
|
||||
RegionGroup getGroup(String name);
|
||||
|
||||
/**
|
||||
* Get all groups.
|
||||
*
|
||||
* @return Collection with all groups (safe to modify)
|
||||
*/
|
||||
Collection<RegionGroup> getGroups();
|
||||
|
||||
/**
|
||||
* Get the default region settings as provided by the user (default.yml).
|
||||
*
|
||||
* @return YamlConfiguration with the settings (might miss settings, which should be filled in with {@link #getFallbackRegionSettings()})
|
||||
*/
|
||||
YamlConfiguration getRegionSettings();
|
||||
|
||||
/**
|
||||
* Get the default regions settings as provided by AreaShop (default.yml).
|
||||
*
|
||||
* @return YamlConfiguration with the default settings
|
||||
*/
|
||||
YamlConfiguration getFallbackRegionSettings();
|
||||
|
||||
/**
|
||||
* Get the config file (config.yml).
|
||||
*
|
||||
* @return YamlConfiguration with the settings of users, with fallback to the settings provided by AreaShop
|
||||
*/
|
||||
YamlConfiguration getConfig();
|
||||
|
||||
/**
|
||||
* Get a region.
|
||||
*
|
||||
* @param name The name of the region to get (will be normalized)
|
||||
* @return The region if found, otherwise null
|
||||
*/
|
||||
@Nullable
|
||||
GeneralRegion getRegion(String name);
|
||||
|
||||
/**
|
||||
* Get a rental region.
|
||||
*
|
||||
* @param name The name of the rental region (will be normalized)
|
||||
* @return RentRegion if it could be found, otherwise null
|
||||
*/
|
||||
@Nullable
|
||||
RentRegion getRent(String name);
|
||||
|
||||
/**
|
||||
* Get a buy region.
|
||||
*
|
||||
* @param name The name of the buy region (will be normalized)
|
||||
* @return BuyRegion if it could be found, otherwise null
|
||||
*/
|
||||
@Nullable
|
||||
BuyRegion getBuy(String name);
|
||||
|
||||
/**
|
||||
* Get all rental regions.
|
||||
*
|
||||
* @return List of all rental regions
|
||||
*/
|
||||
Collection<RentRegion> getRents();
|
||||
|
||||
/**
|
||||
* Get all rental regions.
|
||||
*
|
||||
* @return List of all rental regions
|
||||
*/
|
||||
Collection<RentRegion> getRentsRef();
|
||||
|
||||
/**
|
||||
* Get all buy regions.
|
||||
*
|
||||
* @return List of all buy regions
|
||||
*/
|
||||
List<BuyRegion> getBuys();
|
||||
|
||||
Collection<BuyRegion> getBuysRef();
|
||||
|
||||
/**
|
||||
* Get all regions.
|
||||
*
|
||||
* @return List of all regions (it is safe to modify the list)
|
||||
*/
|
||||
List<GeneralRegion> getRegions();
|
||||
|
||||
/**
|
||||
* Get all regions.
|
||||
*
|
||||
* @return List of all regions (it is safe to modify the list)
|
||||
*/
|
||||
Collection<GeneralRegion> getRegionsRef();
|
||||
|
||||
/**
|
||||
* Get a list of names of all buy regions.
|
||||
*
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
List<String> getBuyNames();
|
||||
|
||||
/**
|
||||
* Get a list of names of all rent regions.
|
||||
*
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
List<String> getRentNames();
|
||||
|
||||
/**
|
||||
* Get a list of names of all regions.
|
||||
*
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
List<String> getRegionNames();
|
||||
|
||||
/**
|
||||
* Get a list of names of all groups.
|
||||
*
|
||||
* @return A String list with all the names
|
||||
*/
|
||||
List<String> getGroupNames();
|
||||
|
||||
/**
|
||||
* Add a region to the list and mark it as to-be-saved.
|
||||
*
|
||||
* @param region Then region to add
|
||||
* @return true when successful, otherwise false (denied by an event listener)
|
||||
*/
|
||||
AddingRegionEvent addRegion(GeneralRegion region);
|
||||
|
||||
/**
|
||||
* Add a region to the list without saving it to disk (useful for loading at startup).
|
||||
*
|
||||
* @param region The region to add
|
||||
* @return true when successful, otherwise false (denied by an event listener)
|
||||
*/
|
||||
AddingRegionEvent addRegionNoSave(GeneralRegion region);
|
||||
|
||||
/**
|
||||
* Mark all RegionGroups that they should regenerate regions.
|
||||
*/
|
||||
void markGroupsAutoDirty();
|
||||
|
||||
/**
|
||||
* Add a RegionGroup.
|
||||
*
|
||||
* @param group The RegionGroup to add
|
||||
*/
|
||||
void addGroup(RegionGroup group);
|
||||
|
||||
/**
|
||||
* Check if a player can add a certain region as rent or buy region.
|
||||
*
|
||||
* @param sender The player/console that wants to add a region
|
||||
* @param region The WorldGuard region to add
|
||||
* @param world The world the ProtectedRegion is located in
|
||||
* @param type The type the region should have in AreaShop
|
||||
* @return The result if a player would want to add this region
|
||||
*/
|
||||
AddResult checkRegionAdd(CommandSender sender,
|
||||
ProtectedRegion region,
|
||||
World world,
|
||||
GeneralRegion.RegionType type);
|
||||
|
||||
/**
|
||||
* Remove a region from the list.
|
||||
*
|
||||
* @param region The region to remove
|
||||
* @param giveMoneyBack use true to give money back to the player if someone is currently holding this region, otherwise false
|
||||
* @return true if the region has been removed, false otherwise
|
||||
*/
|
||||
DeletingRegionEvent deleteRegion(GeneralRegion region, boolean giveMoneyBack);
|
||||
|
||||
/**
|
||||
* Remove a group.
|
||||
*
|
||||
* @param group Group to remove
|
||||
*/
|
||||
void removeGroup(RegionGroup group);
|
||||
|
||||
/**
|
||||
* Update all signs that need periodic updating.
|
||||
*/
|
||||
void performPeriodicSignUpdate();
|
||||
|
||||
/**
|
||||
* Send out rent expire warnings.
|
||||
*/
|
||||
void sendRentExpireWarnings();
|
||||
|
||||
/**
|
||||
* Update regions in a task to minimize lag.
|
||||
*
|
||||
* @param regions Regions to update
|
||||
* @param confirmationReceiver The CommandSender that should be notified at completion
|
||||
*/
|
||||
void updateRegions(Collection<GeneralRegion> regions, CommandSender confirmationReceiver);
|
||||
|
||||
/**
|
||||
* Update a list of regions.
|
||||
*
|
||||
* @param regions The list of regions to update.
|
||||
*/
|
||||
void updateRegions(Collection<GeneralRegion> regions);
|
||||
|
||||
/**
|
||||
* Update all regions, happens in a task to minimize lag.
|
||||
*/
|
||||
void updateAllRegions();
|
||||
|
||||
/**
|
||||
* Update all regions.
|
||||
*
|
||||
* @param confirmationReceiver Optional CommandSender that should receive progress messages
|
||||
*/
|
||||
void updateAllRegions(CommandSender confirmationReceiver);
|
||||
|
||||
/**
|
||||
* Save the group file to disk.
|
||||
*/
|
||||
void saveGroupsIsRequired();
|
||||
|
||||
/**
|
||||
* Check if saving the groups file is required.
|
||||
*
|
||||
* @return true if changes are made and saving is required, otherwise false
|
||||
*/
|
||||
boolean isSaveGroupsRequired();
|
||||
|
||||
/**
|
||||
* Save the groups file to disk synchronously.
|
||||
*/
|
||||
void saveGroupsNow();
|
||||
|
||||
/**
|
||||
* Save all region related files spread over time (low load).
|
||||
*/
|
||||
void saveRequiredFiles();
|
||||
|
||||
/**
|
||||
* Save all region related files directly (only for cases like onDisable()).
|
||||
*/
|
||||
void saveRequiredFilesAtOnce();
|
||||
|
||||
/**
|
||||
* Indicates that a/multiple WorldGuard regions need to be saved.
|
||||
*
|
||||
* @param worldName The world where the regions that should be saved is in
|
||||
*/
|
||||
void saveIsRequiredForRegionWorld(String worldName);
|
||||
|
||||
/**
|
||||
* Save all worldGuard regions that need saving.
|
||||
*/
|
||||
void saveWorldGuardRegions();
|
||||
|
||||
/**
|
||||
* Get the folder the region files are located in.
|
||||
*
|
||||
* @return The folder where the region.yml files are in
|
||||
*/
|
||||
String getRegionFolder();
|
||||
|
||||
/**
|
||||
* Check if a region is on the adding blacklist.
|
||||
*
|
||||
* @param region The region name to check
|
||||
* @return true if the region may not be added, otherwise false
|
||||
*/
|
||||
boolean isBlacklisted(String region);
|
||||
|
||||
/**
|
||||
* Unrent regions that have no time left, regions to check per tick is in the config.
|
||||
*/
|
||||
void checkRents();
|
||||
|
||||
/**
|
||||
* Check all regions and unrent/sell them if the player is inactive for too long.
|
||||
*/
|
||||
void checkForInactiveRegions();
|
||||
|
||||
/**
|
||||
* Load the file with the versions, used to check if the other files need conversion.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
void loadVersions();
|
||||
|
||||
/**
|
||||
* Save the versions file to disk.
|
||||
*/
|
||||
void saveVersions();
|
||||
|
||||
/**
|
||||
* Load all files from disk.
|
||||
*
|
||||
* @param thisTick Load files in the current tick or a tick later
|
||||
* @return true if the files are loaded correctly, otherwise false
|
||||
*/
|
||||
boolean loadFiles(boolean thisTick);
|
||||
|
||||
/**
|
||||
* Load the default.yml file
|
||||
*
|
||||
* @return true if it has been loaded successfully, otherwise false
|
||||
*/
|
||||
boolean loadDefaultFile();
|
||||
|
||||
/**
|
||||
* Load the default.yml file
|
||||
*
|
||||
* @return true if it has been loaded successfully, otherwise false
|
||||
*/
|
||||
boolean loadConfigFile();
|
||||
|
||||
/**
|
||||
* Load the groups.yml file from disk
|
||||
*
|
||||
* @return true if succeeded, otherwise false
|
||||
*/
|
||||
boolean loadGroupsFile();
|
||||
|
||||
/**
|
||||
* Load all region files.
|
||||
*/
|
||||
void loadRegionFiles();
|
||||
|
||||
/**
|
||||
* Get the settings of a group.
|
||||
*
|
||||
* @param groupName Name of the group to get the settings from
|
||||
* @return The settings of the group
|
||||
*/
|
||||
ConfigurationSection getGroupSettings(String groupName);
|
||||
|
||||
/**
|
||||
* Set a setting for a group.
|
||||
*
|
||||
* @param group The group to set it for
|
||||
* @param path The path to set
|
||||
* @param setting The value to set
|
||||
*/
|
||||
void setGroupSetting(RegionGroup group, String path, Object setting);
|
||||
|
||||
// Enum for region types
|
||||
public enum AddResult {
|
||||
BLACKLISTED("blacklisted"),
|
||||
NOPERMISSION("nopermission"),
|
||||
ALREADYADDED("alreadyadded"),
|
||||
ALREADYADDEDOTHERWORLD("alreadyaddedotherworld"),
|
||||
SUCCESS("success");
|
||||
|
||||
private final String value;
|
||||
|
||||
AddResult(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,15 +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.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;
|
||||
@@ -23,51 +22,46 @@ 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);
|
||||
// Setup managers
|
||||
bind(FileManager.class).asEagerSingleton();
|
||||
bind(IFileManager.class).to(FileManager.class).asEagerSingleton();
|
||||
bind(FeatureManager.class).in(Singleton.class);
|
||||
bind(CommandManager.class).in(Singleton.class);
|
||||
bind(SignLinkerManager.class).in(Singleton.class);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -237,31 +237,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 +468,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 +523,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 {
|
||||
|
||||
@@ -13,7 +13,7 @@ import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.FeatureManager;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.bukkitdo.Do;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
@@ -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 {
|
||||
|
||||
@@ -415,7 +417,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
|
||||
* Get the FileManager from the plugin.
|
||||
* @return The FileManager (responsible for saving/loading regions and getting them)
|
||||
*/
|
||||
public FileManager getFileManager() {
|
||||
public IFileManager getFileManager() {
|
||||
return plugin.getFileManager();
|
||||
}
|
||||
|
||||
@@ -478,7 +480,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 +493,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 +512,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 +630,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 +808,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 +819,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 +873,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 +981,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 +1489,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 +1522,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -34,7 +34,7 @@ import java.util.UUID;
|
||||
public class ImportJob {
|
||||
|
||||
private final AreaShop plugin;
|
||||
private final FileManager fileManager;
|
||||
private final IFileManager fileManager;
|
||||
private final SignManager signManager;
|
||||
private final WorldGuardInterface worldGuardInterface;
|
||||
private final CommandSender sender;
|
||||
@@ -48,7 +48,7 @@ public class ImportJob {
|
||||
@AssistedInject
|
||||
ImportJob(
|
||||
@Nonnull AreaShop plugin,
|
||||
@Nonnull FileManager fileManager,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull SignManager signManager,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface,
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@@ -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"));
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.wiefferink.areashop.regions;
|
||||
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -16,7 +16,7 @@ import java.util.Set;
|
||||
public class RegionGroup {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final FileManager fileManager;
|
||||
private final IFileManager fileManager;
|
||||
private final String name;
|
||||
private final Set<String> regions;
|
||||
private Set<String> autoRegions;
|
||||
@@ -29,7 +29,7 @@ public class RegionGroup {
|
||||
* @param name Name of the group, has to be unique
|
||||
*/
|
||||
@AssistedInject
|
||||
RegionGroup(@Nonnull Plugin plugin, @Nonnull FileManager fileManager, @Assisted String name) {
|
||||
RegionGroup(@Nonnull Plugin plugin, @Nonnull IFileManager fileManager, @Assisted String name) {
|
||||
this.plugin = plugin;
|
||||
this.fileManager = fileManager;
|
||||
this.name = name;
|
||||
|
||||
@@ -165,43 +165,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 +657,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 +714,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"))
|
||||
}
|
||||
|
||||
}
|
||||
+14
-15
@@ -1,12 +1,11 @@
|
||||
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.BlockPosition;
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
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.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock;
|
||||
@@ -20,28 +19,28 @@ public class BlockBehaviourImpl implements BlockBehaviourHelper {
|
||||
@Override
|
||||
public boolean canPlace(Location location, BlockData blockData) {
|
||||
Objects.requireNonNull(location.getWorld(), "Null World!");
|
||||
final BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
|
||||
final BlockPos blockPos = new BlockPos(location.getX(), location.getY(), location.getZ());
|
||||
final CraftWorld craftWorld = (CraftWorld) location.getWorld();
|
||||
final World world = craftWorld.getHandle();
|
||||
final ServerLevel world = craftWorld.getHandle();
|
||||
final CraftBlockData craftBlockData = (CraftBlockData) blockData;
|
||||
final IBlockData ibd = craftBlockData.getState();
|
||||
return ibd.canPlace(world, blockPosition);
|
||||
final BlockState ibd = craftBlockData.getState();
|
||||
return ibd.canSurvive(world, blockPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockValid(Block block) {
|
||||
final CraftBlock craftBlock = (CraftBlock) block;
|
||||
final CraftWorld craftWorld = (CraftWorld) craftBlock.getWorld();
|
||||
final World world = craftWorld.getHandle();
|
||||
final IBlockData ibd = craftBlock.getNMS();
|
||||
return ibd.canPlace(world, craftBlock.getPosition());
|
||||
final ServerLevel world = craftWorld.getHandle();
|
||||
final BlockState ibd = craftBlock.getNMS();
|
||||
return ibd.canSurvive(world, craftBlock.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockStateValid(BlockState blockState) {
|
||||
public boolean isBlockStateValid(org.bukkit.block.BlockState blockState) {
|
||||
final CraftBlockState craftBlockState = (CraftBlockState) blockState;
|
||||
final IBlockData ibd = craftBlockState.getHandle();
|
||||
return ibd.canPlace(craftBlockState.getBlock().getCraftWorld().getHandle(), craftBlockState.getPosition());
|
||||
final BlockState ibd = craftBlockState.getHandle();
|
||||
return ibd.canSurvive(craftBlockState.getBlock().getCraftWorld().getHandle(), craftBlockState.getPosition());
|
||||
}
|
||||
|
||||
}
|
||||
+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"))
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package me.wiefferink.areashop.adapters.platform.v1_18_R2;
|
||||
|
||||
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_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;
|
||||
|
||||
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.getX(), location.getY(), location.getZ());
|
||||
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_18_R2;
|
||||
|
||||
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.19.2-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_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_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_19_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.getX(), location.getY(), location.getZ());
|
||||
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_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)
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
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, () -> future.complete(plugin.getServer().getPlayer(username)));
|
||||
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,6 +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'
|
||||
-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,7 +0,0 @@
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.2.5'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.5'
|
||||
}
|
||||
|
||||
description = 'AreaShop Interface'
|
||||
@@ -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,54 +0,0 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'me.wiefferink.areashop'
|
||||
version = '2.7.0-SNAPSHOT'
|
||||
|
||||
subprojects {
|
||||
|
||||
plugins.apply('java')
|
||||
|
||||
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) {
|
||||
tasks.withType(JavaCompile) {
|
||||
javaToolchains.compilerFor {
|
||||
JavaLanguageVersion.of(16)
|
||||
}
|
||||
options.release.set(16)
|
||||
options.encoding = 'UTF-8'
|
||||
options.fork = true
|
||||
options.deprecation = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
plugins {
|
||||
java
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
id("io.papermc.paperweight.userdev") version "1.3.6" apply false
|
||||
idea
|
||||
eclipse
|
||||
}
|
||||
|
||||
group = "me.wiefferink"
|
||||
version = "2.7.9"
|
||||
|
||||
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/")
|
||||
}
|
||||
|
||||
tasks {
|
||||
withType(JavaCompile::class) {
|
||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
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 |
|
||||
@@ -0,0 +1,3 @@
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
org.gradle.java.installations.auto-download=false
|
||||
@@ -0,0 +1,30 @@
|
||||
[versions]
|
||||
# Platforms
|
||||
minecraft = "1.17.1-R0.1-SNAPSHOT"
|
||||
findbugs = "3.0.2"
|
||||
|
||||
# Minecraft Plugins
|
||||
worldedit = "7.2.12"
|
||||
worldguard = "7.0.7"
|
||||
fawe = "2.4.5"
|
||||
|
||||
# Gradle plugins
|
||||
paperweight = "1.3.7"
|
||||
|
||||
[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" }
|
||||
|
||||
[plugins]
|
||||
# Gradle plugins
|
||||
paperweightUserdev = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight" }
|
||||
Vendored
BIN
Binary file not shown.
Loaded 100 of 114 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user