Compare commits

...
88 Commits
Author SHA1 Message Date
Andrew Wong e56107ffd6 Fix signs not being deleted from the global sign cache in memory 2023-11-12 17:59:34 +11:00
Andrew Wong 06fceb4643 Drop support for 1.20 and 1.20.1 2023-11-12 15:50:51 +11:00
Andrew Wong e2077c3b32 Fix region signs losing their interactivity after restart. Resolves #20 2023-11-12 15:40:03 +11:00
Andrew Wong fcb64c2ddb Merge pull request #22 from o0sh4d0w0o/ResoldRegionEvent-resellprice-fix
Fixed getResellPrice unsetted when ResoldRegionEvent is notified
2023-10-04 21:35:03 +11:00
o0sh4d0w0o cc51109720 Fixed getResellPrice unsetted when ResoldRegionEvent is notified 2023-10-01 16:03:07 +02:00
Andrew Wong 0b48f4dd2e Fix not including 1.20.2 adapter 2023-09-25 11:37:12 +10:00
Andrew Wong 4d7f00b0ce Add support for 1.20.2 2023-09-25 11:33:02 +10:00
Andrew Wong b27ea83982 Include 1.18-1.20 adapters for jitpack 2023-09-03 08:47:21 +10:00
Andrew Wong 66da717a77 Fix relocations 2023-09-03 08:47:19 +10:00
Andrew Wong 7f779d2df8 Bump version to 2.7.14-SNAPSHOT 2023-09-03 08:47:16 +10:00
Andrew Wong ed3bd01f2a Fix bad release url
Fixes #19
2023-09-03 07:22:58 +10:00
Andrew Wong ef03501d1c 2.7.13 release 2023-08-30 22:09:28 +10:00
Andrew Wong feb35cfd37 User api for BlockBehaviourImpl 1.18 onwards 2023-08-30 22:08:50 +10:00
Andrew Wong b6a8dcc24c Fix module desc for paper 1.20 2023-08-30 20:23:05 +10:00
Andrew Wong 5619612a6e Update gradle wrapper 2023-08-28 23:10:54 +10:00
Andrew Wong 26ac52cc0a Include plugin adapters in jitpack build 2023-08-28 22:46:14 +10:00
Andrew Wong 5f6bd55afe Don't include nms impls if on jitpack 2023-08-28 22:34:28 +10:00
Andrew Wong aba2e12c5d Don't include nms impls if on jitpack 2023-08-28 22:26:28 +10:00
Andrew Wong 2906de11de Fix merge conflicts 2023-08-28 22:17:42 +10:00
Andrew Wong 436672f85b Don't shadowJar and don't include nms providers if building on jitpack 2023-08-28 22:12:09 +10:00
Andrew Wong 5ba8ed7ad8 Add spotbugs 2023-08-28 20:57:17 +10:00
Andrew Wong 00d97f1beb Update dependencies 2023-08-28 20:36:52 +10:00
Andrew Wong f530fa40af Fix signs not being saved on server stop 2023-08-28 20:14:12 +10:00
Andrew Wong a804df2257 Add jitpack logo 2023-08-09 14:08:12 +10:00
Andrew Wong c96e0b464e More jitpack tests 2023-08-09 13:58:44 +10:00
Andrew Wong 13e52aa4f1 More jitpack tests 2023-08-09 13:55:52 +10:00
Andrew Wong 9aeb531d16 More jitpack tests 2023-08-09 13:52:23 +10:00
Andrew Wong 44f83473d1 Add jitpack.yml 2023-08-09 13:46:05 +10:00
Andrew Wong d7260998f5 Update Guice to 7.0.0 and use JakartaEE annotations 2023-06-12 00:59:16 +10:00
Andrew Wong 638382eacf Snapshot 2.7.13 2023-06-12 00:58:34 +10:00
Andrew Wong e18fe99161 Release 2.7.12 2023-06-12 00:40:46 +10:00
Andrew Wong bdc9e32c13 Add support for 1.20 2023-06-12 00:40:08 +10:00
Andrew Wong 9a46d5ae3b Bump version to 2.7.12-SNAPSHOT 2023-03-29 16:14:26 +11:00
Andrew Wong 6795fc43d9 Release 2.7.11 2023-03-29 16:13:54 +11:00
Andrew Wong dd9bd2c434 Drop support for 1.19.3 and add support for 1.19.4 2023-03-29 16:13:23 +11:00
Andrew Wong 9438166180 Prepare for development 2.7.11 2023-02-27 21:58:41 +11:00
Andrew Wong 9e06b9f268 Release 2.7.10 2023-02-27 21:58:14 +11:00
Andrew Wong 4562bf23f6 Update libs 2023-02-27 21:57:49 +11:00
Andrew Wong 24edb01754 Refactor GeneralRegion#getOwner, #isOwner and #setOwner 2023-02-27 21:46:59 +11:00
Andrew Wong 2739bf6ad4 Fix javadocs for IFileManager 2023-02-27 21:41:28 +11:00
Andrew Wong 2ce84186ab Use Server#getOfflinePlayer in PlayerOfflinePlayerHelper 2023-02-27 21:39:48 +11:00
Andrew Wong 279fa001ea Only support 1.19.3 2023-02-27 11:56:41 +11:00
Andrew Wong b56d5320a6 Add support for 1.19.3 2022-12-15 16:25:06 +08:00
Andrew Wong 30665908b9 Bump to 2.7.10-SNAPSHOT 2022-12-09 16:53:03 +08:00
Andrew Wong 0fd384833a Bump version to 2.7.9 release 2022-12-09 16:45:57 +08:00
Andrew Wong 09634de4bf Fix BukkitSchedulerExecutor not having an injectable ctor 2022-12-07 12:13:34 +08:00
Andrew Wong 7fafee82a7 Minor cleanup 2022-12-07 11:59:37 +08:00
Andrew Wong 2899b2978c Rewrite SetownerCommand 2022-12-07 11:56:50 +08:00
Andrew Wong 7afcba79c9 Rewrite SetlandlordCommand 2022-12-07 11:53:44 +08:00
Andrew Wong 72084b38f8 Use OfflinePlayerHelper in MeCommand 2022-12-07 11:49:01 +08:00
Andrew Wong 6a291feedd Rewrite DelFriendCommand 2022-12-07 11:45:16 +08:00
Andrew Wong b85566882c Rewrite AddfriendCommand 2022-12-07 11:39:09 +08:00
Andrew Wong c14407e14b Add PaperPlatform 2022-12-07 01:23:12 +08:00
Andrew Wong ae9bd60d1b Fix typo 2022-09-14 21:25:04 +08:00
Andrew Wong c689c2fae0 Fix dependency versions for WG and WE, and add a section for FAWE 2022-09-14 21:24:48 +08:00
Andrew Wong 728cfb6dfa Add a compiling.md 2022-09-14 21:16:03 +08:00
Andrew Wong 3abb6c06e4 Update readme 2022-09-14 20:56:00 +08:00
Andrew Wong 51c11738af Prepare for snapshot development 2022-09-12 22:39:45 +08:00
Andrew Wong 172b5a99f1 Bump version to release 2022-09-12 22:21:28 +08:00
Andrew Wong 4c5d025e54 Add config option to toggle whether entities are forcefully cleared 2022-09-12 22:20:55 +08:00
Andrew Wong e93a2d04de Forcefully remove entities from FAWE/WE regions before schematic pasting 2022-09-12 22:12:18 +08:00
Andrew Wong af5980d555 Change the messages for update checking and report file manager loading failures 2022-09-12 17:58:09 +08:00
Andrew Wong 3f7249f4a1 Merge pull request #13 from cleonyc/dev/bleeding
Allow unrented event to use placeholders
2022-09-12 17:39:56 +08:00
Andrew Wong 73c6fc858e Update the logging methods to invoke conditionally 2022-09-12 17:37:47 +08:00
Andrew Wong 360c3e7e21 Use Suppliers when logging in the plugin adapters 2022-09-12 17:35:55 +08:00
Andrew Wong 73d0115b78 Actually fix the FAWE and WE handlers when pasting 2022-09-12 17:25:27 +08:00
Andrew Wong baf7eaabf1 Bump versions of WE and FAWE in the libs.toml 2022-09-11 00:50:36 +08:00
Andrew Wong ca8c0487a8 Fix origin setting so that the blocks paste properly 2022-09-11 00:44:47 +08:00
Andrew Wong 24156a03c4 Rewrite region saving and restoring in the adapters 2022-09-10 23:14:28 +08:00
Andrew Wong ec677766d2 Attempt to prevent duplicate signs from loading 2022-09-10 19:27:03 +08:00
Andrew Wong ef6c8fbf9d Only remove leashes, paintings and item frames 2022-09-10 17:54:48 +08:00
Andrew Wong 4f52fe9e6e Forcefully remvoe Entities in the region before pasting 2022-09-10 17:43:07 +08:00
Andrew Wong 3ebe5a6fa9 Use the WG converter to convert WG regions to WE ones 2022-09-10 17:02:29 +08:00
Andrew Wong 3cebe5d2c7 Fix NPE with sign deletion after worlededit operations 2022-09-10 14:59:35 +08:00
Andrew Wong c76415c4f3 Fix NPE when tabbing region restore 2022-09-10 12:47:45 +08:00
Andrew Wong b7bc02aef3 Compile against 1.19.2 and update the gradle wrapper 2022-09-07 15:31:33 +08:00
Cleo d75094e191 Remove unrenting section in eventCommandProfile 2022-07-07 13:51:02 -04:00
Cleo 4045914b48 Fix placeholders in unrented command event [#11] 2022-07-07 13:50:04 -04:00
Andrew Wong 1fac002ee0 Remove the Bukkit113 module and update the versioning url 2022-06-20 19:57:22 +08:00
Andrew Wong 64301e74e0 Bump version 2022-06-20 19:27:28 +08:00
Andrew Wong 5a5a7fc5ef Bump version 2022-06-20 19:25:42 +08:00
Andrew Wong b928caf0c2 Bump worldedit 2022-06-20 19:19:49 +08:00
Andrew Wong 111f629787 Update dependencies and add adapter for 1.19 2022-06-11 00:59:19 +08:00
Andrew Wong 718474ca95 Update gradle wrapper 2022-06-10 23:37:12 +08:00
Andrew Wong 93b9df3e54 Update gradle wrapper to 7.4.1 2022-03-24 18:48:03 +08:00
Andrew Wong bad983a0b8 Update worldedit and fawe adapters 2022-03-24 18:47:02 +08:00
Andrew Wong e2c8b06b68 Bump dependency versions 2022-03-24 16:30:02 +08:00
Andrew Wong 7249e39c02 bump version 2022-03-24 16:27:49 +08:00
97 changed files with 1880 additions and 1680 deletions

No files matched your search

+26 -13
View File
@@ -1,5 +1,5 @@
plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.github.johnrengelman.shadow") version "8.1.1"
}
description = "AreaShop"
@@ -24,31 +24,41 @@ dependencies {
}
// 3rd party libraries
implementation(libs.findbugs)
implementation("io.papermc:paperlib:1.0.7")
implementation("io.papermc:paperlib:1.0.8")
implementation("com.github.NLthijs48:InteractiveMessenger:e7749258ca")
implementation("com.github.NLthijs48:BukkitDo:819d51ec2b")
implementation("io.github.baked-libs:dough-data:1.0.3")
implementation("com.google.inject:guice:5.1.0") {
implementation("io.github.baked-libs:dough-data:1.2.0")
implementation("com.google.inject:guice:7.0.0") {
exclude("com.google.guava", "guava")
}
implementation("com.google.inject.extensions:guice-assistedinject:5.1.0") {
implementation("com.google.inject.extensions:guice-assistedinject:7.0.0") {
exclude("com.google.guava", "guava")
}
// Project submodules
implementation(projects.areashopInterface)
implementation(projects.areashopBukkit113)
implementation(projects.areashopNms)
// Adapters
implementation(projects.adapters.platform.platformInterface)
implementation(projects.adapters.platform.paper)
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-18-1", "reobf"))
// Adapters
if (!providers.environmentVariable("JITPACK").isPresent) {
runtimeOnly(project(":adapters:platform:bukkit-1-17", "reobf"))
}
runtimeOnly(projects.adapters.platform.bukkit118)
runtimeOnly(projects.adapters.platform.bukkit119)
runtimeOnly(projects.adapters.platform.bukkit120)
testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.9.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
}
repositories {
mavenCentral()
}
@@ -61,7 +71,9 @@ tasks {
}
assemble {
dependsOn(shadowJar)
if (!providers.systemProperty("JITPACK").isPresent) {
dependsOn(shadowJar)
}
}
jar {
@@ -88,8 +100,9 @@ tasks {
relocate("io.papermc.lib", "${base}.paperlib")
relocate("io.github.bakedlibs.dough", "${base}.dough")
relocate("com.google.inject", "${base}.inject")
relocate("com.google.errorprone", "${base}.errorprone")
relocate("org.aopalliance", "${base}.aopalliance")
relocate("javax.annotation", "${base}.javax.annotation")
relocate("javax.inject", "${base}.javax.inject")
relocate("jakarta.inject", "${base}.jakarta.inject")
}
}
@@ -6,9 +6,11 @@ import com.google.inject.Stage;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager;
import io.papermc.lib.PaperLib;
import me.wiefferink.areashop.adapters.platform.MinecraftPlatform;
import me.wiefferink.areashop.adapters.platform.paper.PaperPlatform;
import me.wiefferink.areashop.features.signs.SignManager;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.BukkitInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import me.wiefferink.areashop.listeners.PlayerLoginLogoutListener;
@@ -22,9 +24,11 @@ import me.wiefferink.areashop.managers.SignLinkerManager;
import me.wiefferink.areashop.modules.AreaShopModule;
import me.wiefferink.areashop.modules.BukkitModule;
import me.wiefferink.areashop.modules.DependencyModule;
import me.wiefferink.areashop.modules.PlatformModule;
import me.wiefferink.areashop.nms.NMS;
import me.wiefferink.areashop.tools.GithubUpdateCheck;
import me.wiefferink.areashop.tools.SimpleMessageBridge;
import me.wiefferink.areashop.tools.SpigotPlatform;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.bukkitdo.Do;
import me.wiefferink.interactivemessenger.source.LanguageManager;
@@ -50,8 +54,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.function.Supplier;
/**
* Main class for the AreaShop plugin.
@@ -68,7 +71,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
private WorldEditPlugin worldEdit = null;
private WorldEditInterface worldEditInterface = null;
private NMS nms;
private BukkitInterface bukkitInterface = null;
private MessageBridge messageBridge;
private IFileManager fileManager = null;
private LanguageManager languageManager = null;
@@ -166,7 +168,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
AreaShop.instance = this;
Do.init(this);
managers = new HashSet<>();
boolean error = false;
messageBridge = new SimpleMessageBridge();
signErrorLogger = new SignErrorLogger(new File(getDataFolder(), signLogFile));
@@ -183,6 +184,15 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
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) {
@@ -244,30 +254,24 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
return;
}
try {
Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers.BukkitHandler1_13");
bukkitInterface = (BukkitInterface)clazz.getConstructor(AreaShopInterface.class).newInstance(this);
} catch (Exception e) {
error("Could not load the Bukkit handler (used for sign updates), report this problem to the author:", ExceptionUtils.getStackTrace(e));
shutdownOnError();
return;
}
AreaShopModule asModule = new AreaShopModule(this, messageBridge, nms, bukkitInterface, worldEditInterface, worldGuardInterface, signErrorLogger, dependencyModule);
AreaShopModule asModule = new AreaShopModule(this, messageBridge, nms, worldEditInterface, worldGuardInterface, signErrorLogger, platformModule, dependencyModule);
injector = Guice.createInjector(Stage.PRODUCTION, new BukkitModule(getServer()), asModule);
// Load all data from files and check versions
fileManager = injector.getInstance(IFileManager.class);
managers.add((FileManager) fileManager);
boolean loadFilesResult = fileManager.loadFiles(false);
error = error || !loadFilesResult;
if (!loadFilesResult) {
shutdownOnError();
return;
}
setupLanguageManager();
featureManager = injector.getInstance(FeatureManager.class);
featureManager.initializeFeatures(injector);
managers.add(featureManager);
signManager = new SignManager();
signManager = injector.getInstance(SignManager.class);
managers.add(signManager);
// Register the event listeners
@@ -300,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/AreaShop/releases");
for(Player player : Utils.getOnlinePlayers()) {
notifyUpdate(player);
}
@@ -454,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
@@ -470,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
@@ -704,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, " "));
}
/**
@@ -717,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, " "));
}
/**
@@ -725,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, " "));
}
/**
@@ -1,6 +1,8 @@
package me.wiefferink.areashop.commands;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
@@ -24,8 +26,6 @@ import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
@@ -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,148 +1,142 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@Singleton
public class AddfriendCommand extends CommandAreaShop {
@Inject
private MessageBridge messageBridge;
@Inject
private IFileManager fileManager;
@Inject
private Plugin plugin;
@Inject
private MessageBridge messageBridge;
@Inject
private IFileManager fileManager;
@Inject
private Plugin plugin;
@Override
public String getCommandStart() {
return "areashop addfriend";
}
@Inject
private OfflinePlayerHelper offlinePlayerHelper;
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.addfriendall") || target.hasPermission("areashop.addfriend")) {
return "help-addFriend";
}
return null;
}
@Inject
private BukkitSchedulerExecutor executor;
@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) {
messageBridge.message(sender, "addfriend-noPermission");
return;
}
@Override
public String getCommandStart() {
return "areashop addfriend";
}
if(args.length < 2) {
messageBridge.message(sender, "addfriend-help");
return;
}
@Override
public String getHelp(CommandSender target) {
if (target.hasPermission("areashop.addfriendall") || target.hasPermission("areashop.addfriend")) {
return "help-addFriend";
}
return null;
}
GeneralRegion region;
if(args.length <= 2) {
if(sender instanceof Player) {
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
if(regions.isEmpty()) {
messageBridge.message(sender, "cmd-noRegionsAtLocation");
return;
} else if(regions.size() > 1) {
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
return;
}
} else {
region = fileManager.getRegion(args[2]);
if(region == null) {
messageBridge.message(sender, "cmd-notRegistered", args[2]);
return;
}
}
if(sender.hasPermission("areashop.addfriendall")) {
if((region instanceof RentRegion && !((RentRegion)region).isRented())
|| (region instanceof BuyRegion && !((BuyRegion)region).isSold())) {
messageBridge.message(sender, "addfriend-noOwner", region);
return;
}
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
if(friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
return;
}
if(region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
return;
}
if(region.isOwner(friend.getUniqueId())) {
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
return;
}
if(region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
region.update();
messageBridge.message(sender, "addfriend-successOther", friend.getName(), region);
}
} else {
if(sender.hasPermission("areashop.addfriend") && sender instanceof Player) {
if(region.isOwner((Player)sender)) {
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
if(friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
return;
}
if(region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
return;
}
if(region.isOwner(friend.getUniqueId())) {
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
return;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) {
messageBridge.message(sender, "addfriend-noPermission");
return;
}
if(region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
region.update();
messageBridge.message(sender, "addfriend-success", friend.getName(), region);
}
} else {
messageBridge.message(sender, "addfriend-noPermissionOther", region);
}
} else {
messageBridge.message(sender, "addfriend-noPermission", region);
}
}
}
if (args.length < 2) {
messageBridge.message(sender, "addfriend-help");
return;
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(Player player : Utils.getOnlinePlayers()) {
result.add(player.getName());
}
} else if(toComplete == 3) {
result.addAll(fileManager.getRegionNames());
}
return result;
}
GeneralRegion region;
if (args.length == 2) {
if (sender instanceof Player player) {
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(player.getLocation());
if (regions.isEmpty()) {
messageBridge.message(sender, "cmd-noRegionsAtLocation");
return;
} else if (regions.size() > 1) {
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
return;
}
} else {
region = fileManager.getRegion(args[2]);
if (region == null) {
messageBridge.message(sender, "cmd-notRegistered", args[2]);
return;
}
}
if (sender.hasPermission("areashop.addfriendall")) {
if ((region instanceof RentRegion rentRegion && !rentRegion.isRented())
|| (region instanceof BuyRegion buyRegion && !buyRegion.isSold())) {
messageBridge.message(sender, "addfriend-noOwner", region);
return;
}
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(friend -> {
if (friend.hasPlayedBefore() && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
} else if (region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
} else if (region.isOwner(friend.getUniqueId())) {
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
} else if (region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
region.update();
messageBridge.message(sender, "addfriend-successOther", friend.getName(), region);
}
}, this.executor);
return;
}
if (!sender.hasPermission("areashop.addfriend") || !(sender instanceof Player player)) {
messageBridge.message(sender, "addfriend-noPermission", region);
return;
}
if (!region.isOwner(player)) {
messageBridge.message(sender, "addfriend-noPermissionOther", region);
return;
}
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(friend -> {
if (friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
} else if (region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
} else if (region.isOwner(friend.getUniqueId())) {
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
} else if (region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
region.update();
messageBridge.message(sender, "addfriend-success", friend.getName(), region);
}
}, this.executor);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<>();
if (toComplete == 2) {
for (Player player : Utils.getOnlinePlayers()) {
result.add(player.getName());
}
} else if (toComplete == 3) {
result.addAll(fileManager.getRegionNames());
}
return result;
}
}
@@ -1,12 +1,14 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.features.signs.SignManager;
import me.wiefferink.areashop.interfaces.BukkitInterface;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.Materials;
import me.wiefferink.areashop.tools.SignUtils;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -15,8 +17,6 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.BlockIterator;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -33,8 +33,6 @@ public class AddsignCommand extends CommandAreaShop {
private SignManager signManager;
@Inject
private Plugin plugin;
@Inject
private BukkitInterface bukkitInterface;
@Override
public String getCommandStart() {
@@ -55,11 +53,10 @@ public class AddsignCommand extends CommandAreaShop {
messageBridge.message(sender, "addsign-noPermission");
return;
}
if(!(sender instanceof Player)) {
if(!(sender instanceof Player player)) {
messageBridge.message(sender, "cmd-onlyByPlayer");
return;
}
Player player = (Player)sender;
// Get the sign
Block block = null;
@@ -111,7 +108,7 @@ public class AddsignCommand extends CommandAreaShop {
return;
}
region.getSignsFeature().addSign(block.getLocation(), block.getType(), bukkitInterface.getSignFacing(block), profile);
region.getSignsFeature().addSign(block.getLocation(), block.getType(), SignUtils.getSignFacing(block), profile);
if(profile == null) {
messageBridge.message(sender, "addsign-success", region);
} else {
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -8,8 +10,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -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) {
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
@@ -12,8 +14,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;
@@ -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,130 +1,134 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@Singleton
public class DelfriendCommand extends CommandAreaShop {
@Inject
private MessageBridge messageBridge;
@Inject
private IFileManager fileManager;
@Override
public String getCommandStart() {
return "areashop delfriend";
}
@Inject
private MessageBridge messageBridge;
@Inject
private IFileManager fileManager;
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.delfriendall") || target.hasPermission("areashop.delfriend")) {
return "help-delFriend";
}
return null;
}
@Inject
private OfflinePlayerHelper offlinePlayerHelper;
/**
* Check if a person can remove friends.
* @param person The person to check
* @param region The region to check for
* @return true if the person can remove friends, otherwise false
*/
public static boolean canUse(CommandSender person, GeneralRegion region) {
if(person.hasPermission("areashop.delfriendall")) {
return true;
}
if(person instanceof Player) {
Player player = (Player)person;
return region.isOwner(player) && player.hasPermission("areashop.delfriend");
}
return false;
}
@Inject
private BukkitSchedulerExecutor executor;
@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) {
messageBridge.message(sender, "delfriend-noPermission");
return;
}
if(args.length < 2) {
messageBridge.message(sender, "delfriend-help");
return;
}
GeneralRegion region;
if(args.length <= 2) {
if(sender instanceof Player) {
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
if(regions.isEmpty()) {
messageBridge.message(sender, "cmd-noRegionsAtLocation");
return;
} else if(regions.size() > 1) {
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
return;
}
} else {
region = fileManager.getRegion(args[2]);
if(region == null) {
messageBridge.message(sender, "cmd-notRegistered", args[2]);
return;
}
}
if(sender.hasPermission("areashop.delfriendall")) {
if((region instanceof RentRegion && !((RentRegion)region).isRented())
|| (region instanceof BuyRegion && !((BuyRegion)region).isSold())) {
messageBridge.message(sender, "delfriend-noOwner", region);
return;
}
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
if(!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
return;
}
if(region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
region.update();
messageBridge.message(sender, "delfriend-successOther", friend.getName(), region);
}
} else {
if(sender.hasPermission("areashop.delfriend") && sender instanceof Player) {
if(region.isOwner((Player)sender)) {
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
if(!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
return;
}
if(region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
region.update();
messageBridge.message(sender, "delfriend-success", friend.getName(), region);
}
} else {
messageBridge.message(sender, "delfriend-noPermissionOther", region);
}
} else {
messageBridge.message(sender, "delfriend-noPermission", region);
}
}
}
@Override
public String getCommandStart() {
return "areashop delfriend";
}
@Override
public String getHelp(CommandSender target) {
if (target.hasPermission("areashop.delfriendall") || target.hasPermission("areashop.delfriend")) {
return "help-delFriend";
}
return null;
}
/**
* Check if a person can remove friends.
*
* @param person The person to check
* @param region The region to check for
* @return true if the person can remove friends, otherwise false
*/
public static boolean canUse(CommandSender person, GeneralRegion region) {
if (person.hasPermission("areashop.delfriendall")) {
return true;
}
if (person instanceof Player player) {
return region.isOwner(player) && player.hasPermission("areashop.delfriend");
}
return false;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) {
messageBridge.message(sender, "delfriend-noPermission");
return;
}
if (args.length < 2) {
messageBridge.message(sender, "delfriend-help");
return;
}
GeneralRegion region;
if (args.length == 2) {
if (!(sender instanceof Player player)) {
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
return;
}
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(player.getLocation());
if (regions.isEmpty()) {
messageBridge.message(sender, "cmd-noRegionsAtLocation");
return;
} else if (regions.size() > 1) {
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
region = fileManager.getRegion(args[2]);
if (region == null) {
messageBridge.message(sender, "cmd-notRegistered", args[2]);
return;
}
}
if (sender.hasPermission("areashop.delfriendall")) {
if ((region instanceof RentRegion rentRegion && !rentRegion.isRented())
|| (region instanceof BuyRegion buyRegion && !buyRegion.isSold())) {
messageBridge.message(sender, "delfriend-noOwner", region);
return;
}
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(friend -> {
if (!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
return;
}
if (region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
region.update();
messageBridge.message(sender, "delfriend-successOther", friend.getName(), region);
}
}, this.executor);
return;
}
if (!sender.hasPermission("areashop.delfriend") || !(sender instanceof Player player)) {
messageBridge.message(sender, "delfriend-noPermission", region);
return;
}
if (!region.isOwner(player)) {
messageBridge.message(sender, "delfriend-noPermissionOther", region);
return;
}
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(friend -> {
if (!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
} else if (region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
region.update();
messageBridge.message(sender, "delfriend-success", friend.getName(), region);
}
}, this.executor);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
@@ -1,9 +1,10 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.features.signs.SignManager;
import me.wiefferink.areashop.features.signs.SignsFeature;
import me.wiefferink.areashop.tools.Materials;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -11,8 +12,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -44,18 +43,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 +68,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,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -11,8 +13,6 @@ import net.milkbowl.vault.economy.Economy;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
@@ -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);
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
@@ -11,8 +13,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;
@@ -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");
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
@@ -11,8 +13,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;
@@ -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,13 +1,13 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.RegionGroup;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -1,12 +1,12 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -1,13 +1,12 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.regions.ImportJob;
import me.wiefferink.areashop.regions.ImportJobFactory;
import me.wiefferink.interactivemessenger.processing.Message;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -1,6 +1,8 @@
package me.wiefferink.areashop.commands;
import io.github.bakedlibs.dough.blocks.BlockPosition;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -12,8 +14,6 @@ import me.wiefferink.interactivemessenger.processing.Message;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -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,18 +1,19 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -26,6 +27,12 @@ public class MeCommand extends CommandAreaShop {
@Inject
private IFileManager fileManager;
@Inject
private OfflinePlayerHelper offlinePlayerHelper;
@Inject
private BukkitSchedulerExecutor executor;
@Override
public String getCommandStart() {
return "areashop me";
@@ -55,42 +62,48 @@ public class MeCommand extends CommandAreaShop {
player = (OfflinePlayer)sender;
}
if(args.length > 1) {
player = Bukkit.getOfflinePlayer(args[1]);
if(!player.hasPlayedBefore()) {
messageBridge.message(sender, "me-noPlayer", args[1]);
return;
}
}
if(!player.hasPlayedBefore()) {
// Lookup offline players async
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(offlinePlayer -> {
if (!offlinePlayer.hasPlayedBefore()) {
messageBridge.message(sender, "me-noPlayer", args[1]);
} else {
sendMessageAboutRegions(sender, offlinePlayer);
}
}, this.executor);
return;
}
sendMessageAboutRegions(sender, player);
}
private void sendMessageAboutRegions(CommandSender sender, OfflinePlayer target) {
// Get the regions owned by the player
Set<RentRegion> rentRegions = new HashSet<>();
for(RentRegion region : fileManager.getRentsRef()) {
if(region.isOwner(player)) {
if(region.isOwner(target)) {
rentRegions.add(region);
}
}
Set<BuyRegion> buyRegions = new HashSet<>();
for(BuyRegion region : fileManager.getBuysRef()) {
if(region.isOwner(player)) {
if(region.isOwner(target)) {
buyRegions.add(region);
}
}
// Get the regions the player is added as friend
Set<GeneralRegion> friendRegions = new HashSet<>();
for(GeneralRegion region : fileManager.getRegionsRef()) {
if(region.getFriendsFeature().getFriends().contains(player.getUniqueId())) {
if(region.getFriendsFeature().getFriends().contains(target.getUniqueId())) {
friendRegions.add(region);
}
}
// Send messages
boolean foundSome = !rentRegions.isEmpty() || !buyRegions.isEmpty() || !friendRegions.isEmpty();
if(foundSome) {
messageBridge.message(sender, "me-header", player.getName());
if(!foundSome) {
messageBridge.message(sender, "me-nothing", target.getName());
return;
}
messageBridge.message(sender, "me-header", target.getName());
if(!rentRegions.isEmpty()) {
for(RentRegion region : rentRegions) {
messageBridge.messageNoPrefix(sender, "me-rentLine", region);
@@ -106,12 +119,7 @@ public class MeCommand extends CommandAreaShop {
messageBridge.messageNoPrefix(sender, "me-friendLine", region);
}
}
if(!foundSome) {
messageBridge.message(sender, "me-nothing", player.getName());
} else {
messageBridge.messageNoPrefix(sender, "me-clickHint");
}
messageBridge.messageNoPrefix(sender, "me-clickHint");
}
@Override
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.interactivemessenger.processing.Message;
@@ -8,8 +10,6 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -1,12 +1,11 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.MessageBridge;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class ReloadCommand extends CommandAreaShop {
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.RentRegion;
@@ -7,8 +9,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -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,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -7,8 +9,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -8,8 +10,6 @@ import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -8,8 +10,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -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,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.RentRegion;
@@ -8,8 +10,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -1,97 +1,100 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@Singleton
public class SetlandlordCommand extends CommandAreaShop {
@Inject
private MessageBridge messageBridge;
@Inject
private IFileManager fileManager;
@Override
public String getCommandStart() {
return "areashop setlandlord";
}
@Inject
private MessageBridge messageBridge;
@Inject
private IFileManager fileManager;
@Inject
private OfflinePlayerHelper offlinePlayerHelper;
@Inject
private BukkitSchedulerExecutor executor;
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.setlandlord")) {
return "help-setlandlord";
}
return null;
}
@Override
public String getCommandStart() {
return "areashop setlandlord";
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.setlandlord")) {
messageBridge.message(sender, "setlandlord-noPermission");
return;
}
if(args.length < 2) {
messageBridge.message(sender, "setlandlord-help");
return;
}
@SuppressWarnings("deprecation")
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
GeneralRegion region;
if(args.length < 3) {
if(sender instanceof Player) {
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
if(regions.isEmpty()) {
messageBridge.message(sender, "cmd-noRegionsAtLocation");
return;
} else if(regions.size() > 1) {
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
return;
}
} else {
region = fileManager.getRegion(args[2]);
}
if(region == null) {
messageBridge.message(sender, "cmd-notRegistered", args[2]);
return;
}
String playerName = player.getName();
if(playerName == null || playerName.isEmpty()) {
playerName = args[1];
}
region.setLandlord(player.getUniqueId(), playerName);
region.update();
messageBridge.message(sender, "setlandlord-success", playerName, region);
}
@Override
public String getHelp(CommandSender target) {
if (target.hasPermission("areashop.setlandlord")) {
return "help-setlandlord";
}
return null;
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(Player player : Utils.getOnlinePlayers()) {
result.add(player.getName());
}
} else if(toComplete == 3) {
result.addAll(fileManager.getRegionNames());
}
return result;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.setlandlord")) {
messageBridge.message(sender, "setlandlord-noPermission");
return;
}
if (args.length < 2) {
messageBridge.message(sender, "setlandlord-help");
return;
}
GeneralRegion region;
if (args.length < 3) {
if (!(sender instanceof Player player)) {
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
return;
}
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(player.getLocation());
if (regions.isEmpty()) {
messageBridge.message(sender, "cmd-noRegionsAtLocation");
return;
} else if (regions.size() > 1) {
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
region = fileManager.getRegion(args[2]);
}
if (region == null) {
messageBridge.message(sender, "cmd-notRegistered", args[2]);
return;
}
this.offlinePlayerHelper.lookupOfflinePlayerAsync(args[1]).thenAcceptAsync(offlinePlayer -> {
String playerName = offlinePlayer.getName();
if (playerName == null || playerName.isEmpty()) {
playerName = args[1];
}
region.setLandlord(offlinePlayer.getUniqueId(), playerName);
region.update();
messageBridge.message(sender, "setlandlord-success", playerName, region);
}, this.executor);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<>();
if (toComplete == 2) {
for (Player player : Utils.getOnlinePlayers()) {
result.add(player.getName());
}
} else if (toComplete == 3) {
result.addAll(fileManager.getRegionNames());
}
return result;
}
}
@@ -1,18 +1,18 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
@@ -21,118 +21,116 @@ import java.util.UUID;
@Singleton
public class SetownerCommand extends CommandAreaShop {
@Inject
private MessageBridge messageBridge;
@Inject
private IFileManager fileManager;
@Override
public String getCommandStart() {
return "areashop setowner";
}
@Inject
private MessageBridge messageBridge;
@Inject
private IFileManager fileManager;
@Inject
private OfflinePlayerHelper offlinePlayerHelper;
@Inject
private BukkitSchedulerExecutor executor;
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.setownerrent") || target.hasPermission("areashop.setownerbuy")) {
return "help-setowner";
}
return null;
}
@Override
public String getCommandStart() {
return "areashop setowner";
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.setownerrent") && !sender.hasPermission("areashop.setownerbuy")) {
messageBridge.message(sender, "setowner-noPermission");
return;
}
GeneralRegion region;
if(args.length < 2) {
messageBridge.message(sender, "setowner-help");
return;
}
if(args.length == 2) {
if(sender instanceof Player) {
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
if(regions.isEmpty()) {
messageBridge.message(sender, "cmd-noRegionsAtLocation");
return;
} else if(regions.size() > 1) {
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
return;
}
} else {
region = fileManager.getRegion(args[2]);
}
if(region == null) {
messageBridge.message(sender, "setowner-notRegistered");
return;
}
@Override
public String getHelp(CommandSender target) {
if (target.hasPermission("areashop.setownerrent") || target.hasPermission("areashop.setownerbuy")) {
return "help-setowner";
}
return null;
}
if(region instanceof RentRegion && !sender.hasPermission("areashop.setownerrent")) {
messageBridge.message(sender, "setowner-noPermissionRent", region);
return;
}
if(region instanceof BuyRegion && !sender.hasPermission("areashop.setownerbuy")) {
messageBridge.message(sender, "setowner-noPermissionBuy", region);
return;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.setownerrent") && !sender.hasPermission("areashop.setownerbuy")) {
messageBridge.message(sender, "setowner-noPermission");
return;
}
GeneralRegion region;
if (args.length < 2) {
messageBridge.message(sender, "setowner-help");
return;
}
if (args.length == 2) {
if (!(sender instanceof Player player)) {
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
return;
}
// get the region by location
List<GeneralRegion> regions = Utils.getImportantRegions(player.getLocation());
if (regions.isEmpty()) {
messageBridge.message(sender, "cmd-noRegionsAtLocation");
return;
} else if (regions.size() > 1) {
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
UUID uuid = null;
@SuppressWarnings("deprecation")
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
if(player != null) {
uuid = player.getUniqueId();
}
if(uuid == null) {
messageBridge.message(sender, "setowner-noPlayer", args[1], region);
return;
}
} else {
region = fileManager.getRegion(args[2]);
}
if (region == null) {
messageBridge.message(sender, "setowner-notRegistered");
return;
}
if(region instanceof RentRegion) {
RentRegion rent = (RentRegion)region;
if(rent.isRenter(uuid)) {
// extend
rent.setRentedUntil(rent.getRentedUntil() + rent.getDuration());
rent.setRenter(uuid);
messageBridge.message(sender, "setowner-succesRentExtend", region);
} else {
// change
if(!rent.isRented()) {
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
}
rent.setRenter(uuid);
messageBridge.message(sender, "setowner-succesRent", region);
}
}
if(region instanceof BuyRegion) {
BuyRegion buy = (BuyRegion)region;
buy.setBuyer(uuid);
messageBridge.message(sender, "setowner-succesBuy", region);
}
region.getFriendsFeature().deleteFriend(region.getOwner(), null);
region.update();
region.saveRequired();
}
if (region instanceof RentRegion && !sender.hasPermission("areashop.setownerrent")) {
messageBridge.message(sender, "setowner-noPermissionRent", region);
return;
}
if (region instanceof BuyRegion && !sender.hasPermission("areashop.setownerbuy")) {
messageBridge.message(sender, "setowner-noPermissionBuy", region);
return;
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(Player player : Utils.getOnlinePlayers()) {
result.add(player.getName());
}
} else if(toComplete == 3) {
result.addAll(fileManager.getRegionNames());
}
return result;
}
this.offlinePlayerHelper.lookupUuidAsync(args[1]).thenAcceptAsync(optionalUuid -> {
if (optionalUuid.isEmpty()) {
messageBridge.message(sender, "setowner-noPlayer", args[1], region);
return;
}
final UUID uuid = optionalUuid.get();
if (region instanceof RentRegion rent) {
if (rent.isRenter(uuid)) {
// extend
rent.setRentedUntil(rent.getRentedUntil() + rent.getDuration());
rent.setRenter(uuid);
messageBridge.message(sender, "setowner-succesRentExtend", region);
} else {
// change
if (!rent.isRented()) {
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
}
rent.setRenter(uuid);
messageBridge.message(sender, "setowner-succesRent", region);
}
}
if (region instanceof BuyRegion buy) {
buy.setBuyer(uuid);
messageBridge.message(sender, "setowner-succesBuy", region);
}
region.getFriendsFeature().deleteFriend(region.getOwner(), null);
region.update();
region.saveRequired();
}, this.executor);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<>();
if (toComplete == 2) {
for (Player player : Utils.getOnlinePlayers()) {
result.add(player.getName());
}
} else if (toComplete == 3) {
result.addAll(fileManager.getRegionNames());
}
return result;
}
}
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -9,8 +11,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -1,13 +1,14 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.Plugin;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -79,7 +80,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;
}
@@ -1,6 +1,8 @@
package me.wiefferink.areashop.commands;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -10,8 +12,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -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
@@ -2,6 +2,8 @@ package me.wiefferink.areashop.commands;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
@@ -22,8 +24,6 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -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,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -7,8 +9,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -1,13 +1,13 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -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,5 +1,7 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -8,8 +10,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@@ -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;
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.features;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
import me.wiefferink.areashop.events.ask.BuyingRegionEvent;
@@ -21,8 +23,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
@Singleton
@@ -1,5 +1,7 @@
package me.wiefferink.areashop.features;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.events.ask.BuyingRegionEvent;
import me.wiefferink.areashop.events.ask.RentingRegionEvent;
@@ -20,8 +22,6 @@ import me.wiefferink.areashop.tools.Utils;
import org.bukkit.event.EventHandler;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class DebugFeature extends RegionFeature {
@@ -3,6 +3,7 @@ package me.wiefferink.areashop.features;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import jakarta.inject.Inject;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.features.signs.SignManager;
@@ -19,7 +20,6 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Iterator;
@@ -5,6 +5,8 @@ import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
import me.wiefferink.areashop.interfaces.RegionAccessSet;
@@ -15,8 +17,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.EventHandler;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@@ -6,11 +6,11 @@ import com.google.inject.assistedinject.AssistedInject;
import io.github.bakedlibs.dough.blocks.BlockPosition;
import io.papermc.lib.PaperLib;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.interfaces.BukkitInterface;
import me.wiefferink.areashop.managers.SignErrorLogger;
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.Materials;
import me.wiefferink.areashop.tools.SignUtils;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.interactivemessenger.processing.Message;
import org.bukkit.Bukkit;
@@ -37,7 +37,6 @@ public class RegionSign {
private final BlockBehaviourHelper blockHelper;
private final SignErrorLogger errorLogger;
private final BukkitInterface bukkitInterface;
private final SignsFeature signsFeature;
private final String key;
@@ -47,13 +46,11 @@ public class RegionSign {
RegionSign(
@Nonnull BlockBehaviourHelper blockBehaviourHelper,
@Nonnull SignErrorLogger signErrorLogger,
@Nonnull BukkitInterface bukkitInterface,
@Assisted @Nonnull SignsFeature signsFeature,
@Assisted @Nonnull String key
) {
this.blockHelper = blockBehaviourHelper;
this.errorLogger = signErrorLogger;
this.bukkitInterface = bukkitInterface;
this.signsFeature = signsFeature;
this.key = key;
}
@@ -98,8 +95,11 @@ public class RegionSign {
* Remove this sign from the region.
*/
public void remove() {
getLocation().getBlock().setType(Material.AIR);
this.signsFeature.signManager().removeSign(this);
Location location = getLocation();
if (location != null && location.getWorld() != null) {
location.getBlock().setType(Material.AIR);
this.signsFeature.signManager().removeSign(this);
}
getRegion().setSetting("general.signs." + key, null);
// Remove the sign from the region's sign manager
}
@@ -208,7 +208,7 @@ public class RegionSign {
getRegion().setSetting("general.signs." + key + ".signType", block.getType().name());
}
if(!regionConfig.isString("general.signs." + key + ".facing")) {
BlockFace signFacing = bukkitInterface.getSignFacing(block);
BlockFace signFacing = SignUtils.getSignFacing(block);
getRegion().setSetting("general.signs." + key + ".facing", signFacing == null ? null : signFacing.toString());
}
@@ -3,11 +3,13 @@ package me.wiefferink.areashop.features.signs;
import io.github.bakedlibs.dough.blocks.BlockPosition;
import io.github.bakedlibs.dough.blocks.ChunkPosition;
import org.bukkit.Location;
import org.bukkit.World;
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 +42,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);
}
@@ -51,8 +53,9 @@ public class SignCache {
public Optional<RegionSign> removeSign(BlockPosition position) {
RegionSign removed = this.allSigns.remove(position.getPosition());
if (removed != null) {
Location location = position.toLocation();
this.signsByChunk.remove(new ChunkPosition(location).getPosition());
World world = position.getWorld();
ChunkPosition chunkPosition = new ChunkPosition(world, position.getChunkX(), position.getChunkZ());
this.signsByChunk.remove(chunkPosition.getPosition());
// Remove the sign from the region
}
return Optional.ofNullable(removed);
@@ -7,7 +7,6 @@ import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
import me.wiefferink.areashop.interfaces.BukkitInterface;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.managers.SignLinkerManager;
@@ -17,6 +16,7 @@ import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RegionFactory;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.Materials;
import me.wiefferink.areashop.tools.SignUtils;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.bukkitdo.Do;
import org.bukkit.Chunk;
@@ -36,6 +36,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@@ -47,7 +48,6 @@ public class SignListener implements Listener {
private final MessageBridge messageBridge;
private final SignManager signManager;
private final SignLinkerManager signLinkerManager;
private final BukkitInterface bukkitInterface;
private final WorldGuardInterface worldGuardInterface;
private final RegionFactory regionFactory;
private final IFileManager fileManager;
@@ -58,7 +58,6 @@ public class SignListener implements Listener {
@Nonnull RegionFactory regionFactory,
@Nonnull MessageBridge messageBridge,
@Nonnull SignLinkerManager signLinkerManager,
@Nonnull BukkitInterface bukkitInterface,
@Nonnull WorldGuardInterface worldGuardInterface,
@Nonnull SignManager signManager,
@Nonnull IFileManager fileManager) {
@@ -68,15 +67,14 @@ public class SignListener implements Listener {
this.regionFactory = regionFactory;
this.behaviourHelper = behaviourHelper;
this.plugin = plugin;
this.bukkitInterface = bukkitInterface;
this.worldGuardInterface = worldGuardInterface;
this.messageBridge = messageBridge;
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void regionUpdate(UpdateRegionEvent event) {
Optional<SignsFeature> signsFeature = event.getRegion().getFeature(SignsFeature.class);
signsFeature.map(SignsFeature::signManager).ifPresent(SignManager::update);
SignsFeature signsFeature = event.getRegion().getSignsFeature();
signsFeature.signManager().update();
}
@@ -92,7 +90,6 @@ public class SignListener implements Listener {
if(chunkSigns.isEmpty()) {
return;
}
chunkSigns.remove(null);
Do.forAll(chunkSigns, RegionSign::update);
}
@@ -292,7 +289,7 @@ public class SignListener implements Listener {
if(durationSet) {
rent.setDuration(thirdLine);
}
rent.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), bukkitInterface.getSignFacing(event.getBlock()), null);
rent.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), SignUtils.getSignFacing(event.getBlock()), null);
AddingRegionEvent addingRegionEvent = plugin.getFileManager().addRegion(rent);
if (addingRegionEvent.isCancelled()) {
@@ -392,7 +389,7 @@ public class SignListener implements Listener {
if(priceSet) {
buy.setPrice(price);
}
buy.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), bukkitInterface.getSignFacing(event.getBlock()), null);
buy.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), SignUtils.getSignFacing(event.getBlock()), null);
AddingRegionEvent addingRegionEvent = plugin.getFileManager().addRegion(buy);
if (addingRegionEvent.isCancelled()) {
@@ -438,10 +435,10 @@ public class SignListener implements Listener {
}
if(thirdLine == null || thirdLine.isEmpty()) {
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), bukkitInterface.getSignFacing(event.getBlock()), null);
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), SignUtils.getSignFacing(event.getBlock()), null);
messageBridge.message(player, "addsign-success", region);
} else {
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), bukkitInterface.getSignFacing(event.getBlock()), thirdLine);
region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), SignUtils.getSignFacing(event.getBlock()), thirdLine);
messageBridge.message(player, "addsign-successProfile", thirdLine, region);
}
@@ -1,6 +1,7 @@
package me.wiefferink.areashop.features.signs;
import io.github.bakedlibs.dough.blocks.BlockPosition;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.managers.Manager;
import org.bukkit.Location;
import org.bukkit.World;
@@ -52,11 +53,22 @@ 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) {
return getCacheForWorld(location.getWorld()).flatMap(cache -> cache.removeSign(location));
if (location == null || location.getWorld() == null) {
return Optional.empty();
}
return removeSign(new BlockPosition(location));
}
public Optional<RegionSign> removeSign(BlockPosition blockPosition) {
return getCacheForWorld(blockPosition.getWorld()).flatMap(cache -> cache.removeSign(blockPosition));
}
/**
@@ -65,9 +77,10 @@ public class SignManager extends Manager {
*/
public boolean update() {
boolean result = true;
for (SignCache signCache : this.signCacheMap.values())
for(RegionSign sign : signCache.allSigns()) {
result &= sign.update();
for (SignCache signCache : this.signCacheMap.values()) {
for (RegionSign sign : signCache.allSigns()) {
result &= sign.update();
}
}
return result;
}
@@ -94,6 +107,7 @@ public class SignManager extends Manager {
public void shutdown() {
update();
this.signCacheMap.values().forEach(SignCache::clear);
this.signCacheMap.clear();
}
@@ -2,6 +2,8 @@ package me.wiefferink.areashop.features.signs;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import io.github.bakedlibs.dough.blocks.BlockPosition;
import io.github.bakedlibs.dough.blocks.ChunkPosition;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.features.RegionFeature;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -12,6 +14,8 @@ import org.bukkit.block.BlockFace;
import org.bukkit.configuration.ConfigurationSection;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
public class SignsFeature extends RegionFeature {
@@ -34,17 +38,18 @@ public class SignsFeature extends RegionFeature {
setRegion(region);
// Setup current signs
ConfigurationSection signSection = region.getConfig().getConfigurationSection("general.signs");
if(signSection != null) {
for(String signKey : signSection.getKeys(false)) {
RegionSign sign = signFactory.createRegionSign(this, signKey);
Location location = sign.getLocation();
if(location == null) {
AreaShop.warn("Sign with key " + signKey + " of region " + region.getName() + " does not have a proper location");
continue;
}
this.globalSignManager.cacheForWorld(location.getWorld()).addSign(sign);
this.internalSignManager.addSign(sign);
if (signSection == null) {
return;
}
for(String signKey : signSection.getKeys(false)) {
RegionSign sign = signFactory.createRegionSign(this, signKey);
Location location = sign.getLocation();
if(location == null) {
AreaShop.warn("Sign with key " + signKey + " of region " + region.getName() + " does not have a proper location");
continue;
}
this.globalSignManager.cacheForWorld(location.getWorld()).addSign(sign);
this.internalSignManager.addSign(sign);
}
}
@@ -6,7 +6,6 @@ import com.google.inject.Singleton;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.interfaces.BukkitInterface;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.managers.SignLinkerManager;
@@ -30,7 +29,6 @@ public class SignsModule extends AbstractModule {
@Nonnull RegionFactory regionFactory,
@Nonnull MessageBridge messageBridge,
@Nonnull SignLinkerManager signLinkerManager,
@Nonnull BukkitInterface bukkitInterface,
@Nonnull WorldGuardInterface worldGuardInterface,
@Nonnull SignManager signManager,
@Nonnull IFileManager fileManager
@@ -41,7 +39,6 @@ public class SignsModule extends AbstractModule {
regionFactory,
messageBridge,
signLinkerManager,
bukkitInterface,
worldGuardInterface,
signManager,
fileManager
@@ -1,6 +1,8 @@
package me.wiefferink.areashop.managers;
import com.google.inject.Injector;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.AddCommand;
@@ -43,8 +45,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
@@ -2,6 +2,8 @@ package me.wiefferink.areashop.managers;
import com.google.inject.Injector;
import com.google.inject.ProvisionException;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.features.CommandsFeature;
import me.wiefferink.areashop.features.DebugFeature;
@@ -14,8 +16,6 @@ import me.wiefferink.areashop.features.signs.SignsFeature;
import me.wiefferink.areashop.regions.GeneralRegion;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@@ -1,16 +1,19 @@
package me.wiefferink.areashop.managers;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import io.github.bakedlibs.dough.blocks.BlockPosition;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
import me.wiefferink.areashop.events.notify.AddedRegionEvent;
import me.wiefferink.areashop.events.notify.DeletedRegionEvent;
import me.wiefferink.areashop.features.signs.SignManager;
import me.wiefferink.areashop.features.signs.SignsFeature;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -32,8 +35,6 @@ import org.bukkit.entity.Player;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -43,6 +44,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;
@@ -77,6 +79,8 @@ public class FileManager extends Manager implements IFileManager {
private HashMap<String, Integer> versions = null;
private final String versionPath;
private final String schemFolder;
private final SignManager signManager;
private final WorldGuardInterface worldGuardInterface;
private final MessageBridge messageBridge;
private final RegionFactory regionFactory;
@@ -89,12 +93,14 @@ public class FileManager extends Manager implements IFileManager {
@Nonnull AreaShop plugin,
@Nonnull WorldGuardInterface worldGuardInterface,
@Nonnull MessageBridge messageBridge,
@Nonnull RegionFactory regionFactory
@Nonnull RegionFactory regionFactory,
@Nonnull SignManager signManager
) {
this.plugin = plugin;
this.worldGuardInterface = worldGuardInterface;
this.messageBridge = messageBridge;
this.regionFactory = regionFactory;
this.signManager = signManager;
regions = new HashMap<>();
buys = new HashMap<>();
rents = new HashMap<>();
@@ -117,6 +123,10 @@ public class FileManager extends Manager implements IFileManager {
public void shutdown() {
// Update lastactive time for players that are online now
for(GeneralRegion region : this.regions.values()) {
if (region.getOwner() == null) {
AreaShop.warn(String.format("%s has no owner", region.getName()));
continue;
}
Player player = Bukkit.getPlayer(region.getOwner());
if(player != null) {
region.updateLastActiveTime();
@@ -354,10 +364,10 @@ public class FileManager extends Manager implements IFileManager {
}
final String key = region.getName().toLowerCase(Locale.ENGLISH);
regions.put(key, region);
if (region instanceof BuyRegion) {
buys.put(key, (BuyRegion) region);
} else if (region instanceof RentRegion) {
rents.put(key, (RentRegion) region);
if (region instanceof BuyRegion buyRegion) {
buys.put(key, buyRegion);
} else if (region instanceof RentRegion rentRegion) {
rents.put(key, rentRegion);
}
Bukkit.getPluginManager().callEvent(new AddedRegionEvent(region));
return event;
@@ -465,8 +475,11 @@ public class FileManager extends Manager implements IFileManager {
// Delete the signs
if(region.getWorld() != null) {
for(BlockPosition sign : region.getSignsFeature().signManager().allSignLocations()) {
SignManager regionSignManager = region.getSignsFeature().signManager();
for(BlockPosition sign : regionSignManager.allSignLocations()) {
sign.getBlock().setType(Material.AIR);
regionSignManager.removeSign(sign);
this.signManager.removeSign(sign);
}
}
@@ -837,8 +850,8 @@ public class FileManager extends Manager implements IFileManager {
}
// Load default.yml from the plugin folder, and as backup the default one
try(
InputStreamReader custom = new InputStreamReader(new FileInputStream(defaultFile), Charsets.UTF_8);
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.defaultFile), Charsets.UTF_8)
InputStreamReader custom = new InputStreamReader(new FileInputStream(defaultFile), StandardCharsets.UTF_8);
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.defaultFile), StandardCharsets.UTF_8)
) {
defaultConfig = YamlConfiguration.loadConfiguration(custom);
if(defaultConfig.getKeys(false).isEmpty()) {
@@ -878,9 +891,9 @@ public class FileManager extends Manager implements IFileManager {
}
// Load config.yml from the plugin folder
try(
InputStreamReader custom = new InputStreamReader(new FileInputStream(configFile), Charsets.UTF_8);
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.configFile), Charsets.UTF_8);
InputStreamReader hidden = new InputStreamReader(plugin.getResource(AreaShop.configFileHidden), Charsets.UTF_8)
InputStreamReader custom = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8);
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.configFile), StandardCharsets.UTF_8);
InputStreamReader hidden = new InputStreamReader(plugin.getResource(AreaShop.configFileHidden), StandardCharsets.UTF_8)
) {
config = YamlConfiguration.loadConfiguration(custom);
if(config.getKeys(false).isEmpty()) {
@@ -917,7 +930,7 @@ public class FileManager extends Manager implements IFileManager {
File groupFile = new File(groupsPath);
if(groupFile.exists() && groupFile.isFile()) {
try(
InputStreamReader reader = new InputStreamReader(new FileInputStream(groupFile), Charsets.UTF_8)
InputStreamReader reader = new InputStreamReader(new FileInputStream(groupFile), StandardCharsets.UTF_8)
) {
groupsConfig = YamlConfiguration.loadConfiguration(reader);
} catch(IOException e) {
@@ -939,7 +952,9 @@ public class FileManager extends Manager implements IFileManager {
*/
@Override
public void loadRegionFiles() {
regions.clear();
this.regions.clear();
this.buys.clear();
this.rents.clear();
final File file = new File(regionsPath);
if(!file.exists()) {
if(!file.mkdirs()) {
@@ -971,7 +986,7 @@ public class FileManager extends Manager implements IFileManager {
// Load the region file from disk in UTF8 mode
YamlConfiguration regionConfig;
try(
InputStreamReader reader = new InputStreamReader(new FileInputStream(regionFile), Charsets.UTF_8)
InputStreamReader reader = new InputStreamReader(new FileInputStream(regionFile), StandardCharsets.UTF_8)
) {
regionConfig = YamlConfiguration.loadConfiguration(reader);
if(regionConfig.getKeys(false).isEmpty()) {
@@ -96,9 +96,9 @@ public interface IFileManager {
Collection<RentRegion> getRents();
/**
* Get all rental regions.
* Get all rental regions (readonly)
*
* @return List of all rental regions
* @return Unmodifiable collection of all rental regions
*/
Collection<RentRegion> getRentsRef();
@@ -109,6 +109,10 @@ public interface IFileManager {
*/
List<BuyRegion> getBuys();
/**
* Get all buy regions (readonly)
* @return Unmodifiable collection of all buy regions
*/
Collection<BuyRegion> getBuysRef();
/**
@@ -119,9 +123,9 @@ public interface IFileManager {
List<GeneralRegion> getRegions();
/**
* Get all regions.
* Get all regions (readonly)
*
* @return List of all regions (it is safe to modify the list)
* @return Unmodifiable collection of all regions
*/
Collection<GeneralRegion> getRegionsRef();
@@ -1,12 +1,14 @@
package me.wiefferink.areashop.managers;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
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;
@@ -23,8 +25,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.util.BlockIterator;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -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));
}
}
}
@@ -6,17 +6,16 @@ import com.google.inject.assistedinject.FactoryModuleBuilder;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.features.FeatureFactory;
import me.wiefferink.areashop.features.signs.SignManager;
import me.wiefferink.areashop.features.signs.SignsModule;
import me.wiefferink.areashop.interfaces.BukkitInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import me.wiefferink.areashop.managers.CommandManager;
import me.wiefferink.areashop.managers.FeatureManager;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.managers.FileManager;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.managers.SignErrorLogger;
import me.wiefferink.areashop.managers.SignLinkerManager;
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
import me.wiefferink.areashop.nms.NMS;
import me.wiefferink.areashop.regions.ImportJobFactory;
import me.wiefferink.areashop.regions.RegionModule;
@@ -24,47 +23,43 @@ 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(SignManager.class).asEagerSingleton();
bind(WorldEditInterface.class).toInstance(this.worldEditInterface);
bind(SignErrorLogger.class).toInstance(this.signErrorLogger);
// Setup managers
@@ -0,0 +1,29 @@
package me.wiefferink.areashop.modules;
import com.google.inject.AbstractModule;
import me.wiefferink.areashop.adapters.platform.MinecraftPlatform;
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
import me.wiefferink.areashop.nms.NMS;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import org.jetbrains.annotations.NotNull;
public class PlatformModule extends AbstractModule {
private final MinecraftPlatform minecraftPlatform;
private final NMS nms;
public PlatformModule(@NotNull MinecraftPlatform platform,
@NotNull NMS nms) {
this.minecraftPlatform = platform;
this.nms = nms;
}
@Override
protected void configure() {
bind(MinecraftPlatform.class).toInstance(this.minecraftPlatform);
bind(OfflinePlayerHelper.class).toInstance(this.minecraftPlatform.offlinePlayerHelper());
bind(NMS.class).toInstance(this.nms);
bind(BlockBehaviourHelper.class).toInstance(this.nms.blockBehaviourHelper());
bind(BukkitSchedulerExecutor.class).asEagerSingleton();
}
}
@@ -58,6 +58,21 @@ public class BuyRegion extends GeneralRegion {
this.economy = economy;
}
@Override
public boolean isOwner(UUID player) {
return isBuyer(player);
}
@Override
public UUID getOwner() {
return getBuyer();
}
@Override
public void setOwner(UUID player) {
setBuyer(player);
}
@Override
public RegionType getType() {
return RegionType.BUY;
@@ -237,31 +252,20 @@ public class BuyRegion extends GeneralRegion {
@Override
public Object provideReplacement(String variable) {
switch(variable) {
case AreaShop.tagPrice:
return getFormattedPrice();
case AreaShop.tagRawPrice:
return getPrice();
case AreaShop.tagPlayerName:
return getPlayerName();
case AreaShop.tagPlayerUUID:
return getBuyer();
case AreaShop.tagResellPrice:
return getFormattedResellPrice();
case AreaShop.tagRawResellPrice:
return getResellPrice();
case AreaShop.tagMoneyBackAmount:
return getFormattedMoneyBackAmount();
case AreaShop.tagRawMoneyBackAmount:
return getMoneyBackAmount();
case AreaShop.tagMoneyBackPercentage:
return getMoneyBackPercentage() % 1.0 == 0.0 ? (int)getMoneyBackPercentage() : getMoneyBackPercentage();
case AreaShop.tagMaxInactiveTime:
return this.getFormattedInactiveTimeUntilSell();
default:
return super.provideReplacement(variable);
}
return switch (variable) {
case AreaShop.tagPrice -> getFormattedPrice();
case AreaShop.tagRawPrice -> getPrice();
case AreaShop.tagPlayerName -> getPlayerName();
case AreaShop.tagPlayerUUID -> getBuyer();
case AreaShop.tagResellPrice -> getFormattedResellPrice();
case AreaShop.tagRawResellPrice -> getResellPrice();
case AreaShop.tagMoneyBackAmount -> getFormattedMoneyBackAmount();
case AreaShop.tagRawMoneyBackAmount -> getMoneyBackAmount();
case AreaShop.tagMoneyBackPercentage ->
getMoneyBackPercentage() % 1.0 == 0.0 ? (int) getMoneyBackPercentage() : getMoneyBackPercentage();
case AreaShop.tagMaxInactiveTime -> this.getFormattedInactiveTimeUntilSell();
default -> super.provideReplacement(variable);
};
}
/**
@@ -404,8 +408,6 @@ public class BuyRegion extends GeneralRegion {
if(r == null || !r.transactionSuccess()) {
AreaShop.warn("Something went wrong with paying '" + oldOwnerName + "' " + getFormattedPrice() + " for his resell of region " + getName() + " to " + offlinePlayer.getName());
}
// Resell is done, disable that now
disableReselling();
// Set the owner
setBuyer(offlinePlayer.getUniqueId());
@@ -417,6 +419,9 @@ public class BuyRegion extends GeneralRegion {
// Notify about updates
this.notifyAndUpdate(new ResoldRegionEvent(this, oldOwner));
// Resell is done, disable that now
disableReselling();
// Send message to the player
message(offlinePlayer, "buy-successResale", oldOwnerName);
Player seller = Bukkit.getPlayer(oldOwner);
@@ -479,7 +484,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 +539,7 @@ public class BuyRegion extends GeneralRegion {
// Give back the money
OfflinePlayer player = Bukkit.getOfflinePlayer(getBuyer());
if(player != null && !noPayBack) {
if(player.hasPlayedBefore() && !noPayBack) {
EconomyResponse response = null;
boolean error = false;
try {
@@ -31,6 +31,7 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import javax.annotation.Nonnull;
import java.awt.geom.Area;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
@@ -434,33 +435,18 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @param player Player to check ownership for
* @return true if the player currently rents or buys this region
*/
public boolean isOwner(UUID player) {
return (this instanceof RentRegion && ((RentRegion)this).isRenter(player)) || (this instanceof BuyRegion && ((BuyRegion)this).isBuyer(player));
}
public abstract boolean isOwner(UUID player);
/**
* Get the player that is currently the owner of this region (either bought or rented it).
* @return The UUID of the owner of this region
*/
public UUID getOwner() {
if(this instanceof RentRegion) {
return ((RentRegion)this).getRenter();
} else {
return ((BuyRegion)this).getBuyer();
}
}
public abstract UUID getOwner();
/**
* Change the owner of the region.
* @param player The player that should be the owner
*/
public void setOwner(UUID player) {
if(this instanceof RentRegion) {
((RentRegion)this).setRenter(player);
} else {
((BuyRegion)this).setBuyer(player);
}
}
public abstract void setOwner(UUID player);
/**
* Get the landlord of this region (the player that receives any revenue from this region).
@@ -479,7 +465,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
if(landlordName != null && !landlordName.isEmpty()) {
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(landlordName);
if(offlinePlayer != null) {
if(offlinePlayer.hasPlayedBefore()) {
return offlinePlayer.getUniqueId();
}
}
@@ -492,7 +478,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
*/
public String getLandlordName() {
String result = Utils.toName(getLandlord());
if(result == null || result.isEmpty()) {
if(result.isEmpty()) {
result = config.getString("general.landlordName");
if(result == null || result.isEmpty()) {
result = null;
@@ -511,7 +497,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
setSetting("general.landlord", landlord.toString());
}
String properName = Utils.toName(landlord);
if(properName == null) {
if(properName.isBlank()) {
properName = name;
}
setSetting("general.landlordName", properName);
@@ -629,86 +615,96 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
@Override
public Object provideReplacement(String variable) {
switch(variable) {
switch (variable) {
// Basics
case AreaShop.tagRegionName:
case AreaShop.tagRegionName -> {
return getName();
case AreaShop.tagRegionType:
}
case AreaShop.tagRegionType -> {
return getType().getValue().toLowerCase();
case AreaShop.tagWorldName:
}
case AreaShop.tagWorldName -> {
return getWorldName();
case AreaShop.tagWidth:
}
case AreaShop.tagWidth -> {
return getWidth();
case AreaShop.tagDepth:
}
case AreaShop.tagDepth -> {
return getDepth();
case AreaShop.tagHeight:
}
case AreaShop.tagHeight -> {
return getHeight();
case AreaShop.tagFriends:
}
case AreaShop.tagFriends -> {
return Utils.createCommaSeparatedList(getFriendsFeature().getFriendNames());
case AreaShop.tagFriendsUUID:
}
case AreaShop.tagFriendsUUID -> {
return Utils.createCommaSeparatedList(getFriendsFeature().getFriends());
case AreaShop.tagLandlord:
}
case AreaShop.tagLandlord -> {
return getLandlordName();
case AreaShop.tagLandlordUUID:
}
case AreaShop.tagLandlordUUID -> {
return getLandlord();
case AreaShop.tagVolume:
}
case AreaShop.tagVolume -> {
return getVolume();
}
// Date/time
case AreaShop.tagEpoch:
case AreaShop.tagEpoch -> {
return Calendar.getInstance().getTimeInMillis();
case AreaShop.tagMillisecond:
}
case AreaShop.tagMillisecond -> {
return Calendar.getInstance().get(Calendar.MILLISECOND);
case AreaShop.tagSecond:
}
case AreaShop.tagSecond -> {
return Calendar.getInstance().get(Calendar.SECOND);
case AreaShop.tagMinute:
}
case AreaShop.tagMinute -> {
return Calendar.getInstance().get(Calendar.MINUTE);
case AreaShop.tagHour:
}
case AreaShop.tagHour -> {
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
case AreaShop.tagDay:
}
case AreaShop.tagDay -> {
return Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
case AreaShop.tagMonth:
}
case AreaShop.tagMonth -> {
return Calendar.getInstance().get(Calendar.MONTH) + 1;
case AreaShop.tagYear:
}
case AreaShop.tagYear -> {
return Calendar.getInstance().get(Calendar.YEAR);
case AreaShop.tagDateTime:
}
case AreaShop.tagDateTime -> {
return new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat")).format(Calendar.getInstance().getTime());
case AreaShop.tagDateTimeShort:
}
case AreaShop.tagDateTimeShort -> {
return new SimpleDateFormat(plugin.getConfig().getString("timeFormatSign")).format(Calendar.getInstance().getTime());
}
// Teleport locations
default:
default -> {
Location tp = getTeleportFeature().getTeleportLocation();
if(tp == null) {
if (tp == null) {
return null;
}
switch(variable) {
case AreaShop.tagTeleportBlockX:
return tp.getBlockX();
case AreaShop.tagTeleportBlockY:
return tp.getBlockY();
case AreaShop.tagTeleportBlockZ:
return tp.getBlockZ();
case AreaShop.tagTeleportX:
return tp.getX();
case AreaShop.tagTeleportY:
return tp.getY();
case AreaShop.tagTeleportZ:
return tp.getZ();
case AreaShop.tagTeleportPitch:
return tp.getPitch();
case AreaShop.tagTeleportYaw:
return tp.getYaw();
case AreaShop.tagTeleportPitchRound:
return Math.round(tp.getPitch());
case AreaShop.tagTeleportYawRound:
return Math.round(tp.getYaw());
case AreaShop.tagTeleportWorld:
return tp.getWorld().getName();
default:
return null;
}
return switch (variable) {
case AreaShop.tagTeleportBlockX -> tp.getBlockX();
case AreaShop.tagTeleportBlockY -> tp.getBlockY();
case AreaShop.tagTeleportBlockZ -> tp.getBlockZ();
case AreaShop.tagTeleportX -> tp.getX();
case AreaShop.tagTeleportY -> tp.getY();
case AreaShop.tagTeleportZ -> tp.getZ();
case AreaShop.tagTeleportPitch -> tp.getPitch();
case AreaShop.tagTeleportYaw -> tp.getYaw();
case AreaShop.tagTeleportPitchRound -> Math.round(tp.getPitch());
case AreaShop.tagTeleportYawRound -> Math.round(tp.getYaw());
case AreaShop.tagTeleportWorld -> tp.getWorld().getName();
default -> null;
};
}
}
}
@@ -797,11 +793,9 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
File saveFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName);
// Create parent directories
File parent = saveFile.getParentFile();
if(parent != null && !parent.exists()) {
if(!parent.mkdirs()) {
AreaShop.warn("Did not save region " + getName() + ", schematic directory could not be created: " + saveFile.getAbsolutePath());
return false;
}
if(parent != null && !parent.exists() && !parent.mkdirs()) {
AreaShop.warn("Did not save region " + getName() + ", schematic directory could not be created: " + saveFile.getAbsolutePath());
return false;
}
boolean result = worldEditInterface.saveRegionBlocks(saveFile, this);
if(result) {
@@ -829,15 +823,13 @@ 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 CompletableFuture.completedFuture(false);
}
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(result) {
if(Boolean.TRUE.equals(result)) {
AreaShop.debug("Saved schematic async for region " + getName());
}
return result;
@@ -883,7 +875,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
File restoreFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName);
return worldEditInterface.restoreRegionBlocksAsync(restoreFile, this)
.thenApply(result -> {
if(result) {
if(Boolean.TRUE.equals(result)) {
AreaShop.debug("Restored schematic async for region " + getName());
// Sync back to main
Do.syncLater(10, getSignsFeature().signManager()::update);
@@ -974,7 +966,6 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
if(found) {
return result;
}
if(this.getFileManager().getRegionSettings().isString(path)) {
return this.getFileManager().getRegionSettings().getString(path).equalsIgnoreCase("true");
}
@@ -1483,8 +1474,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
public boolean matchesLimitGroup(String group) {
List<String> worlds = plugin.getConfig().getStringList("limitGroups." + group + ".worlds");
List<String> groups = plugin.getConfig().getStringList("limitGroups." + group + ".groups");
if((worlds == null || worlds.isEmpty() || worlds.contains(getWorldName()))) {
if(groups == null || groups.isEmpty()) {
if(worlds.isEmpty() || worlds.contains(getWorldName())) {
if(groups.isEmpty()) {
return true;
} else {
boolean inGroups = false;
@@ -1517,7 +1508,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
String restore = profileSection.getString(type.getValue() + ".restore");
// Save the region if needed
boolean async = worldEditInterface.supportsAsyncOperations();
if(save != null && !save.isEmpty()) {
if(save != null && !save.isBlank()) {
save = Message.fromString(save).replacements(this).getSingle();
if (async) {
saveRegionBlocksAsync(save);
@@ -1526,7 +1517,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
}
// Restore the region if needed
if(restore != null && !restore.isEmpty()) {
if(restore != null && !restore.isBlank()) {
restore = Message.fromString(restore).replacements(this).getSingle();
if (async) {
restoreRegionBlocksAsync(restore);
@@ -393,8 +393,7 @@ public class ImportJob {
// Set rented until
if(from.isLong("info.last-withdrawal")
&& region instanceof RentRegion) {
RentRegion rentRegion = (RentRegion)region;
&& region instanceof RentRegion rentRegion) {
long lastWithdrawal = from.getLong("info.last-withdrawal");
// Because the rental duration is already imported into the region and its parents this should be correct
rentRegion.setRentedUntil(lastWithdrawal + rentRegion.getDuration());
@@ -445,7 +444,7 @@ public class ImportJob {
}
}
private static final List<TimeUnit> timeUnitLookup = new ArrayList<TimeUnit>() {
private static final List<TimeUnit> timeUnitLookup = new ArrayList<>() {
{
add(new TimeUnit(60 * 24 * 30 * 12, "year"));
add(new TimeUnit(60 * 24 * 30, "month"));
@@ -72,6 +72,22 @@ public class RentRegion extends GeneralRegion {
this.economy = economy;
}
@Override
public boolean isOwner(UUID player) {
return isRenter(player);
}
@Override
public UUID getOwner() {
return getRenter();
}
@Override
public void setOwner(UUID player) {
setRenter(player);
}
@Override
public RegionType getType() {
return RegionType.RENT;
@@ -165,43 +181,28 @@ public class RentRegion extends GeneralRegion {
@Override
public Object provideReplacement(String variable) {
switch(variable) {
case AreaShop.tagPrice:
return getFormattedPrice();
case AreaShop.tagRawPrice:
return getPrice();
case AreaShop.tagDuration:
return getDurationString();
case AreaShop.tagPlayerName:
return getPlayerName();
case AreaShop.tagPlayerUUID:
return getRenter();
case AreaShop.tagRentedUntil:
return new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat")).format(new Date(getRentedUntil()));
case AreaShop.tagRentedUntilShort:
return new SimpleDateFormat(plugin.getConfig().getString("timeFormatSign")).format(new Date(getRentedUntil()));
case AreaShop.tagTimeLeft:
return getTimeLeftString();
case AreaShop.tagMoneyBackAmount:
return getFormattedMoneyBackAmount();
case AreaShop.tagRawMoneyBackAmount:
return getMoneyBackAmount();
case AreaShop.tagMoneyBackPercentage:
return (getMoneyBackPercentage() % 1.0) == 0.0 ? (int)getMoneyBackPercentage() : getMoneyBackPercentage();
case AreaShop.tagTimesExtended:
return this.getTimesExtended();
case AreaShop.tagMaxExtends:
return this.getMaxExtends();
case AreaShop.tagExtendsLeft:
return getMaxExtends() - getTimesExtended();
case AreaShop.tagMaxRentTime:
return millisToHumanFormat(getMaxRentTime());
case AreaShop.tagMaxInactiveTime:
return this.getFormattedInactiveTimeUntilUnrent();
default:
return super.provideReplacement(variable);
}
return switch (variable) {
case AreaShop.tagPrice -> getFormattedPrice();
case AreaShop.tagRawPrice -> getPrice();
case AreaShop.tagDuration -> getDurationString();
case AreaShop.tagPlayerName -> getPlayerName();
case AreaShop.tagPlayerUUID -> getRenter();
case AreaShop.tagRentedUntil ->
new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat")).format(new Date(getRentedUntil()));
case AreaShop.tagRentedUntilShort ->
new SimpleDateFormat(plugin.getConfig().getString("timeFormatSign")).format(new Date(getRentedUntil()));
case AreaShop.tagTimeLeft -> getTimeLeftString();
case AreaShop.tagMoneyBackAmount -> getFormattedMoneyBackAmount();
case AreaShop.tagRawMoneyBackAmount -> getMoneyBackAmount();
case AreaShop.tagMoneyBackPercentage ->
(getMoneyBackPercentage() % 1.0) == 0.0 ? (int) getMoneyBackPercentage() : getMoneyBackPercentage();
case AreaShop.tagTimesExtended -> this.getTimesExtended();
case AreaShop.tagMaxExtends -> this.getMaxExtends();
case AreaShop.tagExtendsLeft -> getMaxExtends() - getTimesExtended();
case AreaShop.tagMaxRentTime -> millisToHumanFormat(getMaxRentTime());
case AreaShop.tagMaxInactiveTime -> this.getFormattedInactiveTimeUntilUnrent();
default -> super.provideReplacement(variable);
};
}
/**
@@ -672,10 +673,10 @@ public class RentRegion extends GeneralRegion {
}
// Broadcast and check event
UnrentingRegionEvent event = new UnrentingRegionEvent(this);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) {
message(executor, "general-cancelled", event.getReason());
UnrentingRegionEvent unrentingRegionEvent = new UnrentingRegionEvent(this);
Bukkit.getPluginManager().callEvent(unrentingRegionEvent);
if(unrentingRegionEvent.isCancelled()) {
message(executor, "general-cancelled", unrentingRegionEvent.getReason());
return false;
}
@@ -729,13 +730,17 @@ public class RentRegion extends GeneralRegion {
// Remove friends, the owner and renteduntil values
getFriendsFeature().clearFriends();
UUID oldRenter = getRenter();
setRenter(null);
setRentedUntil(null);
setTimesExtended(-1);
removeLastActiveTime();
// Notify about updates
this.notifyAndUpdate(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack)));
Bukkit.getPluginManager().callEvent(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack)));
// Placed here so when event is passed, the player renting can still be accessed
setRenter(null);
// Update world (has to be after setting renter to null)
this.update();
return true;
}
@@ -0,0 +1,26 @@
package me.wiefferink.areashop.tools;
import jakarta.inject.Inject;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.jetbrains.annotations.NotNull;
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;
}
}
@@ -2,6 +2,7 @@ package me.wiefferink.areashop.tools;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import jakarta.inject.Inject;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
@@ -23,7 +24,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import javax.inject.Inject;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.RoundingMode;
+4 -2
View File
@@ -121,8 +121,10 @@ debug: false
version: ${project.version}
# Maximum number of blocks to save to or restore from a .schemetic file.
maximumBlocks: 1000000
# Maximum number of entities to save to or restore from a .schematic file (FAWE only)
maximumEntities: 1000
# 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
+3 -3
View File
@@ -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)."
+21 -32
View File
@@ -1,6 +1,8 @@
![AreaShop logo](https://cloud.githubusercontent.com/assets/6951068/9471294/f016d8ee-4b4f-11e5-9bda-d61b1c423ebb.png)<br/>
[![](https://jitpack.io/v/md5sha256/AreaShop.svg)](https://jitpack.io/#md5sha256/AreaShop)
<br>
**Usage and configuration:**
[►Download (releases)](https://github.com/NLthijs48/AreaShop/releases)&nbsp;&nbsp;
[►Download (releases)](https://github.com/md5sha256/AreasShop/releases)&nbsp;&nbsp;
[►Commands and Permissions](https://github.com/NLthijs48/AreaShop/wiki/Commands-and-Permissions)
<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
[►Basic regions setup](https://github.com/NLthijs48/AreaShop/wiki/Basic-regions-setup)&nbsp;&nbsp;
@@ -14,11 +16,10 @@
[►Frequently Asked Questions](https://github.com/NLthijs48/AreaShop/wiki/Frequently-Asked-Questions)&nbsp;&nbsp;
[►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)&nbsp;&nbsp;
[►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)&nbsp;&nbsp;
[►Open issues](https://github.com/md5sha256/AreasShop/issues)<br/>
**Development:**
[►Changelog](https://github.com/NLthijs48/AreaShop/blob/master/changelog.md)&nbsp;&nbsp;
[►Compiling](https://github.com/NLthijs48/AreaShop/wiki/Compiling-AreaShop)&nbsp;&nbsp;
[►Compiling](https://github.com/md5sha256/AreaShop/tree/dev/bleeding/documentation/compiling.md)&nbsp;&nbsp;
[►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 +27,19 @@
[►AreaShop in Spigot Resources](http://www.spigotmc.org/resources/areashop.2991/)&nbsp;&nbsp;
[►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 +49,7 @@ AreaShop allows you selling and renting regions to players. It could be used to
* ![rented-sign](https://cloud.githubusercontent.com/assets/6951068/21939029/3844896a-d9be-11e6-8492-7a23ec71fce2.png)
* 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).
* ![region-information-message](https://cloud.githubusercontent.com/assets/6951068/21939161/bff2fe3c-d9be-11e6-802f-4a0bce073c64.png)
* 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 +74,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/>
[![Tutorial Video](https://cloud.githubusercontent.com/assets/6951068/9532788/147526cc-4d0e-11e5-9672-1274faae280a.png)](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).
![Transifex-translation-progress](https://transifex.com/projects/p/areashop/resource/enyml/chart/image_png)
[![Discord-support-chat](https://discordapp.com/api/v6/guilds/342592311122853893/widget.png?style=banner3)](https://discord.gg/84kGMCQ)
[![Donate through PayPal to support development](https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif)](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)
@@ -1,21 +0,0 @@
plugins.apply("io.papermc.paperweight.userdev")
dependencies {
paperDevBundle("1.18.1-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"))
}
}
@@ -1,46 +0,0 @@
package me.wiefferink.areashop.adapters.platform.v1_18_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_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData;
import 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());
}
}
+1 -11
View File
@@ -1,7 +1,5 @@
plugins.apply("io.papermc.paperweight.userdev")
dependencies {
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
compileOnly(projects.areashopInterface)
compileOnly(projects.areashopNms)
}
@@ -10,12 +8,4 @@ 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"))
}
}
@@ -1,16 +1,10 @@
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.BlockState;
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;
@@ -19,28 +13,16 @@ 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);
return location.getBlock().canPlace(blockData);
}
@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());
return block.canPlace(block.getBlockData());
}
@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());
public boolean isBlockStateValid(BlockState blockState) {
return blockState.getBlock().canPlace(blockState.getBlockData());
}
}
@@ -0,0 +1,11 @@
dependencies {
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
compileOnly(projects.areashopInterface)
compileOnly(projects.areashopNms)
}
description = "AreaShop NMS Helper 1-19"
tasks {
}
@@ -0,0 +1,28 @@
package me.wiefferink.areashop.adapters.platform.v1_19_R3;
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import java.util.Objects;
public class BlockBehaviourImpl implements BlockBehaviourHelper {
@Override
public boolean canPlace(Location location, BlockData blockData) {
Objects.requireNonNull(location.getWorld(), "Null World!");
return location.getBlock().canPlace(blockData);
}
@Override
public boolean isBlockValid(Block block) {
return block.canPlace(block.getBlockData());
}
@Override
public boolean isBlockStateValid(BlockState blockState) {
return blockState.getBlock().canPlace(blockState.getBlockData());
}
}
@@ -1,4 +1,4 @@
package me.wiefferink.areashop.adapters.platform.v1_18_R1;
package me.wiefferink.areashop.adapters.platform.v1_19_R3;
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
import me.wiefferink.areashop.nms.NMS;
@@ -0,0 +1,11 @@
dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT")
compileOnly(projects.areashopInterface)
compileOnly(projects.areashopNms)
}
description = "AreaShop NMS Helper 1-20"
tasks {
}
@@ -0,0 +1,28 @@
package me.wiefferink.areashop.adapters.platform.v1_20_R2;
import me.wiefferink.areashop.nms.BlockBehaviourHelper;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import java.util.Objects;
public class BlockBehaviourImpl implements BlockBehaviourHelper {
@Override
public boolean canPlace(Location location, BlockData blockData) {
Objects.requireNonNull(location.getWorld(), "Null World!");
return location.getBlock().canPlace(blockData);
}
@Override
public boolean isBlockValid(Block block) {
return block.canPlace(block.getBlockData());
}
@Override
public boolean isBlockStateValid(BlockState blockState) {
return blockState.getBlock().canPlace(blockState.getBlockData());
}
}
@@ -0,0 +1,15 @@
package me.wiefferink.areashop.adapters.platform.v1_20_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;
}
}
+6
View File
@@ -0,0 +1,6 @@
description = "AreaShop Paper Helper"
dependencies {
compileOnlyApi(libs.paper)
compileOnlyApi(projects.adapters.platform.platformInterface)
}
@@ -0,0 +1,44 @@
package me.wiefferink.areashop.adapters.platform.paper;
import com.destroystokyo.paper.profile.PlayerProfile;
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class PaperOfflinePlayerHelper implements OfflinePlayerHelper {
private final Plugin plugin;
private final Server server;
public PaperOfflinePlayerHelper(Plugin plugin) {
this.plugin = plugin;
this.server = plugin.getServer();
}
@Override
public CompletableFuture<Optional<UUID>> lookupUuidAsync(String username) {
final PlayerProfile profile = this.server.createProfile(username);
final CompletableFuture<Optional<UUID>> future = new CompletableFuture<>();
this.server.getScheduler().runTaskAsynchronously(this.plugin, () -> {
profile.complete(false);
future.complete(Optional.ofNullable(profile.getId()));
});
return future;
}
@Override
public CompletableFuture<OfflinePlayer> lookupOfflinePlayerAsync(String username) {
final CompletableFuture<OfflinePlayer> future = new CompletableFuture<>();
this.server.getScheduler().runTaskAsynchronously(this.plugin, () -> {
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(username);
future.complete(offlinePlayer);
});
return future;
}
}
@@ -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)
}
@@ -0,0 +1,7 @@
package me.wiefferink.areashop.adapters.platform;
public interface MinecraftPlatform {
OfflinePlayerHelper offlinePlayerHelper();
}
@@ -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);
}
@@ -1,9 +1,14 @@
dependencies {
compileOnly(libs.spigot)
compileOnly(projects.areashopInterface)
compileOnly(libs.fastasyncworldeditCore)
compileOnly(libs.fastasyncworldeditBukkit)
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"
@@ -1,15 +1,8 @@
package me.wiefferink.areashop.adapters.plugins;
import com.fastasyncworldedit.core.FaweAPI;
import com.fastasyncworldedit.core.extent.clipboard.MemoryOptimizedClipboard;
import com.fastasyncworldedit.core.extent.processor.lighting.RelightMode;
import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.fastasyncworldedit.core.limit.FaweLimit;
import com.google.common.annotations.Beta;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
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;
@@ -18,465 +11,326 @@ 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.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Mask2D;
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.util.io.Closer;
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 com.sk89q.worldguard.protection.regions.RegionType;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Player;
import org.bukkit.util.BoundingBox;
import java.io.BufferedOutputStream;
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;
// Future: this class could use the schematic save/paste api of FAWE: https://github.com/boy0001/FastAsyncWorldedit/wiki/Pasting-a-schematic
// This would not allow for shaping the schematic to a polygon region though
public class FastAsyncWorldEditHandler extends WorldEditInterface {
public FastAsyncWorldEditHandler(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
public FastAsyncWorldEditHandler(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
private static class RegionBoundMask implements Mask {
@Override
public boolean supportsAsyncOperations() {
return true;
}
private final BoundingBox boundingBox;
@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);
public RegionBoundMask(final ProtectedRegion region) {
final BlockVector3 min = region.getMinimumPoint();
final BlockVector3 max = region.getMaximumPoint();
this.boundingBox = new BoundingBox(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ());
}
}
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;
public RegionBoundMask(final BoundingBox boundingBox) {
this.boundingBox = boundingBox.clone();
}
}
@Override
public boolean test(BlockVector3 vector) {
return boundingBox.contains(vector.getX(), vector.getY(), vector.getZ());
}
@Override
public 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 Mask2D toMask2D() {
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;
@Override
public Mask copy() {
return new RegionBoundMask(boundingBox);
}
}
}
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 supportsAsyncOperations() {
return true;
}
@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;
}
@Beta
public CompletableFuture<Boolean> restoreRegionBlocksAsync(File rawFile, GeneralRegionInterface regionInterface) {
File file = null;
for (ClipboardFormat formatOption : BuiltInClipboardFormat.values()) {
if (new File(rawFile.getAbsolutePath() + "." + formatOption.getPrimaryFileExtension())
.exists()) {
file = new File(
rawFile.getAbsolutePath() + "." + formatOption.getPrimaryFileExtension());
break;
}
}
if (file == null) {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName()
+ ", schematic file does not exist: " + rawFile.getAbsolutePath());
return CompletableFuture.completedFuture(false);
}
ClipboardFormat format = ClipboardFormats.findByFile(file);
if (format == null) {
pluginInterface.debugI("Did not restore region " + regionInterface.getName() + ", could not find a valid clipboard format");
return CompletableFuture.completedFuture(false);
}
pluginInterface.debugI("Trying to restore region", regionInterface.getName(), " from file",
file.getAbsolutePath(), "with format", format.getName());
@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;
}
}
com.sk89q.worldedit.world.World world = null;
if (regionInterface.getName() != null) {
world = BukkitAdapter.adapt(regionInterface.getWorld());
}
if (world == null) {
pluginInterface.getLogger().info(
"Did not restore region " + regionInterface.getName() + ", world not found: "
+ regionInterface.getWorldName());
return CompletableFuture.completedFuture(false);
}
final FaweLimit limit = FaweLimit.MAX.copy();
limit.MAX_CHANGES = pluginInterface.getConfig().getInt("maximumBlocks");
limit.MAX_ENTITIES = pluginInterface.getConfig().getInt("maximumEntities", (int) (limit.MAX_CHANGES / 1000));
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit()
.newEditSessionBuilder()
.world(world)
.limit(limit)
.build();
editSession.setReorderMode(EditSession.ReorderMode.MULTI_STAGE);
ProtectedRegion region = regionInterface.getRegion();
// Get the origin and size of the region
BlockVector3 origin = BlockVector3
.at(region.getMinimumPoint().getBlockX(),
region.getMinimumPoint().getBlockY(),
region.getMinimumPoint().getBlockZ());
final File finalFile = file;
final String regionName = regionInterface.getName();
final double regionWidth = regionInterface.getWidth(), regionHeight = regionInterface.getHeight(), regionDepth = regionInterface.getDepth();
final LocalSession session =
new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
final CompletableFuture<Boolean> completableFuture = new CompletableFuture<>();
final RegionType regionType = region.getType();
final Mask mask = new RegionBoundMask(region);
FaweAPI.getTaskManager().async(() -> {
boolean result = true;
// Read the schematic and paste it into the world
try (Closer closer = Closer.create()) {
final FileInputStream fis = closer.register(new FileInputStream(finalFile));
final ClipboardReader reader = format.getReader(fis);
final Clipboard clipboard = reader.read();
if (clipboard.getDimensions().getY() != regionHeight
|| clipboard.getDimensions().getX() != regionWidth
|| clipboard.getDimensions().getZ() != regionDepth) {
pluginInterface.getLogger().warning(
"Size of the region " + regionName
+ " is not the same as the schematic to restore!");
pluginInterface.debugI(
"schematic|region, x:" + clipboard.getDimensions().getX() + "|"
+ regionWidth + ", y:" + clipboard.getDimensions().getY()
+ "|" + regionHeight + ", z:" + clipboard.getDimensions()
.getZ() + "|" + regionDepth);
}
clipboard.setOrigin(clipboard.getMinimumPoint());
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard);
session.setBlockChangeLimit((int) limit.MAX_CHANGES);
session.setClipboard(clipboardHolder);
// Build operation
BlockTransformExtent extent = new BlockTransformExtent(clipboard);
ForwardExtentCopy copy =
new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(),
editSession, origin);
copy.setTransform(clipboardHolder.getTransform());
// Mask to region (for polygon and other weird shaped regions)
// TODO make this more efficient (especially for polygon regions)
if (regionType != RegionType.CUBOID) {
copy.setSourceMask(mask);
}
Operations.completeLegacy(copy);
} catch (MaxChangedBlocksException e) {
pluginInterface.getLogger().warning(
"exceeded the block limit while restoring schematic of " + regionInterface.getName()
+ ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: "
+ pluginInterface.getConfig().getInt("maximumBlocks"));
result = false;
} catch (IOException e) {
pluginInterface.getLogger().warning(
"An error occurred while restoring schematic of " + regionInterface.getName()
+ ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
result = false;
} catch (Exception e) {
pluginInterface.getLogger()
.warning("crashed during restore of " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
result = false;
}
editSession.flushQueue();
completableFuture.complete(result);
});
return completableFuture;
}
@Beta
public CompletableFuture<Boolean> saveRegionBlocksAsync(File file, GeneralRegionInterface regionInterface) {
// TODO implement using the FastAsyncWorldEdit api to save async
ClipboardFormat format = BuiltInClipboardFormat.FAST;
// TODO allow selecting FAWE format in the config? (when enabled you cannot go back to vanilla WorldEdit easily)
file = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
pluginInterface.debugI("Trying to save region", regionInterface.getName(), " to file",
file.getAbsolutePath(), "with format", format.getName());
com.sk89q.worldedit.world.World world = null;
if (regionInterface.getWorld() != null) {
world = BukkitAdapter.adapt(regionInterface.getWorld());
}
if (world == null) {
pluginInterface.getLogger().warning(
"Did not save region " + regionInterface.getName() + ", world not found: "
+ regionInterface.getWorldName());
return CompletableFuture.completedFuture(false);
}
final FaweLimit limit = new FaweLimit();
limit.MAX_CHANGES = pluginInterface.getConfig().getInt("maximumBlocks");
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().newEditSessionBuilder()
.world(world)
.relightMode(RelightMode.OPTIMAL)
.limit(limit)
.build();
final ProtectedRegion region = regionInterface.getRegion();
final BlockVector3 min = region.getMinimumPoint(), max = region.getMaximumPoint();
final String regionName = regionInterface.getName();
final World finalWorld = world;
final CompletableFuture<Boolean> completableFuture = new CompletableFuture<>();
final File finalFile = file;
FaweAPI.getTaskManager().async(() -> {
// Create a clipboard
CuboidRegion selection =
new CuboidRegion(finalWorld, min, max);
Clipboard clipboard = new MemoryOptimizedClipboard(selection);
clipboard.setOrigin(min);
ForwardExtentCopy copy = new ForwardExtentCopy(editSession,
selection.clone(), clipboard,
min);
try {
Operations.completeLegacy(copy);
} catch (MaxChangedBlocksException e) {
pluginInterface.getLogger().warning(
"Exceeded the block limit while saving schematic of " + regionName
+ ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: "
+ pluginInterface.getConfig().getInt("maximumBlocks"));
completableFuture.complete(false);
return;
}
try (Closer closer = Closer.create()) {
FileOutputStream fos = closer.register(new FileOutputStream(finalFile));
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
ClipboardWriter writer = closer.register(format.getWriter(bos));
writer.write(clipboard);
} catch (IOException e) {
pluginInterface.getLogger().warning(
"An error occurred while saving schematic of " + regionName
+ ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
completableFuture.complete(false);
} catch (Exception e) {
pluginInterface.getLogger()
.warning("Crashed during save of " + regionName);
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
completableFuture.complete(false);
return;
}
completableFuture.complete(true);
});
return completableFuture;
}
@Override
public boolean restoreRegionBlocks(File rawFile, GeneralRegionInterface regionInterface) {
// TODO implement using the FastAsyncWorldEdit api to paste async
File file = null;
for (ClipboardFormat formatOption : BuiltInClipboardFormat.values()) {
if (new File(rawFile.getAbsolutePath() + "." + formatOption.getPrimaryFileExtension())
.exists()) {
file = new File(
rawFile.getAbsolutePath() + "." + formatOption.getPrimaryFileExtension());
break;
}
}
if (file == null) {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName()
+ ", schematic file does not exist: " + rawFile.getAbsolutePath());
return false;
}
ClipboardFormat format = ClipboardFormats.findByFile(file);
if (format == null) {
pluginInterface.debugI("Did not restore region " + regionInterface.getName() + ", could not find a valid clipboard format");
return false;
}
pluginInterface.debugI("Trying to restore region", regionInterface.getName(), " from file",
file.getAbsolutePath(), "with format", format.getName());
com.sk89q.worldedit.world.World world = null;
if (regionInterface.getName() != null) {
world = BukkitAdapter.adapt(regionInterface.getWorld());
}
if (world == null) {
pluginInterface.getLogger().info(
"Did not restore region " + regionInterface.getName() + ", world not found: "
+ regionInterface.getWorldName());
return false;
}
final FaweLimit limit = FaweLimit.MAX.copy();
limit.MAX_CHANGES = pluginInterface.getConfig().getInt("maximumBlocks");
limit.MAX_ENTITIES = pluginInterface.getConfig().getInt("maximumEntities", (int) (limit.MAX_CHANGES / 1000));
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit()
.newEditSessionBuilder()
.world(world)
.limit(limit)
.build();
editSession.setReorderMode(EditSession.ReorderMode.MULTI_STAGE);
ProtectedRegion region = regionInterface.getRegion();
// Get the origin and size of the region
BlockVector3 origin = BlockVector3
.at(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(),
region.getMinimumPoint().getBlockZ());
// Read the schematic and paste it into the world
try(Closer closer = Closer.create()) {
final FileInputStream fis = closer.register(new FileInputStream(file));
final ClipboardReader reader = format.getReader(fis);
final Clipboard clipboard = reader.read();
if (clipboard.getDimensions().getY() != regionInterface.getHeight()
|| clipboard.getDimensions().getX() != regionInterface.getWidth()
|| clipboard.getDimensions().getZ() != regionInterface.getDepth()) {
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());
}
clipboard.setOrigin(clipboard.getMinimumPoint());
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard);
LocalSession session =
new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
session.setBlockChangeLimit(pluginInterface.getConfig().getInt("maximumBlocks"));
session.setClipboard(clipboardHolder);
// Build operation
BlockTransformExtent extent = new BlockTransformExtent(clipboard);
ForwardExtentCopy copy =
new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(),
editSession, origin);
copy.setTransform(clipboardHolder.getTransform());
// Mask to region (for polygon and other weird shaped regions)
// TODO make this more efficient (especially for polygon regions)
if (region.getType() != RegionType.CUBOID) {
copy.setSourceMask(new RegionBoundMask(region));
}
Operations.completeLegacy(copy);
} catch (MaxChangedBlocksException e) {
pluginInterface.getLogger().warning(
"exceeded the block limit while restoring schematic of " + regionInterface.getName()
+ ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: "
+ pluginInterface.getConfig().getInt("maximumBlocks"));
return false;
} catch (FaweException ex) {
pluginInterface.getLogger().warning(
"exceeded the block entity limit while restoring schematic of " + regionInterface.getName()
+ ", limit passed by AreaShop: "
+ pluginInterface.getConfig().getInt("maximumEntities"));
return false;
}
catch (IOException e) {
pluginInterface.getLogger().warning(
"An error occurred while restoring schematic of " + regionInterface.getName()
+ ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
} catch (Exception e) {
pluginInterface.getLogger()
.warning("crashed during restore of " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
}
editSession.flushQueue();
return true;
}
@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
// TODO implement using the FastAsyncWorldEdit api to save async
ClipboardFormat format = BuiltInClipboardFormat.FAST;
// TODO allow selecting FAWE format in the config? (when enabled you cannot go back to vanilla WorldEdit easily)
file = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
pluginInterface.debugI("Trying to save region", regionInterface.getName(), " to file",
file.getAbsolutePath(), "with format", format.getName());
com.sk89q.worldedit.world.World world = null;
if (regionInterface.getWorld() != null) {
world = BukkitAdapter.adapt(regionInterface.getWorld());
}
if (world == null) {
pluginInterface.getLogger().warning(
"Did not save region " + regionInterface.getName() + ", world not found: "
+ regionInterface.getWorldName());
return false;
}
EditSession editSession =
pluginInterface.getWorldEdit().getWorldEdit()
.newEditSessionBuilder()
.world(world)
.maxBlocks(pluginInterface.getConfig().getInt("maximumBlocks"))
.build();
// Create a clipboard
CuboidRegion selection =
new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(),
regionInterface.getRegion().getMaximumPoint());
BlockArrayClipboard clipboard = new BlockArrayClipboard(selection);
clipboard.setOrigin(regionInterface.getRegion().getMinimumPoint());
ForwardExtentCopy copy = new ForwardExtentCopy(editSession,
new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(),
regionInterface.getRegion().getMaximumPoint()), clipboard,
regionInterface.getRegion().getMinimumPoint());
try {
Operations.completeLegacy(copy);
} catch (MaxChangedBlocksException e) {
pluginInterface.getLogger().warning(
"Exceeded the block limit while saving schematic of " + regionInterface.getName()
+ ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: "
+ pluginInterface.getConfig().getInt("maximumBlocks"));
return false;
}
try (Closer closer = Closer.create()) {
FileOutputStream fos = closer.register(new FileOutputStream(file));
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
ClipboardWriter writer = closer.register(format.getWriter(bos));
writer.write(clipboard);
} catch (IOException e) {
pluginInterface.getLogger().warning(
"An error occurred while saving schematic of " + regionInterface.getName()
+ ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
} catch (Exception e) {
pluginInterface.getLogger()
.warning("Crashed during save of " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
}
return true;
}
@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;
}
}
}
@@ -2,27 +2,29 @@ package me.wiefferink.areashop.adapters.plugins;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
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.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Mask2D;
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.util.io.Closer;
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 com.sk89q.worldguard.protection.regions.RegionType;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
@@ -30,12 +32,13 @@ import me.wiefferink.areashop.interfaces.WorldEditSelection;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.entity.Player;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Objects;
public class WorldEditHandler extends WorldEditInterface {
@@ -59,146 +62,139 @@ public class WorldEditHandler extends WorldEditInterface {
@Override
public boolean restoreRegionBlocks(File rawFile, GeneralRegionInterface regionInterface) {
File file = null;
ClipboardFormat format = null;
File targetFile = null;
for (ClipboardFormat formatOption : ClipboardFormats.getAll()) {
for (String extension : formatOption.getFileExtensions()) {
File fileOption = new File(rawFile.getAbsolutePath() + "." + extension);
if (fileOption.exists()) {
file = fileOption;
format = formatOption;
targetFile = fileOption;
break;
}
}
}
if(file == null) {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", schematic file does not exist: " + rawFile.getAbsolutePath());
if (targetFile == null || !targetFile.exists() || !targetFile.isFile()) {
pluginInterface.getLogger().info(() -> "Not restoring region. Schematic not found: " + rawFile);
return false;
}
pluginInterface.debugI("Trying to restore region", regionInterface.getName(), "from file", file.getAbsolutePath(), "with format", format.getName());
com.sk89q.worldedit.world.World world = null;
if(regionInterface.getName() != null) {
world = BukkitAdapter.adapt(regionInterface.getWorld());
}
if(world == null) {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
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;
}
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
ProtectedRegion region = regionInterface.getRegion();
// Get the origin and size of the region
BlockVector3 origin = BlockVector3.at(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
// Read the schematic and paste it into the world
try(Closer closer = Closer.create()) {
FileInputStream fis = closer.register(new FileInputStream(file));
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
ClipboardReader reader = format.getReader(bis);
//WorldData worldData = world.getWorldData();
LocalSession session = new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
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().getY() != regionInterface.getHeight()
|| clipboard.getDimensions().getX() != regionInterface.getWidth()
|| clipboard.getDimensions().getZ() != regionInterface.getDepth()) {
pluginInterface.getLogger().warning("Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
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;
}
clipboard.setOrigin(clipboard.getMinimumPoint());
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard);
session.setBlockChangeLimit(pluginInterface.getConfig().getInt("maximumBlocks"));
session.setClipboard(clipboardHolder);
// Build operation
BlockTransformExtent extent = new BlockTransformExtent(clipboardHolder.getClipboard(), clipboardHolder.getTransform());
ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), editSession, origin);
copy.setCopyingEntities(false);
copy.setTransform(clipboardHolder.getTransform());
// Mask to region (for polygon and other weird shaped regions)
// TODO make this more efficient (especially for polygon regions)
if(region.getType() != RegionType.CUBOID) {
copy.setSourceMask(new Mask() {
@Override
public boolean test(BlockVector3 vector) {
return region.contains(vector);
}
@Override
public Mask2D toMask2D() {
return null;
}
});
}
Operations.completeLegacy(copy);
} catch(MaxChangedBlocksException e) {
pluginInterface.getLogger().warning("exceeded the block limit while restoring schematic of " + regionInterface.getName() + ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: " + pluginInterface.getConfig().getInt("maximumBlocks"));
return false;
} catch(IOException e) {
pluginInterface.getLogger().warning("An error occured while restoring schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
} catch (Exception e) {
pluginInterface.getLogger().warning("crashed during restore of " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
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));
}
editSession.flushSession();
return true;
return false;
}
@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
ClipboardFormat format = ClipboardFormats.findByAlias("sponge");
if(format == null) {
// Sponge format does not exist, try to select another one
for(ClipboardFormat otherFormat : ClipboardFormats.getAll()) {
format = otherFormat;
}
if(format == null) {
pluginInterface.getLogger().warning("Cannot find a format to save a schematic in, no available formats!");
return false;
}
}
file = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
pluginInterface.debugI("Trying to save region", regionInterface.getName(), " to file", file.getAbsolutePath(), "with format", format.getName());
com.sk89q.worldedit.world.World world = null;
if(regionInterface.getWorld() != null) {
world = BukkitAdapter.adapt(regionInterface.getWorld());
}
if(world == null) {
pluginInterface.getLogger().warning("Did not save region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
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;
}
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
// Create a clipboard
CuboidRegion selection = new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint());
BlockArrayClipboard clipboard = new BlockArrayClipboard(selection);
clipboard.setOrigin(regionInterface.getRegion().getMinimumPoint());
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint()), clipboard, regionInterface.getRegion().getMinimumPoint());
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.completeLegacy(copy);
} catch(MaxChangedBlocksException e) {
pluginInterface.getLogger().warning("Exceeded the block limit while saving schematic of " + regionInterface.getName() + ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: " + pluginInterface.getConfig().getInt("maximumBlocks"));
return false;
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(Closer closer = Closer.create()) {
FileOutputStream fos = closer.register(new FileOutputStream(file));
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
ClipboardWriter writer = closer.register(format.getWriter(bos));
try (OutputStream os = new FileOutputStream(targetFile);
ClipboardWriter writer = format.getWriter(os)) {
writer.write(clipboard);
} catch(IOException e) {
pluginInterface.getLogger().warning("An error occured while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
} catch (Exception e) {
pluginInterface.getLogger().warning("crashed during save of " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
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;
}
return true;
}
}
-6
View File
@@ -1,6 +0,0 @@
dependencies {
compileOnly(libs.spigot)
compileOnly(projects.areashopInterface)
}
description = "AreaShop Bukkit 1.13 and higher"
@@ -1,82 +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;
/**
* Sign handler for 1.13+
* @deprecated Obsolete as we don't support pre-1.13 versions anyway
*/
@Deprecated(forRemoval = true)
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;
}
}
@@ -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();
}
@@ -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;
}
}
@@ -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());
}
}
@@ -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());
}
}
+13 -5
View File
@@ -1,14 +1,20 @@
import com.github.spotbugs.snom.Effort
import com.github.spotbugs.snom.SpotBugsPlugin
plugins {
java
`java-library`
`maven-publish`
id("io.papermc.paperweight.userdev") version "1.3.5" apply false
id("io.papermc.paperweight.userdev") version "1.5.5" apply false
id("com.github.spotbugs") version "5.1.3"
idea
eclipse
}
group = "me.wiefferink"
version = "2.7.6"
version = "2.7.14-SNAPSHOT"
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
subprojects {
@@ -23,12 +29,13 @@ subprojects {
}
plugin<IdeaPlugin>()
plugin<EclipsePlugin>()
// plugin<SpotBugsPlugin>()
}
repositories {
mavenCentral()
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven {
name = "jitpack"
@@ -41,9 +48,10 @@ subprojects {
maven("https://maven.enginehub.org/repo/")
}
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
tasks {
withType(JavaCompile::class) {
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
options.release.set(17)
options.encoding = Charsets.UTF_8.name()
options.isFork = true
+25
View File
@@ -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 |
+4 -12
View File
@@ -1,20 +1,16 @@
[versions]
# Platforms
minecraft = "1.17.1-R0.1-SNAPSHOT"
findbugs = "3.0.2"
# Minecraft Plugins
worldedit = "7.2.8"
worldguard = "7.0.6"
fawe = "2.0.1"
# Gradle plugins
paperweight = "1.3.5"
worldedit = "7.2.15"
worldguard = "7.0.9"
fawe = "2.7.1"
[libraries]
# Platform
spigot = { group = "org.spigotmc", name = "spigot-api", version.ref = "minecraft" }
findbugs = { group = "com.google.code.findbugs", name = "jsr305", version.ref = "findbugs" }
paper = { group = "io.papermc.paper", name = "paper-api", version.ref = "minecraft" }
# Minecraft Plugins
worldeditBukkit = { group = "com.sk89q.worldedit", name = "worldedit-bukkit", version.ref = "worldedit" }
@@ -23,7 +19,3 @@ worldguardBukkit = { group = "com.sk89q.worldguard", name = "worldguard-bukkit",
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" }
Binary file not shown.
+1 -1
View File
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+11 -5
View File
@@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
@@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Vendored
+8 -6
View File
@@ -14,7 +14,7 @@
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
+5
View File
@@ -0,0 +1,5 @@
before_install:
- sdk install java 17.0.8-amzn
- sdk use java 17.0.8-amzn
install:
- ./gradlew build publishToMavenLocal
+12 -8
View File
@@ -1,10 +1,6 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = "paper-repo"
url = uri("https://papermc.io/repo/repository/maven-public/")
}
}
}
@@ -18,18 +14,26 @@ buildCache {
rootProject.name = "areashop-parent"
// Interfaces
include(":areashop-bukkit-1_13")
include(":areashop-interface")
include(":areashop-nms")
// Adapters
include(":adapters:platform:bukkit-1-17")
include(":adapters:platform:bukkit-1-18")
include(":adapters:platform:bukkit-1-18-1")
include(":adapters:platform:paper")
include(":adapters:platform:platform-interface")
include(":adapters:plugins:worldedit")
include(":adapters:plugins:worldguard")
include(":adapters:plugins:fastasyncworldedit")
if (!providers.environmentVariable("JITPACK").isPresent) {
include(":adapters:platform:bukkit-1-17")
}
include(":adapters:platform:bukkit-1-18")
include(":adapters:platform:bukkit-1-19")
include(":adapters:platform:bukkit-1-20")
// Main project
include(":areashop")