permission(@NonNull String permission);
+ /**
+ * Sets the permission node and its default value. The usage of the default value is platform dependant
+ * and may or may not be used. For example, it may be registered to an underlying server.
+ *
+ * Extensions may instead listen for {@link GeyserRegisterPermissionsEvent} to register permissions,
+ * especially if the same permission is required by multiple commands. Also see this event for TriState meanings.
+ *
+ * @param permission the permission node
+ * @param defaultValue the node's default value
+ * @return this builder
+ * @deprecated this method is experimental and may be removed in the future
+ */
+ @Deprecated
+ Builder permission(@NonNull String permission, @NonNull TriState defaultValue);
+
/**
* Sets the aliases.
*
* @param aliases the aliases
- * @return the builder
+ * @return this builder
*/
Builder aliases(@NonNull List aliases);
@@ -168,46 +191,62 @@ public interface Command {
* Sets if this command is designed to be used only by server operators.
*
* @param suggestedOpOnly if this command is designed to be used only by server operators
- * @return the builder
+ * @return this builder
+ * @deprecated this method is not guaranteed to produce meaningful or expected results
*/
+ @Deprecated(forRemoval = true)
Builder suggestedOpOnly(boolean suggestedOpOnly);
/**
* Sets if this command is executable on console.
*
* @param executableOnConsole if this command is executable on console
- * @return the builder
+ * @return this builder
+ * @deprecated use {@link #isPlayerOnly()} instead (inverted)
*/
+ @Deprecated(forRemoval = true)
Builder executableOnConsole(boolean executableOnConsole);
+ /**
+ * Sets if this command can only be executed by players.
+ *
+ * @param playerOnly if this command is player only
+ * @return this builder
+ */
+ Builder playerOnly(boolean playerOnly);
+
+ /**
+ * Sets if this command can only be executed by bedrock players.
+ *
+ * @param bedrockOnly if this command is bedrock only
+ * @return this builder
+ */
+ Builder bedrockOnly(boolean bedrockOnly);
+
/**
* Sets the subcommands.
*
* @param subCommands the subcommands
- * @return the builder
+ * @return this builder
+ * @deprecated this method has no effect
*/
- Builder subCommands(@NonNull List subCommands);
-
- /**
- * Sets if this command is bedrock only.
- *
- * @param bedrockOnly if this command is bedrock only
- * @return the builder
- */
- Builder bedrockOnly(boolean bedrockOnly);
+ @Deprecated(forRemoval = true)
+ default Builder subCommands(@NonNull List subCommands) {
+ return this;
+ }
/**
* Sets the {@link CommandExecutor} for this command.
*
* @param executor the command executor
- * @return the builder
+ * @return this builder
*/
Builder executor(@NonNull CommandExecutor executor);
/**
* Builds the command.
*
- * @return the command
+ * @return a new command from this builder
*/
@NonNull
Command build();
diff --git a/api/src/main/java/org/geysermc/geyser/api/command/CommandSource.java b/api/src/main/java/org/geysermc/geyser/api/command/CommandSource.java
index 45276e2c4..c1453f579 100644
--- a/api/src/main/java/org/geysermc/geyser/api/command/CommandSource.java
+++ b/api/src/main/java/org/geysermc/geyser/api/command/CommandSource.java
@@ -26,6 +26,10 @@
package org.geysermc.geyser.api.command;
import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.geysermc.geyser.api.connection.GeyserConnection;
+
+import java.util.UUID;
/**
* Represents an instance capable of sending commands.
@@ -64,6 +68,17 @@ public interface CommandSource {
*/
boolean isConsole();
+ /**
+ * @return a Java UUID if this source represents a player, otherwise null
+ */
+ @Nullable UUID playerUuid();
+
+ /**
+ * @return a GeyserConnection if this source represents a Bedrock player that is connected
+ * to this Geyser instance, otherwise null
+ */
+ @Nullable GeyserConnection connection();
+
/**
* Returns the locale of the command source.
*
diff --git a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java
index 9bda4f903..ba559a462 100644
--- a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java
+++ b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java
@@ -132,4 +132,9 @@ public interface GeyserConnection extends Connection, CommandSource {
@Deprecated
@NonNull
Set fogEffects();
+
+ /**
+ * Returns the current ping of the connection.
+ */
+ int ping();
}
diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java
index 90b3fc821..48c717089 100644
--- a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java
+++ b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java
@@ -81,4 +81,10 @@ public interface EntityData {
* @return whether the movement is locked
*/
boolean isMovementLocked();
+
+ /**
+ * Sends a request to the Java server to switch the items in the main and offhand.
+ * There is no guarantee of the server accepting the request.
+ */
+ void switchHands();
}
diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCommandsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCommandsEvent.java
index 994373752..d136202bd 100644
--- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCommandsEvent.java
+++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCommandsEvent.java
@@ -50,7 +50,7 @@ public interface GeyserDefineCommandsEvent extends Event {
/**
* Gets all the registered built-in {@link Command}s.
*
- * @return all the registered built-in commands
+ * @return all the registered built-in commands as an unmodifiable map
*/
@NonNull
Map commands();
diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserRegisterPermissionCheckersEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserRegisterPermissionCheckersEvent.java
new file mode 100644
index 000000000..43ebc2c50
--- /dev/null
+++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserRegisterPermissionCheckersEvent.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.geyser.api.event.lifecycle;
+
+import org.geysermc.event.Event;
+import org.geysermc.event.PostOrder;
+import org.geysermc.geyser.api.permission.PermissionChecker;
+
+/**
+ * Fired by any permission manager implementations that wish to add support for custom permission checking.
+ * This event is not guaranteed to be fired - it is currently only fired on Geyser-Standalone and ViaProxy.
+ *
+ * Subscribing to this event with an earlier {@link PostOrder} and registering a {@link PermissionChecker}
+ * will result in that checker having a higher priority than others.
+ */
+public interface GeyserRegisterPermissionCheckersEvent extends Event {
+
+ void register(PermissionChecker checker);
+}
diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserRegisterPermissionsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserRegisterPermissionsEvent.java
new file mode 100644
index 000000000..4f06c4e5f
--- /dev/null
+++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserRegisterPermissionsEvent.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.geyser.api.event.lifecycle;
+
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.geysermc.event.Event;
+import org.geysermc.geyser.api.util.TriState;
+
+/**
+ * Fired by anything that wishes to gather permission nodes and defaults.
+ *
+ * This event is not guaranteed to be fired, as certain Geyser platforms do not have a native permission system.
+ * It can be expected to fire on Geyser-Spigot, Geyser-NeoForge, Geyser-Standalone, and Geyser-ViaProxy
+ * It may be fired by a 3rd party regardless of the platform.
+ */
+public interface GeyserRegisterPermissionsEvent extends Event {
+
+ /**
+ * Registers a permission node and its default value with the firer.
+ * {@link TriState#TRUE} corresponds to all players having the permission by default.
+ * {@link TriState#NOT_SET} corresponds to only server operators having the permission by default (if such a concept exists on the platform).
+ * {@link TriState#FALSE} corresponds to no players having the permission by default.
+ *
+ * @param permission the permission node to register
+ * @param defaultValue the default value of the node
+ */
+ void register(@NonNull String permission, @NonNull TriState defaultValue);
+}
diff --git a/api/src/main/java/org/geysermc/geyser/api/extension/Extension.java b/api/src/main/java/org/geysermc/geyser/api/extension/Extension.java
index 993bdee44..1eacfea9a 100644
--- a/api/src/main/java/org/geysermc/geyser/api/extension/Extension.java
+++ b/api/src/main/java/org/geysermc/geyser/api/extension/Extension.java
@@ -107,6 +107,15 @@ public interface Extension extends EventRegistrar {
return this.extensionLoader().description(this);
}
+ /**
+ * @return the root command that all of this extension's commands will stem from.
+ * By default, this is the extension's id.
+ */
+ @NonNull
+ default String rootCommand() {
+ return this.description().id();
+ }
+
/**
* Gets the extension's logger
*
diff --git a/api/src/main/java/org/geysermc/geyser/api/extension/ExtensionDescription.java b/api/src/main/java/org/geysermc/geyser/api/extension/ExtensionDescription.java
index 2df3ee815..25daf450f 100644
--- a/api/src/main/java/org/geysermc/geyser/api/extension/ExtensionDescription.java
+++ b/api/src/main/java/org/geysermc/geyser/api/extension/ExtensionDescription.java
@@ -59,33 +59,46 @@ public interface ExtensionDescription {
String main();
/**
- * Gets the extension's major api version
+ * Represents the human api version that the extension requires.
+ * See the Geyser version outline)
+ * for more details on the Geyser API version.
*
- * @return the extension's major api version
+ * @return the extension's requested human api version
+ */
+ int humanApiVersion();
+
+ /**
+ * Represents the major api version that the extension requires.
+ * See the Geyser version outline)
+ * for more details on the Geyser API version.
+ *
+ * @return the extension's requested major api version
*/
int majorApiVersion();
/**
- * Gets the extension's minor api version
+ * Represents the minor api version that the extension requires.
+ * See the Geyser version outline)
+ * for more details on the Geyser API version.
*
- * @return the extension's minor api version
+ * @return the extension's requested minor api version
*/
int minorApiVersion();
/**
- * Gets the extension's patch api version
- *
- * @return the extension's patch api version
+ * No longer in use. Geyser is now using an adaption of the romantic versioning scheme.
+ * See here for details.
*/
- int patchApiVersion();
+ @Deprecated(forRemoval = true)
+ default int patchApiVersion() {
+ return minorApiVersion();
+ }
/**
- * Gets the extension's api version.
- *
- * @return the extension's api version
+ * Returns the extension's requested Geyser Api version.
*/
default String apiVersion() {
- return majorApiVersion() + "." + minorApiVersion() + "." + patchApiVersion();
+ return humanApiVersion() + "." + majorApiVersion() + "." + minorApiVersion();
}
/**
diff --git a/api/src/main/java/org/geysermc/geyser/api/permission/PermissionChecker.java b/api/src/main/java/org/geysermc/geyser/api/permission/PermissionChecker.java
new file mode 100644
index 000000000..c0d4af2f4
--- /dev/null
+++ b/api/src/main/java/org/geysermc/geyser/api/permission/PermissionChecker.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.geyser.api.permission;
+
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.geysermc.geyser.api.command.CommandSource;
+import org.geysermc.geyser.api.util.TriState;
+
+/**
+ * Something capable of checking if a {@link CommandSource} has a permission
+ */
+@FunctionalInterface
+public interface PermissionChecker {
+
+ /**
+ * Checks if the given source has a permission
+ *
+ * @param source the {@link CommandSource} whose permissions should be queried
+ * @param permission the permission node to check
+ * @return a {@link TriState} as the value of the node. {@link TriState#NOT_SET} generally means that the permission
+ * node itself was not found, and the source does not have such permission.
+ * {@link TriState#TRUE} and {@link TriState#FALSE} represent explicitly set values.
+ */
+ @NonNull
+ TriState hasPermission(@NonNull CommandSource source, @NonNull String permission);
+}
diff --git a/bootstrap/bungeecord/build.gradle.kts b/bootstrap/bungeecord/build.gradle.kts
index 910e50723..5fe7ea3d1 100644
--- a/bootstrap/bungeecord/build.gradle.kts
+++ b/bootstrap/bungeecord/build.gradle.kts
@@ -1,5 +1,7 @@
dependencies {
api(projects.core)
+
+ implementation(libs.cloud.bungee)
implementation(libs.adventure.text.serializer.bungeecord)
compileOnlyApi(libs.bungeecord.proxy)
}
@@ -8,13 +10,15 @@ platformRelocate("net.md_5.bungee.jni")
platformRelocate("com.fasterxml.jackson")
platformRelocate("io.netty.channel.kqueue") // This is not used because relocating breaks natives, but we must include it or else we get ClassDefNotFound
platformRelocate("net.kyori")
+platformRelocate("org.incendo")
+platformRelocate("io.leangen.geantyref") // provided by cloud, should also be relocated
platformRelocate("org.yaml") // Broken as of 1.20
// These dependencies are already present on the platform
provided(libs.bungeecord.proxy)
-application {
- mainClass.set("org.geysermc.geyser.platform.bungeecord.GeyserBungeeMain")
+tasks.withType {
+ manifest.attributes["Main-Class"] = "org.geysermc.geyser.platform.bungeecord.GeyserBungeeMain"
}
tasks.withType {
diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java
index cd6b59f64..1c0049231 100644
--- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java
+++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java
@@ -27,6 +27,7 @@ package org.geysermc.geyser.platform.bungeecord;
import io.netty.channel.Channel;
import net.md_5.bungee.BungeeCord;
+import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.protocol.ProtocolConstants;
@@ -34,17 +35,20 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl;
-import org.geysermc.geyser.api.command.Command;
-import org.geysermc.geyser.api.extension.Extension;
import org.geysermc.geyser.api.util.PlatformType;
-import org.geysermc.geyser.command.GeyserCommandManager;
+import org.geysermc.geyser.command.CommandRegistry;
+import org.geysermc.geyser.command.CommandSourceConverter;
+import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
-import org.geysermc.geyser.platform.bungeecord.command.GeyserBungeeCommandExecutor;
+import org.geysermc.geyser.platform.bungeecord.command.BungeeCommandSource;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.FileUtils;
+import org.incendo.cloud.CommandManager;
+import org.incendo.cloud.bungee.BungeeCommandManager;
+import org.incendo.cloud.execution.ExecutionCoordinator;
import java.io.File;
import java.io.IOException;
@@ -54,21 +58,22 @@ import java.net.SocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
-import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
- private GeyserCommandManager geyserCommandManager;
+ private CommandRegistry commandRegistry;
private GeyserBungeeConfiguration geyserConfig;
private GeyserBungeeInjector geyserInjector;
private final GeyserBungeeLogger geyserLogger = new GeyserBungeeLogger(getLogger());
private IGeyserPingPassthrough geyserBungeePingPassthrough;
-
private GeyserImpl geyser;
+ // We can't disable the plugin; hence we need to keep track of it manually
+ private boolean disabled;
+
@Override
public void onLoad() {
onGeyserInitialize();
@@ -93,16 +98,23 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
}
if (!this.loadConfig()) {
+ disabled = true;
return;
}
this.geyserLogger.setDebug(geyserConfig.isDebugMode());
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
this.geyser = GeyserImpl.load(PlatformType.BUNGEECORD, this);
this.geyserInjector = new GeyserBungeeInjector(this);
+
+ // Registration of listeners occurs only once
+ this.getProxy().getPluginManager().registerListener(this, new GeyserBungeeUpdateListener());
}
@Override
public void onEnable() {
+ if (disabled) {
+ return; // Config did not load properly!
+ }
// Big hack - Bungee does not provide us an event to listen to, so schedule a repeating
// task that waits for a field to be filled which is set after the plugin enable
// process is complete
@@ -143,10 +155,18 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
this.geyserLogger.setDebug(geyserConfig.isDebugMode());
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
} else {
- // For consistency with other platforms - create command manager before GeyserImpl#start()
- // This ensures the command events are called before the item/block ones are
- this.geyserCommandManager = new GeyserCommandManager(geyser);
- this.geyserCommandManager.init();
+ var sourceConverter = new CommandSourceConverter<>(
+ CommandSender.class,
+ id -> getProxy().getPlayer(id),
+ () -> getProxy().getConsole(),
+ BungeeCommandSource::new
+ );
+ CommandManager cloud = new BungeeCommandManager<>(
+ this,
+ ExecutionCoordinator.simpleCoordinator(),
+ sourceConverter
+ );
+ this.commandRegistry = new CommandRegistry(geyser, cloud, false); // applying root permission would be a breaking change because we can't register permission defaults
}
// Force-disable query if enabled, or else Geyser won't enable
@@ -181,16 +201,6 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
}
this.geyserInjector.initializeLocalChannel(this);
-
- this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor("geyser", this.geyser, this.geyserCommandManager.getCommands()));
- for (Map.Entry> entry : this.geyserCommandManager.extensionCommands().entrySet()) {
- Map commands = entry.getValue();
- if (commands.isEmpty()) {
- continue;
- }
-
- this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor(entry.getKey().description().id(), this.geyser, commands));
- }
}
@Override
@@ -226,8 +236,8 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
}
@Override
- public GeyserCommandManager getGeyserCommandManager() {
- return this.geyserCommandManager;
+ public CommandRegistry getCommandRegistry() {
+ return this.commandRegistry;
}
@Override
diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeUpdateListener.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeUpdateListener.java
index c68839b20..0a89b5421 100644
--- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeUpdateListener.java
+++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeUpdateListener.java
@@ -29,8 +29,8 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
-import org.geysermc.geyser.Constants;
import org.geysermc.geyser.GeyserImpl;
+import org.geysermc.geyser.Permissions;
import org.geysermc.geyser.platform.bungeecord.command.BungeeCommandSource;
import org.geysermc.geyser.util.VersionCheckUtils;
@@ -40,7 +40,7 @@ public final class GeyserBungeeUpdateListener implements Listener {
public void onPlayerJoin(final PostLoginEvent event) {
if (GeyserImpl.getInstance().getConfig().isNotifyOnNewBedrockUpdate()) {
final ProxiedPlayer player = event.getPlayer();
- if (player.hasPermission(Constants.UPDATE_PERMISSION)) {
+ if (player.hasPermission(Permissions.CHECK_UPDATE)) {
VersionCheckUtils.checkForGeyserUpdate(() -> new BungeeCommandSource(player));
}
}
diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/BungeeCommandSource.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/BungeeCommandSource.java
index e3099f170..10ccc5bac 100644
--- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/BungeeCommandSource.java
+++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/BungeeCommandSource.java
@@ -27,19 +27,22 @@ package org.geysermc.geyser.platform.bungeecord.command;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
+import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.text.GeyserLocale;
import java.util.Locale;
+import java.util.UUID;
public class BungeeCommandSource implements GeyserCommandSource {
- private final net.md_5.bungee.api.CommandSender handle;
+ private final CommandSender handle;
- public BungeeCommandSource(net.md_5.bungee.api.CommandSender handle) {
+ public BungeeCommandSource(CommandSender handle) {
this.handle = handle;
// Ensure even Java players' languages are loaded
GeyserLocale.loadGeyserLocale(this.locale());
@@ -72,12 +75,20 @@ public class BungeeCommandSource implements GeyserCommandSource {
return !(handle instanceof ProxiedPlayer);
}
+ @Override
+ public @Nullable UUID playerUuid() {
+ if (handle instanceof ProxiedPlayer player) {
+ return player.getUniqueId();
+ }
+ return null;
+ }
+
@Override
public String locale() {
if (handle instanceof ProxiedPlayer player) {
Locale locale = player.getLocale();
if (locale != null) {
- // Locale can be null early on in the conneciton
+ // Locale can be null early on in the connection
return GeyserLocale.formatLocale(locale.getLanguage() + "_" + locale.getCountry());
}
}
@@ -86,6 +97,12 @@ public class BungeeCommandSource implements GeyserCommandSource {
@Override
public boolean hasPermission(String permission) {
- return handle.hasPermission(permission);
+ // Handle blank permissions ourselves, as bungeecord only handles empty ones
+ return permission.isBlank() || handle.hasPermission(permission);
+ }
+
+ @Override
+ public Object handle() {
+ return handle;
}
}
diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/GeyserBungeeCommandExecutor.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/GeyserBungeeCommandExecutor.java
deleted file mode 100644
index 2d02c9950..000000000
--- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/GeyserBungeeCommandExecutor.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * @author GeyserMC
- * @link https://github.com/GeyserMC/Geyser
- */
-
-package org.geysermc.geyser.platform.bungeecord.command;
-
-import net.md_5.bungee.api.ChatColor;
-import net.md_5.bungee.api.CommandSender;
-import net.md_5.bungee.api.plugin.Command;
-import net.md_5.bungee.api.plugin.TabExecutor;
-import org.geysermc.geyser.GeyserImpl;
-import org.geysermc.geyser.command.GeyserCommand;
-import org.geysermc.geyser.command.GeyserCommandExecutor;
-import org.geysermc.geyser.session.GeyserSession;
-import org.geysermc.geyser.text.GeyserLocale;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Map;
-
-public class GeyserBungeeCommandExecutor extends Command implements TabExecutor {
- private final GeyserCommandExecutor commandExecutor;
-
- public GeyserBungeeCommandExecutor(String name, GeyserImpl geyser, Map commands) {
- super(name);
-
- this.commandExecutor = new GeyserCommandExecutor(geyser, commands);
- }
-
- @Override
- public void execute(CommandSender sender, String[] args) {
- BungeeCommandSource commandSender = new BungeeCommandSource(sender);
- GeyserSession session = this.commandExecutor.getGeyserSession(commandSender);
-
- if (args.length > 0) {
- GeyserCommand command = this.commandExecutor.getCommand(args[0]);
- if (command != null) {
- if (!sender.hasPermission(command.permission())) {
- String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.locale());
-
- commandSender.sendMessage(ChatColor.RED + message);
- return;
- }
- if (command.isBedrockOnly() && session == null) {
- String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.locale());
-
- commandSender.sendMessage(ChatColor.RED + message);
- return;
- }
- command.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
- } else {
- String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.not_found", commandSender.locale());
- commandSender.sendMessage(ChatColor.RED + message);
- }
- } else {
- this.commandExecutor.getCommand("help").execute(session, commandSender, new String[0]);
- }
- }
-
- @Override
- public Iterable onTabComplete(CommandSender sender, String[] args) {
- if (args.length == 1) {
- return commandExecutor.tabComplete(new BungeeCommandSource(sender));
- } else {
- return Collections.emptyList();
- }
- }
-}
diff --git a/bootstrap/mod/build.gradle.kts b/bootstrap/mod/build.gradle.kts
index 32224d00b..57f11b2c7 100644
--- a/bootstrap/mod/build.gradle.kts
+++ b/bootstrap/mod/build.gradle.kts
@@ -16,7 +16,8 @@ afterEvaluate {
dependencies {
api(projects.core)
compileOnly(libs.mixin)
+ compileOnly(libs.mixinextras)
// Only here to suppress "unknown enum constant EnvType.CLIENT" warnings. DO NOT USE!
compileOnly(libs.fabric.loader)
-}
\ No newline at end of file
+}
diff --git a/bootstrap/mod/fabric/build.gradle.kts b/bootstrap/mod/fabric/build.gradle.kts
index 0d083fcf7..fd9d7e99d 100644
--- a/bootstrap/mod/fabric/build.gradle.kts
+++ b/bootstrap/mod/fabric/build.gradle.kts
@@ -1,7 +1,3 @@
-plugins {
- application
-}
-
architectury {
platformSetupLoomIde()
fabric()
@@ -25,10 +21,7 @@ dependencies {
shadow(libs.protocol.connection) { isTransitive = false }
shadow(libs.protocol.common) { isTransitive = false }
shadow(libs.protocol.codec) { isTransitive = false }
- shadow(libs.minecraftauth) { isTransitive = false }
shadow(libs.raknet) { isTransitive = false }
-
- // Consequences of shading + relocating mcauthlib: shadow/relocate mcpl!
shadow(libs.mcprotocollib) { isTransitive = false }
// Since we also relocate cloudburst protocol: shade erosion common
@@ -38,13 +31,12 @@ dependencies {
shadow(projects.api) { isTransitive = false }
shadow(projects.common) { isTransitive = false }
- // Permissions
- modImplementation(libs.fabric.permissions)
- include(libs.fabric.permissions)
+ modImplementation(libs.cloud.fabric)
+ include(libs.cloud.fabric)
}
-application {
- mainClass.set("org.geysermc.geyser.platform.fabric.GeyserFabricMain")
+tasks.withType {
+ manifest.attributes["Main-Class"] = "org.geysermc.geyser.platform.fabric.GeyserFabricMain"
}
relocate("org.cloudburstmc.netty")
@@ -67,4 +59,4 @@ modrinth {
dependencies {
required.project("fabric-api")
}
-}
\ No newline at end of file
+}
diff --git a/bootstrap/mod/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricBootstrap.java b/bootstrap/mod/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricBootstrap.java
index c363ade8f..149246d59 100644
--- a/bootstrap/mod/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricBootstrap.java
+++ b/bootstrap/mod/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricBootstrap.java
@@ -25,7 +25,6 @@
package org.geysermc.geyser.platform.fabric;
-import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
@@ -34,9 +33,16 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.world.entity.player.Player;
-import org.checkerframework.checker.nullness.qual.NonNull;
+import org.geysermc.geyser.GeyserImpl;
+import org.geysermc.geyser.command.CommandRegistry;
+import org.geysermc.geyser.command.CommandSourceConverter;
+import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.platform.mod.GeyserModBootstrap;
import org.geysermc.geyser.platform.mod.GeyserModUpdateListener;
+import org.geysermc.geyser.platform.mod.command.ModCommandSource;
+import org.incendo.cloud.CommandManager;
+import org.incendo.cloud.execution.ExecutionCoordinator;
+import org.incendo.cloud.fabric.FabricServerCommandManager;
public class GeyserFabricBootstrap extends GeyserModBootstrap implements ModInitializer {
@@ -70,20 +76,23 @@ public class GeyserFabricBootstrap extends GeyserModBootstrap implements ModInit
ServerPlayConnectionEvents.JOIN.register((handler, $, $$) -> GeyserModUpdateListener.onPlayReady(handler.getPlayer()));
this.onGeyserInitialize();
+
+ var sourceConverter = CommandSourceConverter.layered(
+ CommandSourceStack.class,
+ id -> getServer().getPlayerList().getPlayer(id),
+ Player::createCommandSourceStack,
+ () -> getServer().createCommandSourceStack(), // NPE if method reference is used, since server is not available yet
+ ModCommandSource::new
+ );
+ CommandManager cloud = new FabricServerCommandManager<>(
+ ExecutionCoordinator.simpleCoordinator(),
+ sourceConverter
+ );
+ this.setCommandRegistry(new CommandRegistry(GeyserImpl.getInstance(), cloud, false)); // applying root permission would be a breaking change because we can't register permission defaults
}
@Override
public boolean isServer() {
return FabricLoader.getInstance().getEnvironmentType().equals(EnvType.SERVER);
}
-
- @Override
- public boolean hasPermission(@NonNull Player source, @NonNull String permissionNode) {
- return Permissions.check(source, permissionNode);
- }
-
- @Override
- public boolean hasPermission(@NonNull CommandSourceStack source, @NonNull String permissionNode, int permissionLevel) {
- return Permissions.check(source, permissionNode, permissionLevel);
- }
}
diff --git a/bootstrap/mod/neoforge/build.gradle.kts b/bootstrap/mod/neoforge/build.gradle.kts
index e0e7c2dfa..81a35a58b 100644
--- a/bootstrap/mod/neoforge/build.gradle.kts
+++ b/bootstrap/mod/neoforge/build.gradle.kts
@@ -1,10 +1,7 @@
-plugins {
- application
-}
-
// This is provided by "org.cloudburstmc.math.mutable" too, so yeet.
// NeoForge's class loader is *really* annoying.
provided("org.cloudburstmc.math", "api")
+provided("com.google.errorprone", "error_prone_annotations")
architectury {
platformSetupLoomIde()
@@ -37,10 +34,13 @@ dependencies {
// Include all transitive deps of core via JiJ
includeTransitive(projects.core)
+
+ modImplementation(libs.cloud.neoforge)
+ include(libs.cloud.neoforge)
}
-application {
- mainClass.set("org.geysermc.geyser.platform.forge.GeyserNeoForgeMain")
+tasks.withType {
+ manifest.attributes["Main-Class"] = "org.geysermc.geyser.platform.neoforge.GeyserNeoForgeMain"
}
tasks {
@@ -56,4 +56,4 @@ tasks {
modrinth {
loaders.add("neoforge")
uploadFile.set(tasks.getByPath("remapModrinthJar"))
-}
\ No newline at end of file
+}
diff --git a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeBootstrap.java b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeBootstrap.java
index b97e42389..7d3b9dc5f 100644
--- a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeBootstrap.java
+++ b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeBootstrap.java
@@ -27,6 +27,7 @@ package org.geysermc.geyser.platform.neoforge;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.world.entity.player.Player;
+import net.neoforged.bus.api.EventPriority;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLLoader;
@@ -35,15 +36,22 @@ import net.neoforged.neoforge.event.GameShuttingDownEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
-import org.checkerframework.checker.nullness.qual.NonNull;
+import net.neoforged.neoforge.server.permission.events.PermissionGatherEvent;
+import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionsEvent;
+import org.geysermc.geyser.command.CommandSourceConverter;
+import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.platform.mod.GeyserModBootstrap;
import org.geysermc.geyser.platform.mod.GeyserModUpdateListener;
+import org.geysermc.geyser.platform.mod.command.ModCommandSource;
+import org.incendo.cloud.CommandManager;
+import org.incendo.cloud.execution.ExecutionCoordinator;
+import org.incendo.cloud.neoforge.NeoForgeServerCommandManager;
+
+import java.util.Objects;
@Mod(ModConstants.MOD_ID)
public class GeyserNeoForgeBootstrap extends GeyserModBootstrap {
- private final GeyserNeoForgePermissionHandler permissionHandler = new GeyserNeoForgePermissionHandler();
-
public GeyserNeoForgeBootstrap(ModContainer container) {
super(new GeyserNeoForgePlatform(container));
@@ -56,9 +64,25 @@ public class GeyserNeoForgeBootstrap extends GeyserModBootstrap {
NeoForge.EVENT_BUS.addListener(this::onServerStopping);
NeoForge.EVENT_BUS.addListener(this::onPlayerJoin);
- NeoForge.EVENT_BUS.addListener(this.permissionHandler::onPermissionGather);
+
+ NeoForge.EVENT_BUS.addListener(EventPriority.HIGHEST, this::onPermissionGather);
this.onGeyserInitialize();
+
+ var sourceConverter = CommandSourceConverter.layered(
+ CommandSourceStack.class,
+ id -> getServer().getPlayerList().getPlayer(id),
+ Player::createCommandSourceStack,
+ () -> getServer().createCommandSourceStack(),
+ ModCommandSource::new
+ );
+ CommandManager cloud = new NeoForgeServerCommandManager<>(
+ ExecutionCoordinator.simpleCoordinator(),
+ sourceConverter
+ );
+ GeyserNeoForgeCommandRegistry registry = new GeyserNeoForgeCommandRegistry(getGeyser(), cloud);
+ this.setCommandRegistry(registry);
+ NeoForge.EVENT_BUS.addListener(EventPriority.LOWEST, registry::onPermissionGatherForUndefined);
}
private void onServerStarted(ServerStartedEvent event) {
@@ -87,13 +111,17 @@ public class GeyserNeoForgeBootstrap extends GeyserModBootstrap {
return FMLLoader.getDist().isDedicatedServer();
}
- @Override
- public boolean hasPermission(@NonNull Player source, @NonNull String permissionNode) {
- return this.permissionHandler.hasPermission(source, permissionNode);
- }
+ private void onPermissionGather(PermissionGatherEvent.Nodes event) {
+ getGeyser().eventBus().fire(
+ (GeyserRegisterPermissionsEvent) (permission, defaultValue) -> {
+ Objects.requireNonNull(permission, "permission");
+ Objects.requireNonNull(defaultValue, "permission default for " + permission);
- @Override
- public boolean hasPermission(@NonNull CommandSourceStack source, @NonNull String permissionNode, int permissionLevel) {
- return this.permissionHandler.hasPermission(source, permissionNode, permissionLevel);
+ if (permission.isBlank()) {
+ return;
+ }
+ PermissionUtils.register(permission, defaultValue, event);
+ }
+ );
}
}
diff --git a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeCommandRegistry.java b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeCommandRegistry.java
new file mode 100644
index 000000000..a8854d5d9
--- /dev/null
+++ b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgeCommandRegistry.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.geyser.platform.neoforge;
+
+import net.neoforged.neoforge.server.permission.events.PermissionGatherEvent;
+import org.geysermc.geyser.GeyserImpl;
+import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionsEvent;
+import org.geysermc.geyser.api.util.TriState;
+import org.geysermc.geyser.command.CommandRegistry;
+import org.geysermc.geyser.command.GeyserCommand;
+import org.geysermc.geyser.command.GeyserCommandSource;
+import org.incendo.cloud.CommandManager;
+import org.incendo.cloud.neoforge.PermissionNotRegisteredException;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class GeyserNeoForgeCommandRegistry extends CommandRegistry {
+
+ /**
+ * Permissions with an undefined permission default. Use Set to not register the same fallback more than once.
+ * NeoForge requires that all permissions are registered, and cloud-neoforge follows that.
+ * This is unlike most platforms, on which we wouldn't register a permission if no default was provided.
+ */
+ private final Set undefinedPermissions = new HashSet<>();
+
+ public GeyserNeoForgeCommandRegistry(GeyserImpl geyser, CommandManager cloud) {
+ super(geyser, cloud);
+ }
+
+ @Override
+ protected void register(GeyserCommand command, Map commands) {
+ super.register(command, commands);
+
+ // FIRST STAGE: Collect all permissions that may have undefined defaults.
+ if (!command.permission().isBlank() && command.permissionDefault() == null) {
+ // Permission requirement exists but no default value specified.
+ undefinedPermissions.add(command.permission());
+ }
+ }
+
+ @Override
+ protected void onRegisterPermissions(GeyserRegisterPermissionsEvent event) {
+ super.onRegisterPermissions(event);
+
+ // SECOND STAGE
+ // Now that we are aware of all commands, we can eliminate some incorrect assumptions.
+ // Example: two commands may have the same permission, but only of them defines a permission default.
+ undefinedPermissions.removeAll(permissionDefaults.keySet());
+ }
+
+ /**
+ * Registers permissions with possibly undefined defaults.
+ * Should be subscribed late to allow extensions and mods to register a desired permission default first.
+ */
+ void onPermissionGatherForUndefined(PermissionGatherEvent.Nodes event) {
+ // THIRD STAGE
+ for (String permission : undefinedPermissions) {
+ if (PermissionUtils.register(permission, TriState.NOT_SET, event)) {
+ // The permission was not already registered
+ geyser.getLogger().debug("Registered permission " + permission + " with fallback default value of NOT_SET");
+ }
+ }
+ }
+
+ @Override
+ public boolean hasPermission(GeyserCommandSource source, String permission) {
+ // NeoForgeServerCommandManager will throw this exception if the permission is not registered to the server.
+ // We can't realistically ensure that every permission is registered (calls by API users), so we catch this.
+ // This works for our calls, but not for cloud's internal usage. For that case, see above.
+ try {
+ return super.hasPermission(source, permission);
+ } catch (PermissionNotRegisteredException e) {
+ return false;
+ }
+ }
+}
diff --git a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgePermissionHandler.java b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgePermissionHandler.java
deleted file mode 100644
index 0a5f8f052..000000000
--- a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/GeyserNeoForgePermissionHandler.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * @author GeyserMC
- * @link https://github.com/GeyserMC/Geyser
- */
-
-package org.geysermc.geyser.platform.neoforge;
-
-import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.server.level.ServerPlayer;
-import net.minecraft.world.entity.player.Player;
-import net.neoforged.neoforge.server.permission.PermissionAPI;
-import net.neoforged.neoforge.server.permission.events.PermissionGatherEvent;
-import net.neoforged.neoforge.server.permission.nodes.PermissionDynamicContextKey;
-import net.neoforged.neoforge.server.permission.nodes.PermissionNode;
-import net.neoforged.neoforge.server.permission.nodes.PermissionType;
-import net.neoforged.neoforge.server.permission.nodes.PermissionTypes;
-import org.checkerframework.checker.nullness.qual.NonNull;
-import org.geysermc.geyser.Constants;
-import org.geysermc.geyser.GeyserImpl;
-import org.geysermc.geyser.api.command.Command;
-import org.geysermc.geyser.command.GeyserCommandManager;
-
-import java.lang.reflect.Constructor;
-import java.util.HashMap;
-import java.util.Map;
-
-public class GeyserNeoForgePermissionHandler {
-
- private static final Constructor> PERMISSION_NODE_CONSTRUCTOR;
-
- static {
- try {
- @SuppressWarnings("rawtypes")
- Constructor constructor = PermissionNode.class.getDeclaredConstructor(
- String.class,
- PermissionType.class,
- PermissionNode.PermissionResolver.class,
- PermissionDynamicContextKey[].class
- );
- constructor.setAccessible(true);
- PERMISSION_NODE_CONSTRUCTOR = constructor;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException("Unable to construct PermissionNode!", e);
- }
- }
-
- private final Map> permissionNodes = new HashMap<>();
-
- public void onPermissionGather(PermissionGatherEvent.Nodes event) {
- this.registerNode(Constants.UPDATE_PERMISSION, event);
-
- GeyserCommandManager commandManager = GeyserImpl.getInstance().commandManager();
- for (Map.Entry entry : commandManager.commands().entrySet()) {
- Command command = entry.getValue();
-
- // Don't register aliases
- if (!command.name().equals(entry.getKey())) {
- continue;
- }
-
- this.registerNode(command.permission(), event);
- }
-
- for (Map commands : commandManager.extensionCommands().values()) {
- for (Map.Entry entry : commands.entrySet()) {
- Command command = entry.getValue();
-
- // Don't register aliases
- if (!command.name().equals(entry.getKey())) {
- continue;
- }
-
- this.registerNode(command.permission(), event);
- }
- }
- }
-
- public boolean hasPermission(@NonNull Player source, @NonNull String permissionNode) {
- PermissionNode node = this.permissionNodes.get(permissionNode);
- if (node == null) {
- GeyserImpl.getInstance().getLogger().warning("Unable to find permission node " + permissionNode);
- return false;
- }
-
- return PermissionAPI.getPermission((ServerPlayer) source, node);
- }
-
- public boolean hasPermission(@NonNull CommandSourceStack source, @NonNull String permissionNode, int permissionLevel) {
- if (!source.isPlayer()) {
- return true;
- }
- assert source.getPlayer() != null;
- boolean permission = this.hasPermission(source.getPlayer(), permissionNode);
- if (!permission) {
- return source.getPlayer().hasPermissions(permissionLevel);
- }
-
- return true;
- }
-
- private void registerNode(String node, PermissionGatherEvent.Nodes event) {
- PermissionNode permissionNode = this.createNode(node);
-
- // NeoForge likes to crash if you try and register a duplicate node
- if (!event.getNodes().contains(permissionNode)) {
- event.addNodes(permissionNode);
- this.permissionNodes.put(node, permissionNode);
- }
- }
-
- @SuppressWarnings("unchecked")
- private PermissionNode createNode(String node) {
- // The typical constructors in PermissionNode require a
- // mod id, which means our permission nodes end up becoming
- // geyser_neoforge. instead of just . We work around
- // this by using reflection to access the constructor that
- // doesn't require a mod id or ResourceLocation.
- try {
- return (PermissionNode) PERMISSION_NODE_CONSTRUCTOR.newInstance(
- node,
- PermissionTypes.BOOLEAN,
- (PermissionNode.PermissionResolver) (player, playerUUID, context) -> false,
- new PermissionDynamicContextKey[0]
- );
- } catch (Exception e) {
- throw new RuntimeException("Unable to create permission node " + node, e);
- }
- }
-}
diff --git a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/PermissionUtils.java b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/PermissionUtils.java
new file mode 100644
index 000000000..c57dc9a6c
--- /dev/null
+++ b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/PermissionUtils.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2024 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.geyser.platform.neoforge;
+
+import net.neoforged.neoforge.server.permission.events.PermissionGatherEvent;
+import net.neoforged.neoforge.server.permission.nodes.PermissionNode;
+import net.neoforged.neoforge.server.permission.nodes.PermissionTypes;
+import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionsEvent;
+import org.geysermc.geyser.api.util.TriState;
+import org.geysermc.geyser.platform.neoforge.mixin.PermissionNodeMixin;
+
+/**
+ * Common logic for handling the more complicated way we have to register permission on NeoForge
+ */
+public class PermissionUtils {
+
+ private PermissionUtils() {
+ //no
+ }
+
+ /**
+ * Registers the given permission and its default value to the event. If the permission has the same name as one
+ * that has already been registered to the event, it will not be registered. In other words, it will not override.
+ *
+ * @param permission the permission to register
+ * @param permissionDefault the permission's default value. See {@link GeyserRegisterPermissionsEvent#register(String, TriState)} for TriState meanings.
+ * @param event the registration event
+ * @return true if the permission was registered
+ */
+ public static boolean register(String permission, TriState permissionDefault, PermissionGatherEvent.Nodes event) {
+ // NeoForge likes to crash if you try and register a duplicate node
+ if (event.getNodes().stream().noneMatch(n -> n.getNodeName().equals(permission))) {
+ PermissionNode node = createNode(permission, permissionDefault);
+ event.addNodes(node);
+ return true;
+ }
+ return false;
+ }
+
+ private static PermissionNode createNode(String node, TriState permissionDefault) {
+ return PermissionNodeMixin.geyser$construct(
+ node,
+ PermissionTypes.BOOLEAN,
+ (player, playerUUID, context) -> switch (permissionDefault) {
+ case TRUE -> true;
+ case FALSE -> false;
+ case NOT_SET -> {
+ if (player != null) {
+ yield player.createCommandSourceStack().hasPermission(player.server.getOperatorUserPermissionLevel());
+ }
+ yield false; // NeoForge javadocs say player is null in the case of an offline player.
+ }
+ }
+ );
+ }
+}
diff --git a/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/mixin/PermissionNodeMixin.java b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/mixin/PermissionNodeMixin.java
new file mode 100644
index 000000000..a43acd58a
--- /dev/null
+++ b/bootstrap/mod/neoforge/src/main/java/org/geysermc/geyser/platform/neoforge/mixin/PermissionNodeMixin.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.geyser.platform.neoforge.mixin;
+
+import net.neoforged.neoforge.server.permission.nodes.PermissionDynamicContextKey;
+import net.neoforged.neoforge.server.permission.nodes.PermissionNode;
+import net.neoforged.neoforge.server.permission.nodes.PermissionType;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Invoker;
+
+@Mixin(value = PermissionNode.class, remap = false) // this is API - do not remap
+public interface PermissionNodeMixin {
+
+ /**
+ * Invokes the matching private constructor in {@link PermissionNode}.
+ *
+ * The typical constructors in PermissionNode require a mod id, which means our permission nodes
+ * would end up becoming {@code geyser_neoforge.} instead of just {@code }.
+ */
+ @SuppressWarnings("rawtypes") // the varargs
+ @Invoker("")
+ static PermissionNode geyser$construct(String nodeName, PermissionType type, PermissionNode.PermissionResolver defaultResolver, PermissionDynamicContextKey... dynamics) {
+ throw new IllegalStateException();
+ }
+}
diff --git a/bootstrap/mod/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/bootstrap/mod/neoforge/src/main/resources/META-INF/neoforge.mods.toml
index fa01bb6ec..56b7d68e1 100644
--- a/bootstrap/mod/neoforge/src/main/resources/META-INF/neoforge.mods.toml
+++ b/bootstrap/mod/neoforge/src/main/resources/META-INF/neoforge.mods.toml
@@ -11,6 +11,8 @@ authors="GeyserMC"
description="${description}"
[[mixins]]
config = "geyser.mixins.json"
+[[mixins]]
+config = "geyser_neoforge.mixins.json"
[[dependencies.geyser_neoforge]]
modId="neoforge"
type="required"
diff --git a/bootstrap/mod/neoforge/src/main/resources/geyser_neoforge.mixins.json b/bootstrap/mod/neoforge/src/main/resources/geyser_neoforge.mixins.json
new file mode 100644
index 000000000..f1653051c
--- /dev/null
+++ b/bootstrap/mod/neoforge/src/main/resources/geyser_neoforge.mixins.json
@@ -0,0 +1,12 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "org.geysermc.geyser.platform.neoforge.mixin",
+ "compatibilityLevel": "JAVA_17",
+ "mixins": [
+ "PermissionNodeMixin"
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModBootstrap.java b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModBootstrap.java
index d7373f0a9..f11b5fbd6 100644
--- a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModBootstrap.java
+++ b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModBootstrap.java
@@ -25,30 +25,21 @@
package org.geysermc.geyser.platform.mod;
-import com.mojang.brigadier.arguments.StringArgumentType;
-import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
-import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
import net.minecraft.server.MinecraftServer;
-import net.minecraft.world.entity.player.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
-import org.geysermc.geyser.api.command.Command;
-import org.geysermc.geyser.api.extension.Extension;
-import org.geysermc.geyser.command.GeyserCommand;
-import org.geysermc.geyser.command.GeyserCommandManager;
+import org.geysermc.geyser.command.CommandRegistry;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.level.WorldManager;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
-import org.geysermc.geyser.platform.mod.command.GeyserModCommandExecutor;
import org.geysermc.geyser.platform.mod.platform.GeyserModPlatform;
import org.geysermc.geyser.platform.mod.world.GeyserModWorldManager;
import org.geysermc.geyser.text.GeyserLocale;
@@ -59,7 +50,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.SocketAddress;
import java.nio.file.Path;
-import java.util.Map;
import java.util.UUID;
@RequiredArgsConstructor
@@ -70,13 +60,15 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
private final GeyserModPlatform platform;
+ @Getter
private GeyserImpl geyser;
private Path dataFolder;
- @Setter
+ @Setter @Getter
private MinecraftServer server;
- private GeyserCommandManager geyserCommandManager;
+ @Setter
+ private CommandRegistry commandRegistry;
private GeyserModConfiguration geyserConfig;
private GeyserModInjector geyserInjector;
private final GeyserModLogger geyserLogger = new GeyserModLogger();
@@ -94,10 +86,6 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
this.geyserLogger.setDebug(geyserConfig.isDebugMode());
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
this.geyser = GeyserImpl.load(this.platform.platformType(), this);
-
- // Create command manager here, since the permission handler on neo needs it
- this.geyserCommandManager = new GeyserCommandManager(geyser);
- this.geyserCommandManager.init();
}
public void onGeyserEnable() {
@@ -130,50 +118,6 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
if (isServer()) {
this.geyserInjector.initializeLocalChannel(this);
}
-
- // Start command building
- // Set just "geyser" as the help command
- GeyserModCommandExecutor helpExecutor = new GeyserModCommandExecutor(geyser,
- (GeyserCommand) geyser.commandManager().getCommands().get("help"));
- LiteralArgumentBuilder builder = Commands.literal("geyser").executes(helpExecutor);
-
- // Register all subcommands as valid
- for (Map.Entry command : geyser.commandManager().getCommands().entrySet()) {
- GeyserModCommandExecutor executor = new GeyserModCommandExecutor(geyser, (GeyserCommand) command.getValue());
- builder.then(Commands.literal(command.getKey())
- .executes(executor)
- // Could also test for Bedrock but depending on when this is called it may backfire
- .requires(executor::testPermission)
- // Allows parsing of arguments; e.g. for /geyser dump logs or the connectiontest command
- .then(Commands.argument("args", StringArgumentType.greedyString())
- .executes(context -> executor.runWithArgs(context, StringArgumentType.getString(context, "args")))
- .requires(executor::testPermission)));
- }
- server.getCommands().getDispatcher().register(builder);
-
- // Register extension commands
- for (Map.Entry> extensionMapEntry : geyser.commandManager().extensionCommands().entrySet()) {
- Map extensionCommands = extensionMapEntry.getValue();
- if (extensionCommands.isEmpty()) {
- continue;
- }
-
- // Register help command for just "/"
- GeyserModCommandExecutor extensionHelpExecutor = new GeyserModCommandExecutor(geyser,
- (GeyserCommand) extensionCommands.get("help"));
- LiteralArgumentBuilder extCmdBuilder = Commands.literal(extensionMapEntry.getKey().description().id()).executes(extensionHelpExecutor);
-
- for (Map.Entry command : extensionCommands.entrySet()) {
- GeyserModCommandExecutor executor = new GeyserModCommandExecutor(geyser, (GeyserCommand) command.getValue());
- extCmdBuilder.then(Commands.literal(command.getKey())
- .executes(executor)
- .requires(executor::testPermission)
- .then(Commands.argument("args", StringArgumentType.greedyString())
- .executes(context -> executor.runWithArgs(context, StringArgumentType.getString(context, "args")))
- .requires(executor::testPermission)));
- }
- server.getCommands().getDispatcher().register(extCmdBuilder);
- }
}
@Override
@@ -206,8 +150,8 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
}
@Override
- public GeyserCommandManager getGeyserCommandManager() {
- return geyserCommandManager;
+ public CommandRegistry getCommandRegistry() {
+ return commandRegistry;
}
@Override
@@ -235,6 +179,7 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
return this.server.getServerVersion();
}
+ @SuppressWarnings("ConstantConditions") // Certain IDEA installations think that ip cannot be null
@NonNull
@Override
public String getServerBindAddress() {
@@ -270,10 +215,6 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
return this.platform.resolveResource(resource);
}
- public abstract boolean hasPermission(@NonNull Player source, @NonNull String permissionNode);
-
- public abstract boolean hasPermission(@NonNull CommandSourceStack source, @NonNull String permissionNode, int permissionLevel);
-
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean loadConfig() {
try {
diff --git a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModUpdateListener.java b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModUpdateListener.java
index 11ca0bc4f..6a724155f 100644
--- a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModUpdateListener.java
+++ b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/GeyserModUpdateListener.java
@@ -25,17 +25,18 @@
package org.geysermc.geyser.platform.mod;
-import net.minecraft.commands.CommandSourceStack;
import net.minecraft.world.entity.player.Player;
-import org.geysermc.geyser.Constants;
-import org.geysermc.geyser.platform.mod.command.ModCommandSender;
+import org.geysermc.geyser.Permissions;
+import org.geysermc.geyser.platform.mod.command.ModCommandSource;
import org.geysermc.geyser.util.VersionCheckUtils;
public final class GeyserModUpdateListener {
public static void onPlayReady(Player player) {
- CommandSourceStack stack = player.createCommandSourceStack();
- if (GeyserModBootstrap.getInstance().hasPermission(stack, Constants.UPDATE_PERMISSION, 2)) {
- VersionCheckUtils.checkForGeyserUpdate(() -> new ModCommandSender(stack));
+ // Should be creating this in the supplier, but we need it for the permission check.
+ // Not a big deal currently because ModCommandSource doesn't load locale, so don't need to try to wait for it.
+ ModCommandSource source = new ModCommandSource(player.createCommandSourceStack());
+ if (source.hasPermission(Permissions.CHECK_UPDATE)) {
+ VersionCheckUtils.checkForGeyserUpdate(() -> source);
}
}
diff --git a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/command/GeyserModCommandExecutor.java b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/command/GeyserModCommandExecutor.java
deleted file mode 100644
index 694dc732e..000000000
--- a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/command/GeyserModCommandExecutor.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * @author GeyserMC
- * @link https://github.com/GeyserMC/Geyser
- */
-
-package org.geysermc.geyser.platform.mod.command;
-
-import com.mojang.brigadier.Command;
-import com.mojang.brigadier.context.CommandContext;
-import net.minecraft.commands.CommandSourceStack;
-import org.geysermc.geyser.GeyserImpl;
-import org.geysermc.geyser.command.GeyserCommand;
-import org.geysermc.geyser.command.GeyserCommandExecutor;
-import org.geysermc.geyser.platform.mod.GeyserModBootstrap;
-import org.geysermc.geyser.session.GeyserSession;
-import org.geysermc.geyser.text.ChatColor;
-import org.geysermc.geyser.text.GeyserLocale;
-
-import java.util.Collections;
-
-public class GeyserModCommandExecutor extends GeyserCommandExecutor implements Command {
- private final GeyserCommand command;
-
- public GeyserModCommandExecutor(GeyserImpl geyser, GeyserCommand command) {
- super(geyser, Collections.singletonMap(command.name(), command));
- this.command = command;
- }
-
- public boolean testPermission(CommandSourceStack source) {
- return GeyserModBootstrap.getInstance().hasPermission(source, command.permission(), command.isSuggestedOpOnly() ? 2 : 0);
- }
-
- @Override
- public int run(CommandContext context) {
- return runWithArgs(context, "");
- }
-
- public int runWithArgs(CommandContext context, String args) {
- CommandSourceStack source = context.getSource();
- ModCommandSender sender = new ModCommandSender(source);
- GeyserSession session = getGeyserSession(sender);
- if (!testPermission(source)) {
- sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.locale()));
- return 0;
- }
-
- if (command.isBedrockOnly() && session == null) {
- sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.locale()));
- return 0;
- }
-
- command.execute(session, sender, args.split(" "));
- return 0;
- }
-}
diff --git a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/command/ModCommandSender.java b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/command/ModCommandSource.java
similarity index 77%
rename from bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/command/ModCommandSender.java
rename to bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/command/ModCommandSource.java
index 5bebfae93..af1f368b3 100644
--- a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/command/ModCommandSender.java
+++ b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/command/ModCommandSource.java
@@ -31,19 +31,21 @@ import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommandSource;
-import org.geysermc.geyser.platform.mod.GeyserModBootstrap;
import org.geysermc.geyser.text.ChatColor;
import java.util.Objects;
+import java.util.UUID;
-public class ModCommandSender implements GeyserCommandSource {
+public class ModCommandSource implements GeyserCommandSource {
private final CommandSourceStack source;
- public ModCommandSender(CommandSourceStack source) {
+ public ModCommandSource(CommandSourceStack source) {
this.source = source;
+ // todo find locale?
}
@Override
@@ -75,8 +77,24 @@ public class ModCommandSender implements GeyserCommandSource {
return !(source.getEntity() instanceof ServerPlayer);
}
+ @Override
+ public @Nullable UUID playerUuid() {
+ if (source.getEntity() instanceof ServerPlayer player) {
+ return player.getUUID();
+ }
+ return null;
+ }
+
@Override
public boolean hasPermission(String permission) {
- return GeyserModBootstrap.getInstance().hasPermission(source, permission, source.getServer().getOperatorUserPermissionLevel());
+ // Unlike other bootstraps; we delegate to cloud here too:
+ // On NeoForge; we'd have to keep track of all PermissionNodes - cloud already does that
+ // For Fabric, we won't need to include the Fabric Permissions API anymore - cloud already does that too :p
+ return GeyserImpl.getInstance().commandRegistry().hasPermission(this, permission);
+ }
+
+ @Override
+ public Object handle() {
+ return source;
}
}
diff --git a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/mixin/server/PistonBaseBlockMixin.java b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/mixin/server/PistonBaseBlockMixin.java
new file mode 100644
index 000000000..6ac51ba52
--- /dev/null
+++ b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/mixin/server/PistonBaseBlockMixin.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2024 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.geyser.platform.mod.mixin.server;
+
+import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
+import com.llamalad7.mixinextras.sugar.Share;
+import com.llamalad7.mixinextras.sugar.ref.LocalRef;
+import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
+import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.piston.PistonBaseBlock;
+import net.minecraft.world.level.block.state.BlockState;
+import org.cloudburstmc.math.vector.Vector3i;
+import org.geysermc.geyser.GeyserImpl;
+import org.geysermc.geyser.session.GeyserSession;
+import org.geysermc.geyser.session.cache.PistonCache;
+import org.geysermc.geyser.translator.level.block.entity.PistonBlockEntity;
+import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.PistonValueType;
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.Unique;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+@Mixin(PistonBaseBlock.class)
+public class PistonBaseBlockMixin {
+
+ @Shadow
+ @Final
+ private boolean isSticky;
+
+ @ModifyExpressionValue(method = "moveBlocks",
+ at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Maps;newHashMap()Ljava/util/HashMap;")
+ )
+ private HashMap geyser$onMapCreate(HashMap original, @Share("pushBlocks") LocalRef