mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-27 21:15:57 +01:00
Added onPlayerRespawn and registered listener
This commit is contained in:
parent
8127e56603
commit
55210caceb
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user