Skip to content

Commit 9aff654

Browse files
committed
Merge branch 'api-8' into api-9
2 parents 8ffbe43 + fe31fe6 commit 9aff654

File tree

69 files changed

+1469
-2346
lines changed

Some content is hidden

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

69 files changed

+1469
-2346
lines changed

src/main/java/org/spongepowered/api/adventure/SpongeComponents.java

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
import net.kyori.adventure.audience.Audience;
2828
import net.kyori.adventure.text.Component;
2929
import net.kyori.adventure.text.event.ClickEvent;
30-
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
31-
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
32-
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
3330
import org.spongepowered.api.Sponge;
3431
import org.spongepowered.api.command.CommandCause;
3532
import org.spongepowered.api.registry.DefaultedRegistryReference;
@@ -102,97 +99,13 @@ public static Component resolve(
10299
return SpongeComponents.factory().render(component, senderContext, resolver, otherResolvers);
103100
}
104101

105-
/**
106-
* Get a serializer for {@link Component}s that will convert to and from the
107-
* legacy component format used by the Vanilla client.
108-
*
109-
* <p>This legacy serializer uses the standard section symbol to mark
110-
* formatting characters.</p>
111-
*
112-
* <p>Implementations may provide a serializer capable of processing any
113-
* information that requires access to implementation details.</p>
114-
*
115-
* @return a section serializer
116-
*/
117-
public static LegacyComponentSerializer legacySectionSerializer() {
118-
return SpongeComponents.factory().legacySectionSerializer();
119-
}
120-
121-
/**
122-
* Get a serializer for {@link Component}s that will convert to and from the
123-
* legacy component format used by the Vanilla client.
124-
*
125-
* <p>This legacy serializer uses the alternate ampersand symbol ({@code &})
126-
* to mark formatting characters.</p>
127-
*
128-
* <p>Implementations may provide a serializer capable of processing any
129-
* information that requires access to implementation details.</p>
130-
*
131-
* @return a legacy serializer using ampersands
132-
*/
133-
public static LegacyComponentSerializer legacyAmpersandSerializer() {
134-
return SpongeComponents.factory().legacyAmpersandSerializer();
135-
}
136-
137-
/**
138-
* Get a serializer for {@link Component}s that will convert to and from the
139-
* legacy component format used by the Vanilla client.
140-
*
141-
* <p>Implementations may provide a serializer capable of processing any
142-
* information that requires access to implementation details.</p>
143-
*
144-
* @param formatChar the format character to use in place of the standard
145-
* section symbol
146-
* @return a legacy serializer using ampersands
147-
*/
148-
public static LegacyComponentSerializer legacySerializer(final char formatChar) {
149-
return SpongeComponents.factory().legacySerializer(formatChar);
150-
}
151-
152-
/**
153-
* Get a serializer for {@link Component}s that will convert to and from the
154-
* standard JSON serialization format using Gson.
155-
*
156-
* <p>Implementations may provide a serializer capable of processing any
157-
* information that requires implementation details, such as legacy
158-
* (pre-1.16) hover events.</p>
159-
*
160-
* @return a json component serializer
161-
*/
162-
public static GsonComponentSerializer gsonSerializer() {
163-
return SpongeComponents.factory().gsonSerializer();
164-
}
165-
166-
/**
167-
* Get a serializer for {@link Component}s that will convert components to
168-
* a plain-text string.
169-
*
170-
* <p>Implementations may provide a serializer capable of processing any
171-
* information that requires access to implementation details.</p>
172-
*
173-
* @return a serializer to plain text
174-
*/
175-
public static PlainComponentSerializer plainSerializer() {
176-
return SpongeComponents.factory().plainSerializer();
177-
}
178-
179102
private static Factory factory() {
180103
return Sponge.game().factoryProvider().provide(Factory.class);
181104
}
182105

