[DEV] Fix up porting patches and configs
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.hypherionmc.craterlib.nojang.advancements;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedAdvancement {
|
||||
|
||||
private final Advancement internal;
|
||||
|
||||
public Optional<BridgedDisplayInfo> displayInfo() {
|
||||
if (internal.getDisplay() != null) {
|
||||
return Optional.of(BridgedDisplayInfo.of(internal.getDisplay()));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.hypherionmc.craterlib.nojang.advancements;
|
||||
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.advancements.DisplayInfo;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedDisplayInfo {
|
||||
|
||||
private final DisplayInfo internal;
|
||||
|
||||
public boolean shouldDisplay() {
|
||||
return internal.shouldAnnounceChat();
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return internal.isHidden();
|
||||
}
|
||||
|
||||
public Component displayName() {
|
||||
return ChatUtils.mojangToAdventure(internal.getTitle());
|
||||
}
|
||||
|
||||
public Component description() {
|
||||
return ChatUtils.mojangToAdventure(internal.getDescription());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.hypherionmc.craterlib.nojang.authlib;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedGameProfile {
|
||||
|
||||
private final GameProfile internal;
|
||||
|
||||
public static BridgedGameProfile mojang(UUID id, String name) {
|
||||
return new BridgedGameProfile(new GameProfile(id, name));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return internal.getName();
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return internal.getId();
|
||||
}
|
||||
|
||||
public GameProfile toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
package com.hypherionmc.craterlib.nojang.client;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedServerData;
|
||||
import com.hypherionmc.craterlib.nojang.client.server.BridgedIntegratedServer;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BridgedMinecraft {
|
||||
|
||||
@Getter
|
||||
private static final BridgedMinecraft instance = new BridgedMinecraft();
|
||||
private final Minecraft internal = Minecraft.getInstance();
|
||||
|
||||
public File getGameDirectory() {
|
||||
return internal.gameDirectory;
|
||||
}
|
||||
|
||||
public BridgedOptions getOptions() {
|
||||
return BridgedOptions.of(internal.options);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BridgedClientLevel getLevel() {
|
||||
if (internal.level == null)
|
||||
return null;
|
||||
|
||||
return BridgedClientLevel.of(internal.level);
|
||||
}
|
||||
|
||||
public boolean isRealmServer() {
|
||||
return internal.getCurrentServer() != null && internal.isConnectedToRealms();
|
||||
}
|
||||
|
||||
public boolean isSinglePlayer() {
|
||||
return internal.hasSingleplayerServer();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BridgedPlayer getPlayer() {
|
||||
if (internal.player == null)
|
||||
return null;
|
||||
|
||||
return BridgedPlayer.of(internal.player);
|
||||
}
|
||||
|
||||
public String getGameVersion() {
|
||||
return SharedConstants.getCurrentVersion().getName();
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return internal.getUser().getName();
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return internal.getUser().getProfileId();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BridgedServerData getCurrentServer() {
|
||||
if (internal.getCurrentServer() == null)
|
||||
return null;
|
||||
|
||||
return BridgedServerData.of(internal.getCurrentServer());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BridgedIntegratedServer getSinglePlayerServer() {
|
||||
return BridgedIntegratedServer.of(internal.getSingleplayerServer());
|
||||
}
|
||||
|
||||
public int getServerPlayerCount () {
|
||||
if (internal.getConnection() == null)
|
||||
return 0;
|
||||
|
||||
return internal.getConnection().getOnlinePlayers().size();
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.hypherionmc.craterlib.nojang.client;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.client.Options;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedOptions {
|
||||
|
||||
private final Options internal;
|
||||
|
||||
public String getLanguage() {
|
||||
return internal.languageCode;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
package com.hypherionmc.craterlib.nojang.client.gui;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.client.gui.screens.LevelLoadingScreen;
|
||||
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||
import net.minecraft.realms.RealmsScreen;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedScreen {
|
||||
|
||||
private final Screen internal;
|
||||
|
||||
public boolean isTitleScreen() {
|
||||
return internal instanceof TitleScreen;
|
||||
}
|
||||
|
||||
public boolean isRealmsScreen() {
|
||||
return internal instanceof RealmsScreen;
|
||||
}
|
||||
|
||||
public boolean isServerBrowserScreen() {
|
||||
return internal instanceof JoinMultiplayerScreen;
|
||||
}
|
||||
|
||||
public boolean isLoadingScreen() {
|
||||
return internal instanceof LevelLoadingScreen || internal instanceof ReceivingLevelScreen;
|
||||
}
|
||||
|
||||
public Screen toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
package com.hypherionmc.craterlib.nojang.client.multiplayer;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.core.BridgedBlockPos;
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedClientLevel {
|
||||
|
||||
private final ClientLevel internal;
|
||||
|
||||
public boolean isClientSide() {
|
||||
return internal.isClientSide();
|
||||
}
|
||||
|
||||
public long getGameTime() {
|
||||
return internal.getGameTime();
|
||||
}
|
||||
|
||||
public long getDayTime() {
|
||||
return internal.getDayTime();
|
||||
}
|
||||
|
||||
public long dayTime() {
|
||||
return internal.dayTime();
|
||||
}
|
||||
|
||||
public boolean isRaining() {
|
||||
return internal.isRaining();
|
||||
}
|
||||
|
||||
public boolean isThundering() {
|
||||
return internal.isThundering();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ResourceIdentifier getDimensionKey() {
|
||||
return ResourceIdentifier.fromMojang(internal.dimension().location());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ResourceIdentifier getBiomeIdentifier(BridgedBlockPos onPos) {
|
||||
AtomicReference<ResourceIdentifier> identifier = new AtomicReference<>(null);
|
||||
internal.getBiome(onPos.toMojang()).unwrap().ifLeft(b -> identifier.set(ResourceIdentifier.fromMojang(b.location())));
|
||||
return identifier.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Component getDifficulty() {
|
||||
return ChatUtils.mojangToAdventure(internal.getDifficulty().getDisplayName());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package com.hypherionmc.craterlib.nojang.client.multiplayer;
|
||||
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.ServerStatusPinger;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedServerData {
|
||||
|
||||
private final ServerData internal;
|
||||
|
||||
public String name() {
|
||||
return internal.name;
|
||||
}
|
||||
|
||||
public String ip() {
|
||||
return internal.ip;
|
||||
}
|
||||
|
||||
public Component motd() {
|
||||
return ChatUtils.mojangToAdventure(internal.motd);
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
if (!internal.pinged || internal.players == null) {
|
||||
try {
|
||||
new ServerStatusPinger().pingServer(internal, () -> {});
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
return internal.players == null ? 0 : internal.players.max();
|
||||
}
|
||||
|
||||
public ServerData toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package com.hypherionmc.craterlib.nojang.client.server;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.client.server.IntegratedServer;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedIntegratedServer {
|
||||
|
||||
private final IntegratedServer internal;
|
||||
|
||||
public String getLevelName() {
|
||||
return internal.getWorldData().getLevelName();
|
||||
}
|
||||
|
||||
public IntegratedServer toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package com.hypherionmc.craterlib.nojang.commands;
|
||||
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedCommandSourceStack {
|
||||
|
||||
private final CommandSourceStack internal;
|
||||
|
||||
public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
||||
internal.sendSuccess(() -> ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
}
|
||||
|
||||
public CommandSourceStack toMojang() {
|
||||
return internal;
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package com.hypherionmc.craterlib.nojang.commands;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class BridgedFakePlayer {
|
||||
|
||||
final MojangBridge internal;
|
||||
|
||||
public BridgedFakePlayer(BridgedMinecraftServer server, int perm, String name) {
|
||||
internal = new MojangBridge(server.toMojang(), perm, name, this::onSuccess, this::onError);
|
||||
}
|
||||
|
||||
public abstract void onSuccess(Supplier<net.kyori.adventure.text.Component> supplier, Boolean aBoolean);
|
||||
|
||||
public void onError(net.kyori.adventure.text.Component component) {
|
||||
this.onSuccess(() -> component, false);
|
||||
}
|
||||
|
||||
public CommandSourceStack toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
static class MojangBridge extends CommandSourceStack {
|
||||
|
||||
private final BiConsumer<Supplier<net.kyori.adventure.text.Component>, Boolean> successCallback;
|
||||
public final Consumer<net.kyori.adventure.text.Component> errorCallback;
|
||||
|
||||
MojangBridge(MinecraftServer server, int perm, String name, BiConsumer<Supplier<net.kyori.adventure.text.Component>, Boolean> successCallback, Consumer<net.kyori.adventure.text.Component> errorCallback) {
|
||||
super(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, server.overworld(), perm, name, Component.literal(name), server, null);
|
||||
this.successCallback = successCallback;
|
||||
this.errorCallback = errorCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
||||
successCallback.accept(() -> ChatUtils.mojangToAdventure(supplier.get()), bl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendFailure(Component arg) {
|
||||
errorCallback.accept(ChatUtils.mojangToAdventure(arg));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
package com.hypherionmc.craterlib.nojang.commands;
|
||||
|
||||
import com.hypherionmc.craterlib.api.commands.CraterCommand;
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.TriConsumer;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class CommandsRegistry {
|
||||
|
||||
public static final CommandsRegistry INSTANCE = new CommandsRegistry();
|
||||
|
||||
private final List<CraterCommand> commands = new ArrayList<>();
|
||||
|
||||
public void registerCommand(CraterCommand cmd) {
|
||||
commands.add(cmd);
|
||||
}
|
||||
|
||||
public void registerCommands(CommandDispatcher<CommandSourceStack> stack) {
|
||||
commands.forEach(cmd -> {
|
||||
if (cmd.hasArguments()) {
|
||||
CommandWithArguments.register(cmd, stack);
|
||||
} else {
|
||||
CommandWithoutArguments.register(cmd, stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static class CommandWithoutArguments {
|
||||
|
||||
public static void register(CraterCommand cmd, CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(cmd.getCommandName())
|
||||
.requires(source -> source.hasPermission(cmd.getPermissionLevel()))
|
||||
.executes(context -> {
|
||||
cmd.getExecutor().accept(BridgedCommandSourceStack.of(context.getSource()));
|
||||
return 1;
|
||||
});
|
||||
|
||||
dispatcher.register(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static class CommandWithArguments {
|
||||
|
||||
public static void register(CraterCommand cmd, CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(cmd.getCommandName())
|
||||
.requires(source -> source.hasPermission(cmd.getPermissionLevel()));
|
||||
|
||||
cmd.getArguments().forEach((key, pair) -> command.then(Commands.argument(key, pair.getLeft()).executes(context -> {
|
||||
|
||||
// This is FUCKING UGLY.... Need to improve this in the future
|
||||
if (pair.getLeft() instanceof GameProfileArgument) {
|
||||
Collection<GameProfile> profiles = GameProfileArgument.getGameProfiles(context, key);
|
||||
List<BridgedGameProfile> bridgedGameProfiles = new ArrayList<>();
|
||||
|
||||
profiles.forEach(p -> bridgedGameProfiles.add(BridgedGameProfile.of(p)));
|
||||
|
||||
((TriConsumer<BridgedPlayer, List<BridgedGameProfile>, BridgedCommandSourceStack>) pair.getRight())
|
||||
.accept(BridgedPlayer.of(context.getSource().getPlayer()), bridgedGameProfiles, BridgedCommandSourceStack.of(context.getSource()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
})));
|
||||
|
||||
dispatcher.register(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.hypherionmc.craterlib.nojang.core;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedBlockPos {
|
||||
|
||||
private final BlockPos internal;
|
||||
|
||||
public int getX() {
|
||||
return internal.getX();
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return internal.getY();
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return internal.getZ();
|
||||
}
|
||||
|
||||
public BlockPos toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.hypherionmc.craterlib.nojang.nbt;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedCompoundTag {
|
||||
|
||||
private final CompoundTag internal;
|
||||
|
||||
public static BridgedCompoundTag empty() {
|
||||
return new BridgedCompoundTag(new CompoundTag());
|
||||
}
|
||||
|
||||
public BridgedCompoundTag getCompound(String key) {
|
||||
return BridgedCompoundTag.of(internal.getCompound(key));
|
||||
}
|
||||
|
||||
public Set<String> getAllKeys() {
|
||||
return internal.getAllKeys();
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return internal.getString(key);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key) {
|
||||
return internal.getBoolean(key);
|
||||
}
|
||||
|
||||
public void putString(String key, String value) {
|
||||
internal.putString(key, value);
|
||||
}
|
||||
|
||||
public void put(String key, BridgedCompoundTag value) {
|
||||
internal.put(key, value.toMojang());
|
||||
}
|
||||
|
||||
public void putBoolean(String key, boolean value) {
|
||||
internal.putBoolean(key, value);
|
||||
}
|
||||
|
||||
public CompoundTag toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.hypherionmc.craterlib.nojang.network;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.nbt.BridgedCompoundTag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedFriendlyByteBuf {
|
||||
|
||||
private final FriendlyByteBuf internal;
|
||||
|
||||
public BridgedCompoundTag readNbt() {
|
||||
return BridgedCompoundTag.of(internal.readNbt());
|
||||
}
|
||||
|
||||
public BridgedFriendlyByteBuf writeNbt(BridgedCompoundTag tag) {
|
||||
internal.writeNbt(tag.toMojang());
|
||||
return BridgedFriendlyByteBuf.of(internal);
|
||||
}
|
||||
|
||||
public BridgedFriendlyByteBuf writeUtf(String value) {
|
||||
internal.writeUtf(value);
|
||||
return BridgedFriendlyByteBuf.of(internal);
|
||||
}
|
||||
|
||||
public String readUtf() {
|
||||
return internal.readUtf();
|
||||
}
|
||||
|
||||
public FriendlyByteBuf toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* This package, called NoJang, exposes various wrapped API's.
|
||||
* Using this api, a mod can essentially run on ANY minecraft version this library
|
||||
* supports, from one code base.
|
||||
* IMPORTANT NOTE: THESE API'S MUST NEVER EXPOSE ANY MINECRAFT CLASSES OR CODE!!!!
|
||||
* THEY MUST ALWAYS BE HANDLED INTERNALLY AND ONLY RETURN WRAPPED VARIANTS
|
||||
*/
|
||||
package com.hypherionmc.craterlib.nojang;
|
@@ -0,0 +1,40 @@
|
||||
package com.hypherionmc.craterlib.nojang.realmsclient.dto;
|
||||
|
||||
import com.mojang.realmsclient.dto.PlayerInfo;
|
||||
import com.mojang.realmsclient.dto.RealmsServer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedRealmsServer {
|
||||
|
||||
private final RealmsServer internal;
|
||||
|
||||
public String getName() {
|
||||
return internal.getName();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return internal.getDescription();
|
||||
}
|
||||
|
||||
public String getWorldType() {
|
||||
return internal.worldType.name();
|
||||
}
|
||||
|
||||
public String getMinigameName() {
|
||||
return internal.getMinigameName();
|
||||
}
|
||||
|
||||
public String getMinigameImage() {
|
||||
return internal.minigameImage;
|
||||
}
|
||||
|
||||
public long getPlayerCount() {
|
||||
return internal.players.stream().filter(PlayerInfo::getOnline).count();
|
||||
}
|
||||
|
||||
public RealmsServer toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
package com.hypherionmc.craterlib.nojang.resources;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class ResourceIdentifier {
|
||||
|
||||
private final ResourceLocation internal;
|
||||
|
||||
public ResourceIdentifier(String namespace, String path) {
|
||||
this.internal = new ResourceLocation(namespace, path);
|
||||
}
|
||||
|
||||
public ResourceIdentifier(String path) {
|
||||
this.internal = new ResourceLocation(path);
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return internal.getNamespace();
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return internal.getPath();
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return internal.toString();
|
||||
}
|
||||
|
||||
public static ResourceIdentifier fromMojang(ResourceLocation location) {
|
||||
return new ResourceIdentifier(location.getNamespace(), location.getPath());
|
||||
}
|
||||
|
||||
public ResourceLocation toMojang() {
|
||||
return internal;
|
||||
}
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
package com.hypherionmc.craterlib.nojang.server;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.commands.BridgedFakePlayer;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.players.UserBanListEntry;
|
||||
import net.minecraft.server.players.UserWhiteListEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedMinecraftServer {
|
||||
|
||||
private final MinecraftServer internal;
|
||||
|
||||
public boolean isUsingWhitelist() {
|
||||
return internal.getPlayerList().isUsingWhitelist();
|
||||
}
|
||||
|
||||
public int getPlayerCount() {
|
||||
return internal.getPlayerList().getPlayerCount();
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return internal.getPlayerList().getMaxPlayers();
|
||||
}
|
||||
|
||||
public String getServerModName() {
|
||||
return internal.getServerModName();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return SharedConstants.getCurrentVersion().getName();
|
||||
}
|
||||
|
||||
public boolean usesAuthentication() {
|
||||
return internal.usesAuthentication();
|
||||
}
|
||||
|
||||
public void broadcastSystemMessage(Component text, boolean bl) {
|
||||
internal.getPlayerList().broadcastSystemMessage(ChatUtils.adventureToMojang(text), bl);
|
||||
}
|
||||
|
||||
public boolean isPlayerBanned(BridgedGameProfile profile) {
|
||||
return internal.getPlayerList().getBans().isBanned(profile.toMojang());
|
||||
}
|
||||
|
||||
public void whitelistPlayer(BridgedGameProfile gameProfile) {
|
||||
if (!internal.getPlayerList().isUsingWhitelist())
|
||||
return;
|
||||
|
||||
internal.getPlayerList().getWhiteList().add(new UserWhiteListEntry(gameProfile.toMojang()));
|
||||
}
|
||||
|
||||
public void unWhitelistPlayer(BridgedGameProfile gameProfile) {
|
||||
if (!internal.getPlayerList().isUsingWhitelist())
|
||||
return;
|
||||
|
||||
internal.getPlayerList().getWhiteList().remove(new UserWhiteListEntry(gameProfile.toMojang()));
|
||||
}
|
||||
|
||||
public List<BridgedPlayer> getPlayers() {
|
||||
List<BridgedPlayer> profiles = new ArrayList<>();
|
||||
|
||||
if (internal.getPlayerList() == null)
|
||||
return profiles;
|
||||
|
||||
internal.getPlayerList().getPlayers().forEach(p -> profiles.add(BridgedPlayer.of(p)));
|
||||
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public void banPlayer(BridgedGameProfile profile) {
|
||||
internal.getPlayerList().getBans().add(new UserBanListEntry(profile.toMojang()));
|
||||
}
|
||||
|
||||
public void executeCommand(BridgedMinecraftServer server, BridgedFakePlayer player, String command) {
|
||||
internal.getCommands().performPrefixedCommand(player.toMojang(), command);
|
||||
}
|
||||
|
||||
public MinecraftServer toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package com.hypherionmc.craterlib.nojang.world.entity.player;
|
||||
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.core.BridgedBlockPos;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class BridgedPlayer {
|
||||
|
||||
private final Player internal;
|
||||
|
||||
public Component getDisplayName() {
|
||||
return ChatUtils.mojangToAdventure(internal.getDisplayName());
|
||||
}
|
||||
|
||||
public Component getName() {
|
||||
return ChatUtils.mojangToAdventure(internal.getName());
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return internal.getUUID();
|
||||
}
|
||||
|
||||
public String getStringUUID() {
|
||||
return internal.getStringUUID();
|
||||
}
|
||||
|
||||
public BridgedGameProfile getGameProfile() {
|
||||
return BridgedGameProfile.of(internal.getGameProfile());
|
||||
}
|
||||
|
||||
public boolean isServerPlayer() {
|
||||
return internal instanceof ServerPlayer;
|
||||
}
|
||||
|
||||
public Player toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
public BridgedBlockPos getOnPos() {
|
||||
return BridgedBlockPos.of(internal.getOnPos());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ServerGamePacketListenerImpl getConnection() {
|
||||
if (isServerPlayer()) {
|
||||
return ((ServerPlayer) internal).connection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ServerPlayer toMojangServerPlayer() {
|
||||
return (ServerPlayer) internal;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user