Re-implemented the region spawn location flag.

This commit is contained in:
sk89q 2011-04-02 17:21:05 -07:00
parent c0be10ad94
commit deba6c79f3
4 changed files with 69 additions and 51 deletions

View File

@ -24,6 +24,7 @@
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
@ -53,4 +54,8 @@ public static Player matchSinglePlayer(Server server, String name) {
return players.get(0); return players.get(0);
} }
public static Location toLocation(World world, Vector vec) {
return new Location(world, vec.getX(), vec.getY(), vec.getZ());
}
} }

View File

@ -21,6 +21,7 @@
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector; import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.util.Iterator; import java.util.Iterator;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -40,6 +41,7 @@
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag.RegionGroup;
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;
@ -521,37 +523,41 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
} }
} }
/*
@Override @Override
public void onPlayerRespawn(PlayerRespawnEvent event) { public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Location location = player.getLocation(); Location location = player.getLocation();
ApplicableRegionSet regions = plugin.getGlobalRegionManager().get( ConfigurationManager cfg = plugin.getGlobalConfiguration();
player.getWorld().getName()).getApplicableRegions( WorldConfiguration wcfg = cfg.get(player.getWorld());
BukkitUtil.toVector(location));
if (wcfg.useRegions) {
Location spawn = regions.getLocationFlag(DefaultFlag.SPAWN_LOC, true).getValue(player.getServer()); Vector pt = toVector(location);
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (spawn != null) { ApplicableRegionSet set = mgr.getApplicableRegions(pt);
RegionGroup spawnconfig = regions.getRegionGroupFlag(DefaultFlag.SPAWN_PERM, true).getValue();
if (spawnconfig != null) { Vector spawn = set.getFlag(DefaultFlag.SPAWN_LOC);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (spawn != null) {
RegionGroup group = set.getFlag(DefaultFlag.SPAWN_PERM);
Location spawnLoc = BukkitUtil.toLocation(player.getWorld(), spawn);
if (spawnconfig == RegionGroup.OWNER) { if (group != null) {
if (regions.isOwner(localPlayer)) { LocalPlayer localPlayer = plugin.wrapPlayer(player);
event.setRespawnLocation(spawn);
} if (group == RegionGroup.OWNERS) {
} else if (spawnconfig == RegionGroup.MEMBER) { if (set.isOwnerOfAll(localPlayer)) {
if (regions.isMember(localPlayer)) { event.setRespawnLocation(spawnLoc);
event.setRespawnLocation(spawn); }
} else if (group == RegionGroup.MEMBERS) {
if (set.isMemberOfAll(localPlayer)) {
event.setRespawnLocation(spawnLoc);
}
} }
} else { } else {
event.setRespawnLocation(spawn); event.setRespawnLocation(spawnLoc);
} }
} else {
event.setRespawnLocation(spawn);
} }
} }
}*/ }
} }

View File

@ -45,9 +45,9 @@ public final class DefaultFlag {
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay"); public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay");
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount"); public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount");
public static final VectorFlag TELE_LOC = new VectorFlag("teleport-loc"); public static final VectorFlag TELE_LOC = new VectorFlag("teleport-loc");
public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-groups"); public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-group");
public static final VectorFlag SPAWN_LOC = new VectorFlag("teleport-location"); public static final VectorFlag SPAWN_LOC = new VectorFlag("spawn-location");
public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-groups"); public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-group");
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable"); public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
public static final DoubleFlag PRICE = new DoubleFlag("price"); public static final DoubleFlag PRICE = new DoubleFlag("price");

View File

@ -18,10 +18,6 @@
*/ */
package com.sk89q.worldguard.protection.flags; package com.sk89q.worldguard.protection.flags;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
@ -29,7 +25,12 @@
* *
* @author sk89q * @author sk89q
*/ */
public class RegionGroupFlag extends Flag<Set<String>> { public class RegionGroupFlag extends Flag<RegionGroupFlag.RegionGroup> {
public static enum RegionGroup {
MEMBERS,
OWNERS
}
public RegionGroupFlag(String name, char legacyCode) { public RegionGroupFlag(String name, char legacyCode) {
super(name, legacyCode); super(name, legacyCode);
@ -40,36 +41,42 @@ public RegionGroupFlag(String name) {
} }
@Override @Override
public Set<String> parseInput(WorldGuardPlugin plugin, CommandSender sender, public RegionGroup parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat { String input) throws InvalidFlagFormat {
Set<String> list = new HashSet<String>(); input = input.trim();
for (String i : input.split(",")) { if (input.equalsIgnoreCase("members") || input.equalsIgnoreCase("member")) {
list.add(i.toLowerCase()); return RegionGroup.MEMBERS;
} else if (input.equalsIgnoreCase("owners") || input.equalsIgnoreCase("owner")) {
return RegionGroup.OWNERS;
} else if (input.equalsIgnoreCase("everyone") || input.equalsIgnoreCase("anyone")) {
return null;
} else {
throw new InvalidFlagFormat("Not none/allow/deny: " + input);
} }
return list;
} }
@Override @Override
public Set<String> unmarshal(Object o) { public RegionGroup unmarshal(Object o) {
if (o instanceof List) { String str = o.toString();
List<?> raw = (List<?>) o; if (str.equalsIgnoreCase("members")) {
Set<String> list = new HashSet<String>(); return RegionGroup.MEMBERS;
} else if (str.equalsIgnoreCase("owners")) {
for (Object i : raw) { return RegionGroup.OWNERS;
list.add(i.toString().toLowerCase()); } else {
} return null;
return list;
} }
return null;
} }
@Override @Override
public Object marshal(Set<String> o) { public Object marshal(RegionGroup o) {
return null; if (o == RegionGroup.MEMBERS) {
return "members";
} else if (o == RegionGroup.OWNERS) {
return "owners";
} else {
return null;
}
} }
} }