@@ -79,39 +79,18 @@ public static class OldItemData {
7979
8080 static final ItemFactory itemFactory = Bukkit .getServer ().getItemFactory ();
8181
82- static final MaterialRegistry materialRegistry ;
83-
8482 private static final boolean SPAWN_EGG_META_EXISTS = Skript .classExists ("org.bukkit.inventory.meta.SpawnEggMeta" );
8583 private static final boolean HAS_NEW_SKULL_META_METHODS = Skript .methodExists (SkullMeta .class , "getOwningPlayer" );
8684
8785 // Load or create material registry
8886 static {
89- Gson gson = new GsonBuilder ().registerTypeAdapterFactory (EnumTypeAdapter .factory ).serializeNulls ().create ();
9087 Path materialsFile = Paths .get (Skript .getInstance ().getDataFolder ().getAbsolutePath (), "materials.json" );
9188 if (Files .exists (materialsFile )) {
92- String content = null ;
9389 try {
94- content = new String ( Files .readAllBytes (materialsFile ), StandardCharsets . UTF_8 );
90+ Files .delete (materialsFile );
9591 } catch (IOException e ) {
96- Skript .exception (e , "Loading material registry failed!" );
97- }
98- if (content != null ) {
99- String [] names = gson .fromJson (content , String [].class );
100- assert names != null ;
101- materialRegistry = MaterialRegistry .load (names );
102- } else {
103- materialRegistry = new MaterialRegistry ();
92+ Skript .exception (e , "Failed to remove legacy material registry file!" );
10493 }
105- } else {
106- materialRegistry = new MaterialRegistry ();
107- }
108-
109- // Always rewrite material registry, in case some updates got applied to it
110- String content = gson .toJson (materialRegistry .getMaterials ());
111- try {
112- Files .write (materialsFile , content .getBytes (StandardCharsets .UTF_8 ));
113- } catch (IOException e ) {
114- Skript .exception (e , "Saving material registry failed!" );
11594 }
11695 }
11796
@@ -142,7 +121,7 @@ public static class OldItemData {
142121 * allow comparing it against other blocks.
143122 */
144123 @ Nullable
145- transient BlockValues blockValues ;
124+ BlockValues blockValues ;
146125
147126 /**
148127 * Whether this represents an item (that definitely cannot have
@@ -613,20 +592,24 @@ public boolean matchPlain(ItemData other) {
613592 @ Override
614593 public Fields serialize () throws NotSerializableException {
615594 Fields fields = new Fields (this ); // ItemStack is transient, will be ignored
616- fields .putPrimitive ("id" , materialRegistry . getId ( type ));
595+ fields .putPrimitive ("id" , type . ordinal ( ));
617596 fields .putObject ("meta" , stack .getItemMeta ());
618597 return fields ;
619598 }
620599
600+ private static final Material [] materials = Material .values ();
601+
621602 @ Override
622603 public void deserialize (Fields fields ) throws StreamCorruptedException , NotSerializableException {
623- this .type = materialRegistry . getMaterial ( fields .getAndRemovePrimitive ("id" , int .class )) ;
604+ this .type = materials [ fields .getAndRemovePrimitive ("id" , int .class )] ;
624605 ItemMeta meta = fields .getAndRemoveObject ("meta" , ItemMeta .class );
625606 fields .setFields (this ); // Everything but ItemStack and Material
626607
627608 // Initialize ItemStack
628609 this .stack = new ItemStack (type );
629610 stack .setItemMeta (meta ); // Just set meta to it
611+
612+ fields .setFields (this ); // Everything but ItemStack and Material
630613 }
631614
632615 /**
0 commit comments