11package dev .drawethree .xprison .api .enchants .model ;
22
3- import com .google .gson .Gson ;
43import com .google .gson .JsonObject ;
54import com .google .gson .JsonParser ;
65import dev .drawethree .xprison .api .currency .CurrencyType ;
6+ import dev .drawethree .xprison .api .utils .JsonUtils ;
77import lombok .Getter ;
88import lombok .Setter ;
99import org .bukkit .ChatColor ;
@@ -66,15 +66,15 @@ public void load() {
6666 }
6767
6868 private void loadBaseProperties (JsonObject config ) {
69- this .id = config . get ( "id" ). getAsInt ( );
70- this .rawName = config . get ( "rawName" ). getAsString ( );
71- this .name = ChatColor .translateAlternateColorCodes ('&' , config . get ( "name" ). getAsString ( ));
69+ this .id = JsonUtils . getRequiredInt ( config , "id" );
70+ this .rawName = JsonUtils . getRequiredString ( config , "rawName" );
71+ this .name = ChatColor .translateAlternateColorCodes ('&' , JsonUtils . getRequiredString ( config , "name" ));
7272 this .nameWithoutColor = name .replaceAll ("§." , "" );
73- this .enabled = config . get ( "enabled" ). getAsBoolean ( );
74- this .maxLevel = config . get ( "maxLevel" ). getAsInt ( );
75- this .baseCost = config . get ( "initialCost" ). getAsLong ( );
76- this .increaseCost = config . get ( "increaseCostBy" ). getAsLong ( );
77- this .currencyType = CurrencyType .valueOf (config . get ( "currency" ). getAsString ( ));
73+ this .enabled = JsonUtils . getRequiredBoolean ( config , "enabled" );
74+ this .maxLevel = JsonUtils . getRequiredInt ( config , "maxLevel" );
75+ this .baseCost = JsonUtils . getRequiredLong ( config , "initialCost" );
76+ this .increaseCost = JsonUtils . getRequiredLong ( config , "increaseCostBy" );
77+ this .currencyType = CurrencyType .valueOf (JsonUtils . getOptionalString ( config , "currency" , CurrencyType . TOKENS . name () ));
7878 }
7979
8080 /**
@@ -83,20 +83,21 @@ private void loadBaseProperties(JsonObject config) {
8383 * @param config The root JSON object containing the "gui" section.
8484 */
8585 private void loadGuiProperties (JsonObject config ) {
86- JsonObject gui = config .getAsJsonObject ("gui" );
87- int slot = gui .get ("slot" ).getAsInt ();
88- String guiName = ChatColor .translateAlternateColorCodes ('&' , gui .get ("name" ).getAsString ());
89- Material mat = Material .valueOf (gui .get ("material" ).getAsString ());
90- String base64 = gui .has ("base64" ) ? gui .get ("base64" ).getAsString () : null ;
86+ JsonObject gui = JsonUtils .getRequiredObject (config , "gui" );
9187
92- List <String > desc = new Gson ().fromJson (gui .get ("description" ), List .class );
88+ int slot = JsonUtils .getRequiredInt (gui , "slot" );
89+ String guiName = ChatColor .translateAlternateColorCodes ('&' , JsonUtils .getRequiredString (gui , "name" ));
90+ Material mat = Material .valueOf (JsonUtils .getRequiredString (gui , "material" ));
91+ String base64 = JsonUtils .getOptionalString (gui , "base64" , null );
92+
93+ List <String > desc = JsonUtils .getRequiredStringList (gui , "description" );
9394 desc = desc .stream ()
9495 .map (s -> ChatColor .translateAlternateColorCodes ('&' , s ))
9596 .toList ();
9697
97- int customModelData = gui . get ( "customModelData" ). getAsInt ( );
98+ int customModelData = JsonUtils . getOptionalInt ( gui , "customModelData" , 0 );
9899
99- this .guiProperties = new XPrisonEnchantmentGuiPropertiesBase (slot , guiName , base64 , mat , desc ,customModelData );
100+ this .guiProperties = new XPrisonEnchantmentGuiPropertiesBase (slot , guiName , base64 , mat , desc , customModelData );
100101 }
101102
102103 /**
0 commit comments