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);
}
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)));
}
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));
}
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()));
}
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;
}
Aggregations