2014-06-28 23:30:02 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2014-06-28 23:30:02 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* 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 General Public License for more details.
|
2014-06-28 23:30:02 +00:00
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2014-06-28 23:30:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.bukkit;
|
|
|
|
|
|
|
|
import com.sk89q.bukkit.util.CommandInspector;
|
2019-11-18 09:50:52 +00:00
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
2014-06-28 23:30:02 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2021-03-29 13:29:16 +00:00
|
|
|
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2014-06-28 23:30:02 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2019-07-06 00:46:48 +00:00
|
|
|
import org.enginehub.piston.CommandManager;
|
|
|
|
import org.enginehub.piston.inject.InjectedValueStore;
|
|
|
|
import org.enginehub.piston.inject.Key;
|
|
|
|
import org.enginehub.piston.inject.MapBackedValueStore;
|
2014-06-28 23:30:02 +00:00
|
|
|
|
2020-10-05 17:41:41 +00:00
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
import static com.sk89q.worldedit.util.formatting.WorldEditText.reduceToText;
|
|
|
|
|
2014-06-28 23:30:02 +00:00
|
|
|
class BukkitCommandInspector implements CommandInspector {
|
|
|
|
|
2021-03-29 13:29:16 +00:00
|
|
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
2014-06-28 23:30:02 +00:00
|
|
|
private final WorldEditPlugin plugin;
|
2019-07-06 00:46:48 +00:00
|
|
|
private final CommandManager dispatcher;
|
2014-06-28 23:30:02 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
BukkitCommandInspector(WorldEditPlugin plugin, CommandManager dispatcher) {
|
2014-06-28 23:30:02 +00:00
|
|
|
checkNotNull(plugin);
|
|
|
|
checkNotNull(dispatcher);
|
|
|
|
this.plugin = plugin;
|
|
|
|
this.dispatcher = dispatcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getShortText(Command command) {
|
2019-07-06 00:46:48 +00:00
|
|
|
Optional<org.enginehub.piston.Command> mapping = dispatcher.getCommand(command.getName());
|
|
|
|
if (mapping.isPresent()) {
|
2019-11-18 09:50:52 +00:00
|
|
|
return reduceToText(mapping.get().getDescription(), WorldEdit.getInstance().getConfiguration().defaultLocale);
|
2014-06-28 23:30:02 +00:00
|
|
|
} else {
|
2021-03-29 13:29:16 +00:00
|
|
|
LOGGER.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
|
2014-06-28 23:30:02 +00:00
|
|
|
return "Help text not available";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getFullText(Command command) {
|
2019-07-06 00:46:48 +00:00
|
|
|
Optional<org.enginehub.piston.Command> mapping = dispatcher.getCommand(command.getName());
|
|
|
|
if (mapping.isPresent()) {
|
2019-11-18 09:50:52 +00:00
|
|
|
return reduceToText(mapping.get().getFullHelp(), WorldEdit.getInstance().getConfiguration().defaultLocale);
|
2014-06-28 23:30:02 +00:00
|
|
|
} else {
|
2021-03-29 13:29:16 +00:00
|
|
|
LOGGER.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
|
2014-06-28 23:30:02 +00:00
|
|
|
return "Help text not available";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean testPermission(CommandSender sender, Command command) {
|
2019-07-06 00:46:48 +00:00
|
|
|
Optional<org.enginehub.piston.Command> mapping = dispatcher.getCommand(command.getName());
|
|
|
|
if (mapping.isPresent()) {
|
|
|
|
InjectedValueStore store = MapBackedValueStore.create();
|
|
|
|
store.injectValue(Key.of(Actor.class), context ->
|
2021-07-24 15:34:05 +00:00
|
|
|
Optional.of(plugin.wrapCommandSender(sender)));
|
2019-07-06 00:46:48 +00:00
|
|
|
return mapping.get().getCondition().satisfied(store);
|
2014-06-28 23:30:02 +00:00
|
|
|
} else {
|
2021-03-29 13:29:16 +00:00
|
|
|
LOGGER.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
|
2014-06-28 23:30:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2014-06-28 23:30:02 +00:00
|
|
|
}
|