Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package me.wiefferink.areashop.commands;

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.RegionParseUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.RentRegion;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
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.flag.CommandFlag;
import org.incendo.cloud.parser.standard.IntegerParser;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;

@Singleton
public class SetMaxExtends extends AreashopCommandBean {

private static final CloudKey<Integer> KEY_EXTENDS = CloudKey.of("extends", Integer.class);
private final MessageBridge messageBridge;
private final CommandFlag<RentRegion> regionFlag;

@Inject
public SetMaxExtends(
@Nonnull MessageBridge messageBridge,
@Nonnull IFileManager fileManager
) {
this.messageBridge = messageBridge;
this.regionFlag = RegionParseUtil.createDefaultRent(fileManager);
}

@Override
public String getHelpKey(@NotNull CommandSender target) {
if (target.hasPermission("areashop.setmaxextends")) {
return "help-setmaxextends";
}
return null;
}

@Override
public String stringDescription() {
return null;
}

@Override
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("setmaxextends")
.required(KEY_EXTENDS, IntegerParser.integerParser(0))
.flag(this.regionFlag)
.handler(this::handleCommand);
}

@Override
protected @NonNull CommandProperties properties() {
return CommandProperties.of("setmaxextends");
}

private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
CommandSender sender = context.sender().sender();
if (!sender.hasPermission("areashop.setmaxextends") && (!sender.hasPermission("areashop.setmaxextends.landlord") && sender instanceof Player)) {
this.messageBridge.message(sender, "setmaxextends-noPermission");
return;
}
RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, sender, this.regionFlag);
if (!sender.hasPermission("areashop.setmaxextends")
&& !(sender instanceof Player player
&& rent.isLandlord(player.getUniqueId()))
) {
this.messageBridge.message(sender, "setmaxextends-noLandlord", rent);
return;
}
int extend = context.get(KEY_EXTENDS);

sender.sendMessage();
rent.setMaxExtends(extend);
rent.update();
this.messageBridge.message(sender, "setmaxextends-success", rent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import me.wiefferink.areashop.commands.ToggleHomeCommand;
import me.wiefferink.areashop.commands.TransferCommand;
import me.wiefferink.areashop.commands.UnrentCommand;
import me.wiefferink.areashop.commands.SetMaxExtends;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.CommandSourceMapper;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -109,7 +110,8 @@ public class AreashopCommands {
TeleportCommand.class,
ToggleHomeCommand.class,
TransferCommand.class,
UnrentCommand.class
UnrentCommand.class,
SetMaxExtends.class
);

private final MessageBridge messageBridge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ public void setTimesExtended(int times) {
}
}

public void setMaxExtends(int times) {
setSetting("rent.maxExtends", times); }

@Override
public Object provideReplacement(String variable) {
return switch (variable) {
Expand Down
5 changes: 5 additions & 0 deletions AreaShop/src/main/resources/lang/EN-MM.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ setduration-noLandlord: You don't have permission to change the duration because
setduration-successRemoved: 'Duration of %lang:region% has been removed, it will now
use the duration from a group or the default.yml file, new duration: %duration%.'

setmaxextends-noPermission: You don't have permission to change the amount of times a region can have rent extended.
setmaxextends-help: /as setmaxextends \<amount> [region], the region you stand in will be used if not specified.
setmaxextends-noLandlord: You don't have permission to change the duration because you are not the landlord of %lang:region%.
setmaxextends-success: Max extensions of %lang:region% changed to %maxextends%

setup-noRegion: You did not specify a region on the second line.
setup-alreadyRentSign: The region you specified is already added to AreaShop as a
rent region, add signs with [as] on the first line or '/as addsign'.
Expand Down
6 changes: 6 additions & 0 deletions AreaShop/src/main/resources/lang/EN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ help-reload: "%lang:helpCommand|/as reload|% Reload all files and update the reg
help-setrestore: "%lang:helpCommand|/as setrestore|% Set restoring on/off and choose profile."
help-setprice: "%lang:helpCommand|/as setprice|% Change the price of a region."
help-setduration: "%lang:helpCommand|/as setduration|% Change the duration of a rent region."
help-setmaxextends: "%lang:helpCommand|/as setmaxextends|% Change the amount of times a renter can extend their rent by."
help-settransfer: "%lang:helpCommand|/as settransfer|% Set transfer on/off."
help-teleport: "%lang:helpCommand|/as tp|% Teleport to a rent/buy region."
help-setteleport: "%lang:helpCommand|/as settp|% Set teleport position for a region."
Expand Down Expand Up @@ -350,6 +351,11 @@ setduration-success: "Duration of region %lang:region% changed to '%duration%'."
setduration-noLandlord: "You don't have permission to change the duration because you are not the landlord of %lang:region%."
setduration-successRemoved: "Duration of %lang:region% has been removed, it will now use the duration from a group or the default.yml file, new duration: %duration%."

setmaxextends-noPermission: "You don't have permission to change the amount of times a region can have rent extended."
setmaxextends-help: "/as setmaxextends <amount> [region], the region you stand in will be used if not specified."
setmaxextends-noLandlord: "You don't have permission to change the duration because you are not the landlord of %lang:region%."
setmaxextends-success: "Max extensions of %lang:region% changed to %maxextends%"

setup-noRegion: "You did not specify a region on the second line."
setup-alreadyRentSign: "The region you specified is already added to AreaShop as a rent region, add signs with [as] on the first line or '/as addsign'."
setup-alreadyOtherWorld: "The region you specified is already added to AreaShop in another world, regions from different worlds still need different names."
Expand Down
Loading