First attempt at integrating Piston as the only command system

This commit is contained in:
Kenzie Togami
2019-04-15 01:21:15 -07:00
parent da35b3c174
commit 267ccf2298
28 changed files with 493 additions and 389 deletions

View File

@@ -19,26 +19,29 @@
package com.sk89q.worldedit.bukkit;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Key;
import com.sk89q.bukkit.util.CommandInspector;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Description;
import com.sk89q.worldedit.util.command.Dispatcher;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.CommandParameters;
import org.enginehub.piston.NoInputCommandParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
class BukkitCommandInspector implements CommandInspector {
private static final Logger logger = LoggerFactory.getLogger(BukkitCommandInspector.class);
private final WorldEditPlugin plugin;
private final Dispatcher dispatcher;
private final CommandManager dispatcher;
BukkitCommandInspector(WorldEditPlugin plugin, Dispatcher dispatcher) {
BukkitCommandInspector(WorldEditPlugin plugin, CommandManager dispatcher) {
checkNotNull(plugin);
checkNotNull(dispatcher);
this.plugin = plugin;
@@ -47,9 +50,9 @@ class BukkitCommandInspector implements CommandInspector {
@Override
public String getShortText(Command command) {
CommandMapping mapping = dispatcher.get(command.getName());
if (mapping != null) {
return mapping.getDescription().getDescription();
Optional<org.enginehub.piston.Command> mapping = dispatcher.getCommand(command.getName());
if (mapping.isPresent()) {
return mapping.get().getDescription();
} else {
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return "Help text not available";
@@ -58,10 +61,9 @@ class BukkitCommandInspector implements CommandInspector {
@Override
public String getFullText(Command command) {
CommandMapping mapping = dispatcher.get(command.getName());
if (mapping != null) {
Description description = mapping.getDescription();
return "Usage: " + description.getUsage() + (description.getHelp() != null ? "\n" + description.getHelp() : "");
Optional<org.enginehub.piston.Command> mapping = dispatcher.getCommand(command.getName());
if (mapping.isPresent()) {
return mapping.get().getFullHelp();
} else {
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return "Help text not available";
@@ -70,11 +72,14 @@ class BukkitCommandInspector implements CommandInspector {
@Override
public boolean testPermission(CommandSender sender, Command command) {
CommandMapping mapping = dispatcher.get(command.getName());
if (mapping != null) {
CommandLocals locals = new CommandLocals();
locals.put(Actor.class, plugin.wrapCommandSender(sender));
return mapping.getCallable().testPermission(locals);
Optional<org.enginehub.piston.Command> mapping = dispatcher.getCommand(command.getName());
if (mapping.isPresent()) {
CommandParameters parameters = NoInputCommandParameters.builder()
.injectedValues(ImmutableMap.of(
Key.get(Actor.class), plugin.wrapCommandSender(sender)
))
.build();
return mapping.get().getCondition().satisfied(parameters);
} else {
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return false;