Skip to content

Commit 402ea10

Browse files
authored
Merge branch 'master' into feature/1.21.20
2 parents 841cb68 + 95c6f7c commit 402ea10

File tree

111 files changed

+2844
-1932
lines changed

Some content is hidden

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

111 files changed

+2844
-1932
lines changed

api/build.gradle.kts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
plugins {
2+
// Allow blossom to mark sources root of templates
3+
idea
24
id("geyser.publish-conventions")
5+
alias(libs.plugins.blossom)
36
}
47

58
dependencies {
69
api(libs.base.api)
710
api(libs.math)
8-
}
11+
}
12+
13+
version = property("version")!!
14+
val apiVersion = (version as String).removeSuffix("-SNAPSHOT")
15+
16+
sourceSets {
17+
main {
18+
blossom {
19+
javaSources {
20+
property("version", apiVersion)
21+
}
22+
}
23+
}
24+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2024 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.api;
27+
28+
import org.geysermc.api.util.ApiVersion;
29+
30+
/**
31+
* Not a public API. For internal use only. May change without notice.
32+
* This class is processed before compilation to insert build properties.
33+
*/
34+
class BuildData {
35+
static final String VERSION = "{{ version }}";
36+
static final ApiVersion API_VERSION;
37+
38+
static {
39+
String[] parts = VERSION.split("\\.");
40+
if (parts.length != 3) {
41+
throw new RuntimeException("Invalid api version: " + VERSION);
42+
}
43+
44+
try {
45+
int human = Integer.parseInt(parts[0]);
46+
int major = Integer.parseInt(parts[1]);
47+
int minor = Integer.parseInt(parts[2]);
48+
API_VERSION = new ApiVersion(human, major, minor);
49+
} catch (Exception e) {
50+
throw new RuntimeException("Invalid api version: " + VERSION, e);
51+
}
52+
}
53+
}

api/src/main/java/org/geysermc/geyser/api/GeyserApi.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.checkerframework.checker.nullness.qual.Nullable;
3030
import org.geysermc.api.Geyser;
3131
import org.geysermc.api.GeyserApiBase;
32+
import org.geysermc.api.util.ApiVersion;
3233
import org.geysermc.geyser.api.command.CommandSource;
3334
import org.geysermc.geyser.api.connection.GeyserConnection;
3435
import org.geysermc.geyser.api.event.EventBus;
@@ -169,4 +170,14 @@ public interface GeyserApi extends GeyserApiBase {
169170
static GeyserApi api() {
170171
return Geyser.api(GeyserApi.class);
171172
}
173+
174+
/**
175+
* Returns the {@link ApiVersion} representing the current Geyser api version.
176+
* See the <a href="https://github.com/geysermc/api/blob/master/geyser-versioning.md">Geyser version outline</a>)
177+
*
178+
* @return the current geyser api version
179+
*/
180+
default ApiVersion geyserApiVersion() {
181+
return BuildData.API_VERSION;
182+
}
172183
}

api/src/main/java/org/geysermc/geyser/api/command/Command.java

Lines changed: 77 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import org.checkerframework.checker.nullness.qual.NonNull;
2929
import org.geysermc.geyser.api.GeyserApi;
3030
import org.geysermc.geyser.api.connection.GeyserConnection;
31+
import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionsEvent;
3132
import org.geysermc.geyser.api.extension.Extension;
33+
import org.geysermc.geyser.api.util.TriState;
3234

3335
import java.util.Collections;
3436
import java.util.List;
@@ -58,15 +60,15 @@ public interface Command {
5860
* Gets the permission node associated with
5961
* this command.
6062
*
61-
* @return the permission node for this command
63+
* @return the permission node for this command if defined, otherwise an empty string
6264
*/
6365
@NonNull
6466
String permission();
6567

6668
/**
67-
* Gets the aliases for this command.
69+
* Gets the aliases for this command, as an unmodifiable list
6870
*
69-
* @return the aliases for this command
71+
* @return the aliases for this command as an unmodifiable list
7072
*/
7173
@NonNull
7274
List<String> aliases();
@@ -75,35 +77,39 @@ public interface Command {
7577
* Gets if this command is designed to be used only by server operators.
7678
*
7779
* @return if this command is designated to be used only by server operators.
80+
* @deprecated this method is not guaranteed to provide meaningful or expected results.
7881
*/
79-
boolean isSuggestedOpOnly();
82+
@Deprecated(forRemoval = true)
83+
default boolean isSuggestedOpOnly() {
84+
return false;
85+
}
8086

8187
/**
82-
* Gets if this command is executable on console.
83-
*
84-
* @return if this command is executable on console
88+
* @return true if this command is executable on console
89+
* @deprecated use {@link #isPlayerOnly()} instead (inverted)
8590
*/
86-
boolean isExecutableOnConsole();
91+
@Deprecated(forRemoval = true)
92+
default boolean isExecutableOnConsole() {
93+
return !isPlayerOnly();
94+
}
8795

8896
/**
89-
* Gets the subcommands associated with this
90-
* command. Mainly used within the Geyser Standalone
91-
* GUI to know what subcommands are supported.
92-
*
93-
* @return the subcommands associated with this command
97+
* @return true if this command can only be used by players
9498
*/
95-
@NonNull
96-
default List<String> subCommands() {
97-
return Collections.emptyList();
98-
}
99+
boolean isPlayerOnly();
99100

100101
/**
101-
* Used to send a deny message to Java players if this command can only be used by Bedrock players.
102-
*
103-
* @return true if this command can only be used by Bedrock players.
102+
* @return true if this command can only be used by Bedrock players
104103
*/
105-
default boolean isBedrockOnly() {
106-
return false;
104+
boolean isBedrockOnly();
105+
106+
/**
107+
* @deprecated this method will always return an empty immutable list
108+
*/
109+
@Deprecated(forRemoval = true)
110+
@NonNull
111+
default List<String> subCommands() {
112+
return Collections.emptyList();
107113
}
108114

109115
/**
@@ -128,86 +134,119 @@ interface Builder<T extends CommandSource> {
128134
* is an instance of this source.
129135
*
130136
* @param sourceType the source type
131-
* @return the builder
137+
* @return this builder
132138
*/
133139
Builder<T> source(@NonNull Class<? extends T> sourceType);
134140

135141
/**
136142
* Sets the command name.
137143
*
138144
* @param name the command name
139-
* @return the builder
145+
* @return this builder
140146
*/
141147
Builder<T> name(@NonNull String name);
142148

143149
/**
144150
* Sets the command description.
145151
*
146152
* @param description the command description
147-
* @return the builder
153+
* @return this builder
148154
*/
149155
Builder<T> description(@NonNull String description);
150156

151157
/**
152-
* Sets the permission node.
158+
* Sets the permission node required to run this command. <br>
159+
* It will not be registered with any permission registries, such as an underlying server,
160+
* or a permissions Extension (unlike {@link #permission(String, TriState)}).
153161
*
154162
* @param permission the permission node
155-
* @return the builder
163+
* @return this builder
156164
*/
157165
Builder<T> permission(@NonNull String permission);
158166

167+
/**
168+
* Sets the permission node and its default value. The usage of the default value is platform dependant
169+
* and may or may not be used. For example, it may be registered to an underlying server.
170+
* <p>
171+
* Extensions may instead listen for {@link GeyserRegisterPermissionsEvent} to register permissions,
172+
* especially if the same permission is required by multiple commands. Also see this event for TriState meanings.
173+
*
174+
* @param permission the permission node
175+
* @param defaultValue the node's default value
176+
* @return this builder
177+
* @deprecated this method is experimental and may be removed in the future
178+
*/
179+
@Deprecated
180+
Builder<T> permission(@NonNull String permission, @NonNull TriState defaultValue);
181+
159182
/**
160183
* Sets the aliases.
161184
*
162185
* @param aliases the aliases
163-
* @return the builder
186+
* @return this builder
164187
*/
165188
Builder<T> aliases(@NonNull List<String> aliases);
166189

167190
/**
168191
* Sets if this command is designed to be used only by server operators.
169192
*
170193
* @param suggestedOpOnly if this command is designed to be used only by server operators
171-
* @return the builder
194+
* @return this builder
195+
* @deprecated this method is not guaranteed to produce meaningful or expected results
172196
*/
197+
@Deprecated(forRemoval = true)
173198
Builder<T> suggestedOpOnly(boolean suggestedOpOnly);
174199

175200
/**
176201
* Sets if this command is executable on console.
177202
*
178203
* @param executableOnConsole if this command is executable on console
179-
* @return the builder
204+
* @return this builder
205+
* @deprecated use {@link #isPlayerOnly()} instead (inverted)
180206
*/
207+
@Deprecated(forRemoval = true)
181208
Builder<T> executableOnConsole(boolean executableOnConsole);
182209

183210
/**
184-
* Sets the subcommands.
211+
* Sets if this command can only be executed by players.
185212
*
186-
* @param subCommands the subcommands
187-
* @return the builder
213+
* @param playerOnly if this command is player only
214+
* @return this builder
188215
*/
189-
Builder<T> subCommands(@NonNull List<String> subCommands);
216+
Builder<T> playerOnly(boolean playerOnly);
190217

191218
/**
192-
* Sets if this command is bedrock only.
219+
* Sets if this command can only be executed by bedrock players.
193220
*
194221
* @param bedrockOnly if this command is bedrock only
195-
* @return the builder
222+
* @return this builder
196223
*/
197224
Builder<T> bedrockOnly(boolean bedrockOnly);
198225

226+
/**
227+
* Sets the subcommands.
228+
*
229+
* @param subCommands the subcommands
230+
* @return this builder
231+
* @deprecated this method has no effect
232+
*/
233+
@Deprecated(forRemoval = true)
234+
default Builder<T> subCommands(@NonNull List<String> subCommands) {
235+
return this;
236+
}
237+
199238
/**
200239
* Sets the {@link CommandExecutor} for this command.
201240
*
202241
* @param executor the command executor
203-
* @return the builder
242+
* @return this builder
204243
*/
205244
Builder<T> executor(@NonNull CommandExecutor<T> executor);
206245

207246
/**
208247
* Builds the command.
209248
*
210-
* @return the command
249+
* @return a new command from this builder
211250
*/
212251
@NonNull
213252
Command build();

api/src/main/java/org/geysermc/geyser/api/command/CommandSource.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
package org.geysermc.geyser.api.command;
2727

2828
import org.checkerframework.checker.nullness.qual.NonNull;
29+
import org.checkerframework.checker.nullness.qual.Nullable;
30+
import org.geysermc.geyser.api.connection.GeyserConnection;
31+
32+
import java.util.UUID;
2933

3034
/**
3135
* Represents an instance capable of sending commands.
@@ -64,6 +68,17 @@ default void sendMessage(String[] messages) {
6468
*/
6569
boolean isConsole();
6670

71+
/**
72+
* @return a Java UUID if this source represents a player, otherwise null
73+
*/
74+
@Nullable UUID playerUuid();
75+
76+
/**
77+
* @return a GeyserConnection if this source represents a Bedrock player that is connected
78+
* to this Geyser instance, otherwise null
79+
*/
80+
@Nullable GeyserConnection connection();
81+
6782
/**
6883
* Returns the locale of the command source.
6984
*

api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,9 @@ public interface GeyserConnection extends Connection, CommandSource {
132132
@Deprecated
133133
@NonNull
134134
Set<String> fogEffects();
135+
136+
/**
137+
* Returns the current ping of the connection.
138+
*/
139+
int ping();
135140
}

api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ public interface EntityData {
8181
* @return whether the movement is locked
8282
*/
8383
boolean isMovementLocked();
84+
85+
/**
86+
* Sends a request to the Java server to switch the items in the main and offhand.
87+
* There is no guarantee of the server accepting the request.
88+
*/
89+
void switchHands();
8490
}

api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCommandsEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public interface GeyserDefineCommandsEvent extends Event {
5050
/**
5151
* Gets all the registered built-in {@link Command}s.
5252
*
53-
* @return all the registered built-in commands
53+
* @return all the registered built-in commands as an unmodifiable map
5454
*/
5555
@NonNull
5656
Map<String, Command> commands();

0 commit comments

Comments
 (0)