diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EssentialsListener.java b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EssentialsListener.java index be97191..c39b54f 100644 --- a/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EssentialsListener.java +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EssentialsListener.java @@ -20,7 +20,7 @@ public class EssentialsListener implements Listener @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onGodStatusChangeEvent(GodStatusChangeEvent event) { - IUser user = event.getController(); + IUser user = event.getAffected(); Player player = user.getBase(); ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation()); diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GodmodeFlagHandler.java b/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GodmodeFlagHandler.java index 11c8082..d1dbac1 100644 --- a/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GodmodeFlagHandler.java +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GodmodeFlagHandler.java @@ -1,12 +1,17 @@ package net.goldtreeservers.worldguardextraflags.wg.handlers; +import java.util.Set; + import javax.annotation.Nullable; +import org.bukkit.Location; import org.bukkit.entity.Player; import com.earth2me.essentials.User; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.StateFlag.State; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.sk89q.worldguard.session.MoveType; import com.sk89q.worldguard.session.Session; import com.sk89q.worldguard.session.handler.Handler; @@ -35,13 +40,24 @@ public class GodmodeFlagHandler extends Handler super(session); } - @Nullable @Override - public State getInvincibility(Player player) + public void initialize(Player player, Location current, ApplicableRegionSet set) { - ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation()); + State state = WorldGuardUtils.queryState(player, current.getWorld(), set.getRegions(), Flags.GODMODE); + this.handleValue(player, state); + } + + @Override + public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) + { + State state = WorldGuardUtils.queryState(player, to.getWorld(), toSet.getRegions(), Flags.GODMODE); + this.handleValue(player, state); - State state = WorldGuardUtils.queryState(player, player.getWorld(), regions.getRegions(), Flags.GODMODE); + return true; + } + + private void handleValue(Player player, State state) + { if (state != null) { this.isGodmodeEnabled = (state == State.ALLOW ? true : false); @@ -71,13 +87,23 @@ public class GodmodeFlagHandler extends Handler { if (this.originalEssentialsGodmode != null) { - user.setGodModeEnabled(this.isGodmodeEnabled); + user.setGodModeEnabled(this.originalEssentialsGodmode); this.originalEssentialsGodmode = null; } } } + } + + @Nullable + @Override + public State getInvincibility(Player player) + { + if (this.isGodmodeEnabled != null) + { + return this.isGodmodeEnabled ? State.ALLOW : State.DENY; + } - return state; + return null; } }