Implement suggestions for Bukkit + Sponge

This commit is contained in:
Kenzie Togami
2019-05-05 22:06:20 -07:00
committed by Kenzie Togami
parent 1c54a04fd1
commit 8a3e6a12b9
15 changed files with 295 additions and 133 deletions

View File

@ -80,36 +80,6 @@ public class WorldEditListener implements Listener {
WorldEdit.getInstance().getSessionManager().get(plugin.wrapPlayer(event.getPlayer()));
}
/**
* Called when a player attempts to use a command
*
* @param event Relevant event details
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String[] split = event.getMessage().split(" ");
if (split.length > 0) {
split[0] = split[0].substring(1);
split = plugin.getWorldEdit().getPlatformManager().getPlatformCommandManager().commandDetection(split);
}
final String newMessage = "/" + StringUtil.joinString(split, " ");
if (!newMessage.equals(event.getMessage())) {
event.setMessage(newMessage);
plugin.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (!event.getMessage().isEmpty()) {
plugin.getServer().dispatchCommand(event.getPlayer(), event.getMessage().substring(1));
}
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandSendEvent event) {
InjectedValueStore store = MapBackedValueStore.create();

View File

@ -37,6 +37,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.command.CommandUtil;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockCategory;
@ -313,9 +314,10 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + cmd.getName();
CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
String arguments = Joiner.on(" ").join(split);
CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), arguments);
getWorldEdit().getEventBus().post(event);
return event.getSuggestions();
return CommandUtil.fixSuggestions(arguments, event.getSuggestions());
}
/**