当前位置: 首页>>代码示例>>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;未经允许,请勿转载。