Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-10 05:20:04 +01:00
Register command permissions, integrate with the Bukkit help API
Help API support requires a fix in Bukkit to work fully Allow annotation-free registering of commands with other plugins
Dieser Commit ist enthalten in:
Ursprung
956b3dd02f
Commit
4328be282c
65
src/main/java/com/sk89q/bukkit/util/CommandInfo.java
Normale Datei
65
src/main/java/com/sk89q/bukkit/util/CommandInfo.java
Normale Datei
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2012 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.bukkit.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zml2008
|
||||||
|
*/
|
||||||
|
public class CommandInfo {
|
||||||
|
private final String[] aliases;
|
||||||
|
private final Object registeredWith;
|
||||||
|
private final String usage, desc;
|
||||||
|
private final String[] permissions;
|
||||||
|
|
||||||
|
public CommandInfo(String usage, String desc, String[] aliases, Object registeredWith) {
|
||||||
|
this(usage, desc, aliases, registeredWith, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandInfo(String usage, String desc, String[] aliases, Object registeredWith, String[] permissions) {
|
||||||
|
this.usage = usage;
|
||||||
|
this.desc = desc;
|
||||||
|
this.aliases = aliases;
|
||||||
|
this.permissions = permissions;
|
||||||
|
this.registeredWith = registeredWith;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getAliases() {
|
||||||
|
return aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return aliases[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsage() {
|
||||||
|
return usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getRegisteredWith() {
|
||||||
|
return registeredWith;
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
|
||||||
import com.sk89q.util.ReflectionUtil;
|
import com.sk89q.util.ReflectionUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@ -37,8 +36,13 @@ import org.bukkit.plugin.Plugin;
|
|||||||
* @author zml2008
|
* @author zml2008
|
||||||
*/
|
*/
|
||||||
public class CommandRegistration {
|
public class CommandRegistration {
|
||||||
private final Plugin plugin;
|
|
||||||
private final CommandExecutor executor;
|
static {
|
||||||
|
Bukkit.getServer().getHelpMap().registerHelpTopicFactory(DynamicPluginCommand.class, new DynamicPluginCommandHelpTopic.Factory());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Plugin plugin;
|
||||||
|
protected final CommandExecutor executor;
|
||||||
private CommandMap fallbackCommands;
|
private CommandMap fallbackCommands;
|
||||||
|
|
||||||
public CommandRegistration(Plugin plugin) {
|
public CommandRegistration(Plugin plugin) {
|
||||||
@ -49,15 +53,17 @@ public class CommandRegistration {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean registerAll(List<Command> registered) {
|
public boolean register(List<CommandInfo> registered) {
|
||||||
CommandMap commandMap = getCommandMap();
|
CommandMap commandMap = getCommandMap();
|
||||||
if (registered == null || commandMap == null) {
|
if (registered == null || commandMap == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (Command command : registered) {
|
for (CommandInfo command : registered) {
|
||||||
commandMap.register(plugin.getDescription().getName(),
|
DynamicPluginCommand cmd = new DynamicPluginCommand(command.getAliases(),
|
||||||
new DynamicPluginCommand(command.aliases(), command.desc(), "/" + command.aliases()[0] + " " + command.usage(), executor));
|
command.getDesc(), "/" + command.getAliases()[0] + " " + command.getUsage(), executor, command.getRegisteredWith());
|
||||||
|
cmd.setPermissions(command.getPermissions());
|
||||||
|
commandMap.register(plugin.getDescription().getName(), cmd);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,14 @@
|
|||||||
package com.sk89q.bukkit.util;
|
package com.sk89q.bukkit.util;
|
||||||
|
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
import com.sk89q.minecraft.util.commands.Command;
|
||||||
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||||
import com.sk89q.minecraft.util.commands.CommandsManager;
|
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandMap;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +47,21 @@ public class CommandsManagerRegistration extends CommandRegistration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean register(Class<?> clazz) {
|
public boolean register(Class<?> clazz) {
|
||||||
List<Command> registered = commands.registerAndReturn(clazz);
|
return registerAll(commands.registerAndReturn(clazz));
|
||||||
return registerAll(registered);
|
}
|
||||||
|
|
||||||
|
public boolean registerAll(List<Command> registered) {
|
||||||
|
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
|
||||||
|
for (Command command : registered) {
|
||||||
|
String[] permissions = null;
|
||||||
|
Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]);
|
||||||
|
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
|
||||||
|
permissions = cmdMethod.getAnnotation(CommandPermissions.class).value();
|
||||||
|
}
|
||||||
|
|
||||||
|
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions));
|
||||||
|
}
|
||||||
|
|
||||||
|
return register(toRegister);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.bukkit.util;
|
package com.sk89q.bukkit.util;
|
||||||
|
|
||||||
|
import com.sk89q.util.StringUtil;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -29,18 +30,36 @@ import java.util.Arrays;
|
|||||||
public class DynamicPluginCommand extends org.bukkit.command.Command {
|
public class DynamicPluginCommand extends org.bukkit.command.Command {
|
||||||
|
|
||||||
protected final CommandExecutor owner;
|
protected final CommandExecutor owner;
|
||||||
|
protected final Object registeredWith;
|
||||||
|
protected String[] permissions = new String[0];
|
||||||
|
|
||||||
public DynamicPluginCommand(String[] aliases, String desc, String usage, CommandExecutor owner) {
|
public DynamicPluginCommand(String[] aliases, String desc, String usage, CommandExecutor owner, Object registeredWith) {
|
||||||
super(aliases[0], desc, usage, Arrays.asList(aliases));
|
super(aliases[0], desc, usage, Arrays.asList(aliases));
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
this.registeredWith = registeredWith;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||||
return owner.onCommand(sender, this, label, args);
|
return owner.onCommand(sender, this, label, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getOwner() {
|
public Object getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getRegisteredWith() {
|
||||||
|
return registeredWith;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissions(String[] permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
if (permissions != null) {
|
||||||
|
super.setPermission(StringUtil.joinString(permissions, ";"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
112
src/main/java/com/sk89q/bukkit/util/DynamicPluginCommandHelpTopic.java
Normale Datei
112
src/main/java/com/sk89q/bukkit/util/DynamicPluginCommandHelpTopic.java
Normale Datei
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2012 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.bukkit.util;
|
||||||
|
|
||||||
|
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||||
|
import com.sk89q.wepif.PermissionsResolverManager;
|
||||||
|
import com.sk89q.wepif.WEPIFRuntimeException;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.help.HelpTopic;
|
||||||
|
import org.bukkit.help.HelpTopicFactory;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zml2008
|
||||||
|
*/
|
||||||
|
public class DynamicPluginCommandHelpTopic extends HelpTopic {
|
||||||
|
private final DynamicPluginCommand cmd;
|
||||||
|
|
||||||
|
public DynamicPluginCommandHelpTopic(DynamicPluginCommand cmd) {
|
||||||
|
this.cmd = cmd;
|
||||||
|
this.name = "/" + cmd.getName();
|
||||||
|
|
||||||
|
if (cmd.getRegisteredWith() instanceof CommandsManager) {
|
||||||
|
Map<String, String> helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getHelpMessages();
|
||||||
|
final String lookupName = cmd.getName().replaceAll("/", "");
|
||||||
|
if (helpText.containsKey(lookupName)) {
|
||||||
|
this.fullText = helpText.get(lookupName);
|
||||||
|
}
|
||||||
|
helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getCommands();
|
||||||
|
if (helpText.containsKey(cmd.getName())) {
|
||||||
|
final String shortText = helpText.get(cmd.getName());
|
||||||
|
if (this.fullText == null) {
|
||||||
|
this.fullText = this.name + " " + shortText;
|
||||||
|
}
|
||||||
|
this.shortText = shortText;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.shortText = cmd.getDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public boolean canSee(CommandSender player) {
|
||||||
|
if (cmd.getPermissions() != null && cmd.getPermissions().length > 0) {
|
||||||
|
if (cmd.getRegisteredWith() instanceof CommandsManager) {
|
||||||
|
try {
|
||||||
|
for (String perm : cmd.getPermissions()) {
|
||||||
|
if (((CommandsManager<Object>) cmd.getRegisteredWith()).hasPermission(player, perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// Doesn't take the CommandSender (Hooray for compile-time generics!), we have other methods at our disposal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (player instanceof OfflinePlayer) {
|
||||||
|
try {
|
||||||
|
for (String perm : cmd.getPermissions()) {
|
||||||
|
if (PermissionsResolverManager.getInstance().hasPermission((OfflinePlayer) player, perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (WEPIFRuntimeException e) {
|
||||||
|
// PermissionsResolverManager not initialized, eat it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String perm : cmd.getPermissions()) {
|
||||||
|
if (player.hasPermission(perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullText(CommandSender forWho) {
|
||||||
|
if (this.fullText == null || this.fullText.length() == 0) {
|
||||||
|
return getShortText();
|
||||||
|
} else {
|
||||||
|
return this.fullText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Factory implements HelpTopicFactory<DynamicPluginCommand> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HelpTopic createTopic(DynamicPluginCommand command) {
|
||||||
|
return new DynamicPluginCommandHelpTopic(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -35,12 +35,8 @@ public class FallbackRegistrationListener implements Listener {
|
|||||||
this.commandRegistration = commandRegistration;
|
this.commandRegistration = commandRegistration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (commandRegistration.dispatch(event.getPlayer(), event.getMessage())) {
|
if (commandRegistration.dispatch(event.getPlayer(), event.getMessage())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package com.sk89q.worldedit;
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
import com.sk89q.minecraft.util.commands.Command;
|
||||||
|
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -32,16 +33,16 @@ public abstract class ServerInterface {
|
|||||||
/**
|
/**
|
||||||
* Resolves an item name to its ID.
|
* Resolves an item name to its ID.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name The name to look up
|
||||||
* @return
|
* @return The id that corresponds to the name, or -1 if no such ID exists
|
||||||
*/
|
*/
|
||||||
public abstract int resolveItem(String name);
|
public abstract int resolveItem(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a mob type is valid.
|
* Checks if a mob type is valid.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type The mob type name to check
|
||||||
* @return
|
* @return Whether the name is a valid mod bype
|
||||||
*/
|
*/
|
||||||
public abstract boolean isValidMobType(String type);
|
public abstract boolean isValidMobType(String type);
|
||||||
|
|
||||||
@ -66,8 +67,13 @@ public abstract class ServerInterface {
|
|||||||
public List<LocalWorld> getWorlds() {
|
public List<LocalWorld> getWorlds() {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void onCommandRegistration(List<Command> commands) {
|
public void onCommandRegistration(List<Command> commands) {
|
||||||
// Do nothing :)
|
// Do nothing :)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onCommandRegistration(List<Command> commands, CommandsManager<LocalPlayer> manager) {
|
||||||
|
onCommandRegistration(commands);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an instance of the plugin
|
* Construct an instance of the plugin
|
||||||
*
|
*
|
||||||
* @param server
|
* @param server
|
||||||
* @param config
|
* @param config
|
||||||
*/
|
*/
|
||||||
@ -182,22 +182,22 @@ public class WorldEdit {
|
|||||||
super.invokeMethod(parent, args, player, method, instance, methodArgs, level);
|
super.invokeMethod(parent, args, player, method, instance, methodArgs, level);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
commands.setInjector(new SimpleInjector(this));
|
commands.setInjector(new SimpleInjector(this));
|
||||||
|
|
||||||
server.onCommandRegistration(commands.registerAndReturn(ChunkCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(ChunkCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(ClipboardCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(ClipboardCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(GeneralCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(GeneralCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(GenerationCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(GenerationCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(HistoryCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(HistoryCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(NavigationCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(NavigationCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(RegionCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(RegionCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(ScriptingCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(ScriptingCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(SelectionCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(SelectionCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(SnapshotUtilCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(SnapshotUtilCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(ToolUtilCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(ToolUtilCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(ToolCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(ToolCommands.class), commands);
|
||||||
server.onCommandRegistration(commands.registerAndReturn(UtilityCommands.class));
|
server.onCommandRegistration(commands.registerAndReturn(UtilityCommands.class), commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,7 +262,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the player has a session.
|
* Returns true if the player has a session.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -498,8 +498,8 @@ public class WorldEdit {
|
|||||||
* @param player
|
* @param player
|
||||||
* @param patternString
|
* @param patternString
|
||||||
* @return pattern
|
* @return pattern
|
||||||
* @throws UnknownItemException
|
* @throws UnknownItemException
|
||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public Pattern getBlockPattern(LocalPlayer player, String patternString)
|
public Pattern getBlockPattern(LocalPlayer player, String patternString)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws UnknownItemException, DisallowedItemException {
|
||||||
@ -648,8 +648,8 @@ public class WorldEdit {
|
|||||||
* @param list
|
* @param list
|
||||||
* @param allBlocksAllowed
|
* @param allBlocksAllowed
|
||||||
* @return set
|
* @return set
|
||||||
* @throws UnknownItemException
|
* @throws UnknownItemException
|
||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public Set<Integer> getBlockIDs(LocalPlayer player,
|
public Set<Integer> getBlockIDs(LocalPlayer player,
|
||||||
String list, boolean allBlocksAllowed)
|
String list, boolean allBlocksAllowed)
|
||||||
@ -668,8 +668,8 @@ public class WorldEdit {
|
|||||||
* has valid characters and has an extension. It also prevents directory
|
* has valid characters and has an extension. It also prevents directory
|
||||||
* traversal exploits by checking the root directory and the file directory.
|
* traversal exploits by checking the root directory and the file directory.
|
||||||
* On success, a <code>java.io.File</code> object will be returned.
|
* On success, a <code>java.io.File</code> object will be returned.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param dir sub-directory to look in
|
* @param dir sub-directory to look in
|
||||||
* @param filename filename (user-submitted)
|
* @param filename filename (user-submitted)
|
||||||
* @param defaultExt append an extension if missing one, null to not use
|
* @param defaultExt append an extension if missing one, null to not use
|
||||||
@ -688,8 +688,8 @@ public class WorldEdit {
|
|||||||
* has valid characters and has an extension. It also prevents directory
|
* has valid characters and has an extension. It also prevents directory
|
||||||
* traversal exploits by checking the root directory and the file directory.
|
* traversal exploits by checking the root directory and the file directory.
|
||||||
* On success, a <code>java.io.File</code> object will be returned.
|
* On success, a <code>java.io.File</code> object will be returned.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param dir sub-directory to look in
|
* @param dir sub-directory to look in
|
||||||
* @param filename filename (user-submitted)
|
* @param filename filename (user-submitted)
|
||||||
* @param defaultExt append an extension if missing one, null to not use
|
* @param defaultExt append an extension if missing one, null to not use
|
||||||
@ -705,7 +705,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a safe path to a file.
|
* Get a safe path to a file.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param dir
|
* @param dir
|
||||||
* @param filename
|
* @param filename
|
||||||
@ -775,7 +775,7 @@ public class WorldEdit {
|
|||||||
/**
|
/**
|
||||||
* Get a file relative to the defined working directory. If the specified
|
* Get a file relative to the defined working directory. If the specified
|
||||||
* path is absolute, then the working directory is not used.
|
* path is absolute, then the working directory is not used.
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -790,7 +790,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Modulus, divisor-style.
|
* Modulus, divisor-style.
|
||||||
*
|
*
|
||||||
* @param a
|
* @param a
|
||||||
* @param n
|
* @param n
|
||||||
* @return
|
* @return
|
||||||
@ -802,11 +802,11 @@ public class WorldEdit {
|
|||||||
/**
|
/**
|
||||||
* Get the direction vector for a player's direction. May return
|
* Get the direction vector for a player's direction. May return
|
||||||
* null if a direction could not be found.
|
* null if a direction could not be found.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param dirStr
|
* @param dirStr
|
||||||
* @return
|
* @return
|
||||||
* @throws UnknownDirectionException
|
* @throws UnknownDirectionException
|
||||||
*/
|
*/
|
||||||
public Vector getDirection(LocalPlayer player, String dirStr)
|
public Vector getDirection(LocalPlayer player, String dirStr)
|
||||||
throws UnknownDirectionException {
|
throws UnknownDirectionException {
|
||||||
@ -897,11 +897,11 @@ public class WorldEdit {
|
|||||||
/**
|
/**
|
||||||
* Get diagonal direction vector for a player's direction. May return
|
* Get diagonal direction vector for a player's direction. May return
|
||||||
* null if a direction could not be found.
|
* null if a direction could not be found.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param dirStr
|
* @param dirStr
|
||||||
* @return
|
* @return
|
||||||
* @throws UnknownDirectionException
|
* @throws UnknownDirectionException
|
||||||
*/
|
*/
|
||||||
public Vector getDiagonalDirection(LocalPlayer player, String dirStr)
|
public Vector getDiagonalDirection(LocalPlayer player, String dirStr)
|
||||||
throws UnknownDirectionException {
|
throws UnknownDirectionException {
|
||||||
@ -913,9 +913,9 @@ public class WorldEdit {
|
|||||||
* Get the flip direction for a player's direction.
|
* Get the flip direction for a player's direction.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param dirStr
|
* @param dirStr
|
||||||
* @return
|
* @return
|
||||||
* @throws UnknownDirectionException
|
* @throws UnknownDirectionException
|
||||||
*/
|
*/
|
||||||
public FlipDirection getFlipDirection(LocalPlayer player, String dirStr)
|
public FlipDirection getFlipDirection(LocalPlayer player, String dirStr)
|
||||||
throws UnknownDirectionException {
|
throws UnknownDirectionException {
|
||||||
@ -941,7 +941,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a session.
|
* Remove a session.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public void removeSession(LocalPlayer player) {
|
public void removeSession(LocalPlayer player) {
|
||||||
@ -961,7 +961,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Flush a block bag's changes to a player.
|
* Flush a block bag's changes to a player.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param editSession
|
* @param editSession
|
||||||
*/
|
*/
|
||||||
@ -1064,9 +1064,9 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on arm swing.
|
* Called on arm swing.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean handleArmSwing(LocalPlayer player) {
|
public boolean handleArmSwing(LocalPlayer player) {
|
||||||
if (player.getItemInHand() == config.navigationWand) {
|
if (player.getItemInHand() == config.navigationWand) {
|
||||||
@ -1103,9 +1103,9 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on right click (not on a block).
|
* Called on right click (not on a block).
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean handleRightClick(LocalPlayer player) {
|
public boolean handleRightClick(LocalPlayer player) {
|
||||||
if (player.getItemInHand() == config.navigationWand) {
|
if (player.getItemInHand() == config.navigationWand) {
|
||||||
@ -1327,7 +1327,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] commandDetection(String[] split) {
|
public String[] commandDetection(String[] split) {
|
||||||
split[0] = split[0].substring(1);
|
split[0] = split[0].substring(1);
|
||||||
|
|
||||||
@ -1355,11 +1355,11 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a WorldEdit script.
|
* Executes a WorldEdit script.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param f
|
* @param f
|
||||||
* @param args
|
* @param args
|
||||||
* @throws WorldEditException
|
* @throws WorldEditException
|
||||||
*/
|
*/
|
||||||
public void runScript(LocalPlayer player, File f, String[] args)
|
public void runScript(LocalPlayer player, File f, String[] args)
|
||||||
throws WorldEditException {
|
throws WorldEditException {
|
||||||
@ -1444,7 +1444,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Worldedit's configuration.
|
* Get Worldedit's configuration.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public LocalConfiguration getConfiguration() {
|
public LocalConfiguration getConfiguration() {
|
||||||
@ -1453,7 +1453,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the server interface.
|
* Get the server interface.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ServerInterface getServer() {
|
public ServerInterface getServer() {
|
||||||
|
@ -19,12 +19,17 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.bukkit;
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.sk89q.bukkit.util.CommandInfo;
|
||||||
import com.sk89q.bukkit.util.CommandRegistration;
|
import com.sk89q.bukkit.util.CommandRegistration;
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
import com.sk89q.minecraft.util.commands.Command;
|
||||||
|
|
||||||
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||||
|
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||||
|
import com.sk89q.worldedit.LocalPlayer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -78,12 +83,23 @@ public class BukkitServerInterface extends ServerInterface {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommandRegistration(List<Command> commands) {
|
public void onCommandRegistration(List<Command> commands, CommandsManager<LocalPlayer> manager) {
|
||||||
dynamicCommands.registerAll(commands);
|
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
|
||||||
|
for (Command command : commands) {
|
||||||
|
String[] permissions = null;
|
||||||
|
Method cmdMethod = manager.getMethods().get(null).get(command.aliases()[0]);
|
||||||
|
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
|
||||||
|
permissions = cmdMethod.getAnnotation(CommandPermissions.class).value();
|
||||||
|
}
|
||||||
|
|
||||||
|
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), manager, permissions));
|
||||||
|
}
|
||||||
|
|
||||||
|
dynamicCommands.register(toRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterCommands() {
|
public void unregisterCommands() {
|
||||||
dynamicCommands.unregisterCommands();
|
dynamicCommands.unregisterCommands();
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren