Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.3 #114

Merged
merged 11 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ dependencies {
include(libs.examination.string)
include(libs.adventure.textSerializerJson)
include(libs.ansi)
include(libs.option)
modCompileOnly(libs.jetbrainsAnnotations)

minecraft(libs.minecraft)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=net.kyori
version=5.10.2-SNAPSHOT
version=5.11.0-SNAPSHOT
description=Integration between the adventure library and Minecraft: Java Edition, using the Fabric modding system

javadocPublishRoot=https://jd.advntr.dev/platform/
Expand Down
11 changes: 6 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
version = "1.0"

[versions]
adventure = "4.14.0"
adventure = "4.15.0"
adventurePlatform = "4.3.1"
ansi = "1.0.3"
autoService = "1.1.1"
checkstyle = "10.12.5"
examination = "1.3.0"
fabricApi = "0.89.1+1.20.2"
fabricLoader = "0.14.22"
fabricApi = "0.91.1+1.20.3"
fabricLoader = "0.15.0"
indra = "3.1.3"
junit = "5.10.1"
minecraft = "1.20.2"
parchment = "1.20.1:2023.09.03"
minecraft = "1.20.3"
parchment = "1.20.2:2023.10.22"
vineflower = "1.9.3"
spotless = "6.21.0"

Expand All @@ -37,6 +37,7 @@ fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fab
fabric-permissionsApi = { module = "me.lucko:fabric-permissions-api", version = "0.2-SNAPSHOT" }
jetbrainsAnnotations = "org.jetbrains:annotations:24.1.0"
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
option = { module = "net.kyori:option", version = "1.0.0" }

# build
autoService = { module = "com.google.auto.service:auto-service", version.ref = "autoService" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of adventure-platform-fabric, licensed under the MIT License.
*
* Copyright (c) 2020-2022 KyoriPowered
* Copyright (c) 2020-2023 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,21 +21,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.platform.fabric.impl.accessor.minecraft.network.chat;
package net.kyori.adventure.platform.fabric.impl.accessor.minecraft.commands;

import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import net.minecraft.network.chat.Component;
import net.minecraft.commands.ParserUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(Component.Serializer.class)
public interface Component_SerializerAccess {
@Mixin(ParserUtils.class)
public interface ParserUtilsAccess {
// @formatter:off
@Accessor static Gson getGSON() {
throw new AssertionError();
}
@Invoker("getPos") static int getPos(final JsonReader reader) {
throw new AssertionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"minecraft.network.ConnectionAccess",
"minecraft.network.ServerCommonPacketListenerImplAccess",
"minecraft.network.ServerGamePacketListenerImplAccess",
"minecraft.network.chat.Component_SerializerAccess",
"minecraft.commands.ParserUtilsAccess",
"minecraft.world.level.LevelAccess"
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of adventure-platform-fabric, licensed under the MIT License.
*
* Copyright (c) 2020-2022 KyoriPowered
* Copyright (c) 2020-2023 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,9 +23,10 @@
*/
package net.kyori.adventure.platform.fabric.impl.client;

import java.net.MalformedURLException;
import java.time.Duration;
import java.util.Objects;
import net.kyori.adventure.audience.Audience;
import java.util.UUID;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.chat.ChatType;
Expand All @@ -35,11 +36,16 @@
import net.kyori.adventure.key.Key;
import net.kyori.adventure.platform.fabric.FabricAudiences;
import net.kyori.adventure.platform.fabric.impl.AdventureCommon;
import net.kyori.adventure.platform.fabric.impl.ControlledAudience;
import net.kyori.adventure.platform.fabric.impl.FabricAudiencesInternal;
import net.kyori.adventure.platform.fabric.impl.GameEnums;
import net.kyori.adventure.platform.fabric.impl.PointerProviderBridge;
import net.kyori.adventure.platform.fabric.impl.accessor.minecraft.world.level.LevelAccess;
import net.kyori.adventure.platform.fabric.impl.client.mixin.minecraft.resources.sounds.AbstractSoundInstanceAccess;
import net.kyori.adventure.pointer.Pointers;
import net.kyori.adventure.resource.ResourcePackInfo;
import net.kyori.adventure.resource.ResourcePackRequest;
import net.kyori.adventure.resource.ResourcePackStatus;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.sound.SoundStop;
import net.kyori.adventure.text.Component;
Expand All @@ -62,7 +68,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ClientAudience implements Audience {
public class ClientAudience implements ControlledAudience {
private final Minecraft client;
private final FabricClientAudiencesImpl controller;

Expand All @@ -71,6 +77,11 @@ public ClientAudience(final Minecraft client, final FabricClientAudiencesImpl re
this.controller = renderer;
}

@Override
public @NotNull FabricAudiencesInternal controller() {
return this.controller;
}

@Override
public void sendMessage(final @NotNull Component message) {
this.client.gui.getChat().addMessage(this.controller.toNative(message));
Expand Down Expand Up @@ -295,13 +306,42 @@ public void sendPlayerListHeaderAndFooter(final @NotNull Component header, final
this.sendPlayerListFooter(footer);
}

@Override
public void sendResourcePacks(final @NotNull ResourcePackRequest request) {
if (request.replace()) {
this.client.getDownloadedPackSource().popAll();
}

for (final ResourcePackInfo info : request.packs()) {
try {
this.client.getDownloadedPackSource().pushPack(info.id(), info.uri().toURL(), info.hash());
} catch (final MalformedURLException ex) {
request.callback().packEventReceived(info.id(), ResourcePackStatus.INVALID_URL, this);
}
// TODO: callbacks, required, prompting?
}
}

@Override
public void removeResourcePacks(final @NotNull UUID id, final @NotNull UUID@NotNull... others) {
this.client.getDownloadedPackSource().popPack(id);
for (final UUID other : others) {
this.client.getDownloadedPackSource().popPack(other);
}
}

@Override
public void clearResourcePacks() {
this.client.getDownloadedPackSource().popAll();
}

@Override
public @NotNull Pointers pointers() {
final @Nullable LocalPlayer clientPlayer = this.client.player;
if (clientPlayer != null) {
return ((PointerProviderBridge) clientPlayer).adventure$pointers();
} else {
return Audience.super.pointers();
return ControlledAudience.super.pointers();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.platform.fabric.FabricClientAudiences;
import net.kyori.adventure.platform.fabric.impl.ControlledAudience;
import net.kyori.adventure.platform.fabric.impl.FabricAudiencesInternal;
import net.kyori.adventure.platform.fabric.impl.LocaleHolderBridge;
import net.kyori.adventure.pointer.Pointers;
import net.kyori.adventure.sound.Sound;
Expand All @@ -42,7 +44,7 @@
import org.spongepowered.asm.mixin.Shadow;

@Mixin(LocalPlayer.class)
public abstract class LocalPlayerMixin extends Player implements ForwardingAudience.Single, LocaleHolderBridge {
public abstract class LocalPlayerMixin extends Player implements ForwardingAudience.Single, ControlledAudience, LocaleHolderBridge {
// @formatter:off
@Shadow @Final protected Minecraft minecraft;
// @formatter:on
Expand All @@ -65,6 +67,11 @@ private LocalPlayerMixin(final Level level, final BlockPos blockPos, final float
return this.audience().pointers();
}

@Override
public @NotNull FabricAudiencesInternal controller() {
return (FabricAudiencesInternal) FabricClientAudiences.of();
}

@Override
public void playSound(final @NotNull Sound sound) {
this.audience().playSound(sound, this.getX(), this.getY(), this.getZ());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of adventure-platform-fabric, licensed under the MIT License.
*
* Copyright (c) 2020-2022 KyoriPowered
* Copyright (c) 2020-2023 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -32,9 +32,10 @@
import java.util.List;
import net.kyori.adventure.Adventure;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.platform.fabric.impl.accessor.minecraft.network.chat.Component_SerializerAccess;
import net.kyori.adventure.platform.fabric.impl.accessor.minecraft.commands.ParserUtilsAccess;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.util.Index;
import net.minecraft.commands.arguments.ComponentArgument;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -168,8 +169,8 @@ public enum Format {
@Override
ReadResult parse(final String allInput) throws Exception {
try (final JsonReader json = new JsonReader(new java.io.StringReader(allInput))) {
final Component ret = Component_SerializerAccess.getGSON().fromJson(json, Component.class);
return new ReadResult(ret, Component_SerializerAccess.getPos(json));
final Component ret = GsonComponentSerializer.gson().serializer().fromJson(json, Component.class);
return new ReadResult(ret, ParserUtilsAccess.getPos(json));
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of adventure-platform-fabric, licensed under the MIT License.
*
* Copyright (c) 2020-2022 KyoriPowered
* Copyright (c) 2020-2023 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,14 +33,14 @@
import net.kyori.adventure.platform.fabric.impl.AdventureCommon;
import net.kyori.adventure.platform.fabric.impl.NonWrappingComponentSerializer;
import net.kyori.adventure.platform.fabric.impl.WrappedComponent;
import net.kyori.adventure.platform.fabric.impl.accessor.minecraft.network.chat.Component_SerializerAccess;
import net.kyori.adventure.pointer.Pointered;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.flattener.ComponentFlattener;
import net.kyori.adventure.text.renderer.ComponentRenderer;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.util.ComponentMessageThrowable;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -78,7 +78,7 @@ public interface FabricAudiences {
partition = ((WrappedComponent) input).partition();
renderer = ((WrappedComponent) input).renderer();
} else {
final Component original = Component_SerializerAccess.getGSON().fromJson(net.minecraft.network.chat.Component.Serializer.toJsonTree(input), Component.class);
final Component original = GsonComponentSerializer.gson().deserializeFromTree(net.minecraft.network.chat.Component.Serializer.toJsonTree(input));
modified = modifier.apply(original);
partition = null;
renderer = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* This file is part of adventure-platform-fabric, licensed under the MIT License.
*
* Copyright (c) 2023 KyoriPowered
*
* 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.
*/
package net.kyori.adventure.platform.fabric;

import java.util.UUID;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.platform.fabric.impl.ControlledAudience;
import net.kyori.adventure.platform.fabric.impl.server.FabricServerAudiencesImpl;
import net.kyori.adventure.resource.ResourcePackCallback;
import net.kyori.adventure.resource.ResourcePackStatus;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static java.util.Objects.requireNonNull;

/**
* Resource pack callbacks for the Fabric environment.
*
* @since 5.11.0
*/
public final class FabricResourcePackCallback {
private static final ComponentLogger LOGGER = ComponentLogger.logger();
private static final Component DEFAULT_KICK_MESSAGE = Component.translatable("multiplayer.requiredTexturePrompt.disconnect"); // vanilla translation

private FabricResourcePackCallback() {
}

/**
* Kick a resource pack receiver if they do not accept a resource pack.
*
* @return the kicking callback
* @since 5.11.0
*/
public static @NotNull ResourcePackCallback kickIfNotApplied() {
return kickIfNotApplied(DEFAULT_KICK_MESSAGE);
}

/**
* Kick a resource pack receiver if they do not accept a resource pack.
*
* @param kickMessage the message to kick the player with
* @return the kicking callback
* @since 5.11.0
*/
public static @NotNull ResourcePackCallback kickIfNotApplied(final @NotNull Component kickMessage) {
requireNonNull(kickMessage, "kickMessage");

return (uuid, status, audience) -> {
if (!status.intermediate() && status != ResourcePackStatus.SUCCESSFULLY_LOADED) { // we've reached a terminal, non-successful state
// now we attempt to extract a connection that can be kicked -- assuming that it's players that will be sent a resource pack
if (!(audience instanceof ControlledAudience controlled)) {
LOGGER.debug("Audience {} was not a ControlledAudience, we cannot kick them", audience);
return;
}
final ServerCommonPacketListenerImpl kicker;
if (audience instanceof ServerPlayer player) { // when you send a resource pack via the Audience implemented on ServerPlayer
kicker = player.connection;
} else {
final @Nullable UUID id = audience.get(Identity.UUID).orElse(null);
if (id == null) return; // not a player?
if (!(controlled.controller() instanceof FabricServerAudiencesImpl server)) return;

final ServerPlayer ply = server.server().getPlayerList().getPlayer(id);
if (ply == null) return;

kicker = ply.connection;
}

LOGGER.debug("Audience {} did not successfully apply a resource pack with ID {}, kicking with message: {}", kicker.getOwner(), uuid, kickMessage);
kicker.disconnect(controlled.controller().toNative(kickMessage));
}
};
}
}
Loading