Added onPlayerRespawn and registered listener

This commit is contained in:
Valentin Churavy 2011-02-25 23:10:45 +01:00
parent 8127e56603
commit 55210caceb
2 changed files with 40 additions and 2 deletions

View File

@ -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);
}
}
}

View File

@ -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;
}
}
}