From da8289f8ba52d0ce132edfea32567b3a38270cb1 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 25 Aug 2021 16:19:51 +0100 Subject: [PATCH] Fix #826 --- .../worldedit/bukkit/WorldEditListener.java | 25 +++++++++++++++++-- .../com/sk89q/worldedit/LocalSession.java | 22 +++++++++++++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java index dcb2802db..235a13ed1 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.bukkit; +import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.SessionIdleEvent; @@ -37,6 +38,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerCommandSendEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.EquipmentSlot; import org.enginehub.piston.CommandManager; @@ -68,10 +70,29 @@ public class WorldEditListener implements Listener { return; } - // this will automatically refresh their session, we don't have to do anything - WorldEdit.getInstance().getSessionManager().get(plugin.wrapPlayer(event.getPlayer())); + //FAWE start - correctly handle refreshing LocalSession + Player player = plugin.wrapPlayer(event.getPlayer()); + LocalSession session; + if ((session = WorldEdit.getInstance().getSessionManager().getIfPresent(player)) == null) { + session = WorldEdit.getInstance().getSessionManager().get(player); + } + session.loadDefaults(player, true); } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onJoin(PlayerJoinEvent event) { + if (!plugin.getInternalPlatform().isHookingEvents()) { + return; + } + + Player player = plugin.wrapPlayer(event.getPlayer()); + LocalSession session; + if ((session = WorldEdit.getInstance().getSessionManager().getIfPresent(player)) != null) { + session.loadDefaults(player, true); + } + } + //FAWE end + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerCommandSend(PlayerCommandSendEvent event) { InjectedValueStore store = MapBackedValueStore.create(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 711e1ae29..819e6b375 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -1071,10 +1071,26 @@ public class LocalSession implements TextureHolder { */ @Nullable @Deprecated - public Tool getTool(ItemType item) { + //FAWE start - refresh wand item if permissions change + public Tool getTool(ItemType item, Player player) { + Tool tool; synchronized (this.tools) { - return tools.get(item.getInternalId()); + tool = tools.get(item.getInternalId()); } + if (tool == SelectionWand.INSTANCE && !SelectionWand.INSTANCE.canUse(player)) { + tools.remove(wandItem.getInternalId()); + loadDefaults(player, true); // Permissions have changed so redo the player's current tools. + return null; + } + if (tool != null) { + return tool; + } else if (item.getInternalId() == wandItem.getInternalId() && SelectionWand.INSTANCE.canUse(player)) { + loadDefaults(player, true); // Permissions have changed so redo the player's current tools. + return SelectionWand.INSTANCE; + } else { + return null; + } + //FAWE end } //FAWE start @@ -1098,7 +1114,7 @@ public class LocalSession implements TextureHolder { return tool; } } - return getTool(item.getType()); + return getTool(item.getType(), player); } public void loadDefaults(Actor actor, boolean force) {