From 2c9d14f44844cba50abaa1c50f822be5093bea27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Ba=C5=BEant?= Date: Mon, 6 Nov 2023 22:02:23 +0100 Subject: [PATCH] Fix crash on version 1.20 --- .../structures/DynmapStructuresPlugin.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/kovuthehusky/dynmap/structures/DynmapStructuresPlugin.java b/src/main/java/com/kovuthehusky/dynmap/structures/DynmapStructuresPlugin.java index 275d74a..20f4c4b 100644 --- a/src/main/java/com/kovuthehusky/dynmap/structures/DynmapStructuresPlugin.java +++ b/src/main/java/com/kovuthehusky/dynmap/structures/DynmapStructuresPlugin.java @@ -526,35 +526,14 @@ public void onEnable() { } } // Add bastion remnant if supported - if (StructureType.getStructureTypes().containsKey("bastion_remnant")) { - for (Biome biome : new Biome[]{NETHER_WASTES, SOUL_SAND_VALLEY, CRIMSON_FOREST, WARPED_FOREST}) { - StructureType[] temp = new StructureType[BIOMES[biome.ordinal()].length + 1]; - System.arraycopy(BIOMES[biome.ordinal()], 0, temp, 0, BIOMES[biome.ordinal()].length); - temp[temp.length - 1] = BASTION_REMNANT; - BIOMES[biome.ordinal()] = temp; - } - } + registerStructure("bastion_remnant", BASTION_REMNANT, new Biome[]{NETHER_WASTES, SOUL_SAND_VALLEY, CRIMSON_FOREST, WARPED_FOREST}); + // Add nether fossils if supported - if (StructureType.getStructureTypes().containsKey("nether_fossil")) { - for (Biome biome : new Biome[]{SOUL_SAND_VALLEY}) { - StructureType[] temp = new StructureType[BIOMES[biome.ordinal()].length + 1]; - System.arraycopy(BIOMES[biome.ordinal()], 0, temp, 0, BIOMES[biome.ordinal()].length); - temp[temp.length - 1] = NETHER_FOSSIL; - BIOMES[biome.ordinal()] = temp; - } - } + registerStructure("nether_fossil", NETHER_FOSSIL, new Biome[]{SOUL_SAND_VALLEY}); + // Add ruined portals if supported - if (StructureType.getStructureTypes().containsKey("ruined_portal")) { - for (Biome biome : Biome.values()) { - if (biome == THE_END) { - continue; - } - StructureType[] temp = new StructureType[BIOMES[biome.ordinal()].length + 1]; - System.arraycopy(BIOMES[biome.ordinal()], 0, temp, 0, BIOMES[biome.ordinal()].length); - temp[temp.length - 1] = RUINED_PORTAL; - BIOMES[biome.ordinal()] = temp; - } - } + registerStructure("ruined_portal", RUINED_PORTAL, Biome.values()); + // Add ancient cities if supported // if (StructureType.getStructureTypes().containsKey("ancient_city")) { // ArrayList biomes = new ArrayList() {{ @@ -640,6 +619,23 @@ public void onEnable() { } } + private void registerStructure(String structureKey, StructureType structureType, Biome[] biomes) { + if (StructureType.getStructureTypes().containsKey(structureKey)) { + for (Biome biome : biomes) { + StructureType[] oldStructures = BIOMES[biome.ordinal()]; + if (oldStructures == null) { + BIOMES[biome.ordinal()] = new StructureType[]{structureType}; + } else { + StructureType[] newStructures = new StructureType[oldStructures.length + 1]; + System.arraycopy(oldStructures, 0, newStructures, 0, oldStructures.length); + newStructures[newStructures.length - 1] = structureType; + BIOMES[biome.ordinal()] = newStructures; + } + } + + } + } + @EventHandler public void onChunkLoad(ChunkLoadEvent event) { if (event.getWorld().canGenerateStructures()) {