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");
}
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));
}
}
}
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);
}
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;
}
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);
}
Aggregations