mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-05 18:32:28 +01:00
Fix game crash on join.
This commit is contained in:
parent
68049b3eab
commit
1f95cd5e23
@ -14,6 +14,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Handles loading and caching of tags
|
||||
@ -22,15 +23,156 @@ public class TagManager {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TagManager.class);
|
||||
private final Gson gson;
|
||||
private Map<NamespaceID, Tag> cache = new HashMap<>();
|
||||
private Map<NamespaceID, Tag> cache = new ConcurrentHashMap<>();
|
||||
private List<RequiredTag> requiredTags = new LinkedList<>();
|
||||
|
||||
public TagManager() {
|
||||
gson = new GsonBuilder()
|
||||
.create();
|
||||
|
||||
addRequiredTag(Tag.BasicTypes.FLUIDS, NamespaceID.from("lava"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("planks"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("wooden_trapdoors"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("stone_tool_materials"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("infiniburn_nether"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("infiniburn_end"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("sand"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("crimson_stems"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("buttons"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("spruce_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("wooden_stairs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("fire"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("pressure_plates"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("wooden_buttons"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("warped_stems"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("underwater_bonemeals"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("logs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("prevent_mob_spawning_inside"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("saplings"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("small_flowers"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("acacia_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("trapdoors"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("dragon_immune"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wooden_slabs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("signs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("soul_speed_blocks"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wooden_stairs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("wooden_doors"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("beacon_payment_items"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("bamboo_plantable_on"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("impermeable"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wooden_buttons"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("leaves"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("fishes"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("corals"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("climbable"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("birch_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wall_signs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("planks"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("non_flammable_wood"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("logs_that_burn"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("buttons"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("coral_blocks"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("anvil"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("gold_ores"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("small_flowers"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("ice"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("stairs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wooden_trapdoors"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("boats"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("wool"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("hoglin_repellents"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("piglin_repellents"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("tall_flowers"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("tall_flowers"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("leaves"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("soul_fire_base_blocks"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("shulker_boxes"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("banners"));
|
||||
addRequiredTag(Tag.BasicTypes.ENTITY_TYPES, NamespaceID.from("raiders"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wooden_fences"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("beacon_base_blocks"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("piglin_repellents"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("warped_stems"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wither_immune"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wart_blocks"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("flowers"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("soul_fire_base_blocks"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("saplings"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wool"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wall_post_override"));
|
||||
addRequiredTag(Tag.BasicTypes.ENTITY_TYPES, NamespaceID.from("impact_projectiles"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("beehives"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("wooden_pressure_plates"));
|
||||
addRequiredTag(Tag.BasicTypes.FLUIDS, NamespaceID.from("water"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wooden_doors"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wall_corals"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("campfires"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("trapdoors"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("walls"));
|
||||
addRequiredTag(Tag.BasicTypes.FLUIDS, NamespaceID.from("lava"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("anvil"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("stairs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("dark_oak_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("wooden_fences"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("signs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("carpets"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("oak_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("wooden_slabs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("stone_bricks"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("coals"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("carpets"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("jungle_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("enderman_holdable"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("lectern_books"));
|
||||
addRequiredTag(Tag.BasicTypes.ENTITY_TYPES, NamespaceID.from("arrows"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wither_summon_base_blocks"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("fence_gates"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("portals"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("rails"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("nylium"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("guarded_by_piglins"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("stone_bricks"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("wooden_pressure_plates"));
|
||||
addRequiredTag(Tag.BasicTypes.ENTITY_TYPES, NamespaceID.from("skeletons"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("oak_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("creeper_drop_music_discs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("jungle_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("spruce_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("walls"));
|
||||
addRequiredTag(Tag.BasicTypes.ENTITY_TYPES, NamespaceID.from("beehive_inhabitors"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("music_discs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("gold_ores"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("logs_that_burn"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("acacia_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("fences"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("crops"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("beds"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("dark_oak_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("arrows"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("non_flammable_wood"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("logs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("standing_signs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("flowers"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("slabs"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("piglin_loved"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("beds"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("banners"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("fences"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("birch_logs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("doors"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("strider_warm_blocks"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("flower_pots"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("slabs"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("rails"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("infiniburn_overworld"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("furnace_materials"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("doors"));
|
||||
addRequiredTag(Tag.BasicTypes.ITEMS, NamespaceID.from("sand"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("valid_spawn"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("crimson_stems"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("stone_pressure_plates"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("coral_plants"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("unstable_bottom_center"));
|
||||
addRequiredTag(Tag.BasicTypes.BLOCKS, NamespaceID.from("bee_growables"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +206,6 @@ public class TagManager {
|
||||
*/
|
||||
public Tag forceLoad(NamespaceID name, String tagType, ReaderSupplierWithFileNotFound readerSupplier) throws FileNotFoundException {
|
||||
Tag prev = cache.getOrDefault(name, Tag.EMPTY);
|
||||
FileNotFoundException[] ex = new FileNotFoundException[1]; // very ugly code but Java does not let its standard interfaces throw exceptions
|
||||
Tag result = create(prev, name, tagType, readerSupplier);
|
||||
cache.put(name, result);
|
||||
return result;
|
||||
@ -79,17 +220,10 @@ public class TagManager {
|
||||
*/
|
||||
public Tag load(NamespaceID name, String tagType, ReaderSupplierWithFileNotFound readerSupplier) throws FileNotFoundException {
|
||||
Tag prev = cache.getOrDefault(name, Tag.EMPTY);
|
||||
FileNotFoundException[] ex = new FileNotFoundException[1]; // very ugly code but Java does not let its standard interfaces throw exceptions
|
||||
Tag result = cache.computeIfAbsent(name, _name -> {
|
||||
try {
|
||||
return create(prev, name, tagType, readerSupplier);
|
||||
} catch (FileNotFoundException e) {
|
||||
ex[0] = e;
|
||||
return Tag.EMPTY;
|
||||
}
|
||||
});
|
||||
if(ex[0] != null) {
|
||||
throw ex[0];
|
||||
Tag result = cache.get(name);
|
||||
if (result == null) {
|
||||
result = create(prev, name, tagType, readerSupplier);
|
||||
cache.put(name, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user