Godmode flag now works correctly with essentials

This commit is contained in:
isokissa3 2018-04-12 22:08:22 +03:00
parent 9edee9bf5b
commit 75be12e7db
2 changed files with 33 additions and 7 deletions

View file

@ -20,7 +20,7 @@ public class EssentialsListener implements Listener
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onGodStatusChangeEvent(GodStatusChangeEvent event) public void onGodStatusChangeEvent(GodStatusChangeEvent event)
{ {
IUser user = event.getController(); IUser user = event.getAffected();
Player player = user.getBase(); Player player = user.getBase();
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation()); ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());

View file

@ -1,12 +1,17 @@
package net.goldtreeservers.worldguardextraflags.wg.handlers; package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State; 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.Session;
import com.sk89q.worldguard.session.handler.Handler; import com.sk89q.worldguard.session.handler.Handler;
@ -35,13 +40,24 @@ public class GodmodeFlagHandler extends Handler
super(session); super(session);
} }
@Nullable
@Override @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<ProtectedRegion> entered, Set<ProtectedRegion> 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) if (state != null)
{ {
this.isGodmodeEnabled = (state == State.ALLOW ? true : false); this.isGodmodeEnabled = (state == State.ALLOW ? true : false);
@ -71,13 +87,23 @@ public class GodmodeFlagHandler extends Handler
{ {
if (this.originalEssentialsGodmode != null) if (this.originalEssentialsGodmode != null)
{ {
user.setGodModeEnabled(this.isGodmodeEnabled); user.setGodModeEnabled(this.originalEssentialsGodmode);
this.originalEssentialsGodmode = null; 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;
} }
} }