Replace old version command with brigadier equivalent (#12502)

---------

Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
This commit is contained in:
David
2025-05-18 22:24:02 +02:00
committed by GitHub
parent 6f73e62ecd
commit ce0fa4c438
7 changed files with 216 additions and 17 deletions

View File

@ -21,12 +21,24 @@ public interface VersionFetcher {
/**
* Gets the version message to cache and show to command senders.
*
* <p>NOTE: This is run in a new thread separate from that of the command processing thread</p>
* @return the message to show when requesting a version
* @apiNote This method may involve a web request which will block the executing thread
*/
Component getVersionMessage();
/**
* Gets the version message to cache and show to command senders.
*
* @param serverVersion the current version of the server (will match {@link Bukkit#getVersion()})
* @return the message to show when requesting a version
* @apiNote This method may involve a web request which will block the current thread
* @see #getVersionMessage()
* @deprecated {@code serverVersion} is not required
*/
Component getVersionMessage(String serverVersion);
@Deprecated
default Component getVersionMessage(String serverVersion) {
return getVersionMessage();
}
@ApiStatus.Internal
class DummyVersionFetcher implements VersionFetcher {
@ -37,7 +49,7 @@ public interface VersionFetcher {
}
@Override
public Component getVersionMessage(final String serverVersion) {
public Component getVersionMessage() {
Bukkit.getLogger().warning("Version provider has not been set, cannot check for updates!");
Bukkit.getLogger().info("Override the default implementation of org.bukkit.UnsafeValues#getVersionFetcher()");
new Throwable().printStackTrace();

View File

@ -5,7 +5,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@ -14,32 +13,26 @@ import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.command.defaults.HelpCommand;
import org.bukkit.command.defaults.PluginsCommand;
import org.bukkit.command.defaults.ReloadCommand;
import org.bukkit.command.defaults.VersionCommand;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SimpleCommandMap implements CommandMap {
protected final Map<String, Command> knownCommands; // Paper
protected final Map<String, Command> knownCommands;
private final Server server;
// Paper start
@org.jetbrains.annotations.ApiStatus.Internal
public SimpleCommandMap(@NotNull final Server server, Map<String, Command> backing) {
this.knownCommands = backing;
// Paper end
this.server = server;
setDefaultCommands();
}
private void setDefaultCommands() {
register("bukkit", new VersionCommand("version"));
register("bukkit", new ReloadCommand("reload"));
//register("bukkit", new PluginsCommand("plugins")); // Paper
register("bukkit", new co.aikar.timings.TimingsCommand("timings")); // Paper
register("bukkit", new co.aikar.timings.TimingsCommand("timings"));
}
public void setFallbackCommands() {

View File

@ -32,6 +32,7 @@ import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
@Deprecated(forRemoval = true)
public class VersionCommand extends BukkitCommand {
private VersionFetcher versionFetcher; // Paper - version command 2.0
private VersionFetcher getVersionFetcher() { // lazy load because unsafe isn't available at command registration