Skip to content

Commit

Permalink
Add SetTransferCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
md5sha256 committed Nov 24, 2023
1 parent c0794da commit c9dc8dd
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package me.wiefferink.areashop.commands;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.wiefferink.areashop.MessageBridge;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;

import java.util.ArrayList;
import java.util.List;

@Singleton
public class SetTransferCommand extends CommandAreaShop {

@Inject
private MessageBridge messageBridge;
@Inject
private IFileManager fileManager;
@Inject
private Plugin plugin;

@Override
public String getCommandStart() {
return "areashop settransfer";
}

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

@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.settransfer")) {
messageBridge.message(sender, "settransfer-noPermission");
return;
}
if (args.length <= 2 || args[1] == null || args[2] == null) {
messageBridge.message(sender, "settransfer-help");
return;
}
GeneralRegion region = fileManager.getRegion(args[1]);
if (region == null) {
messageBridge.message(sender, "settransfer-notRegistered", args[1]);
return;
}
boolean value;
if (args[2].equalsIgnoreCase("true")) {
value = true;
} else if (args[2].equalsIgnoreCase("false")) {
value = false;
} else {
messageBridge.message(sender, "settransfer-invalidSetting", args[2]);
return;
}
region.setTransferEnabled(value);
messageBridge.message(sender, "settransfer-success", args[2], region);
region.update();
}

@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<>();
if (toComplete == 2) {
result = fileManager.getRegionNames();
} else if (toComplete == 3) {
result.add("true");
result.add("false");
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import me.wiefferink.areashop.commands.ResellCommand;
import me.wiefferink.areashop.commands.SchematiceventCommand;
import me.wiefferink.areashop.commands.SellCommand;
import me.wiefferink.areashop.commands.SetTransferCommand;
import me.wiefferink.areashop.commands.SetdurationCommand;
import me.wiefferink.areashop.commands.SetlandlordCommand;
import me.wiefferink.areashop.commands.SetownerCommand;
Expand Down Expand Up @@ -85,6 +86,7 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl
commands.add(injector.getInstance(SetpriceCommand.class));
commands.add(injector.getInstance(SetownerCommand.class));
commands.add(injector.getInstance(SetdurationCommand.class));
commands.add(injector.getInstance(SetTransferCommand.class));
commands.add(injector.getInstance(ReloadCommand.class));
commands.add(injector.getInstance(GroupaddCommand.class));
commands.add(injector.getInstance(GroupdelCommand.class));
Expand Down
7 changes: 7 additions & 0 deletions AreaShop/src/main/resources/lang/EN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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-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."
help-find: "%lang:helpCommand|/as find|% Find an empty buy or rent."
Expand Down Expand Up @@ -313,6 +314,12 @@ setrestore-invalidSetting: "'%0%' is not a valid state, should be true, false or
setrestore-success: "Successfully set the restore setting of %lang:region% to '%0%'."
setrestore-successProfile: "Successfully set the restore setting of %lang:region% to '%0%' and the profile to '%1%'."

settransfer-help: "/as settransfer <region> <true|false>."
settransfer-noPermission: "You don't have permission to change the transfer settings."
settransfer-notRegistered: "The specified region is not registered: %0%."
settransfer-invalidSetting: "'%0%' is not a valid state, should be true, false or general."
settransfer-success: "Successfully set the transfer setting of %lang:region% to '%0%'."

setprice-noPermission: "You don't have permission to change the price of a region."
setprice-help: "/as setprice <price> [region], the region you stand in will be used if not specified."
setprice-notRegistered: "The specified region is not registered: %0%."
Expand Down

0 comments on commit c9dc8dd

Please sign in to comment.