Search in sources :

Example 1 with PluginContainer

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

the class SpongeTimings method getPluginTaskTimings.

/**
 * Gets a timer associated with a plugins tasks.
 *
 * @param task
 * @param period
 * @return
 */
public static Timing getPluginTaskTimings(Task task, long period) {
    if (task.isAsynchronous()) {
        return null;
    }
    PluginContainer plugin = task.getOwner();
    String name = "Task: " + task.getName();
    if (period > 0) {
        name += " (interval:" + period + ")";
    } else {
        name += " (Single)";
    }
    return SpongeTimingsFactory.ofSafe(plugin, name);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 2 with PluginContainer

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

the class SpongeAdvancementBuilder method build.

@Override
public Advancement build() {
    checkState(this.id != null, "The id must be set");
    final PluginContainer plugin = Sponge.getCauseStackManager().getCurrentCause().first(PluginContainer.class).get();
    final Tuple<Map<String, Criterion>, String[][]> result = SpongeCriterionHelper.toVanillaCriteriaData(this.criterion);
    final AdvancementRewards rewards = AdvancementRewards.EMPTY;
    final ResourceLocation resourceLocation = new ResourceLocation(plugin.getId(), this.id);
    final net.minecraft.advancements.DisplayInfo displayInfo = this.displayInfo == null ? null : // Create a copy
    (net.minecraft.advancements.DisplayInfo) DisplayInfo.builder().from(this.displayInfo).build();
    net.minecraft.advancements.Advancement parent = (net.minecraft.advancements.Advancement) this.parent;
    if (parent == null) {
        // Attach a dummy root until a tree is constructed
        parent = DUMMY_ROOT_ADVANCEMENT;
    }
    final Advancement advancement = (Advancement) new net.minecraft.advancements.Advancement(resourceLocation, parent, displayInfo, rewards, result.getFirst(), result.getSecond());
    ((IMixinAdvancement) advancement).setCriterion(this.criterion);
    if (StringUtils.isNotEmpty(this.name)) {
        ((IMixinAdvancement) advancement).setName(this.name);
    }
    return advancement;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) AdvancementRewards(net.minecraft.advancements.AdvancementRewards) ResourceLocation(net.minecraft.util.ResourceLocation) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Advancement(org.spongepowered.api.advancement.Advancement) IMixinAdvancement(org.spongepowered.common.interfaces.advancement.IMixinAdvancement) IMixinAdvancement(org.spongepowered.common.interfaces.advancement.IMixinAdvancement)

Example 3 with PluginContainer

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

the class MixinTraitInventory method getPlugin.

@Override
public PluginContainer getPlugin() {
    if (this.plugin == null) {
        Object base = this;
        PluginContainer container;
        if (base instanceof CarriedInventory) {
            final Optional<?> carrier = ((CarriedInventory<?>) base).getCarrier();
            if (carrier.isPresent()) {
                base = carrier.get();
            }
        }
        if (base instanceof TileEntity) {
            final String id = ((TileEntity) base).getBlock().getType().getId();
            final String pluginId = id.substring(0, id.indexOf(":"));
            container = Sponge.getPluginManager().getPlugin(pluginId).orElseThrow(() -> new AssertionError("Missing plugin " + pluginId + " for block " + id));
        } else if (base instanceof Entity) {
            final String id = ((Entity) base).getType().getId();
            final String pluginId = id.substring(0, id.indexOf(":"));
            container = Sponge.getPluginManager().getPlugin(pluginId).orElseThrow(() -> new AssertionError("Missing plugin " + pluginId + " for entity " + id + " (" + this.getClass().getName() + ")"));
        } else if (base instanceof SpongeUser) {
            container = SpongeImpl.getMinecraftPlugin();
        } else {
            container = Sponge.getPluginManager().getPlugin(SpongeImplHooks.getModIdFromClass(this.getClass())).orElseGet(() -> {
                SpongeImpl.getLogger().warn("Unknown plugin for " + this);
                return SpongeImpl.getMinecraftPlugin();
            });
        }
        this.plugin = container;
    }
    return this.plugin;
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Entity(org.spongepowered.api.entity.Entity) PluginContainer(org.spongepowered.api.plugin.PluginContainer) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) SpongeUser(org.spongepowered.common.entity.player.SpongeUser)

Example 4 with PluginContainer

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

the class KeyRegistryModule method registerAdditionalCatalog.

@Override
public void registerAdditionalCatalog(Key<?> extraCatalog) {
    checkState(!SpongeDataManager.areRegistrationsComplete(), "Cannot register new Keys after Data Registration has completed!");
    checkNotNull(extraCatalog, "Key cannot be null!");
    final PluginContainer parent = ((SpongeKey) extraCatalog).getParent();
    final String pluginId = parent.getId().toLowerCase(Locale.ENGLISH);
    final String id = extraCatalog.getId().toLowerCase(Locale.ENGLISH);
    final String[] split = id.split(":");
    checkArgument(split.length == 2, "Key id's have to be in two parts! The first part being the plugin id, the second part being the key's individual id. Currently you have: " + Arrays.toString(split));
    checkArgument(split[0].equals(pluginId), "A plugin is trying to register custom keys under a different plugin id namespace! This is unsupported! The provided key: " + id);
    this.keyMap.put(id, extraCatalog);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) SpongeKey(org.spongepowered.common.data.SpongeKey)

Example 5 with PluginContainer

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

the class AITaskTypeModule method createAITaskType.

public AITaskType createAITaskType(Object plugin, String id, String name, Class<? extends AITask<? extends Agent>> aiClass) {
    final Optional<PluginContainer> optPluginContainer = SpongeImpl.getGame().getPluginManager().fromInstance(plugin);
    Preconditions.checkArgument(optPluginContainer.isPresent());
    final PluginContainer pluginContainer = optPluginContainer.get();
    final String combinedId = pluginContainer.getId().toLowerCase(Locale.ENGLISH) + ':' + id;
    return createAITaskType(combinedId, name, aiClass);
}
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