use of org.spongepowered.api.plugin.PluginContainer in project SpongeForge by SpongePowered.
the class SpongeModNetworkManager method createRawChannel.
@Override
public RawDataChannel createRawChannel(Object plugin, String channelName) throws ChannelRegistrationException {
SpongeRawChannel channel;
PluginContainer pluginContainer = checkCreateChannelArgs(plugin, channelName);
try {
channel = new SpongeRawChannel(this, channelName, pluginContainer);
} catch (Exception e) {
throw new ChannelRegistrationException("Error registering channel \"" + channelName + "\" to " + pluginContainer, e);
}
return this.registerChannel(channel);
}
use of org.spongepowered.api.plugin.PluginContainer in project SpongeForge by SpongePowered.
the class SpongeModNetworkManager method createChannel.
@Override
public IndexedMessageChannel createChannel(Object plugin, String channelName) throws ChannelRegistrationException {
SpongeIndexedMessageChannel channel;
PluginContainer pluginContainer = checkCreateChannelArgs(plugin, channelName);
try {
channel = new SpongeIndexedMessageChannel(this, channelName, pluginContainer);
} catch (Exception e) {
throw new ChannelRegistrationException("Error registering channel \"" + channelName + "\" to " + pluginContainer, e);
}
return this.registerChannel(channel);
}
use of org.spongepowered.api.plugin.PluginContainer in project SpongeForge by SpongePowered.
the class SpongeModPluginContainer method constructMod.
@Subscribe
public void constructMod(FMLConstructionEvent event) {
try {
if (this.invalid) {
throw new InvalidPluginException();
}
// Add source file to classloader so we can load it.
ModClassLoader modClassLoader = event.getModClassLoader();
modClassLoader.addFile(getSource());
modClassLoader.clearNegativeCacheFor(this.candidate.getClassList());
Class<?> pluginClazz = Class.forName(this.className, true, modClassLoader);
Injector injector = spongeInjector.getParent().createChildInjector(new PluginModule((PluginContainer) this, pluginClazz));
this.injector = injector;
this.instance = injector.getInstance(pluginClazz);
// TODO: Detect Scala or use meta to know if we're scala and use proper adapter here...
ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), new ILanguageAdapter.JavaAdapter());
Sponge.getEventManager().registerListeners(this, this.instance);
} catch (Throwable t) {
this.controller.errorOccurred(this, t);
}
}
use of org.spongepowered.api.plugin.PluginContainer in project core by CubeEngine.
the class CubeCommandManager method registerSpongeCommand.
private Optional<CommandMapping> registerSpongeCommand(CommandDescriptor descriptor) {
ArrayList<String> aliasList = new ArrayList<>();
aliasList.add(descriptor.getName().toLowerCase());
for (AliasConfiguration alias : descriptor.getAliases()) {
if ((alias.getDispatcher() == null || (alias.getDispatcher() != null && alias.getDispatcher().length == 0))) {
aliasList.add(alias.getName().toLowerCase());
}
}
PluginContainer plugin = mm.getPlugin(descriptor.getOwner()).orElse(mm.getPlugin(LibCube.class).get());
return baseDispatcher.register(plugin, new ProxyCallable(this, commandTime, descriptor.getName(), logger), aliasList);
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class CommandWhitelist method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.child(CommandSpec.builder().arguments(GenericArguments.string(Text.of("player"))).executor((src, args) -> {
final String playerName = args.<String>getOne("player").get();
final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
Lantern.getGame().getGameProfileManager().get(playerName).whenComplete((profile, error) -> {
if (error != null) {
src.sendMessage(t("commands.whitelist.add.failed", playerName));
} else {
src.sendMessage(t("commands.whitelist.add.success", playerName));
service.addProfile(((LanternGameProfile) profile).withoutProperties());
}
});
return CommandResult.success();
}).build(), "add").child(CommandSpec.builder().arguments(GenericArguments.string(Text.of("player"))).executor((src, args) -> {
final String playerName = args.<String>getOne("player").get();
final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
Lantern.getGame().getGameProfileManager().get(playerName).whenComplete((profile, error) -> {
if (error != null || !service.isWhitelisted(profile = ((LanternGameProfile) profile).withoutProperties())) {
src.sendMessage(t("commands.whitelist.remove.failed", playerName));
} else {
src.sendMessage(t("commands.whitelist.remove.success", playerName));
service.removeProfile(profile);
}
});
return CommandResult.success();
}).build(), "remove").child(CommandSpec.builder().executor((src, args) -> {
final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
final List<String> whitelisted = service.getWhitelistedProfiles().stream().map(p -> p.getName().get()).collect(Collectors.toList());
src.sendMessage(t("commands.whitelist.list", whitelisted.size(), Sponge.getServer().getOnlinePlayers().size()));
src.sendMessage(Text.of(Joiner.on(", ").join(whitelisted)));
return CommandResult.success();
}).build(), "list").child(CommandSpec.builder().executor((src, args) -> {
Lantern.getGame().getGlobalConfig().setWhitelistEnabled(true);
src.sendMessage(t("commands.whitelist.enabled"));
return CommandResult.success();
}).build(), "on").child(CommandSpec.builder().executor((src, args) -> {
Lantern.getGame().getGlobalConfig().setWhitelistEnabled(false);
src.sendMessage(t("commands.whitelist.disabled"));
return CommandResult.success();
}).build(), "off").child(CommandSpec.builder().executor((src, args) -> {
final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
if (service instanceof Reloadable) {
try {
((Reloadable) service).reload();
} catch (Exception e) {
throw new CommandException(t("commands.whitelist.reload.failed", e.getMessage()), e);
}
} else {
src.sendMessage(t("commands.whitelist.reload.not_supported"));
return CommandResult.empty();
}
return CommandResult.success();
}).build(), "reload");
}
Aggregations