3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 07:40:10 +01:00

Implement support for adding Geyser subcommands

Dieser Commit ist enthalten in:
RednedEpic 2022-01-16 15:09:53 -06:00
Ursprung 57345fa102
Commit 30303d5f16
90 geänderte Dateien mit 1207 neuen und 402 gelöschten Zeilen

Datei anzeigen

@ -26,6 +26,12 @@
<version>3.19.0</version> <version>3.19.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>event-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId> <artifactId>adventure-api</artifactId>
@ -33,10 +39,10 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>org.yaml</groupId>
<artifactId>event-api</artifactId> <artifactId>snakeyaml</artifactId>
<version>3.0.0</version> <version>1.27</version>
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.geysermc</groupId> <groupId>org.geysermc</groupId>

Datei anzeigen

@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.api.Geyser; import org.geysermc.api.Geyser;
import org.geysermc.api.GeyserApiBase; import org.geysermc.api.GeyserApiBase;
import org.geysermc.geyser.api.command.CommandManager;
import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.event.EventBus; import org.geysermc.geyser.api.event.EventBus;
import org.geysermc.geyser.api.extension.ExtensionManager; import org.geysermc.geyser.api.extension.ExtensionManager;
@ -89,6 +90,13 @@ public interface GeyserApi extends GeyserApiBase {
*/ */
ExtensionManager extensionManager(); ExtensionManager extensionManager();
/**
* Gets the {@link CommandManager}.
*
* @return the command manager
*/
CommandManager commandManager();
/** /**
* Gets the {@link EventBus} for handling * Gets the {@link EventBus} for handling
* Geyser events. * Geyser events.

Datei anzeigen

@ -0,0 +1,124 @@
/*
* 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.api.command;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.GeyserApi;
import java.util.Collections;
import java.util.List;
/**
* Represents a command.
*/
public interface Command {
/**
* Gets the command name.
*
* @return the command name
*/
@NonNull
String name();
/**
* Gets the command description.
*
* @return the command description
*/
@NonNull
String description();
/**
* Gets the permission node associated with
* this command.
*
* @return the permission node for this command
*/
@NonNull
String permission();
/**
* Gets the aliases for this command.
*
* @return the aliases for this command
*/
@NonNull
List<String> aliases();
/**
* Gets if this command is executable on console.
*
* @return if this command is executable on console
*/
boolean isExecutableOnConsole();
/**
* Gets the subcommands associated with this
* command. Mainly used within the Geyser Standalone
* GUI to know what subcommands are supported.
*
* @return the subcommands associated with this command
*/
@NonNull
default List<String> subCommands() {
return Collections.emptyList();
}
/**
* Used to send a deny message to Java players if this command can only be used by Bedrock players.
*
* @return true if this command can only be used by Bedrock players.
*/
default boolean isBedrockOnly() {
return false;
}
static <T extends CommandSource> Command.Builder<T> builder(Class<T> sourceType) {
return GeyserApi.api().commandManager().provideBuilder(sourceType);
}
interface Builder<T extends CommandSource> {
Builder<T> name(String name);
Builder<T> description(String description);
Builder<T> permission(String permission);
Builder<T> aliases(List<String> aliases);
Builder<T> executableOnConsole(boolean executableOnConsole);
Builder<T> subCommands(List<String> subCommands);
Builder<T> bedrockOnly(boolean bedrockOnly);
Builder<T> executor(CommandExecutor<T> executor);
Command build();
}
}

Datei anzeigen

@ -0,0 +1,44 @@
/*
* 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.api.command;
/**
* Handles executing a command.
*
* @param <T> the command source
*/
public interface CommandExecutor<T extends CommandSource> {
/**
* Executes the given {@link Command} with the given
* {@link CommandSource}.
*
* @param source the command source
* @param command the command
* @param args the arguments
*/
void execute(T source, Command command, String[] args);
}

Datei anzeigen

@ -0,0 +1,67 @@
/*
* 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.api.command;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Map;
/**
* Manages Bedrock commands within Geyser.
*/
public abstract class CommandManager {
/**
* Provides a {@link Command.Builder}.
*
* @param sourceType the command source type
* @param <T> the type
* @return a command builder
*/
protected abstract <T extends CommandSource> Command.Builder<T> provideBuilder(Class<T> sourceType);
/**
* Registers the given {@link Command}.
*
* @param command the command to register
*/
public abstract void register(@NonNull Command command);
/**
* Unregisters the given {@link Command}.
*
* @param command the command to unregister
*/
public abstract void unregister(@NonNull Command command);
/**
* Gets all the registered {@link Command}s.
*
* @return all the registered commands
*/
@NonNull
public abstract Map<String, Command> commands();
}

Datei anzeigen

@ -23,45 +23,57 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.geyser.command; package org.geysermc.geyser.api.command;
import org.geysermc.geyser.text.GeyserLocale;
/** /**
* Implemented on top of any class that can send a command. * Represents an instance capable of sending commands.
* For example, it wraps around Spigot's CommandSender class.
*/ */
public interface CommandSender { public interface CommandSource {
/**
* The name of the command source.
*
* @return the name of the command source
*/
String name(); String name();
/**
* Sends the given message to the command source
*
* @param message the message to send
*/
void sendMessage(String message);
/**
* Sends the given messages to the command source
*
* @param messages the messages to send
*/
default void sendMessage(String[] messages) { default void sendMessage(String[] messages) {
for (String message : messages) { for (String message : messages) {
sendMessage(message); sendMessage(message);
} }
} }
void sendMessage(String message);
/** /**
* @return true if the specified sender is from the console. * If this source is the console.
*
* @return true if this source is the console
*/ */
boolean isConsole(); boolean isConsole();
/** /**
* Returns the locale of the command sender. Defaults to the default locale at {@link GeyserLocale#getDefaultLocale()}. * Returns the locale of the command source.
* *
* @return the locale of the command sender. * @return the locale of the command source.
*/ */
default String getLocale() { String locale();
return GeyserLocale.getDefaultLocale();
}
/** /**
* Checks if the CommandSender has a permission * Checks if this command source has the given permission
* *
* @param permission The permission node to check * @param permission The permission node to check
* @return true if the CommandSender has the requested permission, false if not * @return true if this command source has a permission
*/ */
boolean hasPermission(String permission); boolean hasPermission(String permission);
} }

Datei anzeigen

@ -26,9 +26,10 @@
package org.geysermc.geyser.api.connection; package org.geysermc.geyser.api.connection;
import org.geysermc.api.connection.Connection; import org.geysermc.api.connection.Connection;
import org.geysermc.geyser.api.command.CommandSource;
/** /**
* Represents a player connection used in Geyser. * Represents a player connection used in Geyser.
*/ */
public interface GeyserConnection extends Connection { public interface GeyserConnection extends Connection, CommandSource {
} }

Datei anzeigen

@ -40,18 +40,7 @@ public interface EventBus {
/** /**
* Subscribes to the given event see {@link EventSubscription}. * Subscribes to the given event see {@link EventSubscription}.
* *
* @param eventClass the class of the event * The difference between this method and {@link ExtensionEventBus#subscribe(Class, Consumer)}
* @param consumer the consumer for handling the event
* @param <T> the event class
* @return the event subscription
*/
@NonNull
<T extends Event> EventSubscription<T> subscribe(@NonNull Class<T> eventClass, @NonNull Consumer<? super T> consumer);
/**
* Subscribes to the given event see {@link EventSubscription}.
*
* The difference between this method and {@link #subscribe(Class, Consumer)}
* is that this method takes in an extension parameter which allows for * is that this method takes in an extension parameter which allows for
* the event to be unsubscribed upon extension disable and reloads. * the event to be unsubscribed upon extension disable and reloads.
* *
@ -79,6 +68,13 @@ public interface EventBus {
*/ */
void register(@NonNull Extension extension, @NonNull Object eventHolder); void register(@NonNull Extension extension, @NonNull Object eventHolder);
/**
* Unregisters all events from a given {@link Extension}.
*
* @param extension the extension
*/
void unregisterAll(@NonNull Extension extension);
/** /**
* Fires the given {@link Event}. * Fires the given {@link Event}.
* *

Datei anzeigen

@ -63,7 +63,7 @@ public interface EventSubscription<T extends Event> {
* *
* @return the extension that owns this subscription * @return the extension that owns this subscription
*/ */
@Nullable @NonNull
Extension owner(); Extension owner();
/** /**

Datei anzeigen

@ -0,0 +1,61 @@
/*
* 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.api.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.function.Consumer;
/**
* An {@link EventBus} with additional methods that implicitly
* set the extension instance.
*
*/
public interface ExtensionEventBus extends EventBus {
/**
* Subscribes to the given event see {@link EventSubscription}.
*
* @param eventClass the class of the event
* @param consumer the consumer for handling the event
* @param <T> the event class
* @return the event subscription
*/
@NonNull
<T extends Event> EventSubscription<T> subscribe(@NonNull Class<T> eventClass, @NonNull Consumer<? super T> consumer);
/**
* Registers events for the given listener.
*
* @param eventHolder the listener
*/
void register(@NonNull Object eventHolder);
/**
* Unregisters all events for this extension.
*/
void unregisterAll();
}

Datei anzeigen

@ -0,0 +1,47 @@
/*
* 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.api.event.connection;
import lombok.RequiredArgsConstructor;
import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.event.Event;
/**
* An event that contains a {@link GeyserConnection}.
*/
@RequiredArgsConstructor
public abstract class ConnectionEvent implements Event {
private final GeyserConnection connection;
/**
* Gets the {@link GeyserConnection}.
*
* @return the connection
*/
public GeyserConnection connection() {
return this.connection;
}
}

Datei anzeigen

@ -0,0 +1,81 @@
/*
* 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.api.event.downstream;
import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.event.Cancellable;
import org.geysermc.geyser.api.event.connection.ConnectionEvent;
import java.util.Set;
/**
* Called when the downstream server defines the commands available on the server.
*/
public class ServerDefineCommandsEvent extends ConnectionEvent implements Cancellable {
private final Set<? extends CommandInfo> commands;
private boolean cancelled;
public ServerDefineCommandsEvent(GeyserConnection connection, Set<? extends CommandInfo> commands) {
super(connection);
this.commands = commands;
}
/**
* A mutable collection of the commands sent over.
*
* @return a mutable collection of the commands sent over
*/
public Set<? extends CommandInfo> commands() {
return this.commands;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public interface CommandInfo {
/**
* Gets the name of the command.
*
* @return the name of the command
*/
String name();
/**
* Gets the description of the command.
*
* @return the description of the command
*/
String description();
}
}

Datei anzeigen

@ -0,0 +1,42 @@
/*
* 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.api.event.lifecycle;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.command.CommandManager;
import org.geysermc.geyser.api.event.Event;
import java.util.Map;
/**
* Called when commands are defined within Geyser.
*
* @param commandManager the command manager
* @param commands a mutable list of the currently
* registered default commands
*/
public record GeyserDefineCommandsEvent(CommandManager commandManager, Map<String, Command> commands) implements Event {
}

Datei anzeigen

@ -27,6 +27,7 @@ package org.geysermc.geyser.api.extension;
import org.geysermc.api.GeyserApiBase; import org.geysermc.api.GeyserApiBase;
import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.event.ExtensionEventBus;
import java.nio.file.Path; import java.nio.file.Path;
@ -80,6 +81,15 @@ public interface Extension {
return this.extensionLoader().dataFolder(this); return this.extensionLoader().dataFolder(this);
} }
/**
* Gets the {@link ExtensionEventBus}.
*
* @return the extension event bus
*/
default ExtensionEventBus eventBus() {
return this.extensionLoader().eventBus(this);
}
/** /**
* Gets the {@link ExtensionManager}. * Gets the {@link ExtensionManager}.
* *

Datei anzeigen

@ -26,6 +26,7 @@
package org.geysermc.geyser.api.extension; package org.geysermc.geyser.api.extension;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.event.ExtensionEventBus;
import java.nio.file.Path; import java.nio.file.Path;
@ -68,6 +69,15 @@ public abstract class ExtensionLoader {
@NonNull @NonNull
protected abstract ExtensionDescription description(@NonNull Extension extension); protected abstract ExtensionDescription description(@NonNull Extension extension);
/**
* Gets the given {@link Extension}'s {@link ExtensionEventBus}.
*
* @param extension the extension
* @return the extension's event bus
*/
@NonNull
protected abstract ExtensionEventBus eventBus(@NonNull Extension extension);
/** /**
* Gets the {@link ExtensionLogger} for the given {@link Extension}. * Gets the {@link ExtensionLogger} for the given {@link Extension}.
* *

Datei anzeigen

@ -30,7 +30,7 @@ import net.md_5.bungee.api.plugin.Plugin;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.session.auth.AuthType; import org.geysermc.geyser.session.auth.AuthType;
import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.dump.BootstrapDumpInfo;
@ -126,6 +126,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
this.geyserInjector.initializeLocalChannel(this); this.geyserInjector.initializeLocalChannel(this);
this.geyserCommandManager = new GeyserBungeeCommandManager(geyser); this.geyserCommandManager = new GeyserBungeeCommandManager(geyser);
this.geyserCommandManager.init();
if (geyserConfig.isLegacyPingPassthrough()) { if (geyserConfig.isLegacyPingPassthrough()) {
this.geyserBungeePingPassthrough = GeyserLegacyPingPassthrough.init(geyser); this.geyserBungeePingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
@ -157,7 +158,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
} }
@Override @Override
public CommandManager getGeyserCommandManager() { public GeyserCommandManager getGeyserCommandManager() {
return this.geyserCommandManager; return this.geyserCommandManager;
} }

Datei anzeigen

@ -27,17 +27,17 @@ package org.geysermc.geyser.platform.bungeecord.command;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
public class BungeeCommandSender implements CommandSender { public class BungeeCommandSource implements GeyserCommandSource {
private final net.md_5.bungee.api.CommandSender handle; private final net.md_5.bungee.api.CommandSender handle;
public BungeeCommandSender(net.md_5.bungee.api.CommandSender handle) { public BungeeCommandSource(net.md_5.bungee.api.CommandSender handle) {
this.handle = handle; this.handle = handle;
// Ensure even Java players' languages are loaded // Ensure even Java players' languages are loaded
GeyserLocale.loadGeyserLocale(getLocale()); GeyserLocale.loadGeyserLocale(this.locale());
} }
@Override @Override
@ -56,7 +56,7 @@ public class BungeeCommandSender implements CommandSender {
} }
@Override @Override
public String getLocale() { public String locale() {
if (handle instanceof ProxiedPlayer player) { if (handle instanceof ProxiedPlayer player) {
String locale = player.getLocale().getLanguage() + "_" + player.getLocale().getCountry(); String locale = player.getLocale().getLanguage() + "_" + player.getLocale().getCountry();
return GeyserLocale.formatLocale(locale); return GeyserLocale.formatLocale(locale);

Datei anzeigen

@ -30,7 +30,7 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor; import net.md_5.bungee.api.plugin.TabExecutor;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandExecutor; import org.geysermc.geyser.command.GeyserCommandExecutor;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
@ -39,30 +39,30 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
public class GeyserBungeeCommandExecutor extends Command implements TabExecutor { public class GeyserBungeeCommandExecutor extends Command implements TabExecutor {
private final CommandExecutor commandExecutor; private final GeyserCommandExecutor commandExecutor;
public GeyserBungeeCommandExecutor(GeyserImpl geyser) { public GeyserBungeeCommandExecutor(GeyserImpl geyser) {
super("geyser"); super("geyser");
this.commandExecutor = new CommandExecutor(geyser); this.commandExecutor = new GeyserCommandExecutor(geyser);
} }
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
BungeeCommandSender commandSender = new BungeeCommandSender(sender); BungeeCommandSource commandSender = new BungeeCommandSource(sender);
GeyserSession session = this.commandExecutor.getGeyserSession(commandSender); GeyserSession session = this.commandExecutor.getGeyserSession(commandSender);
if (args.length > 0) { if (args.length > 0) {
GeyserCommand command = this.commandExecutor.getCommand(args[0]); GeyserCommand command = this.commandExecutor.getCommand(args[0]);
if (command != null) { if (command != null) {
if (!sender.hasPermission(command.getPermission())) { if (!sender.hasPermission(command.permission())) {
String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale()); String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.locale());
commandSender.sendMessage(ChatColor.RED + message); commandSender.sendMessage(ChatColor.RED + message);
return; return;
} }
if (command.isBedrockOnly() && session == null) { if (command.isBedrockOnly() && session == null) {
String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale()); String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.locale());
commandSender.sendMessage(ChatColor.RED + message); commandSender.sendMessage(ChatColor.RED + message);
return; return;
@ -77,7 +77,7 @@ public class GeyserBungeeCommandExecutor extends Command implements TabExecutor
@Override @Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args) { public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
if (args.length == 1) { if (args.length == 1) {
return commandExecutor.tabComplete(new BungeeCommandSender(sender)); return commandExecutor.tabComplete(new BungeeCommandSource(sender));
} else { } else {
return Collections.emptyList(); return Collections.emptyList();
} }

Datei anzeigen

@ -26,16 +26,16 @@
package org.geysermc.geyser.platform.bungeecord.command; package org.geysermc.geyser.platform.bungeecord.command;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
public class GeyserBungeeCommandManager extends CommandManager { public class GeyserBungeeCommandManager extends GeyserCommandManager {
public GeyserBungeeCommandManager(GeyserImpl geyser) { public GeyserBungeeCommandManager(GeyserImpl geyser) {
super(geyser); super(geyser);
} }
@Override @Override
public String getDescription(String command) { public String description(String command) {
return ""; // no support for command descriptions in bungee return ""; // no support for command descriptions in bungee
} }
} }

Datei anzeigen

@ -34,7 +34,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.session.auth.AuthType; import org.geysermc.geyser.session.auth.AuthType;
import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.dump.BootstrapDumpInfo;
@ -48,7 +48,7 @@ import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.adapters.spigot.SpigotAdapters; import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
import org.geysermc.geyser.platform.spigot.command.GeyserSpigotCommandExecutor; import org.geysermc.geyser.platform.spigot.command.GeyserSpigotCommandExecutor;
import org.geysermc.geyser.platform.spigot.command.GeyserSpigotCommandManager; import org.geysermc.geyser.platform.spigot.command.GeyserSpigotCommandManager;
import org.geysermc.geyser.platform.spigot.command.SpigotCommandSender; import org.geysermc.geyser.platform.spigot.command.SpigotCommandSource;
import org.geysermc.geyser.platform.spigot.world.GeyserPistonListener; import org.geysermc.geyser.platform.spigot.world.GeyserPistonListener;
import org.geysermc.geyser.platform.spigot.world.GeyserSpigot1_11CraftingListener; import org.geysermc.geyser.platform.spigot.world.GeyserSpigot1_11CraftingListener;
import org.geysermc.geyser.platform.spigot.world.GeyserSpigotBlockPlaceListener; import org.geysermc.geyser.platform.spigot.world.GeyserSpigotBlockPlaceListener;
@ -161,6 +161,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
} }
this.geyserCommandManager = new GeyserSpigotCommandManager(geyser); this.geyserCommandManager = new GeyserSpigotCommandManager(geyser);
this.geyserCommandManager.init();
boolean isViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion") != null; boolean isViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
if (isViaVersion) { if (isViaVersion) {
@ -182,7 +183,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
boolean isPre1_12 = !isCompatible(Bukkit.getServer().getVersion(), "1.12.0"); boolean isPre1_12 = !isCompatible(Bukkit.getServer().getVersion(), "1.12.0");
// Set if we need to use a different method for getting a player's locale // Set if we need to use a different method for getting a player's locale
SpigotCommandSender.setUseLegacyLocaleMethod(isPre1_12); SpigotCommandSource.setUseLegacyLocaleMethod(isPre1_12);
// We want to do this late in the server startup process to allow plugins such as ViaVersion and ProtocolLib // We want to do this late in the server startup process to allow plugins such as ViaVersion and ProtocolLib
// To do their job injecting, then connect into *that* // To do their job injecting, then connect into *that*
@ -267,7 +268,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
} }
@Override @Override
public CommandManager getGeyserCommandManager() { public GeyserCommandManager getGeyserCommandManager() {
return this.geyserCommandManager; return this.geyserCommandManager;
} }

Datei anzeigen

@ -30,7 +30,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandExecutor; import org.geysermc.geyser.command.GeyserCommandExecutor;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
@ -39,7 +39,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class GeyserSpigotCommandExecutor extends CommandExecutor implements TabExecutor { public class GeyserSpigotCommandExecutor extends GeyserCommandExecutor implements TabExecutor {
public GeyserSpigotCommandExecutor(GeyserImpl geyser) { public GeyserSpigotCommandExecutor(GeyserImpl geyser) {
super(geyser); super(geyser);
@ -47,20 +47,20 @@ public class GeyserSpigotCommandExecutor extends CommandExecutor implements TabE
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
SpigotCommandSender commandSender = new SpigotCommandSender(sender); SpigotCommandSource commandSender = new SpigotCommandSource(sender);
GeyserSession session = getGeyserSession(commandSender); GeyserSession session = getGeyserSession(commandSender);
if (args.length > 0) { if (args.length > 0) {
GeyserCommand geyserCommand = getCommand(args[0]); GeyserCommand geyserCommand = getCommand(args[0]);
if (geyserCommand != null) { if (geyserCommand != null) {
if (!sender.hasPermission(geyserCommand.getPermission())) { if (!sender.hasPermission(geyserCommand.permission())) {
String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale()); String message = GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.locale());
commandSender.sendMessage(ChatColor.RED + message); commandSender.sendMessage(ChatColor.RED + message);
return true; return true;
} }
if (geyserCommand.isBedrockOnly() && session == null) { if (geyserCommand.isBedrockOnly() && session == null) {
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale())); sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.locale()));
return true; return true;
} }
geyserCommand.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]); geyserCommand.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
@ -76,7 +76,7 @@ public class GeyserSpigotCommandExecutor extends CommandExecutor implements TabE
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 1) { if (args.length == 1) {
return tabComplete(new SpigotCommandSender(sender)); return tabComplete(new SpigotCommandSource(sender));
} }
return Collections.emptyList(); return Collections.emptyList();
} }

Datei anzeigen

@ -29,11 +29,11 @@ import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandMap; import org.bukkit.command.CommandMap;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import java.lang.reflect.Field; import java.lang.reflect.Field;
public class GeyserSpigotCommandManager extends CommandManager { public class GeyserSpigotCommandManager extends GeyserCommandManager {
private static CommandMap COMMAND_MAP; private static CommandMap COMMAND_MAP;
@ -52,7 +52,7 @@ public class GeyserSpigotCommandManager extends CommandManager {
} }
@Override @Override
public String getDescription(String command) { public String description(String command) {
Command cmd = COMMAND_MAP.getCommand(command.replace("/", "")); Command cmd = COMMAND_MAP.getCommand(command.replace("/", ""));
return cmd != null ? cmd.getDescription() : ""; return cmd != null ? cmd.getDescription() : "";
} }

Datei anzeigen

@ -28,13 +28,13 @@ package org.geysermc.geyser.platform.spigot.command;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class SpigotCommandSender implements CommandSender { public class SpigotCommandSource implements GeyserCommandSource {
/** /**
* Whether to use {@code Player.getLocale()} or {@code Player.spigot().getLocale()}, depending on version. * Whether to use {@code Player.getLocale()} or {@code Player.spigot().getLocale()}, depending on version.
@ -46,7 +46,7 @@ public class SpigotCommandSender implements CommandSender {
private final org.bukkit.command.CommandSender handle; private final org.bukkit.command.CommandSender handle;
private final String locale; private final String locale;
public SpigotCommandSender(org.bukkit.command.CommandSender handle) { public SpigotCommandSource(org.bukkit.command.CommandSender handle) {
this.handle = handle; this.handle = handle;
this.locale = getSpigotLocale(); this.locale = getSpigotLocale();
// Ensure even Java players' languages are loaded // Ensure even Java players' languages are loaded
@ -69,7 +69,7 @@ public class SpigotCommandSender implements CommandSender {
} }
@Override @Override
public String getLocale() { public String locale() {
return locale; return locale;
} }

Datei anzeigen

@ -29,7 +29,7 @@ import com.google.inject.Inject;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough; import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
@ -120,6 +120,7 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
} }
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser); this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser);
this.geyserCommandManager.init();
Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(geyser), "geyser"); Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(geyser), "geyser");
} }
@ -139,7 +140,7 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
} }
@Override @Override
public CommandManager getGeyserCommandManager() { public GeyserCommandManager getGeyserCommandManager() {
return this.geyserCommandManager; return this.geyserCommandManager;
} }

Datei anzeigen

@ -26,8 +26,8 @@
package org.geysermc.geyser.platform.sponge.command; package org.geysermc.geyser.platform.sponge.command;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandExecutor; import org.geysermc.geyser.command.GeyserCommandExecutor;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.ChatColor;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
@ -45,7 +45,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
public class GeyserSpongeCommandExecutor extends CommandExecutor implements CommandCallable { public class GeyserSpongeCommandExecutor extends GeyserCommandExecutor implements CommandCallable {
public GeyserSpongeCommandExecutor(GeyserImpl geyser) { public GeyserSpongeCommandExecutor(GeyserImpl geyser) {
super(geyser); super(geyser);
@ -53,14 +53,14 @@ public class GeyserSpongeCommandExecutor extends CommandExecutor implements Comm
@Override @Override
public CommandResult process(CommandSource source, String arguments) { public CommandResult process(CommandSource source, String arguments) {
CommandSender commandSender = new SpongeCommandSender(source); GeyserCommandSource commandSender = new SpongeCommandSource(source);
GeyserSession session = getGeyserSession(commandSender); GeyserSession session = getGeyserSession(commandSender);
String[] args = arguments.split(" "); String[] args = arguments.split(" ");
if (args.length > 0) { if (args.length > 0) {
GeyserCommand command = getCommand(args[0]); GeyserCommand command = getCommand(args[0]);
if (command != null) { if (command != null) {
if (!source.hasPermission(command.getPermission())) { if (!source.hasPermission(command.permission())) {
// Not ideal to use log here but we dont get a session // Not ideal to use log here but we dont get a session
source.sendMessage(Text.of(ChatColor.RED + GeyserLocale.getLocaleStringLog("geyser.bootstrap.command.permission_fail"))); source.sendMessage(Text.of(ChatColor.RED + GeyserLocale.getLocaleStringLog("geyser.bootstrap.command.permission_fail")));
return CommandResult.success(); return CommandResult.success();
@ -80,7 +80,7 @@ public class GeyserSpongeCommandExecutor extends CommandExecutor implements Comm
@Override @Override
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) { public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) {
if (arguments.split(" ").length == 1) { if (arguments.split(" ").length == 1) {
return tabComplete(new SpongeCommandSender(source)); return tabComplete(new SpongeCommandSource(source));
} }
return Collections.emptyList(); return Collections.emptyList();
} }

Datei anzeigen

@ -26,12 +26,12 @@
package org.geysermc.geyser.platform.sponge.command; package org.geysermc.geyser.platform.sponge.command;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import org.spongepowered.api.Sponge; import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandMapping; import org.spongepowered.api.command.CommandMapping;
import org.spongepowered.api.text.Text; import org.spongepowered.api.text.Text;
public class GeyserSpongeCommandManager extends CommandManager { public class GeyserSpongeCommandManager extends GeyserCommandManager {
private final org.spongepowered.api.command.CommandManager handle; private final org.spongepowered.api.command.CommandManager handle;
public GeyserSpongeCommandManager(org.spongepowered.api.command.CommandManager handle, GeyserImpl geyser) { public GeyserSpongeCommandManager(org.spongepowered.api.command.CommandManager handle, GeyserImpl geyser) {
@ -41,7 +41,7 @@ public class GeyserSpongeCommandManager extends CommandManager {
} }
@Override @Override
public String getDescription(String command) { public String description(String command) {
return handle.get(command).map(CommandMapping::getCallable) return handle.get(command).map(CommandMapping::getCallable)
.map(callable -> callable.getShortDescription(Sponge.getServer().getConsole()).orElse(Text.EMPTY)) .map(callable -> callable.getShortDescription(Sponge.getServer().getConsole()).orElse(Text.EMPTY))
.orElse(Text.EMPTY).toPlain(); .orElse(Text.EMPTY).toPlain();

Datei anzeigen

@ -27,13 +27,13 @@ package org.geysermc.geyser.platform.sponge.command;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.source.ConsoleSource; import org.spongepowered.api.command.source.ConsoleSource;
import org.spongepowered.api.text.Text; import org.spongepowered.api.text.Text;
@AllArgsConstructor @AllArgsConstructor
public class SpongeCommandSender implements CommandSender { public class SpongeCommandSource implements GeyserCommandSource {
private CommandSource handle; private CommandSource handle;

Datei anzeigen

@ -41,15 +41,15 @@ import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.configuration.GeyserJacksonConfiguration; import org.geysermc.geyser.configuration.GeyserJacksonConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough; import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough; import org.geysermc.geyser.ping.IGeyserPingPassthrough;
import org.geysermc.geyser.platform.standalone.command.GeyserStandaloneCommandManager;
import org.geysermc.geyser.util.FileUtils; import org.geysermc.geyser.util.FileUtils;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.platform.standalone.command.GeyserCommandManager;
import org.geysermc.geyser.platform.standalone.gui.GeyserStandaloneGUI; import org.geysermc.geyser.platform.standalone.gui.GeyserStandaloneGUI;
import java.io.File; import java.io.File;
@ -63,7 +63,7 @@ import java.util.stream.Collectors;
public class GeyserStandaloneBootstrap implements GeyserBootstrap { public class GeyserStandaloneBootstrap implements GeyserBootstrap {
private GeyserCommandManager geyserCommandManager; private GeyserStandaloneCommandManager geyserCommandManager;
private GeyserStandaloneConfiguration geyserConfig; private GeyserStandaloneConfiguration geyserConfig;
private GeyserStandaloneLogger geyserLogger; private GeyserStandaloneLogger geyserLogger;
private IGeyserPingPassthrough geyserPingPassthrough; private IGeyserPingPassthrough geyserPingPassthrough;
@ -215,7 +215,8 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
logger.get().setLevel(geyserConfig.isDebugMode() ? Level.DEBUG : Level.INFO); logger.get().setLevel(geyserConfig.isDebugMode() ? Level.DEBUG : Level.INFO);
geyser = GeyserImpl.start(PlatformType.STANDALONE, this); geyser = GeyserImpl.start(PlatformType.STANDALONE, this);
geyserCommandManager = new GeyserCommandManager(geyser); geyserCommandManager = new GeyserStandaloneCommandManager(geyser);
geyserCommandManager.init();
if (gui != null) { if (gui != null) {
gui.setupInterface(geyserLogger, geyserCommandManager); gui.setupInterface(geyserLogger, geyserCommandManager);
@ -260,7 +261,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
} }
@Override @Override
public CommandManager getGeyserCommandManager() { public GeyserCommandManager getGeyserCommandManager() {
return geyserCommandManager; return geyserCommandManager;
} }

Datei anzeigen

@ -31,11 +31,11 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator; import org.apache.logging.log4j.core.config.Configurator;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger; import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.ChatColor;
@Log4j2 @Log4j2
public class GeyserStandaloneLogger extends SimpleTerminalConsole implements GeyserLogger, CommandSender { public class GeyserStandaloneLogger extends SimpleTerminalConsole implements GeyserLogger, GeyserCommandSource {
@Override @Override
protected boolean isRunning() { protected boolean isRunning() {
@ -44,7 +44,7 @@ public class GeyserStandaloneLogger extends SimpleTerminalConsole implements Gey
@Override @Override
protected void runCommand(String line) { protected void runCommand(String line) {
GeyserImpl.getInstance().getCommandManager().runCommand(this, line); GeyserImpl.getInstance().commandManager().runCommand(this, line);
} }
@Override @Override

Datei anzeigen

@ -26,16 +26,16 @@
package org.geysermc.geyser.platform.standalone.command; package org.geysermc.geyser.platform.standalone.command;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
public class GeyserCommandManager extends CommandManager { public class GeyserStandaloneCommandManager extends GeyserCommandManager {
public GeyserCommandManager(GeyserImpl geyser) { public GeyserStandaloneCommandManager(GeyserImpl geyser) {
super(geyser); super(geyser);
} }
@Override @Override
public String getDescription(String command) { public String description(String command) {
return ""; // this is not sent over the protocol, so we return none return ""; // this is not sent over the protocol, so we return none
} }
} }

Datei anzeigen

@ -26,11 +26,12 @@
package org.geysermc.geyser.platform.standalone.gui; package org.geysermc.geyser.platform.standalone.gui;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.platform.standalone.GeyserStandaloneLogger; import org.geysermc.geyser.platform.standalone.GeyserStandaloneLogger;
import org.geysermc.geyser.platform.standalone.command.GeyserCommandManager; import org.geysermc.geyser.platform.standalone.command.GeyserStandaloneCommandManager;
import javax.swing.*; import javax.swing.*;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
@ -255,33 +256,34 @@ public class GeyserStandaloneGUI {
* @param geyserStandaloneLogger The current logger * @param geyserStandaloneLogger The current logger
* @param geyserCommandManager The commands manager * @param geyserCommandManager The commands manager
*/ */
public void setupInterface(GeyserStandaloneLogger geyserStandaloneLogger, GeyserCommandManager geyserCommandManager) { public void setupInterface(GeyserStandaloneLogger geyserStandaloneLogger, GeyserStandaloneCommandManager geyserCommandManager) {
commandsMenu.removeAll(); commandsMenu.removeAll();
optionsMenu.removeAll(); optionsMenu.removeAll();
for (Map.Entry<String, GeyserCommand> command : geyserCommandManager.getCommands().entrySet()) { for (Map.Entry<String, Command> entry : geyserCommandManager.getCommands().entrySet()) {
// Remove the offhand command and any alias commands to prevent duplicates in the list // Remove the offhand command and any alias commands to prevent duplicates in the list
if (!command.getValue().isExecutableOnConsole() || command.getValue().getAliases().contains(command.getKey())) { if (!entry.getValue().isExecutableOnConsole() || entry.getValue().aliases().contains(entry.getKey())) {
continue; continue;
} }
GeyserCommand command = (GeyserCommand) entry.getValue();
// Create the button that runs the command // Create the button that runs the command
boolean hasSubCommands = command.getValue().hasSubCommands(); boolean hasSubCommands = !entry.getValue().subCommands().isEmpty();
// Add an extra menu if there are more commands that can be run // Add an extra menu if there are more commands that can be run
JMenuItem commandButton = hasSubCommands ? new JMenu(command.getValue().getName()) : new JMenuItem(command.getValue().getName()); JMenuItem commandButton = hasSubCommands ? new JMenu(entry.getValue().name()) : new JMenuItem(entry.getValue().name());
commandButton.getAccessibleContext().setAccessibleDescription(command.getValue().getDescription()); commandButton.getAccessibleContext().setAccessibleDescription(entry.getValue().description());
if (!hasSubCommands) { if (!hasSubCommands) {
commandButton.addActionListener(e -> command.getValue().execute(null, geyserStandaloneLogger, new String[]{ })); commandButton.addActionListener(e -> command.execute(null, geyserStandaloneLogger, new String[]{ }));
} else { } else {
// Add a submenu that's the same name as the menu can't be pressed // Add a submenu that's the same name as the menu can't be pressed
JMenuItem otherCommandButton = new JMenuItem(command.getValue().getName()); JMenuItem otherCommandButton = new JMenuItem(entry.getValue().name());
otherCommandButton.getAccessibleContext().setAccessibleDescription(command.getValue().getDescription()); otherCommandButton.getAccessibleContext().setAccessibleDescription(entry.getValue().description());
otherCommandButton.addActionListener(e -> command.getValue().execute(null, geyserStandaloneLogger, new String[]{ })); otherCommandButton.addActionListener(e -> command.execute(null, geyserStandaloneLogger, new String[]{ }));
commandButton.add(otherCommandButton); commandButton.add(otherCommandButton);
// Add a menu option for all possible subcommands // Add a menu option for all possible subcommands
for (String subCommandName : command.getValue().getSubCommands()) { for (String subCommandName : entry.getValue().subCommands()) {
JMenuItem item = new JMenuItem(subCommandName); JMenuItem item = new JMenuItem(subCommandName);
item.addActionListener(e -> command.getValue().execute(null, geyserStandaloneLogger, new String[]{subCommandName})); item.addActionListener(e -> command.execute(null, geyserStandaloneLogger, new String[]{subCommandName}));
commandButton.add(item); commandButton.add(item);
} }
} }

Datei anzeigen

@ -38,6 +38,7 @@ import lombok.Getter;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough; import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
@ -145,6 +146,8 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
// Will be initialized after the proxy has been bound // Will be initialized after the proxy has been bound
this.geyserCommandManager = new GeyserVelocityCommandManager(geyser); this.geyserCommandManager = new GeyserVelocityCommandManager(geyser);
this.geyserCommandManager.init();
this.commandManager.register("geyser", new GeyserVelocityCommandExecutor(geyser)); this.commandManager.register("geyser", new GeyserVelocityCommandExecutor(geyser));
if (geyserConfig.isLegacyPingPassthrough()) { if (geyserConfig.isLegacyPingPassthrough()) {
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser); this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
@ -174,7 +177,7 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
} }
@Override @Override
public org.geysermc.geyser.command.CommandManager getGeyserCommandManager() { public GeyserCommandManager getGeyserCommandManager() {
return this.geyserCommandManager; return this.geyserCommandManager;
} }

Datei anzeigen

@ -27,8 +27,8 @@ package org.geysermc.geyser.platform.velocity.command;
import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.command.SimpleCommand;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandExecutor; import org.geysermc.geyser.command.GeyserCommandExecutor;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.ChatColor;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
@ -38,7 +38,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class GeyserVelocityCommandExecutor extends CommandExecutor implements SimpleCommand { public class GeyserVelocityCommandExecutor extends GeyserCommandExecutor implements SimpleCommand {
public GeyserVelocityCommandExecutor(GeyserImpl geyser) { public GeyserVelocityCommandExecutor(GeyserImpl geyser) {
super(geyser); super(geyser);
@ -46,18 +46,18 @@ public class GeyserVelocityCommandExecutor extends CommandExecutor implements Si
@Override @Override
public void execute(Invocation invocation) { public void execute(Invocation invocation) {
CommandSender sender = new VelocityCommandSender(invocation.source()); GeyserCommandSource sender = new VelocityCommandSource(invocation.source());
GeyserSession session = getGeyserSession(sender); GeyserSession session = getGeyserSession(sender);
if (invocation.arguments().length > 0) { if (invocation.arguments().length > 0) {
GeyserCommand command = getCommand(invocation.arguments()[0]); GeyserCommand command = getCommand(invocation.arguments()[0]);
if (command != null) { if (command != null) {
if (!invocation.source().hasPermission(getCommand(invocation.arguments()[0]).getPermission())) { if (!invocation.source().hasPermission(getCommand(invocation.arguments()[0]).permission())) {
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale())); sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.locale()));
return; return;
} }
if (command.isBedrockOnly() && session == null) { if (command.isBedrockOnly() && session == null) {
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.getLocale())); sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.locale()));
return; return;
} }
command.execute(session, sender, invocation.arguments().length > 1 ? Arrays.copyOfRange(invocation.arguments(), 1, invocation.arguments().length) : new String[0]); command.execute(session, sender, invocation.arguments().length > 1 ? Arrays.copyOfRange(invocation.arguments(), 1, invocation.arguments().length) : new String[0]);
@ -71,7 +71,7 @@ public class GeyserVelocityCommandExecutor extends CommandExecutor implements Si
public List<String> suggest(Invocation invocation) { public List<String> suggest(Invocation invocation) {
// Velocity seems to do the splitting a bit differently. This results in the same behaviour in bungeecord/spigot. // Velocity seems to do the splitting a bit differently. This results in the same behaviour in bungeecord/spigot.
if (invocation.arguments().length == 0 || invocation.arguments().length == 1) { if (invocation.arguments().length == 0 || invocation.arguments().length == 1) {
return tabComplete(new VelocityCommandSender(invocation.source())); return tabComplete(new VelocityCommandSource(invocation.source()));
} }
return Collections.emptyList(); return Collections.emptyList();
} }

Datei anzeigen

@ -26,16 +26,16 @@
package org.geysermc.geyser.platform.velocity.command; package org.geysermc.geyser.platform.velocity.command;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
public class GeyserVelocityCommandManager extends CommandManager { public class GeyserVelocityCommandManager extends GeyserCommandManager {
public GeyserVelocityCommandManager(GeyserImpl geyser) { public GeyserVelocityCommandManager(GeyserImpl geyser) {
super(geyser); super(geyser);
} }
@Override @Override
public String getDescription(String command) { public String description(String command) {
return ""; // no support for command descriptions in velocity return ""; // no support for command descriptions in velocity
} }
} }

Datei anzeigen

@ -29,19 +29,19 @@ import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
import java.util.Locale; import java.util.Locale;
public class VelocityCommandSender implements CommandSender { public class VelocityCommandSource implements GeyserCommandSource {
private final CommandSource handle; private final CommandSource handle;
public VelocityCommandSender(CommandSource handle) { public VelocityCommandSource(CommandSource handle) {
this.handle = handle; this.handle = handle;
// Ensure even Java players' languages are loaded // Ensure even Java players' languages are loaded
GeyserLocale.loadGeyserLocale(getLocale()); GeyserLocale.loadGeyserLocale(this.locale());
} }
@Override @Override
@ -65,7 +65,7 @@ public class VelocityCommandSender implements CommandSender {
} }
@Override @Override
public String getLocale() { public String locale() {
if (handle instanceof Player) { if (handle instanceof Player) {
Locale locale = ((Player) handle).getPlayerSettings().getLocale(); Locale locale = ((Player) handle).getPlayerSettings().getLocale();
return GeyserLocale.formatLocale(locale.getLanguage() + "_" + locale.getCountry()); return GeyserLocale.formatLocale(locale.getLanguage() + "_" + locale.getCountry());

Datei anzeigen

@ -136,7 +136,7 @@ public class GeyserSession {
} }
public String getLocale() { public String getLocale() {
return this.handle.getLocale(); return this.handle.locale();
} }
public void sendUpstreamPacket(BedrockPacket packet) { public void sendUpstreamPacket(BedrockPacket packet) {

Datei anzeigen

@ -25,7 +25,7 @@
package org.geysermc.geyser; package org.geysermc.geyser;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.level.GeyserWorldManager; import org.geysermc.geyser.level.GeyserWorldManager;
@ -72,7 +72,7 @@ public interface GeyserBootstrap {
* *
* @return The current CommandManager * @return The current CommandManager
*/ */
CommandManager getGeyserCommandManager(); GeyserCommandManager getGeyserCommandManager();
/** /**
* Returns the current PingPassthrough manager * Returns the current PingPassthrough manager

Datei anzeigen

@ -52,7 +52,7 @@ import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.event.EventBus; import org.geysermc.geyser.api.event.EventBus;
import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserShutdownEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserShutdownEvent;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.EntityDefinitions;
import org.geysermc.geyser.event.GeyserEventBus; import org.geysermc.geyser.event.GeyserEventBus;
@ -470,12 +470,11 @@ public class GeyserImpl implements GeyserApi {
skinUploader.close(); skinUploader.close();
} }
newsHandler.shutdown(); newsHandler.shutdown();
this.getCommandManager().getCommands().clear(); this.commandManager().getCommands().clear();
ResourcePack.PACKS.clear(); ResourcePack.PACKS.clear();
this.eventBus.fire(new GeyserShutdownEvent()); this.eventBus.fire(new GeyserShutdownEvent());
this.extensionManager.disableExtensions(); this.extensionManager.disableExtensions();
bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.done")); bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.done"));
@ -504,6 +503,11 @@ public class GeyserImpl implements GeyserApi {
return this.extensionManager; return this.extensionManager;
} }
@Override
public GeyserCommandManager commandManager() {
return this.bootstrap.getGeyserCommandManager();
}
@Override @Override
public EventBus eventBus() { public EventBus eventBus() {
return this.eventBus; return this.eventBus;
@ -531,10 +535,6 @@ public class GeyserImpl implements GeyserApi {
return bootstrap.getGeyserConfig(); return bootstrap.getGeyserConfig();
} }
public CommandManager getCommandManager() {
return bootstrap.getGeyserCommandManager();
}
public WorldManager getWorldManager() { public WorldManager getWorldManager() {
return bootstrap.getWorldManager(); return bootstrap.getWorldManager();
} }

Datei anzeigen

@ -1,122 +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.command;
import lombok.Getter;
import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.defaults.*;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;
import java.util.*;
public abstract class CommandManager {
@Getter
private final Map<String, GeyserCommand> commands = new HashMap<>();
private final GeyserImpl geyser;
public CommandManager(GeyserImpl geyser) {
this.geyser = geyser;
registerCommand(new HelpCommand(geyser, "help", "geyser.commands.help.desc", "geyser.command.help"));
registerCommand(new ListCommand(geyser, "list", "geyser.commands.list.desc", "geyser.command.list"));
registerCommand(new ReloadCommand(geyser, "reload", "geyser.commands.reload.desc", "geyser.command.reload"));
registerCommand(new OffhandCommand(geyser, "offhand", "geyser.commands.offhand.desc", "geyser.command.offhand"));
registerCommand(new DumpCommand(geyser, "dump", "geyser.commands.dump.desc", "geyser.command.dump"));
registerCommand(new VersionCommand(geyser, "version", "geyser.commands.version.desc", "geyser.command.version"));
registerCommand(new SettingsCommand(geyser, "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
registerCommand(new StatisticsCommand(geyser, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
registerCommand(new AdvancementsCommand("advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
registerCommand(new AdvancedTooltipsCommand("tooltips", "geyser.commands.advancedtooltips.desc", "geyser.command.tooltips"));
if (GeyserImpl.getInstance().getPlatformType() == PlatformType.STANDALONE) {
registerCommand(new StopCommand(geyser, "stop", "geyser.commands.stop.desc", "geyser.command.stop"));
}
}
public void registerCommand(GeyserCommand command) {
commands.put(command.getName(), command);
geyser.getLogger().debug(GeyserLocale.getLocaleStringLog("geyser.commands.registered", command.getName()));
if (command.getAliases().isEmpty())
return;
for (String alias : command.getAliases())
commands.put(alias, command);
}
public void runCommand(CommandSender sender, String command) {
if (!command.startsWith("geyser "))
return;
command = command.trim().replace("geyser ", "");
String label;
String[] args;
if (!command.contains(" ")) {
label = command.toLowerCase();
args = new String[0];
} else {
label = command.substring(0, command.indexOf(" ")).toLowerCase();
String argLine = command.substring(command.indexOf(" ") + 1);
args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine };
}
GeyserCommand cmd = commands.get(label);
if (cmd == null) {
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.invalid"));
return;
}
if (sender instanceof GeyserSession) {
cmd.execute((GeyserSession) sender, sender, args);
} else {
if (!cmd.isBedrockOnly()) {
cmd.execute(null, sender, args);
} else {
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.command.bedrock_only"));
}
}
}
/**
* @return a list of all subcommands under {@code /geyser}.
*/
public List<String> getCommandNames() {
return Arrays.asList(geyser.getCommandManager().getCommands().keySet().toArray(new String[0]));
}
/**
* Returns the description of the given command
*
* @param command Command to get the description for
* @return Command description
*/
public abstract String getDescription(String command);
}

Datei anzeigen

@ -27,7 +27,9 @@ package org.geysermc.geyser.command;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.experimental.Accessors;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -35,9 +37,10 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@Accessors(fluent = true)
@Getter @Getter
@RequiredArgsConstructor @RequiredArgsConstructor
public abstract class GeyserCommand { public abstract class GeyserCommand implements Command {
protected final String name; protected final String name;
/** /**
@ -46,16 +49,16 @@ public abstract class GeyserCommand {
protected final String description; protected final String description;
protected final String permission; protected final String permission;
@Setter
private List<String> aliases = new ArrayList<>(); private List<String> aliases = new ArrayList<>();
public abstract void execute(@Nullable GeyserSession session, CommandSender sender, String[] args); public abstract void execute(@Nullable GeyserSession session, GeyserCommandSource sender, String[] args);
/** /**
* If false, hides the command from being shown on the Geyser Standalone GUI. * If false, hides the command from being shown on the Geyser Standalone GUI.
* *
* @return true if the command can be run on the server console * @return true if the command can be run on the server console
*/ */
@Override
public boolean isExecutableOnConsole() { public boolean isExecutableOnConsole() {
return true; return true;
} }
@ -65,25 +68,22 @@ public abstract class GeyserCommand {
* *
* @return a list of all possible subcommands, or empty if none. * @return a list of all possible subcommands, or empty if none.
*/ */
public List<String> getSubCommands() { @NonNull
@Override
public List<String> subCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }
/** /**
* Shortcut to {@link #getSubCommands()}{@code .isEmpty()}. * Shortcut to {@link #subCommands()} ()}{@code .isEmpty()}.
* *
* @return true if there are subcommand present for this command. * @return true if there are subcommand present for this command.
*/ */
public boolean hasSubCommands() { public boolean hasSubCommands() {
return !getSubCommands().isEmpty(); return !this.subCommands().isEmpty();
} }
/** public void setAliases(List<String> aliases) {
* Used to send a deny message to Java players if this command can only be used by Bedrock players. this.aliases = aliases;
*
* @return true if this command can only be used by Bedrock players.
*/
public boolean isBedrockOnly() {
return false;
} }
} }

Datei anzeigen

@ -27,6 +27,7 @@ package org.geysermc.geyser.command;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -39,16 +40,16 @@ import java.util.Map;
* Represents helper functions for listening to {@code /geyser} commands. * Represents helper functions for listening to {@code /geyser} commands.
*/ */
@AllArgsConstructor @AllArgsConstructor
public class CommandExecutor { public class GeyserCommandExecutor {
protected final GeyserImpl geyser; protected final GeyserImpl geyser;
public GeyserCommand getCommand(String label) { public GeyserCommand getCommand(String label) {
return geyser.getCommandManager().getCommands().get(label); return (GeyserCommand) geyser.commandManager().commands().get(label);
} }
@Nullable @Nullable
public GeyserSession getGeyserSession(CommandSender sender) { public GeyserSession getGeyserSession(GeyserCommandSource sender) {
if (sender.isConsole()) { if (sender.isConsole()) {
return null; return null;
} }
@ -70,20 +71,19 @@ public class CommandExecutor {
* If the command sender does not have the permission for a given command, the command will not be shown. * If the command sender does not have the permission for a given command, the command will not be shown.
* @return A list of command names to include in the tab complete * @return A list of command names to include in the tab complete
*/ */
public List<String> tabComplete(CommandSender sender) { public List<String> tabComplete(GeyserCommandSource sender) {
if (getGeyserSession(sender) != null) { if (getGeyserSession(sender) != null) {
// Bedrock doesn't get tab completions or argument suggestions // Bedrock doesn't get tab completions or argument suggestions
return Collections.emptyList(); return Collections.emptyList();
} }
List<String> availableCommands = new ArrayList<>(); List<String> availableCommands = new ArrayList<>();
Map<String, GeyserCommand> commands = geyser.getCommandManager().getCommands(); Map<String, Command> commands = geyser.commandManager().getCommands();
// Only show commands they have permission to use // Only show commands they have permission to use
for (Map.Entry<String, GeyserCommand> entry : commands.entrySet()) { for (Map.Entry<String, Command> entry : commands.entrySet()) {
GeyserCommand geyserCommand = entry.getValue(); Command geyserCommand = entry.getValue();
if (sender.hasPermission(geyserCommand.getPermission())) { if (sender.hasPermission(geyserCommand.permission())) {
if (geyserCommand.isBedrockOnly()) { if (geyserCommand.isBedrockOnly()) {
// Don't show commands the JE player can't run // Don't show commands the JE player can't run
continue; continue;

Datei anzeigen

@ -0,0 +1,256 @@
/*
* 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.command;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.command.CommandExecutor;
import org.geysermc.geyser.api.command.CommandManager;
import org.geysermc.geyser.api.command.CommandSource;
import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent;
import org.geysermc.geyser.command.defaults.*;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@RequiredArgsConstructor
public abstract class GeyserCommandManager extends CommandManager {
@Getter
private final Map<String, Command> commands = new HashMap<>();
private final GeyserImpl geyser;
public void init() {
register(new HelpCommand(geyser, "help", "geyser.commands.help.desc", "geyser.command.help"));
register(new ListCommand(geyser, "list", "geyser.commands.list.desc", "geyser.command.list"));
register(new ReloadCommand(geyser, "reload", "geyser.commands.reload.desc", "geyser.command.reload"));
register(new OffhandCommand(geyser, "offhand", "geyser.commands.offhand.desc", "geyser.command.offhand"));
register(new DumpCommand(geyser, "dump", "geyser.commands.dump.desc", "geyser.command.dump"));
register(new VersionCommand(geyser, "version", "geyser.commands.version.desc", "geyser.command.version"));
register(new SettingsCommand(geyser, "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
register(new StatisticsCommand(geyser, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
register(new AdvancementsCommand("advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
register(new AdvancedTooltipsCommand("tooltips", "geyser.commands.advancedtooltips.desc", "geyser.command.tooltips"));
if (GeyserImpl.getInstance().getPlatformType() == PlatformType.STANDALONE) {
register(new StopCommand(geyser, "stop", "geyser.commands.stop.desc", "geyser.command.stop"));
}
this.geyser.eventBus().fire(new GeyserDefineCommandsEvent(this, this.commands));
}
@Override
public void register(@NonNull Command command) {
this.commands.put(command.name(), command);
this.geyser.getLogger().debug(GeyserLocale.getLocaleStringLog("geyser.commands.registered", command.name()));
if (command.aliases().isEmpty()) {
return;
}
for (String alias : command.aliases()) {
this.commands.put(alias, command);
}
}
@Override
public void unregister(@NonNull Command command) {
this.commands.remove(command.name(), command);
if (command.aliases().isEmpty()) {
return;
}
for (String alias : command.aliases()) {
this.commands.remove(alias, command);
}
}
@NotNull
@Override
public Map<String, Command> commands() {
return Collections.unmodifiableMap(this.commands);
}
public void runCommand(GeyserCommandSource sender, String command) {
if (!command.startsWith("geyser "))
return;
command = command.trim().replace("geyser ", "");
String label;
String[] args;
if (!command.contains(" ")) {
label = command.toLowerCase();
args = new String[0];
} else {
label = command.substring(0, command.indexOf(" ")).toLowerCase();
String argLine = command.substring(command.indexOf(" ") + 1);
args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine };
}
Command cmd = commands.get(label);
if (cmd == null) {
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.invalid"));
return;
}
if (cmd instanceof GeyserCommand) {
if (sender instanceof GeyserSession) {
((GeyserCommand) cmd).execute((GeyserSession) sender, sender, args);
} else {
if (!cmd.isBedrockOnly()) {
((GeyserCommand) cmd).execute(null, sender, args);
} else {
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.command.bedrock_only"));
}
}
}
}
/**
* Returns the description of the given command
*
* @param command Command to get the description for
* @return Command description
*/
public abstract String description(String command);
@Override
protected <T extends CommandSource> Command.Builder<T> provideBuilder(Class<T> sourceType) {
return new CommandBuilder<>(sourceType);
}
@RequiredArgsConstructor
public static class CommandBuilder<T extends CommandSource> implements Command.Builder<T> {
private final Class<T> sourceType;
private String name;
private String description = "";
private String permission = "";
private List<String> aliases;
private boolean executableOnConsole = true;
private List<String> subCommands;
private boolean bedrockOnly;
private CommandExecutor<T> executor;
public CommandBuilder<T> name(String name) {
this.name = name;
return this;
}
public CommandBuilder<T> description(String description) {
this.description = description;
return this;
}
public CommandBuilder<T> permission(String permission) {
this.permission = permission;
return this;
}
public CommandBuilder<T> aliases(List<String> aliases) {
this.aliases = aliases;
return this;
}
public CommandBuilder<T> executableOnConsole(boolean executableOnConsole) {
this.executableOnConsole = executableOnConsole;
return this;
}
public CommandBuilder<T> subCommands(List<String> subCommands) {
this.subCommands = subCommands;
return this;
}
public CommandBuilder<T> bedrockOnly(boolean bedrockOnly) {
this.bedrockOnly = bedrockOnly;
return this;
}
public CommandBuilder<T> executor(CommandExecutor<T> executor) {
this.executor = executor;
return this;
}
public GeyserCommand build() {
if (this.name == null || this.name.isBlank()) {
throw new IllegalArgumentException("Command cannot be null or blank!");
}
return new GeyserCommand(this.name, this.description, this.permission) {
@SuppressWarnings("unchecked")
@Override
public void execute(@Nullable GeyserSession session, GeyserCommandSource sender, String[] args) {
Class<T> sourceType = CommandBuilder.this.sourceType;
CommandExecutor<T> executor = CommandBuilder.this.executor;
if (sourceType.isInstance(session)) {
executor.execute((T) session, this, args);
return;
}
if (sourceType.isInstance(sender)) {
executor.execute((T) sender, this, args);
return;
}
GeyserImpl.getInstance().getLogger().debug("Ignoring command " + this.name + " due to no suitable sender.");
}
@NonNull
@Override
public List<String> aliases() {
return CommandBuilder.this.aliases == null ? Collections.emptyList() : CommandBuilder.this.aliases;
}
@NonNull
@Override
public List<String> subCommands() {
return CommandBuilder.this.subCommands == null ? Collections.emptyList() : CommandBuilder.this.subCommands;
}
@Override
public boolean isBedrockOnly() {
return CommandBuilder.this.bedrockOnly;
}
@Override
public boolean isExecutableOnConsole() {
return CommandBuilder.this.executableOnConsole;
}
};
}
}
}

Datei anzeigen

@ -0,0 +1,43 @@
/*
* 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.command;
import org.geysermc.geyser.api.command.CommandSource;
import org.geysermc.geyser.text.GeyserLocale;
/**
* Implemented on top of any class that can send a command.
* For example, it wraps around Spigot's CommandSender class.
*/
public interface GeyserCommandSource extends CommandSource {
/**
* {@inheritDoc}
*/
default String locale() {
return GeyserLocale.getDefaultLocale();
}
}

Datei anzeigen

@ -25,7 +25,7 @@
package org.geysermc.geyser.command.defaults; package org.geysermc.geyser.command.defaults;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.MinecraftLocale; import org.geysermc.geyser.text.MinecraftLocale;
@ -36,11 +36,11 @@ public class AdvancedTooltipsCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
if (session != null) { if (session != null) {
String onOrOff = session.isAdvancedTooltips() ? "off" : "on"; String onOrOff = session.isAdvancedTooltips() ? "off" : "on";
session.setAdvancedTooltips(!session.isAdvancedTooltips()); session.setAdvancedTooltips(!session.isAdvancedTooltips());
session.sendMessage("§l§e" + MinecraftLocale.getLocaleString("debug.prefix", session.getLocale()) + " §r" + MinecraftLocale.getLocaleString("debug.advanced_tooltips." + onOrOff, session.getLocale())); session.sendMessage("§l§e" + MinecraftLocale.getLocaleString("debug.prefix", session.locale()) + " §r" + MinecraftLocale.getLocaleString("debug.advanced_tooltips." + onOrOff, session.locale()));
session.getInventoryTranslator().updateInventory(session, session.getPlayerInventory()); session.getInventoryTranslator().updateInventory(session, session.getPlayerInventory());
} }
} }

Datei anzeigen

@ -25,7 +25,7 @@
package org.geysermc.geyser.command.defaults; package org.geysermc.geyser.command.defaults;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
@ -35,7 +35,7 @@ public class AdvancementsCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
if (session != null) { if (session != null) {
session.getAdvancementsCache().buildAndShowMenuForm(); session.getAdvancementsCache().buildAndShowMenuForm();
} }

Datei anzeigen

@ -29,9 +29,10 @@ import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.ChatColor;
import org.geysermc.geyser.text.AsteriskSerializer; import org.geysermc.geyser.text.AsteriskSerializer;
@ -58,10 +59,10 @@ public class DumpCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
// Only allow the console to create dumps on Geyser Standalone // Only allow the console to create dumps on Geyser Standalone
if (!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE) { if (!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE) {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale())); sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.locale()));
return; return;
} }
@ -80,7 +81,7 @@ public class DumpCommand extends GeyserCommand {
AsteriskSerializer.showSensitive = showSensitive; AsteriskSerializer.showSensitive = showSensitive;
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collecting", sender.getLocale())); sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collecting", sender.locale()));
String dumpData; String dumpData;
try { try {
if (offlineDump) { if (offlineDump) {
@ -92,7 +93,7 @@ public class DumpCommand extends GeyserCommand {
dumpData = MAPPER.writeValueAsString(new DumpInfo(addLog)); dumpData = MAPPER.writeValueAsString(new DumpInfo(addLog));
} }
} catch (IOException e) { } catch (IOException e) {
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collect_error", sender.getLocale())); sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collect_error", sender.locale()));
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.dump.collect_error_short"), e); geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.dump.collect_error_short"), e);
return; return;
} }
@ -100,21 +101,21 @@ public class DumpCommand extends GeyserCommand {
String uploadedDumpUrl = ""; String uploadedDumpUrl = "";
if (offlineDump) { if (offlineDump) {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.writing", sender.getLocale())); sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.writing", sender.locale()));
try { try {
FileOutputStream outputStream = new FileOutputStream(GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("dump.json").toFile()); FileOutputStream outputStream = new FileOutputStream(GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("dump.json").toFile());
outputStream.write(dumpData.getBytes()); outputStream.write(dumpData.getBytes());
outputStream.close(); outputStream.close();
} catch (IOException e) { } catch (IOException e) {
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.write_error", sender.getLocale())); sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.write_error", sender.locale()));
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.dump.write_error_short"), e); geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.dump.write_error_short"), e);
return; return;
} }
uploadedDumpUrl = "dump.json"; uploadedDumpUrl = "dump.json";
} else { } else {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.uploading", sender.getLocale())); sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.uploading", sender.locale()));
String response; String response;
JsonNode responseNode; JsonNode responseNode;
@ -122,27 +123,28 @@ public class DumpCommand extends GeyserCommand {
response = WebUtils.post(DUMP_URL + "documents", dumpData); response = WebUtils.post(DUMP_URL + "documents", dumpData);
responseNode = MAPPER.readTree(response); responseNode = MAPPER.readTree(response);
} catch (IOException e) { } catch (IOException e) {
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.upload_error", sender.getLocale())); sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.upload_error", sender.locale()));
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.dump.upload_error_short"), e); geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.dump.upload_error_short"), e);
return; return;
} }
if (!responseNode.has("key")) { if (!responseNode.has("key")) {
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.upload_error_short", sender.getLocale()) + ": " + (responseNode.has("message") ? responseNode.get("message").asText() : response)); sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.upload_error_short", sender.locale()) + ": " + (responseNode.has("message") ? responseNode.get("message").asText() : response));
return; return;
} }
uploadedDumpUrl = DUMP_URL + responseNode.get("key").asText(); uploadedDumpUrl = DUMP_URL + responseNode.get("key").asText();
} }
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.message", sender.getLocale()) + " " + ChatColor.DARK_AQUA + uploadedDumpUrl); sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.message", sender.locale()) + " " + ChatColor.DARK_AQUA + uploadedDumpUrl);
if (!sender.isConsole()) { if (!sender.isConsole()) {
geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.commands.dump.created", sender.name(), uploadedDumpUrl)); geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.commands.dump.created", sender.name(), uploadedDumpUrl));
} }
} }
@NonNull
@Override @Override
public List<String> getSubCommands() { public List<String> subCommands() {
return Arrays.asList("offline", "full", "logs"); return Arrays.asList("offline", "full", "logs");
} }
} }

