From 2ba51e66e01024f069ce6079f07bb7e1dad8474b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Feb 2024 21:48:14 +0100 Subject: [PATCH] Fix BindCommand --- .../bausystem/features/util/BindCommand.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java index ab213c83..c0190486 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/BindCommand.java @@ -1,9 +1,17 @@ package de.steamwar.bausystem.features.util; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.event.platform.CommandEvent; +import com.sk89q.worldedit.extension.platform.Actor; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.script.ScriptCommand; import de.steamwar.bausystem.features.script.ScriptRunner; +import de.steamwar.bausystem.features.world.WorldEditListener; +import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; @@ -20,14 +28,18 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; +import org.luaj.vm2.LuaValue; import java.lang.reflect.Field; import java.util.*; +import java.util.logging.Level; import java.util.stream.Collectors; @Linked public class BindCommand extends SWCommand implements Listener { + private static final boolean hasFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null; + @Linked public static class UnBindCommand extends SWCommand { @@ -107,7 +119,21 @@ public class BindCommand extends SWCommand implements Listener { PlayerCommandPreprocessEvent playerCommandPreprocessEvent = new PlayerCommandPreprocessEvent(event.getPlayer(), "/" + command); Bukkit.getPluginManager().callEvent(playerCommandPreprocessEvent); if (playerCommandPreprocessEvent.isCancelled()) return; - Bukkit.getServer().dispatchCommand(event.getPlayer(), command); + + Bukkit.getLogger().log(Level.INFO, event.getPlayer().getName() + " dispatched command: " + command); + String[] commandSplit = command.split(" "); + if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) { + if (!Permission.WORLDEDIT.hasPermission(event.getPlayer())) { + return; + } + EditSession editSession = WorldEditUtils.getEditSession(event.getPlayer()); + Actor actor = BukkitAdapter.adapt(event.getPlayer()); + WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession)); + editSession.flushSession(); + WorldEditUtils.addToPlayer(event.getPlayer(), editSession); + } else { + Bukkit.getServer().dispatchCommand(event.getPlayer(), command); + } }, 1); }