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


Java SimplePluginManager類代碼示例

本文整理匯總了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();
		}
	}
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:27,代碼來源:CommandInjector.java

示例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();
		}
	}
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:27,代碼來源:CommandInjector.java

示例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;
}
 
開發者ID:LukkitPlus,項目名稱:Lukkit,代碼行數:18,代碼來源:CentralPoint.java

示例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;
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:27,代碼來源:MonitorUtils.java

示例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();
		}
	}
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:22,代碼來源:CommandInjector.java

示例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();
		}
	}
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:27,代碼來源:CommandInjector.java

示例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;
}
 
開發者ID:EntryPointKR,項目名稱:MCLibrary,代碼行數:17,代碼來源:MockFactory.java

示例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();
        }
    }
}
 
開發者ID:ijoeleoli,項目名稱:ServerCommons,代碼行數:17,代碼來源:CommandFramework.java

示例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;
}
 
開發者ID:Borlea,項目名稱:EchoPet,代碼行數:27,代碼來源:CommandManager.java

示例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();
}
 
開發者ID:BurnyDaKath,項目名稱:OMGPI,代碼行數:27,代碼來源:OMGPI.java

示例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();
        }
	}			
}        
  }
 
開發者ID:FabioZumbi12,項目名稱:UltimateChat,代碼行數:21,代碼來源:UChat.java

示例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);
}
 
開發者ID:lucko,項目名稱:LuckPerms,代碼行數:24,代碼來源:SubscriptionMapInjector.java

示例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();
    }
}
 
開發者ID:lucko,項目名稱:LuckPerms,代碼行數:17,代碼來源:SubscriptionMapInjector.java

示例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);
}
 
開發者ID:caoli5288,項目名稱:EnderChest,代碼行數:19,代碼來源:PluginHelper.java

示例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);
}
 
開發者ID:TechzoneMC,項目名稱:TagTabAPI,代碼行數:20,代碼來源:FakePlugin.java


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