Datei anzeigen

@ -27,7 +27,8 @@ package org.geysermc.geyser.command.defaults;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.ChatColor;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
@ -54,25 +55,25 @@ public class HelpCommand extends GeyserCommand {
* @param args Not used. * @param args Not used.
*/ */
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
int page = 1; int page = 1;
int maxPage = 1; int maxPage = 1;
String header = GeyserLocale.getPlayerLocaleString("geyser.commands.help.header", sender.getLocale(), page, maxPage); String header = GeyserLocale.getPlayerLocaleString("geyser.commands.help.header", sender.locale(), page, maxPage);
sender.sendMessage(header); sender.sendMessage(header);
Map<String, GeyserCommand> cmds = geyser.getCommandManager().getCommands(); Map<String, Command> cmds = geyser.commandManager().getCommands();
for (Map.Entry<String, GeyserCommand> entry : cmds.entrySet()) { for (Map.Entry<String, Command> entry : cmds.entrySet()) {
GeyserCommand cmd = entry.getValue(); Command cmd = entry.getValue();
// Standalone hack-in since it doesn't have a concept of permissions // Standalone hack-in since it doesn't have a concept of permissions
if (geyser.getPlatformType() == PlatformType.STANDALONE || sender.hasPermission(cmd.getPermission())) { if (geyser.getPlatformType() == PlatformType.STANDALONE || sender.hasPermission(cmd.permission())) {
// Only list commands the player can actually run // Only list commands the player can actually run
if (cmd.isBedrockOnly() && session == null) { if (cmd.isBedrockOnly() && session == null) {
continue; continue;
} }
sender.sendMessage(ChatColor.YELLOW + "/geyser " + entry.getKey() + ChatColor.WHITE + ": " + sender.sendMessage(ChatColor.YELLOW + "/geyser " + entry.getKey() + ChatColor.WHITE + ": " +
GeyserLocale.getPlayerLocaleString(cmd.getDescription(), sender.getLocale())); GeyserLocale.getPlayerLocaleString(cmd.description(), sender.locale()));
} }
} }
} }

