diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index de8d79f2..3f995e02 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -30,6 +30,7 @@ import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.TaskManager; +import com.sk89q.bukkit.util.FallbackRegistrationListener; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.EditSessionBlockChangeDelegate; import com.sk89q.worldedit.bukkit.WorldEditPlugin; @@ -76,6 +77,7 @@ public class FaweBukkit implements IFawe, Listener { setupInjector(); com.sk89q.worldedit.bukkit.BukkitPlayer.inject(); // Fixes BukkitWorld.inject(); // Fixes + FallbackRegistrationListener.inject(); // Fixes try { new BrushListener(plugin); } catch (Throwable e) { diff --git a/bukkit/src/main/java/com/sk89q/bukkit/util/FallbackRegistrationListener.java b/bukkit/src/main/java/com/sk89q/bukkit/util/FallbackRegistrationListener.java new file mode 100644 index 00000000..ab5a28ca --- /dev/null +++ b/bukkit/src/main/java/com/sk89q/bukkit/util/FallbackRegistrationListener.java @@ -0,0 +1,52 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.bukkit.util; + +import com.sk89q.worldedit.WorldEdit; +import org.bukkit.command.CommandMap; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class FallbackRegistrationListener implements Listener { + + private final CommandMap commandRegistration; + + public FallbackRegistrationListener(CommandMap commandRegistration) { + this.commandRegistration = commandRegistration; + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + boolean doubleSlash = WorldEdit.getInstance().getConfiguration().noDoubleSlash; + String msg = event.getMessage(); + if (doubleSlash || !msg.startsWith("/")) { + msg = "/" + msg; + } + if (commandRegistration.dispatch(event.getPlayer(), msg)) { + event.setCancelled(true); + } + } + + public static Class inject() { + return FallbackRegistrationListener.class; + } + +}