use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class DefaultCommandsCollection method load.
public void load() {
final Multimap<PluginContainer, CommandProvider> commandProviders = HashMultimap.create();
// Minecraft Commands
commandProviders.put(this.minecraft, new CommandBan());
commandProviders.put(this.minecraft, new CommandBanIp());
commandProviders.put(this.minecraft, new CommandBorder());
commandProviders.put(this.minecraft, new CommandDeop());
commandProviders.put(this.minecraft, new CommandDifficulty());
commandProviders.put(this.minecraft, new CommandGameMode());
commandProviders.put(this.minecraft, new CommandGameRule());
commandProviders.put(this.minecraft, new CommandHelp());
commandProviders.put(this.minecraft, new CommandKick());
commandProviders.put(this.minecraft, new CommandListBans());
commandProviders.put(this.minecraft, new CommandListPlayers());
commandProviders.put(this.minecraft, new CommandMe());
commandProviders.put(this.minecraft, new CommandOp());
commandProviders.put(this.minecraft, new CommandPardon());
commandProviders.put(this.minecraft, new CommandPardonIp());
commandProviders.put(this.minecraft, new CommandParticle());
commandProviders.put(this.implementation, new CommandParticleEffect());
commandProviders.put(this.minecraft, new CommandPlaySound());
commandProviders.put(this.minecraft, new CommandSay());
commandProviders.put(this.minecraft, new CommandScoreboard());
commandProviders.put(this.implementation, new CommandSetData());
commandProviders.put(this.minecraft, new CommandSetIdleTimeout());
commandProviders.put(this.minecraft, new CommandSetSpawn());
commandProviders.put(this.minecraft, new CommandStop());
commandProviders.put(this.minecraft, new CommandStopSound());
commandProviders.put(this.minecraft, new CommandTeleport());
commandProviders.put(this.minecraft, new CommandTell());
commandProviders.put(this.minecraft, new CommandTime());
commandProviders.put(this.minecraft, new CommandTitle());
commandProviders.put(this.minecraft, new CommandToggleDownfall());
commandProviders.put(this.minecraft, new CommandTp());
commandProviders.put(this.implementation, new CommandVersion());
commandProviders.put(this.minecraft, new CommandWeather());
commandProviders.put(this.minecraft, new CommandWhitelist());
// Testing Commands
commandProviders.put(this.implementation, new CommandOpenTestContainer());
for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
final PluginContainer plugin = entry.getKey();
this.commandManager.register(plugin, entry.getValue().buildSpecFor(plugin), entry.getValue().getAliases());
}
final PermissionService permissionService = this.permissionService.get();
if (permissionService instanceof LanternPermissionService) {
final LanternPermissionService lanternPermissionService = (LanternPermissionService) permissionService;
// noinspection Convert2streamapi
for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
entry.getValue().getOpPermissionLevel().ifPresent(level -> lanternPermissionService.getGroupForOpLevel(level).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE));
}
} else {
// noinspection Convert2streamapi
for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
if (entry.getValue().getOpPermissionLevel().orElse(0) == 0) {
permissionService.getDefaults().getTransientSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE);
}
}
}
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class LanternCommandManager method register.
@Override
public Optional<CommandMapping> register(Object plugin, CommandCallable callable, List<String> aliases, Function<List<String>, List<String>> callback) {
checkNotNull(plugin, "plugin");
Optional<PluginContainer> containerOptional = Sponge.getGame().getPluginManager().fromInstance(plugin);
if (!containerOptional.isPresent()) {
throw new IllegalArgumentException("The provided plugin object does not have an associated plugin container " + "(in other words, is 'plugin' actually your plugin object?");
}
PluginContainer container = containerOptional.get();
synchronized (this.lock) {
// <namespace>:<alias> for all commands
final List<String> aliasesWithPrefix = new ArrayList<>(aliases.size() * 2);
for (String alias : aliases) {
final Collection<CommandMapping> ownedCommands = this.owners.get(container);
for (CommandMapping mapping : this.dispatcher.getAll(alias)) {
if (ownedCommands.contains(mapping)) {
throw new IllegalArgumentException("A plugin may not register multiple commands for the same alias ('" + alias + "')!");
}
}
aliasesWithPrefix.add(alias);
aliasesWithPrefix.add(container.getId() + ':' + alias);
}
final Optional<CommandMapping> mapping = this.dispatcher.register(callable, aliasesWithPrefix, callback);
if (mapping.isPresent()) {
this.owners.put(container, mapping.get());
this.reverseOwners.put(mapping.get(), container);
}
return mapping;
}
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class LanternConfigManager method getPluginConfig.
@Override
public ConfigRoot getPluginConfig(Object instance) {
final PluginContainer pluginContainer = checkPlugin(instance, "instance");
final String name = pluginContainer.getId().toLowerCase();
return new LanternConfigRoot(getMapperFactory(pluginContainer), name, this.configFolder.resolve(name));
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class LanternConfigManager method getSharedConfig.
@Override
public ConfigRoot getSharedConfig(Object instance) {
final PluginContainer pluginContainer = checkPlugin(instance, "instance");
final String name = pluginContainer.getId().toLowerCase();
return new LanternConfigRoot(getMapperFactory(pluginContainer), name, this.configFolder);
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class LanternSmeltingRecipeBuilder method build.
@SuppressWarnings("ConstantConditions")
@Override
public ISmeltingRecipe build(String id, Object plugin) {
check();
checkNotNull(id, "id");
checkNotNull(plugin, "plugin");
final PluginContainer container = checkPlugin(plugin, "plugin");
final int index = id.indexOf(':');
if (index != -1) {
final String pluginId = id.substring(0, index);
checkState(pluginId.equals(container.getId()), "Plugin ids mismatch, " + "found %s in the id but got %s from the container", pluginId, container.getId());
id = id.substring(index + 1);
}
return build0(id, container);
}
Aggregations