mirror of
https://github.com/TotalFreedomMC/TF-WorldGuardExtraFlagsPlugin.git
synced 2024-12-30 19:14:34 +00:00
Fixed possible deadlock when game-mode flag is being used
When joining to region with game-mode flag set while initializing flag handlers PlayerGameModeChangeEvent is fired causing the plugin to try check the current status of fly flag to decide whenever can they fly or not. This causes issues as the intializers are being fired from the guava's LoadingCache causing the get to block, tho Guava actually prevents deadlocks and throws exception. The workaround is to check if the session is present at the moment and if not then scheduale it for next tick, otherwise we can continue
This commit is contained in:
parent
aea7e4c3df
commit
3c3fc1f660
1 changed files with 28 additions and 7 deletions
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.Location;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||||
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.session.Session;
|
||||||
|
|
||||||
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
|
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
|
||||||
import net.goldtreeservers.worldguardextraflags.essentials.EssentialsUtils;
|
import net.goldtreeservers.worldguardextraflags.essentials.EssentialsUtils;
|
||||||
|
@ -125,24 +126,44 @@ public class PlayerListener implements Listener
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
|
Session wgSession = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().getIfPresent(player);
|
||||||
if (value != null)
|
if (wgSession != null)
|
||||||
|
{
|
||||||
|
Boolean value = wgSession.getHandler(FlyFlagHandler.class).getCurrentValue();
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
PlayerListener.this.checkFlyStatus(player);
|
||||||
|
}
|
||||||
|
}.runTask(WorldGuardExtraFlagsPlugin.getPlugin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
new BukkitRunnable()
|
new BukkitRunnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
|
PlayerListener.this.checkFlyStatus(player);
|
||||||
if (value != null)
|
|
||||||
{
|
|
||||||
player.setAllowFlight(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.runTask(WorldGuardExtraFlagsPlugin.getPlugin());
|
}.runTask(WorldGuardExtraFlagsPlugin.getPlugin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkFlyStatus(Player player)
|
||||||
|
{
|
||||||
|
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
player.setAllowFlight(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Re-enable if needed and the plugin checks for cancelled events
|
//Re-enable if needed and the plugin checks for cancelled events
|
||||||
/*@EventHandler(priority = EventPriority.LOWEST)
|
/*@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerInteractEvent(PlayerInteractEvent event)
|
public void onPlayerInteractEvent(PlayerInteractEvent event)
|
||||||
|
|
Loading…
Reference in a new issue