9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 10:59:07 +00:00

浅浅添加一个之前资源包记录

This commit is contained in:
XiaoMoMi
2025-04-16 20:33:11 +08:00
parent a33721446f
commit 244e65f12c
3 changed files with 31 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@@ -47,6 +48,7 @@ public class BukkitServerPlayer extends Player {
private UUID uuid;
private ConnectionState decoderState;
private ConnectionState encoderState;
private UUID resourcePackUUID;
// some references
private Reference<org.bukkit.entity.Player> playerRef;
private Reference<Object> serverPlayerRef;
@@ -742,9 +744,31 @@ public class BukkitServerPlayer extends Player {
this.hasClientMod = enable;
}
@Override
public void setCurrentResourcePackUUID(UUID uuid) {
this.resourcePackUUID = uuid;
}
@Override
public @Nullable UUID currentResourcePackUUID() {
return this.resourcePackUUID;
}
@Override
public void clearView() {
this.entityTypeView.clear();
this.furnitureView.clear();
}
@Override
public void unloadCurrentResourcePack() {
if (decoderState() == ConnectionState.PLAY && this.resourcePackUUID != null && VersionHelper.isVersionNewerThan1_20_3()) {
try {
sendPacket(Reflections.constructor$ClientboundResourcePackPopPacket.newInstance(Optional.of(this.resourcePackUUID)), true);
this.resourcePackUUID = null;
} catch (ReflectiveOperationException e) {
this.plugin.logger().warn("Failed to unload resource pack for player " + name());
}
}
}
}

View File

@@ -82,4 +82,6 @@ public abstract class Player extends Entity implements NetWorkUser {
public abstract void closeInventory();
public abstract void clearView();
public abstract void unloadCurrentResourcePack();
}

View File

@@ -4,6 +4,7 @@ import io.netty.channel.Channel;
import net.momirealms.craftengine.core.plugin.Plugin;
import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
@@ -50,5 +51,8 @@ public interface NetWorkUser {
void setClientModState(boolean enable);
void setCurrentResourcePackUUID(UUID uuid);
@Nullable
UUID currentResourcePackUUID();
}