Commit 675a057 1 parent 2562a0c commit 675a057 Copy full SHA for 675a057
File tree 2 files changed +50
-0
lines changed
src/main/java/cat/nyaa/nyaacore
2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import cat .nyaa .nyaacore .component .IMessageQueue ;
4
4
import cat .nyaa .nyaacore .component .NyaaComponent ;
5
+ import cat .nyaa .nyaacore .configuration .NbtItemStack ;
5
6
import cat .nyaa .nyaacore .http .client .HttpClient ;
6
7
import cat .nyaa .nyaacore .timer .TimerManager ;
7
8
import cat .nyaa .nyaacore .utils .ClickSelectionUtils ;
8
9
import cat .nyaa .nyaacore .utils .OfflinePlayerUtils ;
9
10
import org .bukkit .Bukkit ;
11
+ import org .bukkit .configuration .serialization .ConfigurationSerialization ;
10
12
import org .bukkit .craftbukkit .v1_13_R2 .util .CraftMagicNumbers ;
11
13
import org .bukkit .plugin .java .JavaPlugin ;
12
14
@@ -20,6 +22,10 @@ public static NyaaCoreLoader getInstance() {
20
22
21
23
public static final String TARGET_MAPPING = "00ed8e5c39debc3ed194ad7c5645cc45" ;
22
24
25
+ static {
26
+ ConfigurationSerialization .registerClass (NbtItemStack .class );
27
+ }
28
+
23
29
@ Override
24
30
public void onLoad () {
25
31
instance = this ;
Original file line number Diff line number Diff line change
1
+ package cat .nyaa .nyaacore .configuration ;
2
+
3
+ import cat .nyaa .nyaacore .utils .ItemStackUtils ;
4
+ import org .bukkit .configuration .serialization .ConfigurationSerializable ;
5
+ import org .bukkit .inventory .ItemStack ;
6
+
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
10
+ public class NbtItemStack implements ConfigurationSerializable {
11
+ public ItemStack it ;
12
+
13
+ public NbtItemStack (ItemStack it ) {
14
+ this .it = it ;
15
+ }
16
+
17
+ @ Override
18
+ public Map <String , Object > serialize () {
19
+ Map <String , Object > ret = new HashMap <>();
20
+ if (it != null ) {
21
+ try {
22
+ ret .put ("nbt" , ItemStackUtils .itemToBase64 (it ));
23
+ } catch (Exception ex ) {
24
+ ex .printStackTrace ();
25
+ ret .put ("nbt" , "<null>" );
26
+ }
27
+ } else {
28
+ ret .put ("nbt" , "<null>" );
29
+ }
30
+
31
+ return ret ;
32
+ }
33
+
34
+ public static NbtItemStack deserialize (Map <String , Object > map ) {
35
+ try {
36
+ String nbt = (String ) map .getOrDefault ("nbt" , 0 );
37
+ if (nbt == null || "<null>" .equalsIgnoreCase (nbt )) return new NbtItemStack (null );
38
+ return new NbtItemStack (ItemStackUtils .itemFromBase64 (nbt ));
39
+ } catch (Exception ex ) {
40
+ ex .printStackTrace ();
41
+ return new NbtItemStack (null );
42
+ }
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments