mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-30 02:26:42 +00:00
Switch to Gradle. Use git log --follow for history.
This converts the project into a multi-module Gradle build. By default, Git does not show history past a rename, so use git log --follow to see further history.
This commit is contained in:
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.bukkit.util;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.bukkit.util;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public interface CommandInspector {
|
||||
|
||||
String getShortText(Command command);
|
||||
|
||||
String getFullText(Command command);
|
||||
|
||||
boolean testPermission(CommandSender sender, Command command);
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.bukkit.util;
|
||||
|
||||
import com.sk89q.util.ReflectionUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandRegistration {
|
||||
|
||||
static {
|
||||
Bukkit.getServer().getHelpMap().registerHelpTopicFactory(DynamicPluginCommand.class, new DynamicPluginCommandHelpTopic.Factory());
|
||||
}
|
||||
|
||||
protected final Plugin plugin;
|
||||
protected final CommandExecutor executor;
|
||||
private CommandMap fallbackCommands;
|
||||
|
||||
public CommandRegistration(Plugin plugin) {
|
||||
this(plugin, plugin);
|
||||
}
|
||||
|
||||
public CommandRegistration(Plugin plugin, CommandExecutor executor) {
|
||||
this.plugin = plugin;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public boolean register(List<CommandInfo> registered) {
|
||||
CommandMap commandMap = getCommandMap();
|
||||
if (registered == null || commandMap == null) {
|
||||
return false;
|
||||
}
|
||||
for (CommandInfo command : registered) {
|
||||
DynamicPluginCommand cmd = new DynamicPluginCommand(command.getAliases(),
|
||||
command.getDesc(), "/" + command.getAliases()[0] + " " + command.getUsage(), executor, command.getRegisteredWith(), plugin);
|
||||
cmd.setPermissions(command.getPermissions());
|
||||
commandMap.register(plugin.getDescription().getName(), cmd);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public CommandMap getCommandMap() {
|
||||
CommandMap commandMap = ReflectionUtil.getField(plugin.getServer().getPluginManager(), "commandMap");
|
||||
if (commandMap == null) {
|
||||
if (fallbackCommands != null) {
|
||||
commandMap = fallbackCommands;
|
||||
} else {
|
||||
Bukkit.getServer().getLogger().severe(plugin.getDescription().getName() +
|
||||
": Could not retrieve server CommandMap, using fallback instead!");
|
||||
fallbackCommands = commandMap = new SimpleCommandMap(Bukkit.getServer());
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new FallbackRegistrationListener(fallbackCommands), plugin);
|
||||
}
|
||||
}
|
||||
return commandMap;
|
||||
}
|
||||
|
||||
public boolean unregisterCommands() {
|
||||
CommandMap commandMap = getCommandMap();
|
||||
List<String> toRemove = new ArrayList<String>();
|
||||
Map<String, org.bukkit.command.Command> knownCommands = ReflectionUtil.getField(commandMap, "knownCommands");
|
||||
Set<String> aliases = ReflectionUtil.getField(commandMap, "aliases");
|
||||
if (knownCommands == null || aliases == null) {
|
||||
return false;
|
||||
}
|
||||
for (Iterator<org.bukkit.command.Command> i = knownCommands.values().iterator(); i.hasNext();) {
|
||||
org.bukkit.command.Command cmd = i.next();
|
||||
if (cmd instanceof DynamicPluginCommand && ((DynamicPluginCommand) cmd).getOwner().equals(executor)) {
|
||||
i.remove();
|
||||
for (String alias : cmd.getAliases()) {
|
||||
org.bukkit.command.Command aliasCmd = knownCommands.get(alias);
|
||||
if (cmd.equals(aliasCmd)) {
|
||||
aliases.remove(alias);
|
||||
toRemove.add(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String string : toRemove) {
|
||||
knownCommands.remove(string);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser 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.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandsManagerRegistration extends CommandRegistration {
|
||||
|
||||
protected CommandsManager<?> commands;
|
||||
|
||||
public CommandsManagerRegistration(Plugin plugin, CommandsManager<?> commands) {
|
||||
super(plugin);
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public CommandsManagerRegistration(Plugin plugin, CommandExecutor executor, CommandsManager<?> commands) {
|
||||
super(plugin, executor);
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public boolean register(Class<?> clazz) {
|
||||
return registerAll(commands.registerAndReturn(clazz));
|
||||
}
|
||||
|
||||
public boolean registerAll(List<Command> registered) {
|
||||
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
|
||||
for (Command command : registered) {
|
||||
List<String> permissions = null;
|
||||
Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]);
|
||||
Map<String, Method> childMethods = commands.getMethods().get(cmdMethod);
|
||||
|
||||
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
|
||||
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
|
||||
} else if (cmdMethod != null && childMethods != null && !childMethods.isEmpty()) {
|
||||
permissions = new ArrayList<String>();
|
||||
for (Method m : childMethods.values()) {
|
||||
if (m.isAnnotationPresent(CommandPermissions.class)) {
|
||||
permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()])));
|
||||
}
|
||||
|
||||
return register(toRegister);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser 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.util.StringUtil;
|
||||
import com.sk89q.wepif.PermissionsResolverManager;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An implementation of a dynamically registered {@link org.bukkit.command.Command} attached to a plugin
|
||||
*/
|
||||
public class DynamicPluginCommand extends org.bukkit.command.Command implements PluginIdentifiableCommand {
|
||||
|
||||
protected final CommandExecutor owner;
|
||||
protected final Object registeredWith;
|
||||
protected final Plugin owningPlugin;
|
||||
protected String[] permissions = new String[0];
|
||||
|
||||
public DynamicPluginCommand(String[] aliases, String desc, String usage, CommandExecutor owner, Object registeredWith, Plugin plugin) {
|
||||
super(aliases[0], desc, usage, Arrays.asList(aliases));
|
||||
this.owner = owner;
|
||||
this.owningPlugin = plugin;
|
||||
this.registeredWith = registeredWith;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
return owner.onCommand(sender, this, label, args);
|
||||
}
|
||||
|
||||
public Object getOwner() {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin getPlugin() {
|
||||
return owningPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
if (registeredWith instanceof CommandInspector) {
|
||||
return ((TabCompleter) owner).onTabComplete(sender, this, alias, args);
|
||||
} else {
|
||||
return super.tabComplete(sender, alias, args);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean testPermissionSilent(CommandSender sender) {
|
||||
if (permissions == null || permissions.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (registeredWith instanceof CommandInspector) {
|
||||
CommandInspector resolver = (CommandInspector) registeredWith;
|
||||
return resolver.testPermission(sender, this);
|
||||
} else if (registeredWith instanceof CommandsManager<?>) {
|
||||
try {
|
||||
for (String permission : permissions) {
|
||||
if (((CommandsManager<CommandSender>) registeredWith).hasPermission(sender, permission)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
} else if (PermissionsResolverManager.isInitialized() && sender instanceof OfflinePlayer) {
|
||||
for (String permission : permissions) {
|
||||
if (PermissionsResolverManager.getInstance().hasPermission((OfflinePlayer) sender, permission)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return super.testPermissionSilent(sender);
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser 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.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.help.HelpTopic;
|
||||
import org.bukkit.help.HelpTopicFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class DynamicPluginCommandHelpTopic extends HelpTopic {
|
||||
|
||||
private final DynamicPluginCommand cmd;
|
||||
|
||||
public DynamicPluginCommandHelpTopic(DynamicPluginCommand cmd) {
|
||||
this.cmd = cmd;
|
||||
this.name = "/" + cmd.getName();
|
||||
|
||||
if (cmd.getRegisteredWith() instanceof CommandInspector) {
|
||||
CommandInspector resolver = (CommandInspector) cmd.getRegisteredWith();
|
||||
this.shortText = resolver.getShortText(cmd);
|
||||
this.fullText = resolver.getFullText(cmd);
|
||||
} else {
|
||||
String fullTextTemp = null;
|
||||
StringBuilder fullText = new StringBuilder();
|
||||
|
||||
if (cmd.getRegisteredWith() instanceof CommandsManager) {
|
||||
Map<String, String> helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getHelpMessages();
|
||||
final String lookupName = cmd.getName().replaceAll("/", "");
|
||||
if (helpText.containsKey(lookupName)) { // We have full help text for this command
|
||||
fullTextTemp = helpText.get(lookupName);
|
||||
}
|
||||
// No full help text, assemble help text from info
|
||||
helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getCommands();
|
||||
if (helpText.containsKey(cmd.getName())) {
|
||||
final String shortText = helpText.get(cmd.getName());
|
||||
if (fullTextTemp == null) {
|
||||
fullTextTemp = this.name + " " + shortText;
|
||||
}
|
||||
this.shortText = shortText;
|
||||
}
|
||||
} else {
|
||||
this.shortText = cmd.getDescription();
|
||||
}
|
||||
|
||||
// Put the usage in the format: Usage string (newline) Aliases (newline) Help text
|
||||
String[] split = fullTextTemp == null ? new String[2] : fullTextTemp.split("\n", 2);
|
||||
fullText.append(ChatColor.BOLD).append(ChatColor.GOLD).append("Usage: ").append(ChatColor.WHITE);
|
||||
fullText.append(split[0]).append("\n");
|
||||
|
||||
if (!cmd.getAliases().isEmpty()) {
|
||||
fullText.append(ChatColor.BOLD).append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.WHITE);
|
||||
boolean first = true;
|
||||
for (String alias : cmd.getAliases()) {
|
||||
if (!first) {
|
||||
fullText.append(", ");
|
||||
}
|
||||
fullText.append(alias);
|
||||
first = false;
|
||||
}
|
||||
fullText.append("\n");
|
||||
}
|
||||
if (split.length > 1) {
|
||||
fullText.append(split[1]);
|
||||
}
|
||||
this.fullText = fullText.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean canSee(CommandSender player) {
|
||||
if (cmd.getRegisteredWith() instanceof CommandInspector) {
|
||||
CommandInspector resolver = (CommandInspector) cmd.getRegisteredWith();
|
||||
return resolver.testPermission(player, cmd);
|
||||
} else 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.isEmpty()) {
|
||||
return getShortText();
|
||||
} else {
|
||||
return this.fullText;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Factory implements HelpTopicFactory<DynamicPluginCommand> {
|
||||
@Override
|
||||
public HelpTopic createTopic(DynamicPluginCommand command) {
|
||||
return new DynamicPluginCommandHelpTopic(command);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.bukkit.util;
|
||||
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class FallbackRegistrationListener implements Listener {
|
||||
|
||||
private final CommandMap commandRegistration;
|
||||
|
||||
public FallbackRegistrationListener(CommandMap commandRegistration) {
|
||||
this.commandRegistration = commandRegistration;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (commandRegistration.dispatch(event.getPlayer(), event.getMessage())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user