Skip to content

Commit

Permalink
Update cloud-paper to 2.0.0-SNAPSHOT. Refactor commands to accomodate…
Browse files Browse the repository at this point in the history
… the new CommandSourceStack
  • Loading branch information
md5sha256 committed Jun 21, 2024
1 parent cd79e07 commit 5640a55
Show file tree
Hide file tree
Showing 59 changed files with 468 additions and 332 deletions.
14 changes: 7 additions & 7 deletions AreaShop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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-SNAPSHOT") {
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")
Expand Down Expand Up @@ -132,15 +132,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.20.4")
minecraftVersion("1.20.6")

downloadPlugins {
github("EssentialsX", "essentials", "2.20.1", "EssentialsX-2.20.1.jar")
github("MilkBowl", "Vault", "1.7.3", "Vault.jar")
// WorldEdit 7.3.0
url("https://mediafilez.forgecdn.net/files/5168/643/worldedit-bukkit-7.3.0.jar")
// WorldGuard 7.0.9
url("https://mediafilez.forgecdn.net/files/4675/318/worldguard-bukkit-7.0.9-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")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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;
Expand All @@ -28,13 +30,11 @@
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;

Expand Down Expand Up @@ -92,31 +92,29 @@ public String getHelpKey(@NotNull CommandSender target) {
}

@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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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;
Expand Down Expand Up @@ -55,21 +57,21 @@ public String getHelpKey(CommandSender target) {
}

@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()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
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;
Expand Down Expand Up @@ -66,16 +68,16 @@ public String getHelpKey(CommandSender target) {
}

@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");
}
Expand All @@ -93,7 +95,7 @@ private void handleCommand(@Nonnull CommandContext<Player> context) {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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;
Expand Down Expand Up @@ -46,20 +48,21 @@ public String stringDescription() {


@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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand All @@ -21,7 +22,6 @@
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 javax.annotation.Nonnull;
import java.util.ArrayList;
Expand Down Expand Up @@ -70,18 +70,14 @@ public String getHelpKey(CommandSender target) {
}

@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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -81,19 +82,19 @@ public String stringDescription() {
}

@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")) {
Expand Down Expand Up @@ -128,16 +129,16 @@ private void handleCommand(@Nonnull CommandContext<CommandSender> context) {
}

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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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.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;
Expand Down Expand Up @@ -44,9 +46,9 @@ public String stringDescription() {
}

@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);
}

Expand All @@ -58,8 +60,8 @@ public String getHelpKey(CommandSender target) {
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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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;
Expand Down Expand Up @@ -73,9 +75,9 @@ public String getHelpKey(CommandSender target) {
}

@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)
Expand All @@ -87,8 +89,8 @@ public String getHelpKey(CommandSender target) {
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");
}
Expand Down
Loading

0 comments on commit 5640a55

Please sign in to comment.