Save region name as given to /as add and /as stack

- Previously the WorldGuard region id was used, converting the name to lowercase
This commit is contained in:
Thijs Wiefferink 2018-01-26 13:55:41 +01:00
parent d4df691166
commit 8474edd29d
3 changed files with 21 additions and 13 deletions

View File

@ -16,9 +16,12 @@ import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public class AddCommand extends CommandAreaShop { public class AddCommand extends CommandAreaShop {
@ -52,7 +55,7 @@ public class AddCommand extends CommandAreaShop {
plugin.message(sender, "add-help"); plugin.message(sender, "add-help");
return; return;
} }
List<ProtectedRegion> regions = new ArrayList<>(); Map<String, ProtectedRegion> regions = new HashMap<>();
World world; World world;
Player player = null; Player player = null;
if(sender instanceof Player) { if(sender instanceof Player) {
@ -69,7 +72,7 @@ public class AddCommand extends CommandAreaShop {
return; return;
} }
world = selection.getWorld(); world = selection.getWorld();
regions = Utils.getWorldEditRegionsInSelection(selection); regions = Utils.getWorldEditRegionsInSelection(selection).stream().collect(Collectors.toMap(ProtectedRegion::getId, region -> region));
if(regions.size() == 0) { if(regions.size() == 0) {
plugin.message(player, "cmd-noWERegionsFound"); plugin.message(player, "cmd-noWERegionsFound");
return; return;
@ -102,10 +105,10 @@ public class AddCommand extends CommandAreaShop {
plugin.message(sender, "cmd-noRegion", args[2]); plugin.message(sender, "cmd-noRegion", args[2]);
return; return;
} }
regions.add(region); regions.put(args[2], region);
} }
final boolean isRent = "rent".equals(args[1].toLowerCase()); final boolean isRent = "rent".equals(args[1].toLowerCase());
final List<ProtectedRegion> finalRegions = regions; final Map<String, ProtectedRegion> finalRegions = regions;
final Player finalPlayer = player; final Player finalPlayer = player;
final World finalWorld = world; final World finalWorld = world;
AreaShop.debug("Starting add task with " + regions.size() + " regions"); AreaShop.debug("Starting add task with " + regions.size() + " regions");
@ -116,8 +119,10 @@ public class AddCommand extends CommandAreaShop {
TreeSet<String> namesNoPermission = new TreeSet<>(); TreeSet<String> namesNoPermission = new TreeSet<>();
Do.forAll( Do.forAll(
plugin.getConfig().getInt("adding.regionsPerTick"), plugin.getConfig().getInt("adding.regionsPerTick"),
regions, regions.entrySet(),
region -> { regionEntry -> {
String regionName = regionEntry.getKey();
ProtectedRegion region = regionEntry.getValue();
// Determine if the player is an owner or member of the region // Determine if the player is an owner or member of the region
boolean isMember = finalPlayer != null && plugin.getWorldGuardHandler().containsMember(region, finalPlayer.getUniqueId()); boolean isMember = finalPlayer != null && plugin.getWorldGuardHandler().containsMember(region, finalPlayer.getUniqueId());
boolean isOwner = finalPlayer != null && plugin.getWorldGuardHandler().containsMember(region, finalPlayer.getUniqueId()); boolean isOwner = finalPlayer != null && plugin.getWorldGuardHandler().containsMember(region, finalPlayer.getUniqueId());
@ -129,11 +134,11 @@ public class AddCommand extends CommandAreaShop {
} }
FileManager.AddResult result = plugin.getFileManager().checkRegionAdd(sender, region, isRent ? GeneralRegion.RegionType.RENT : GeneralRegion.RegionType.BUY); FileManager.AddResult result = plugin.getFileManager().checkRegionAdd(sender, region, isRent ? GeneralRegion.RegionType.RENT : GeneralRegion.RegionType.BUY);
if(result == FileManager.AddResult.ALREADYADDED) { if(result == FileManager.AddResult.ALREADYADDED) {
regionsAlready.add(plugin.getFileManager().getRegion(region.getId())); regionsAlready.add(plugin.getFileManager().getRegion(regionName));
} else if(result == FileManager.AddResult.BLACKLISTED) { } else if(result == FileManager.AddResult.BLACKLISTED) {
namesBlacklisted.add(region.getId()); namesBlacklisted.add(regionName);
} else if(result == FileManager.AddResult.NOPERMISSION) { } else if(result == FileManager.AddResult.NOPERMISSION) {
namesNoPermission.add(region.getId()); namesNoPermission.add(regionName);
} else { } else {
// Check if the player should be landlord // Check if the player should be landlord
boolean landlord = (!sender.hasPermission("areashop.create" + type) boolean landlord = (!sender.hasPermission("areashop.create" + type)
@ -143,7 +148,7 @@ public class AddCommand extends CommandAreaShop {
existing.addAll(plugin.getWorldGuardHandler().getOwners(region).asUniqueIdList()); existing.addAll(plugin.getWorldGuardHandler().getOwners(region).asUniqueIdList());
existing.addAll(plugin.getWorldGuardHandler().getMembers(region).asUniqueIdList()); existing.addAll(plugin.getWorldGuardHandler().getMembers(region).asUniqueIdList());
if(isRent) { if(isRent) {
RentRegion rent = new RentRegion(region.getId(), finalWorld); RentRegion rent = new RentRegion(regionName, finalWorld);
// Set landlord // Set landlord
if(landlord) { if(landlord) {
rent.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName()); rent.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
@ -186,7 +191,7 @@ public class AddCommand extends CommandAreaShop {
regionsSuccess.add(rent); regionsSuccess.add(rent);
} else { } else {
BuyRegion buy = new BuyRegion(region.getId(), finalWorld); BuyRegion buy = new BuyRegion(regionName, finalWorld);
// Set landlord // Set landlord
if(landlord) { if(landlord) {
buy.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName()); buy.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());

View File

@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Abstract class for generalising command classes. * Abstract class for generalising command classes.
@ -14,6 +15,8 @@ public abstract class CommandAreaShop {
AreaShop plugin = AreaShop.getInstance(); AreaShop plugin = AreaShop.getInstance();
private Map<String, Long> confirmed;
/** /**
* Check if this Command instance can execute the given command and arguments. * Check if this Command instance can execute the given command and arguments.
* @param command The command to check for execution * @param command The command to check for execution

View File

@ -191,7 +191,7 @@ public class StackCommand extends CommandAreaShop {
manager.addRegion(region); manager.addRegion(region);
// Add the region to AreaShop // Add the region to AreaShop
if(rentRegions) { if(rentRegions) {
RentRegion rent = new RentRegion(region.getId(), selection.getWorld()); RentRegion rent = new RentRegion(regionName, selection.getWorld());
if(finalGroup != null) { if(finalGroup != null) {
finalGroup.addMember(rent); finalGroup.addMember(rent);
} }
@ -201,7 +201,7 @@ public class StackCommand extends CommandAreaShop {
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false); rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
rent.update(); rent.update();
} else { } else {
BuyRegion buy = new BuyRegion(region.getId(), selection.getWorld()); BuyRegion buy = new BuyRegion(regionName, selection.getWorld());
if(finalGroup != null) { if(finalGroup != null) {
finalGroup.addMember(buy); finalGroup.addMember(buy);
} }