Implement non-economy 'buying' of regions via addowner

This commit is contained in:
Wizjany 2011-10-08 00:30:25 -04:00
parent ecef9c9792
commit 2ec6f04763

View File

@ -31,6 +31,8 @@
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.util.RegionUtil;
@ -100,6 +102,15 @@ public static void addOwner(CommandContext args, WorldGuardPlugin plugin,
throw new CommandException("Could not find a region by that ID.");
}
Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
DefaultDomain owners = region.getOwners();
if (flag != null && flag == true && owners != null && owners.size() == 0) {
if (mgr.getRegionCountOfPlayer(localPlayer)
>= plugin.getGlobalStateManager().get(world).maxRegionCountPerPlayer) {
throw new CommandException("You already own the maximum allowed amount of regions.");
}
plugin.checkPermission(sender, "worldguard.region.addowner.unclaimed." + id.toLowerCase());
} else {
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addowner.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
@ -107,6 +118,7 @@ public static void addOwner(CommandContext args, WorldGuardPlugin plugin,
} else {
plugin.checkPermission(sender, "worldguard.region.addowner." + id.toLowerCase());
}
}
RegionUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);