public void loadPlugins() { pluginManager.registerInterface(JavaPluginLoader.class); File pluginFolder = (File) console.options.valueOf("plugins"); if (pluginFolder.exists()) { Plugin[] plugins = pluginManager.loadPlugins(pluginFolder); for (Plugin plugin : plugins) { try { String message = String.format("Loading %s", plugin.getDescription().getFullName()); plugin.getLogger().info(message); plugin.onLoad(); } catch (Throwable ex) { Logger.getLogger(CraftServer.class.getName()).log(Level.SEVERE, ex.getMessage() + " initializing " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex); } } } else { pluginFolder.mkdir(); } }
public void loadPlugins() { pluginManager.registerInterface(JavaPluginLoader.class); File pluginFolder = new File("plugins/"); if (pluginFolder.exists()) { Plugin[] plugins = pluginManager.loadPlugins(pluginFolder); for (Plugin plugin : plugins) { try { String message = String.format("Loading %s", plugin.getDescription().getFullName()); plugin.getLogger().info(message); plugin.onLoad(); } catch (Throwable ex) { Logger.getLogger(NetherServer.class.getName()).log(Level.SEVERE, ex.getMessage() + " initializing " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex); } } } else { pluginFolder.mkdir(); } }
public void loadPlugins() { // Clear the command map commandMap.clearCommands(); // Clear plugins and prepare to load pluginManager.clearPlugins(); pluginManager.registerInterface(JavaPluginLoader.class); // Call onLoad methods for (Plugin plugin : pluginManager.loadPlugins(Constants.pluginsDir)) { try { getLogger().info(String.format("Loading %s", plugin.getDescription().getFullName())); plugin.onLoad(); } catch (Exception ex) { getLogger().log(Level.SEVERE, ex.getMessage() + " initializing " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex); } } }
@Before public void setUpPlugin() throws IOException { dataFolder = temporaryFolder.newFolder(); // Wire various Bukkit components setField(Bukkit.class, "server", null, server); given(server.getLogger()).willReturn(mock(Logger.class)); given(server.getScheduler()).willReturn(mock(BukkitScheduler.class)); given(server.getPluginManager()).willReturn(pluginManager); given(server.getVersion()).willReturn("1.9.4-RC1"); // SettingsManager always returns the default given(settings.getProperty(any(Property.class))).willAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return ((Property<?>) invocation.getArguments()[0]).getDefaultValue(); } }); // PluginDescriptionFile is final and so cannot be mocked PluginDescriptionFile descriptionFile = new PluginDescriptionFile( "PerWorldInventory", "N/A", PerWorldInventory.class.getCanonicalName()); JavaPluginLoader pluginLoader = new JavaPluginLoader(server); plugin = new PerWorldInventory(pluginLoader, descriptionFile, dataFolder, null); setField(JavaPlugin.class, "logger", plugin, mock(PluginLogger.class)); }
@Before public void setUpPlugin() throws IOException { File dataFolder = temporaryFolder.newFolder(); // Set mock server setField(Bukkit.class, "server", null, server); given(server.getLogger()).willReturn(mock(Logger.class)); // PluginDescriptionFile is final and so cannot be mocked PluginDescriptionFile descriptionFile = new PluginDescriptionFile( "PerWorldInventory", "N/A", PerWorldInventory.class.getCanonicalName()); JavaPluginLoader pluginLoader = new JavaPluginLoader(server); plugin = new PerWorldInventory(pluginLoader, descriptionFile, dataFolder, null); setField(JavaPlugin.class, "logger", plugin, mock(PluginLogger.class)); Injector injector = new InjectorBuilder().addDefaultHandlers("me.gnat008.perworldinventory").create(); injector.register(PermissionManager.class, permissionManager); injector.register(ConvertCommand.class, convertCommand); injector.register(HelpCommand.class, helpCommand); injector.register(PerWorldInventoryCommand.class, pwiCommand); injector.register(ReloadCommand.class, reloadCommand); injector.register(SetWorldDefaultCommand.class, setWorldDefaultsCommand); injector.register(VersionCommand.class, versionCommand); plugin.registerCommands(injector); TestHelper.setField(PerWorldInventory.class, "permissionManager", plugin, permissionManager); }
/** * Retrieve loaders field from JavaPluginLoader instance * @param pm plugin manager to search for JavaPluginLoader in (if necessary) * @return loaders field retrieved */ @SuppressWarnings("unchecked") public static Map<String, ?> getJavaLoaders(PluginManager pm) { if (javaLoaders != null) return javaLoaders; getJavaPluginLoader(pm); if (javapluginloader == null) return null; try { Field fieldLoaders = JavaPluginLoader.class.getDeclaredField("loaders"); fieldLoaders.setAccessible(true); javaLoaders = (Map<String, ?>) fieldLoaders.get(javapluginloader); return javaLoaders; } catch (Throwable t) { t.printStackTrace(); return null; } }
private void loadPlugins() { File pluginsDir = new File("plugins"); if (!pluginsDir.isDirectory()) { getLogger().info("Creating plugins directory"); if (!pluginsDir.mkdir()) { getLogger().severe("Failed to create plugins directory"); System.exit(-1); } } pluginManager.registerInterface(JavaPluginLoader.class); logger.info("Loading plugins..."); pluginManager.loadPlugins(pluginsDir); getLogger().info("Loaded "+pluginManager.getPlugins().length+" plugins"); for (Plugin plugin : pluginManager.getPlugins()) { getLogger().info("Enabling plugin " + plugin); pluginManager.enablePlugin(plugin); } }
public void loadPlugins() { if (pluginsDir.isDirectory()) { // Clear plugins and prepare to load pluginManager.clearPlugins(); pluginManager.registerInterface(JavaPluginLoader.class); // Call onLoad methods for (Plugin plugin : pluginManager.loadPlugins(pluginsDir)) { try { getLogger().info(String.format("Loading %s", plugin.getDescription().getFullName())); plugin.onLoad(); } catch (RuntimeException ex) { getLogger().log(Level.SEVERE, ex.getMessage() + " initializing " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex); } } } else { if (!pluginsDir.mkdir()) { logger.log(Level.SEVERE, "Could not create plugins directory: " + pluginsDir); } } }
@Before public void initAuthMe() throws IOException { dataFolder = temporaryFolder.newFolder(); File settingsFile = new File(dataFolder, "config.yml"); JavaPluginLoader pluginLoader = new JavaPluginLoader(server); Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "config.test.yml"), settingsFile); // Mock / wire various Bukkit components given(server.getLogger()).willReturn(Logger.getAnonymousLogger()); ReflectionTestUtils.setField(Bukkit.class, null, "server", server); given(server.getPluginManager()).willReturn(pluginManager); // PluginDescriptionFile is final: need to create a sample one PluginDescriptionFile descriptionFile = new PluginDescriptionFile( "AuthMe", "N/A", AuthMe.class.getCanonicalName()); // Initialize AuthMe authMe = new AuthMe(pluginLoader, descriptionFile, dataFolder, null); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); // Initialize the Mock server. JavaPluginLoader mockPluginLoader = new JavaPluginLoader(mockServer); Whitebox.setInternalState(mockPluginLoader, "server", mockServer); when(mockServer.getName()).thenReturn("TestBukkit"); Logger.getLogger("Minecraft").setParent(TestUtil.logger); when(mockServer.getLogger()).thenReturn(TestUtil.logger); // Return a fake PDF file. PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("PrisonPicks", "1.3.4-Test", "com.philderbeast.prisonpicks.PrisonPicks")); when(pdf.getAuthors()).thenReturn(new ArrayList<String>()); pickCommands = new PickCommands(); // MOCKS BELOW HERE when(player.getUniqueId()).thenReturn(UUID.fromString("e3078d5d-8943-420c-8366-4aa51e212df3")); when(player.getInventory()).thenReturn(playerInventory); PowerMockito.mockStatic(Bukkit.class); when(Bukkit.getPlayer(anyString())).thenReturn(player); when(Bukkit.getItemFactory()).thenReturn(itemFactory); when(itemFactory.getItemMeta(Material.DIAMOND_PICKAXE)).thenReturn(itemMeta); }
public BukkitServer(SpongeBukkitMod mod, MinecraftServer server) { this.mod = Preconditions.checkNotNull(mod); this.server = Preconditions.checkNotNull(server); this.commandMap = new BukkitCommandMap(this); this.pluginManager = new SimplePluginManager(this,this.commandMap); this.pluginManager.registerInterface(JavaPluginLoader.class); }
/** * Constructor for testing. */ protected BukkitPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { super(loader, description, dataFolder, file); Nucleus._plugin = this; }
/** * Constructor for testing. */ protected NucleusPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { super(loader, description, dataFolder, file); _isTesting = true; try { onInit(); } catch (Throwable e) { e.printStackTrace(); throw new RuntimeException(e); } }
protected MockPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { super(loader, description, dataFolder, file); }
@SuppressWarnings("deprecation") public PluginManagerMock(ServerMock server) { this.server = server; loader = new JavaPluginLoader(this.server); }
protected TestPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { super(loader, description, dataFolder, file); }
@SuppressWarnings({"resource", "deprecation"}) @Before public void before() throws Exception { final File dataDir = new File("target/classes/"); final File jar = new File("target/", "skript.jar"); assumeTrue(jar.exists()); final Logger l = Logger.getLogger(getClass().getCanonicalName()); l.setParent(SkriptLogger.LOGGER); l.setLevel(Level.WARNING); final Server s = createMock(Server.class); s.getLogger(); expectLastCall().andReturn(l).anyTimes(); s.isPrimaryThread(); expectLastCall().andReturn(true).anyTimes(); s.getName(); expectLastCall().andReturn("Whatever").anyTimes(); s.getVersion(); expectLastCall().andReturn("2.0").anyTimes(); s.getBukkitVersion(); expectLastCall().andReturn("2.0").anyTimes(); replay(s); Bukkit.setServer(s); final Skript skript = (Skript) ObjenesisHelper.newInstance(Skript.class); // bypass the class loader check final Field instance = Skript.class.getDeclaredField("instance"); instance.setAccessible(true); instance.set(null, skript); final PluginDescriptionFile pdf = new PluginDescriptionFile(new FileInputStream(new File(dataDir, "plugin.yml"))); // final void init(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) { final Method init = JavaPlugin.class.getDeclaredMethod("init", PluginLoader.class, Server.class, PluginDescriptionFile.class, File.class, File.class, ClassLoader.class); init.setAccessible(true); init.invoke(skript, new JavaPluginLoader(s), s, pdf, dataDir, jar, getClass().getClassLoader()); Skript.getAddonInstance().loadClasses("ch.njol.skript", "entity"); new JavaClasses(); new BukkitClasses(); new BukkitEventValues(); new SkriptClasses(); final Field r = Skript.class.getDeclaredField("acceptRegistrations"); r.setAccessible(true); r.set(null, false); Classes.onRegistrationsStop(); }
protected ExilePearlPlugin(final JavaPluginLoader loader, final PluginDescriptionFile description, final File dataFolder, final File file) { super(loader, description, dataFolder, file); core = CorePluginFactory.createCore(this); }
protected PerWorldInventory(final JavaPluginLoader loader, final PluginDescriptionFile description, final File dataFolder, final File file) { super(loader, description, dataFolder, file); }
protected JavaPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { }