Compare commits

...
22 Commits
Author SHA1 Message Date
Andrew Wong 628aa83089 Update cloud to beta.9 2024-07-24 14:45:59 +10:00
Andrew Wong 11da15454d Enforce min version to 1.21 2024-07-24 14:45:59 +10:00
Andrew Wong ff2e4e235d Compile against 1.21, bump version to 2.9.1-SNAPSHOT 2024-07-24 14:45:59 +10:00
Andrew Wong 88c7b7a4bd Release 2.9.0 2024-07-24 14:04:44 +10:00
Andrew Wong cd3a7e97a7 Remove extra listener for SignChangeEvent in SignListener 2024-07-24 14:04:13 +10:00
Andrew Wong d33739491a Revert "Release 2.9.0"
This reverts commit ff59fa7f70.
2024-07-24 13:35:27 +10:00
Andrew Wong 5488deb0d7 Fix message sending errors in the ArgumentParseHandler, fix issue with quickbuy and quickrent where newly joined playes are treated as invalid 2024-07-24 13:35:09 +10:00
Andrew Wong ff59fa7f70 Release 2.9.0 2024-07-24 13:21:03 +10:00
Andrew Wong 219ba0335e Remove paperweight userdev, update cloud to 2.0.0-beta.8 2024-07-24 13:15:08 +10:00
Andrew Wong 724439da7d Remove BukkitInterface 2024-06-30 17:43:23 +10:00
Andrew Wong 7bebca5dca Inline BlockBehaviourHelper, remove areashop-nms and areashop-platform-modern 2024-06-30 17:37:45 +10:00
Andrew Wong 5989ecbcbc Handle new SignChangeEvent in the sign listener 2024-06-28 21:39:15 +10:00
Andrew Wong a6a38be0a5 Set version to 2.9.0-SNAPSHOT 2024-06-22 01:26:21 +10:00
Andrew Wong 5034aa358a Fix version util parsing for versions without trailing zeros 2024-06-22 01:22:55 +10:00
Andrew Wong 4f7982f5b2 Update min required version to 1.20.6 2024-06-22 01:16:47 +10:00
Andrew Wong 92c8eea23a Code cleanup, migrate to java 21 2024-06-22 01:10:28 +10:00
Andrew Wong 4ff5852a9d Update the worldguard, worldedit and fastasyncworldedit dependency and adapters 2024-06-22 00:52:07 +10:00
Andrew Wong b30a292398 Bump version to 2.9.0 2024-06-22 00:39:28 +10:00
Andrew Wong 5640a55d73 Update cloud-paper to 2.0.0-SNAPSHOT. Refactor commands to accomodate the new CommandSourceStack 2024-06-22 00:39:05 +10:00
Andrew Wong cd79e071a4 Bump java version in workflows and jitpack 2024-06-22 00:39:03 +10:00
Andrew Wong 49a4b1420d Initial work on compiling against 1.20.6 2024-06-22 00:39:01 +10:00
Andrew Wong 7ef50fbcba Update gradle wrapper to 8.7 2024-06-22 00:38:59 +10:00
105 changed files with 706 additions and 706 deletions

No files matched your search