Datei anzeigen

@ -26,7 +26,7 @@
package org.geysermc.geyser.command.defaults; package org.geysermc.geyser.command.defaults;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
@ -44,8 +44,8 @@ public class ListCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
String message = GeyserLocale.getPlayerLocaleString("geyser.commands.list.message", sender.getLocale(), String message = GeyserLocale.getPlayerLocaleString("geyser.commands.list.message", sender.locale(),
geyser.getSessionManager().size(), geyser.getSessionManager().size(),
geyser.getSessionManager().getAllSessions().stream().map(GeyserSession::name).collect(Collectors.joining(" "))); geyser.getSessionManager().getAllSessions().stream().map(GeyserSession::name).collect(Collectors.joining(" ")));

Datei anzeigen

@ -29,7 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction; import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.BlockUtils; import org.geysermc.geyser.util.BlockUtils;
@ -41,7 +41,7 @@ public class OffhandCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
if (session == null) { if (session == null) {
return; return;
} }

Datei anzeigen

@ -27,7 +27,7 @@ package org.geysermc.geyser.command.defaults;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
@ -42,12 +42,12 @@ public class ReloadCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
if (!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE) { if (!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE) {
return; return;
} }
String message = GeyserLocale.getPlayerLocaleString("geyser.commands.reload.message", sender.getLocale()); String message = GeyserLocale.getPlayerLocaleString("geyser.commands.reload.message", sender.locale());
sender.sendMessage(message); sender.sendMessage(message);

