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.minecraft.util.commands.CommandException;
import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; 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.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.util.RegionUtil; import com.sk89q.worldguard.util.RegionUtil;
@ -99,13 +101,23 @@ public static void addOwner(CommandContext args, WorldGuardPlugin plugin,
if (region == null) { if (region == null) {
throw new CommandException("Could not find a region by that ID."); throw new CommandException("Could not find a region by that ID.");
} }
if (region.isOwner(localPlayer)) { Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
plugin.checkPermission(sender, "worldguard.region.addowner.own." + id.toLowerCase()); DefaultDomain owners = region.getOwners();
} else if (region.isMember(localPlayer)) { if (flag != null && flag == true && owners != null && owners.size() == 0) {
plugin.checkPermission(sender, "worldguard.region.addowner.member." + id.toLowerCase()); 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 { } else {
plugin.checkPermission(sender, "worldguard.region.addowner." + id.toLowerCase()); if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addowner.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addowner.member." + id.toLowerCase());
} else {
plugin.checkPermission(sender, "worldguard.region.addowner." + id.toLowerCase());
}
} }
RegionUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0); RegionUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);