/** * Gets the {@link PluginManager}. * * @return The plugin manager */ default PluginManager getPluginManager() { return Sponge.getPluginManager(); }
@Override protected Object getValue(String choice) throws IllegalArgumentException { Optional<PluginContainer> plugin = Sponge.getPluginManager().getPlugin(choice); return plugin.orElseThrow(() -> new IllegalArgumentException("Plugin " + choice + " was not found")); } }
@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getPluginManager().getPlugins().stream().map(PluginContainer::getId).collect(Collectors.toList()); }
/** * Gets whether permission for third-party metrics gathering has been * granted for a specific plugin (or the global permission if the plugin * has not got a specific permission or lack thereof). * * <p>The value returned from this <em>should not be stored</em>. As the * configuration/permission can be updated at any time, it is best to * check this each time server metric collection is due to occur.</p> * * @param plugin The plugin object (annotated with * {@link org.spongepowered.api.plugin.Plugin}) * @throws IllegalArgumentException if the supplied object is not a plugin * object * @return true if metrics gathering plugins have permission to gather * data about this plugin */ default boolean areMetricsEnabled(final Object plugin) throws IllegalArgumentException { return this.areMetricsEnabled(Sponge.getPluginManager().fromInstance(plugin) .orElseThrow(() -> new IllegalArgumentException("The supplied object is not a plugin object."))); }
/** * Builds a new {@link ShapelessCraftingRecipe} from this builder. * * @param id The id of this recipe. * @param plugin The owning plugin. * @return A new {@link ShapelessCraftingRecipe} * @throws IllegalStateException If not all required options * were specified * @deprecated Use {@link #build()} instead in combination with {@link #id(String)} */ @Deprecated default ShapelessCraftingRecipe build(String id, Object plugin) { try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { final PluginContainer container; if (plugin instanceof PluginContainer) { container = (PluginContainer) plugin; } else { container = Sponge.getPluginManager().fromInstance(plugin).orElseThrow(() -> new IllegalArgumentException( "Plugin must be a PluginContainer or plugin instance, not " + plugin)); } frame.pushCause(container); return id(id).build(); } } }
/** * Builds a {@link ShapedCraftingRecipe} from this builder. * * @param id The id of this recipe. * @param plugin The owning plugin. * @return A new {@link ShapedCraftingRecipe} * @throws IllegalStateException If not all required options * were specified * @deprecated Use {@link #build()} instead in combination with {@link #id(String)} */ @Deprecated default ShapedCraftingRecipe build(String id, Object plugin) { try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { final PluginContainer container; if (plugin instanceof PluginContainer) { container = (PluginContainer) plugin; } else { container = Sponge.getPluginManager().fromInstance(plugin).orElseThrow(() -> new IllegalArgumentException( "Plugin must be a PluginContainer or plugin instance, not " + plugin)); } frame.pushCause(container); return id(id).build(); } } }
private SpongeGameInterface(Object plugin, AsyncQueue asyncQueue) { this.asyncQueue = asyncQueue; if (plugin == null || !Sponge.getPluginManager().fromInstance(plugin).isPresent()) { throw new IllegalArgumentException("Not a valid Sponge Plugin"); } this.plugin = plugin; }
@Override protected Object getValue(String choice) throws IllegalArgumentException { Optional<PluginContainer> plugin = Sponge.getPluginManager().getPlugin(choice); return plugin.orElseThrow(() -> new IllegalArgumentException("Plugin " + choice + " was not found")); } }
@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getPluginManager().getPlugins().stream().map(PluginContainer::getId).collect(Collectors.toList()); }
@Override public Optional<PluginContainer> getLive() { return Sponge.getPluginManager().getPlugin(id); }
private Main getMMCRestrictPlugin() { Optional<PluginContainer> optContainer = Sponge.getPluginManager().getPlugin("mmcrestrict"); if (!optContainer.isPresent()) { throw new InternalServerErrorException("MMCRestrict plugin not found"); } Optional<?> optPlugin = optContainer.get().getInstance(); if (!optPlugin.isPresent()) { throw new InternalServerErrorException("MMCRestrict plugin instance not found"); } return (Main)optPlugin.get(); }
public static String getNick(Player p) { if (!Sponge.getPluginManager().getPlugin("nucleus").isPresent()) return p.getName(); return NucleusAPI.getNicknameService() .map(s -> s.getNickname(p).map(Text::toPlain).orElse(null)) .orElse(p.getName()); }
private UniversalMarket getUMPlugin() { Optional<PluginContainer> optContainer = Sponge.getPluginManager().getPlugin("universalmarket"); if (!optContainer.isPresent()) { throw new InternalServerErrorException("UniversalMarket plugin not found"); } Optional<?> optPlugin = optContainer.get().getInstance(); if (!optPlugin.isPresent()) { throw new InternalServerErrorException("UniversalMarket plugin instance not found"); } return (UniversalMarket)optPlugin.get(); } }
private HuskyCrates getHuskyPlugin() { Optional<PluginContainer> optContainer = Sponge.getPluginManager().getPlugin("huskycrates"); if (!optContainer.isPresent()) { throw new InternalServerErrorException("HuskyCrates plugin not found"); } Optional<?> optPlugin = optContainer.get().getInstance(); if (!optPlugin.isPresent()) { throw new InternalServerErrorException("HuskyCrates plugin instance not found"); } return (HuskyCrates)optPlugin.get(); }
private Main getMMCTicketsPlugin() { Optional<PluginContainer> optContainer = Sponge.getPluginManager().getPlugin("mmctickets"); if (!optContainer.isPresent()) { throw new InternalServerErrorException("MMCTickets plugin not found"); } Optional<?> optPlugin = optContainer.get().getInstance(); if (!optPlugin.isPresent()) { throw new InternalServerErrorException("MMCTickets plugin instance not found"); } return (Main)optPlugin.get(); }
private void appendPluginInformation() { Collection<PluginContainer> plugins = Sponge.getPluginManager().getPlugins(); appendHeader("Plugins (" + plugins.size() + ')'); LogListBlock log = new LogListBlock(); for (PluginContainer plugin : plugins) { log.put(plugin.getName(), plugin.getVersion().orElse("UNKNOWN")); } append(log); appendln(); }
@Override public void run() { // Plugin was disabled, e.g. because of a reload (is this even possible in Sponge?) if (!Sponge.getPluginManager().isLoaded(plugin.getId())) { timer.cancel(); return; } // The data collection (e.g. for custom graphs) is done sync // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) Scheduler scheduler = Sponge.getScheduler(); Task.Builder taskBuilder = scheduler.createTaskBuilder(); taskBuilder.execute(() -> submitData()).submit(plugin); } }, 1000*60*5, 1000*60*30);
@Listener public void onMessageChannelEvent(MessageChannelEvent.Chat e, @First Player p) { if (!p.hasPermission("magibridge.chat")) return; if (!Sponge.getServer().getOnlinePlayers().contains(p) || e.isMessageCancelled()) return; if (e.getChannel().isPresent() && Sponge.getPluginManager().isLoaded("nations")) { if (e.getChannel().get() instanceof NationMessageChannel) { return; // don't want to send private nation messages to Discord } } FormatType format = FormatType.SERVER_TO_DISCORD_FORMAT; String channel = MagiBridge.getConfig().CHANNELS.MAIN_CHANNEL; if (e.getChannel().isPresent() && Sponge.getPluginManager().isLoaded("nucleus") && MagiBridge.getConfig().CORE.SEND_HELPOP) { if (e.getChannel().get().getClass().getName().equals("io.github.nucleuspowered.util.PermissionMessageChannel")) { channel = MagiBridge.getConfig().CHANNELS.NUCLEUS.HELPOP_CHANNEL.isEmpty() ? MagiBridge.getConfig().CHANNELS.NUCLEUS.STAFF_CHANNEL : MagiBridge.getConfig().CHANNELS.NUCLEUS.HELPOP_CHANNEL; } } Map<String, String> placeholders = new HashMap<>(); placeholders.put("%prefix%", p.getOption("prefix").orElse("")); placeholders.put("%player%", p.getName()); placeholders.put("%message%", e.getFormatter().getBody().toText().toPlain()); boolean removeEveryone = !p.hasPermission("magibridge.everyone"); DiscordHandler.sendMessageToDiscord(channel, format, placeholders, removeEveryone, 0, p.hasPermission("magibridge.mention")); }
private void registerListeners() { if (Config.CHANNELS.USE_NUCLEUS) { if (Sponge.getPluginManager().getPlugin("nucleus").isPresent()) { Sponge.getEventManager().registerListeners(this, new SpongeChatListener()); logger.info("Hooking into Nucleus"); if (Sponge.getPluginManager().getPlugin("ultimatechat").isPresent()) { Sponge.getEventManager().registerListeners(this, new ChatListener()); logger.info("Hooking into UltimateChat");
@Listener public void onMessage(SendChannelMessageEvent e) { if (!e.getSender().hasPermission("magibridge.chat")) return; // Tell if (e.getChannel() == null) return; String channel = getKey(e.getChannel().getName().toLowerCase()); if (channel == null) return; Player p = e.getSender() instanceof Player ? (Player) e.getSender() : null; if (p != null && MagiBridge.getConfig().CORE.HIDE_VANISHED_CHAT && p.get(Keys.VANISH).orElse(false)) return; FormatType format = FormatType.SERVER_TO_DISCORD_FORMAT; Map<String, String> placeholders = new HashMap<>(); placeholders.put("%prefix%", e.getSender().getOption("prefix").orElse("")); placeholders.put("%player%", e.getSender().getName()); placeholders.put("%message%", e.getMessage().toPlain()); placeholders.put("%topgroup%", p != null ? GroupUtil.getHighestGroup(p) : ""); if (p != null && Sponge.getPluginManager().getPlugin("nucleus").isPresent()) { placeholders.put("%nick%", NucleusHandler.getNick(p)); } boolean removeEveryone = !e.getSender().hasPermission("magibridge.everyone"); DiscordHandler.sendMessageToDiscord(channel, format, placeholders, removeEveryone, 0, e.getSender().hasPermission("magibridge.mention")); }