Search in sources :

Example 16 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LuckPerms by lucko.

the class LPSpongeBootstrap method getServerVersion.

@Override
public String getServerVersion() {
    PluginContainer api = getGame().getPlatform().getContainer(Platform.Component.API);
    PluginContainer impl = getGame().getPlatform().getContainer(Platform.Component.IMPLEMENTATION);
    return api.getName() + ": " + api.getVersion().orElse("null") + " - " + impl.getName() + ": " + impl.getVersion().orElse("null");
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 17 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project modules-extra by CubeEngine.

the class ApiServer method registerApiHandlers.

public void registerApiHandlers(final Class owner, final Object holder) {
    checkNotNull(holder, "The API holder must not be null!");
    for (Method method : holder.getClass().getDeclaredMethods()) {
        Endpoint aEndpoint = method.getAnnotation(Endpoint.class);
        if (aEndpoint != null) {
            String route = aEndpoint.route();
            if (route.isEmpty()) {
                route = deCamelCase(method.getName(), "/");
            }
            Optional<PluginContainer> pc = mm.getPlugin(owner);
            if (pc.isPresent()) {
                route = pc.get().getId() + "/" + route;
            } else {
                route = deCamelCase(owner.getSimpleName().toLowerCase(), "-") + "/" + route;
            }
            route = HttpRequestHandler.normalizePath(route);
            String perm = null;
            if (aEndpoint.authRequired()) {
                perm = pm.getBasePermission(owner).getId() + ".webapi.";
                if (method.isAnnotationPresent(ApiPermission.class)) {
                    ApiPermission apiPerm = method.getAnnotation(ApiPermission.class);
                    if (apiPerm.value().isEmpty()) {
                        perm = perm + route;
                    } else {
                        perm = perm + apiPerm.value();
                    }
                } else {
                    perm = perm + route;
                }
            }
            LinkedHashMap<String, Class> params = new LinkedHashMap<>();
            Class<?>[] types = method.getParameterTypes();
            Annotation[][] paramAnnotations = method.getParameterAnnotations();
            for (int i = 1; i < types.length; i++) {
                Class<?> type = types[i];
                Value val = null;
                for (Annotation annotation : paramAnnotations[i]) {
                    if (annotation instanceof Value) {
                        val = (Value) annotation;
                        break;
                    }
                }
                if (val == null) {
                    throw new IllegalArgumentException("Missing Value Annotation for Additional Parameters");
                }
                if (params.put(val.value(), type) != null) {
                    throw new IllegalArgumentException("Duplicate value in Value Annotation");
                }
            }
            this.handlers.put(route, new ReflectedApiHandler(owner, route, perm, params, aEndpoint.method(), method, holder, cm));
        }
    }
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) LinkedHashMap(java.util.LinkedHashMap)

Example 18 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeVanilla by SpongePowered.

the class MixinAdvancementManager method onLoadAdvancements.

@Redirect(method = "reload", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementList;loadAdvancements(Ljava/util/Map;)V"))
private void onLoadAdvancements(AdvancementList advancementList, Map<ResourceLocation, Advancement.Builder> advancements) {
    if (!SpongeImpl.isInitialized()) {
        return;
    }
    for (PluginContainer pluginContainer : Sponge.getPluginManager().getPlugins()) {
        // Skip the minecraft advancements
        if (pluginContainer.getId().equals("minecraft")) {
            continue;
        }
        final Optional<Path> optSource = pluginContainer.getSource();
        if (optSource.isPresent()) {
            final Path source = optSource.get();
            final String base = "assets/" + pluginContainer.getId() + "/advancements";
            Path root;
            if (Files.isDirectory(source)) {
                root = source.resolve(base);
            } else {
                try {
                    final FileSystem fileSystem = FileSystems.newFileSystem(source, null);
                    root = fileSystem.getPath("/" + base);
                } catch (IOException e) {
                    SpongeImpl.getLogger().error("Error loading FileSystem from jar: ", e);
                    continue;
                }
            }
            if (!Files.exists(root)) {
                continue;
            }
            try {
                Files.walk(root).forEach(path -> {
                    if (!FilenameUtils.getExtension(path.getFileName().toString()).equals("json")) {
                        return;
                    }
                    final Path relPath = root.relativize(path);
                    final String id = FilenameUtils.removeExtension(relPath.toString()).replaceAll("\\\\", "/");
                    final ResourceLocation resourceLocation = new ResourceLocation(pluginContainer.getId(), id);
                    if (!advancements.containsKey(resourceLocation)) {
                        try (BufferedReader reader = Files.newBufferedReader(path)) {
                            final Advancement.Builder advancementBuilder = JsonUtils.fromJson(GSON, reader, Advancement.Builder.class);
                            advancements.put(resourceLocation, advancementBuilder);
                        } catch (IOException e) {
                            SpongeImpl.getLogger().error("Failed to read advancement " + resourceLocation + " from path " + path, e);
                        }
                    }
                });
            } catch (IOException e) {
                SpongeImpl.getLogger().error("Failed to walk path: " + root, e);
            }
        }
    }
    advancementList.loadAdvancements(advancements);
}
Also used : Path(java.nio.file.Path) PluginContainer(org.spongepowered.api.plugin.PluginContainer) FileSystem(java.nio.file.FileSystem) ResourceLocation(net.minecraft.util.ResourceLocation) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Advancement(net.minecraft.advancements.Advancement) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 19 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeVanilla by SpongePowered.

the class VanillaChannelRegistrar method createRawChannel.

@Override
public ChannelBinding.RawDataChannel createRawChannel(Object plugin, String name) throws ChannelRegistrationException {
    PluginContainer container = checkCreateChannelArgs(plugin, name);
    validateChannel(name);
    VanillaRawDataChannel channel = new VanillaRawDataChannel(this, name, container);
    registerChannel(channel);
    return channel;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 20 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project core by CubeEngine.

the class ModuleManager method getLoggerFor.

public Log getLoggerFor(Class module) {
    PluginContainer container = this.modulePlugins.get(module);
    String name;
    if (container == null) {
        name = module.getSimpleName();
    } else {
        name = container.getName();
        if (name.startsWith("CubeEngine - ")) {
            name = name.substring("CubeEngine - ".length());
        }
    }
    return this.logProvider.getLogger(module, name, container != null);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Aggregations

PluginContainer (org.spongepowered.api.plugin.PluginContainer)75 Text (org.spongepowered.api.text.Text)15 CommandResult (org.spongepowered.api.command.CommandResult)13 GenericArguments (org.spongepowered.api.command.args.GenericArguments)13 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)13 List (java.util.List)12 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)11 CommandException (org.spongepowered.api.command.CommandException)11 ArrayList (java.util.ArrayList)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)9 Sponge (org.spongepowered.api.Sponge)9 Player (org.spongepowered.api.entity.living.player.Player)8 Collection (java.util.Collection)7 Map (java.util.Map)7 Nullable (javax.annotation.Nullable)7 CommandSource (org.spongepowered.api.command.CommandSource)7 GenericArguments2 (org.lanternpowered.server.command.element.GenericArguments2)6 CommandMapping (org.spongepowered.api.command.CommandMapping)6 ArgumentParseException (org.spongepowered.api.command.args.ArgumentParseException)6