183106
public interface Factory {
184107
ClickEvent callbackClickEvent(final Consumer<CommandCause> callback);
185108

186-
LegacyComponentSerializer legacySectionSerializer();
187-
188-
LegacyComponentSerializer legacyAmpersandSerializer();
189-
190-
LegacyComponentSerializer legacySerializer(final char formatChar);
191-
192-
GsonComponentSerializer gsonSerializer();
193-
194-
PlainComponentSerializer plainSerializer();
195-
196109
@SuppressWarnings("unchecked")
197110
Component render(
198111
final Component component,

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@
3939
import org.spongepowered.api.event.Cause;
4040
import org.spongepowered.api.event.EventContext;
4141
import org.spongepowered.api.event.lifecycle.RegisterCommandEvent;
42+
import org.spongepowered.api.service.permission.PermissionDescription;
4243
import org.spongepowered.api.service.permission.Subject;
4344

4445
import java.util.Arrays;
4546
import java.util.List;
4647
import java.util.Map;
48+
import java.util.Objects;
4749
import java.util.Optional;
4850
import java.util.function.Function;
4951
import java.util.function.Predicate;
@@ -555,6 +557,31 @@ default Builder shortDescription(@Nullable final Component description) {
555557
*/
556558
Builder permission(@Nullable String permission);
557559

560+
/**
561+
* The permission that the responsible {@link Subject} in the given
562+
* {@link Cause} requires to run this command.
563+
*
564+
* <p>For more control over whether a command can be executed, use
565+
* {@link #executionRequirements(Predicate)}. However, note that
566+
* setting a permission here will not override anything set in
567+
* {@link #executionRequirements(Predicate)}, both will be checked
568+
* during execution.</p>
569+
*
570+
* <p>Any permission checks set here will be performed during the
571+
* {@link Command#canExecute(CommandCause)}.</p>
572+
*
573+
* <p>Calling this repeatedly will not add additional permission
574+
* checks, instead replacing the permission check. If multiple
575+
* permission checks are required, use
576+
* {@link #executionRequirements(Predicate)}.</p>
577+
*
578+
* @param permission The description for the required permission.
579+
* @return This builder, for chaining
580+
*/
581+
default Builder permission(PermissionDescription permission) {
582+
return this.permission(Objects.requireNonNull(permission, "permission").id());
583+
}
584+
558585
/**
559586
* Sets a function that determines what is required of the provided
560587
* {@link Cause} before this command executes. Calling this method

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ static CommandCause create() {
125125
*/
126126
Cause cause();
127127

128+
@Override
129+
default Cause contextCause() {
130+
return this.cause();
131+
}
132+
128133
/**
129134
* @see Cause#context()
130135
*
@@ -250,6 +255,9 @@ default List<Object> all() {
250255
* </li>
251256
* </ul>
252257
*
258+
* <p>This subject may present a different view of default context than
259+
* calls to {@link Subject} methods directly on this cause.</p>
260+
*
253261
* <p><strong>Note:</strong> while it might be tempting to use this as the
254262
* invoker of the command, the {@link Cause#root()} and this might be
255263
* different. Command executors should generally use the root of the

src/main/java/org/spongepowered/api/command/parameter/Parameter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.spongepowered.api.world.server.ServerLocation;
6666
import org.spongepowered.api.world.server.ServerWorld;
6767
import org.spongepowered.configurate.util.Types;
68+
import org.spongepowered.math.vector.Vector2d;
6869
import org.spongepowered.math.vector.Vector3d;
6970
import org.spongepowered.plugin.PluginContainer;
7071

@@ -618,6 +619,16 @@ static Parameter.Value.Builder<ResourceKey> resourceKey() {
618619
return Parameter.builder(ResourceKey.class, ResourceKeyedValueParameters.RESOURCE_KEY);
619620
}
620621

622+
/**
623+
* Creates a builder that has the {@link ValueParameter} set to
624+
* {@link ResourceKeyedValueParameters#ROTATION}.
625+
*
626+
* @return A {@link Parameter.Value.Builder}
627+
*/
628+
static Parameter.Value.Builder<Vector3d> rotation() {
629+
return Parameter.builder(Vector3d.class, ResourceKeyedValueParameters.ROTATION);
630+
}
631+
621632
/**
622633
* Creates a builder that has the {@link ValueParameter} set to
623634
* {@link ResourceKeyedValueParameters#STRING}.

src/main/java/org/spongepowered/api/command/parameter/managed/standard/ResourceKeyedValueParameters.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,28 @@ public final class ResourceKeyedValueParameters {
296296
*/
297297
public static final DefaultedRegistryReference<ResourceKeyedValueParameter<ResourceKey>> RESOURCE_KEY = ResourceKeyedValueParameters.key(ResourceKey.sponge("resource_key"));
298298

299+
/**
300+
* Require an argument to be a {@link Vector3d}, where any relative value
301+
* (i.e. anything specified using tilde (~) notation) will be based on the
302+
* invoker's current rotation.
303+
*
304+
* <p>The supplied {@link Vector2d} will contain the Euler components
305+
* (yaw, pitch, roll), where:</p>
306+
*
307+
* <ul>
308+
* <li>the angles are specified in degrees;</li>
309+
* <li>(0, 0) is looking directly south, parallel to the x-z plane;</li>
310+
* <li>the yaw is measured as the angle counter-clockwise from due south
311+
* in the x-z plane; and</li>
312+
* <li>the pitch is negative when rotating up from the x-z plane.</li>
313+
* <li>the roll is zero</li>
314+
* </ul>
315+
*
316+
* <p>This is presented as a {@link Vector3d} even though only two arguments
317+
* are parsed for consistency with {@link Entity#rotation()}.</p>
318+
*/
319+
public static final DefaultedRegistryReference<ResourceKeyedValueParameter<Vector3d>> ROTATION = ResourceKeyedValueParameters.key(ResourceKey.sponge("rotation"));
320+
299321
/**
300322
* Require an argument to be a string.
301323
*

src/main/java/org/spongepowered/api/entity/living/player/server/ServerPlayer.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import org.spongepowered.api.resourcepack.ResourcePack;
5151
import org.spongepowered.api.scoreboard.Scoreboard;
5252
import org.spongepowered.api.service.permission.Subject;
53-
import org.spongepowered.api.world.WorldBorder;
53+
import org.spongepowered.api.world.border.WorldBorder;
5454
import org.spongepowered.api.world.server.ServerWorld;
5555
import org.spongepowered.plugin.PluginContainer;
5656

@@ -239,20 +239,30 @@ default SetValue.Mutable<SkinPart> displayedSkinParts() {
239239

240240
/**
241241
* Gets the {@link WorldBorder} for this player, if present. If no border is
242-
* set, {@link Optional#empty()} is returned.
242+
* set, an empty {@code Optional} is returned.
243243
*
244244
* @return The {@code WorldBorder} of this player as an {@code Optional}, if
245245
* present
246246
*/
247247
Optional<WorldBorder> worldBorder();
248248

249249
/**
250-
* Sets the {@link WorldBorder} instance for this player to the given world
251-
* border. If {@code null} is passed, the world border is unset.
250+
* Sets the {@link WorldBorder} that this player sees. If {@code null}, the
251+
* border is unset, reverting to the border of the world the player is
252+
* currently in.
253+
*
254+
* <p>The values that are set may be altered by events, so users should
255+
* check the returned value if they need to know if an event altered the
256+
* values in some way. If no alterations were made, the supplied object
257+
* and the returned object (within the optional) will be the same.</p>
252258
*
253259
* @param border The world border to be used, may be {@code null}
260+
* @return the values that were actually set, which may be different
261+
* from those requested. If the result is an empty optional,
262+
* then the player does not have a personal border, and uses
263+
* that of the world they are in instead.
254264
*/
255-
void setWorldBorder(@Nullable WorldBorder border);
265+
Optional<WorldBorder> setWorldBorder(@Nullable WorldBorder border);
256266

257267
/**
258268
* Gets the {@link CooldownTracker} for this player, allowing control

src/main/java/org/spongepowered/api/event/action/LightningEvent.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,25 @@
2828
import org.spongepowered.api.event.Event;
2929
import org.spongepowered.api.event.entity.AffectEntityEvent;
3030

31+
/**
32+
* Base event for {@link org.spongepowered.api.entity.EntityTypes#LIGHTNING_BOLT}s.
33+
*/
3134
public interface LightningEvent extends Event {
3235

36+
/**
37+
* Fires before a lightning strike happens.
38+
* <p>Cancelling this completely prevents the lightning at its effects.</p>
39+
*/
3340
interface Pre extends LightningEvent, Cancellable {}
3441

42+
/**
43+
* Fires when a lightning strike happens.
44+
* <p>The affected entities can be modified.</p>
45+
*/
3546
interface Strike extends LightningEvent, AffectEntityEvent {}
3647

48+
/**
49+
* Fires after a lightning strike happened.
50+
*/
3751
interface Post extends LightningEvent {}
3852
}

0 commit comments

Comments
 (0)