9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-19 14:59:21 +00:00

refactor: update map persistence logic

Stop using deprecated methods
This commit is contained in:
William
2024-08-26 15:32:28 +01:00
parent 347d2d0a8f
commit 7d8ef7b6b3

View File

@@ -31,7 +31,7 @@ import net.william278.mapdataapi.MapData;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.ShulkerBox; import org.bukkit.block.Container;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.BlockStateMeta;
@@ -96,7 +96,7 @@ public interface BukkitMapPersister {
} }
if (item.getType() == Material.FILLED_MAP && item.hasItemMeta()) { if (item.getType() == Material.FILLED_MAP && item.hasItemMeta()) {
items[i] = function.apply(item); items[i] = function.apply(item);
} else if (item.getItemMeta() instanceof BlockStateMeta b && b.getBlockState() instanceof ShulkerBox box) { } else if (item.getItemMeta() instanceof BlockStateMeta b && b.getBlockState() instanceof Container box) {
forEachMap(box.getInventory().getContents(), function); forEachMap(box.getInventory().getContents(), function);
b.setBlockState(box); b.setBlockState(box);
} }
@@ -276,7 +276,7 @@ public interface BukkitMapPersister {
@NotNull @NotNull
private static World getDefaultMapWorld() { private static World getDefaultMapWorld() {
final World world = Bukkit.getWorlds().get(0); final World world = Bukkit.getWorlds().getFirst();
if (world == null) { if (world == null) {
throw new IllegalStateException("No worlds are loaded on the server!"); throw new IllegalStateException("No worlds are loaded on the server!");
} }
@@ -447,7 +447,7 @@ public interface BukkitMapPersister {
final String BANNER_PREFIX = "banner_"; final String BANNER_PREFIX = "banner_";
for (int i = 0; i < getCursors().size(); i++) { for (int i = 0; i < getCursors().size(); i++) {
final MapCursor cursor = getCursors().getCursor(i); final MapCursor cursor = getCursors().getCursor(i);
final String type = cursor.getType().name().toLowerCase(Locale.ENGLISH); final String type = cursor.getType().getKey().getKey();
if (type.startsWith(BANNER_PREFIX)) { if (type.startsWith(BANNER_PREFIX)) {
banners.add(new MapBanner( banners.add(new MapBanner(
type.replaceAll(BANNER_PREFIX, ""), type.replaceAll(BANNER_PREFIX, ""),