From 55210caceb0bd1eed0c8ce384e53f6bba6ebe31a Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Fri, 25 Feb 2011 23:10:45 +0100 Subject: [PATCH] Added onPlayerRespawn and registered listener --- .../bukkit/WorldGuardPlayerListener.java | 34 +++++++++++++++++++ .../worldguard/bukkit/WorldGuardPlugin.java | 8 +++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java index 5d219293..31c7b68c 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java @@ -20,6 +20,7 @@ package com.sk89q.worldguard.bukkit; import com.nijikokun.bukkit.iConomy.iConomy; +import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.regionmanager.RegionManager; import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent; import org.bukkit.entity.Item; @@ -32,6 +33,8 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; import com.sk89q.worldguard.protection.regions.AreaFlags; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; + import static com.sk89q.worldguard.bukkit.BukkitUtil.*; /** @@ -247,5 +250,36 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) { } } } + + public void onPlayerRespawn(PlayerRespawnEvent event) { + Player player = event.getPlayer(); + Location location = player.getLocation(); + + WorldGuardConfiguration cfg = plugin.getWgConfiguration(); + + ApplicableRegionSet regions = plugin.getGlobalRegionManager().getRegionManager( + player.getWorld().getName()).getApplicableRegions( + BukkitUtil.toVector(location)); + + BukkitPlayer localPlayer = BukkitPlayer.wrapPlayer(cfg, player); + ProtectedRegion childRegion = regions.getChildRegion(); + + AreaFlags flags = childRegion.getFlags(); + + Boolean owner = flags.getBooleanFlag("spawn", "settings.owner", true); + Boolean member = flags.getBooleanFlag("spawn", "settings.owner", true); + Boolean all = flags.getBooleanFlag("spawn", "settings.owner", false); + + Location spawn = flags.getLocationFlag(player.getServer(), "spawn"); + + if(childRegion.isOwner(localPlayer) && owner ){ + player.teleportTo(spawn); + } else if (childRegion.isMember(localPlayer) && member) { + player.teleportTo(spawn); + } else if (all){ + player.teleportTo(spawn); + } + + } } diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 12e89117..3d676034 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -44,6 +44,8 @@ public class WorldGuardPlugin extends JavaPlugin { new WorldGuardBlockListener(this); private final WorldGuardEntityListener entityListener = new WorldGuardEntityListener(this); + private final WorldGuardServerListener serverListener = + new WorldGuardServerListener(this); private final CommandHandler commandHandler = new CommandHandler(this); private final GlobalRegionManager globalRegionManager = new GlobalRegionManager(this); @@ -100,6 +102,9 @@ private void registerEvents() { pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.High, this); + + pm.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Priority.Monitor, this); // 25 equals about 1s real time this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimedFlagsTimer(this), 25 * 5, 25 * 5); @@ -130,5 +135,4 @@ public GlobalRegionManager getGlobalRegionManager() { public WorldGuardConfiguration getWgConfiguration() { return configuration; } - -} +} \ No newline at end of file