use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class LanternPluginManager method loadPlugin.
private void loadPlugin(PluginCandidate candidate) {
final String id = candidate.getId();
final LanternClassLoader classLoader = LanternClassLoader.get();
if (candidate.getSource().isPresent()) {
try {
classLoader.addBaseURL(candidate.getSource().get().toUri().toURL());
} catch (MalformedURLException e) {
throw new RuntimeException("Failed to add plugin '" + id + "' from " + candidate.getDisplaySource() + " to classpath", e);
}
}
final PluginMetadata metadata = candidate.getMetadata();
checkNotNull(metadata, "metadata");
final String name = firstNonNull(metadata.getName(), id);
final String version = firstNonNull(metadata.getVersion(), "unknown");
try {
final Class<?> pluginClass = Class.forName(candidate.getPluginClass());
final PluginContainer container = new LanternPluginContainer(id, this.injector, pluginClass, metadata, candidate.getSource().orElse(null));
registerPlugin(container);
registerPluginInstance(container);
this.eventManager.registerListeners(container, container.getInstance().get());
this.logger.info("Loaded plugin: {} {} (from {})", name, version, candidate.getDisplaySource());
} catch (Throwable e) {
this.logger.error("Failed to load plugin: {} {} (from {})", name, version, candidate.getDisplaySource(), e);
}
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class LanternTaskBuilder method submit.
@Override
public Task submit(Object plugin) {
final PluginContainer pluginContainer = checkPlugin(plugin, "plugin");
checkState(this.consumer != null, "consumer not set");
final String name;
if (this.name == null) {
name = this.scheduler.getNameFor(pluginContainer, this.syncType);
} else {
name = this.name;
}
long delay = this.delay;
long interval = this.interval;
boolean delayIsTicks = this.delayIsTicks;
boolean intervalIsTicks = this.intervalIsTicks;
if (this.syncType == ScheduledTask.TaskSynchronicity.ASYNCHRONOUS) {
delay = delayIsTicks ? delay * LanternGame.TICK_DURATION_NS : delay;
interval = intervalIsTicks ? interval * LanternGame.TICK_DURATION_NS : interval;
delayIsTicks = intervalIsTicks = false;
}
ScheduledTask task = new ScheduledTask(this.syncType, this.consumer, name, delay, delayIsTicks, interval, intervalIsTicks, pluginContainer);
this.scheduler.submit(task);
return task;
}
use of org.spongepowered.api.plugin.PluginContainer in project SpongeAPI by SpongePowered.
the class SimpleDispatcher method process.
@Override
public CommandResult process(CommandSource source, String commandLine) throws CommandException {
final String[] argSplit = commandLine.split(" ", 2);
Optional<CommandMapping> cmdOptional = get(argSplit[0], source);
if (!cmdOptional.isPresent()) {
// TODO: Fix properly to use a SpongeTranslation??
throw new CommandNotFoundException(t("commands.generic.notFound"), argSplit[0]);
}
final String arguments = argSplit.length > 1 ? argSplit[1] : "";
CommandMapping mapping = cmdOptional.get();
Optional<PluginContainer> pluginOwner = Sponge.getCommandManager().getOwner(mapping);
if (pluginOwner.isPresent()) {
Sponge.getCauseStackManager().pushCause(pluginOwner.get());
}
final CommandCallable spec = mapping.getCallable();
try {
return spec.process(source, arguments);
} catch (CommandNotFoundException e) {
throw new CommandException(t("No such child command: %s", e.getCommand()));
} finally {
if (pluginOwner.isPresent()) {
Sponge.getCauseStackManager().popCause();
}
}
}
use of org.spongepowered.api.plugin.PluginContainer in project Almura by AlmuraDev.
the class SimpleAboutMenu method construct.
@SuppressWarnings({ "unchecked" })
@Override
public void construct() {
super.construct();
this.list = new BasicList<>(this, 125, UIComponent.INHERITED);
this.list.setPosition(4, 0);
this.list.setItemComponentSpacing(4);
this.list.setCanDeselect(false);
final List<AboutItemData> elementDataList = Lists.newArrayList();
// Static entry
elementDataList.add(new AboutItemData(this.list, new UIImage(this, new GuiTexture(GuiConfig.Location.ALMURA_MAN), null), 5, 0, 23, 32, 8, AboutConfig.TITLE, AboutConfig.STORY));
// Dynamic entry
AboutConfig.ENTRIES.forEach(entry -> {
Text titles = Text.EMPTY;
for (final String title : entry.titles) {
titles = titles.toBuilder().append(Text.of(" • ", I18n.format(title)), Text.NEW_LINE).build();
}
elementDataList.add(new AboutItemData(this.list, new UIImage(this, new GuiRemoteTexture(GuiConfig.Location.GENERIC_AVATAR, new ResourceLocation(Almura.ID, "textures/gui/skins/avatars/" + entry.uniqueId + ".png"), String.format(GuiConfig.Url.SKINS, entry.uniqueId, 32), 32, 32), null), 2, 0, 32, 32, 4, Text.of(entry.color, I18n.format(entry.name)), Text.of(TextColors.WHITE, I18n.format(entry.description), Text.NEW_LINE, Text.NEW_LINE, TextStyles.BOLD, I18n.format("almura.menu.about.titles"), TextStyles.RESET, TextColors.RESET, Text.NEW_LINE, titles)));
});
final UIButton doneButton = new UIButtonBuilder(this).text(I18n.format("gui.done")).size(98, 20).position(0, -15, 1).anchor(Anchor.BOTTOM | Anchor.CENTER).listener(this).build("button.done");
this.textField = new UITextField(this, "", true);
this.textField.setPosition(BasicScreen.getPaddedX(this.list, 4), 0);
this.textField.setEditable(false);
this.textField.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).shadow(false).build());
this.list.setItemComponentFactory(AboutItemComponent::new);
this.list.setItems(elementDataList);
this.list.setSelectConsumer(i -> this.textField.setText(TextSerializers.LEGACY_FORMATTING_CODE.serialize(i.getContent())));
this.list.setSelectedItem(elementDataList.get(0));
this.getContainer().add(this.list, this.textField);
// SpongeForge
final UILabel spongeForgeVersionLabel = new UILabel(this, TextFormatting.WHITE + "SpongeForge: " + ((Optional<String>) Sponge.getPlatform().asMap().get("ImplementationVersion")).orElse("dev"));
spongeForgeVersionLabel.setPosition(4, -24, Anchor.LEFT | Anchor.BOTTOM);
// Forge
final PluginContainer forgeContainer = Sponge.getPluginManager().getPlugin("Forge").orElseThrow(NullPointerException::new);
final UILabel forgeVersionLabel = new UILabel(this, TextFormatting.WHITE + "Forge: " + forgeContainer.getVersion().orElse("dev"));
forgeVersionLabel.setPosition(4, -14, Anchor.LEFT | Anchor.BOTTOM);
addToScreen(forgeVersionLabel);
// Almura
final PluginContainer almuraContainer = Sponge.getPluginManager().getPlugin("almura").orElseThrow(NullPointerException::new);
final UILabel almuraVersionLabel = new UILabel(this, TextFormatting.WHITE + "Almura 3.1 - " + Almura.buildNumber);
almuraVersionLabel.setPosition(4, -4, Anchor.LEFT | Anchor.BOTTOM);
addToScreen(almuraVersionLabel);
addToScreen(doneButton);
addToScreen(spongeForgeVersionLabel);
}
use of org.spongepowered.api.plugin.PluginContainer in project SpongeCommon by SpongePowered.
the class SpongeCommandFactory method sendContainerMeta.
public static void sendContainerMeta(CommandSource src, CommandContext args, String argumentName) {
for (PluginContainer container : args.<PluginContainer>getAll(argumentName)) {
Text.Builder builder = Text.builder().append(title(container.getName()));
container.getVersion().ifPresent(version -> builder.append(Text.of((" v" + version))));
appendPluginMeta(builder, "ID", container.getId());
appendPluginMeta(builder, "Description", container.getDescription());
appendPluginMeta(builder, "URL", container.getUrl().map(url -> {
ClickAction.OpenUrl action = null;
try {
// make the url clickable
action = TextActions.openUrl(new URL(url));
} catch (MalformedURLException e) {
// or not
}
return Text.builder(url).onClick(action);
}));
if (!container.getAuthors().isEmpty()) {
appendPluginMeta(builder, "Authors", String.join(", ", container.getAuthors()));
}
appendPluginMeta(builder, "Main class", container.getInstance().map(instance -> instance.getClass().getCanonicalName()));
src.sendMessage(builder.build());
}
}
Aggregations