use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class LanternShapedCraftingRecipeBuilder method build.
@Override
public IShapedCraftingRecipe build(String id, Object plugin) {
checkState(!this.aisle.isEmpty(), "aisle has not been set");
checkState(!this.ingredientMap.isEmpty(), "no ingredients set");
checkState(this.resultProvider != null, "no result provider");
checkNotNull(id, "id");
checkNotNull(id, "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);
}
final int h = this.aisle.size();
checkState(h > 0, "The aisle cannot be empty.");
final int w = this.aisle.get(0).length();
checkState(w > 0, "The aisle cannot be empty.");
final IIngredient[][] ingredients = new IIngredient[w][h];
for (int j = 0; j < h; j++) {
final String s = this.aisle.get(j);
checkState(s.length() == w, "The aisle has an inconsistent width.");
for (int i = 0; i < w; i++) {
final char c = s.charAt(i);
final Ingredient ingredient;
if (c == ' ') {
ingredient = Ingredient.NONE;
} else {
ingredient = this.ingredientMap.get(c);
checkState(ingredient != null, "No ingredient is present for the character: %s", c);
}
ingredients[i][j] = (IIngredient) ingredient;
}
}
final ItemStackSnapshot exemplary = this.resultProvider.getSnapshot(EmptyCraftingMatrix.INSTANCE, EmptyIngredientList.INSTANCE);
return new LanternShapedCraftingRecipe(container.getId(), id, exemplary, this.groupName, this.resultProvider, ingredients);
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class LanternShapelessCraftingRecipeBuilder method build.
@SuppressWarnings("ConstantConditions")
@Override
public IShapelessCraftingRecipe build(String id, Object plugin) {
checkState(this.resultProvider != null, "The result provider is not set.");
checkState(!this.ingredients.isEmpty(), "The ingredients are not set.");
checkNotNull(id, "id");
checkNotNull(id, "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);
}
final ItemStackSnapshot exemplary = this.resultProvider.getSnapshot(EmptyCraftingMatrix.INSTANCE, EmptyIngredientList.INSTANCE);
return new LanternShapelessCraftingRecipe(container.getId(), id, exemplary, this.groupName, this.resultProvider, ImmutableList.copyOf(this.ingredients));
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class LanternCraftingRecipeRegistryModule method registerDefaults.
@DelayedRegistration(RegistrationPhase.POST_INIT)
@Override
public void registerDefaults() {
try {
ReflectionHelper.setField(Ingredient.class.getField("NONE"), null, IIngredient.builder().with(ItemStack::isEmpty).withDisplay(ItemTypes.NONE).build());
} catch (Exception e) {
throw new RuntimeException(e);
}
PluginContainer plugin = Lantern.getMinecraftPlugin();
register(ICraftingRecipe.shapedBuilder().aisle("x", "x").where('x', Ingredient.of(ItemTypes.PLANKS)).result(ItemStack.of(ItemTypes.STICK, 4)).build("stick", plugin));
// Extra, testing stuff
plugin = Lantern.getImplementationPlugin();
ItemStack result = ItemStack.of(ItemTypes.GOLD_NUGGET, 4);
result.offer(Keys.DISPLAY_NAME, Text.of(TextColors.GOLD, "€1"));
register(ICraftingRecipe.shapedBuilder().aisle("x", "y").where('x', Ingredient.of(ItemTypes.GOLD_INGOT)).where('y', IIngredient.builder().with(ItemTypes.LAVA_BUCKET).withRemaining(ItemTypes.BUCKET).build()).result(result).build("one_euro", plugin));
// Two sticks?
register(ICraftingRecipe.shapelessBuilder().addIngredients(Ingredient.of(ItemTypes.STICK), 2).result(ItemStack.of(ItemTypes.STICK, 2)).build("two_sticks", plugin));
// Two buckets?
result = ItemStack.of(ItemTypes.LAVA_BUCKET, 1);
result.offer(Keys.DISPLAY_NAME, Text.of(TextColors.GOLD, "¿Compressed Lava?"));
register(ICraftingRecipe.shapelessBuilder().addIngredient(Ingredient.of(ItemTypes.LAVA_BUCKET)).addIngredient(IIngredient.builder().with(ItemTypes.LAVA_BUCKET).withRemaining(ItemTypes.BUCKET).build()).result(result).build("compressed_lava", plugin));
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class PluginCandidate method collectDependencies.
public boolean collectDependencies(Map<String, PluginContainer> loadedPlugins, Map<String, PluginCandidate> candidates) {
checkState(this.dependencies == null, "Dependencies already collected");
if (loadedPlugins.containsKey(this.id)) {
this.invalid = true;
}
this.dependencies = new HashSet<>();
this.requirements = new HashSet<>();
this.versions = new HashMap<>();
this.missingRequirements = new HashMap<>();
for (PluginDependency dependency : this.metadata.collectRequiredDependencies()) {
final String id = dependency.getId();
if (this.id.equals(id)) {
Lantern.getLogger().warn("Plugin '{}' from {} requires itself to be loaded. " + "This is redundant and can be removed from the dependencies.", this.id, getDisplaySource());
continue;
}
final String version = dependency.getVersion();
final PluginContainer loaded = loadedPlugins.get(id);
if (loaded != null) {
if (!verifyVersionRange(id, version, loaded.getVersion().orElse(null))) {
this.missingRequirements.put(id, version);
}
continue;
}
final PluginCandidate candidate = candidates.get(id);
if (candidate != null && verifyVersionRange(id, version, candidate.getMetadata().getVersion())) {
this.requirements.add(candidate);
continue;
}
this.missingRequirements.put(id, version);
}
final Map<PluginDependency.LoadOrder, Set<PluginDependency>> dependencies = this.metadata.groupDependenciesByLoadOrder();
collectOptionalDependencies(dependencies.get(PluginDependency.LoadOrder.BEFORE), loadedPlugins, candidates);
final Set<PluginDependency> loadAfter = dependencies.get(PluginDependency.LoadOrder.AFTER);
if (loadAfter != null && !loadAfter.isEmpty()) {
this.invalid = true;
Lantern.getLogger().error("Invalid dependency with load order BEFORE on plugin '{}' from {}. " + "This is currently not supported for Sponge plugins! Requested dependencies: {}", this.id, getDisplaySource(), loadAfter);
}
return isLoadable();
}
use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.
the class PluginCandidate method collectOptionalDependencies.
private void collectOptionalDependencies(@Nullable Iterable<PluginDependency> dependencies, Map<String, PluginContainer> loadedPlugins, Map<String, PluginCandidate> candidates) {
if (dependencies == null) {
return;
}
for (PluginDependency dependency : dependencies) {
final String id = dependency.getId();
if (this.id.equals(id)) {
Lantern.getLogger().error("Plugin '{}' from {} cannot have a dependency on itself. This is redundant and should be " + "removed.", this.id, getDisplaySource());
this.invalid = true;
continue;
}
final String version = dependency.getVersion();
final PluginContainer loaded = loadedPlugins.get(id);
if (loaded != null) {
if (!verifyVersionRange(id, version, loaded.getVersion().orElse(null))) {
this.missingRequirements.put(id, version);
}
continue;
}
final PluginCandidate candidate = candidates.get(id);
if (candidate != null) {
if (verifyVersionRange(id, version, candidate.getMetadata().getVersion())) {
this.dependencies.add(candidate);
} else {
this.missingRequirements.put(id, version);
}
}
}
}
Aggregations