Datei anzeigen

@ -26,7 +26,7 @@
package org.geysermc.geyser.command.defaults; package org.geysermc.geyser.command.defaults;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.SettingsUtils; import org.geysermc.geyser.util.SettingsUtils;
@ -37,7 +37,7 @@ public class SettingsCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
if (session != null) { if (session != null) {
session.sendForm(SettingsUtils.buildForm(session)); session.sendForm(SettingsUtils.buildForm(session));
} }

Datei anzeigen

@ -28,7 +28,7 @@ package org.geysermc.geyser.command.defaults;
import com.github.steveice10.mc.protocol.data.game.ClientCommand; import com.github.steveice10.mc.protocol.data.game.ClientCommand;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
@ -39,7 +39,7 @@ public class StatisticsCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
if (session == null) return; if (session == null) return;
session.setWaitingForStatistics(true); session.setWaitingForStatistics(true);

Datei anzeigen

@ -27,7 +27,7 @@ package org.geysermc.geyser.command.defaults;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
@ -46,9 +46,9 @@ public class StopCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
if (!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE) { if (!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE) {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale())); sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.locale()));
return; return;
} }

Datei anzeigen

@ -28,7 +28,7 @@ package org.geysermc.geyser.command.defaults;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.network.MinecraftProtocol; import org.geysermc.geyser.network.MinecraftProtocol;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
@ -54,7 +54,7 @@ public class VersionCommand extends GeyserCommand {
} }
@Override @Override
public void execute(GeyserSession session, CommandSender sender, String[] args) { public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
String bedrockVersions; String bedrockVersions;
List<BedrockPacketCodec> supportedCodecs = MinecraftProtocol.SUPPORTED_BEDROCK_CODECS; List<BedrockPacketCodec> supportedCodecs = MinecraftProtocol.SUPPORTED_BEDROCK_CODECS;
if (supportedCodecs.size() > 1) { if (supportedCodecs.size() > 1) {
@ -70,12 +70,12 @@ public class VersionCommand extends GeyserCommand {
javaVersions = supportedJavaVersions.get(0); javaVersions = supportedJavaVersions.get(0);
} }
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.version", sender.getLocale(), sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.version", sender.locale(),
GeyserImpl.NAME, GeyserImpl.VERSION, javaVersions, bedrockVersions)); GeyserImpl.NAME, GeyserImpl.VERSION, javaVersions, bedrockVersions));
// Disable update checking in dev mode and for players in Geyser Standalone // Disable update checking in dev mode and for players in Geyser Standalone
if (GeyserImpl.getInstance().productionEnvironment() && !(!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE)) { if (GeyserImpl.getInstance().productionEnvironment() && !(!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE)) {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.checking", sender.getLocale())); sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.checking", sender.locale()));
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("git.properties")) { try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("git.properties")) {
Properties gitProp = new Properties(); Properties gitProp = new Properties();
gitProp.load(stream); gitProp.load(stream);
@ -86,17 +86,17 @@ public class VersionCommand extends GeyserCommand {
int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?(/)?buildNumber>", "").trim()); int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?(/)?buildNumber>", "").trim());
int buildNum = Integer.parseInt(gitProp.getProperty("git.build.number")); int buildNum = Integer.parseInt(gitProp.getProperty("git.build.number"));
if (latestBuildNum == buildNum) { if (latestBuildNum == buildNum) {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.no_updates", sender.getLocale())); sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.no_updates", sender.locale()));
} else { } else {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.outdated", sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.outdated",
sender.getLocale(), (latestBuildNum - buildNum), "https://ci.geysermc.org/")); sender.locale(), (latestBuildNum - buildNum), "https://ci.geysermc.org/"));
} }
} else { } else {
throw new AssertionError("buildNumber missing"); throw new AssertionError("buildNumber missing");
} }
} catch (IOException | AssertionError | NumberFormatException e) { } catch (IOException | AssertionError | NumberFormatException e) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.version.failed"), e); GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.version.failed"), e);
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.version.failed", sender.getLocale())); sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.version.failed", sender.locale()));
} }
} }
} }

