use of org.bukkit.plugin.PluginManager in project AuthMeReloaded by AuthMe.
the class PluginHookServiceTest method shouldUnhookEssentialsAndMultiverse.
@Test
public void shouldUnhookEssentialsAndMultiverse() {
// given
PluginManager pluginManager = mock(PluginManager.class);
setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// when
pluginHookService.unhookEssentials();
pluginHookService.unhookMultiverse();
// then
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false));
assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false));
}
use of org.bukkit.plugin.PluginManager in project AuthMeReloaded by AuthMe.
the class PluginHookServiceTest method shouldReturnNullForUnavailableMultiverse.
@Test
public void shouldReturnNullForUnavailableMultiverse() {
// given
PluginManager pluginManager = mock(PluginManager.class);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
World world = mock(World.class);
// when
Location result = pluginHookService.getMultiverseSpawn(world);
// then
assertThat(result, nullValue());
}
use of org.bukkit.plugin.PluginManager in project Jobs by GamingMesh.
the class JobsListener method onWorldLoad.
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldLoad(WorldLoadEvent event) {
World world = event.getWorld();
PluginManager pm = plugin.getServer().getPluginManager();
if (pm.getPermission("jobs.world." + world.getName().toLowerCase()) == null)
pm.addPermission(new Permission("jobs.world." + world.getName().toLowerCase(), PermissionDefault.TRUE));
}
use of org.bukkit.plugin.PluginManager in project SpaciousLib by anhcraft.
the class SPlugin method unloadPlugin.
public static boolean unloadPlugin(Plugin plugin) throws NoSuchFieldException, IllegalAccessException, IOException {
String name = plugin.getName();
PluginManager pluginManager = Bukkit.getPluginManager();
SimpleCommandMap commandMap = null;
List<Plugin> plugins = null;
Map<String, Plugin> names = null;
Map<String, Command> commands = null;
disablePlugin(plugin);
if (pluginManager != null) {
Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins");
Field lookupNamesField = Bukkit.getPluginManager().getClass().getDeclaredField("lookupNames");
Field commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
Field commandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
commandsField.setAccessible(true);
pluginsField.setAccessible(true);
commandMapField.setAccessible(true);
lookupNamesField.setAccessible(true);
commandMap = (SimpleCommandMap) commandMapField.get(pluginManager);
commands = (Map<String, Command>) commandsField.get(commandMap);
plugins = (List<Plugin>) pluginsField.get(pluginManager);
names = (Map<String, Plugin>) lookupNamesField.get(pluginManager);
}
if (plugins != null && plugins.contains(plugin)) {
plugins.remove(plugin);
}
if (names != null && names.containsKey(name)) {
names.remove(name);
}
if (commandMap != null) {
for (Iterator<Map.Entry<String, Command>> it = commands.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Command> entry = it.next();
if (entry.getValue() instanceof PluginCommand) {
PluginCommand c = (PluginCommand) entry.getValue();
if (c.getPlugin() == plugin) {
c.unregister(commandMap);
it.remove();
}
}
}
}
ClassLoader cl = plugin.getClass().getClassLoader();
if (cl instanceof URLClassLoader) {
((URLClassLoader) cl).close();
}
System.gc();
return true;
}
use of org.bukkit.plugin.PluginManager in project Essentials by drtshock.
the class EssentialsGeoIP method onEnable.
@Override
public void onEnable() {
final PluginManager pm = getServer().getPluginManager();
final IEssentials ess = (IEssentials) pm.getPlugin("Essentials");
if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
getLogger().log(Level.WARNING, tl("versionMismatchAll"));
}
if (!ess.isEnabled()) {
this.setEnabled(false);
return;
}
final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess);
pm.registerEvents(playerListener, this);
getLogger().log(Level.INFO, "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/.");
}
Aggregations