当前位置: 首页>>代码示例>>Java>>正文


Java CommandMap类代码示例

本文整理汇总了Java中org.bukkit.command.CommandMap的典型用法代码示例。如果您正苦于以下问题:Java CommandMap类的具体用法?Java CommandMap怎么用?Java CommandMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CommandMap类属于org.bukkit.command包,在下文中一共展示了CommandMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unregisterCommand

import org.bukkit.command.CommandMap; //导入依赖的package包/类
/**
 * Unregisters a CommandExecutor with the server
 *
 * @param command the command instance
 * @param <T> the command executor class type
 * @return the command executor
 */
@Nonnull
public static <T extends CommandExecutor> T unregisterCommand(@Nonnull T command) {
    CommandMap map = getCommandMap();
    try {
        //noinspection unchecked
        Map<String, Command> knownCommands = (Map<String, Command>) KNOWN_COMMANDS_FIELD.get(map);

        Iterator<Command> iterator = knownCommands.values().iterator();
        while (iterator.hasNext()) {
            Command cmd = iterator.next();
            if (cmd instanceof PluginCommand) {
                CommandExecutor executor = ((PluginCommand) cmd).getExecutor();
                if (command == executor) {
                    cmd.unregister(map);
                    iterator.remove();
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not unregister command", e);
    }

    return command;
}
 
开发者ID:lucko,项目名称:helper,代码行数:32,代码来源:CommandMapUtil.java

示例2: onCalled

import org.bukkit.command.CommandMap; //导入依赖的package包/类
@Override
public LuaValue onCalled(Varargs parameters) {
    String name = parameters.arg(1).tojstring();
    String desc = parameters.arg(2).tojstring();
    String usage = parameters.arg(3).tojstring();
    LuaValue func = parameters.arg(4);
    DynamicCommand command = new DynamicCommand(name, desc, usage, func);
    try {
        Field cmdMapField = SimplePluginManager.class.getDeclaredField("commandMap");
        cmdMapField.setAccessible(true);
        CommandMap commandMap = (CommandMap) cmdMapField.get(Bukkit.getPluginManager());
        commandMap.register(command.getName(), command);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return LuaValue.NIL;
}
 
开发者ID:LukkitPlus,项目名称:Lukkit,代码行数:18,代码来源:CentralPoint.java

示例3: CommandFramework

import org.bukkit.command.CommandMap; //导入依赖的package包/类
public CommandFramework(Plugin plugin) {
    this.plugin = plugin;

    if (plugin.getServer().getPluginManager() instanceof SimplePluginManager) {
        SimplePluginManager manager = (SimplePluginManager) plugin.getServer().getPluginManager();

        try {
            Field field = SimplePluginManager.class.getDeclaredField("commandMap");
            field.setAccessible(true);
            this.map = (CommandMap) field.get(manager);
        }
        catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:ijoeleoli,项目名称:ServerCommons,代码行数:17,代码来源:CommandFramework.java

示例4: unregister

import org.bukkit.command.CommandMap; //导入依赖的package包/类
public boolean unregister() {
    CommandMap commandMap = getCommandMap();
    List<String> toRemove = new ArrayList<String>();
    Map<String, Command> knownCommands = KNOWN_COMMANDS.get(commandMap);
    if (knownCommands == null) {
        return false;
    }
    for (Iterator<Command> i = knownCommands.values().iterator(); i.hasNext(); ) {
        Command cmd = i.next();
        if (cmd instanceof DynamicPluginCommand) {
            i.remove();
            for (String alias : cmd.getAliases()) {
                Command aliasCmd = knownCommands.get(alias);
                if (cmd.equals(aliasCmd)) {
                    toRemove.add(alias);
                }
            }
        }
    }
    for (String string : toRemove) {
        knownCommands.remove(string);
    }
    return true;
}
 
开发者ID:Borlea,项目名称:EchoPet,代码行数:25,代码来源:CommandManager.java

示例5: getCommandMap

import org.bukkit.command.CommandMap; //导入依赖的package包/类
public CommandMap getCommandMap() {
    if (!(Bukkit.getPluginManager() instanceof SimplePluginManager)) {
        this.plugin.getLogger().warning("Seems like your server is using a custom PluginManager? Well let's try injecting our custom commands anyways...");
    }

    CommandMap map = null;

    try {
        map = SERVER_COMMAND_MAP.get(Bukkit.getPluginManager());

        if (map == null) {
            if (fallback != null) {
                return fallback;
            } else {
                fallback = map = new SimpleCommandMap(EchoPet.getPlugin().getServer());
                Bukkit.getPluginManager().registerEvents(new FallbackCommandRegistrationListener(fallback), this.plugin);
            }
        }
    } catch (Exception pie) {
        this.plugin.getLogger().warning("Failed to dynamically register the commands! Let's give it a last shot...");
        // Hmmm.... Pie...
        fallback = map = new SimpleCommandMap(EchoPet.getPlugin().getServer());
        Bukkit.getPluginManager().registerEvents(new FallbackCommandRegistrationListener(fallback), this.plugin);
    }
    return map;
}
 
开发者ID:Borlea,项目名称:EchoPet,代码行数:27,代码来源:CommandManager.java

示例6: addExecutor

import org.bukkit.command.CommandMap; //导入依赖的package包/类
@SneakyThrows
public static void addExecutor(Plugin plugin, Command command) {
    Field f = SimplePluginManager.class.getDeclaredField("commandMap");
    f.setAccessible(true);
    CommandMap map = (CommandMap) f.get(plugin.getServer().getPluginManager());
    Constructor<PluginCommand> init = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
    init.setAccessible(true);
    PluginCommand inject = init.newInstance(command.getName(), plugin);
    inject.setExecutor((who, __, label, input) -> command.execute(who, label, input));
    inject.setAliases(command.getAliases());
    inject.setDescription(command.getDescription());
    inject.setLabel(command.getLabel());
    inject.setName(command.getName());
    inject.setPermission(command.getPermission());
    inject.setPermissionMessage(command.getPermissionMessage());
    inject.setUsage(command.getUsage());
    map.register(plugin.getName().toLowerCase(), inject);
}
 
开发者ID:caoli5288,项目名称:EnderChest,代码行数:19,代码来源:PluginHelper.java

示例7: unregister

import org.bukkit.command.CommandMap; //导入依赖的package包/类
/**
 * Unregisters the command.
 */
public void unregister() {	
	try {
		Field fMap = Command.class.getDeclaredField("commandMap");
		fMap.setAccessible(true);
		CommandMap map = (CommandMap) fMap.get(this);
		this.unregister(map);
		
		Field fKnownCommands = map.getClass().getDeclaredField("knownCommands");
		fKnownCommands.setAccessible(true);
		@SuppressWarnings("unchecked")
		HashMap<String, Command> knownCommands = (HashMap<String, Command>) fKnownCommands.get(map);
		for (Entry<String, Command> entry : knownCommands.entrySet()) {
			if (entry.getValue() == this) {
				knownCommands.remove(entry.getKey());
				break;
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:BtoBastian,项目名称:EpicSpleef,代码行数:25,代码来源:SpleefCommand.java

示例8: BukkitCommandHandler

import org.bukkit.command.CommandMap; //导入依赖的package包/类
public BukkitCommandHandler(Plugin plugin) {
	cmdMap = new HashMap<String, BukkitExecutor>();
	this.plugin = plugin;

	if (plugin.getServer().getPluginManager() instanceof SimplePluginManager) {
		SimplePluginManager manager = (SimplePluginManager) plugin
				.getServer().getPluginManager();
		try {
			Field field = SimplePluginManager.class
					.getDeclaredField("commandMap");
			field.setAccessible(true);
			map = (CommandMap) field.get(manager);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:18,代码来源:BukkitCommandHandler.java

示例9: register

import org.bukkit.command.CommandMap; //导入依赖的package包/类
private void register() {
    if (pluginCommand == null) return;

    plugin.debug("Registering command " + name);

    try {
        Field f = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
        f.setAccessible(true);

        Object commandMapObject = f.get(Bukkit.getPluginManager());
        if (commandMapObject instanceof CommandMap) {
            CommandMap commandMap = (CommandMap) commandMapObject;
            commandMap.register(plugin.getName(), pluginCommand);
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        plugin.getLogger().severe("Failed to register command");
        plugin.debug("Failed to register plugin command");
        plugin.debug(e);
    }
}
 
开发者ID:EpicEricEE,项目名称:ShopChest,代码行数:21,代码来源:ShopCommand.java

示例10: registerCommand

import org.bukkit.command.CommandMap; //导入依赖的package包/类
/**
 * Registers a command in the server's CommandMap.
 *
 * @param ce CommandExecutor to be registered
 * @param rc ReflectCommand the command was annotated with
 */
public void registerCommand(@NotNull final BaseCommand<? extends Plugin> ce, @NotNull final ReflectCommand rc) {
    Preconditions.checkNotNull(ce, "ce was null");
    Preconditions.checkNotNull(rc, "rc was null");
    try {
        final Constructor c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
        c.setAccessible(true);
        final PluginCommand pc = (PluginCommand) c.newInstance(rc.name(), this.plugin);
        pc.setExecutor(ce);
        pc.setAliases(Arrays.asList(rc.aliases()));
        pc.setDescription(rc.description());
        pc.setUsage(rc.usage());
        final CommandMap cm = this.getCommandMap();
        if (cm == null) {
            this.plugin.getLogger().warning("CommandMap was null. Command " + rc.name() + " not registered.");
            return;
        }
        cm.register(this.plugin.getDescription().getName(), pc);
        this.commandHandler.addCommand(new CommandCoupling(ce, pc));
    } catch (Exception e) {
        this.plugin.getLogger().warning("Could not register command \"" + rc.name() + "\" - an error occurred: " + e.getMessage() + ".");
    }
}
 
开发者ID:Chatterbox,项目名称:Chatterbox,代码行数:29,代码来源:ReflectiveCommandRegistrar.java

示例11: CommandFramework

import org.bukkit.command.CommandMap; //导入依赖的package包/类
/**
 * Initializes the command framework and sets up the command maps
 * 
 * @param plugin
 */
public CommandFramework(Plugin plugin) {
	this.plugin = plugin;
	if (plugin.getServer().getPluginManager() instanceof SimplePluginManager) {
		SimplePluginManager manager = (SimplePluginManager) plugin
				.getServer().getPluginManager();
		try {
			Field field = SimplePluginManager.class
					.getDeclaredField("commandMap");
			field.setAccessible(true);
			map = (CommandMap) field.get(manager);
		} catch (IllegalArgumentException | NoSuchFieldException
				| IllegalAccessException | SecurityException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:skavrx,项目名称:PartyLobby,代码行数:22,代码来源:CommandFramework.java

示例12: unregisterCommand

import org.bukkit.command.CommandMap; //导入依赖的package包/类
public void unregisterCommand(Command command, CommandMap commandMap)
{
    try
    {
        command.unregister(commandMap);
        HashMap<String, Command> knownCommands = getKnownCommands(commandMap);
        if (knownCommands != null)
        {
            knownCommands.remove(command.getName());
            for (String alias : command.getAliases())
            {
                knownCommands.remove(alias);
            }
        }
    }
    catch (Exception ex)
    {
        TFM_Log.severe(ex);
    }
}
 
开发者ID:Yoshi41023,项目名称:TatsuCraftMod,代码行数:21,代码来源:TFM_CommandLoader.java

示例13: getCommandMap

import org.bukkit.command.CommandMap; //导入依赖的package包/类
private CommandMap getCommandMap() {
    final PluginManager m = getServer().getPluginManager();
    if (! (m instanceof SimplePluginManager) )
        return null;

    try {
        final Field f = SimplePluginManager.class.getDeclaredField("commandMap");
        f.setAccessible(true);

        Object map = f.get(m);
        if ( map instanceof CommandMap )
            return (CommandMap) map;

    } catch(final Exception e) { }

    return null;
}
 
开发者ID:stendec,项目名称:Abyss,代码行数:18,代码来源:AbyssPlugin.java

示例14: getCommandMap

import org.bukkit.command.CommandMap; //导入依赖的package包/类
private static CommandMap getCommandMap() {
    try {
        return (CommandMap) COMMAND_MAP_FIELD.get(Bukkit.getServer().getPluginManager());
    } catch (Exception e) {
        throw new RuntimeException("Could not get CommandMap", e);
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:8,代码来源:CommandMapUtil.java

示例15: addExecutor

import org.bukkit.command.CommandMap; //导入依赖的package包/类
public static void addExecutor(Plugin plugin, Command command) {
    try {
        Field f = SimplePluginManager.class.getDeclaredField("commandMap");
        f.setAccessible(true);
        CommandMap map = (CommandMap) f.get(plugin.getServer().getPluginManager());
        map.register(plugin.getName().toLowerCase(), command);
    } catch (ReflectiveOperationException e) {
        e.printStackTrace();
    }
}
 
开发者ID:caoli5288,项目名称:chatcolor,代码行数:11,代码来源:PluginHelper.java


注:本文中的org.bukkit.command.CommandMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。