Indicate if a region has already been added with another world

- Closes #287
This commit is contained in:
Thijs Wiefferink 2018-05-23 22:51:46 +02:00
parent e34daeb5ff
commit 6154454f96
5 changed files with 33 additions and 10 deletions

View File

@ -108,13 +108,12 @@ public class AddCommand extends CommandAreaShop {
regions.put(args[2], region);
}
final boolean isRent = "rent".equals(args[1].toLowerCase());
final Map<String, ProtectedRegion> finalRegions = regions;
final Player finalPlayer = player;
final World finalWorld = world;
AreaShop.debug("Starting add task with " + regions.size() + " regions");
TreeSet<GeneralRegion> regionsSuccess = new TreeSet<>();
TreeSet<GeneralRegion> regionsAlready = new TreeSet<>();
TreeSet<GeneralRegion> regionsAlreadyOtherWorld = new TreeSet<>();
TreeSet<String> namesBlacklisted = new TreeSet<>();
TreeSet<String> namesNoPermission = new TreeSet<>();
Do.forAll(
@ -132,9 +131,11 @@ public class AddCommand extends CommandAreaShop {
} else {
type = "buy";
}
FileManager.AddResult result = plugin.getFileManager().checkRegionAdd(sender, region, isRent ? GeneralRegion.RegionType.RENT : GeneralRegion.RegionType.BUY);
FileManager.AddResult result = plugin.getFileManager().checkRegionAdd(sender, region, world, isRent ? GeneralRegion.RegionType.RENT : GeneralRegion.RegionType.BUY);
if(result == FileManager.AddResult.ALREADYADDED) {
regionsAlready.add(plugin.getFileManager().getRegion(regionName));
} else if(result == FileManager.AddResult.ALREADYADDEDOTHERWORLD) {
regionsAlreadyOtherWorld.add(plugin.getFileManager().getRegion(regionName));
} else if(result == FileManager.AddResult.BLACKLISTED) {
namesBlacklisted.add(regionName);
} else if(result == FileManager.AddResult.NOPERMISSION) {
@ -148,7 +149,7 @@ public class AddCommand extends CommandAreaShop {
existing.addAll(plugin.getWorldGuardHandler().getOwners(region).asUniqueIdList());
existing.addAll(plugin.getWorldGuardHandler().getMembers(region).asUniqueIdList());
if(isRent) {
RentRegion rent = new RentRegion(regionName, finalWorld);
RentRegion rent = new RentRegion(regionName, world);
// Set landlord
if(landlord) {
rent.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
@ -191,7 +192,7 @@ public class AddCommand extends CommandAreaShop {
regionsSuccess.add(rent);
} else {
BuyRegion buy = new BuyRegion(regionName, finalWorld);
BuyRegion buy = new BuyRegion(regionName, world);
// Set landlord
if(landlord) {
buy.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
@ -243,6 +244,9 @@ public class AddCommand extends CommandAreaShop {
if(!regionsAlready.isEmpty()) {
plugin.message(sender, "add-failed", Utils.combinedMessage(regionsAlready, "region"));
}
if(!regionsAlreadyOtherWorld.isEmpty()) {
plugin.message(sender, "add-failedOtherWorld", Utils.combinedMessage(regionsAlreadyOtherWorld, "region"));
}
if(!namesBlacklisted.isEmpty()) {
plugin.message(sender, "add-blacklisted", Utils.createCommaSeparatedList(namesBlacklisted));
}

View File

@ -223,11 +223,13 @@ public class SignsFeature extends RegionFeature {
return;
}
FileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, regionManager.getRegion(secondLine), GeneralRegion.RegionType.RENT);
FileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, regionManager.getRegion(secondLine), event.getPlayer().getWorld(), GeneralRegion.RegionType.RENT);
if(addResult == FileManager.AddResult.BLACKLISTED) {
plugin.message(player, "setup-blacklisted", secondLine);
} else if(addResult == FileManager.AddResult.ALREADYADDED) {
plugin.message(player, "setup-alreadyRentSign");
} else if(addResult == FileManager.AddResult.ALREADYADDEDOTHERWORLD) {
plugin.message(player, "setup-alreadyOtherWorld");
} else if(addResult == FileManager.AddResult.NOPERMISSION) {
plugin.message(player, "setup-noPermission", secondLine);
} else if(thirdLine != null && thirdLine.length() != 0 && !Utils.checkTimeFormat(thirdLine)) {
@ -331,11 +333,13 @@ public class SignsFeature extends RegionFeature {
plugin.message(player, "cmd-noRegion", secondLine);
return;
}
FileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, region, GeneralRegion.RegionType.BUY);
FileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, region, event.getPlayer().getWorld(), GeneralRegion.RegionType.BUY);
if(addResult == FileManager.AddResult.BLACKLISTED) {
plugin.message(player, "setup-blacklisted", secondLine);
} else if(addResult == FileManager.AddResult.ALREADYADDED) {
plugin.message(player, "setup-alreadyRentSign");
} else if(addResult == FileManager.AddResult.ALREADYADDEDOTHERWORLD) {
plugin.message(player, "setup-alreadyOtherWorld");
} else if(addResult == FileManager.AddResult.NOPERMISSION) {
plugin.message(player, "setup-noPermission", secondLine);
} else {

View File

@ -67,6 +67,7 @@ public class FileManager extends Manager {
BLACKLISTED("blacklisted"),
NOPERMISSION("nopermission"),
ALREADYADDED("alreadyadded"),
ALREADYADDEDOTHERWORLD("alreadyaddedotherworld"),
SUCCESS("success");
private final String value;
@ -357,10 +358,11 @@ public class FileManager extends Manager {
* Check if a player can add a certain region as rent or buy region.
* @param sender The player/console that wants to add a region
* @param region The WorldGuard region to add
* @param world The world the ProtectedRegion is located in
* @param type The type the region should have in AreaShop
* @return The result if a player would want to add this region
*/
public AddResult checkRegionAdd(CommandSender sender, ProtectedRegion region, RegionType type) {
public AddResult checkRegionAdd(CommandSender sender, ProtectedRegion region, World world, RegionType type) {
Player player = null;
if(sender instanceof Player) {
player = (Player)sender;
@ -383,7 +385,11 @@ public class FileManager extends Manager {
}
GeneralRegion asRegion = plugin.getFileManager().getRegion(region.getId());
if(asRegion != null) {
return AddResult.ALREADYADDED;
if(asRegion.getWorld().equals(world)) {
return AddResult.ALREADYADDED;
} else {
return AddResult.ALREADYADDEDOTHERWORLD;
}
} else if(plugin.getFileManager().isBlacklisted(region.getId())) {
return AddResult.BLACKLISTED;
} else {

View File

@ -33,7 +33,14 @@ import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public abstract class GeneralRegion implements GeneralRegionInterface, Comparable<GeneralRegion>, ReplacementProvider {
static final AreaShop plugin = AreaShop.getInstance();

View File

@ -323,6 +323,7 @@ setduration-successRemoved: "Duration of %lang:region% has been removed, it will
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."
setup-alreadyBuySign: "The region you specified is already added to AreaShop as a buy region, add signs with [as] on the first line or '/as addsign'."
setup-noDuration: "You did not specify how long the region can be rented, do this on the third line."
setup-wrongDuration: "The time specified is not in the correct format, example: 1 day."
@ -411,6 +412,7 @@ add-help: "/as add <rent|buy> [region] [world]."
add-noPermission: "You don't have permission to add a region to AreaShop."
add-success: "Added as %0%: [gray]%1%."
add-failed: "Already registered: [gray]%0%."
add-failedOtherWorld: "Already registered from another world: [gray]%0%."
add-blacklisted: "On the blacklist: [gray]%0%."
add-specifyWorld: "Specify the world of the region when using from console."
add-incorrectWorld: "World '%0%' not found, try again (case-sensitive)."