99import net .swofty .commons .statistics .ItemStatistics ;
1010import org .jetbrains .annotations .Nullable ;
1111
12+ import org .json .JSONObject ;
13+
1214public class ItemAttributeHotPotatoBookData extends ItemAttribute <ItemAttributeHotPotatoBookData .HotPotatoBookData > {
1315
1416 @ Override
@@ -24,6 +26,10 @@ public HotPotatoBookData getDefaultValue(@Nullable ItemStatistics defaultStatist
2426 @ Override
2527 public HotPotatoBookData loadFromString (String string ) {
2628 HotPotatoBookData hotPotatoBookData = new HotPotatoBookData ();
29+
30+ JSONObject obj = new JSONObject (string );
31+
32+
2733 String [] split = string .split ("," );
2834 for (String s : split ) {
2935 String [] split1 = s .split (":" );
@@ -45,14 +51,22 @@ public HotPotatoBookData loadFromString(String string) {
4551
4652 @ Override
4753 public String saveIntoString () {
48- StringBuilder stringBuilder = new StringBuilder ();
54+ JSONObject obj = new JSONObject ();
55+
4956 if (getValue ().hasPotatoBook ()) {
50- stringBuilder . append ("potatoType:" ). append ( getValue ().getPotatoType ()). append ( "," );
57+ obj . put ("potatoType" , getValue ().getPotatoType ());
5158 } else {
52- stringBuilder . append ("potatoType:null," );
59+ obj . put ("potatoType" , null );
5360 }
54- stringBuilder .append ("amount:" ).append (getValue ().getAmount ());
55- return stringBuilder .toString ();
61+
62+ JSONArray array = new JSONArray ();
63+
64+ for (Map .Entry <ItemType , Integer > appliedItem : getValue ().getAppliedItems ()) {
65+ array .put (appliedItem .getKey () + ":" + appliableItem .getValue ())
66+ }
67+
68+ obj .put ("applied" , array );
69+ return obj .toString ();
5670 }
5771
5872 @ AllArgsConstructor
@@ -61,14 +75,18 @@ public String saveIntoString() {
6175 @ Setter
6276 public static class HotPotatoBookData {
6377 private PotatoType potatoType = null ;
64- private int amount = 0 ;
78+ private HashMap < ItemType , Integer > appliedItems = new HashMap <>() ;
6579
66- public void addAmount (int amount ) {
67- this .amount += amount ;
80+ public void addAmount (ItemType itemType , int amount ) {
81+ if (!appliedItems .containsKey (itemType )){
82+ appliedItems .put (itemType , amount )
83+ }else {
84+ appliedItems .put (itemType , appliableItems .get (itemType ) + amount )
85+ }
6886 }
6987
70- public boolean hasPotatoBook () {
71- return amount > 0 ;
88+ public bool hasAppliedItem ( ItemType itemType ) {
89+ return appliedItems . containsKey ( itemType ) && appliedItems . get ( itemType ) > 0 ;
7290 }
7391 }
7492}
0 commit comments