Datei anzeigen

@ -356,7 +356,7 @@ public class Entity {
public void setDisplayName(EntityMetadata<Optional<Component>, ?> entityMetadata) { public void setDisplayName(EntityMetadata<Optional<Component>, ?> entityMetadata) {
Optional<Component> name = entityMetadata.getValue(); Optional<Component> name = entityMetadata.getValue();
if (name.isPresent()) { if (name.isPresent()) {
nametag = MessageTranslator.convertMessage(name.get(), session.getLocale()); nametag = MessageTranslator.convertMessage(name.get(), session.locale());
dirtyMetadata.put(EntityData.NAMETAG, nametag); dirtyMetadata.put(EntityData.NAMETAG, nametag);
} else if (!nametag.isEmpty()) { } else if (!nametag.isEmpty()) {
// Clear nametag // Clear nametag

Datei anzeigen

@ -25,6 +25,7 @@
package org.geysermc.geyser.event; package org.geysermc.geyser.event;
import net.kyori.event.EventSubscriber;
import net.kyori.event.SimpleEventBus; import net.kyori.event.SimpleEventBus;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.event.Event; import org.geysermc.geyser.api.event.Event;
@ -37,17 +38,12 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class GeyserEventBus implements EventBus { public class GeyserEventBus implements EventBus {
private final SimpleEventBus<Event> bus = new SimpleEventBus<>(Event.class); private final SimpleEventBus<Event> bus = new SimpleEventBus<>(Event.class);
@NonNull
@Override
public <T extends Event> EventSubscription<T> subscribe(@NonNull Class<T> eventClass, @NonNull Consumer<? super T> consumer) {
return this.subscribe(eventClass, consumer, null, Subscribe.Priority.NORMAL);
}
@NonNull @NonNull
@Override @Override
public <T extends Event> EventSubscription<T> subscribe(@NonNull Extension extension, @NonNull Class<T> eventClass, @NonNull Consumer<? super T> consumer) { public <T extends Event> EventSubscription<T> subscribe(@NonNull Extension extension, @NonNull Class<T> eventClass, @NonNull Consumer<? super T> consumer) {
@ -86,6 +82,11 @@ public class GeyserEventBus implements EventBus {
} }
} }
@Override
public void unregisterAll(@NonNull Extension extension) {
this.bus.unregister((Predicate<EventSubscriber<?>>) subscriber -> extension.equals(((GeyserEventSubscription<?>) subscriber).owner()));
}
@Override @Override
public boolean fire(@NonNull Event event) { public boolean fire(@NonNull Event event) {
return this.bus.post(event).wasSuccessful(); return this.bus.post(event).wasSuccessful();

Datei anzeigen

@ -29,6 +29,7 @@ import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.geysermc.geyser.api.event.ExtensionEventBus;
import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.extension.Extension;
import org.geysermc.geyser.api.extension.ExtensionDescription; import org.geysermc.geyser.api.extension.ExtensionDescription;
import org.geysermc.geyser.api.extension.ExtensionLoader; import org.geysermc.geyser.api.extension.ExtensionLoader;
@ -45,6 +46,7 @@ public class GeyserExtensionContainer {
private final ExtensionDescription description; private final ExtensionDescription description;
private final ExtensionLoader loader; private final ExtensionLoader loader;
private final ExtensionLogger logger; private final ExtensionLogger logger;
private final ExtensionEventBus eventBus;
@Getter(AccessLevel.NONE) protected boolean enabled; @Getter(AccessLevel.NONE) protected boolean enabled;
} }

Datei anzeigen

@ -28,6 +28,7 @@ package org.geysermc.geyser.extension;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.event.ExtensionEventBus;
import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.extension.Extension;
import org.geysermc.geyser.api.extension.ExtensionDescription; import org.geysermc.geyser.api.extension.ExtensionDescription;
import org.geysermc.geyser.api.extension.ExtensionLoader; import org.geysermc.geyser.api.extension.ExtensionLoader;
@ -35,6 +36,7 @@ import org.geysermc.geyser.api.extension.ExtensionLogger;
import org.geysermc.geyser.api.extension.ExtensionManager; import org.geysermc.geyser.api.extension.ExtensionManager;
import org.geysermc.geyser.api.extension.exception.InvalidDescriptionException; import org.geysermc.geyser.api.extension.exception.InvalidDescriptionException;
import org.geysermc.geyser.api.extension.exception.InvalidExtensionException; import org.geysermc.geyser.api.extension.exception.InvalidExtensionException;
import org.geysermc.geyser.extension.event.GeyserExtensionEventBus;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;
import java.io.IOException; import java.io.IOException;
@ -83,12 +85,12 @@ public class GeyserExtensionLoader extends ExtensionLoader {
} }
this.classLoaders.put(description.name(), loader); this.classLoaders.put(description.name(), loader);
return this.setup(loader.extension(), description, dataFolder); return this.setup(loader.extension(), description, dataFolder, new GeyserExtensionEventBus(GeyserImpl.getInstance().eventBus(), loader.extension()));
} }
private GeyserExtensionContainer setup(Extension extension, GeyserExtensionDescription description, Path dataFolder) { private GeyserExtensionContainer setup(Extension extension, GeyserExtensionDescription description, Path dataFolder, ExtensionEventBus eventBus) {
GeyserExtensionLogger logger = new GeyserExtensionLogger(GeyserImpl.getInstance().getLogger(), description.name()); GeyserExtensionLogger logger = new GeyserExtensionLogger(GeyserImpl.getInstance().getLogger(), description.name());
GeyserExtensionContainer container = new GeyserExtensionContainer(extension, dataFolder, description, this, logger); GeyserExtensionContainer container = new GeyserExtensionContainer(extension, dataFolder, description, this, logger, eventBus);
extension.onLoad(); extension.onLoad();
return container; return container;
} }
@ -246,6 +248,12 @@ public class GeyserExtensionLoader extends ExtensionLoader {
return this.extensionContainers.get(extension).description(); return this.extensionContainers.get(extension).description();
} }
@NonNull
@Override
protected ExtensionEventBus eventBus(@NonNull Extension extension) {
return this.extensionContainers.get(extension).eventBus();
}
@NonNull @NonNull
@Override @Override
protected ExtensionLogger logger(@NonNull Extension extension) { protected ExtensionLogger logger(@NonNull Extension extension) {

Datei anzeigen

@ -90,15 +90,18 @@ public class GeyserExtensionManager extends ExtensionManager {
public void enableExtension(Extension extension) { public void enableExtension(Extension extension) {
if (!extension.isEnabled()) { if (!extension.isEnabled()) {
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.enable.success", extension.description().name()));
extension.setEnabled(true); extension.setEnabled(true);
GeyserImpl.getInstance().eventBus().register(extension, extension);
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.enable.success", extension.description().name()));
} }
} }
private void disableExtension(@NonNull Extension extension) { private void disableExtension(@NonNull Extension extension) {
if (extension.isEnabled()) { if (extension.isEnabled()) {
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.disable.success", extension.description().name())); GeyserImpl.getInstance().eventBus().unregisterAll(extension);
extension.setEnabled(false); extension.setEnabled(false);
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.disable.success", extension.description().name()));
} }
} }

Datei anzeigen

@ -0,0 +1,87 @@
/*
* 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.extension.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.event.Event;
import org.geysermc.geyser.api.event.EventBus;
import org.geysermc.geyser.api.event.EventSubscription;
import org.geysermc.geyser.api.event.ExtensionEventBus;
import org.geysermc.geyser.api.extension.Extension;
import java.util.Set;
import java.util.function.Consumer;
public record GeyserExtensionEventBus(EventBus eventBus,
Extension extension) implements ExtensionEventBus {
@NonNull
@Override
public <T extends Event> EventSubscription<T> subscribe(@NonNull Class<T> eventClass, @NonNull Consumer<? super T> consumer) {
return this.eventBus.subscribe(this.extension, eventClass, consumer);
}
@Override
public void register(@NonNull Object eventHolder) {
this.eventBus.register(this.extension, eventHolder);
}
@Override
public void unregisterAll() {
this.eventBus.unregisterAll(this.extension);
}
@NonNull
@Override
public <T extends Event> EventSubscription<T> subscribe(@NonNull Extension extension, @NonNull Class<T> eventClass, @NonNull Consumer<? super T> consumer) {
return this.eventBus.subscribe(extension, eventClass, consumer);
}
@Override
public <T extends Event> void unsubscribe(@NonNull EventSubscription<T> subscription) {
this.eventBus.unsubscribe(subscription);
}
@Override
public void register(@NonNull Extension extension, @NonNull Object eventHolder) {
this.eventBus.register(extension, eventHolder);
}
@Override
public void unregisterAll(@NonNull Extension extension) {
this.eventBus.unregisterAll(extension);
}
@Override
public boolean fire(@NonNull Event event) {
return this.eventBus.fire(event);
}
@NonNull
@Override
public <T extends Event> Set<EventSubscription<T>> subscriptions(@NonNull Class<T> eventClass) {
return this.eventBus.subscriptions(eventClass);
}
}

Datei anzeigen

@ -115,7 +115,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater {
// Changing the item in the input slot resets the name field on Bedrock, but // Changing the item in the input slot resets the name field on Bedrock, but
// does not result in a FilterTextPacket // does not result in a FilterTextPacket
String originalName = MessageTranslator.convertToPlainText(ItemUtils.getCustomName(input.getNbt()), session.getLocale()); String originalName = MessageTranslator.convertToPlainText(ItemUtils.getCustomName(input.getNbt()), session.locale());
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName); ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName);
session.sendDownstreamPacket(renameItemPacket); session.sendDownstreamPacket(renameItemPacket);
@ -427,7 +427,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater {
String originalName = ItemUtils.getCustomName(anvilContainer.getInput().getNbt()); String originalName = ItemUtils.getCustomName(anvilContainer.getInput().getNbt());
if (bedrock && originalName != null && anvilContainer.getNewName() != null) { if (bedrock && originalName != null && anvilContainer.getNewName() != null) {
// Check text and formatting // Check text and formatting
String legacyOriginalName = MessageTranslator.convertMessageLenient(originalName, session.getLocale()); String legacyOriginalName = MessageTranslator.convertMessageLenient(originalName, session.locale());
return !legacyOriginalName.equals(anvilContainer.getNewName()); return !legacyOriginalName.equals(anvilContainer.getNewName());
} }
return !Objects.equals(originalName, ItemUtils.getCustomName(anvilContainer.getResult().getNbt())); return !Objects.equals(originalName, ItemUtils.getCustomName(anvilContainer.getResult().getNbt()));

Datei anzeigen

@ -112,7 +112,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
resourcePacksInfo.setForcedToAccept(GeyserImpl.getInstance().getConfig().isForceResourcePacks()); resourcePacksInfo.setForcedToAccept(GeyserImpl.getInstance().getConfig().isForceResourcePacks());
session.sendUpstreamPacket(resourcePacksInfo); session.sendUpstreamPacket(resourcePacksInfo);
GeyserLocale.loadGeyserLocale(session.getLocale()); GeyserLocale.loadGeyserLocale(session.locale());
return true; return true;
} }
@ -208,7 +208,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
if (session.isLoggingIn()) { if (session.isLoggingIn()) {
SetTitlePacket titlePacket = new SetTitlePacket(); SetTitlePacket titlePacket = new SetTitlePacket();
titlePacket.setType(SetTitlePacket.Type.ACTIONBAR); titlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
titlePacket.setText(GeyserLocale.getPlayerLocaleString("geyser.auth.login.wait", session.getLocale())); titlePacket.setText(GeyserLocale.getPlayerLocaleString("geyser.auth.login.wait", session.locale()));
titlePacket.setFadeInTime(0); titlePacket.setFadeInTime(0);
titlePacket.setFadeOutTime(1); titlePacket.setFadeOutTime(1);
titlePacket.setStayTime(2); titlePacket.setStayTime(2);

Datei anzeigen

@ -79,7 +79,7 @@ import org.geysermc.floodgate.util.BedrockData;
import org.geysermc.geyser.Constants; import org.geysermc.geyser.Constants;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.command.CommandSender; import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.configuration.EmoteOffhandWorkaroundOption; import org.geysermc.geyser.configuration.EmoteOffhandWorkaroundOption;
import org.geysermc.geyser.entity.InteractiveTagManager; import org.geysermc.geyser.entity.InteractiveTagManager;
import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
@ -122,7 +122,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@Getter @Getter
public class GeyserSession implements GeyserConnection, CommandSender { public class GeyserSession implements GeyserConnection, GeyserCommandSource {
private final GeyserImpl geyser; private final GeyserImpl geyser;
private final UpstreamSession upstream; private final UpstreamSession upstream;
@ -876,7 +876,7 @@ public class GeyserSession implements GeyserConnection, CommandSender {
if (cause instanceof UnexpectedEncryptionException) { if (cause instanceof UnexpectedEncryptionException) {
if (remoteAuthType != AuthType.FLOODGATE) { if (remoteAuthType != AuthType.FLOODGATE) {
// Server expects online mode // Server expects online mode
disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.authentication_type_mismatch", getLocale()); disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.authentication_type_mismatch", locale());
// Explain that they may be looking for Floodgate. // Explain that they may be looking for Floodgate.
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog( geyser.getLogger().warning(GeyserLocale.getLocaleStringLog(
geyser.getPlatformType() == PlatformType.STANDALONE ? geyser.getPlatformType() == PlatformType.STANDALONE ?
@ -886,14 +886,14 @@ public class GeyserSession implements GeyserConnection, CommandSender {
)); ));
} else { } else {
// Likely that Floodgate is not configured correctly. // Likely that Floodgate is not configured correctly.
disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.floodgate_login_error", getLocale()); disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.floodgate_login_error", locale());
if (geyser.getPlatformType() == PlatformType.STANDALONE) { if (geyser.getPlatformType() == PlatformType.STANDALONE) {
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.remote.floodgate_login_error_standalone")); geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.remote.floodgate_login_error_standalone"));
} }
} }
} else if (cause instanceof ConnectException) { } else if (cause instanceof ConnectException) {
// Server is offline, probably // Server is offline, probably
disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.server_offline", getLocale()); disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.server_offline", locale());
} else { } else {
disconnectMessage = MessageTranslator.convertMessageLenient(event.getReason()); disconnectMessage = MessageTranslator.convertMessageLenient(event.getReason());
} }
@ -1156,7 +1156,7 @@ public class GeyserSession implements GeyserConnection, CommandSender {
} }
@Override @Override
public String getLocale() { public String locale() {
return clientData.getLanguageCode(); return clientData.getLanguageCode();
} }

Datei anzeigen

@ -80,7 +80,7 @@ public final class SessionManager {
public void disconnectAll(String message) { public void disconnectAll(String message) {
Collection<GeyserSession> sessions = getAllSessions(); Collection<GeyserSession> sessions = getAllSessions();
for (GeyserSession session : sessions) { for (GeyserSession session : sessions) {
session.disconnect(GeyserLocale.getPlayerLocaleString(message, session.getLocale())); session.disconnect(GeyserLocale.getPlayerLocaleString(message, session.locale()));
} }
} }

Datei anzeigen

@ -72,14 +72,14 @@ public class AdvancementsCache {
public void buildAndShowMenuForm() { public void buildAndShowMenuForm() {
SimpleForm.Builder builder = SimpleForm.Builder builder =
SimpleForm.builder() SimpleForm.builder()
.translator(MinecraftLocale::getLocaleString, session.getLocale()) .translator(MinecraftLocale::getLocaleString, session.locale())
.title("gui.advancements"); .title("gui.advancements");
boolean hasAdvancements = false; boolean hasAdvancements = false;
for (Map.Entry<String, GeyserAdvancement> advancement : storedAdvancements.entrySet()) { for (Map.Entry<String, GeyserAdvancement> advancement : storedAdvancements.entrySet()) {
if (advancement.getValue().getParentId() == null) { // No parent means this is a root advancement if (advancement.getValue().getParentId() == null) { // No parent means this is a root advancement
hasAdvancements = true; hasAdvancements = true;
builder.button(MessageTranslator.convertMessage(advancement.getValue().getDisplayData().getTitle(), session.getLocale())); builder.button(MessageTranslator.convertMessage(advancement.getValue().getDisplayData().getTitle(), session.locale()));
} }
} }
@ -128,7 +128,7 @@ public class AdvancementsCache {
*/ */
public void buildAndShowListForm() { public void buildAndShowListForm() {
GeyserAdvancement categoryAdvancement = storedAdvancements.get(currentAdvancementCategoryId); GeyserAdvancement categoryAdvancement = storedAdvancements.get(currentAdvancementCategoryId);
String language = session.getLocale(); String language = session.locale();
SimpleForm.Builder builder = SimpleForm.Builder builder =
SimpleForm.builder() SimpleForm.builder()
@ -190,7 +190,7 @@ public class AdvancementsCache {
*/ */
public void buildAndShowInfoForm(GeyserAdvancement advancement) { public void buildAndShowInfoForm(GeyserAdvancement advancement) {
// Cache language for easier access // Cache language for easier access
String language = session.getLocale(); String language = session.locale();
String earned = isEarned(advancement) ? "yes" : "no"; String earned = isEarned(advancement) ? "yes" : "no";

Datei anzeigen

@ -57,7 +57,7 @@ public class BossBar {
BossEventPacket bossEventPacket = new BossEventPacket(); BossEventPacket bossEventPacket = new BossEventPacket();
bossEventPacket.setBossUniqueEntityId(entityId); bossEventPacket.setBossUniqueEntityId(entityId);
bossEventPacket.setAction(BossEventPacket.Action.CREATE); bossEventPacket.setAction(BossEventPacket.Action.CREATE);
bossEventPacket.setTitle(MessageTranslator.convertMessage(title, session.getLocale())); bossEventPacket.setTitle(MessageTranslator.convertMessage(title, session.locale()));
bossEventPacket.setHealthPercentage(health); bossEventPacket.setHealthPercentage(health);
bossEventPacket.setColor(color); bossEventPacket.setColor(color);
bossEventPacket.setOverlay(overlay); bossEventPacket.setOverlay(overlay);
@ -71,7 +71,7 @@ public class BossBar {
BossEventPacket bossEventPacket = new BossEventPacket(); BossEventPacket bossEventPacket = new BossEventPacket();
bossEventPacket.setBossUniqueEntityId(entityId); bossEventPacket.setBossUniqueEntityId(entityId);
bossEventPacket.setAction(BossEventPacket.Action.UPDATE_NAME); bossEventPacket.setAction(BossEventPacket.Action.UPDATE_NAME);
bossEventPacket.setTitle(MessageTranslator.convertMessage(title, session.getLocale())); bossEventPacket.setTitle(MessageTranslator.convertMessage(title, session.locale()));
session.sendUpstreamPacket(bossEventPacket); session.sendUpstreamPacket(bossEventPacket);
} }

Datei anzeigen

@ -157,7 +157,7 @@ public abstract class ItemTranslator {
nbt = translateDisplayProperties(session, nbt, bedrockItem); nbt = translateDisplayProperties(session, nbt, bedrockItem);
if (session.isAdvancedTooltips()) { if (session.isAdvancedTooltips()) {
nbt = addAdvancedTooltips(nbt, session.getItemMappings().getMapping(stack), session.getLocale()); nbt = addAdvancedTooltips(nbt, session.getItemMappings().getMapping(stack), session.locale());
} }
ItemStack itemStack = new ItemStack(stack.getId(), stack.getAmount(), nbt); ItemStack itemStack = new ItemStack(stack.getId(), stack.getAmount(), nbt);
@ -474,7 +474,7 @@ public abstract class ItemTranslator {
String name = ((StringTag) display.get("Name")).getValue(); String name = ((StringTag) display.get("Name")).getValue();
// Get the translated name and prefix it with a reset char // Get the translated name and prefix it with a reset char
name = MessageTranslator.convertMessageLenient(name, session.getLocale()); name = MessageTranslator.convertMessageLenient(name, session.locale());
// Add the new name tag // Add the new name tag
display.put(new StringTag("Name", name)); display.put(new StringTag("Name", name));
@ -500,7 +500,7 @@ public abstract class ItemTranslator {
String translationKey = mapping.getTranslationString(); String translationKey = mapping.getTranslationString();
// Reset formatting since Bedrock defaults to italics // Reset formatting since Bedrock defaults to italics
display.put(new StringTag("Name", "§r§" + translationColor + MinecraftLocale.getLocaleString(translationKey, session.getLocale()))); display.put(new StringTag("Name", "§r§" + translationColor + MinecraftLocale.getLocaleString(translationKey, session.locale())));
} }
return tag; return tag;

Datei anzeigen

@ -42,7 +42,7 @@ public class AxolotlBucketTranslator extends NbtItemStackTranslator {
// Bedrock Edition displays the properties of the axolotl. Java does not. // Bedrock Edition displays the properties of the axolotl. Java does not.
// To work around this, set the custom name to the Axolotl translation and it's displayed correctly // To work around this, set the custom name to the Axolotl translation and it's displayed correctly
itemTag.put(new ByteTag("AppendCustomName", (byte) 1)); itemTag.put(new ByteTag("AppendCustomName", (byte) 1));
itemTag.put(new StringTag("CustomName", MinecraftLocale.getLocaleString("entity.minecraft.axolotl", session.getLocale()))); itemTag.put(new StringTag("CustomName", MinecraftLocale.getLocaleString("entity.minecraft.axolotl", session.locale())));
// Boilerplate required so the nametag does not appear as "Bucket of " // Boilerplate required so the nametag does not appear as "Bucket of "
itemTag.put(new StringTag("ColorID", "")); itemTag.put(new StringTag("ColorID", ""));
itemTag.put(new StringTag("BodyID", "")); itemTag.put(new StringTag("BodyID", ""));

Datei anzeigen

@ -61,7 +61,7 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
List<Tag> lore = new ArrayList<>(); List<Tag> lore = new ArrayList<>();
for (Tag tag : listTag.getValue()) { for (Tag tag : listTag.getValue()) {
if (!(tag instanceof StringTag)) continue; if (!(tag instanceof StringTag)) continue;
lore.add(new StringTag("", MessageTranslator.convertMessageLenient(((StringTag) tag).getValue(), session.getLocale()))); lore.add(new StringTag("", MessageTranslator.convertMessageLenient(((StringTag) tag).getValue(), session.locale())));
} }
displayTag.put(new ListTag("Lore", lore)); displayTag.put(new ListTag("Lore", lore));
} }

Datei anzeigen

@ -56,7 +56,7 @@ public class PlayerHeadTranslator extends NbtItemStackTranslator {
} }
// Add correct name of player skull // Add correct name of player skull
// TODO: It's always yellow, even with a custom name. Handle? // TODO: It's always yellow, even with a custom name. Handle?
String displayName = "\u00a7r\u00a7e" + MinecraftLocale.getLocaleString("block.minecraft.player_head.named", session.getLocale()).replace("%s", name.getValue()); String displayName = "\u00a7r\u00a7e" + MinecraftLocale.getLocaleString("block.minecraft.player_head.named", session.locale()).replace("%s", name.getValue());
if (!itemTag.contains("display")) { if (!itemTag.contains("display")) {
itemTag.put(new CompoundTag("display")); itemTag.put(new CompoundTag("display"));
} }

Datei anzeigen

@ -50,7 +50,7 @@ public class TropicalFishBucketTranslator extends NbtItemStackTranslator {
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) { public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
// Prevent name from appearing as "Bucket of" // Prevent name from appearing as "Bucket of"
itemTag.put(new ByteTag("AppendCustomName", (byte) 1)); itemTag.put(new ByteTag("AppendCustomName", (byte) 1));
itemTag.put(new StringTag("CustomName", MinecraftLocale.getLocaleString("entity.minecraft.tropical_fish", session.getLocale()))); itemTag.put(new StringTag("CustomName", MinecraftLocale.getLocaleString("entity.minecraft.tropical_fish", session.locale())));
// Add Java's client side lore tag // Add Java's client side lore tag
Tag bucketVariantTag = itemTag.get("BucketVariantTag"); Tag bucketVariantTag = itemTag.get("BucketVariantTag");
if (bucketVariantTag instanceof IntTag) { if (bucketVariantTag instanceof IntTag) {
@ -66,10 +66,10 @@ public class TropicalFishBucketTranslator extends NbtItemStackTranslator {
int predefinedVariantId = TropicalFishEntity.getPredefinedId(varNumber); int predefinedVariantId = TropicalFishEntity.getPredefinedId(varNumber);
if (predefinedVariantId != -1) { if (predefinedVariantId != -1) {
Component tooltip = Component.translatable("entity.minecraft.tropical_fish.predefined." + predefinedVariantId, LORE_STYLE); Component tooltip = Component.translatable("entity.minecraft.tropical_fish.predefined." + predefinedVariantId, LORE_STYLE);
lore.add(0, new StringTag("", MessageTranslator.convertMessage(tooltip, session.getLocale()))); lore.add(0, new StringTag("", MessageTranslator.convertMessage(tooltip, session.locale())));
} else { } else {
Component typeTooltip = Component.translatable("entity.minecraft.tropical_fish.type." + TropicalFishEntity.getVariantName(varNumber), LORE_STYLE); Component typeTooltip = Component.translatable("entity.minecraft.tropical_fish.type." + TropicalFishEntity.getVariantName(varNumber), LORE_STYLE);
lore.add(0, new StringTag("", MessageTranslator.convertMessage(typeTooltip, session.getLocale()))); lore.add(0, new StringTag("", MessageTranslator.convertMessage(typeTooltip, session.locale())));
byte baseColor = TropicalFishEntity.getBaseColor(varNumber); byte baseColor = TropicalFishEntity.getBaseColor(varNumber);
byte patternColor = TropicalFishEntity.getPatternColor(varNumber); byte patternColor = TropicalFishEntity.getPatternColor(varNumber);
@ -78,7 +78,7 @@ public class TropicalFishBucketTranslator extends NbtItemStackTranslator {
colorTooltip = colorTooltip.append(Component.text(", ", LORE_STYLE)) colorTooltip = colorTooltip.append(Component.text(", ", LORE_STYLE))
.append(Component.translatable("color.minecraft." + TropicalFishEntity.getColorName(patternColor), LORE_STYLE)); .append(Component.translatable("color.minecraft." + TropicalFishEntity.getColorName(patternColor), LORE_STYLE));
} }
lore.add(1, new StringTag("", MessageTranslator.convertMessage(colorTooltip, session.getLocale()))); lore.add(1, new StringTag("", MessageTranslator.convertMessage(colorTooltip, session.locale())));
} }
ListTag loreTag = displayTag.get("Lore"); ListTag loreTag = displayTag.get("Lore");

Datei anzeigen

@ -27,7 +27,7 @@ package org.geysermc.geyser.translator.protocol.bedrock;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
@ -42,7 +42,7 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
@Override @Override
public void translate(GeyserSession session, CommandRequestPacket packet) { public void translate(GeyserSession session, CommandRequestPacket packet) {
String command = packet.getCommand().replace("/", ""); String command = packet.getCommand().replace("/", "");
CommandManager commandManager = GeyserImpl.getInstance().getCommandManager(); GeyserCommandManager commandManager = GeyserImpl.getInstance().commandManager();
if (session.getGeyser().getPlatformType() == PlatformType.STANDALONE && command.trim().startsWith("geyser ") && commandManager.getCommands().containsKey(command.split(" ")[1])) { if (session.getGeyser().getPlatformType() == PlatformType.STANDALONE && command.trim().startsWith("geyser ") && commandManager.getCommands().containsKey(command.split(" ")[1])) {
commandManager.runCommand(session, command); commandManager.runCommand(session, command);
} else { } else {

Datei anzeigen

@ -54,8 +54,8 @@ public class BedrockFilterTextTranslator extends PacketTranslator<FilterTextPack
String originalName = ItemUtils.getCustomName(anvilContainer.getInput().getNbt()); String originalName = ItemUtils.getCustomName(anvilContainer.getInput().getNbt());
String plainOriginalName = MessageTranslator.convertToPlainText(originalName, session.getLocale()); String plainOriginalName = MessageTranslator.convertToPlainText(originalName, session.locale());
String plainNewName = MessageTranslator.convertToPlainText(packet.getText(), session.getLocale()); String plainNewName = MessageTranslator.convertToPlainText(packet.getText(), session.locale());
if (!plainOriginalName.equals(plainNewName)) { if (!plainOriginalName.equals(plainNewName)) {
// Strip out formatting since Java Edition does not allow it // Strip out formatting since Java Edition does not allow it
packet.setText(plainNewName); packet.setText(plainNewName);

Datei anzeigen

@ -49,7 +49,7 @@ public class JavaChatTranslator extends PacketTranslator<ClientboundChatPacket>
}); });
textPacket.setNeedsTranslation(false); textPacket.setNeedsTranslation(false);
textPacket.setMessage(MessageTranslator.convertMessage(packet.getMessage(), session.getLocale())); textPacket.setMessage(MessageTranslator.convertMessage(packet.getMessage(), session.locale()));
session.sendUpstreamPacket(textPacket); session.sendUpstreamPacket(textPacket);
} }

Datei anzeigen

@ -43,7 +43,8 @@ import lombok.Getter;
import lombok.ToString; import lombok.ToString;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandManager; import org.geysermc.geyser.api.event.downstream.ServerDefineCommandsEvent;
import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
@ -112,7 +113,7 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
return; return;
} }
CommandManager manager = session.getGeyser().getCommandManager(); GeyserCommandManager manager = session.getGeyser().commandManager();
CommandNode[] nodes = packet.getNodes(); CommandNode[] nodes = packet.getNodes();
List<CommandData> commandData = new ArrayList<>(); List<CommandData> commandData = new ArrayList<>();
IntSet commandNodes = new IntOpenHashSet(); IntSet commandNodes = new IntOpenHashSet();
@ -141,15 +142,20 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
CommandParamData[][] params = getParams(session, nodes[nodeIndex], nodes); CommandParamData[][] params = getParams(session, nodes[nodeIndex], nodes);
// Insert the alias name into the command list // Insert the alias name into the command list
commands.computeIfAbsent(new BedrockCommandInfo(manager.getDescription(node.getName().toLowerCase(Locale.ROOT)), params), commands.computeIfAbsent(new BedrockCommandInfo(node.getName().toLowerCase(Locale.ROOT), manager.description(node.getName().toLowerCase(Locale.ROOT)), params),
index -> new HashSet<>()).add(node.getName().toLowerCase()); index -> new HashSet<>()).add(node.getName().toLowerCase());
} }
ServerDefineCommandsEvent event = new ServerDefineCommandsEvent(session, commands.keySet());
session.getGeyser().eventBus().fire(event);
if (event.isCancelled()) {
return;
}
// The command flags, not sure what these do apart from break things // The command flags, not sure what these do apart from break things
List<CommandData.Flag> flags = Collections.emptyList(); List<CommandData.Flag> flags = Collections.emptyList();
// Loop through all the found commands // Loop through all the found commands
for (Map.Entry<BedrockCommandInfo, Set<String>> entry : commands.entrySet()) { for (Map.Entry<BedrockCommandInfo, Set<String>> entry : commands.entrySet()) {
String commandName = entry.getValue().iterator().next(); // We know this has a value String commandName = entry.getValue().iterator().next(); // We know this has a value
@ -236,7 +242,7 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
/** /**
* Stores the command description and parameter data for best optimizing the Bedrock commands packet. * Stores the command description and parameter data for best optimizing the Bedrock commands packet.
*/ */
private static record BedrockCommandInfo(String description, CommandParamData[][] paramData) { private static record BedrockCommandInfo(String name, String description, CommandParamData[][] paramData) implements ServerDefineCommandsEvent.CommandInfo {
} }
@Getter @Getter

Datei anzeigen

@ -36,7 +36,7 @@ public class JavaDisconnectTranslator extends PacketTranslator<ClientboundDiscon
@Override @Override
public void translate(GeyserSession session, ClientboundDisconnectPacket packet) { public void translate(GeyserSession session, ClientboundDisconnectPacket packet) {
session.disconnect(MessageTranslator.convertMessage(packet.getReason(), session.getLocale())); session.disconnect(MessageTranslator.convertMessage(packet.getReason(), session.locale()));
} }
@Override @Override

Datei anzeigen

@ -37,7 +37,7 @@ public class JavaLoginDisconnectTranslator extends PacketTranslator<ClientboundL
@Override @Override
public void translate(GeyserSession session, ClientboundLoginDisconnectPacket packet) { public void translate(GeyserSession session, ClientboundLoginDisconnectPacket packet) {
// The client doesn't manually get disconnected so we have to do it ourselves // The client doesn't manually get disconnected so we have to do it ourselves
session.disconnect(MessageTranslator.convertMessage(packet.getReason(), session.getLocale())); session.disconnect(MessageTranslator.convertMessage(packet.getReason(), session.locale()));
} }
@Override @Override

Datei anzeigen

@ -102,7 +102,7 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
session.setRenderDistance(packet.getViewDistance()); session.setRenderDistance(packet.getViewDistance());
// We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc // We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc
String locale = session.getLocale(); String locale = session.locale();
// TODO customize // TODO customize
ServerboundClientInformationPacket infoPacket = new ServerboundClientInformationPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, SKIN_PART_VALUES, HandPreference.RIGHT_HAND, false, true); ServerboundClientInformationPacket infoPacket = new ServerboundClientInformationPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, SKIN_PART_VALUES, HandPreference.RIGHT_HAND, false, true);
session.sendDownstreamPacket(infoPacket); session.sendDownstreamPacket(infoPacket);

Datei anzeigen

@ -84,13 +84,13 @@ public class JavaUpdateAdvancementsTranslator extends PacketTranslator<Clientbou
// Java uses some pink color for toast challenge completes // Java uses some pink color for toast challenge completes
String color = advancement.getDisplayData().getFrameType() == Advancement.DisplayData.FrameType.CHALLENGE ? String color = advancement.getDisplayData().getFrameType() == Advancement.DisplayData.FrameType.CHALLENGE ?
"§d" : "§a"; "§d" : "§a";
String advancementName = MessageTranslator.convertMessage(advancement.getDisplayData().getTitle(), session.getLocale()); String advancementName = MessageTranslator.convertMessage(advancement.getDisplayData().getTitle(), session.locale());
// Send an action bar message stating they earned an achievement // Send an action bar message stating they earned an achievement
// Sent for instances where broadcasting advancements through chat are disabled // Sent for instances where broadcasting advancements through chat are disabled
SetTitlePacket titlePacket = new SetTitlePacket(); SetTitlePacket titlePacket = new SetTitlePacket();
titlePacket.setText(color + "[" + MinecraftLocale.getLocaleString("advancements.toast." + titlePacket.setText(color + "[" + MinecraftLocale.getLocaleString("advancements.toast." +
advancement.getDisplayData().getFrameType().toString().toLowerCase(), session.getLocale()) + "]§f " + advancementName); advancement.getDisplayData().getFrameType().toString().toLowerCase(), session.locale()) + "]§f " + advancementName);
titlePacket.setType(SetTitlePacket.Type.ACTIONBAR); titlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
titlePacket.setFadeOutTime(3); titlePacket.setFadeOutTime(3);
titlePacket.setFadeInTime(3); titlePacket.setFadeInTime(3);

Datei anzeigen

@ -57,8 +57,8 @@ public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenSc
return; return;
} }
String name = MessageTranslator.convertMessageLenient(packet.getName(), session.getLocale()); String name = MessageTranslator.convertMessageLenient(packet.getName(), session.locale());
name = MinecraftLocale.getLocaleString(name, session.getLocale()); name = MinecraftLocale.getLocaleString(name, session.locale());
Inventory newInventory = newTranslator.createInventory(name, packet.getContainerId(), packet.getType(), session.getPlayerInventory()); Inventory newInventory = newTranslator.createInventory(name, packet.getContainerId(), packet.getType(), session.getPlayerInventory());
if (openInventory != null) { if (openInventory != null) {

Datei anzeigen

@ -153,7 +153,7 @@ public class JavaGameEventTranslator extends PacketTranslator<ClientboundGameEve
case INVALID_BED: case INVALID_BED:
// Not sent as a proper message? Odd. // Not sent as a proper message? Odd.
session.sendMessage(MinecraftLocale.getLocaleString("block.minecraft.spawn.not_valid", session.sendMessage(MinecraftLocale.getLocaleString("block.minecraft.spawn.not_valid",
session.getLocale())); session.locale()));
break; break;
case ARROW_HIT_PLAYER: case ARROW_HIT_PLAYER:
PlaySoundPacket arrowSoundPacket = new PlaySoundPacket(); PlaySoundPacket arrowSoundPacket = new PlaySoundPacket();

Datei anzeigen

@ -82,7 +82,7 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
textPacket.setSourceName(null); textPacket.setSourceName(null);
textPacket.setMessage("record.nowPlaying"); textPacket.setMessage("record.nowPlaying");
String recordString = "%item." + soundEvent.name().toLowerCase(Locale.ROOT) + ".desc"; String recordString = "%item." + soundEvent.name().toLowerCase(Locale.ROOT) + ".desc";
textPacket.setParameters(Collections.singletonList(MinecraftLocale.getLocaleString(recordString, session.getLocale()))); textPacket.setParameters(Collections.singletonList(MinecraftLocale.getLocaleString(recordString, session.locale())));
session.sendUpstreamPacket(textPacket); session.sendUpstreamPacket(textPacket);
} }
return; return;

Datei anzeigen

@ -67,8 +67,8 @@ public class JavaSetPlayerTeamTranslator extends PacketTranslator<ClientboundSet
.setName(MessageTranslator.convertMessage(packet.getDisplayName())) .setName(MessageTranslator.convertMessage(packet.getDisplayName()))
.setColor(packet.getColor()) .setColor(packet.getColor())
.setNameTagVisibility(packet.getNameTagVisibility()) .setNameTagVisibility(packet.getNameTagVisibility())
.setPrefix(MessageTranslator.convertMessage(packet.getPrefix(), session.getLocale())) .setPrefix(MessageTranslator.convertMessage(packet.getPrefix(), session.locale()))
.setSuffix(MessageTranslator.convertMessage(packet.getSuffix(), session.getLocale())); .setSuffix(MessageTranslator.convertMessage(packet.getSuffix(), session.locale()));
if (packet.getPlayers().length != 0) { if (packet.getPlayers().length != 0) {
if ((team.getNameTagVisibility() != NameTagVisibility.ALWAYS && !team.isVisibleFor(session.getPlayerEntity().getUsername())) if ((team.getNameTagVisibility() != NameTagVisibility.ALWAYS && !team.isVisibleFor(session.getPlayerEntity().getUsername()))
@ -98,8 +98,8 @@ public class JavaSetPlayerTeamTranslator extends PacketTranslator<ClientboundSet
team.setName(MessageTranslator.convertMessage(packet.getDisplayName())) team.setName(MessageTranslator.convertMessage(packet.getDisplayName()))
.setColor(packet.getColor()) .setColor(packet.getColor())
.setNameTagVisibility(packet.getNameTagVisibility()) .setNameTagVisibility(packet.getNameTagVisibility())
.setPrefix(MessageTranslator.convertMessage(packet.getPrefix(), session.getLocale())) .setPrefix(MessageTranslator.convertMessage(packet.getPrefix(), session.locale()))
.setSuffix(MessageTranslator.convertMessage(packet.getSuffix(), session.getLocale())) .setSuffix(MessageTranslator.convertMessage(packet.getSuffix(), session.locale()))
.setUpdateType(UpdateType.UPDATE); .setUpdateType(UpdateType.UPDATE);
if (oldVisibility != team.getNameTagVisibility() if (oldVisibility != team.getNameTagVisibility()

Datei anzeigen

@ -41,7 +41,7 @@ public class JavaSetActionBarTextTranslator extends PacketTranslator<Clientbound
if (packet.getText() == null) { //TODO 1.17 can this happen? if (packet.getText() == null) { //TODO 1.17 can this happen?
text = " "; text = " ";
} else { } else {
text = MessageTranslator.convertMessage(packet.getText(), session.getLocale()); text = MessageTranslator.convertMessage(packet.getText(), session.locale());
} }
SetTitlePacket titlePacket = new SetTitlePacket(); SetTitlePacket titlePacket = new SetTitlePacket();

Datei anzeigen

@ -41,7 +41,7 @@ public class JavaSetSubtitleTextTranslator extends PacketTranslator<ClientboundS
if (packet.getText() == null) { //TODO 1.17 can this happen? if (packet.getText() == null) { //TODO 1.17 can this happen?
text = " "; text = " ";
} else { } else {
text = MessageTranslator.convertMessage(packet.getText(), session.getLocale()); text = MessageTranslator.convertMessage(packet.getText(), session.locale());
} }
SetTitlePacket titlePacket = new SetTitlePacket(); SetTitlePacket titlePacket = new SetTitlePacket();

Datei anzeigen

@ -42,7 +42,7 @@ public class JavaSetTitleTextTranslator extends PacketTranslator<ClientboundSetT
if (packet.getText() == null || Component.empty().equals(packet.getText())) { // This can happen, see https://github.com/KyoriPowered/adventure/issues/447 if (packet.getText() == null || Component.empty().equals(packet.getText())) { // This can happen, see https://github.com/KyoriPowered/adventure/issues/447
text = " "; text = " ";
} else { } else {
text = MessageTranslator.convertMessage(packet.getText(), session.getLocale()); text = MessageTranslator.convertMessage(packet.getText(), session.locale());
} }
SetTitlePacket titlePacket = new SetTitlePacket(); SetTitlePacket titlePacket = new SetTitlePacket();

Datei anzeigen

@ -245,7 +245,7 @@ public class MessageTranslator {
*/ */
public static boolean isTooLong(String message, GeyserSession session) { public static boolean isTooLong(String message, GeyserSession session) {
if (message.length() > 256) { if (message.length() > 256) {
session.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.chat.too_long", session.getLocale(), message.length())); session.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.chat.too_long", session.locale(), message.length()));
return true; return true;
} }

Datei anzeigen

@ -226,7 +226,7 @@ public class LoginEncryptionUtils {
session.sendForm( session.sendForm(
SimpleForm.builder() SimpleForm.builder()
.translator(GeyserLocale::getPlayerLocaleString, session.getLocale()) .translator(GeyserLocale::getPlayerLocaleString, session.locale())
.title("geyser.auth.login.form.notice.title") .title("geyser.auth.login.form.notice.title")
.content("geyser.auth.login.form.notice.desc") .content("geyser.auth.login.form.notice.desc")
.optionalButton("geyser.auth.login.form.notice.btn_login.mojang", isPasswordAuthEnabled) .optionalButton("geyser.auth.login.form.notice.btn_login.mojang", isPasswordAuthEnabled)
@ -257,14 +257,14 @@ public class LoginEncryptionUtils {
return; return;
} }
session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.getLocale())); session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.locale()));
})); }));
} }
public static void buildAndShowLoginDetailsWindow(GeyserSession session) { public static void buildAndShowLoginDetailsWindow(GeyserSession session) {
session.sendForm( session.sendForm(
CustomForm.builder() CustomForm.builder()
.translator(GeyserLocale::getPlayerLocaleString, session.getLocale()) .translator(GeyserLocale::getPlayerLocaleString, session.locale())
.title("geyser.auth.login.form.details.title") .title("geyser.auth.login.form.details.title")
.label("geyser.auth.login.form.details.desc") .label("geyser.auth.login.form.details.desc")
.input("geyser.auth.login.form.details.email", "account@geysermc.org", "") .input("geyser.auth.login.form.details.email", "account@geysermc.org", "")
@ -286,7 +286,7 @@ public class LoginEncryptionUtils {
public static void buildAndShowMicrosoftAuthenticationWindow(GeyserSession session) { public static void buildAndShowMicrosoftAuthenticationWindow(GeyserSession session) {
session.sendForm( session.sendForm(
SimpleForm.builder() SimpleForm.builder()
.translator(GeyserLocale::getPlayerLocaleString, session.getLocale()) .translator(GeyserLocale::getPlayerLocaleString, session.locale())
.title("geyser.auth.login.form.notice.btn_login.microsoft") .title("geyser.auth.login.form.notice.btn_login.microsoft")
.button("geyser.auth.login.method.browser") .button("geyser.auth.login.method.browser")
.button("geyser.auth.login.method.password") .button("geyser.auth.login.method.password")
@ -303,7 +303,7 @@ public class LoginEncryptionUtils {
} else if (response.getClickedButtonId() == 1) { } else if (response.getClickedButtonId() == 1) {
buildAndShowLoginDetailsWindow(session); buildAndShowLoginDetailsWindow(session);
} else { } else {
session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.getLocale())); session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.locale()));
} }
})); }));
} }
@ -326,7 +326,7 @@ public class LoginEncryptionUtils {
} }
if (response.getClickedButtonId() == 1) { if (response.getClickedButtonId() == 1) {
session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.getLocale())); session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.locale()));
} }
}) })
); );

Datei anzeigen

@ -45,7 +45,7 @@ public class SettingsUtils {
*/ */
public static CustomForm buildForm(GeyserSession session) { public static CustomForm buildForm(GeyserSession session) {
// Cache the language for cleaner access // Cache the language for cleaner access
String language = session.getLocale(); String language = session.locale();
CustomForm.Builder builder = CustomForm.builder() CustomForm.Builder builder = CustomForm.builder()
.translator(SettingsUtils::translateEntry, language) .translator(SettingsUtils::translateEntry, language)

Datei anzeigen

@ -53,7 +53,7 @@ public class StatisticsUtils {
*/ */
public static void buildAndSendStatisticsMenu(GeyserSession session) { public static void buildAndSendStatisticsMenu(GeyserSession session) {
// Cache the language for cleaner access // Cache the language for cleaner access
String language = session.getLocale(); String language = session.locale();
session.sendForm( session.sendForm(
SimpleForm.builder() SimpleForm.builder()