Skip to content

Commit 3f577f4

Browse files
Add fetching MC versions and Console from the extensions API (#4168)
* Add fetching MC versions and Console from the extensions API * Address reviews, expose custom MinecraftVersion interface * Rename of McVersion -> MinecraftVersionImpl; proper nonnull annotation * fluent consoleCommandSource(), change MinecraftVersion#name() to versionString() * Javadocs adjustments * Create impl package and move `MinecraftVersionImpl` there * api version bump --------- Co-authored-by: onebeastchris <[email protected]>
1 parent 97ba6a2 commit 3f577f4

File tree

5 files changed

+134
-4
lines changed

5 files changed

+134
-4
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
import org.checkerframework.checker.nullness.qual.Nullable;
3030
import org.geysermc.api.Geyser;
3131
import org.geysermc.api.GeyserApiBase;
32+
import org.geysermc.geyser.api.command.CommandSource;
3233
import org.geysermc.geyser.api.connection.GeyserConnection;
3334
import org.geysermc.geyser.api.event.EventBus;
3435
import org.geysermc.geyser.api.event.EventRegistrar;
3536
import org.geysermc.geyser.api.extension.ExtensionManager;
3637
import org.geysermc.geyser.api.network.BedrockListener;
3738
import org.geysermc.geyser.api.network.RemoteServer;
39+
import org.geysermc.geyser.api.util.MinecraftVersion;
3840
import org.geysermc.geyser.api.util.PlatformType;
3941

4042
import java.nio.file.Path;
@@ -134,6 +136,30 @@ public interface GeyserApi extends GeyserApiBase {
134136
@NonNull
135137
PlatformType platformType();
136138

139+
/**
140+
* Gets the version of Java Minecraft that is supported.
141+
*
142+
* @return the supported version of Java Minecraft
143+
*/
144+
@NonNull
145+
MinecraftVersion supportedJavaVersion();
146+
147+
/**
148+
* Gets a list of Bedrock Minecraft versions that are supported.
149+
*
150+
* @return the list of supported Bedrock Minecraft versions
151+
*/
152+
@NonNull
153+
List<MinecraftVersion> supportedBedrockVersions();
154+
155+
/**
156+
* Gets the {@link CommandSource} for the console.
157+
*
158+
* @return the console command source
159+
*/
160+
@NonNull
161+
CommandSource consoleCommandSource();
162+
137163
/**
138164
* Gets the current {@link GeyserApiBase} instance.
139165
*
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2019-2023 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.util;
27+
28+
import org.checkerframework.checker.nullness.qual.NonNull;
29+
30+
/**
31+
* Represents a Minecraft version.
32+
*/
33+
public interface MinecraftVersion {
34+
35+
/**
36+
* Gets the Minecraft version as a String.
37+
* Example: "1.20.2", or "1.20.40/1.20.41"
38+
*
39+
* @return the version string
40+
*/
41+
@NonNull String versionString();
42+
43+
/**
44+
* Gets the protocol version of this Minecraft version.
45+
*
46+
* @return the protocol version
47+
*/
48+
int protocolVersion();
49+
}

core/src/main/java/org/geysermc/geyser/GeyserImpl.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
4343
import org.checkerframework.checker.nullness.qual.NonNull;
4444
import org.checkerframework.checker.nullness.qual.Nullable;
45+
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
4546
import org.geysermc.api.Geyser;
47+
import org.geysermc.geyser.api.command.CommandSource;
48+
import org.geysermc.geyser.api.util.MinecraftVersion;
49+
import org.geysermc.geyser.api.util.PlatformType;
4650
import org.geysermc.cumulus.form.Form;
4751
import org.geysermc.cumulus.form.util.FormBuilder;
4852
import org.geysermc.erosion.packet.Packets;
@@ -60,14 +64,15 @@
6064
import org.geysermc.geyser.api.network.AuthType;
6165
import org.geysermc.geyser.api.network.BedrockListener;
6266
import org.geysermc.geyser.api.network.RemoteServer;
63-
import org.geysermc.geyser.api.util.PlatformType;
6467
import org.geysermc.geyser.command.GeyserCommandManager;
6568
import org.geysermc.geyser.configuration.GeyserConfiguration;
6669
import org.geysermc.geyser.entity.EntityDefinitions;
6770
import org.geysermc.geyser.erosion.UnixSocketClientListener;
6871
import org.geysermc.geyser.event.GeyserEventBus;
6972
import org.geysermc.geyser.extension.GeyserExtensionManager;
73+
import org.geysermc.geyser.impl.MinecraftVersionImpl;
7074
import org.geysermc.geyser.level.WorldManager;
75+
import org.geysermc.geyser.network.GameProtocol;
7176
import org.geysermc.geyser.network.netty.GeyserServer;
7277
import org.geysermc.geyser.registry.BlockRegistries;
7378
import org.geysermc.geyser.registry.Registries;
@@ -111,8 +116,8 @@ public class GeyserImpl implements GeyserApi {
111116
.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
112117

113118
public static final String NAME = "Geyser";
114-
public static final String GIT_VERSION = "${gitVersion}"; // A fallback for running in IDEs
115-
public static final String VERSION = "${version}"; // A fallback for running in IDEs
119+
public static final String GIT_VERSION = "${gitVersion}";
120+
public static final String VERSION = "${version}";
116121

117122
public static final String BUILD_NUMBER = "${buildNumber}";
118123
public static final String BRANCH = "${branch}";
@@ -683,6 +688,25 @@ public PlatformType platformType() {
683688
return platformType;
684689
}
685690

691+
@Override
692+
public @NonNull MinecraftVersion supportedJavaVersion() {
693+
return new MinecraftVersionImpl(GameProtocol.getJavaMinecraftVersion(), GameProtocol.getJavaProtocolVersion());
694+
}
695+
696+
@Override
697+
public @NonNull List<MinecraftVersion> supportedBedrockVersions() {
698+
ArrayList<MinecraftVersion> versions = new ArrayList<>();
699+
for (BedrockCodec codec : GameProtocol.SUPPORTED_BEDROCK_CODECS) {
700+
versions.add(new MinecraftVersionImpl(codec.getMinecraftVersion(), codec.getProtocolVersion()));
701+
}
702+
return Collections.unmodifiableList(versions);
703+
}
704+
705+
@Override
706+
public @NonNull CommandSource consoleCommandSource() {
707+
return getLogger();
708+
}
709+
686710
public int buildNumber() {
687711
if (!this.isProductionEnvironment()) {
688712
return 0;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2019-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.impl;
27+
28+
import org.geysermc.geyser.api.util.MinecraftVersion;
29+
30+
public record MinecraftVersionImpl(String versionString, int protocolVersion) implements MinecraftVersion {
31+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ org.gradle.vfs.watch=false
77

88
group=org.geysermc
99
id=geyser
10-
version=2.2.0-SNAPSHOT
10+
version=2.2.1-SNAPSHOT
1111
description=Allows for players from Minecraft: Bedrock Edition to join Minecraft: Java Edition servers.

0 commit comments

Comments
 (0)