Skip to content

Commit 5014f7a

Browse files
author
Daniel Naylor
committed
Merge remote-tracking branch 'origin/api-8' into api-9
2 parents dc1bfca + f8f8e28 commit 5014f7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1542
-661
lines changed

src/main/java/org/spongepowered/api/data/Keys.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,13 @@ public final class Keys {
11161116
*/
11171117
public static final Key<Value<HorseStyle>> HORSE_STYLE = Keys.key(ResourceKey.sponge("horse_style"), HorseStyle.class);
11181118

1119+
/**
1120+
* The inaccuracy of an {@link ItemStack} that launches {@link Projectile}s.
1121+
*
1122+
* <p>An inaccuracy of 0 means perfect accuracy. Inaccuracy of 1 is the default for most vanilla items.</p>
1123+
*/
1124+
public static final Key<Value<Double>> INACCURACY = Keys.key(ResourceKey.sponge("inaccuracy"), Double.class);
1125+
11191126
/**
11201127
* Whether an {@link Item} will not despawn for an infinite time.
11211128
*/

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ static Builder builder() {
4646
return Sponge.game().builderProvider().provide(Builder.class);
4747
}
4848

49-
/**
50-
* Creates a new {@link EntityArchetype} with the specified {@link EntityType}.
51-
*
52-
* @param type Type of the entity
53-
* @return An archetype of the given entity type
54-
*/
55-
static EntityArchetype of(Supplier<? extends EntityType<?>> type) {
56-
return EntityArchetype.builder().type(type).build();
57-
}
58-
5949
/**
6050
* Creates a new {@link EntityArchetype} with the specified {@link EntityType}.
6151
*
@@ -105,16 +95,6 @@ interface Builder extends SerializableDataHolderBuilder.Mutable<EntityArchetype,
10595
*/
10696
Builder from(Entity entity);
10797

108-
/**
109-
* Sets the desired {@link EntityType} of the produced {@link EntityArchetype}.
110-
*
111-
* @param type The type of entity type
112-
* @return This builder, for chaining
113-
*/
114-
default Builder type(Supplier<? extends EntityType<?>> type) {
115-
return this.type(type.get());
116-
}
117-
11898
/**
11999
* Sets the desired {@link EntityType} of the produced {@link EntityArchetype}.
120100
*

src/main/java/org/spongepowered/api/event/EventListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*
3030
* @param <T> The type of the event
3131
*/
32+
@FunctionalInterface
3233
public interface EventListener<T extends Event> {
3334

3435
/**
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.event;
26+
27+
import io.leangen.geantyref.TypeToken;
28+
import org.spongepowered.api.Sponge;
29+
import org.spongepowered.api.util.ResettableBuilder;
30+
import org.spongepowered.plugin.PluginContainer;
31+
32+
import java.lang.reflect.Type;
33+
import java.util.Objects;
34+
35+
/**
36+
* Represents the composition of a {@link EventListener listener} and the attributes that define it
37+
* to the system.
38+
*
39+
* @param <T> The event type
40+
*/
41+
public interface EventListenerRegistration<T extends Event> {
42+
43+
static <T extends Event> EventListenerRegistration.Builder<T> builder(final TypeToken<T> eventType) {
44+
return Sponge.game().factoryProvider().provide(Factory.class).builder(Objects.requireNonNull(eventType, "eventType"));
45+
}
46+
47+
static <T extends Event> EventListenerRegistration.Builder<T> builder(final Class<T> eventClass) {
48+
return Sponge.game().factoryProvider().provide(Factory.class).builder(TypeToken.get(eventClass));
49+
}
50+
51+
Type eventType();
52+
53+
PluginContainer plugin();
54+
55+
Order order();
56+
57+
boolean beforeModifications();
58+
59+
EventListener<? super T> listener();
60+
61+
interface Builder<T extends Event> extends ResettableBuilder<EventListenerRegistration<T>, Builder<T>> {
62+
63+
Builder<T> plugin(PluginContainer plugin);
64+
65+
Builder<T> order(Order order);
66+
67+
Builder<T> beforeModifications(boolean beforeModifications);
68+
69+
Builder<T> listener(EventListener<? super T> listener);
70+
71+
EventListenerRegistration<T> build();
72+
}
73+
74+
interface Factory {
75+
76+
<T extends Event> Builder<T> builder(TypeToken<T> eventType);
77+
}
78+
}

src/main/java/org/spongepowered/api/event/EventManager.java

Lines changed: 16 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@
2424
*/
2525
package org.spongepowered.api.event;
2626

27-
import io.leangen.geantyref.TypeToken;
2827
import org.spongepowered.plugin.PluginContainer;
2928

3029
/**
3130
* Manages the registration of event listeners and the dispatching of events.
3231
*/
3332
public interface EventManager {
3433

34+
/**
35+
* Submits a new {@link EventListenerRegistration listener registration} to this manager.
36+
* @param registration The registration
37+
* @param <E> The event type
38+
* @return This manager, for fluency
39+
*/
40+
<E extends Event> EventManager registerListener(EventListenerRegistration<E> registration);
41+
3542
/**
3643
* Registers {@link Event} methods annotated with @{@link Listener} in the
3744
* specified object.
@@ -41,129 +48,23 @@ public interface EventManager {
4148
*
4249
* @param plugin The plugin container
4350
* @param obj The object
51+
* @return This manager, for fluency
4452
*/
45-
void registerListeners(PluginContainer plugin, Object obj);
46-
47-
/**
48-
* Registers an event listener for a specific event class.
49-
*
50-
* <p>Normally, the annotation-based way in
51-
* {@link #registerListeners(PluginContainer, Object)} should be preferred over this way. This
52-
* method exists primarily to support dynamic event registration like needed
53-
* in scripting plugins.</p>
54-
*
55-
* @param plugin The plugin instance
56-
* @param eventClass The event to listen to
57-
* @param listener The listener to receive the events
58-
* @param <T> The type of the event
59-
*/
60-
<T extends Event> void registerListener(PluginContainer plugin, Class<T> eventClass, EventListener<? super T> listener);
61-
62-
/**
63-
* Registers an event listener for a specific event {@link TypeToken}.
64-
*
65-
* <p>Normally, the annotation-based way in
66-
* {@link #registerListeners(PluginContainer, Object)} should be preferred over this way. This
67-
* method exists primarily to support dynamic event registration like needed
68-
* in scripting plugins.</p>
69-
*
70-
* @param plugin The plugin instance
71-
* @param eventType The event to listen to
72-
* @param listener The listener to receive the events
73-
* @param <T> The type of the event
74-
*/
75-
<T extends Event> void registerListener(PluginContainer plugin, TypeToken<T> eventType, EventListener<? super T> listener);
76-
77-
/**
78-
* Registers an event listener with the specified order for a specific event
79-
* class.
80-
*
81-
* <p>Normally, the annotation-based way in
82-
* {@link #registerListeners(PluginContainer, Object)} should be preferred over this way. This
83-
* method exists primarily to support dynamic event registration like needed
84-
* in scripting plugins.</p>
85-
*
86-
* @param plugin The plugin instance
87-
* @param eventClass The event to listen to
88-
* @param order The order the listener will get called at
89-
* @param listener The listener to receive the events
90-
* @param <T> The type of the event
91-
*/
92-
<T extends Event> void registerListener(PluginContainer plugin, Class<T> eventClass, Order order, EventListener<? super T> listener);
93-
94-
/**
95-
* Registers an event listener with the specified order for a specific event
96-
* {@link TypeToken}.
97-
*
98-
* <p>Normally, the annotation-based way in
99-
* {@link #registerListeners(PluginContainer, Object)} should be preferred over this way. This
100-
* method exists primarily to support dynamic event registration like needed
101-
* in scripting plugins.</p>
102-
*
103-
* @param plugin The plugin instance
104-
* @param eventType The event to listen to
105-
* @param order The order the listener will get called at
106-
* @param listener The listener to receive the events
107-
* @param <T> The type of the event
108-
*/
109-
<T extends Event> void registerListener(PluginContainer plugin, TypeToken<T> eventType, Order order, EventListener<? super T> listener);
110-
111-
/**
112-
* Registers an event listener with the specified order for a specific event
113-
* class.
114-
*
115-
* <p>Normally, the annotation-based way in
116-
* {@link #registerListeners(PluginContainer, Object)} should be preferred over this way. This
117-
* method exists primarily to support dynamic event registration like needed
118-
* in scripting plugins.</p>
119-
*
120-
* @param plugin The plugin instance
121-
* @param eventClass The event to listen to
122-
* @param order The order the listener will get called at
123-
* @param beforeModifications Whether to call the listener before other
124-
* server modifications
125-
* @param listener The listener to receive the events
126-
* @param <T> The type of the event
127-
*/
128-
<T extends Event> void registerListener(PluginContainer plugin, Class<T> eventClass, Order order, boolean beforeModifications,
129-
EventListener<? super T> listener);
130-
131-
/**
132-
* Registers an event listener with the specified order for a specific event
133-
* class.
134-
*
135-
* <p>Normally, the annotation-based way in
136-
* {@link #registerListeners(PluginContainer, Object)} should be preferred over this way. This
137-
* method exists primarily to support dynamic event registration like needed
138-
* in scripting plugins.</p>
139-
*
140-
* @param plugin The plugin instance
141-
* @param eventType The event to listen to
142-
* @param order The order the listener will get called at
143-
* @param beforeModifications Whether to call the listener before other
144-
* server modifications
145-
* @param listener The listener to receive the events
146-
* @param <T> The type of the event
147-
*/
148-
<T extends Event> void registerListener(PluginContainer plugin, TypeToken<T> eventType, Order order, boolean beforeModifications,
149-
EventListener<? super T> listener);
53+
EventManager registerListeners(PluginContainer plugin, Object obj);
15054

15155
/**
15256
* Un-registers an object from receiving {@link Event}s.
15357
*
154-
* @param obj The object
155-
*/
156-
void unregisterListeners(Object obj);
157-
158-
/**
159-
* Un-registers all event listeners of a plugin.
58+
* <p>If the provided object is a {@link PluginContainer plugin}, all events associated
59+
* with that plugin will be unregistered.</p>
16060
*
161-
* @param plugin The plugin instance
61+
* @param obj The object
62+
* @return This manager, for fluency
16263
*/
163-
void unregisterPluginListeners(PluginContainer plugin);
64+
EventManager unregisterListeners(Object obj);
16465

16566
/**
166-
* Calls a {@link Event} to all listeners that listen to it.
67+
* Calls an {@link Event} to all listeners that listen to it.
16768
*
16869
* @param event The event
16970
* @return True if cancelled, false if not

src/main/java/org/spongepowered/api/event/cause/entity/SpawnTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.spongepowered.api.registry.RegistryScopes;
4242
import org.spongepowered.api.registry.RegistryTypes;
4343
import org.spongepowered.api.world.World;
44-
import org.spongepowered.api.world.chunk.Chunk;
44+
import org.spongepowered.api.world.chunk.WorldChunk;
4545
import org.spongepowered.api.world.weather.WeatherType;
4646
import org.spongepowered.plugin.PluginContainer;
4747

@@ -68,7 +68,7 @@ public final class SpawnTypes {
6868
public static final DefaultedRegistryReference<SpawnType> BREEDING = SpawnTypes.key(ResourceKey.sponge("breeding"));
6969

7070
/**
71-
* An entity spawned due to a {@link Chunk} being loaded.
71+
* An entity spawned due to a {@link WorldChunk} being loaded.
7272
*/
7373
public static final DefaultedRegistryReference<SpawnType> CHUNK_LOAD = SpawnTypes.key(ResourceKey.sponge("chunk_load"));
7474

0 commit comments

Comments
 (0)