mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-02 17:09:35 +01:00
Re-implemented the region spawn location flag.
This commit is contained in:
parent
c0be10ad94
commit
deba6c79f3
@ -24,6 +24,7 @@
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
@ -53,4 +54,8 @@ public static Player matchSinglePlayer(Server server, String name) {
|
||||
return players.get(0);
|
||||
}
|
||||
|
||||
public static Location toLocation(World world, Vector vec) {
|
||||
return new Location(world, vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
import java.util.Iterator;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
@ -40,6 +41,7 @@
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
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.regions.ProtectedRegion;
|
||||
|
||||
@ -521,37 +523,41 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Location location = player.getLocation();
|
||||
|
||||
ApplicableRegionSet regions = plugin.getGlobalRegionManager().get(
|
||||
player.getWorld().getName()).getApplicableRegions(
|
||||
BukkitUtil.toVector(location));
|
||||
ConfigurationManager cfg = plugin.getGlobalConfiguration();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
Location spawn = regions.getLocationFlag(DefaultFlag.SPAWN_LOC, true).getValue(player.getServer());
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(location);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
Vector spawn = set.getFlag(DefaultFlag.SPAWN_LOC);
|
||||
|
||||
if (spawn != null) {
|
||||
RegionGroup spawnconfig = regions.getRegionGroupFlag(DefaultFlag.SPAWN_PERM, true).getValue();
|
||||
if (spawnconfig != null) {
|
||||
RegionGroup group = set.getFlag(DefaultFlag.SPAWN_PERM);
|
||||
Location spawnLoc = BukkitUtil.toLocation(player.getWorld(), spawn);
|
||||
|
||||
if (group != null) {
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
if (spawnconfig == RegionGroup.OWNER) {
|
||||
if (regions.isOwner(localPlayer)) {
|
||||
event.setRespawnLocation(spawn);
|
||||
if (group == RegionGroup.OWNERS) {
|
||||
if (set.isOwnerOfAll(localPlayer)) {
|
||||
event.setRespawnLocation(spawnLoc);
|
||||
}
|
||||
} else if (group == RegionGroup.MEMBERS) {
|
||||
if (set.isMemberOfAll(localPlayer)) {
|
||||
event.setRespawnLocation(spawnLoc);
|
||||
}
|
||||
} else if (spawnconfig == RegionGroup.MEMBER) {
|
||||
if (regions.isMember(localPlayer)) {
|
||||
event.setRespawnLocation(spawn);
|
||||
}
|
||||
} else {
|
||||
event.setRespawnLocation(spawn);
|
||||
}
|
||||
} else {
|
||||
event.setRespawnLocation(spawn);
|
||||
event.setRespawnLocation(spawnLoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -45,9 +45,9 @@ public final class DefaultFlag {
|
||||
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay");
|
||||
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount");
|
||||
public static final VectorFlag TELE_LOC = new VectorFlag("teleport-loc");
|
||||
public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-groups");
|
||||
public static final VectorFlag SPAWN_LOC = new VectorFlag("teleport-location");
|
||||
public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-groups");
|
||||
public static final RegionGroupFlag TELE_PERM = new RegionGroupFlag("teleport-group");
|
||||
public static final VectorFlag SPAWN_LOC = new VectorFlag("spawn-location");
|
||||
public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-group");
|
||||
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
|
||||
public static final DoubleFlag PRICE = new DoubleFlag("price");
|
||||
|
||||
|
@ -18,10 +18,6 @@
|
||||
*/
|
||||
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 com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
@ -29,7 +25,12 @@
|
||||
*
|
||||
* @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) {
|
||||
super(name, legacyCode);
|
||||
@ -40,36 +41,42 @@ public RegionGroupFlag(String name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
public RegionGroup parseInput(WorldGuardPlugin plugin, CommandSender sender,
|
||||
String input) throws InvalidFlagFormat {
|
||||
Set<String> list = new HashSet<String>();
|
||||
input = input.trim();
|
||||
|
||||
for (String i : input.split(",")) {
|
||||
list.add(i.toLowerCase());
|
||||
if (input.equalsIgnoreCase("members") || input.equalsIgnoreCase("member")) {
|
||||
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
|
||||
public Set<String> unmarshal(Object o) {
|
||||
if (o instanceof List) {
|
||||
List<?> raw = (List<?>) o;
|
||||
Set<String> list = new HashSet<String>();
|
||||
|
||||
for (Object i : raw) {
|
||||
list.add(i.toString().toLowerCase());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public RegionGroup unmarshal(Object o) {
|
||||
String str = o.toString();
|
||||
if (str.equalsIgnoreCase("members")) {
|
||||
return RegionGroup.MEMBERS;
|
||||
} else if (str.equalsIgnoreCase("owners")) {
|
||||
return RegionGroup.OWNERS;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(Set<String> o) {
|
||||
public Object marshal(RegionGroup o) {
|
||||
if (o == RegionGroup.MEMBERS) {
|
||||
return "members";
|
||||
} else if (o == RegionGroup.OWNERS) {
|
||||
return "owners";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user