Major command changes that don't work yet.

This commit is contained in:
MattBDev
2019-07-05 20:46:48 -04:00
parent ffc2092d93
commit 8108d0a936
399 changed files with 13558 additions and 7985 deletions

View File

@@ -19,26 +19,28 @@
package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.bukkit.BukkitTextAdapter.reduceToText;
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 java.util.Optional;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.inject.InjectedValueStore;
import org.enginehub.piston.inject.Key;
import org.enginehub.piston.inject.MapBackedValueStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 +49,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 reduceToText(mapping.get().getDescription());
} else {
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return "Help text not available";
@@ -58,10 +60,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 reduceToText(mapping.get().getFullHelp());
} else {
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return "Help text not available";
@@ -70,11 +71,12 @@ 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()) {
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context ->
Optional.of(plugin.wrapCommandSender(sender)));
return mapping.get().getCondition().satisfied(store);
} else {
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return false;