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:
isokissa3 2018-04-24 17:45:32 +03:00
parent aea7e4c3df
commit 3c3fc1f660

View file

@ -25,6 +25,7 @@ import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.session.Session;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.essentials.EssentialsUtils;
@ -125,23 +126,43 @@ public class PlayerListener implements Listener
{
Player player = event.getPlayer();
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
if (value != null)
Session wgSession = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().getIfPresent(player);
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()
{
@Override
public void run()
{
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
if (value != null)
{
player.setAllowFlight(value);
}
PlayerListener.this.checkFlyStatus(player);
}
}.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
/*@EventHandler(priority = EventPriority.LOWEST)