本文整理汇总了Java中org.bukkit.plugin.SimplePluginManager类的典型用法代码示例。如果您正苦于以下问题:Java SimplePluginManager类的具体用法?Java SimplePluginManager怎么用?Java SimplePluginManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimplePluginManager类属于org.bukkit.plugin包,在下文中一共展示了SimplePluginManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inject
import org.bukkit.plugin.SimplePluginManager; //导入依赖的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();
}
}
}
示例2: uninject
import org.bukkit.plugin.SimplePluginManager; //导入依赖的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();
}
}
}
示例3: onCalled
import org.bukkit.plugin.SimplePluginManager; //导入依赖的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;
}
示例4: getCommandTimingsByPlugin
import org.bukkit.plugin.SimplePluginManager; //导入依赖的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;
}
示例5: inject
import org.bukkit.plugin.SimplePluginManager; //导入依赖的package包/类
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();
}
}
}
示例6: uninject
import org.bukkit.plugin.SimplePluginManager; //导入依赖的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) completer).getTabCompleter());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例7: createMockServer
import org.bukkit.plugin.SimplePluginManager; //导入依赖的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;
}
示例8: CommandFramework
import org.bukkit.plugin.SimplePluginManager; //导入依赖的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();
}
}
}
示例9: getCommandMap
import org.bukkit.plugin.SimplePluginManager; //导入依赖的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;
}
示例10: reload
import org.bukkit.plugin.SimplePluginManager; //导入依赖的package包/类
/**
* Restart game and reset OMGPI registered systems.
*/
@SuppressWarnings("unchecked")
public void reload() {
Bukkit.getScheduler().cancelAllTasks();
OMGPlayer.link.values().forEach(OMGPlayer::remove);
OMGTeam.registeredTeams.clear();
OMGKit.kits.clear();
OMGLoot.loots.clear();
OMGCommand.unregisterAll();
gameworld.unload();
Bukkit.getServer().getPluginManager().disablePlugin(g);
try {
Field pl = SimplePluginManager.class.getDeclaredField("plugins");
pl.setAccessible(true);
((List<Plugin>) pl.get(Bukkit.getServer().getPluginManager())).remove(g);
Field ln = SimplePluginManager.class.getDeclaredField("lookupNames");
ln.setAccessible(true);
((Map<String, Plugin>) ln.get(Bukkit.getServer().getPluginManager())).remove(g.getDescription().getName());
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
HandlerList.unregisterAll();
init();
}
示例11: registerAliases
import org.bukkit.plugin.SimplePluginManager; //导入依赖的package包/类
private void registerAliases(String name, List<String> aliases) {
List<String> aliases1 = new ArrayList<>(aliases);
for (Command cmd:PluginCommandYamlParser.parse(uchat)){
if (cmd.getName().equals(name)){
cmd.setAliases(aliases1);
cmd.setLabel(name);
try {
Field field = SimplePluginManager.class.getDeclaredField("commandMap");
field.setAccessible(true);
CommandMap commandMap = (CommandMap)(field.get(getServer().getPluginManager()));
Method register = commandMap.getClass().getMethod("register", String.class, Command.class);
register.invoke(commandMap, cmd.getName(),cmd);
((PluginCommand) cmd).setExecutor(listener);
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
示例12: inject
import org.bukkit.plugin.SimplePluginManager; //导入依赖的package包/类
private void inject() throws Exception {
PluginManager pluginManager = this.plugin.getServer().getPluginManager();
if (!(pluginManager instanceof SimplePluginManager)) {
this.plugin.getLog().severe("PluginManager instance is not a 'SimplePluginManager', instead: " + pluginManager.getClass());
this.plugin.getLog().severe("Unable to inject LuckPerms Permission Subscription map.");
return;
}
Object map = PERM_SUBS_FIELD.get(pluginManager);
if (map instanceof LPSubscriptionMap) {
return; // already injected
}
//noinspection unchecked
Map<String, Map<Permissible, Boolean>> castedMap = (Map<String, Map<Permissible, Boolean>>) map;
// make a new subscription map
LPSubscriptionMap newMap = new LPSubscriptionMap(this.plugin, castedMap);
// inject it
PERM_SUBS_FIELD.set(pluginManager, newMap);
}
示例13: uninject
import org.bukkit.plugin.SimplePluginManager; //导入依赖的package包/类
public static void uninject() {
try {
PluginManager pluginManager = Bukkit.getServer().getPluginManager();
if (!(pluginManager instanceof SimplePluginManager)) {
return;
}
Object map = PERM_SUBS_FIELD.get(pluginManager);
if (map instanceof LPSubscriptionMap) {
LPSubscriptionMap lpMap = (LPSubscriptionMap) map;
PERM_SUBS_FIELD.set(pluginManager, lpMap.detach());
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: addExecutor
import org.bukkit.plugin.SimplePluginManager; //导入依赖的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);
}
示例15: FakePlugin
import org.bukkit.plugin.SimplePluginManager; //导入依赖的package包/类
public FakePlugin(Plugin parent) {
this.parent = parent;
plugins = Reflection.getField(Reflection.makeField(SimplePluginManager.class, "plugins"), parent.getServer().getPluginManager());
lookupNames = Reflection.getField(Reflection.makeField( SimplePluginManager.class, "lookupNames"), parent.getServer().getPluginManager());
StringWriter write = new StringWriter();
parent.getDescription().save(write);
String yaml = write.toString().replaceAll(parent.getName(), getFakeName());
try {
description = new PluginDescriptionFile(new StringReader(yaml));
} catch (InvalidDescriptionException ex) {
Throwables.propagate(ex);
}
plugins.add(this);
lookupNames.put(getName(), this);
}