Move PlatformType to API and expose it for extensions (#3798)

* Move PlatformType to API and expose it for extensions

* Move to a record
This commit is contained in:
rtm516 2023-06-17 02:56:50 +01:00 committed by GitHub
parent 8d068ee28f
commit f272ed9383
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 52 additions and 41 deletions

View file

@ -35,6 +35,7 @@ import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.extension.ExtensionManager; import org.geysermc.geyser.api.extension.ExtensionManager;
import org.geysermc.geyser.api.network.BedrockListener; import org.geysermc.geyser.api.network.BedrockListener;
import org.geysermc.geyser.api.network.RemoteServer; import org.geysermc.geyser.api.network.RemoteServer;
import org.geysermc.geyser.api.util.PlatformType;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
@ -124,6 +125,14 @@ public interface GeyserApi extends GeyserApiBase {
@NonNull @NonNull
Path packDirectory(); Path packDirectory();
/**
* Gets {@link PlatformType} the extension is running on
*
* @return type of platform
*/
@NonNull
PlatformType platformType();
/** /**
* Gets the current {@link GeyserApiBase} instance. * Gets the current {@link GeyserApiBase} instance.
* *

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -23,21 +23,17 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.common; package org.geysermc.geyser.api.util;
import lombok.AllArgsConstructor; /**
import lombok.Getter; * Represents the platform Geyser is running on.
*/
@Getter public record PlatformType(String platformName) {
@AllArgsConstructor public static PlatformType ANDROID = new PlatformType("Android");
public enum PlatformType { public static PlatformType BUNGEECORD = new PlatformType("BungeeCord");
ANDROID("Android"), public static PlatformType FABRIC = new PlatformType("Fabric");
BUNGEECORD("BungeeCord"), public static PlatformType SPIGOT = new PlatformType("Spigot");
FABRIC("Fabric"), public static PlatformType SPONGE = new PlatformType("Sponge");
SPIGOT("Spigot"), public static PlatformType STANDALONE = new PlatformType("Standalone");
SPONGE("Sponge"), public static PlatformType VELOCITY = new PlatformType("Velocity");
STANDALONE("Standalone"),
VELOCITY("Velocity");
private final String platformName;
} }

View file

@ -31,7 +31,7 @@ import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.ProtocolConstants;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.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.api.command.Command; import org.geysermc.geyser.api.command.Command;

View file

@ -36,7 +36,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands; import net.minecraft.commands.Commands;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.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.GeyserLogger; import org.geysermc.geyser.GeyserLogger;

View file

@ -42,7 +42,7 @@ import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.Constants; import org.geysermc.geyser.Constants;
import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;

View file

@ -27,7 +27,7 @@ package org.geysermc.geyser.platform.sponge;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.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.api.command.Command; import org.geysermc.geyser.api.command.Command;

View file

@ -38,7 +38,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.ConsoleAppender; import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.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.command.GeyserCommandManager;

View file

@ -36,7 +36,7 @@ import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import lombok.Getter; import lombok.Getter;
import net.kyori.adventure.util.Codec; import net.kyori.adventure.util.Codec;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.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.api.command.Command; import org.geysermc.geyser.api.command.Command;

View file

@ -26,7 +26,7 @@
package org.geysermc.connector; package org.geysermc.connector;
import org.geysermc.api.Geyser; import org.geysermc.api.Geyser;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;

View file

@ -43,7 +43,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull; 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.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.cumulus.form.Form; import org.geysermc.cumulus.form.Form;
import org.geysermc.cumulus.form.util.FormBuilder; import org.geysermc.cumulus.form.util.FormBuilder;
import org.geysermc.erosion.packet.Packets; import org.geysermc.erosion.packet.Packets;
@ -411,7 +411,7 @@ public class GeyserImpl implements GeyserApi {
metrics.addCustomChart(new Metrics.SingleLineChart("players", sessionManager::size)); metrics.addCustomChart(new Metrics.SingleLineChart("players", sessionManager::size));
// Prevent unwanted words best we can // Prevent unwanted words best we can
metrics.addCustomChart(new Metrics.SimplePie("authMode", () -> config.getRemote().authType().toString().toLowerCase(Locale.ROOT))); metrics.addCustomChart(new Metrics.SimplePie("authMode", () -> config.getRemote().authType().toString().toLowerCase(Locale.ROOT)));
metrics.addCustomChart(new Metrics.SimplePie("platform", platformType::getPlatformName)); metrics.addCustomChart(new Metrics.SimplePie("platform", platformType::platformName));
metrics.addCustomChart(new Metrics.SimplePie("defaultLocale", GeyserLocale::getDefaultLocale)); metrics.addCustomChart(new Metrics.SimplePie("defaultLocale", GeyserLocale::getDefaultLocale));
metrics.addCustomChart(new Metrics.SimplePie("version", () -> GeyserImpl.VERSION)); metrics.addCustomChart(new Metrics.SimplePie("version", () -> GeyserImpl.VERSION));
metrics.addCustomChart(new Metrics.AdvancedPie("playerPlatform", () -> { metrics.addCustomChart(new Metrics.AdvancedPie("playerPlatform", () -> {
@ -447,7 +447,7 @@ public class GeyserImpl implements GeyserApi {
if (minecraftVersion != null) { if (minecraftVersion != null) {
Map<String, Map<String, Integer>> versionMap = new HashMap<>(); Map<String, Map<String, Integer>> versionMap = new HashMap<>();
Map<String, Integer> platformMap = new HashMap<>(); Map<String, Integer> platformMap = new HashMap<>();
platformMap.put(platformType.getPlatformName(), 1); platformMap.put(platformType.platformName(), 1);
versionMap.put(minecraftVersion, platformMap); versionMap.put(minecraftVersion, platformMap);
metrics.addCustomChart(new Metrics.DrilldownPie("minecraftServerVersion", () -> { metrics.addCustomChart(new Metrics.DrilldownPie("minecraftServerVersion", () -> {
@ -694,6 +694,12 @@ public class GeyserImpl implements GeyserApi {
return bootstrap.getConfigFolder().resolve("packs"); return bootstrap.getConfigFolder().resolve("packs");
} }
@Override
@NonNull
public PlatformType platformType() {
return platformType;
}
public int buildNumber() { public int buildNumber() {
if (!this.isProductionEnvironment()) { if (!this.isProductionEnvironment()) {
return 0; return 0;

View file

@ -29,7 +29,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.command.CommandExecutor; import org.geysermc.geyser.api.command.CommandExecutor;

View file

@ -26,7 +26,7 @@
package org.geysermc.geyser.command.defaults; package org.geysermc.geyser.command.defaults;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.command.GeyserCommandSource;

View file

@ -30,7 +30,7 @@ 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.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.command.GeyserCommandSource;

View file

@ -25,7 +25,7 @@
package org.geysermc.geyser.command.defaults; package org.geysermc.geyser.command.defaults;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;

View file

@ -25,7 +25,7 @@
package org.geysermc.geyser.command.defaults; package org.geysermc.geyser.command.defaults;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.command.GeyserCommandSource;

View file

@ -25,7 +25,7 @@
package org.geysermc.geyser.command.defaults; package org.geysermc.geyser.command.defaults;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.command.GeyserCommandSource;

View file

@ -26,7 +26,7 @@
package org.geysermc.geyser.command.defaults; package org.geysermc.geyser.command.defaults;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.command.GeyserCommandSource;

View file

@ -27,7 +27,7 @@ package org.geysermc.geyser.dump;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.text.AsteriskSerializer; import org.geysermc.geyser.text.AsteriskSerializer;

View file

@ -99,7 +99,7 @@ import org.cloudburstmc.protocol.common.util.OptionalBoolean;
import org.geysermc.api.util.BedrockPlatform; import org.geysermc.api.util.BedrockPlatform;
import org.geysermc.api.util.InputMode; import org.geysermc.api.util.InputMode;
import org.geysermc.api.util.UiProfile; import org.geysermc.api.util.UiProfile;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.cumulus.form.Form; import org.geysermc.cumulus.form.Form;
import org.geysermc.cumulus.form.util.FormBuilder; import org.geysermc.cumulus.form.util.FormBuilder;
import org.geysermc.floodgate.crypto.FloodgateCipher; import org.geysermc.floodgate.crypto.FloodgateCipher;

View file

@ -36,7 +36,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import lombok.Getter; import lombok.Getter;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.level.block.BlockStateValues;
import org.geysermc.geyser.level.physics.Axis; import org.geysermc.geyser.level.physics.Axis;
import org.geysermc.geyser.level.physics.BoundingBox; import org.geysermc.geyser.level.physics.BoundingBox;

View file

@ -26,7 +26,7 @@
package org.geysermc.geyser.translator.protocol.bedrock; package org.geysermc.geyser.translator.protocol.bedrock;
import org.cloudburstmc.protocol.bedrock.packet.CommandRequestPacket; import org.cloudburstmc.protocol.bedrock.packet.CommandRequestPacket;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
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;

View file

@ -29,7 +29,7 @@ import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLog
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.TranslatableComponent;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.network.GameProtocol;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.GeyserLocale;

View file

@ -33,7 +33,7 @@ import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket; import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket;
import org.cloudburstmc.protocol.bedrock.packet.BlockEventPacket; import org.cloudburstmc.protocol.bedrock.packet.BlockEventPacket;
import it.unimi.dsi.fastutil.objects.Object2IntMaps; import it.unimi.dsi.fastutil.objects.Object2IntMaps;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.level.block.BlockStateValues;
import org.geysermc.geyser.level.physics.Direction; import org.geysermc.geyser.level.physics.Direction;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;

View file

@ -29,7 +29,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.Clientb
import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.common.PlatformType; import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.registry.type.BlockMapping; import org.geysermc.geyser.registry.type.BlockMapping;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;