@@ -23,10 +23,14 @@ public class SignShop {
23
23
@ PrimaryKey
24
24
public UUID owner ;
25
25
public String yaml = "" ;
26
+ private YamlConfiguration config = null ;
26
27
27
28
@ DataColumn ("yaml" )
28
29
public String getYaml () {
29
- return Base64 .getEncoder ().encodeToString (this .yaml .getBytes ());
30
+ if (config == null ) {
31
+ return Base64 .getEncoder ().encodeToString (this .yaml .getBytes ());
32
+ }
33
+ return Base64 .getEncoder ().encodeToString (this .config .saveToString ().getBytes ());
30
34
}
31
35
32
36
public void setYaml (String yaml ) {
@@ -46,15 +50,12 @@ public List<ShopItem> getItems(ShopMode mode) {
46
50
}
47
51
48
52
public List <ShopItem > loadItems (String path ) {
49
- YamlConfiguration configuration = new YamlConfiguration ();
50
- try {
51
- configuration .loadFromString (this .yaml );
52
- } catch (InvalidConfigurationException e ) {
53
- e .printStackTrace ();
53
+ if (config == null ) {
54
+ load ();
54
55
}
55
56
ArrayList <ShopItem > list = new ArrayList <>();
56
- if (configuration .isConfigurationSection (path )) {
57
- ConfigurationSection section = configuration .getConfigurationSection (path );
57
+ if (config .isConfigurationSection (path )) {
58
+ ConfigurationSection section = config .getConfigurationSection (path );
58
59
for (String k : section .getKeys (false )) {
59
60
list .add (new ShopItem (section .getConfigurationSection (k )));
60
61
}
@@ -63,20 +64,33 @@ public List<ShopItem> loadItems(String path) {
63
64
}
64
65
65
66
public void saveItems (String path , List <ShopItem > list ) {
66
- YamlConfiguration configuration = new YamlConfiguration ();
67
- try {
68
- configuration .loadFromString (this .yaml );
69
- } catch (InvalidConfigurationException e ) {
70
- e .printStackTrace ();
67
+ if (config == null ) {
68
+ load ();
71
69
}
72
- configuration .set (path , null );
73
- ConfigurationSection section = configuration .createSection (path );
70
+ config .set (path , null );
71
+ ConfigurationSection section = config .createSection (path );
74
72
for (int i = 0 ; i < list .size (); i ++) {
75
73
ShopItem item = list .get (i );
76
74
if (item .amount > 0 && item .getItemStack (1 ).getType () != Material .AIR ) {
77
75
list .get (i ).save (section .createSection (String .valueOf (i )));
78
76
}
79
77
}
80
- this .yaml = configuration .saveToString ();
78
+ }
79
+
80
+ public void yamlToNBT () {
81
+ if (config == null ) {
82
+ load ();
83
+ }
84
+ setItems (getItems (ShopMode .BUY ), ShopMode .BUY );
85
+ setItems (getItems (ShopMode .SELL ), ShopMode .SELL );
86
+ }
87
+
88
+ private void load () {
89
+ config = new YamlConfiguration ();
90
+ try {
91
+ config .loadFromString (this .yaml );
92
+ } catch (InvalidConfigurationException e ) {
93
+ e .printStackTrace ();
94
+ }
81
95
}
82
96
}
0 commit comments