Fix fallback command registration (worldedit bug)

This commit is contained in:
Jesse Boyd 2017-07-17 23:51:01 +10:00
parent 6b6f285972
commit 8c6e24a3e5
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 54 additions and 0 deletions

View File

@ -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) {

View File

@ -0,0 +1,52 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}