當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleCommandMap類代碼示例

本文整理匯總了Java中org.bukkit.command.SimpleCommandMap的典型用法代碼示例。如果您正苦於以下問題:Java SimpleCommandMap類的具體用法?Java SimpleCommandMap怎麽用?Java SimpleCommandMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SimpleCommandMap類屬於org.bukkit.command包,在下文中一共展示了SimpleCommandMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: inject

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
/**
 * 
 * @author jiongjionger,Vlvxingze
 */

public static void inject(Plugin plg) {
	if (plg != null) {
		try {
			SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager());
			for (Command command : simpleCommandMap.getCommands()) {
				if (command instanceof PluginCommand) {
					PluginCommand pluginCommand = (PluginCommand) command;
					if (plg.equals(pluginCommand.getPlugin())) {
						FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class);
						FieldAccessor<TabCompleter> tabField = Reflection.getField(PluginCommand.class, "completer", TabCompleter.class);
						CommandInjector commandInjector = new CommandInjector(plg, commandField.get(pluginCommand), tabField.get(pluginCommand));
						commandField.set(pluginCommand, commandInjector);
						tabField.set(pluginCommand, commandInjector);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:27,代碼來源:CommandInjector.java

示例2: uninject

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
public static void uninject(Plugin plg) {
	if (plg != null) {
		try {
			SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager());
			for (Command command : simpleCommandMap.getCommands()) {
				if (command instanceof PluginCommand) {
					PluginCommand pluginCommand = (PluginCommand) command;
					if (plg.equals(pluginCommand.getPlugin())) {
						FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class);
						FieldAccessor<TabCompleter> tabField = Reflection.getField(PluginCommand.class, "completer", TabCompleter.class);
						CommandExecutor executor = commandField.get(pluginCommand);
						if (executor instanceof CommandInjector) {
							commandField.set(pluginCommand, ((CommandInjector) executor).getCommandExecutor());
						}
						TabCompleter completer = tabField.get(pluginCommand);
						if (completer instanceof CommandInjector) {
							tabField.set(pluginCommand, ((CommandInjector) executor).getTabCompleter());
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:27,代碼來源:CommandInjector.java

示例3: getCommandTimingsByPlugin

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
public static Map<String, MonitorRecord> getCommandTimingsByPlugin(Plugin plg) {
	Map<String, MonitorRecord> record = new HashMap<>();
	if (plg == null) {
		return record;
	}
	try {
		SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager());
		for (Command command : simpleCommandMap.getCommands()) {
			if (command instanceof PluginCommand) {
				PluginCommand pluginCommand = (PluginCommand) command;
				if (plg.equals(pluginCommand.getPlugin())) {
					FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class);
					CommandExecutor executor = commandField.get(pluginCommand);
					if (executor instanceof CommandInjector) {
						CommandInjector commandInjector = (CommandInjector) executor;
						record = mergeRecordMap(record, commandInjector.getMonitorRecordMap());
					}

				}
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return record;
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:27,代碼來源:MonitorUtils.java

示例4: createMockServer

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
public static Server createMockServer() {
    ConsoleCommandSender commandSender = (ConsoleCommandSender) createCommandSender();
    Server server = mock(Server.class);
    when(server.getLogger()).thenReturn(Logger.getGlobal());
    when(server.getPluginManager()).thenReturn(
            new SimplePluginManager(server, new SimpleCommandMap(server)));
    when(server.getItemFactory()).thenReturn(new MockItemFactory());
    doAnswer(invocation -> new MockInventory(InventoryType.CHEST, invocation.getArgument(1), invocation.getArgument(2)))
            .when(server).createInventory(any(), anyInt(), anyString());
    when(server.getBukkitVersion()).thenReturn("1.0");
    when(server.getConsoleSender()).thenReturn(commandSender);
    doAnswer(invocation -> createMockWorld())
            .when(server).getWorld(anyString());

    return server;
}
 
開發者ID:EntryPointKR,項目名稱:MCLibrary,代碼行數:17,代碼來源:MockFactory.java

示例5: getCommandMap

import org.bukkit.command.SimpleCommandMap; //導入依賴的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: register

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
public void register(final SimpleCommandMap commandMap, final Map<String, Command> knownCommands, final @Nullable Set<String> aliases) {
	synchronized (commandMap) {
		overriddenAliases.clear();
		overridden = knownCommands.put(label, bukkitCommand);
		if (aliases != null)
			aliases.remove(label);
		final Iterator<String> as = activeAliases.iterator();
		while (as.hasNext()) {
			final String lowerAlias = as.next().toLowerCase();
			if (knownCommands.containsKey(lowerAlias) && (aliases == null || !aliases.contains(lowerAlias))) {
				as.remove();
				continue;
			}
			overriddenAliases.put(lowerAlias, knownCommands.put(lowerAlias, bukkitCommand));
			if (aliases != null)
				aliases.add(lowerAlias);
		}
		bukkitCommand.setAliases(activeAliases);
		bukkitCommand.register(commandMap);
	}
}
 
開發者ID:nfell2009,項目名稱:Skript,代碼行數:22,代碼來源:ScriptCommand.java

示例7: unregister

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
public void unregister(final SimpleCommandMap commandMap, final Map<String, Command> knownCommands, final @Nullable Set<String> aliases) {
	synchronized (commandMap) {
		knownCommands.remove(label);
		if (aliases != null)
			aliases.removeAll(activeAliases);
		for (final String alias : activeAliases)
			knownCommands.remove(alias);
		activeAliases = new ArrayList<String>(this.aliases);
		bukkitCommand.unregister(commandMap);
		bukkitCommand.setAliases(this.aliases);
		if (overridden != null) {
			knownCommands.put(label, overridden);
			overridden = null;
		}
		for (final Entry<String, Command> e : overriddenAliases.entrySet()) {
			if (e.getValue() == null)
				continue;
			knownCommands.put(e.getKey(), e.getValue());
			if (aliases != null)
				aliases.add(e.getKey());
		}
		overriddenAliases.clear();
	}
}
 
開發者ID:nfell2009,項目名稱:Skript,代碼行數:25,代碼來源:ScriptCommand.java

示例8: getCommandMap

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
private SimpleCommandMap getCommandMap()
{
	final PluginManager pluginManager = getOwner().getServer().getPluginManager();

	FieldAccessor<SimpleCommandMap> cmdMapField = FieldAccessor.access(
			pluginManager, "commandMap" );

	Optional<SimpleCommandMap> optCmdMap = cmdMapField.getValue();

	if ( optCmdMap.isPresent() )
		return optCmdMap.get();

	final String message = String.format( "Cound not get commandMap, CraftBukkit Version: %s, PluginManager: %s",
			MCReflectUtil.getCBVersion(),
			pluginManager );

	throw new IllegalStateException( message );
}
 
開發者ID:ProjectSandstone,項目名稱:EventoZero,代碼行數:19,代碼來源:CommandManagerImpl.java

示例9: unRegisterBukkitCommand

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
public void unRegisterBukkitCommand(PluginCommand cmd) {
    try {
        Object result = getPrivateField(plugin.getServer().getPluginManager(), "commandMap");
        SimpleCommandMap commandMap = (SimpleCommandMap) result;
        Object map = getPrivateField(commandMap, "knownCommands");
        @SuppressWarnings("unchecked")
        HashMap<String, Command> knownCommands = (HashMap<String, Command>) map;
        knownCommands.remove(cmd.getName());
        for (String alias : cmd.getAliases()) {
            if (knownCommands.containsKey(alias) && knownCommands.get(alias).toString().contains(plugin.getName())) {
                knownCommands.remove(alias);
            }
        }
    } catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        plugin.getLogger().severe(e.toString());
    }
}
 
開發者ID:ddonofrio,項目名稱:libelula,代碼行數:18,代碼來源:CommandManager.java

示例10: unRegisterBukkitCommand

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
/**
 * unregister a command, credits to zeeveener for his awesome code to unregister commands!
 * 
 * @author zeeveener, xize
 * @param cmd - the command to be unregistered
 */
public void unRegisterBukkitCommand(PluginCommand cmd) {
	try {
		Object result = getPrivateField(Bukkit.getServer().getPluginManager(), "commandMap");
		SimpleCommandMap commandMap = (SimpleCommandMap) result;
		Object map = getPrivateField(commandMap, "knownCommands");
		@SuppressWarnings("unchecked")
		HashMap<String, Command> knownCommands = (HashMap<String, Command>) map;
		knownCommands.remove("xessentials"+":"+cmd.getName());
		if(knownCommands.containsKey(cmd.getName()) && knownCommands.get(cmd.getName().toLowerCase()).toString().contains(pl.getName())) {
			knownCommands.remove(cmd.getName());
		}
		for (String alias : cmd.getAliases()){
			if(knownCommands.containsKey("xessentials:"+alias) && knownCommands.get("xessentials:"+alias).toString().contains(pl.getName())){
				knownCommands.remove("xessentials:"+alias);
			}
			if(knownCommands.containsKey(alias) && knownCommands.get(alias).toString().contains(pl.getName())){
				knownCommands.remove(alias);
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:xEssentials,項目名稱:xEssentials-deprecated-bukkit,代碼行數:30,代碼來源:CommandManager.java

示例11: isRegistered

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
/**
 * returns true if the command is registered inside xEssentials otherwise false
 * 
 * @author xize
 * @param cmd - the command
 * @return boolean
 */
public boolean isRegistered(String cmd) {
	try {
		Object result = getPrivateField(Bukkit.getServer().getPluginManager(), "commandMap");
		SimpleCommandMap commandMap = (SimpleCommandMap) result;
		Object map = getPrivateField(commandMap, "knownCommands");
		@SuppressWarnings("unchecked")
		HashMap<String, Command> knownCommands = (HashMap<String, Command>) map;
		if(knownCommands.containsKey("xessentials"+":"+cmd) || (knownCommands.containsKey(cmd) && knownCommands.get(cmd).toString().contains(pl.getName()))) {
			return true;
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return false;
}
 
開發者ID:xEssentials,項目名稱:xEssentials-deprecated-bukkit,代碼行數:23,代碼來源:CommandManager.java

示例12: registerBukkitCommand

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
/**
 * re-registers the command in the plugin
 * 
 * @author zeeveener, xize
 * @param cmd - the command
 */
@SuppressWarnings("unchecked")
public void registerBukkitCommand(PluginCommand cmd) {
	try {
		Object result = getPrivateField(Bukkit.getServer().getPluginManager(), "commandMap");
		SimpleCommandMap commandMap = (SimpleCommandMap) result;
		Object map = getPrivateField(commandMap, "knownCommands");
		HashMap<String, Command> knownCommands = (HashMap<String, Command>) map;
		knownCommands.put("xessentials:"+cmd.getName(), cmd);
		knownCommands.put(cmd.getName(), cmd);
		List<String> aliases = (List<String>)pl.getDescription().getCommands().get(cmd.getName()).get("aliases");
		for(String alias : aliases){
			if(!knownCommands.containsKey("xessentials:"+alias)){
				knownCommands.put("xessentials:"+alias, cmd);
			}
			if(!knownCommands.containsKey(alias)){
				knownCommands.put(alias, cmd);
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:xEssentials,項目名稱:xEssentials-deprecated-bukkit,代碼行數:29,代碼來源:CommandManager.java

示例13: unregisterBukkitCommand

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
public static void unregisterBukkitCommand(PluginCommand cmd) {
	try {
		Object result = getPrivateField(Bukkit.getServer().getPluginManager(), "commandMap");
		SimpleCommandMap commandMap = (SimpleCommandMap) result;
		Object map = getPrivateField(commandMap, "knownCommands");
		@SuppressWarnings("unchecked")
		HashMap<String, Command> knownCommands = (HashMap<String, Command>) map;
		knownCommands.remove(cmd.getName());
		for (String alias : cmd.getAliases()) {
			if(knownCommands.containsKey(alias) && knownCommands.get(alias).toString().contains(Bukkit.getName())) {
				knownCommands.remove(alias);
			}
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:jalapeno777,項目名稱:AdminAid,代碼行數:19,代碼來源:CommandUtilities.java

示例14: getCommandTimingsByPlugin

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
public static Map<String, MonitorRecord> getCommandTimingsByPlugin(Plugin plg) {
	Map<String, MonitorRecord> record = new HashMap<>();
	if (plg == null) {
		return record;
	}
	try {
		SimpleCommandMap simpleCommandMap = Reflection
				.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class)
				.get(Bukkit.getPluginManager());
		for (Command command : simpleCommandMap.getCommands()) {
			if (command instanceof PluginCommand) {
				PluginCommand pluginCommand = (PluginCommand) command;
				if (plg.equals(pluginCommand.getPlugin())) {
					FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class,
							"executor", CommandExecutor.class);
					CommandExecutor executor = commandField.get(pluginCommand);
					if (executor instanceof CommandInjector) {
						CommandInjector commandInjector = (CommandInjector) executor;
						record = mergeRecordMap(record, commandInjector.getMonitorRecordMap());
					}

				}
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return record;
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:30,代碼來源:MonitorUtils.java

示例15: registerDynamicCommand

import org.bukkit.command.SimpleCommandMap; //導入依賴的package包/類
/**
 * Registers the dynamic command.
 *
 * @param command command
 */
private void registerDynamicCommand(String command) {
    try {
        final Class<?> clazz = Class.forName("org.bukkit.craftbukkit.VERSION.CraftServer".replace("VERSION", getServerVersion()));
        final Object server = clazz.cast(Bukkit.getServer());
        final SimpleCommandMap map = (SimpleCommandMap) server.getClass().getDeclaredMethod("getCommandMap").invoke(server);
        map.register(command, this);
    } catch (final Exception ex) {
        Bukkit.getLogger().log(Level.WARNING, "Cannot register dynamic command.", ex);
    }
}
 
開發者ID:Shynixn,項目名稱:PetBlocks,代碼行數:16,代碼來源:SimpleCommandExecutor.java


注:本文中的org.bukkit.command.SimpleCommandMap類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。