Skip to content

Commit 9ddb42b

Browse files
author
Daniel Naylor
committed
Merge branch 'api-8' into api-9
2 parents 5014f7a + 323e1e6 commit 9ddb42b

File tree

16 files changed

+138
-92
lines changed

16 files changed

+138
-92
lines changed

src/ap/java/org/spongepowered/plugin/processor/ListenerParameterAnnotation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void validate(final ParameterContext ctx) {
6363
if (!contained.getModifiers().contains(Modifier.STATIC)) {
6464
ctx.logError("The @ContextValue annotation must refer to a static field", entry.getValue());
6565
}
66-
if (!ctx.types().isSubtype(contained.asType(), key.asType())) {
66+
if (!ctx.types().isSubtype(contained.asType(), ctx.types().erasure(key.asType()))) {
6767
ctx.logError("The @ContextValue annotation must refer to a field with type EventContextKey, but got '" + contained.asType() + "' instead", entry.getValue());
6868
}
6969
// validate field type?
@@ -123,7 +123,7 @@ void validate(final ParameterContext ctx) {
123123
expectedType = declared.getTypeArguments().get(0);
124124
}
125125
}
126-
if (!ctx.types().isSameType(expectedType, ctx.param().asType())) {
126+
if (!ctx.types().isAssignable(ctx.param().asType(), expectedType)) {
127127
ctx.logParamError(
128128
"Annotated parameter was of incorrect type for the method referenced in @Getter. The parameter type should be '"
129129
+ expectedType + "'!"

src/main/java/org/spongepowered/api/block/BlockSnapshot.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,15 @@
4040

4141
import java.util.Optional;
4242
import java.util.UUID;
43-
import java.util.function.Supplier;
4443

4544
/**
4645
* An immutable representation of a {@link BlockState} and any extra data that
4746
* may be associated with it, including {@link BlockEntity} related data.
4847
*/
4948
public interface BlockSnapshot extends LocatableSnapshot<BlockSnapshot> {
5049

51-
/**
52-
* Represents a {@link BlockSnapshot} with the default state of
53-
* {@link BlockTypes#AIR} and a {@link ServerLocation} that cannot be determined.
54-
*/
55-
Supplier<BlockSnapshot> NONE = BlockSnapshot::empty;
56-
5750
static BlockSnapshot empty() {
58-
return Sponge.game().builderProvider().provide(Builder.class).empty();
51+
return Sponge.game().factoryProvider().provide(Factory.class).empty();
5952
}
6053

6154
/**
@@ -205,6 +198,9 @@ interface Builder extends SerializableDataHolderBuilder.Immutable<BlockSnapshot,
205198
* @return This builder, for chaining
206199
*/
207200
Builder notifier(UUID uuid);
201+
}
202+
203+
interface Factory {
208204

209205
BlockSnapshot empty();
210206
}

src/main/java/org/spongepowered/api/command/CommandResult.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,19 @@ static Builder builder() {
4545
}
4646

4747
/**
48-
* Builds a result that indicates successes.
48+
* Builds a result that indicates success (where {@link Builder#result(int)}
49+
* is set to 1.
4950
*
50-
* @return The {@link CommandResult}
51-
*/
52-
static CommandResult success() {
53-
return CommandResults.SUCCESS;
54-
}
55-
56-
/**
57-
* Builds an empty result.
51+
* <p>Note that a successful result is one where the command has done what
52+
* is expected of it. This should be used in place of "empty" from previous
53+
* API iterations. If an error condition should be reported, use
54+
* {@link #error(Component)} instead, which will allow the system to react
55+
* accordingly.</p>
5856
*
5957
* @return The {@link CommandResult}
6058
*/
61-
static CommandResult empty() {
62-
return CommandResults.EMPTY;
59+
static CommandResult success() {
60+
return Sponge.game().factoryProvider().provide(Factory.class).success();
6361
}
6462

6563
/**
@@ -105,7 +103,8 @@ interface Builder extends org.spongepowered.api.util.Builder<CommandResult, Buil
105103
*
106104
* <ul>
107105
* <li>A positive value indicates successful execution,</li>
108-
* <li>Zero indicates the command didn't fulfil its task</li>
106+
* <li>Zero (generally) indicates the command didn't fulfil its
107+
* task, though that is not necessarily an error condition.</li>
109108
* <li>A negative value is undefined in the API, if returned, the
110109
* effects are implementation specific.</li>
111110
* </ul>
@@ -116,11 +115,12 @@ interface Builder extends org.spongepowered.api.util.Builder<CommandResult, Buil
116115
Builder result(int result);
117116

118117
/**
119-
* Sets or removes the error message to return to the user without
120-
* throwing an exception.
118+
* Sets the built result to report an error, with an optional error
119+
* message.
121120
*
122121
* <p>If this is set, then the command parser will send this message to
123-
* the command invoker.</p>
122+
* the command invoker. Otherwise, the parser will report an unknown
123+
* exception.</p>
124124
*
125125
* @param errorMessage The message to send to the user.
126126
* @return This builder, for chaining
@@ -137,4 +137,10 @@ interface Builder extends org.spongepowered.api.util.Builder<CommandResult, Buil
137137

138138
}
139139

140+
interface Factory {
141+
142+
CommandResult success();
143+
144+
}
145+
140146
}

src/main/java/org/spongepowered/api/entity/Entity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ default boolean canSee(final Entity entity) {
328328
return !optional.isPresent() || !optional.get();
329329
}
330330

331+
/**
332+
* Makes the entity look at the specified target position.
333+
*
334+
* @param targetPos Position to target
335+
*/
336+
void lookAt(Vector3d targetPos);
337+
331338
/**
332339
* {@link Keys#DISPLAY_NAME}
333340
*

src/main/java/org/spongepowered/api/entity/living/Living.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.spongepowered.api.entity.attribute.Attribute;
3232
import org.spongepowered.api.entity.attribute.AttributeHolder;
3333
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
34-
import org.spongepowered.api.projectile.source.EntityProjectileSource;
3534
import org.spongepowered.api.scoreboard.TeamMember;
3635
import org.spongepowered.math.imaginary.Quaterniond;
3736
import org.spongepowered.math.vector.Vector3d;
@@ -164,13 +163,6 @@ default Value.Mutable<Double> walkingSpeed() {
164163
return this.requireValue(Keys.WALKING_SPEED).asMutable();
165164
}
166165

167-
/**
168-
* Makes the entity look at the specified target position.
169-
*
170-
* @param targetPos Position to target
171-
*/
172-
void lookAt(Vector3d targetPos);
173-
174166
/**
175167
* Converts the {@link Living}'s head rotation into a quaternion direction unit vector.
176168
*

src/main/java/org/spongepowered/api/event/filter/cause/ContextValue.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.spongepowered.api.event.EventContext;
2828
import org.spongepowered.api.event.EventContextKey;
29+
import org.spongepowered.api.event.EventContextKeys;
2930

3031
import java.lang.annotation.ElementType;
3132
import java.lang.annotation.Retention;
@@ -46,6 +47,8 @@
4647
/**
4748
* Gets the name to use with the {@link EventContextKey}.
4849
*
50+
* <p>This must be a field in {@link EventContextKeys}.</p>
51+
*
4952
* @return The name to use
5053
*/
5154
String value();

src/main/java/org/spongepowered/api/event/world/chunk/ChunkEvent.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,62 +36,80 @@
3636
public interface ChunkEvent extends Event {
3737

3838
/**
39-
* Gets the position of the {@link Chunk}, in chunk co-ordinates.
39+
* Gets the position of the {@link Chunk chunk}, in chunk co-ordinates.
4040
*
4141
* @return the position
4242
*/
4343
Vector3i chunkPosition();
4444

4545
/**
46-
* Represents an event that has knowledge about the {@link ServerWorld} that
46+
* Represents an event that has knowledge about the {@link ServerWorld world} that
4747
* is being operated upon.
4848
*/
4949
@NoFactoryMethod
5050
interface WorldScoped extends ChunkEvent {
5151

5252
/**
53-
* Gets the {@link ResourceKey} of the {@link WorldScoped} that the
54-
* {@link WorldChunk} resides in.
53+
* Gets the {@link ResourceKey key} of the {@link WorldScoped} that the
54+
* {@link WorldChunk chunk} resides in.
5555
*
56-
* <p>Be careful when retrieving the {@link ServerWorld} within this
56+
* <p>Be careful when retrieving the {@link ServerWorld world} within this
5757
* event as some events may not fire on the main thread and such world
5858
* access is not thread safe.</p>
5959
*
60-
* @return The world's {@link ResourceKey}
60+
* @return The world's {@link ResourceKey key}
6161
*/
6262
ResourceKey worldKey();
63-
6463
}
6564

6665
/**
67-
* Called when a {@link WorldChunk} was unloaded.
66+
* Called when a {@link WorldChunk chunk} was unloaded.
6867
*/
6968
interface Unload extends WorldScoped {
7069

70+
/**
71+
* Called before the {@link WorldChunk chunk} is unloaded.
72+
*/
73+
interface Pre extends Unload {
74+
75+
/**
76+
* Gets the {@link WorldChunk chunk} being changed.
77+
*
78+
* @return The chunk
79+
*/
80+
WorldChunk chunk();
81+
}
82+
83+
/**
84+
* Called after the {@link WorldChunk chunk} is unloaded.
85+
*/
86+
interface Post extends Unload {
87+
88+
}
7189
}
7290

7391
/**
74-
* Called when a {@link WorldChunk} is performing a save.
92+
* Called when a {@link WorldChunk chunk} is performing a save.
7593
*/
7694
interface Save extends WorldScoped {
7795

7896
/**
79-
* Called before the {@link WorldChunk} is saved. Cancelling this will prevent any of
97+
* Called before the {@link WorldChunk chunk} is saved. Cancelling this will prevent any of
8098
* the chunk's data being written to it's storage container.
8199
*/
82100
interface Pre extends Save, Cancellable {
83101

84102
/**
85-
* Gets the {@link WorldChunk} being changed.
103+
* Gets the {@link WorldChunk chunk} being changed.
86104
*
87-
* @return The Chunk
105+
* @return The chunk
88106
*/
89-
WorldChunk targetChunk();
107+
WorldChunk chunk();
90108

91109
}
92110

93111
/**
94-
* Called after the {@link WorldChunk} is saved. Guaranteed to exist in the chunk's
112+
* Called after the {@link WorldChunk chunk} is saved. Guaranteed to exist in the chunk's
95113
* storage container.
96114
*
97115
* Depending on the implementation, this event may be called off-thread.
@@ -100,22 +118,22 @@ interface Post extends Save {}
100118
}
101119

102120
/**
103-
* Called when a new {@link WorldChunk} was generated.
121+
* Called when a new {@link WorldChunk chunk} was generated.
104122
*/
105123
interface Generated extends WorldScoped {
106124

107125
}
108126

109127
/**
110-
* Called when a {@link WorldChunk} is done loading.
128+
* Called when a {@link WorldChunk chunk} is done loading.
111129
*/
112130
interface Load extends WorldScoped {
113131

114132
/**
115-
* Gets the {@link WorldChunk} being changed.
133+
* Gets the {@link WorldChunk chunk} being changed.
116134
*
117-
* @return The Chunk
135+
* @return The chunk
118136
*/
119-
WorldChunk targetChunk();
137+
WorldChunk chunk();
120138
}
121139
}

src/main/java/org/spongepowered/api/item/inventory/ItemStack.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.spongepowered.api.entity.attribute.AttributeModifier;
3838
import org.spongepowered.api.entity.attribute.type.AttributeType;
3939
import org.spongepowered.api.item.ItemType;
40-
import org.spongepowered.api.item.ItemTypes;
4140
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
4241
import org.spongepowered.api.registry.DefaultedRegistryReference;
4342

@@ -59,6 +58,15 @@
5958
*/
6059
public interface ItemStack extends SerializableDataHolder.Mutable {
6160

61+
/**
62+
* Returns an empty {@link ItemStack}.
63+
*
64+
* @return The empty ItemStack
65+
*/
66+
static ItemStack empty() {
67+
return Sponge.game().factoryProvider().provide(Factory.class).empty();
68+
}
69+
6270
/**
6371
* Creates a new {@link Builder} to build an {@link ItemStack}.
6472
*
@@ -112,15 +120,6 @@ static ItemStack of(ItemType itemType) {
112120
return ItemStack.of(itemType, 1);
113121
}
114122

115-
/**
116-
* Returns an empty {@link ItemStack}.
117-
*
118-
* @return The empty ItemStack
119-
*/
120-
static ItemStack empty() {
121-
return ItemStack.builder().itemType(ItemTypes.AIR).build();
122-
}
123-
124123
/**
125124
* Gets the {@link ItemType} of this {@link ItemStack}.
126125
*
@@ -413,4 +412,9 @@ default Builder apply(Predicate<Builder> predicate, Consumer<Builder> consumer)
413412
@Override
414413
ItemStack build() throws IllegalStateException;
415414
}
415+
416+
interface Factory {
417+
418+
ItemStack empty();
419+
}
416420
}

src/main/java/org/spongepowered/api/plugin/PluginManager.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,4 @@ public interface PluginManager {
5959
* @return The plugins
6060
*/
6161
Collection<PluginContainer> plugins();
62-
63-
/**
64-
* Checks if a plugin is loaded based on its ID.
65-
* This may contain plugins/mods from other systems in some implementations.
66-
*
67-
* @param id the id of the {@link PluginContainer}
68-
* @return {@code true} if loaded {@code false} if not loaded.
69-
*/
70-
boolean isLoaded(String id);
71-
7262
}

src/main/java/org/spongepowered/api/command/CommandResults.java renamed to src/main/java/org/spongepowered/api/world/DefaultWorldKeys.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,22 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package org.spongepowered.api.command;
25+
package org.spongepowered.api.world;
26+
27+
import org.spongepowered.api.ResourceKey;
28+
import org.spongepowered.api.world.server.ServerWorld;
2629

2730
/**
28-
* Common {@link CommandResult}s.
31+
* A listing of the {@link ResourceKey keys} of the default {@link ServerWorld worlds} in Minecraft.
2932
*/
30-
public final class CommandResults {
33+
public final class DefaultWorldKeys {
3134

32-
/**
33-
* Indicates that the command executed successfully.
34-
*/
35-
public static final CommandResult SUCCESS = CommandResult.builder().result(1).build();
35+
public static final ResourceKey OVERWORLD = ResourceKey.minecraft("overworld");
3636

37-
/**
38-
* Indicates that the command executed but was unable to carry out its task.
39-
*/
40-
public static final CommandResult EMPTY = CommandResult.builder().build();
37+
public static final ResourceKey THE_NETHER = ResourceKey.minecraft("the_nether");
4138

42-
private CommandResults() {
43-
throw new AssertionError("You shouldn't be trying to instantiate this");
44-
}
39+
public static final ResourceKey THE_END = ResourceKey.minecraft("the_end");
4540

41+
private DefaultWorldKeys() {
42+
}
4643
}

0 commit comments

Comments
 (0)