Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions src/main/java/org/spongepowered/api/advancement/Advancement.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
import org.spongepowered.api.advancement.criteria.AdvancementCriterion;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.TextRepresentable;
import org.spongepowered.api.util.ResettableBuilder;
import org.spongepowered.api.util.CatalogBuilder;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -103,7 +104,7 @@ static Builder builder() {
/**
* A builder to create {@link Advancement}s.
*/
interface Builder extends ResettableBuilder<Advancement, Builder> {
interface Builder extends CatalogBuilder<Advancement, Builder> {

/**
* Sets the parent {@link Advancement}. Defaults to {code null}.
Expand All @@ -130,13 +131,7 @@ interface Builder extends ResettableBuilder<Advancement, Builder> {
*/
Builder displayInfo(@Nullable DisplayInfo displayInfo);

/**
* Sets the identifier of the {@link Advancement}
* (without the namespace).
*
* @param id The identifier
* @return This builder, for chaining
*/
@Override
Builder id(String id);

/**
Expand All @@ -148,13 +143,10 @@ interface Builder extends ResettableBuilder<Advancement, Builder> {
* @param name The name
* @return This builder, for chaining
*/
@Override
Builder name(String name);

/**
* Builds the {@link Advancement}.
*
* @return The advancement
*/
@Override
Advancement build();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.spongepowered.api.CatalogType;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.util.CatalogBuilder;
import org.spongepowered.api.util.ResettableBuilder;

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ static Builder builder() {
/**
* A builder to create {@link AdvancementTree}s.
*/
interface Builder extends ResettableBuilder<AdvancementTree, Builder> {
interface Builder extends CatalogBuilder<AdvancementTree, Builder> {

/**
* Sets the root {@link Advancement}. The root advancement MUST have
Expand All @@ -90,31 +91,22 @@ interface Builder extends ResettableBuilder<AdvancementTree, Builder> {

// Builder background(ResourcePath background);

/**
* Sets the identifier of the {@link AdvancementTree}
* (without the namespace).
*
* @param id The identifier
* @return This builder, for chaining
*/
@Override
Builder id(String id);

/**
* Sets the name of the {@link AdvancementTree}. Defaults to
* the plain {@link DisplayInfo#getTitle()} of the root
* {@link Advancement} if {@link DisplayInfo} is present.
* {@link Advancement} if {@link DisplayInfo} is present.
* Otherwise will it default to the identifier ({@link #id(String)}).
*
* @param name The name
* @return This builder, for chaining
*/
@Override
Builder name(String name);

/**
* Builds the {@link AdvancementTree}.
*
* @return The advancement tree
*/
@Override
AdvancementTree build();

@Override
Expand Down
52 changes: 45 additions & 7 deletions src/main/java/org/spongepowered/api/data/DataRegistration.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
import org.spongepowered.api.data.manipulator.DataManipulator;
import org.spongepowered.api.data.manipulator.DataManipulatorBuilder;
import org.spongepowered.api.data.manipulator.ImmutableDataManipulator;
import org.spongepowered.api.event.CauseStackManager;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.util.ResettableBuilder;
import org.spongepowered.api.util.CatalogBuilder;

public interface DataRegistration<T extends DataManipulator<T, I>, I extends ImmutableDataManipulator<I, T>> extends CatalogType {

Expand Down Expand Up @@ -97,7 +98,7 @@ public interface DataRegistration<T extends DataManipulator<T, I>, I extends Imm
String getName();

interface Builder<T extends DataManipulator<T, I>, I extends ImmutableDataManipulator<I, T>>
extends ResettableBuilder<DataRegistration<T, I>, Builder<T, I>> {
extends CatalogBuilder<DataRegistration<T, I>, Builder<T, I>> {

/**
* Sets the {@link DataManipulator} class to be used. For the sake of
Expand Down Expand Up @@ -164,8 +165,16 @@ interface Builder<T extends DataManipulator<T, I>, I extends ImmutableDataManipu
*
* @param id The id for the manipulator
* @return This builder, for chaining
* @deprecated Use {@link #id(String)} instead
*/
Builder<T, I> manipulatorId(String id);
@Deprecated
default Builder<T, I> manipulatorId(String id) {
final int index = id.indexOf(':');
if (index != -1) {
id = id.substring(index + 1);
}
return id(id);
}

/**
* Sets a more generalized name to refer to the registered
Expand All @@ -176,8 +185,12 @@ interface Builder<T extends DataManipulator<T, I>, I extends ImmutableDataManipu
*
* @param name The data name
* @return This builder, for chaining
* @deprecated Use {@link #name(String)} instead
*/
Builder<T, I> dataName(String name);
@Deprecated
default Builder<T, I> dataName(String name) {
return name(name);
}

/**
* Sets the {@link DataManipulatorBuilder} to be used to generate new
Expand Down Expand Up @@ -234,10 +247,35 @@ interface Builder<T extends DataManipulator<T, I>, I extends ImmutableDataManipu
* @throws IllegalArgumentException Various reasons
* @throws DataAlreadyRegisteredException If the classes and or builder
* has already been registered
* @deprecated Use {@link #build()} instead
*/
DataRegistration<T, I> buildAndRegister(PluginContainer container) throws IllegalStateException, IllegalArgumentException,
DataAlreadyRegisteredException;
@Deprecated
default DataRegistration<T, I> buildAndRegister(PluginContainer container)
throws IllegalStateException, IllegalArgumentException, DataAlreadyRegisteredException {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(container);
return build();
}
}

/**
* {@inheritDoc}
*
* All of the objects for the provided {@link DataRegistration}
* object, including the registration's
* {@link DataRegistration#getManipulatorClass()} for the
* {@link DataManipulator} and
* {@link DataRegistration#getImmutableManipulatorClass()}
* and {@link DataRegistration#getDataManipulatorBuilder()}
* object will also be registered.
*
* @return The data registration object
* @throws IllegalStateException If registrations can no longer take place
* @throws IllegalArgumentException Various reasons
* @throws DataAlreadyRegisteredException If the classes and or builder
* has already been registered
*/
@Override
DataRegistration<T, I> build();
}

}
22 changes: 5 additions & 17 deletions src/main/java/org/spongepowered/api/data/key/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.spongepowered.api.data.value.ValueContainer;
import org.spongepowered.api.event.EventListener;
import org.spongepowered.api.event.data.ChangeDataHolderEvent;
import org.spongepowered.api.util.ResettableBuilder;
import org.spongepowered.api.util.CatalogBuilder;
import org.spongepowered.api.util.TypeTokens;

import java.lang.reflect.Type;
Expand Down Expand Up @@ -102,7 +102,7 @@ public interface Key<V extends BaseValue<?>> extends CatalogType {
*/
<E extends DataHolder> void registerEvent(Class<E> holderFilter, EventListener<ChangeDataHolderEvent.ValueChange> listener);

interface Builder<E, V extends BaseValue<E>> extends ResettableBuilder<Key<V>, Builder<E, V>> {
interface Builder<E, V extends BaseValue<E>> extends CatalogBuilder<Key<V>, Builder<E, V>> {

/**
* Starter method for the builder, to be used immediately after
Expand All @@ -123,23 +123,10 @@ interface Builder<E, V extends BaseValue<E>> extends ResettableBuilder<Key<V>, B
*/
<T, B extends BaseValue<T>> Builder<T, B> type(TypeToken<B> token);

/**
* Sets the string id to be used for {@link CatalogType#getId()}.
*
* <p>This should be formatted appropriately, review {@link CatalogType}
* documentation for formatted ids.</p>
*
* @param id The string id
* @return This builder, for chaining
*/
@Override
Builder<E, V> id(String id);

/**
* Sets the human readable name for the generated {@link Key}.
*
* @param name The human readable name
* @return This builder, for chaining
*/
@Override
Builder<E, V> name(String name);

/**
Expand All @@ -159,6 +146,7 @@ interface Builder<E, V extends BaseValue<E>> extends ResettableBuilder<Key<V>, B
*
* @return The generated Key
*/
@Override
Key<V> build();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
import static com.google.common.base.Preconditions.checkNotNull;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.CauseStackManager;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.text.translation.Translation;
import org.spongepowered.api.util.CatalogBuilder;
import org.spongepowered.api.util.ResettableBuilder;

import java.util.Map;
Expand Down Expand Up @@ -235,7 +239,7 @@ default EndStep result(ItemStackSnapshot result) {
/**
* In this Step set the group of the Recipe and/or build it.
*/
interface EndStep extends Builder {
interface EndStep extends Builder, CatalogBuilder<ShapedCraftingRecipe, Builder> {

/**
* Sets the group of the recipe.
Expand All @@ -245,6 +249,15 @@ interface EndStep extends Builder {
*/
EndStep group(@Nullable String name);

@Override
EndStep id(String id);

@Override
EndStep name(String name);

@Override
EndStep name(Translation name);

/**
* Builds a {@link ShapedCraftingRecipe} from this builder.
*
Expand All @@ -253,8 +266,22 @@ interface EndStep extends Builder {
* @return A new {@link ShapedCraftingRecipe}
* @throws IllegalStateException If not all required options
* were specified
* @deprecated Use {@link #build()} instead in combination with {@link #id(String)}
*/
ShapedCraftingRecipe build(String id, Object plugin);
@Deprecated
default ShapedCraftingRecipe build(String id, Object plugin) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
final PluginContainer container;
if (plugin instanceof PluginContainer) {
container = (PluginContainer) plugin;
} else {
container = Sponge.getPluginManager().fromInstance(plugin).orElseThrow(() -> new IllegalArgumentException(
"Plugin must be a PluginContainer or plugin instance, not " + plugin));
}
frame.pushCause(container);
return id(id).build();
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
import static com.google.common.base.Preconditions.checkNotNull;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.CauseStackManager;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.text.translation.Translation;
import org.spongepowered.api.util.CatalogBuilder;
import org.spongepowered.api.util.ResettableBuilder;

import java.util.List;
Expand Down Expand Up @@ -102,7 +106,7 @@ default EndStep result(ItemStack result) {
/**
* In this Step set the group of the Recipe and/or build it.
*/
interface EndStep extends Builder {
interface EndStep extends Builder, CatalogBuilder<ShapelessCraftingRecipe, Builder> {

/**
* Sets the group of the recipe.
Expand All @@ -112,6 +116,15 @@ interface EndStep extends Builder {
*/
EndStep group(@Nullable String name);

@Override
EndStep id(String id);

@Override
EndStep name(String name);

@Override
EndStep name(Translation name);

/**
* Builds a new {@link ShapelessCraftingRecipe} from this builder.
*
Expand All @@ -120,8 +133,22 @@ interface EndStep extends Builder {
* @return A new {@link ShapelessCraftingRecipe}
* @throws IllegalStateException If not all required options
* were specified
* @deprecated Use {@link #build()} instead in combination with {@link #id(String)}
*/
ShapelessCraftingRecipe build(String id, Object plugin);
@Deprecated
default ShapelessCraftingRecipe build(String id, Object plugin) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
final PluginContainer container;
if (plugin instanceof PluginContainer) {
container = (PluginContainer) plugin;
} else {
container = Sponge.getPluginManager().fromInstance(plugin).orElseThrow(() -> new IllegalArgumentException(
"Plugin must be a PluginContainer or plugin instance, not " + plugin));
}
frame.pushCause(container);
return id(id).build();
}
}
}

}
Expand Down
Loading