+5 -5
View File
@@ -11,12 +11,12 @@ jobs:
os: ["ubuntu-latest", "windows-latest"]
runs-on: "${{ matrix.os }}"
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1.0.4
- name: Set up JDK 17
uses: actions/setup-java@v2
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v3
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'zulu'
cache: 'gradle'
- name: Build with Gradle
+9 -11
View File
@@ -1,6 +1,6 @@
plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
id("xyz.jpenilla.run-paper") version "2.2.3"
id("io.github.goooler.shadow") version "8.1.7"
id("xyz.jpenilla.run-paper") version "2.3.0"
}
idea {
@@ -31,10 +31,10 @@ dependencies {
api("com.google.inject.extensions:guice-assistedinject:7.0.0") {
exclude("com.google.guava")
}
implementation("org.incendo:cloud-paper:2.0.0-beta.5") {
implementation("org.incendo:cloud-paper:2.0.0-beta.9") {
exclude("com.google.guava")
}
implementation("org.incendo:cloud-processors-confirmation:1.0.0-beta.2") {
implementation("org.incendo:cloud-processors-confirmation:1.0.0-beta.3") {
exclude("com.google.guava")
}
implementation("net.kyori:adventure-text-minimessage:4.16.0")
@@ -43,7 +43,6 @@ dependencies {
// Project submodules
api(projects.areashopInterface)
api(projects.areashopNms)
api(projects.adapters.platform.platformInterface)
api(projects.adapters.platform.paper)
@@ -53,7 +52,6 @@ dependencies {
runtimeOnly(projects.adapters.plugins.worldguard)
runtimeOnly(projects.adapters.plugins.fastasyncworldedit)
runtimeOnly(projects.adapters.plugins.essentials)
runtimeOnly(projects.adapters.platform.bukkitModern)
}
testImplementation("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.86.1")
@@ -132,15 +130,15 @@ tasks {
// Configure the Minecraft version for our task.
// This is the only required configuration besides applying the plugin.
// Your plugin's jar (or shadowJar if present) will be used automatically.
minecraftVersion("1.18.2")
minecraftVersion("1.21")
downloadPlugins {
github("EssentialsX", "essentials", "2.20.1", "EssentialsX-2.20.1.jar")
github("MilkBowl", "Vault", "1.7.3", "Vault.jar")
// WorldEdit 7.2.19
url("https://mediafilez.forgecdn.net/files/5077/477/worldedit-bukkit-7.2.19.jar")
// WorldGuard 7.0.7
url("https://mediafilez.forgecdn.net/files/3677/516/worldguard-bukkit-7.0.7-dist.jar")
// WorldEdit 7.3.3
url("https://mediafilez.forgecdn.net/files/5400/331/worldedit-bukkit-7.3.3.jar")
// WorldGuard 7.0.10
url("https://mediafilez.forgecdn.net/files/5344/377/worldguard-bukkit-7.0.10-dist.jar")
}
}
}
@@ -100,7 +100,7 @@ public class ASLanguageManager extends LanguageManager {
Log.error("Failed to find location of jar file:", ExceptionUtils.getStackTrace(e));
return;
}
try (ZipFile jar = new ZipFile(jarPath);) {
try (ZipFile jar = new ZipFile(jarPath)) {
Enumeration<? extends ZipEntry> entries = jar.entries();
// Each entry is a file or directory
@@ -26,7 +26,6 @@ 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.platform.adapter.PlatformAdapter;
import me.wiefferink.areashop.services.ServiceManager;
import me.wiefferink.areashop.tools.GithubUpdateCheck;
import me.wiefferink.areashop.tools.LanguageConverter;
@@ -79,7 +78,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
private WorldGuardInterface worldGuardInterface = null;
private WorldEditPlugin worldEdit = null;
private WorldEditInterface worldEditInterface = null;
private PlatformAdapter platformAdapter;
private MessageBridge messageBridge;
private IFileManager fileManager = null;
private LanguageManager languageManager = null;
@@ -183,18 +181,8 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
// Setup NMS Impl
Version currentServerVersion = VersionUtil.parseMinecraftVersion(Bukkit.getBukkitVersion());
if (currentServerVersion.versionData().isOlderThan(VersionUtil.MC_1_18_2)) {
error("Unsupported minecraft version: " + currentServerVersion + "! Minimum is 1.18.2");
shutdownOnError();
return;
}
try {
Class<?> adapterImpl = Class.forName("me.wiefferink.areashop.adapters.platform.modern.ModernPlatformAdapter");
this.platformAdapter = adapterImpl.asSubclass(PlatformAdapter.class).getConstructor().newInstance();
} catch (ReflectiveOperationException ex) {
ex.printStackTrace();
error("Failed to initialize modern PlatformAdapter implementation!");
if (currentServerVersion.versionData().isOlderThan(VersionUtil.MC_1_21)) {
error("Unsupported minecraft version: " + currentServerVersion + "! Minimum is 1.21");
shutdownOnError();
return;
}
@@ -207,7 +195,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
platform = new SpigotPlatform(this);
info("Detected Spigot; using the SpigotPlatform impl");
}
final PlatformModule platformModule = new PlatformModule(platform, this.platformAdapter);
final PlatformModule platformModule = new PlatformModule(platform);
// Check if Vault is present
if(getServer().getPluginManager().getPlugin("Vault") == null) {
@@ -271,7 +259,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
AreaShopModule asModule = new AreaShopModule(this,
this.messageBridge,
this.platformAdapter,
this.worldEditInterface,
this.worldGuardInterface,
this.signErrorLogger,
@@ -454,7 +441,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
List<String> chatPrefix = getConfig().getStringList("chatPrefix");
List<String> convertedChatPrefix = LanguageConverter.convertRawList(chatPrefix);
if (convertedChatPrefix.size() == 1) {
getConfig().set("mmChatPrefix", convertedChatPrefix.get(0));
getConfig().set("mmChatPrefix", convertedChatPrefix.getFirst());
} else {
getConfig().set("mmChatPrefix", convertedChatPrefix);
}
@@ -503,10 +490,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
this.chatprefix = chatprefix;
}
public PlatformAdapter getPlatformAdapter() {
return platformAdapter;
}
public SignErrorLogger getSignErrorLogger() {
return signErrorLogger;
}
@@ -605,7 +588,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
* Function to get the Vault plugin.
* @return Economy
*/
@Deprecated
private Economy getEconomy() {
RegisteredServiceProvider<Economy> economy = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if(economy == null) {
@@ -619,7 +601,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
* Get the Vault permissions provider.
* @return Vault permissions provider
*/
@Deprecated
private net.milkbowl.vault.permission.Permission getPermissionProvider() {
RegisteredServiceProvider<net.milkbowl.vault.permission.Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
if (permissionProvider == null) {
@@ -10,6 +10,8 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.WorldFlagUtil;
import me.wiefferink.areashop.commands.util.WorldGuardRegionParser;
import me.wiefferink.areashop.commands.util.WorldSelection;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
import me.wiefferink.areashop.events.ask.BuyingRegionEvent;
import me.wiefferink.areashop.events.ask.RentingRegionEvent;
@@ -28,13 +30,11 @@ import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.key.CloudKey;
import org.incendo.cloud.parser.ParserDescriptor;
import org.incendo.cloud.parser.standard.EnumParser;
import org.jetbrains.annotations.NotNull;
@@ -92,31 +92,29 @@ public class AddCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
// /as add <rent|buy> [region] [world]
ParserDescriptor<Entity, ProtectedRegion> wgRegionParser = ParserDescriptor.of(new WorldGuardRegionParser<>(
WorldFlagUtil.DEFAULT_WORLD_FLAG,
this.worldGuardInterface), ProtectedRegion.class);
var wgRegionParser = WorldGuardRegionParser.worldGuardRegionParser(WorldFlagUtil.DEFAULT_WORLD_FLAG, this.worldGuardInterface);
return builder
.literal("add")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.required(KEY_REGION_TYPE, EnumParser.enumParser(GeneralRegion.RegionType.class))
.optional(KEY_REGION, wgRegionParser)
.flag(WorldFlagUtil.DEFAULT_WORLD_FLAG)
.handler(this::handleCommand);
}
private void handleCommand(CommandContext<Player> context) {
Player player = context.sender();
private void handleCommand(CommandContext<PlayerCommandSource> context) {
Player player = context.sender().sender();
final GeneralRegion.RegionType regionType = context.get(KEY_REGION_TYPE);
World world = WorldFlagUtil.parseOrDetectWorld(context);
World world = WorldFlagUtil.parseOrDetectWorld(context, player);
Map<String, ProtectedRegion> regions;
Optional<ProtectedRegion> inputRegion = context.optional(KEY_REGION);
if (inputRegion.isPresent()) {
regions = new HashMap<>();
regions.put(inputRegion.get().getId(), inputRegion.get());
} else {
WorldSelection selection = WorldSelection.fromPlayer(context.sender(), this.worldEditInterface);
WorldSelection selection = WorldSelection.fromPlayer(player, this.worldEditInterface);
regions = Utils.getWorldEditRegionsInSelection(selection.selection()).stream()
.collect(Collectors.toMap(ProtectedRegion::getId, region -> region));
}
@@ -318,7 +316,7 @@ public class AddCommand extends AreashopCommandBean {
// Add existing owners/members if any
if (!landlord && !existing.isEmpty()) {
UUID rentBy = existing.remove(0);
UUID rentBy = existing.removeFirst();
OfflinePlayer rentByPlayer = Bukkit.getOfflinePlayer(rentBy);
RentingRegionEvent rentingRegionEvent = new RentingRegionEvent(rent,
@@ -378,7 +376,7 @@ public class AddCommand extends AreashopCommandBean {
// Add existing owners/members if any
if (!landlord && !existing.isEmpty()) {
UUID buyBy = existing.remove(0);
UUID buyBy = existing.removeFirst();
OfflinePlayer buyByPlayer = Bukkit.getOfflinePlayer(buyBy);
BuyingRegionEvent buyingRegionEvent = new BuyingRegionEvent(buy,
@@ -6,6 +6,8 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -19,6 +21,7 @@ import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.key.CloudKey;
import org.incendo.cloud.parser.flag.CommandFlag;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
@@ -47,7 +50,7 @@ public class AddFriendCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.addfriendall") || target.hasPermission("areashop.addfriend")) {
return "help-addFriend";
}
@@ -55,21 +58,21 @@ public class AddFriendCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("addfriend")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.required(KEY_FRIEND, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser())
.flag(this.regionFlag)
.handler(this::handleCommand);
}
private void handleCommand(CommandContext<Player> context) {
Player sender = context.sender();
private void handleCommand(CommandContext<PlayerCommandSource> context) {
Player sender = context.sender().sender();
if (!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) {
this.messageBridge.message(sender, "addfriend-noPermission");
return;
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
OfflinePlayer friend = context.get(KEY_FRIEND);
if (sender.hasPermission("areashop.addfriendall") && ((region instanceof RentRegion rentRegion && !rentRegion.isRented())
|| (region instanceof BuyRegion buyRegion && !buyRegion.isSold()))) {
@@ -8,6 +8,8 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.SignProfileUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.features.signs.SignManager;
import me.wiefferink.areashop.managers.IFileManager;
@@ -24,6 +26,7 @@ import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.key.CloudKey;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.Optional;
@@ -58,7 +61,7 @@ public class AddSignCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if(target.hasPermission("areashop.addsign")) {
return "help-addsign";
}
@@ -66,16 +69,16 @@ public class AddSignCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("addsign")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.optional(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
.flag(SignProfileUtil.DEFAULT_FLAG)
.handler(this::handleCommand);
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player sender = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player sender = context.sender().sender();
if (!sender.hasPermission("areashop.addsign")) {
throw new AreaShopCommandException("addsign-noPermission");
}
@@ -93,7 +96,7 @@ public class AddSignCommand extends AreashopCommandBean {
return;
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, KEY_REGION);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, KEY_REGION);
String profile = SignProfileUtil.getOrParseProfile(context, this.plugin);
Optional<RegionSign> optionalRegionSign = this.signManager.signFromLocation(block.getLocation());
if(optionalRegionSign.isPresent()) {
@@ -5,6 +5,8 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import org.bukkit.command.CommandSender;
@@ -13,6 +15,7 @@ import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.parser.flag.CommandFlag;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
@@ -27,7 +30,7 @@ public class BuyCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if(target.hasPermission("areashop.buy")) {
return "help-buy";
}
@@ -46,20 +49,21 @@ public class BuyCommand extends AreashopCommandBean {
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder
.literal("buy")
.flag(this.buyRegionFlag)
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.handler(this::handleCommand);
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
if (!context.hasPermission("areashop.buy")) {
throw new AreaShopCommandException("buy-noPermission");
}
BuyRegion region = RegionParseUtil.getOrParseBuyRegion(context, this.buyRegionFlag);
region.buy(context.sender());
Player sender = context.sender().sender();
BuyRegion region = RegionParseUtil.getOrParseBuyRegion(context, sender, this.buyRegionFlag);
region.buy(sender);
}
}
@@ -8,6 +8,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
import me.wiefferink.areashop.commands.util.WorldSelection;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.managers.IFileManager;
@@ -21,7 +22,7 @@ import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.key.CloudKey;
import org.incendo.cloud.parser.ParserDescriptor;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.ArrayList;
@@ -56,7 +57,7 @@ public class DelCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.destroyrent") || target.hasPermission("areashop.destroybuy") || target.hasPermission(
"areashop.destroyrent.landlord") || target.hasPermission("areashop.destroybuy.landlord")) {
return "help-del";
@@ -70,18 +71,14 @@ public class DelCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
ParserDescriptor<CommandSender, GeneralRegion> regionParser = ParserDescriptor.of(
new GeneralRegionParser<>(this.fileManager),
GeneralRegion.class
);
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("del", "delete")
.optional(KEY_REGION, regionParser)
.optional(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
.handler(this::handleCommand);
}
public void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
public void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.destroybuy")
&& !sender.hasPermission("areashop.destroybuy.landlord")
&& !sender.hasPermission("areashop.destroyrent")
@@ -179,12 +176,9 @@ public class DelCommand extends AreashopCommandBean {
return true;
}
if (region instanceof BuyRegion
return region instanceof BuyRegion
&& (!sender.hasPermission("areashop.destroybuy") && !(isLandlord && sender.hasPermission(
"areashop.destroybuy.landlord")))) {
return true;
}
return false;
"areashop.destroybuy.landlord")));
}
}
@@ -7,6 +7,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.features.FriendsFeature;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -22,6 +23,7 @@ import org.incendo.cloud.context.CommandInput;
import org.incendo.cloud.key.CloudKey;
import org.incendo.cloud.parser.flag.CommandFlag;
import org.incendo.cloud.suggestion.Suggestion;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.Collection;
@@ -63,7 +65,7 @@ public class DelFriendCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.delfriendall") || target.hasPermission("areashop.delfriend")) {
return "help-delFriend";
}
@@ -81,19 +83,19 @@ public class DelFriendCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("delfriend", "deletefriend")
.required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser(), this::suggestFriends)
.flag(this.regionFlag)
.handler(this::handleCommand);
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) {
throw new AreaShopCommandException("delfriend-noPermission");
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
OfflinePlayer friend = context.get(KEY_PLAYER);
FriendsFeature friendsFeature = region.getFriendsFeature();
if (sender.hasPermission("areashop.delfriendall")) {
@@ -128,16 +130,16 @@ public class DelFriendCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestFriends(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
CommandSender sender = context.sender();
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.delfriend")) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
GeneralRegion region;
try {
region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
} catch (AreaShopCommandException ignored) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
@@ -5,6 +5,8 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.features.signs.SignManager;
import me.wiefferink.areashop.tools.Materials;
@@ -16,6 +18,7 @@ import org.bukkit.util.BlockIterator;
import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.Optional;
@@ -44,22 +47,22 @@ public class DelSignCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("delsign", "deletesign")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.handler(this::handleCommand);
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.delsign")) {
return "help-delsign";
}
return null;
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player sender = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player sender = context.sender().sender();
if (!sender.hasPermission("areashop.delsign")) {
throw new AreaShopCommandException("delsign-noPermission");
}
@@ -6,6 +6,8 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionGroupParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -24,6 +26,7 @@ import org.incendo.cloud.parser.ParserDescriptor;
import org.incendo.cloud.parser.flag.CommandFlag;
import org.incendo.cloud.parser.standard.DoubleParser;
import org.incendo.cloud.parser.standard.EnumParser;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.Collection;
@@ -65,7 +68,7 @@ public class FindCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if(target.hasPermission("areashop.find")) {
return "help-find";
}
@@ -73,9 +76,9 @@ public class FindCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("find")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.required(KEY_REGION_TYPE, EnumParser.enumParser(GeneralRegion.RegionType.class))
.optional(KEY_PRICE, DoubleParser.doubleParser(0))
.flag(this.regionGroupFlag)
@@ -87,8 +90,8 @@ public class FindCommand extends AreashopCommandBean {
return CommandProperties.of("find");
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player sender = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player sender = context.sender().sender();
if (!sender.hasPermission("areashop.find")) {
throw new AreaShopCommandException("find-noPermission");
}
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RegionFactory;
@@ -20,6 +21,7 @@ import org.incendo.cloud.key.CloudKey;
import org.incendo.cloud.parser.flag.CommandFlag;
import org.incendo.cloud.parser.standard.StringParser;
import org.incendo.cloud.suggestion.Suggestion;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.Collection;
@@ -57,7 +59,7 @@ public class GroupAddCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if(target.hasPermission("areashop.groupadd")) {
return "help-groupadd";
}
@@ -65,7 +67,7 @@ public class GroupAddCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("groupadd")
.required(KEY_GROUP, StringParser.stringParser(), this::suggestGroupNames)
.flag(this.regionFlag)
@@ -77,8 +79,8 @@ public class GroupAddCommand extends AreashopCommandBean {
return CommandProperties.of("groupadd");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.groupadd")) {
throw new AreaShopCommandException("groupadd-noPermission");
}
@@ -102,7 +104,7 @@ public class GroupAddCommand extends AreashopCommandBean {
return;
}
Collection<GeneralRegion> regions = RegionParseUtil.getOrParseRegionsInSel(context, this.regionFlag);
Collection<GeneralRegion> regions = RegionParseUtil.getOrParseRegionsInSel(context, sender, this.regionFlag);
Set<GeneralRegion> regionsSuccess = new TreeSet<>();
Set<GeneralRegion> regionsFailed = new TreeSet<>();
for (GeneralRegion region : regions) {
@@ -129,7 +131,7 @@ public class GroupAddCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestGroupNames(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
String text = input.peekString();
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RegionFactory;
@@ -20,6 +21,7 @@ import org.incendo.cloud.key.CloudKey;
import org.incendo.cloud.parser.flag.CommandFlag;
import org.incendo.cloud.parser.standard.StringParser;
import org.incendo.cloud.suggestion.Suggestion;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.Collection;
@@ -57,7 +59,7 @@ public class GroupDelCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if(target.hasPermission("areashop.groupdel")) {
return "help-groupdel";
}
@@ -65,7 +67,7 @@ public class GroupDelCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("groupdel")
.required(KEY_GROUP, StringParser.stringParser(), this::suggestGroupNames)
.flag(this.regionFlag)
@@ -77,8 +79,8 @@ public class GroupDelCommand extends AreashopCommandBean {
return CommandProperties.of("groupdel");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("groupdel")) {
throw new AreaShopCommandException("groupdel-noPermission");
}
@@ -101,7 +103,7 @@ public class GroupDelCommand extends AreashopCommandBean {
return;
}
Collection<GeneralRegion> regions = RegionParseUtil.getOrParseRegionsInSel(context, this.regionFlag);
Collection<GeneralRegion> regions = RegionParseUtil.getOrParseRegionsInSel(context, sender, this.regionFlag);
Set<GeneralRegion> regionsSuccess = new TreeSet<>();
Set<GeneralRegion> regionsFailed = new TreeSet<>();
for (GeneralRegion region : regions) {
@@ -129,7 +131,7 @@ public class GroupDelCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestGroupNames(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
String text = input.peekString();
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionGroupParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.RegionGroup;
import me.wiefferink.areashop.tools.Utils;
@@ -15,6 +16,7 @@ import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.key.CloudKey;
import org.incendo.cloud.parser.ParserDescriptor;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.Set;
@@ -39,7 +41,7 @@ public class GroupInfoCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if(target.hasPermission("areashop.groupinfo")) {
return "help-groupinfo";
}
@@ -47,8 +49,8 @@ public class GroupInfoCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
ParserDescriptor<CommandSender, RegionGroup> regionGroupParser = ParserDescriptor.of(
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
ParserDescriptor<CommandSource<?>, RegionGroup> regionGroupParser = ParserDescriptor.of(
new RegionGroupParser<>(this.fileManager, "groupinfo-noGroup"),
RegionGroup.class);
return builder
@@ -63,7 +65,7 @@ public class GroupInfoCommand extends AreashopCommandBean {
return CommandProperties.of("groupinfo");
}
public void handleCommand(@Nonnull CommandContext<CommandSender> context) {
public void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
if (!context.hasPermission("groupinfo")) {
throw new AreaShopCommandException("groupinfo-noPermission");
}
@@ -5,6 +5,7 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.command.CommandSender;
@@ -41,7 +42,7 @@ public class GroupListCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("grouplist", "groups")
.handler(this::handleCommand);
}
@@ -51,12 +52,12 @@ public class GroupListCommand extends AreashopCommandBean {
return CommandProperties.of("grouplist", "groups");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
if (!context.hasPermission("areashop.grouplist")) {
throw new AreaShopCommandException("grouplist-noPermission");
}
List<String> groups = this.fileManager.getGroupNames();
CommandSender sender = context.sender();
CommandSender sender = context.sender().sender();
if(groups.isEmpty()) {
messageBridge.message(sender, "grouplist-noGroups");
} else {
@@ -5,6 +5,7 @@ import com.google.inject.Singleton;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.AreashopCommands;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import org.bukkit.command.CommandSender;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.Command;
@@ -24,7 +25,7 @@ public class HelpCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.help")) {
return "help-help";
}
@@ -36,9 +37,8 @@ public class HelpCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("help")
.handler(this::handleCommand);
}
@@ -48,8 +48,8 @@ public class HelpCommand extends AreashopCommandBean {
return CommandProperties.of("help");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.help")) {
throw new AreaShopCommandException("help-noPermission");
}
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AcceptedValuesParser;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.regions.ImportJobFactory;
import org.bukkit.command.CommandSender;
import org.incendo.cloud.Command;
@@ -13,6 +14,7 @@ import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.key.CloudKey;
import org.incendo.cloud.parser.ParserDescriptor;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.List;
@@ -42,7 +44,7 @@ public class ImportCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if(target.hasPermission("areashop.import")) {
return "help-import";
}
@@ -50,7 +52,7 @@ public class ImportCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
withConfirmation();
var sourceParser = AcceptedValuesParser.ofConstant(List.of("RegionForSale"), "import-wrongSource", true);
return builder.literal("import")
@@ -69,8 +71,8 @@ public class ImportCommand extends AreashopCommandBean {
// - Region flags?
// - Settings from the 'permissions' section in RegionForSale/config.yml?
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.import")) {
this.messageBridge.message(sender, "import-noPermission");
return;
@@ -4,10 +4,12 @@ import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import org.bukkit.command.CommandSender;
import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
@@ -29,7 +31,7 @@ public class InfoBaseCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.info")) {
return "help-info";
}
@@ -37,7 +39,7 @@ public class InfoBaseCommand extends AreashopCommandBean {
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("info").handler(this::handleCommand);
}
@@ -46,8 +48,8 @@ public class InfoBaseCommand extends AreashopCommandBean {
return CommandProperties.of("info");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.info")) {
messageBridge.message(sender, "info-noPermission");
return;
@@ -5,6 +5,7 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionGroupParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -21,6 +22,7 @@ import org.incendo.cloud.parser.ParserDescriptor;
import org.incendo.cloud.parser.flag.CommandFlag;
import org.incendo.cloud.parser.standard.EnumParser;
import org.incendo.cloud.parser.standard.IntegerParser;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.LinkedList;
@@ -59,15 +61,12 @@ public class InfoCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
if(target.hasPermission("areashop.info")) {
return "help-info";
}
public String getHelpKey(@NotNull CommandSender target) {
return null;
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("info")
.required(KEY_TYPE, EnumParser.enumParser(RegionStateFilterType.class))
.flag(FLAG_PAGE)
@@ -80,8 +79,8 @@ public class InfoCommand extends AreashopCommandBean {
return CommandProperties.of("info");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.info")) {
messageBridge.message(sender, "info-noPermission");
return;
@@ -90,7 +89,7 @@ public class InfoCommand extends AreashopCommandBean {
processOtherFilters(context, filterType);
}
private void processOtherFilters(@Nonnull CommandContext<CommandSender> context,
private void processOtherFilters(@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull RegionStateFilterType filterType) {
RegionGroup filterGroup = context.flags().get(this.filterGroupFlag);
int page = context.flags().getValue(FLAG_PAGE).orElse(1);
@@ -127,7 +126,7 @@ public class InfoCommand extends AreashopCommandBean {
case RESELLING -> "info reselling";
case NOGROUP -> "info nogroup";
};
showSortedPagedList(context.sender(), toShow, filterGroup, header, page, baseCommand);
showSortedPagedList(context.sender().sender(), toShow, filterGroup, header, page, baseCommand);
}
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionInfoUtil;
import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@@ -40,14 +41,11 @@ public class InfoPlayerCommand extends AreashopCommandBean {
@Override
public String getHelpKey(CommandSender target) {
if (target.hasPermission("areashop.info")) {
return "help-info";
}
return null;
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("info").literal("player")
.required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser())
.handler(this::handleCommand);
@@ -58,8 +56,8 @@ public class InfoPlayerCommand extends AreashopCommandBean {
return CommandProperties.of("info region");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.info")) {
messageBridge.message(sender, "info-noPermission");
return;
@@ -6,6 +6,7 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -18,6 +19,7 @@ import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.parser.flag.CommandFlag;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.ArrayList;
@@ -45,15 +47,12 @@ public class InfoRegionCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
if (target.hasPermission("areashop.info")) {
return "help-info";
}
public String getHelpKey(@NotNull CommandSender target) {
return null;
}
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("info").literal("region")
.flag(this.regionFlag)
.handler(this::handleCommand);
@@ -64,14 +63,14 @@ public class InfoRegionCommand extends AreashopCommandBean {
return CommandProperties.of("info region");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.info")) {
messageBridge.message(sender, "info-noPermission");
return;
}
// Region info
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
if (region instanceof RentRegion rent) {
handleRent(sender, rent);
} else if (region instanceof BuyRegion buy) {
@@ -7,6 +7,8 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.SignProfileUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.SignLinkerManager;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -22,7 +24,6 @@ import javax.annotation.Nonnull;
@Singleton
public class LinkSignsCommand extends AreashopCommandBean {
private final MessageBridge messageBridge;
private final SignLinkerManager signLinkerManager;
private final AreaShop plugin;
@@ -34,7 +35,6 @@ public class LinkSignsCommand extends AreashopCommandBean {
@Nonnull SignLinkerManager signLinkerManager,
@Nonnull AreaShop plugin
) {
this.messageBridge = messageBridge;
this.signLinkerManager = signLinkerManager;
this.plugin = plugin;
this.profileFlag = SignProfileUtil.createDefault(plugin);
@@ -46,11 +46,10 @@ public class LinkSignsCommand extends AreashopCommandBean {
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("linksign")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.flag(this.profileFlag)
.handler(this::handleCommand);
}
@@ -68,8 +67,8 @@ public class LinkSignsCommand extends AreashopCommandBean {
return null;
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player player = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player player = context.sender().sender();
if (!player.hasPermission("linksigns")) {
throw new AreaShopCommandException("linksigns-noPermission");
}
@@ -7,6 +7,8 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionInfoUtil;
import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@@ -41,11 +43,10 @@ public class MeCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("me")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.optional(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser())
.handler(this::handleCommand);
}
@@ -56,15 +57,15 @@ public class MeCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.me")) {
return "help-me";
}
return null;
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player sender = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player sender = context.sender().sender();
if (!sender.hasPermission("areashop.me")) {
throw new AreaShopCommandException("me-noPermission");
}
@@ -1,10 +1,9 @@
package me.wiefferink.areashop.commands;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.tools.SimpleMessageBridge;
import me.wiefferink.interactivemessenger.processing.Message;
import org.bukkit.command.CommandSender;
@@ -26,14 +25,7 @@ public class MessageCommand extends AreashopCommandBean {
private static final CloudKey<Player> KEY_PLAYER = CloudKey.of("player", Player.class);
private static final CloudKey<String> KEY_MESSAGE = CloudKey.of("message", String.class);
private final MessageBridge messageBridge;
@Inject
public MessageCommand(@Nonnull MessageBridge messageBridge) {
this.messageBridge = messageBridge;
}
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
// Internal command, no need to show in the help list
return null;
}
@@ -43,9 +35,8 @@ public class MessageCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("message")
.required(KEY_PLAYER, PlayerParser.playerParser())
.required(KEY_MESSAGE, StringParser.greedyStringParser())
@@ -57,8 +48,8 @@ public class MessageCommand extends AreashopCommandBean {
return CommandProperties.of("message");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if(!sender.hasPermission("areashop.message")) {
throw new AreaShopCommandException("message-noPermission");
}
@@ -8,6 +8,8 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.ArgumentParseExceptionHandler;
import me.wiefferink.areashop.commands.util.RegionCreationUtil;
import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.RegionFactory;
@@ -61,10 +63,10 @@ public class QuickBuyCommand extends AreashopCommandBean {
@Nonnull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("quickbuy")
.permission("permission")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.required(KEY_REGION, StringParser.stringParser())
.required(KEY_PRICE, DoubleParser.doubleParser(0))
.required(KEY_LANDLORD, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser())
@@ -73,16 +75,16 @@ public class QuickBuyCommand extends AreashopCommandBean {
// /as quickbuy <name> <price> <duration> <landlord>
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player player = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player player = context.sender().sender();
if (!player.hasPermission("areashop.quickbuy")) {
player.sendMessage("Insufficient permission");
return;
}
this.regionCreationUtil.createRegion(context, KEY_REGION)
this.regionCreationUtil.createRegion(context, player, KEY_REGION)
.exceptionally(throwable -> {
if (throwable instanceof AreaShopCommandException exception) {
ArgumentParseExceptionHandler.handleException(this.messageBridge, player, exception);
ArgumentParseExceptionHandler.handleException(this.messageBridge, context.sender(), exception);
} else {
throw new CommandExecutionException(throwable, context);
}
@@ -96,8 +98,8 @@ public class QuickBuyCommand extends AreashopCommandBean {
double price = context.get(KEY_PRICE);
OfflinePlayer landlord = context.get(KEY_LANDLORD);
if (!landlord.hasPlayedBefore()) {
this.messageBridge.message(player, "me-noPlayer");
if (!landlord.isOnline() && !landlord.hasPlayedBefore()) {
this.messageBridge.message(player, "me-noPlayer", landlord.getName());
return;
}
String regionName = region.getId();
@@ -7,6 +7,8 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import me.wiefferink.areashop.managers.IFileManager;
@@ -56,16 +58,16 @@ public class QuickDeleteCommand extends AreashopCommandBean {
@Nonnull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("quickdelete", "quickdel")
.permission("areashop.quickdelete")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
.handler(this::handleCommand);
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player player = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player player = context.sender().sender();
GeneralRegion region = context.get(KEY_REGION);
boolean giveMoneyBack = context.flags().isPresent(FLAG_RETURN_MONEY);
DeletingRegionEvent event = this.fileManager.deleteRegion(region, giveMoneyBack);
@@ -9,6 +9,8 @@ import me.wiefferink.areashop.commands.util.ArgumentParseExceptionHandler;
import me.wiefferink.areashop.commands.util.DurationInputParser;
import me.wiefferink.areashop.commands.util.RegionCreationUtil;
import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.RegionFactory;
import me.wiefferink.areashop.regions.RentRegion;
@@ -65,10 +67,10 @@ public class QuickRentCommand extends AreashopCommandBean {
@Nonnull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("quickrent")
.permission("permission")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.required(KEY_REGION, StringParser.stringParser())
.required(KEY_PRICE, DoubleParser.doubleParser(0))
.required(KEY_DURATION, DurationInputParser.durationInputParser())
@@ -78,16 +80,16 @@ public class QuickRentCommand extends AreashopCommandBean {
// /as quickrent <name> <price> <duration> <landlord>
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player player = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player player = context.sender().sender();
if (!player.hasPermission("areashop.quickrent")) {
player.sendMessage("Insufficient permission");
return;
}
this.regionCreationUtil.createRegion(context, KEY_REGION)
this.regionCreationUtil.createRegion(context, player, KEY_REGION)
.exceptionally(throwable -> {
if (throwable instanceof AreaShopCommandException exception) {
ArgumentParseExceptionHandler.handleException(this.messageBridge, player, exception);
ArgumentParseExceptionHandler.handleException(this.messageBridge, context.sender(), exception);
} else {
throw new CommandExecutionException(throwable, context);
}
@@ -102,7 +104,7 @@ public class QuickRentCommand extends AreashopCommandBean {
DurationInput duration = context.get(KEY_DURATION);
OfflinePlayer landlord = context.get(KEY_LANDLORD);
if (!landlord.hasPlayedBefore()) {
if (!landlord.isOnline() && !landlord.hasPlayedBefore()) {
this.messageBridge.message(player, "me-noPlayer");
return;
}
@@ -5,6 +5,7 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import org.bukkit.command.CommandSender;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.Command;
@@ -30,7 +31,7 @@ public class ReloadCommand extends AreashopCommandBean {
@Nonnull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("reload")
.handler(this::handleCommand);
}
@@ -49,10 +50,10 @@ public class ReloadCommand extends AreashopCommandBean {
return null;
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
if (!context.hasPermission("areashop.reload")) {
throw new AreaShopCommandException("reload-noPermission");
}
this.plugin.reload(context.sender());
this.plugin.reload(context.sender().sender());
}
}
@@ -5,6 +5,8 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.RentRegion;
import org.bukkit.command.CommandSender;
@@ -13,6 +15,7 @@ import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandProperties;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.parser.flag.CommandFlag;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
@@ -32,7 +35,7 @@ public class RentCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if(target.hasPermission("areashop.rent")) {
return "help-rent";
}
@@ -46,20 +49,21 @@ public class RentCommand extends AreashopCommandBean {
@Override
protected @Nonnull Command.Builder<? extends CommandSender> configureCommand(@Nonnull Command.Builder<CommandSender> builder) {
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder
.literal("rent")
.flag(this.rentRegionFlag)
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.handler(this::handleCommand);
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
if (!context.hasPermission("areashop.rent")) {
throw new AreaShopCommandException("rent-noPermission");
}
RentRegion region = RegionParseUtil.getOrParseRentRegion(context, this.rentRegionFlag);
region.rent(context.sender());
Player sender = context.sender().sender();
RentRegion region = RegionParseUtil.getOrParseRentRegion(context, sender, this.rentRegionFlag);
region.rent(sender);
}
}
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.BuyRegionParser;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -39,11 +40,11 @@ public class ResellCommand extends AreashopCommandBean {
public ResellCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
this.messageBridge = messageBridge;
this.fileManager = fileManager;
ParserDescriptor<CommandSender, BuyRegion> regionParser = ParserDescriptor.of(
ParserDescriptor<CommandSource<?>, BuyRegion> regionParser = ParserDescriptor.of(
new BuyRegionParser<>(fileManager, this::suggestBuyRegions),
BuyRegion.class
);
this.regionFlag = CommandFlag.builder("region").withComponent(regionParser).build();
this.regionFlag = CommandFlag.<CommandSource<?>>builder("region").withComponent(regionParser).build();
}
@Override
@@ -51,9 +52,9 @@ public class ResellCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
@Nonnull
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
return builder.literal("resell")
.required(KEY_PRICE, DoubleParser.doubleParser(0))
.flag(this.regionFlag)
@@ -67,7 +68,7 @@ public class ResellCommand extends AreashopCommandBean {
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.resellall") || target.hasPermission("areashop.resell")) {
return "help-resell";
}
@@ -75,14 +76,14 @@ public class ResellCommand extends AreashopCommandBean {
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.resell") && !sender.hasPermission("areashop.resellall")) {
messageBridge.message(sender, "resell-noPermissionOther");
return;
}
double price = context.get(KEY_PRICE);
BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, this.regionFlag);
BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, sender, this.regionFlag);
if (!buy.isSold()) {
messageBridge.message(sender, "resell-notBought", buy);
return;
@@ -111,7 +112,7 @@ public class ResellCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestBuyRegions(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
String text = input.peekString();
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.command.CommandSender;
@@ -39,9 +40,8 @@ public class SchematicEventCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("schemevent")
.required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
.required(KEY_EVENT_TYPE, EnumParser.enumParser(GeneralRegion.RegionEvent.class))
@@ -54,15 +54,15 @@ public class SchematicEventCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.schematicevents")) {
return "help-schemevent";
}
return null;
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.schematicevents")) {
throw new AreaShopCommandException("schemevent-noPermission");
}
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.BuyRegionParser;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -34,11 +35,11 @@ public class SellCommand extends AreashopCommandBean {
@Inject
public SellCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
ParserDescriptor<CommandSender, BuyRegion> regionParser =
ParserDescriptor<CommandSource<?>, BuyRegion> regionParser =
ParserDescriptor.of(new BuyRegionParser<>(fileManager, this::suggestBuyRegions), BuyRegion.class);
this.messageBridge = messageBridge;
this.fileManager = fileManager;
this.buyRegionFlag = CommandFlag.builder("region").withComponent(regionParser).build();
this.buyRegionFlag = CommandFlag.<CommandSource<?>>builder("region").withComponent(regionParser).build();
}
/**
@@ -63,9 +64,8 @@ public class SellCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("sell")
.flag(this.buyRegionFlag)
.handler(this::handleCommand);
@@ -84,13 +84,13 @@ public class SellCommand extends AreashopCommandBean {
return null;
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.sell") && !sender.hasPermission("areashop.sellown")) {
this.messageBridge.message(sender, "sell-noPermission");
return;
}
BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, this.buyRegionFlag);
BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, sender, this.buyRegionFlag);
if (!buy.isSold()) {
messageBridge.message(sender, "sell-notBought", buy);
return;
@@ -99,7 +99,7 @@ public class SellCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestBuyRegions(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
String text = input.peekString();
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.DurationInput;
@@ -40,7 +41,7 @@ public class SetDurationCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.setduration")) {
return "help-setduration";
}
@@ -52,9 +53,8 @@ public class SetDurationCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("setduration")
.required(KEY_DURATION, StringParser.stringParser())
.flag(this.regionFlag)
@@ -66,13 +66,13 @@ public class SetDurationCommand extends AreashopCommandBean {
return CommandProperties.of("setduration");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.setduration") && (!sender.hasPermission("areashop.setduration.landlord") && sender instanceof Player)) {
this.messageBridge.message(sender, "setduration-noPermission");
return;
}
RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, this.regionFlag);
RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, sender, this.regionFlag);
if (!sender.hasPermission("areashop.setduration")
&& !(sender instanceof Player player
&& rent.isLandlord(player.getUniqueId()))
@@ -7,6 +7,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.OfflinePlayer;
@@ -40,7 +41,7 @@ public class SetLandlordCommand extends AreashopCommandBean {
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.setlandlord")) {
return "help-setlandlord";
}
@@ -52,9 +53,8 @@ public class SetLandlordCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("setlandlord")
.required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser())
.flag(this.regionFlag)
@@ -66,12 +66,12 @@ public class SetLandlordCommand extends AreashopCommandBean {
return CommandProperties.of("setlandlord");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.setlandlord")) {
throw new AreaShopCommandException("setlandlord-noPermission");
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
OfflinePlayer player = context.get(KEY_PLAYER);
String playerName = player.getName();
region.setLandlord(player.getUniqueId(), playerName);
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -42,7 +43,7 @@ public class SetOwnerCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.setownerrent") || target.hasPermission("areashop.setownerbuy")) {
return "help-setowner";
}
@@ -54,9 +55,8 @@ public class SetOwnerCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("setowner")
.required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser())
.flag(this.regionFlag)
@@ -68,13 +68,13 @@ public class SetOwnerCommand extends AreashopCommandBean {
return CommandProperties.of("setowner");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.setownerrent") && !sender.hasPermission("areashop.setownerbuy")) {
this.messageBridge.message(sender, "setowner-noPermission");
return;
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
if (region instanceof RentRegion && !sender.hasPermission("areashop.setownerrent")) {
this.messageBridge.message(sender, "setowner-noPermissionRent", region);
return;
@@ -5,6 +5,7 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -49,9 +50,8 @@ public class SetPriceCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("setprice")
.required(KEY_PRICE, StringParser.stringParser())
.flag(this.regionFlag)
@@ -63,13 +63,13 @@ public class SetPriceCommand extends AreashopCommandBean {
return CommandProperties.of("setprice");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.setprice") && (!sender.hasPermission("areashop.setprice.landlord") && sender instanceof Player)) {
this.messageBridge.message(sender, "setprice-noPermission");
return;
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
if (!sender.hasPermission("areashop.setprice")
&& !(sender instanceof Player player && region.isLandlord(player.getUniqueId()))) {
this.messageBridge.message(sender, "setprice-noLandlord", region);
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.command.CommandSender;
@@ -44,7 +45,7 @@ public class SetRestoreCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.setrestore")) {
return "help-setrestore";
}
@@ -56,9 +57,8 @@ public class SetRestoreCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("setrestore")
.required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
.required(KEY_RESTORE, StringParser.stringParser(), this::suggestRestoreType)
@@ -71,8 +71,8 @@ public class SetRestoreCommand extends AreashopCommandBean {
return CommandProperties.of("setrestore");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.setrestore")) {
throw new AreaShopCommandException("setrestore-noPermission");
}
@@ -101,7 +101,7 @@ public class SetRestoreCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestRestoreType(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
String text = input.peekString();
@@ -113,7 +113,7 @@ public class SetRestoreCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestSchematicProfiles(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
ConfigurationSection schemProfiles = fileManager.getConfig().getConfigurationSection("schematicProfiles");
@@ -7,6 +7,8 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -53,7 +55,7 @@ public class SetTeleportCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.setteleportall") || target.hasPermission("areashop.setteleport")) {
return "help-setteleport";
}
@@ -65,11 +67,10 @@ public class SetTeleportCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("settp")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.flag(this.regionFlag)
.handler(this::handleCommand);
}
@@ -79,13 +80,13 @@ public class SetTeleportCommand extends AreashopCommandBean {
return CommandProperties.of("settp");
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player player = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player player = context.sender().sender();
if (!player.hasPermission("areashop.setteleport") && !player.hasPermission("areashop.setteleportall")) {
this.messageBridge.message(player, "setteleport-noPermission");
return;
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, player, this.regionFlag);
boolean owner;
if (region instanceof RentRegion rentRegion) {
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.command.CommandSender;
@@ -49,9 +50,8 @@ public class SetTransferCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("settransfer")
.required(KEY_ENABLED, BooleanParser.booleanParser(true))
.flag(this.regionFlag)
@@ -63,12 +63,12 @@ public class SetTransferCommand extends AreashopCommandBean {
return CommandProperties.of("settransfer");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.settransfer")) {
throw new AreaShopCommandException("settransfer-noPermission");
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
boolean enabled = context.get(KEY_ENABLED);
region.setTransferEnabled(enabled);
messageBridge.message(sender, "settransfer-success", enabled, region);
@@ -7,6 +7,8 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
@@ -96,7 +98,7 @@ public class StackCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.stack")) {
return "help-stack";
}
@@ -108,11 +110,10 @@ public class StackCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("stack")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.required(KEY_AMOUNT, IntegerParser.integerParser(0))
.required(KEY_GAP, IntegerParser.integerParser(0))
.required(KEY_NAME, StringParser.stringParser())
@@ -127,8 +128,8 @@ public class StackCommand extends AreashopCommandBean {
return CommandProperties.of("stack");
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player player = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player player = context.sender().sender();
if (!player.hasPermission("areashop.stack")) {
throw new AreaShopCommandException("stack-noPermission");
}
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.BuyRegionParser;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -35,11 +36,11 @@ public class StopResellCommand extends AreashopCommandBean {
@Inject
public StopResellCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
ParserDescriptor<CommandSender, BuyRegion> regionParser =
ParserDescriptor<CommandSource<?>, BuyRegion> regionParser =
ParserDescriptor.of(new BuyRegionParser<>(fileManager, this::suggestBuyRegions), BuyRegion.class);
this.messageBridge = messageBridge;
this.fileManager = fileManager;
this.regionFlag = CommandFlag.builder("region")
this.regionFlag = CommandFlag.<CommandSource<?>>builder("region")
.withComponent(regionParser)
.build();
}
@@ -57,9 +58,8 @@ public class StopResellCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("stopresell")
.flag(this.regionFlag)
.handler(this::handleCommand);
@@ -70,14 +70,14 @@ public class StopResellCommand extends AreashopCommandBean {
return CommandProperties.of("stopresell");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.stopresell") && !sender.hasPermission("areashop.stopresellall")) {
this.messageBridge.message(sender, "stopresell-noPermissionOther");
return;
}
BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, this.regionFlag);
BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, sender, this.regionFlag);
if (!buy.isInResellingMode()) {
this.messageBridge.message(sender, "stopresell-notResell", buy);
return;
@@ -100,7 +100,7 @@ public class StopResellCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestBuyRegions(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
String text = input.peekString();
@@ -5,6 +5,8 @@ import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.command.CommandSender;
@@ -53,7 +55,7 @@ public class TeleportCommand extends AreashopCommandBean {
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.teleportall") || target.hasPermission("areashop.teleport")) {
return "help-teleport";
}
@@ -65,11 +67,10 @@ public class TeleportCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("tp", "teleport")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
.handler(this::handleCommand);
}
@@ -79,8 +80,8 @@ public class TeleportCommand extends AreashopCommandBean {
return CommandProperties.of("teleport", "tp");
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player player = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player player = context.sender().sender();
if (!player.hasPermission("areashop.teleport") && !player.hasPermission("areashop.teleportall") && !player.hasPermission(
"areashop.teleportavailable") && !player.hasPermission("areashop.teleportavailablesign") && !player.hasPermission(
"areashop.teleportsign") && !player.hasPermission("areashop.teleportsignall") && !player.hasPermission(
@@ -7,6 +7,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.features.homeaccess.HomeAccessFeature;
import me.wiefferink.areashop.features.homeaccess.HomeAccessType;
import me.wiefferink.areashop.managers.IFileManager;
@@ -43,9 +44,9 @@ public final class ToggleHomeCommand extends AreashopCommandBean {
public ToggleHomeCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
this.messageBridge = messageBridge;
this.fileManager = fileManager;
this.regionFlag = CommandFlag.builder("region")
this.regionFlag = CommandFlag.<CommandSource<?>>builder("region")
.withComponent(
new CommandComponent.Builder<CommandSender, GeneralRegion>()
CommandComponent.<CommandSource<?>, GeneralRegion>builder()
.name("region")
.description(Description.EMPTY)
.valueType(GeneralRegion.class)
@@ -57,7 +58,7 @@ public final class ToggleHomeCommand extends AreashopCommandBean {
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (!target.hasPermission("sethomecontrol.control")) {
return null;
}
@@ -69,9 +70,8 @@ public final class ToggleHomeCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("togglehome")
.required(KEY_ACCESS_TYPE, EnumParser.enumParser(HomeAccessType.class))
.flag(this.regionFlag)
@@ -83,13 +83,13 @@ public final class ToggleHomeCommand extends AreashopCommandBean {
return CommandProperties.of("togglehome");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.togglehome")) {
throw new AreaShopCommandException("togglehome-noPermission");
}
final HomeAccessType accessType = context.get(KEY_ACCESS_TYPE);
final GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
final GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
if (!(sender instanceof Player) && !sender.hasPermission("sethome.control.other")) {
return;
}
@@ -101,11 +101,11 @@ public final class ToggleHomeCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestRegions(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
String text = input.peekString();
CommandSender sender = context.sender();
CommandSender sender = context.sender().sender();
Stream<GeneralRegion> regions;
if (sender.hasPermission("sethome.control.other")) {
regions = this.fileManager.getRegionsRef().stream();
@@ -8,6 +8,8 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.OfflinePlayer;
@@ -43,17 +45,17 @@ public class TransferCommand extends AreashopCommandBean {
@Nonnull MessageBridge messageBridge,
@Nonnull IFileManager fileManager
) {
ParserDescriptor<Player, GeneralRegion> regionParser =
ParserDescriptor<PlayerCommandSource, GeneralRegion> regionParser =
ParserDescriptor.of(new GeneralRegionParser<>(fileManager, this::suggestRegions), GeneralRegion.class);
this.messageBridge = messageBridge;
this.fileManager = fileManager;
this.regionFlag = CommandFlag.builder("region")
this.regionFlag = CommandFlag.<PlayerCommandSource>builder("region")
.withComponent(regionParser)
.build();
}
@Override
public String getHelpKey(CommandSender target) {
public String getHelpKey(@NotNull CommandSender target) {
if (!target.hasPermission("areashop.transfer")) {
return null;
}
@@ -65,11 +67,10 @@ public class TransferCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("transfer")
.senderType(Player.class)
.senderType(PlayerCommandSource.class)
.required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser())
.flag(this.regionFlag)
.handler(this::handleCommand);
@@ -80,12 +81,12 @@ public class TransferCommand extends AreashopCommandBean {
return CommandProperties.of("transfer");
}
private void handleCommand(@Nonnull CommandContext<Player> context) {
Player sender = context.sender();
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
Player sender = context.sender().sender();
if (!sender.hasPermission("areashop.transfer")) {
throw new AreaShopCommandException("transfer-noPermission");
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag);
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
if (!region.isTransferEnabled()) {
throw new AreaShopCommandException("transfer-disabled");
}
@@ -124,11 +125,11 @@ public class TransferCommand extends AreashopCommandBean {
}
private CompletableFuture<Iterable<Suggestion>> suggestRegions(
@Nonnull CommandContext<Player> context,
@Nonnull CommandContext<PlayerCommandSource> context,
@Nonnull CommandInput input
) {
String text = input.peekString();
UUID uuid = context.sender().getUniqueId();
UUID uuid = context.sender().sender().getUniqueId();
List<Suggestion> suggestions = this.fileManager.getRegions()
.stream()
.filter(region -> region.isOwner(uuid) || region.isLandlord(uuid))
@@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException;
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
import me.wiefferink.areashop.commands.util.RegionParseUtil;
import me.wiefferink.areashop.commands.util.RentRegionParser;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RentRegion;
@@ -32,10 +33,10 @@ public class UnrentCommand extends AreashopCommandBean {
@Inject
public UnrentCommand(@Nonnull IFileManager fileManager) {
ParserDescriptor<CommandSender, RentRegion> regionParser =
ParserDescriptor<CommandSource<?>, RentRegion> regionParser =
ParserDescriptor.of(new RentRegionParser<>(fileManager, this::suggestRegions), RentRegion.class);
this.fileManager = fileManager;
this.regionFlag = CommandFlag.builder("region")
this.regionFlag = CommandFlag.<CommandSource<?>>builder("region")
.withComponent(regionParser)
.build();
}
@@ -70,9 +71,8 @@ public class UnrentCommand extends AreashopCommandBean {
return null;
}
@NotNull
@Override
protected Command.Builder<? extends CommandSender> configureCommand(@NotNull Command.Builder<CommandSender> builder) {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("unrent")
.flag(this.regionFlag)
.handler(this::handleCommand);
@@ -83,12 +83,12 @@ public class UnrentCommand extends AreashopCommandBean {
return CommandProperties.of("unrent");
}
private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
CommandSender sender = context.sender();
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.unrent") && !sender.hasPermission("areashop.unrentown")) {
throw new AreaShopCommandException("unrent-noPermission");
}
RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, this.regionFlag);
RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, sender, this.regionFlag);
if (!rent.isRented()) {
throw new AreaShopCommandException("unrent-notRented", rent);
}
@@ -97,7 +97,7 @@ public class UnrentCommand extends AreashopCommandBean {
@Nonnull
private CompletableFuture<Iterable<Suggestion>> suggestRegions(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<CommandSource<?>> context,
@Nonnull CommandInput input
) {
String text = input.peekString();
@@ -1,6 +1,6 @@
package me.wiefferink.areashop.commands.util;
import org.bukkit.command.CommandSender;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandBean;
import org.incendo.cloud.key.CloudKey;
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
* An extension of {@link CommandBean} which does extra pre-processing of the commands.
* Adapted from <a href="https://github.com/Incendo/kitchensink">KitchenSink</a>
*/
public abstract class AreashopCommandBean extends CommandBean<CommandSender> implements HelpProvider {
public abstract class AreashopCommandBean extends CommandBean<CommandSource<?>> implements HelpProvider {
private boolean requireConfirmation;
@@ -21,8 +21,8 @@ public abstract class AreashopCommandBean extends CommandBean<CommandSender> imp
}
@Override
protected final @Nonnull Command.Builder<? extends CommandSender> configure(
final @Nonnull Command.Builder<CommandSender> builder
protected final @Nonnull Command.Builder<? extends CommandSource<?>> configure(
final @Nonnull Command.Builder<CommandSource<?>> builder
) {
return this.configureCommand(builder)
.meta(CloudKey.of("bukkit_description", String.class), this.stringDescription())
@@ -44,7 +44,7 @@ public abstract class AreashopCommandBean extends CommandBean<CommandSender> imp
* @param builder builder to configure
* @return the updated builder
*/
protected abstract @Nonnull Command.Builder<? extends CommandSender> configureCommand(
@Nonnull Command.Builder<CommandSender> builder
protected abstract @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(
@Nonnull Command.Builder<CommandSource<?>> builder
);
}
@@ -46,10 +46,10 @@ import me.wiefferink.areashop.commands.TeleportCommand;
import me.wiefferink.areashop.commands.ToggleHomeCommand;
import me.wiefferink.areashop.commands.TransferCommand;
import me.wiefferink.areashop.commands.UnrentCommand;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.CommandSourceMapper;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.incendo.cloud.SenderMapper;
import org.incendo.cloud.bukkit.CloudBukkitCapabilities;
import org.incendo.cloud.exception.ArgumentParseException;
import org.incendo.cloud.exception.CommandExecutionException;
import org.incendo.cloud.exception.InvalidCommandSenderException;
@@ -115,7 +115,7 @@ public class AreashopCommands {
private final MessageBridge messageBridge;
private final Injector injector;
private final PaperCommandManager<CommandSender> commandManager;
private final PaperCommandManager<CommandSource<?>> commandManager;
private final List<AreashopCommandBean> commands = new ArrayList<>();
private HelpRenderer helpRenderer;
@@ -123,11 +123,9 @@ public class AreashopCommands {
@Inject
AreashopCommands(@Nonnull Injector injector, @Nonnull Plugin plugin, @Nonnull MessageBridge messageBridge) {
this.injector = injector;
this.commandManager = new PaperCommandManager<>(
plugin,
ExecutionCoordinator.simpleCoordinator(),
SenderMapper.identity()
);
this.commandManager = PaperCommandManager.builder(new CommandSourceMapper())
.executionCoordinator(ExecutionCoordinator.simpleCoordinator())
.buildOnEnable(plugin);
this.messageBridge = messageBridge;
}
@@ -142,15 +140,12 @@ public class AreashopCommands {
this.commandManager.command(configuredBuilder);
}
// Show help by default
this.commandManager.command(builder.handler(context -> showHelp(context.sender())));
this.commandManager.command(builder.handler(context -> showHelp(context.sender().sender())));
this.helpRenderer = new HelpRenderer(this.messageBridge, this.commands);
}
private void initCommandManager() {
if (this.commandManager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
this.commandManager.registerBrigadier();
}
ExceptionController<CommandSender> exceptionController = this.commandManager.exceptionController();
ExceptionController<CommandSource<?>> exceptionController = this.commandManager.exceptionController();
// We need to unwrap ArgumentParseException because they wrap the custom exception messages
exceptionController.registerHandler(ArgumentParseException.class,
ExceptionHandler.unwrappingHandler(AreaShopCommandException.class));
@@ -160,7 +155,7 @@ public class AreashopCommands {
new InvalidCommandSenderHandler(this.messageBridge));
exceptionController.registerHandler(AreaShopCommandException.class,
new ArgumentParseExceptionHandler<>(this.messageBridge));
var confirmationConfiguration = ConfirmationConfiguration.<CommandSender>builder()
var confirmationConfiguration = ConfirmationConfiguration.<CommandSource<?>>builder()
.cache(GuavaCache.of(CacheBuilder.newBuilder().build()))
.noPendingCommandNotifier(x -> {
})
@@ -1,13 +1,13 @@
package me.wiefferink.areashop.commands.util;
import me.wiefferink.areashop.MessageBridge;
import org.bukkit.command.CommandSender;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import org.incendo.cloud.exception.handling.ExceptionContext;
import org.incendo.cloud.exception.handling.ExceptionHandler;
import javax.annotation.Nonnull;
public class ArgumentParseExceptionHandler<C extends CommandSender> implements ExceptionHandler<C, AreaShopCommandException> {
public class ArgumentParseExceptionHandler<C extends CommandSource<?>> implements ExceptionHandler<C, AreaShopCommandException> {
private final MessageBridge messageBridge;
@@ -17,17 +17,17 @@ public class ArgumentParseExceptionHandler<C extends CommandSender> implements E
public static void handleException(
@Nonnull MessageBridge messageBridge,
@Nonnull CommandSender sender,
@Nonnull CommandSource<?> sender,
@Nonnull AreaShopCommandException exception
) {
String key = exception.messageKey();
Object[] replacements = exception.replacements();
if (replacements.length == 0) {
messageBridge.message(sender, key);
messageBridge.message(sender.sender(), key);
return;
}
// Pass the values as a var-args and not as a string[]
messageBridge.message(sender, key, replacements);
messageBridge.message(sender.sender(), key, replacements);
}
@Override
@@ -1,8 +1,8 @@
package me.wiefferink.areashop.commands.util;
import me.wiefferink.areashop.MessageBridge;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.exception.InvalidCommandSenderException;
import org.incendo.cloud.exception.handling.ExceptionContext;
@@ -10,7 +10,7 @@ import org.incendo.cloud.exception.handling.ExceptionHandler;
import javax.annotation.Nonnull;
public class InvalidCommandSenderHandler implements ExceptionHandler<CommandSender, InvalidCommandSenderException> {
public class InvalidCommandSenderHandler implements ExceptionHandler<CommandSource<?>, InvalidCommandSenderException> {
private final MessageBridge messageBridge;
@@ -19,9 +19,9 @@ public class InvalidCommandSenderHandler implements ExceptionHandler<CommandSend
}
@Override
public void handle(@NonNull ExceptionContext<CommandSender, InvalidCommandSenderException> context) throws Throwable {
public void handle(@NonNull ExceptionContext<CommandSource<?>, InvalidCommandSenderException> context) throws Throwable {
InvalidCommandSenderException exception = context.exception();
if (exception.requiredSender().equals(Player.class)) {
if (exception.requiredSenderTypes().contains(PlayerCommandSource.class)) {
this.messageBridge.message(exception.commandSender(), "cmd-onlyByPlayer");
return;
}
@@ -38,16 +38,16 @@ public class RegionCreationUtil {
}
public CompletableFuture<ProtectedRegion> createRegion(
@Nonnull CommandContext<Player> context,
@Nonnull CommandContext<?> context,
@Nonnull Player sender,
@Nonnull CloudKey<String> regionKey
) {
Player player = context.sender();
World world = player.getWorld();
World world = sender.getWorld();
String regionName = context.get(regionKey);
if (this.fileManager.getRegion(regionName) != null) {
return CompletableFuture.failedFuture(new AreaShopCommandException("add-failed", regionName));
}
this.server.dispatchCommand(player, String.format("rg define %s", regionName));
this.server.dispatchCommand(sender, String.format("rg define %s", regionName));
CompletableFuture<ProtectedRegion> future = new CompletableFuture<>();
this.server.getScheduler().runTaskLater(this.plugin, () -> {
ProtectedRegion region = this.worldGuardInterface.getRegionManager(world).getRegion(regionName);
@@ -33,10 +33,10 @@ public final class RegionParseUtil {
@Nonnull
public static Collection<GeneralRegion> getOrParseRegionsInSel(
@Nonnull CommandContext<CommandSender> context,
@Nonnull CommandContext<?> context,
@Nonnull CommandSender sender,
@Nonnull CommandFlag<GeneralRegion> regionFlag
) {
CommandSender sender = context.sender();
if (!(sender instanceof Player player)) {
throw new AreaShopCommandException("cmd-weOnlyByPlayer");
}
@@ -54,15 +54,15 @@ public final class RegionParseUtil {
}
@Nonnull
public static <C> GeneralRegion getOrParseRegion(
@Nonnull CommandContext<C> context,
public static GeneralRegion getOrParseRegion(
@Nonnull CommandContext<?> context,
@Nonnull CommandSender sender,
@Nonnull CommandFlag<GeneralRegion> flag
) throws AreaShopCommandException {
GeneralRegion region = context.flags().get(flag);
if (region != null) {
return region;
}
C sender = context.sender();
if (!(sender instanceof Entity entity)) {
throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer");
}
@@ -74,21 +74,21 @@ public final class RegionParseUtil {
} else if (regions.size() > 1) {
errorMessageKey = "cmd-moreRegionsAtLocation";
} else {
return regions.get(0);
return regions.getFirst();
}
throw new AreaShopCommandException(errorMessageKey);
}
@Nonnull
public static <C> GeneralRegion getOrParseRegion(
@Nonnull CommandContext<C> context,
public static GeneralRegion getOrParseRegion(
@Nonnull CommandContext<?> context,
@Nonnull CommandSender sender,
@Nonnull CloudKey<GeneralRegion> key
) throws AreaShopCommandException {
GeneralRegion region = context.getOrDefault(key, null);
if (region != null) {
return region;
}
C sender = context.sender();
if (!(sender instanceof Entity entity)) {
throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer");
}
@@ -100,7 +100,7 @@ public final class RegionParseUtil {
} else if (regions.size() > 1) {
errorMessageKey = "cmd-moreRegionsAtLocation";
} else {
return regions.get(0);
return regions.getFirst();
}
throw new AreaShopCommandException(errorMessageKey);
}
@@ -121,12 +121,14 @@ public final class RegionParseUtil {
}
@Nonnull
public static BuyRegion getOrParseBuyRegion(@Nonnull CommandContext<? extends CommandSender> context, CommandFlag<BuyRegion> flag) {
public static BuyRegion getOrParseBuyRegion(
@Nonnull CommandContext<?> context,
@Nonnull CommandSender sender,
@Nonnull CommandFlag<BuyRegion> flag) {
BuyRegion buyRegion = context.flags().get(flag);
if (buyRegion != null) {
return buyRegion;
}
CommandSender sender = context.sender();
if (!(sender instanceof Player player)) {
throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer");
}
@@ -136,16 +138,18 @@ public final class RegionParseUtil {
} else if (regions.size() != 1) {
throw new AreaShopCommandException("cmd-moreRegionsAtLocation");
}
return regions.get(0);
return regions.getFirst();
}
@Nonnull
public static RentRegion getOrParseRentRegion(@Nonnull CommandContext<? extends CommandSender> context, CommandFlag<RentRegion> flag) {
public static RentRegion getOrParseRentRegion(
@Nonnull CommandContext<?> context,
@Nonnull CommandSender sender,
@Nonnull CommandFlag<RentRegion> flag) {
RentRegion rentRegion = context.flags().get(flag);
if (rentRegion != null) {
return rentRegion;
}
CommandSender sender = context.sender();
if (!(sender instanceof Player player)) {
throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer");
}
@@ -155,7 +159,7 @@ public final class RegionParseUtil {
} else if (regions.size() != 1) {
throw new AreaShopCommandException("cmd-moreRegionsAtLocation");
}
return regions.get(0);
return regions.getFirst();
}
}
@@ -1,6 +1,5 @@
package me.wiefferink.areashop.commands.util;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.Plugin;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -45,14 +44,14 @@ public final class SignProfileUtil {
}
@Nullable
public static String getOrParseProfile(@Nonnull CommandContext<? extends CommandSender> context,
public static String getOrParseProfile(@Nonnull CommandContext<?> context,
@Nonnull Plugin plugin) {
return getOrParseProfile(context, DEFAULT_FLAG, plugin);
}
@Nullable
public static String getOrParseProfile(
@Nonnull CommandContext<? extends CommandSender> context,
@Nonnull CommandContext<?> context,
@Nonnull CommandFlag<String> flag,
@Nonnull Plugin plugin
) throws AreaShopCommandException {
@@ -13,6 +13,8 @@ import org.incendo.cloud.parser.ArgumentParser;
import org.incendo.cloud.parser.ParserDescriptor;
import org.incendo.cloud.suggestion.BlockingSuggestionProvider;
import java.util.Collections;
public class ValidatedOfflinePlayerParser<C> implements ArgumentParser<C, OfflinePlayer>, BlockingSuggestionProvider.Strings<C> {
public static <C> ParserDescriptor<C, OfflinePlayer> validatedOfflinePlayerParser() {
@@ -50,6 +52,9 @@ public class ValidatedOfflinePlayerParser<C> implements ArgumentParser<C, Offlin
final @NonNull CommandContext<C> commandContext,
final @NonNull CommandInput input
) {
if (!commandContext.contains(BukkitCommandContextKeys.BUKKIT_COMMAND_SENDER)) {
return Collections.emptyList();
}
final CommandSender sender = commandContext.get(BukkitCommandContextKeys.BUKKIT_COMMAND_SENDER);
return Bukkit.getOnlinePlayers().stream()
.filter(onlinePlayer -> !(sender instanceof Player player && !((Player) sender).canSee(player)))
@@ -19,20 +19,21 @@ public final class WorldFlagUtil {
}
@Nonnull
public static <C extends Entity> World parseOrDetectWorld(@Nonnull CommandContext<C> context) {
return parseOrDetectWorld(context, DEFAULT_WORLD_FLAG);
public static World parseOrDetectWorld(@Nonnull CommandContext<?> context, @Nonnull Entity sender) {
return parseOrDetectWorld(context, sender, DEFAULT_WORLD_FLAG);
}
@Nonnull
public static <C extends Entity> World parseOrDetectWorld(
@Nonnull CommandContext<C> context,
public static World parseOrDetectWorld(
@Nonnull CommandContext<?> context,
@Nonnull Entity sender,
@Nonnull CommandFlag<World> flag
) {
World world = context.flags().get(flag);
if (world != null) {
return world;
}
return context.sender().getWorld();
return sender.getWorld();
}
}
@@ -2,6 +2,7 @@ package me.wiefferink.areashop.commands.util;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.commands.util.commandsource.EntityCommandSource;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import org.bukkit.World;
import org.bukkit.entity.Entity;
@@ -17,7 +18,7 @@ import org.incendo.cloud.suggestion.SuggestionProvider;
import javax.annotation.Nonnull;
import java.util.Collections;
public class WorldGuardRegionParser<C extends Entity> implements ArgumentParser<C, ProtectedRegion> {
public class WorldGuardRegionParser<C extends EntityCommandSource> implements ArgumentParser<C, ProtectedRegion> {
private final WorldGuardInterface worldGuardInterface;
private final CommandFlag<World> worldFlag;
@@ -29,7 +30,7 @@ public class WorldGuardRegionParser<C extends Entity> implements ArgumentParser<
this.worldGuardInterface = worldGuardInterface;
}
public static <C extends Entity> ParserDescriptor<C, ProtectedRegion> worldGuardRegionParser(
public static <C extends EntityCommandSource> ParserDescriptor<C, ProtectedRegion> worldGuardRegionParser(
@Nonnull CommandFlag<World> worldFlag,
@Nonnull WorldGuardInterface worldGuardInterface
) {
@@ -39,7 +40,8 @@ public class WorldGuardRegionParser<C extends Entity> implements ArgumentParser<
@Override
public @Nonnull ArgumentParseResult<ProtectedRegion> parse(@Nonnull CommandContext<C> commandContext,
@Nonnull CommandInput commandInput) {
World world = WorldFlagUtil.parseOrDetectWorld(commandContext, worldFlag);
Entity sender = commandContext.sender().sender();
World world = WorldFlagUtil.parseOrDetectWorld(commandContext, sender, worldFlag);
String regionName = commandInput.peekString();
RegionManager regionManager = this.worldGuardInterface.getRegionManager(world);
if (regionManager == null) {
@@ -57,7 +59,7 @@ public class WorldGuardRegionParser<C extends Entity> implements ArgumentParser<
@Override
public @Nonnull SuggestionProvider<C> suggestionProvider() {
return SuggestionProvider.blockingStrings((commandContext, input) -> {
C sender = commandContext.sender();
Entity sender = commandContext.sender().sender();
if (!(sender instanceof Player player)) {
return Collections.emptyList();
}
@@ -0,0 +1,16 @@
package me.wiefferink.areashop.commands.util.commandsource;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.command.CommandSender;
import javax.annotation.Nonnull;
public interface CommandSource<C extends CommandSender> {
@Nonnull
CommandSourceStack sourceStack();
@Nonnull
C sender();
}
@@ -0,0 +1,27 @@
package me.wiefferink.areashop.commands.util.commandsource;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.SenderMapper;
public class CommandSourceMapper implements SenderMapper<CommandSourceStack, CommandSource<?>> {
@Override
public @NonNull CommandSource<?> map(@NonNull CommandSourceStack base) {
CommandSender sender = base.getSender();
if (sender instanceof Player) {
return new PlayerCommandSource(base);
} else if (sender instanceof Entity) {
return new EntityCommandSource(base);
}
return new GenericCommandSource(base);
}
@Override
public @NonNull CommandSourceStack reverse(@NonNull CommandSource<?> mapped) {
return mapped.sourceStack();
}
}
@@ -0,0 +1,15 @@
package me.wiefferink.areashop.commands.util.commandsource;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.command.CommandSender;
import javax.annotation.Nonnull;
public record CommandSourceWrapper(@Nonnull CommandSourceStack commandSourceStack) {
@Nonnull
public CommandSender sender() {
return commandSourceStack().getSender();
}
}
@@ -0,0 +1,23 @@
package me.wiefferink.areashop.commands.util.commandsource;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
public sealed class EntityCommandSource extends GenericCommandSource permits PlayerCommandSource {
public EntityCommandSource(@Nonnull CommandSourceStack sourceStack) {
super(sourceStack);
if (!(sourceStack.getSender() instanceof Entity)) {
throw new IllegalArgumentException("Source stack sender is not an entity!");
}
}
@NotNull
@Override
public Entity sender() {
return (Entity) super.sender();
}
}
@@ -0,0 +1,31 @@
package me.wiefferink.areashop.commands.util.commandsource;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
public class GenericCommandSource implements CommandSource<CommandSender> {
private final CommandSourceStack sourceStack;
private final CommandSender sender;
public GenericCommandSource(@Nonnull CommandSourceStack sourceStack) {
this.sourceStack = sourceStack;
this.sender = sourceStack.getSender();
}
@NotNull
@Override
public final CommandSourceStack sourceStack() {
return this.sourceStack;
}
@NotNull
@Override
public CommandSender sender() {
return this.sender;
}
}
@@ -0,0 +1,22 @@
package me.wiefferink.areashop.commands.util.commandsource;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
public final class PlayerCommandSource extends EntityCommandSource {
public PlayerCommandSource(@Nonnull CommandSourceStack sourceStack) {
super(sourceStack);
if (!(sourceStack.getSender() instanceof Player)) {
throw new IllegalArgumentException("Source stack sender is not a player!");
}
}
@Override
public @NotNull Player sender() {
return (Player) super.sender();
}
}
@@ -103,7 +103,7 @@ public class FriendsFeature extends RegionFeature {
HashSet<String> result = new HashSet<>();
for(UUID friend : getFriends()) {
OfflinePlayer player = Bukkit.getOfflinePlayer(friend);
if(player != null && player.getName() != null) {
if(player.getName() != null) {
result.add(player.getName());
}
}
@@ -133,7 +133,7 @@ public class WorldGuardRegionFlagsFeature extends RegionFeature {
}
} else {
// Parse all other normal flags (groups are also handled)
String flagSetting = null;
StringBuilder flagSetting = null;
com.sk89q.worldguard.protection.flags.RegionGroup groupValue = null;
Flag<?> foundFlag = worldGuardInterface.fuzzyMatchFlag(flagName);
@@ -152,7 +152,7 @@ public class WorldGuardRegionFlagsFeature extends RegionFeature {
//AreaShop.debug(" Flag " + flagName + " reset (+ possible group of flag)");
} else {
if(groupFlag == null) {
flagSetting = value;
flagSetting = new StringBuilder(value);
} else {
for(String part : value.split(" ")) {
if(part.startsWith("g:")) {
@@ -165,16 +165,16 @@ public class WorldGuardRegionFlagsFeature extends RegionFeature {
}
} else {
if(flagSetting == null) {
flagSetting = part;
flagSetting = new StringBuilder(part);
} else {
flagSetting += " " + part;
flagSetting.append(" ").append(part);
}
}
}
}
if(flagSetting != null) {
try {
setFlag(worldguardRegion, foundFlag, flagSetting);
setFlag(worldguardRegion, foundFlag, flagSetting.toString());
//AreaShop.debug(" Flag " + flagName + " set: " + flagSetting);
} catch(InvalidFlagFormat e) {
AreaShop.warn("Found wrong value for flag " + flagName);
@@ -7,7 +7,6 @@ import io.github.bakedlibs.dough.blocks.BlockPosition;
import io.papermc.lib.PaperLib;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.managers.SignErrorLogger;
import me.wiefferink.areashop.platform.adapter.BlockBehaviourHelper;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.Materials;
import me.wiefferink.areashop.tools.SignUtils;
@@ -16,6 +15,7 @@ import me.wiefferink.interactivemessenger.processing.Message;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
@@ -35,8 +35,8 @@ import java.util.List;
*/
public class RegionSign {
private final BlockBehaviourHelper blockHelper;
private final SignErrorLogger errorLogger;
private final Server server;
private final SignsFeature signsFeature;
private final String key;
@@ -44,13 +44,13 @@ public class RegionSign {
@AssistedInject
RegionSign(
@Nonnull BlockBehaviourHelper blockBehaviourHelper,
@Nonnull SignErrorLogger signErrorLogger,
@Nonnull Server server,
@Assisted @Nonnull SignsFeature signsFeature,
@Assisted @Nonnull String key
) {
this.blockHelper = blockBehaviourHelper;
this.errorLogger = signErrorLogger;
this.server = server;
this.signsFeature = signsFeature;
this.key = key;
}
@@ -176,7 +176,7 @@ public class RegionSign {
// Place the sign back (with proper rotation and type) after it has been hidden or (indirectly) destroyed
if(!Materials.isSign(block.getType())) {
Material signType = getMaterial();
if (!blockHelper.canPlace(block.getLocation(), Bukkit.createBlockData(signType))) {
if (!block.canPlace(this.server.createBlockData(signType))) {
errorLogger.submitWarning("Setting sign" + key + "of region" + getRegion().getName() + "failed, could not set sign block back");
this.remove();
return false;
@@ -278,7 +278,7 @@ public class RegionSign {
for(String command : stateConfig.getStringList(clickType.getValue() + "Console")) {
consoleCommands.add(command.replace(Message.VARIABLE_START + AreaShop.tagClicker + Message.VARIABLE_END, clicker.getName()));
}
getRegion().runCommands(Bukkit.getConsoleSender(), consoleCommands);
getRegion().runCommands(this.server.getConsoleSender(), consoleCommands);
return !playerCommands.isEmpty() || !consoleCommands.isEmpty();
}
@@ -10,7 +10,6 @@ import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.managers.SignLinkerManager;
import me.wiefferink.areashop.platform.adapter.BlockBehaviourHelper;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RegionFactory;
@@ -42,7 +41,6 @@ import java.util.Set;
public class SignListener implements Listener {
private final BlockBehaviourHelper behaviourHelper;
private final AreaShop plugin;
private final MessageBridge messageBridge;
private final SignManager signManager;
@@ -53,7 +51,6 @@ public class SignListener implements Listener {
public SignListener(
@Nonnull AreaShop plugin,
@Nonnull BlockBehaviourHelper behaviourHelper,
@Nonnull RegionFactory regionFactory,
@Nonnull MessageBridge messageBridge,
@Nonnull SignLinkerManager signLinkerManager,
@@ -64,7 +61,6 @@ public class SignListener implements Listener {
this.signManager = signManager;
this.signLinkerManager = signLinkerManager;
this.regionFactory = regionFactory;
this.behaviourHelper = behaviourHelper;
this.plugin = plugin;
this.worldGuardInterface = worldGuardInterface;
this.messageBridge = messageBridge;
@@ -96,8 +92,9 @@ public class SignListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onIndirectSignBreak(BlockPhysicsEvent event) {
Block block = event.getBlock();
// Check if the block is a sign
if(!Materials.isSign(event.getBlock().getType()) || behaviourHelper.isBlockValid(event.getBlock())) {
if(!Materials.isSign(block.getType()) || block.canPlace(block.getBlockData())) {
return;
}
@@ -152,24 +149,13 @@ public class SignListener implements Listener {
if (!(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK)) {
return;
}
// Only care about clicking blocks
if(!Materials.isSign(block.getType())) {
Optional<RegionSign> optionalRegionSign = getRegionSign(block, event.getPlayer());
if (optionalRegionSign.isEmpty()) {
return;
}
RegionSign regionSign = optionalRegionSign.get();
// Check if this sign belongs to a region
Optional<RegionSign> optional = signManager.signFromLocation(block.getLocation());
if(optional.isEmpty()) {
return;
}
RegionSign regionSign = optional.get();
// Ignore players that are in sign link mode (which will handle the event itself)
Player player = event.getPlayer();
if(signLinkerManager.isInSignLinkMode(player)) {
return;
}
// Get the clicktype
GeneralRegion.ClickType clickType = null;
@@ -189,6 +175,21 @@ public class SignListener implements Listener {
event.setCancelled(ran);
}
private Optional<RegionSign> getRegionSign(@Nonnull Block block, @Nonnull Player player) {
// Only care about clicking blocks
if(!Materials.isSign(block.getType())) {
return Optional.empty();
}
// Ignore players that are in sign link mode (which will handle the event itself)
if(signLinkerManager.isInSignLinkMode(player)) {
return Optional.empty();
}
// Check if this sign belongs to a region
return signManager.signFromLocation(block.getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
@@ -9,7 +9,6 @@ import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.managers.SignLinkerManager;
import me.wiefferink.areashop.platform.adapter.BlockBehaviourHelper;
import me.wiefferink.areashop.regions.RegionFactory;
import javax.annotation.Nonnull;
@@ -25,7 +24,6 @@ public class SignsModule extends AbstractModule {
@Provides
@Singleton
public SignListener provideSignListener(@Nonnull AreaShop plugin,
@Nonnull BlockBehaviourHelper behaviourHelper,
@Nonnull RegionFactory regionFactory,
@Nonnull MessageBridge messageBridge,
@Nonnull SignLinkerManager signLinkerManager,
@@ -35,7 +33,6 @@ public class SignsModule extends AbstractModule {
) {
final SignListener signListener = new SignListener(
plugin,
behaviourHelper,
regionFactory,
messageBridge,
signLinkerManager,
@@ -1052,8 +1052,8 @@ public class FileManager extends Manager implements IFileManager {
boolean noWorldRegions = !noWorld.isEmpty();
while(!noWorld.isEmpty()) {
List<GeneralRegion> toDisplay = new ArrayList<>();
String missingWorld = noWorld.get(0).getWorldName();
toDisplay.add(noWorld.get(0));
String missingWorld = noWorld.getFirst().getWorldName();
toDisplay.add(noWorld.getFirst());
for(int i = 1; i < noWorld.size(); i++) {
if(noWorld.get(i).getWorldName().equalsIgnoreCase(missingWorld)) {
toDisplay.add(noWorld.get(i));
@@ -379,7 +379,7 @@ public interface IFileManager {
void setGroupSetting(RegionGroup group, String path, Object setting);
// Enum for region types
public enum AddResult {
enum AddResult {
BLACKLISTED("blacklisted"),
NOPERMISSION("nopermission"),
ALREADYADDED("alreadyadded"),
@@ -111,7 +111,7 @@ public class SignLinkerManager extends Manager implements Listener {
Block next = blockIterator.next();
List<GeneralRegion> regions = Utils.getRegions(next.getLocation());
if(regions.size() == 1) {
linker.setRegion(regions.get(0));
linker.setRegion(regions.getFirst());
return;
} else if(regions.size() > 1) {
Set<String> names = new HashSet<>();
@@ -16,7 +16,6 @@ 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.platform.adapter.PlatformAdapter;
import me.wiefferink.areashop.regions.ImportJobFactory;
import me.wiefferink.areashop.regions.RegionModule;
import me.wiefferink.areashop.services.ServiceManager;
@@ -32,7 +31,6 @@ public class AreaShopModule extends AbstractModule {
private final AreaShop instance;
private final WorldGuardInterface worldGuardInterface;
private final WorldEditInterface worldEditInterface;
private final PlatformAdapter platformAdapter;
private final MessageBridge messageBridge;
private final SignErrorLogger signErrorLogger;
private final AbstractModule[] extras;
@@ -41,7 +39,6 @@ public class AreaShopModule extends AbstractModule {
public AreaShopModule(@Nonnull AreaShop instance,
@Nonnull MessageBridge messageBridge,
@Nonnull PlatformAdapter platformAdapter,
@Nonnull WorldEditInterface worldEditInterface,
@Nonnull WorldGuardInterface worldGuardInterface,
@Nonnull SignErrorLogger signErrorLogger,
@@ -50,7 +47,6 @@ public class AreaShopModule extends AbstractModule {
) {
this.instance = instance;
this.messageBridge = messageBridge;
this.platformAdapter = platformAdapter;
this.signErrorLogger = signErrorLogger;
this.worldEditInterface = worldEditInterface;
this.worldGuardInterface = worldGuardInterface;
@@ -3,27 +3,20 @@ 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.platform.adapter.BlockBehaviourHelper;
import me.wiefferink.areashop.platform.adapter.PlatformAdapter;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import org.jetbrains.annotations.NotNull;
public class PlatformModule extends AbstractModule {
private final MinecraftPlatform minecraftPlatform;
private final PlatformAdapter platformAdapter;
public PlatformModule(@NotNull MinecraftPlatform platform,
@NotNull PlatformAdapter platformAdapter) {
public PlatformModule(@NotNull MinecraftPlatform platform) {
this.minecraftPlatform = platform;
this.platformAdapter = platformAdapter;
}
@Override
protected void configure() {
bind(MinecraftPlatform.class).toInstance(this.minecraftPlatform);
bind(OfflinePlayerHelper.class).toInstance(this.minecraftPlatform.offlinePlayerHelper());
bind(PlatformAdapter.class).toInstance(this.platformAdapter);
bind(BlockBehaviourHelper.class).toInstance(this.platformAdapter.blockBehaviourHelper());
bind(BukkitSchedulerExecutor.class).asEagerSingleton();
}
}
@@ -147,7 +147,7 @@ public class BuyRegion extends GeneralRegion {
*/
public String getPlayerName() {
String result = Utils.toName(getBuyer());
if(result == null || result.isEmpty()) {
if(result.isEmpty()) {
result = getStringSetting("buy.buyerName");
if(result == null || result.isEmpty()) {
result = "<UNKNOWN>";
@@ -402,7 +402,7 @@ public class BuyRegion extends GeneralRegion {
r = null;
OfflinePlayer oldOwnerPlayer = Bukkit.getOfflinePlayer(oldOwner);
String oldOwnerName = getPlayerName();
if(oldOwnerPlayer != null && oldOwnerPlayer.getName() != null) {
if(oldOwnerPlayer.getName() != null) {
r = economy.depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice());
oldOwnerName = oldOwnerPlayer.getName();
} else if(oldOwnerName != null) {
@@ -1307,7 +1307,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
// Check all limitgroups the player has
List<String> groups = new ArrayList<>(plugin.getConfig().getConfigurationSection("limitGroups").getKeys(false));
while(!groups.isEmpty()) {
String group = groups.get(0);
String group = groups.getFirst();
if(plugin.hasPermission(offlinePlayer, "areashop.limits." + group) && this.matchesLimitGroup(group)) {
String pathPrefix = "limitGroups." + group + ".";
if(!plugin.getConfig().isInt(pathPrefix + "total")) {
@@ -1386,7 +1386,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
/**
* Class to store the result of a limits check.
*/
public class LimitResult {
public static class LimitResult {
private final boolean actionAllowed;
private final LimitType limitingFactor;
private final int maximum;
@@ -1464,12 +1464,12 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
private boolean limitGroupsOfSameCategory(String firstGroup, String secondGroup) {
List<String> firstGroups = plugin.getConfig().getStringList("limitGroups." + firstGroup + ".groups");
List<String> secondGroups = plugin.getConfig().getStringList("limitGroups." + secondGroup + ".groups");
if(!firstGroups.containsAll(secondGroups) || !secondGroups.containsAll(firstGroups)) {
if(!new HashSet<>(firstGroups).containsAll(secondGroups) || !new HashSet<>(secondGroups).containsAll(firstGroups)) {
return false;
}
List<String> firstWorlds = plugin.getConfig().getStringList("limitGroups." + firstGroup + ".worlds");
List<String> secondWorlds = plugin.getConfig().getStringList("limitGroups." + secondGroup + ".worlds");
return !(!firstWorlds.containsAll(secondWorlds) || !secondWorlds.containsAll(firstWorlds));
return !(!new HashSet<>(firstWorlds).containsAll(secondWorlds) || !new HashSet<>(secondWorlds).containsAll(firstWorlds));
}
/**
@@ -1675,8 +1675,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
x1 = points.get(numPoints - 1).getBlockX();
z1 = points.get(numPoints - 1).getBlockZ();
x2 = points.get(0).getBlockX();
z2 = points.get(0).getBlockZ();
x2 = points.getFirst().getBlockX();
z2 = points.getFirst().getBlockZ();
area += ((z1 + z2) * (x1 - x2));
area = Math.ceil(Math.abs(area) / 2);
@@ -296,7 +296,7 @@ public class ImportJob {
// First owner (or if none, the first member) will be the renter/buyer
if(!existing.isEmpty()) {
region.setOwner(existing.remove(0));
region.setOwner(existing.removeFirst());
}
// Add others as friends
for(UUID friend : existing) {
@@ -15,8 +15,7 @@ import java.util.Set;
// TODO consider switching to saving lowercase regions
public class RegionGroup {
private final Plugin plugin;
private final IFileManager fileManager;
private final IFileManager fileManager;
private final String name;
private final Set<String> regions;
private Set<String> autoRegions;
@@ -30,8 +29,7 @@ public class RegionGroup {
*/
@AssistedInject
RegionGroup(@Nonnull Plugin plugin, @Nonnull IFileManager fileManager, @Assisted String name) {
this.plugin = plugin;
this.fileManager = fileManager;
this.fileManager = fileManager;
this.name = name;
this.autoDirty = true;
setSetting("name", name);
@@ -230,7 +230,7 @@ public class RentRegion extends GeneralRegion {
*/
public String getPlayerName() {
String result = Utils.toName(getRenter());
if(result == null || result.isEmpty()) {
if(result.isEmpty()) {
result = config.getString("rent.renterName");
if(result == null || result.isEmpty()) {
result = "<UNKNOWN>";
@@ -252,11 +252,7 @@ public class RentRegion extends GeneralRegion {
* @param rentedUntil The time until the region is rented
*/
public void setRentedUntil(Long rentedUntil) {
if(rentedUntil == null) {
setSetting("rent.rentedUntil", null);
} else {
setSetting("rent.rentedUntil", rentedUntil);
}
setSetting("rent.rentedUntil", rentedUntil);
}
/**
@@ -420,7 +416,7 @@ public class RentRegion extends GeneralRegion {
// Check if a warning needs to be send for each defined point in time
Player player = Bukkit.getPlayer(getRenter());
long sendUntil = Calendar.getInstance().getTimeInMillis() + (plugin.getConfig().getInt("expireWarning.delay") * 60 * 1000);
long sendUntil = Calendar.getInstance().getTimeInMillis() + (plugin.getConfig().getInt("expireWarning.delay") * 60 * 1000L);
for(String timeBefore : profileSection.getKeys(false)) {
long timeBeforeParsed = Utils.durationStringToLong(timeBefore);
if(timeBeforeParsed <= 0) {
@@ -489,12 +485,9 @@ public class RentRegion extends GeneralRegion {
message(offlinePlayer, "general-noRegion");
return false;
}
boolean extend = false;
if(getRenter() != null && offlinePlayer.getUniqueId().equals(getRenter())) {
extend = true;
}
boolean extend = getRenter() != null && offlinePlayer.getUniqueId().equals(getRenter());
// Check if available or extending
// Check if available or extending
if (isRented() && !extend) {
message(offlinePlayer, "rent-someoneElse");
return false;
@@ -714,7 +707,7 @@ public class RentRegion extends GeneralRegion {
// Give back the money
OfflinePlayer player = Bukkit.getOfflinePlayer(getRenter());
if(player != null && !noPayBack) {
if(!noPayBack) {
r = null;
boolean error = false;
try {
@@ -11,6 +11,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
@@ -89,7 +90,7 @@ public class GithubUpdateCheck {
try {
try {
String rawUrl = API_HOST + "/" + author + "/" + repository + "/" + API_LATEST_RELEASE;
url = new URL(rawUrl);
url = URI.create(rawUrl).toURL();
} catch(MalformedURLException e) {
logger.severe("Invalid url: '" + url + "', are the author '" + author + "' and repository '" + repository + "' correct?");
error = true;
@@ -79,7 +79,7 @@ public class LanguageConverter {
}
List<String> converted = convertRawList(messages);
if (converted.size() == 1) {
node.set(String.class, converted.get(0));
node.set(String.class, converted.getFirst());
} else {
node.setList(String.class, converted);
}
@@ -3,7 +3,7 @@ package me.wiefferink.areashop.tools;
/**
* Parse math from a string
* Adapted from:
* https://stackoverflow.com/questions/3422673/how-to-evaluate-a-math-expression-given-in-string-form
* <a href="https://stackoverflow.com/questions/3422673/how-to-evaluate-a-math-expression-given-in-string-form">...</a>
*/
public final class OperandParser {
@@ -38,7 +38,7 @@ public class SimpleMessageBridge implements MessageBridge {
}
if (message.get() == null || message.get().isEmpty() || (message.get().size() == 1 && message.get()
.get(0)
.getFirst()
.isEmpty())) {
return;
}
@@ -396,10 +396,10 @@ public class Utils {
result.add(pr);
first = false;
} else {
if(pr.getPriority() > result.get(0).getPriority()) {
if(pr.getPriority() > result.getFirst().getPriority()) {
result.clear();
result.add(pr);
} else if(pr.getParent() != null && pr.getParent().equals(result.get(0))) {
} else if(pr.getParent() != null && pr.getParent().equals(result.getFirst())) {
result.clear();
result.add(pr);
} else {
@@ -480,10 +480,10 @@ public class Utils {
result.add(region);
first = false;
} else {
if(region.getRegion().getPriority() > result.get(0).getRegion().getPriority()) {
if(region.getRegion().getPriority() > result.getFirst().getRegion().getPriority()) {
result.clear();
result.add(region);
} else if(region.getRegion().getParent() != null && region.getRegion().getParent().equals(result.get(0).getRegion())) {
} else if(region.getRegion().getParent() != null && region.getRegion().getParent().equals(result.getFirst().getRegion())) {
result.clear();
result.add(region);
} else {
@@ -523,7 +523,7 @@ public class Utils {
String result;
// Check for infinite and NaN
if(Double.isInfinite(amount)) {
result = "\u221E"; // Infinite symbol
result = "∞"; // Infinite symbol
} else if(Double.isNaN(amount)) {
result = "NaN";
} else {
@@ -802,16 +802,15 @@ public class Utils {
* @return the name of the player
*/
public static String toName(UUID uuid) {
if(uuid == null) {
return "";
} else {
String name = Bukkit.getOfflinePlayer(uuid).getName();
if(name != null) {
return name;
}
return "";
}
}
if (uuid == null) {
return "";
}
String name = Bukkit.getOfflinePlayer(uuid).getName();
if (name != null) {
return name;
}
return "";
}
/**
* Conversion from name to uuid.
@@ -7,7 +7,7 @@ public record Version(String original, VersionData versionData) {
/**
* Semver pattern, cg1 = major, cg2 = minor, cg3 = patch, cg4 = prerelease and cg5 = buildmetadata
* Taken from https://semver.org/ and https://regex101.com/r/vkijKf/1/
* Taken from <a href="https://semver.<a href="org/">...</a>">and https://regex1</a>01.com/r/vkijKf/1/
*/
public static final Pattern SEMVER_PATTERN = Pattern.compile(
"^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
@@ -1,10 +1,29 @@
package me.wiefferink.areashop.tools.version;
import javax.annotation.Nonnull;
import java.util.StringJoiner;
public class VersionUtil {
public static VersionData MC_1_18_2 = new VersionData(1, 18, 2);
public static final VersionData MC_1_21 = new VersionData(1, 21);
public static Version parseMinecraftVersion(String minecraftVersion) {
@Nonnull
public static String padTrailingZero(@Nonnull String minecraftVersion) {
int dotCount = 0;
for (char c : minecraftVersion.toCharArray()) {
if (c == '.') {
dotCount += 1;
}
}
StringJoiner joiner = new StringJoiner("");
for (int i = 0; i < 2 - dotCount; i++) {
joiner.add(".0");
}
return minecraftVersion + joiner;
}
@Nonnull
public static Version parseMinecraftVersion(@Nonnull String minecraftVersion) {
// Expecting 1.X.X-R0.1-SNAPSHOT
int stripLength = "-R0.1-SNAPSHOT".length();
int length = minecraftVersion.length();
@@ -13,7 +32,7 @@ public class VersionUtil {
}
String strippedVersion = minecraftVersion.substring(0, length - stripLength);
try {
return Version.parse(strippedVersion);
return Version.parse(padTrailingZero(strippedVersion));
} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException("Invalid minecraft version: " + minecraftVersion, ex);
}
@@ -1,11 +0,0 @@
dependencies {
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
compileOnly(projects.areashopInterface)
compileOnly(projects.areashopNms)
}
description = "AreaShop NMS Helper 1-18"
tasks {
}
@@ -1,28 +0,0 @@
package me.wiefferink.areashop.adapters.platform.modern;
import me.wiefferink.areashop.platform.adapter.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,15 +0,0 @@
package me.wiefferink.areashop.adapters.platform.modern;
import me.wiefferink.areashop.platform.adapter.BlockBehaviourHelper;
import me.wiefferink.areashop.platform.adapter.PlatformAdapter;
public class ModernPlatformAdapter implements PlatformAdapter {
private final BlockBehaviourImpl blockBehaviourHelper = new BlockBehaviourImpl();
@Override
public BlockBehaviourHelper blockBehaviourHelper() {
return this.blockBehaviourHelper;
}
}
@@ -23,19 +23,13 @@ public class PaperOfflinePlayerHelper implements OfflinePlayerHelper {
@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;
return profile.update().thenApply(PlayerProfile::getId).thenApply(Optional::ofNullable);
}
@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);
});
@@ -1,7 +1,6 @@
package me.wiefferink.areashop.adapters.plugins.essentials;
import me.wiefferink.areashop.features.homeaccess.AccessControlValidator;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
@@ -23,7 +23,6 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
import java.util.Optional;
@@ -1,7 +1,6 @@
package me.wiefferink.areashop.adapters.plugins.essentials;
import net.essentialsx.api.v2.services.mail.MailSender;
import org.bukkit.plugin.Plugin;
import javax.annotation.Nonnull;
import java.util.UUID;
@@ -25,14 +25,11 @@ import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.ExceptionUtil;
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Player;
import java.io.File;
@@ -113,12 +110,12 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
}
} 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));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
future.complete(false);
return;
} catch (Exception ex) {
pluginInterface.getLogger().warning(() -> "crashed during restore of " + regionInterface.getName());
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
future.complete(false);
return;
}
@@ -135,7 +132,7 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
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));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
future.complete(false);
}
});
@@ -179,10 +176,10 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
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));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
} catch (Exception ex) {
pluginInterface.getLogger().warning(() -> "crashed during save of " + regionInterface.getName());
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
}
future.complete(false);
});
@@ -250,10 +247,10 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
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));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
} catch (Exception ex) {
pluginInterface.getLogger().warning(() -> "crashed during restore of " + regionInterface.getName());
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
}
return false;
}
@@ -290,10 +287,10 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
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));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
} catch (Exception ex) {
pluginInterface.getLogger().warning("crashed during save of " + regionInterface.getName());
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
}
return false;
}
@@ -329,7 +326,7 @@ public class FastAsyncWorldEditHandler extends WorldEditInterface {
return false;
} catch (WorldEditException ex) {
pluginInterface.getLogger().warning("crashed during save of " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(ex));
pluginInterface.debugI(ExceptionUtil.getStackTrace(ex));
return true;
}
}
@@ -26,10 +26,10 @@ import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.ExceptionUtil;
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.entity.Player;
import java.io.File;
@@ -38,7 +38,6 @@ 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 {
@@ -107,9 +106,10 @@ public class WorldEditHandler extends WorldEditInterface {
try (InputStream is = new FileInputStream(finalFile);
ClipboardReader reader = format.getReader(is)) {
Clipboard clipboard = reader.read();
if (!clipboard.getDimensions().equals(dimensions)) {
BlockVector3 clipboardDimensions = clipboard.getDimensions();
if (!clipboardDimensions.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());
pluginInterface.debugI("schematic|region, x:" + clipboardDimensions.x() + "|" + regionInterface.getWidth() + ", y:" + clipboardDimensions.y() + "|" + regionInterface.getHeight() + ", z:" + clipboardDimensions.z() + "|" + regionInterface.getDepth());
return false;
}
final Operation operation = new ClipboardHolder(clipboard).createPaste(world)
@@ -119,18 +119,20 @@ public class WorldEditHandler extends WorldEditInterface {
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));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
} catch (Exception ex) {
pluginInterface.getLogger().warning(() -> "crashed during restore of " + regionInterface.getName());
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
}
return false;
}
@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
final ClipboardFormat format = BuiltInClipboardFormat.SPONGE_SCHEMATIC;
final ClipboardFormat format = BuiltInClipboardFormat.SPONGE_V3_SCHEMATIC;
final File targetFile = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
ProtectedRegion wgRegion = regionInterface.getRegion();
Region region = new CuboidRegion(wgRegion.getMinimumPoint(), wgRegion.getMaximumPoint());
@@ -153,7 +155,7 @@ public class WorldEditHandler extends WorldEditInterface {
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));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
}
try (OutputStream os = new FileOutputStream(targetFile);
ClipboardWriter writer = format.getWriter(os)) {
@@ -161,10 +163,10 @@ public class WorldEditHandler extends WorldEditInterface {
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));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
} catch (Exception ex) {
pluginInterface.getLogger().warning(() -> "crashed during save of " + regionInterface.getName());
pluginInterface.debugI(() -> ExceptionUtils.getStackTrace(ex));
pluginInterface.debugI(() -> ExceptionUtil.getStackTrace(ex));
}
return false;
}
@@ -192,7 +194,7 @@ public class WorldEditHandler extends WorldEditInterface {
return false;
} catch (WorldEditException ex) {
pluginInterface.getLogger().warning("crashed during save of " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(ex));
pluginInterface.debugI(ExceptionUtil.getStackTrace(ex));
return true;
}
}
@@ -135,20 +135,20 @@ public class WorldGuardHandler extends WorldGuardInterface {
@Override
public Vector getMinimumPoint(ProtectedRegion region) {
BlockVector3 min = region.getMinimumPoint();
return new Vector(min.getX(), min.getY(), min.getZ());
return new Vector(min.x(), min.y(), min.z());
}
@Override
public Vector getMaximumPoint(ProtectedRegion region) {
BlockVector3 min = region.getMaximumPoint();
return new Vector(min.getX(), min.getY(), min.getZ());
return new Vector(min.x(), min.y(), min.z());
}
@Override
public List<Vector> getRegionPoints(ProtectedRegion region) {
List<Vector> result = new ArrayList<>();
for (BlockVector2 point : region.getPoints()) {
result.add(new Vector(point.getX(), 0,point.getZ()));
result.add(new Vector(point.x(), 0, point.z()));
}
return result;
}
@@ -1,76 +0,0 @@
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;
/**
* 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) {
}
// Uses BlockData, which does not yet exist in 1.12-
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-
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;
}
}
@@ -0,0 +1,26 @@
package me.wiefferink.areashop.interfaces;
import javax.annotation.Nonnull;
import java.io.PrintWriter;
import java.io.StringWriter;
public class ExceptionUtil {
private ExceptionUtil() {
throw new IllegalStateException("Cannot instantiate static utility class");
}
@Nonnull
public static String getStackTrace(@Nonnull Throwable throwable) {
// Taken from Commons lang 3
final StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer, true));
return writer.toString();
}
@Nonnull
public static String dumpCurrentStack() {
return getStackTrace(new Exception());
}
}
-5
View File
@@ -1,5 +0,0 @@
dependencies {
compileOnly(libs.spigot)
}
description = "AreaShop NMS Interface"
@@ -1,16 +0,0 @@
package me.wiefferink.areashop.platform.adapter;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
public interface BlockBehaviourHelper {
boolean canPlace(Location location, BlockData blockData);
boolean isBlockValid(Block block);
boolean isBlockStateValid(BlockState blockState);
}
@@ -1,7 +0,0 @@
package me.wiefferink.areashop.platform.adapter;
public interface PlatformAdapter {
BlockBehaviourHelper blockBehaviourHelper();
}
+8 -3
View File
@@ -5,16 +5,15 @@ plugins {
java
`java-library`
`maven-publish`
id("io.papermc.paperweight.userdev") version "1.5.11" apply false
id("com.github.spotbugs") version "5.1.3"
idea
eclipse
}
group = "me.wiefferink"
version = "2.8.0"
version = "2.9.1-SNAPSHOT"
val targetJavaVersion = 17
val targetJavaVersion = 21
val encoding = Charsets.UTF_8
val encodingName: String = encoding.name()
@@ -37,6 +36,12 @@ subprojects {
repositories {
mavenCentral()
maven("https://oss.sonatype.org/content/groups/public/")
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
name = "sonatype-oss-snapshots"
mavenContent {
snapshotsOnly()
}
}
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven {
Loaded 100 of 105 files, more files were not shown because too many files have changed in this diff. Show more