Search in sources :

Example 6 with PluginContainer

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

the class GoalTypeModule method createGoalType.

public GoalType createGoalType(Object plugin, String id, String name) {
    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 createGoalType(combinedId, name);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 7 with PluginContainer

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

the class SpongeShapedCraftingRecipeBuilder method build.

@Override
public ShapedCraftingRecipe build(String id, Object plugin) {
    checkState(!this.aisle.isEmpty(), "aisle has not been set");
    checkState(!this.ingredientMap.isEmpty(), "no ingredients set");
    checkState(!this.result.isEmpty(), "no result set");
    checkNotNull(id, "id");
    checkNotNull(id, "plugin");
    PluginContainer container = SpongeImpl.getPluginContainer(plugin);
    if (!id.startsWith(container.getId() + ":")) {
        id = container.getId() + ":" + id;
    }
    Iterator<String> aisleIterator = this.aisle.iterator();
    String aisleRow = aisleIterator.next();
    int width = aisleRow.length();
    int height = 1;
    checkState(width > 0, "The aisle cannot be empty.");
    while (aisleIterator.hasNext()) {
        height++;
        aisleRow = aisleIterator.next();
        checkState(aisleRow.length() == width, "The aisle has an inconsistent width.");
    }
    String[] keys = this.aisle.toArray(new String[this.aisle.size()]);
    Map<String, net.minecraft.item.crafting.Ingredient> ingredientsMap = this.ingredientMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toString(), e -> IngredientUtil.toNative(e.getValue())));
    // Default space to Empty Ingredient
    ingredientsMap.putIfAbsent(" ", net.minecraft.item.crafting.Ingredient.EMPTY);
    // Throws JsonException when pattern is not complete or defines unused Ingredients
    NonNullList<net.minecraft.item.crafting.Ingredient> ingredients = ShapedRecipes.deserializeIngredients(keys, ingredientsMap, width, height);
    return ((ShapedCraftingRecipe) new SpongeShapedRecipe(id, this.groupName, width, height, ingredients, ItemStackUtil.toNative(this.result)));
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) Iterator(java.util.Iterator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Char2ObjectArrayMap(it.unimi.dsi.fastutil.chars.Char2ObjectArrayMap) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Strings(com.google.common.base.Strings) ShapedCraftingRecipe(org.spongepowered.api.item.recipe.crafting.ShapedCraftingRecipe) ItemStack(org.spongepowered.api.item.inventory.ItemStack) List(java.util.List) Lists(com.google.common.collect.Lists) Ingredient(org.spongepowered.api.item.recipe.crafting.Ingredient) Map(java.util.Map) Preconditions(com.google.common.base.Preconditions) NonNullList(net.minecraft.util.NonNullList) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Ingredient(org.spongepowered.api.item.recipe.crafting.Ingredient)

Example 8 with PluginContainer

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

the class SpongeShapelessCraftingRecipeBuilder method build.

@SuppressWarnings("ConstantConditions")
@Override
public ShapelessCraftingRecipe build(String id, Object plugin) {
    checkState(this.exemplaryResult != null && this.exemplaryResult != ItemStackSnapshot.NONE, "The result is not set.");
    checkState(!this.ingredients.isEmpty(), "The ingredients are not set.");
    checkNotNull(id, "id");
    checkNotNull(id, "plugin");
    PluginContainer container = SpongeImpl.getPluginContainer(plugin);
    if (!id.startsWith(container.getId() + ":")) {
        id = container.getId() + ":" + id;
    }
    return ((ShapelessCraftingRecipe) new SpongeShapelessRecipe(id, groupName, ItemStackUtil.toNative(this.exemplaryResult.createStack()), ingredients));
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 9 with PluginContainer

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

the class SpongeEventManager method unregisterPluginListeners.

@Override
public void unregisterPluginListeners(Object pluginObj) {
    final PluginContainer plugin = getPlugin(pluginObj);
    unregister(handler -> plugin.equals(handler.getPlugin()));
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 10 with PluginContainer

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

the class SpongeHooks method getFriendlyCauseName.

public static String getFriendlyCauseName(Cause cause) {
    String causedBy = "Unknown";
    Object rootCause = cause.root();
    if (rootCause instanceof User) {
        User user = (User) rootCause;
        causedBy = user.getName();
    } else if (rootCause instanceof EntityItem) {
        EntityItem item = (EntityItem) rootCause;
        causedBy = item.getItem().getDisplayName();
    } else if (rootCause instanceof Entity) {
        Entity causeEntity = (Entity) rootCause;
        causedBy = causeEntity.getName();
    } else if (rootCause instanceof BlockSnapshot) {
        BlockSnapshot snapshot = (BlockSnapshot) rootCause;
        causedBy = snapshot.getState().getType().getId();
    } else if (rootCause instanceof CatalogType) {
        CatalogType type = (CatalogType) rootCause;
        causedBy = type.getId();
    } else if (rootCause instanceof PluginContainer) {
        PluginContainer plugin = (PluginContainer) rootCause;
        causedBy = plugin.getId();
    } else {
        causedBy = rootCause.getClass().getName();
    }
    return causedBy;
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) CatalogType(org.spongepowered.api.CatalogType) User(org.spongepowered.api.entity.living.player.User) PluginContainer(org.spongepowered.api.plugin.PluginContainer) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) EntityItem(net.minecraft.entity.item.EntityItem)

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