mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-25 18:47:44 +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.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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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));
|
|
||||||
|
|
||||||
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) {
|
if (spawn != null) {
|
||||||
RegionGroup spawnconfig = regions.getRegionGroupFlag(DefaultFlag.SPAWN_PERM, true).getValue();
|
RegionGroup group = set.getFlag(DefaultFlag.SPAWN_PERM);
|
||||||
if (spawnconfig != null) {
|
Location spawnLoc = BukkitUtil.toLocation(player.getWorld(), spawn);
|
||||||
|
|
||||||
|
if (group != null) {
|
||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||||
|
|
||||||
if (spawnconfig == RegionGroup.OWNER) {
|
if (group == RegionGroup.OWNERS) {
|
||||||
if (regions.isOwner(localPlayer)) {
|
if (set.isOwnerOfAll(localPlayer)) {
|
||||||
event.setRespawnLocation(spawn);
|
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 {
|
} else {
|
||||||
event.setRespawnLocation(spawn);
|
event.setRespawnLocation(spawnLoc);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
event.setRespawnLocation(spawn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
|
|
||||||
|
@ -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 list;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user