From 5f435941e4f21dd6ebf0af654dc54ec041d4f2fc Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Sun, 12 Nov 2023 21:19:48 +1100 Subject: [PATCH 01/10] Add transfer region command --- .../areashop/commands/TransferCommand.java | 136 ++++++++++++++++++ .../areashop/managers/CommandManager.java | 2 + .../areashop/regions/GeneralRegion.java | 16 +++ AreaShop/src/main/resources/lang/EN.yml | 9 ++ 4 files changed, 163 insertions(+) create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java new file mode 100644 index 00000000..6dd99f5f --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java @@ -0,0 +1,136 @@ +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 me.wiefferink.areashop.regions.RentRegion; +import me.wiefferink.areashop.tools.Utils; +import org.bukkit.OfflinePlayer; +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +@Singleton +public class TransferCommand extends CommandAreaShop { + + @Inject + private MessageBridge messageBridge; + @Inject + private IFileManager fileManager; + @Inject + private Plugin plugin; + @Inject + private Server server; + + @Override + public String getCommandStart() { + return "areashop transfer"; + } + + @Override + public String getHelp(CommandSender target) { + if (!target.hasPermission("areashop.transfer")) { + return null; + } + return "help-transfer"; + } + + @Override + public void execute(CommandSender sender, String[] args) { + if (!sender.hasPermission("areashop.transfer")) { + this.messageBridge.message(sender, "transfer-noPermission"); + return; + } + if (sender instanceof Player player) { + handlePlayer(player, args); + } else { + this.messageBridge.message(sender, "cmd-onlyByPlayer"); + } + } + + private void handlePlayer(Player player, String[] args) { + if (args.length < 1) { + this.messageBridge.message(player, "help-transfer"); + return; + } + String targetPlayerName = args[0]; + if (targetPlayerName.equals(player.getName())) { + this.messageBridge.message(player, "transfer-transferSelf"); + return; + } + GeneralRegion region; + if (args.length > 1) { + String targetRegionName = args[1]; + region = this.fileManager.getRegion(targetRegionName); + if (region == null) { + messageBridge.message(player, "cmd-noRegion"); + return; + } + } else { + List regions = Utils.getImportantRegions(player.getLocation()); + if (regions.isEmpty()) { + messageBridge.message(player, "cmd-noRegionsAtLocation"); + return; + } else if (regions.size() > 1) { + messageBridge.message(player, "cmd-moreRegionsAtLocation"); + return; + } + region = regions.get(0); + } + @SuppressWarnings("deprecation") + OfflinePlayer targetPlayer = this.server.getOfflinePlayer(targetPlayerName); + if (!targetPlayer.hasPlayedBefore()) { + // Unknown player + this.messageBridge.message(player, "transfer-noPlayer", targetPlayerName); + return; + } + if (player.getUniqueId().equals(region.getLandlord())) { + // Transfer ownership if same as landlord + region.setOwner(targetPlayer.getUniqueId()); + + } else if (region instanceof RentRegion rentRegion) { + if (!player.getUniqueId().equals(rentRegion.getOwner())) { + // Cannot transfer tenant if we aren't the current tenant + this.messageBridge.message(player, "transfer-notCurrentTenant"); + return; + } + // Don't restart the rent, just swap the renter + rentRegion.setRenter(targetPlayer.getUniqueId()); + } + } + + @Override + public List getTabCompleteList(int toComplete, String[] start, CommandSender sender) { + if (toComplete == 1) { + Collection players = this.server.getOnlinePlayers(); + List ret = players.stream() + .map(Player::getName) + .collect(Collectors.toCollection(ArrayList::new)); + if (sender instanceof Player player) { + ret.remove(player.getName()); + } + return ret; + } else if (toComplete == 2) { + if (!(sender instanceof Player player)) { + return this.fileManager.getRegionNames(); + } + UUID uuid = player.getUniqueId(); + return this.fileManager.getRegions() + .stream() + .filter(region -> region.isOwner(uuid) || region.isLandlord(uuid)) + .map(GeneralRegion::getName) + .toList(); + } + return Collections.emptyList(); + } +} diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/managers/CommandManager.java b/AreaShop/src/main/java/me/wiefferink/areashop/managers/CommandManager.java index 5c4ac506..0f21d243 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/managers/CommandManager.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/managers/CommandManager.java @@ -38,6 +38,7 @@ import me.wiefferink.areashop.commands.StackCommand; import me.wiefferink.areashop.commands.StopresellCommand; import me.wiefferink.areashop.commands.TeleportCommand; +import me.wiefferink.areashop.commands.TransferCommand; import me.wiefferink.areashop.commands.UnrentCommand; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -70,6 +71,7 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl commands.add(injector.getInstance(UnrentCommand.class)); commands.add(injector.getInstance(BuyCommand.class)); commands.add(injector.getInstance(SellCommand.class)); + commands.add(injector.getInstance(TransferCommand.class)); commands.add(injector.getInstance(MeCommand.class)); commands.add(injector.getInstance(InfoCommand.class)); commands.add(injector.getInstance(TeleportCommand.class)); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/regions/GeneralRegion.java b/AreaShop/src/main/java/me/wiefferink/areashop/regions/GeneralRegion.java index fcf0bb7e..054a9057 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/regions/GeneralRegion.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/regions/GeneralRegion.java @@ -1589,6 +1589,22 @@ public long getVolume() { return volume; } + /** + * Whether region transfers are enabled + * @return Returns true if region transfers are enabled, false otherwise + */ + public boolean isTransferEnabled() { + return getBooleanSetting("transferMode"); + } + + /** + * Se whether region transfers are enabled + * @param enabled Whether region transfers should be enabled, false otherwise + */ + public void setTransferEnabled(boolean enabled) { + setSetting("transferMode", enabled); + } + /** * Calculate the volume of the region (could be expensive for polygon regions). * @return Number of blocks in the region diff --git a/AreaShop/src/main/resources/lang/EN.yml b/AreaShop/src/main/resources/lang/EN.yml index 7424cd46..8f47ce59 100644 --- a/AreaShop/src/main/resources/lang/EN.yml +++ b/AreaShop/src/main/resources/lang/EN.yml @@ -102,6 +102,7 @@ help-linksigns: "%lang:helpCommand|/as linksigns|% Use bulk sign linking mode." help-stack: "%lang:helpCommand|/as stack|% Create multiple regions and add them." help-setlandlord: "%lang:helpCommand|/as setlandlord|% Set the landlord of a region." help-import: "%lang:helpCommand|/as import|% Import region from RegionForSale." +help-transfer: "%lang:helpCommand|/as transfer|% Transfer a region to another player." rent-help: "/as rent [region], the region you stand in will be used if not specified." rent-noPermission: "You don't have permission to rent a region." @@ -156,6 +157,14 @@ sell-noPermission: "You don't have permission to sell a region." sell-noPermissionOther: "You don't have permission to sell another region." sell-disabled: "Selling has been disabled for this region." +transfer-help: "/as transfer [region] , the region you stand in will be used if not specified." +transfer-noPermission: "You don't have permission to transfer a region." +transfer-disabled: "Transferring has been disabled for this region." +transfer-transferred: "%lang:region% has been transferred to %lang:player%." +transfer-noPlayer: "Unknown player: %0%" +transfer-notCurrentTenant: "You are not the current tenant/renter of this region." +transfer-transferSelf: "You cannot transfer a region to yourself." + reload-reloading: "Reloaded all configuration and region files." reload-updateStart: "" reload-updateComplete: "" From e09d4ebd83f65c5bf23d80515fde515255b23150 Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Sun, 12 Nov 2023 21:36:09 +1100 Subject: [PATCH 02/10] Fix lang and incorrect argument access --- .../areashop/commands/TransferCommand.java | 14 +++++++------- AreaShop/src/main/resources/lang/EN.yml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java index 6dd99f5f..d232bf94 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java @@ -59,18 +59,18 @@ public void execute(CommandSender sender, String[] args) { } private void handlePlayer(Player player, String[] args) { - if (args.length < 1) { - this.messageBridge.message(player, "help-transfer"); + if (args.length < 2) { + this.messageBridge.message(player, "transfer-help"); return; } - String targetPlayerName = args[0]; + String targetPlayerName = args[1]; if (targetPlayerName.equals(player.getName())) { this.messageBridge.message(player, "transfer-transferSelf"); return; } GeneralRegion region; - if (args.length > 1) { - String targetRegionName = args[1]; + if (args.length > 2) { + String targetRegionName = args[2]; region = this.fileManager.getRegion(targetRegionName); if (region == null) { messageBridge.message(player, "cmd-noRegion"); @@ -111,7 +111,7 @@ private void handlePlayer(Player player, String[] args) { @Override public List getTabCompleteList(int toComplete, String[] start, CommandSender sender) { - if (toComplete == 1) { + if (toComplete == 2) { Collection players = this.server.getOnlinePlayers(); List ret = players.stream() .map(Player::getName) @@ -120,7 +120,7 @@ public List getTabCompleteList(int toComplete, String[] start, CommandSe ret.remove(player.getName()); } return ret; - } else if (toComplete == 2) { + } else if (toComplete == 3) { if (!(sender instanceof Player player)) { return this.fileManager.getRegionNames(); } diff --git a/AreaShop/src/main/resources/lang/EN.yml b/AreaShop/src/main/resources/lang/EN.yml index 8f47ce59..b4183b2b 100644 --- a/AreaShop/src/main/resources/lang/EN.yml +++ b/AreaShop/src/main/resources/lang/EN.yml @@ -157,7 +157,7 @@ sell-noPermission: "You don't have permission to sell a region." sell-noPermissionOther: "You don't have permission to sell another region." sell-disabled: "Selling has been disabled for this region." -transfer-help: "/as transfer [region] , the region you stand in will be used if not specified." +transfer-help: "/as transfer [region], the region you stand in will be used if not specified." transfer-noPermission: "You don't have permission to transfer a region." transfer-disabled: "Transferring has been disabled for this region." transfer-transferred: "%lang:region% has been transferred to %lang:player%." From dd343aa58782f8739c32e0cd644f7d00ae4b7a8f Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Sun, 12 Nov 2023 22:31:57 +1100 Subject: [PATCH 03/10] Add messages for when regions are transferred --- .../me/wiefferink/areashop/commands/TransferCommand.java | 8 ++++++++ AreaShop/src/main/resources/lang/EN.yml | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java index d232bf94..63410e9b 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java @@ -97,6 +97,10 @@ private void handlePlayer(Player player, String[] args) { if (player.getUniqueId().equals(region.getLandlord())) { // Transfer ownership if same as landlord region.setOwner(targetPlayer.getUniqueId()); + this.messageBridge.message(player, "transfer-transferred-owner", targetPlayerName); + if (targetPlayer.isOnline()) { + this.messageBridge.message(targetPlayer.getPlayer(), "transfer-transferred-owner", targetPlayerName); + } } else if (region instanceof RentRegion rentRegion) { if (!player.getUniqueId().equals(rentRegion.getOwner())) { @@ -106,6 +110,10 @@ private void handlePlayer(Player player, String[] args) { } // Don't restart the rent, just swap the renter rentRegion.setRenter(targetPlayer.getUniqueId()); + this.messageBridge.message(player, "transfer-transferred-tenant", targetPlayerName); + if (targetPlayer.isOnline()) { + this.messageBridge.message(targetPlayer.getPlayer(), "transfer-transferred-tenant", targetPlayerName); + } } } diff --git a/AreaShop/src/main/resources/lang/EN.yml b/AreaShop/src/main/resources/lang/EN.yml index b4183b2b..70b8b207 100644 --- a/AreaShop/src/main/resources/lang/EN.yml +++ b/AreaShop/src/main/resources/lang/EN.yml @@ -160,7 +160,8 @@ sell-disabled: "Selling has been disabled for this region." transfer-help: "/as transfer [region], the region you stand in will be used if not specified." transfer-noPermission: "You don't have permission to transfer a region." transfer-disabled: "Transferring has been disabled for this region." -transfer-transferred: "%lang:region% has been transferred to %lang:player%." +transfer-transferred-owner: "%lang:region% has been transferred and is now owned by %0%." +transfer-transferred-tenant: "%lang:region% has been transferred and is now rented by %0%." transfer-noPlayer: "Unknown player: %0%" transfer-notCurrentTenant: "You are not the current tenant/renter of this region." transfer-transferSelf: "You cannot transfer a region to yourself." From a06d9271c451a9a5dad9c35cef92ae6f706811e2 Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Tue, 14 Nov 2023 02:37:20 +1100 Subject: [PATCH 04/10] Make sure tab complete list is mutable in transfer command --- .../me/wiefferink/areashop/commands/TransferCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java index 63410e9b..fc3b9b6f 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java @@ -18,6 +18,7 @@ import java.util.Collections; import java.util.List; import java.util.UUID; +import java.util.function.Predicate; import java.util.stream.Collectors; @Singleton @@ -121,9 +122,9 @@ private void handlePlayer(Player player, String[] args) { public List getTabCompleteList(int toComplete, String[] start, CommandSender sender) { if (toComplete == 2) { Collection players = this.server.getOnlinePlayers(); - List ret = players.stream() + List ret = new ArrayList<>(players.stream() .map(Player::getName) - .collect(Collectors.toCollection(ArrayList::new)); + .toList()); if (sender instanceof Player player) { ret.remove(player.getName()); } From f7b010b3f3e45bddb9ad281aa8165dd9b8011faf Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Tue, 14 Nov 2023 03:16:29 +1100 Subject: [PATCH 05/10] Fix lang issue with region not being replaced, fix landlord/owner not being changed --- .../wiefferink/areashop/commands/TransferCommand.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java index fc3b9b6f..b2b0a52d 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java @@ -4,6 +4,7 @@ import jakarta.inject.Singleton; import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.managers.IFileManager; +import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; import me.wiefferink.areashop.regions.RentRegion; import me.wiefferink.areashop.tools.Utils; @@ -95,10 +96,11 @@ private void handlePlayer(Player player, String[] args) { this.messageBridge.message(player, "transfer-noPlayer", targetPlayerName); return; } - if (player.getUniqueId().equals(region.getLandlord())) { + if (region.isLandlord(targetPlayer.getUniqueId())) { // Transfer ownership if same as landlord region.setOwner(targetPlayer.getUniqueId()); - this.messageBridge.message(player, "transfer-transferred-owner", targetPlayerName); + region.setLandlord(targetPlayer.getUniqueId(), targetPlayerName); + this.messageBridge.message(player, "transfer-transferred-owner", targetPlayerName, region); if (targetPlayer.isOnline()) { this.messageBridge.message(targetPlayer.getPlayer(), "transfer-transferred-owner", targetPlayerName); } @@ -134,11 +136,11 @@ public List getTabCompleteList(int toComplete, String[] start, CommandSe return this.fileManager.getRegionNames(); } UUID uuid = player.getUniqueId(); - return this.fileManager.getRegions() + return new ArrayList<>(this.fileManager.getRegions() .stream() .filter(region -> region.isOwner(uuid) || region.isLandlord(uuid)) .map(GeneralRegion::getName) - .toList(); + .toList()); } return Collections.emptyList(); } From d40b9c660bccdfdd372142a75cd2b7673048c8df Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:01:01 +1100 Subject: [PATCH 06/10] Fix transfer missing region arg replacement and incorrect ownership checks in TransferCommand --- .../areashop/commands/TransferCommand.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java index b2b0a52d..70faeee2 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java @@ -96,26 +96,27 @@ private void handlePlayer(Player player, String[] args) { this.messageBridge.message(player, "transfer-noPlayer", targetPlayerName); return; } - if (region.isLandlord(targetPlayer.getUniqueId())) { + if (region.isLandlord(player.getUniqueId())) { // Transfer ownership if same as landlord region.setOwner(targetPlayer.getUniqueId()); region.setLandlord(targetPlayer.getUniqueId(), targetPlayerName); this.messageBridge.message(player, "transfer-transferred-owner", targetPlayerName, region); if (targetPlayer.isOnline()) { - this.messageBridge.message(targetPlayer.getPlayer(), "transfer-transferred-owner", targetPlayerName); + this.messageBridge.message(targetPlayer.getPlayer(), "transfer-transferred-owner", targetPlayerName, region); } - - } else if (region instanceof RentRegion rentRegion) { - if (!player.getUniqueId().equals(rentRegion.getOwner())) { + return; + } + if (region instanceof RentRegion rentRegion) { + if (!rentRegion.isRenter(player.getUniqueId())) { // Cannot transfer tenant if we aren't the current tenant this.messageBridge.message(player, "transfer-notCurrentTenant"); return; } // Don't restart the rent, just swap the renter rentRegion.setRenter(targetPlayer.getUniqueId()); - this.messageBridge.message(player, "transfer-transferred-tenant", targetPlayerName); + this.messageBridge.message(player, "transfer-transferred-tenant", targetPlayerName, region); if (targetPlayer.isOnline()) { - this.messageBridge.message(targetPlayer.getPlayer(), "transfer-transferred-tenant", targetPlayerName); + this.messageBridge.message(targetPlayer.getPlayer(), "transfer-transferred-tenant", targetPlayerName, region); } } } From c0794daeeb47b2e0b2a5286361bdd07477ac5f10 Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:24:03 +1100 Subject: [PATCH 07/10] Actually respect transfers being disabled --- .../java/me/wiefferink/areashop/commands/TransferCommand.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java index 70faeee2..b587ac90 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java @@ -89,6 +89,10 @@ private void handlePlayer(Player player, String[] args) { } region = regions.get(0); } + if (!region.isTransferEnabled()) { + this.messageBridge.message(player, "transfer-disabled"); + return; + } @SuppressWarnings("deprecation") OfflinePlayer targetPlayer = this.server.getOfflinePlayer(targetPlayerName); if (!targetPlayer.hasPlayedBefore()) { From c9dc8dd840c20d42d05f41deebb71f09e53425c2 Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:36:00 +1100 Subject: [PATCH 08/10] Add SetTransferCommand --- .../areashop/commands/SetTransferCommand.java | 77 +++++++++++++++++++ .../areashop/managers/CommandManager.java | 2 + AreaShop/src/main/resources/lang/EN.yml | 7 ++ 3 files changed, 86 insertions(+) create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTransferCommand.java diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTransferCommand.java new file mode 100644 index 00000000..a1241e5f --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTransferCommand.java @@ -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 getTabCompleteList(int toComplete, String[] start, CommandSender sender) { + List result = new ArrayList<>(); + if (toComplete == 2) { + result = fileManager.getRegionNames(); + } else if (toComplete == 3) { + result.add("true"); + result.add("false"); + } + return result; + } +} diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/managers/CommandManager.java b/AreaShop/src/main/java/me/wiefferink/areashop/managers/CommandManager.java index 0f21d243..6d466656 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/managers/CommandManager.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/managers/CommandManager.java @@ -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; @@ -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)); diff --git a/AreaShop/src/main/resources/lang/EN.yml b/AreaShop/src/main/resources/lang/EN.yml index 70b8b207..728264ca 100644 --- a/AreaShop/src/main/resources/lang/EN.yml +++ b/AreaShop/src/main/resources/lang/EN.yml @@ -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." @@ -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 ." +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 [region], the region you stand in will be used if not specified." setprice-notRegistered: "The specified region is not registered: %0%." From ff1ea3ae511340180d063b4f04abb12cfeb1b55c Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:42:08 +1100 Subject: [PATCH 09/10] Add default config for transfers --- AreaShop/src/main/resources/default.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AreaShop/src/main/resources/default.yml b/AreaShop/src/main/resources/default.yml index d110c243..25452bf0 100644 --- a/AreaShop/src/main/resources/default.yml +++ b/AreaShop/src/main/resources/default.yml @@ -34,6 +34,8 @@ general: landlordName: '' # Disable to prevent counting this region towards limits set by 'limitGroups' in config.yml. countForLimits: true + # Whether transferring tenant <--> tenant and landlord <--> landlord should be enabled + transferMode: false ##### Set the layout and functions of the signs. # The following sections can be added for performing certain commands when the sign is clicked: From 7e1d7168f1ec41428ba321a493cfabbf440f4b14 Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Fri, 24 Nov 2023 21:36:47 +1100 Subject: [PATCH 10/10] Refactor transfer to transfer both buyers and renters. Update lang files and fix data keys in GeneralRegion --- .../areashop/commands/TransferCommand.java | 22 +++++++++---------- .../areashop/regions/GeneralRegion.java | 4 ++-- AreaShop/src/main/resources/lang/EN.yml | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java index b587ac90..739cab50 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java @@ -110,18 +110,16 @@ private void handlePlayer(Player player, String[] args) { } return; } - if (region instanceof RentRegion rentRegion) { - if (!rentRegion.isRenter(player.getUniqueId())) { - // Cannot transfer tenant if we aren't the current tenant - this.messageBridge.message(player, "transfer-notCurrentTenant"); - return; - } - // Don't restart the rent, just swap the renter - rentRegion.setRenter(targetPlayer.getUniqueId()); - this.messageBridge.message(player, "transfer-transferred-tenant", targetPlayerName, region); - if (targetPlayer.isOnline()) { - this.messageBridge.message(targetPlayer.getPlayer(), "transfer-transferred-tenant", targetPlayerName, region); - } + if (!region.isOwner(player.getUniqueId())) { + // Cannot transfer tenant if we aren't the current tenant + this.messageBridge.message(player, "transfer-notCurrentTenant"); + return; + } + // Swap the owner/occupant (renter or buyer) + region.setOwner(targetPlayer.getUniqueId()); + this.messageBridge.message(player, "transfer-transferred-tenant", targetPlayerName, region); + if (targetPlayer.isOnline()) { + this.messageBridge.message(targetPlayer.getPlayer(), "transfer-transferred-tenant", targetPlayerName, region); } } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/regions/GeneralRegion.java b/AreaShop/src/main/java/me/wiefferink/areashop/regions/GeneralRegion.java index 054a9057..59e8d5b1 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/regions/GeneralRegion.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/regions/GeneralRegion.java @@ -1594,7 +1594,7 @@ public long getVolume() { * @return Returns true if region transfers are enabled, false otherwise */ public boolean isTransferEnabled() { - return getBooleanSetting("transferMode"); + return getBooleanSetting("general.transferMode"); } /** @@ -1602,7 +1602,7 @@ public boolean isTransferEnabled() { * @param enabled Whether region transfers should be enabled, false otherwise */ public void setTransferEnabled(boolean enabled) { - setSetting("transferMode", enabled); + setSetting("general.transferMode", enabled); } /** diff --git a/AreaShop/src/main/resources/lang/EN.yml b/AreaShop/src/main/resources/lang/EN.yml index 728264ca..801c59fa 100644 --- a/AreaShop/src/main/resources/lang/EN.yml +++ b/AreaShop/src/main/resources/lang/EN.yml @@ -162,9 +162,9 @@ transfer-help: "/as transfer [region], the region you stand in will be transfer-noPermission: "You don't have permission to transfer a region." transfer-disabled: "Transferring has been disabled for this region." transfer-transferred-owner: "%lang:region% has been transferred and is now owned by %0%." -transfer-transferred-tenant: "%lang:region% has been transferred and is now rented by %0%." +transfer-transferred-tenant: "%lang:region% has been transferred and is now occupied by %0%." transfer-noPlayer: "Unknown player: %0%" -transfer-notCurrentTenant: "You are not the current tenant/renter of this region." +transfer-notCurrentTenant: "You are not the current tenant of this region." transfer-transferSelf: "You cannot transfer a region to yourself." reload-reloading: "Reloaded all configuration and region files."