9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-27 10:39:11 +00:00

Compare commits

...

8 Commits

Author SHA1 Message Date
William278
70d6b671f2 Merge remote-tracking branch 'origin/test/debug-log-advancements' into test/debug-log-advancements 2025-03-20 19:34:16 +00:00
William278
98576c72fb feat: debug log all advancements 2025-03-20 19:34:00 +00:00
William278
ae657acee3 feat: skip unserializable items on Fabric 2025-03-20 19:29:20 +00:00
William278
34dc6a537d feat: add count check on fabric item array serializer 2025-03-17 20:06:41 +00:00
William278
e99ba66271 refactor: check if read map data was null 2025-03-17 19:48:10 +00:00
William278
546e663e4e feat: debug log all advancements 2025-03-14 18:04:43 +00:00
William278
0111f25865 Merge remote-tracking branch 'origin/master' 2025-03-09 15:02:07 +00:00
William278
2a59a0b3f5 feat: implement hashCode in Identifier classes 2025-03-06 14:38:01 +00:00
4 changed files with 43 additions and 12 deletions

View File

@@ -375,6 +375,9 @@ public abstract class BukkitData implements Data {
// Performs a consuming function for every advancement registered on the server // Performs a consuming function for every advancement registered on the server
private static void forEachAdvancement(@NotNull ThrowingConsumer<org.bukkit.advancement.Advancement> consumer) { private static void forEachAdvancement(@NotNull ThrowingConsumer<org.bukkit.advancement.Advancement> consumer) {
final StringJoiner joiner = new StringJoiner(", ");
Bukkit.getServer().advancementIterator().forEachRemaining(a -> joiner.add(a.toString()));
Bukkit.getLogger().log(Level.INFO, "Advancements: %s".formatted(joiner.toString()));
Bukkit.getServer().advancementIterator().forEachRemaining(consumer); Bukkit.getServer().advancementIterator().forEachRemaining(consumer);
} }

View File

@@ -268,9 +268,14 @@ public interface BukkitMapHandler {
// Read the pixel data and generate a map view otherwise // Read the pixel data and generate a map view otherwise
getPlugin().debug("Deserializing map data from NBT and generating view..."); getPlugin().debug("Deserializing map data from NBT and generating view...");
final MapData canvasData = Objects.requireNonNull(readMapData(originServerName, originalMapId), "Pixel data null!").getKey(); final @Nullable Map.Entry<MapData, Boolean> readMapData = readMapData(originServerName, originalMapId);
if (readMapData == null) {
getPlugin().debug("Read pixel data was not found in database, skipping...");
return;
}
// Add a renderer to the map with the data and save to file // Add a renderer to the map with the data and save to file
final MapData canvasData = Objects.requireNonNull(readMapData, "Pixel data null!").getKey();
final MapView view = generateRenderedMap(canvasData); final MapView view = generateRenderedMap(canvasData);
meta.setMapView(view); meta.setMapView(view);
map.setItemMeta(meta); map.setItemMeta(meta);

View File

@@ -234,6 +234,11 @@ public class Identifier {
return obj instanceof Identifier other ? toString().equals(other.toString()) : super.equals(obj); return obj instanceof Identifier other ? toString().equals(other.toString()) : super.equals(obj);
} }
@Override
public int hashCode() {
return key.toString().hashCode();
}
// Get the config entry for the identifier // Get the config entry for the identifier
@NotNull @NotNull
private Map.Entry<String, Boolean> getConfigEntry() { private Map.Entry<String, Boolean> getConfigEntry() {
@@ -313,6 +318,11 @@ public class Identifier {
} }
return false; return false;
} }
@Override
public int hashCode() {
return key.toString().hashCode();
}
} }
} }

View File

@@ -39,6 +39,7 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -173,16 +174,24 @@ public abstract class FabricSerializer {
container.putInt("size", items.length); container.putInt("size", items.length);
final NbtList itemList = new NbtList(); final NbtList itemList = new NbtList();
final DynamicRegistryManager registryManager = plugin.getMinecraftServer().getRegistryManager(); final DynamicRegistryManager registryManager = plugin.getMinecraftServer().getRegistryManager();
final List<ItemStack> skipped = new ArrayList<>();
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
final ItemStack item = items[i]; final ItemStack item = items[i];
if (item == null || item.isEmpty()) { if (item == null || item.isEmpty() || item.getCount() < 1 || item.getCount() > 99) {
continue; continue;
} }
final NbtCompound entry = encodeNbt(item, registryManager); final NbtCompound entry = encodeNbt(item, registryManager);
if (entry == null) {
skipped.add(item);
continue;
}
entry.putInt("Slot", i); entry.putInt("Slot", i);
itemList.add(entry); itemList.add(entry);
} }
if (!skipped.isEmpty()) {
plugin.debug("Skipped serializing items in array: %s".formatted(Arrays.toString(skipped.toArray())));
}
container.put(ITEMS_TAG, itemList); container.put(ITEMS_TAG, itemList);
return container; return container;
} }
@@ -216,17 +225,21 @@ public abstract class FabricSerializer {
).getValue(); ).getValue();
} }
@NotNull @Nullable
private NbtCompound encodeNbt(@NotNull ItemStack item, @NotNull DynamicRegistryManager registryManager) { private NbtCompound encodeNbt(@NotNull ItemStack item, @NotNull DynamicRegistryManager registryManager) {
//#if MC==12104 try {
return (NbtCompound) item.toNbt(registryManager); //#if MC==12104
//#elseif MC==12101 return (NbtCompound) item.toNbt(registryManager);
//$$ return (NbtCompound) item.encode(registryManager); //#elseif MC==12101
//#elseif MC==12001 //$$ return (NbtCompound) item.encode(registryManager);
//$$ final NbtCompound compound = new NbtCompound(); //#elseif MC==12001
//$$ item.writeNbt(compound); //$$ final NbtCompound compound = new NbtCompound();
//$$ return compound; //$$ item.writeNbt(compound);
//#endif //$$ return compound;
//#endif
} catch (Throwable e) {
return null;
}
} }
@NotNull @NotNull