Detach from permissible objects with a 1 tick delay after player quit to allow plugins listening on monitor to still access data (#1220)

This commit is contained in:
Luck
2018-09-20 11:07:20 +01:00
Unverified
parent 11a3ecbba0
commit 04e511026d
7 changed files with 54 additions and 89 deletions
@@ -40,6 +40,7 @@ import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerAsyncPreLoginEvent;
import cn.nukkit.event.player.PlayerLoginEvent;
import cn.nukkit.event.player.PlayerQuitEvent;
import cn.nukkit.scheduler.Task;
import java.util.Collections;
import java.util.HashSet;
@@ -179,33 +180,26 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent e) {
final Player player = e.getPlayer();
handleDisconnect(player.getUniqueId());
// Remove the custom permissible
try {
PermissibleInjector.unInject(player, true);
} catch (Exception ex) {
ex.printStackTrace();
}
// Handle auto op
if (this.plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
player.setOp(false);
}
// Register with the housekeeper, so the User's instance will stick
// around for a bit after they disconnect
this.plugin.getUserManager().getHouseKeeper().registerUsage(player.getUniqueId());
// force a clear of transient nodes
this.plugin.getBootstrap().getScheduler().executeAsync(() -> {
User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
if (user != null) {
user.clearTransientNodes();
// perform unhooking from nukkit objects 1 tick later.
// this allows plugins listening after us on MONITOR to still have intact permissions data
this.plugin.getBootstrap().getServer().getScheduler().scheduleDelayedTask(this.plugin.getBootstrap(), () -> {
// Remove the custom permissible
try {
PermissibleInjector.unInject(player, true);
} catch (Exception ex) {
ex.printStackTrace();
}
});
// remove their contexts cache
this.plugin.getContextManager().onPlayerQuit(player);
// Handle auto op
if (this.plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
player.setOp(false);
}
// remove their contexts cache
this.plugin.getContextManager().onPlayerQuit(player);
}, 1, true);
}
}