mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
feat: fix some error again
This commit is contained in:
@@ -5,12 +5,10 @@ import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtAccounter;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.server.players.NameAndId;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.TagValueInput;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.leavesmc.leaves.util.TagUtil;
|
||||
import org.slf4j.Logger;
|
||||
@@ -76,17 +74,10 @@ public class BotDataStorage implements IPlayerDataStorage {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ValueInput> load(Player player, ProblemReporter reporter) {
|
||||
return this.load(player.getScoreboardName(), player.getStringUUID()).map(nbt -> {
|
||||
ValueInput valueInput = TagValueInput.create(reporter, player.registryAccess(), nbt);
|
||||
player.load(valueInput);
|
||||
return valueInput;
|
||||
});
|
||||
}
|
||||
|
||||
private Optional<CompoundTag> load(String name, String uuid) {
|
||||
File file = new File(this.botDir, uuid + ".dat");
|
||||
@Override
|
||||
public Optional<CompoundTag> load(NameAndId nameAndId) {
|
||||
File file = new File(this.botDir, nameAndId.id() + ".dat");
|
||||
|
||||
if (file.exists() && file.isFile()) {
|
||||
try {
|
||||
@@ -94,11 +85,11 @@ public class BotDataStorage implements IPlayerDataStorage {
|
||||
if (!file.delete()) {
|
||||
throw new IOException("Failed to delete fakeplayer data");
|
||||
}
|
||||
this.savedBotList.remove(name);
|
||||
this.savedBotList.remove(nameAndId.name());
|
||||
this.saveBotList();
|
||||
return optional;
|
||||
} catch (Exception exception) {
|
||||
BotDataStorage.LOGGER.warn("Failed to load fakeplayer data for {}", name);
|
||||
BotDataStorage.LOGGER.warn("Failed to load fakeplayer data for {}", nameAndId.name());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,11 @@ import net.minecraft.world.entity.npc.AbstractVillager;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.storage.TagValueInput;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.event.entity.EntityRemoveEvent;
|
||||
@@ -106,7 +108,12 @@ public class BotList {
|
||||
bot.connection = new ServerBotPacketListenerImpl(this.server, bot);
|
||||
Optional<ValueInput> optional;
|
||||
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(bot.problemPath(), LOGGER)) {
|
||||
optional = playerIO.load(bot, scopedCollector);
|
||||
Optional<CompoundTag> nbt = playerIO.load(bot.nameAndId());
|
||||
if (nbt.isEmpty()) {
|
||||
optional = Optional.empty();
|
||||
} else {
|
||||
optional = Optional.of(TagValueInput.create(scopedCollector, bot.registryAccess(), nbt.orElseThrow()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -118,7 +125,7 @@ public class BotList {
|
||||
|
||||
ResourceKey<Level> resourcekey = null;
|
||||
if (nbt.getLong("WorldUUIDMost").isPresent() && nbt.getLong("WorldUUIDLeast").isPresent()) {
|
||||
org.bukkit.World bWorld = Bukkit.getServer().getWorld(new UUID(nbt.getLong("WorldUUIDMost").orElseThrow(), nbt.getLong("WorldUUIDLeast").orElseThrow()));
|
||||
World bWorld = Bukkit.getServer().getWorld(new UUID(nbt.getLong("WorldUUIDMost").orElseThrow(), nbt.getLong("WorldUUIDLeast").orElseThrow()));
|
||||
if (bWorld != null) {
|
||||
resourcekey = ((CraftWorld) bWorld).getHandle().dimension();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.leavesmc.leaves.bot;
|
||||
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.players.NameAndId;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -10,5 +10,5 @@ public interface IPlayerDataStorage {
|
||||
|
||||
void save(Player player);
|
||||
|
||||
Optional<ValueInput> load(Player player, ProblemReporter reporter);
|
||||
Optional<CompoundTag> load(NameAndId nameAndId);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.google.common.collect.Lists;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
@@ -36,9 +35,9 @@ public enum CampfireProvider implements IServerExtensionProvider<ItemStack> {
|
||||
}
|
||||
stack = stack.copy();
|
||||
|
||||
int finalI = i;
|
||||
CustomData customData = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.update(NbtOps.INSTANCE, COOKING_TIME_CODEC, campfire.cookingTime[i] - campfire.cookingProgress[i])
|
||||
.getOrThrow();
|
||||
.update(tag -> tag.store(COOKING_TIME_CODEC, campfire.cookingTime[finalI] - campfire.cookingProgress[finalI]));
|
||||
stack.set(DataComponents.CUSTOM_DATA, customData);
|
||||
|
||||
list.add(stack);
|
||||
|
||||
Reference in New Issue
Block a user