當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。