11package com .laytonsmith .abstraction .bukkit ;
22
3+ import com .laytonsmith .abstraction .MCNamespacedKey ;
34import com .laytonsmith .abstraction .MCTagContainer ;
45import com .laytonsmith .abstraction .enums .MCTagType ;
5- import com .laytonsmith .commandhelper .CommandHelperPlugin ;
66import org .bukkit .NamespacedKey ;
77import org .bukkit .persistence .PersistentDataContainer ;
88import org .bukkit .persistence .PersistentDataType ;
99
10- import java .util .Collection ;
10+ import java .util .HashSet ;
11+ import java .util .Set ;
1112
1213public class BukkitMCTagContainer implements MCTagContainer {
1314
@@ -19,7 +20,7 @@ public BukkitMCTagContainer(PersistentDataContainer pdc) {
1920
2021 @ Override
2122 public MCTagContainer newContainer () {
22- return new BukkitMCTagContainer (pdc .getAdapterContext ().newPersistentDataContainer ());
23+ return new BukkitMCTagContainer (this . pdc .getAdapterContext ().newPersistentDataContainer ());
2324 }
2425
2526 @ Override
@@ -28,46 +29,50 @@ public boolean isEmpty() {
2829 }
2930
3031 @ Override
31- public Collection getKeys () {
32- return pdc .getKeys ();
32+ public Set <MCNamespacedKey > getKeys () {
33+ Set <MCNamespacedKey > keys = new HashSet <>();
34+ for (NamespacedKey key : this .pdc .getKeys ()) {
35+ keys .add (new BukkitMCNamespacedKey (key ));
36+ }
37+ return keys ;
3338 }
3439
3540 @ Override
36- public MCTagType getType (Object key ) {
37- NamespacedKey namespacedKey = NamespacedKey ( key );
41+ public MCTagType getType (MCNamespacedKey key ) {
42+ NamespacedKey namespacedKey = ( NamespacedKey ) key . getHandle ( );
3843 // Check tag types in order of most frequently used
39- if (pdc .has (namespacedKey , PersistentDataType .STRING )) {
44+ if (this . pdc .has (namespacedKey , PersistentDataType .STRING )) {
4045 return MCTagType .STRING ;
41- } else if (pdc .has (namespacedKey , PersistentDataType .INTEGER )) {
46+ } else if (this . pdc .has (namespacedKey , PersistentDataType .INTEGER )) {
4247 return MCTagType .INTEGER ;
43- } else if (pdc .has (namespacedKey , PersistentDataType .BYTE )) {
48+ } else if (this . pdc .has (namespacedKey , PersistentDataType .BYTE )) {
4449 return MCTagType .BYTE ;
45- } else if (pdc .has (namespacedKey , PersistentDataType .DOUBLE )) {
50+ } else if (this . pdc .has (namespacedKey , PersistentDataType .DOUBLE )) {
4651 return MCTagType .DOUBLE ;
47- } else if (pdc .has (namespacedKey , PersistentDataType .LONG )) {
52+ } else if (this . pdc .has (namespacedKey , PersistentDataType .LONG )) {
4853 return MCTagType .LONG ;
49- } else if (pdc .has (namespacedKey , PersistentDataType .FLOAT )) {
54+ } else if (this . pdc .has (namespacedKey , PersistentDataType .FLOAT )) {
5055 return MCTagType .FLOAT ;
51- } else if (pdc .has (namespacedKey , PersistentDataType .TAG_CONTAINER )) {
56+ } else if (this . pdc .has (namespacedKey , PersistentDataType .TAG_CONTAINER )) {
5257 return MCTagType .TAG_CONTAINER ;
53- } else if (pdc .has (namespacedKey , PersistentDataType .BYTE_ARRAY )) {
58+ } else if (this . pdc .has (namespacedKey , PersistentDataType .BYTE_ARRAY )) {
5459 return MCTagType .BYTE_ARRAY ;
55- } else if (pdc .has (namespacedKey , PersistentDataType .SHORT )) {
60+ } else if (this . pdc .has (namespacedKey , PersistentDataType .SHORT )) {
5661 return MCTagType .SHORT ;
57- } else if (pdc .has (namespacedKey , PersistentDataType .INTEGER_ARRAY )) {
62+ } else if (this . pdc .has (namespacedKey , PersistentDataType .INTEGER_ARRAY )) {
5863 return MCTagType .INTEGER_ARRAY ;
59- } else if (pdc .has (namespacedKey , PersistentDataType .LONG_ARRAY )) {
64+ } else if (this . pdc .has (namespacedKey , PersistentDataType .LONG_ARRAY )) {
6065 return MCTagType .LONG_ARRAY ;
61- } else if (pdc .has (namespacedKey , PersistentDataType .TAG_CONTAINER_ARRAY )) {
66+ } else if (this . pdc .has (namespacedKey , PersistentDataType .TAG_CONTAINER_ARRAY )) {
6267 return MCTagType .TAG_CONTAINER_ARRAY ;
6368 }
6469 return null ;
6570 }
6671
6772 @ Override
68- public Object get (Object key , MCTagType type ) {
73+ public Object get (MCNamespacedKey key , MCTagType type ) {
6974 PersistentDataType bukkitType = GetPersistentDataType (type );
70- Object value = pdc .get (NamespacedKey ( key ), bukkitType );
75+ Object value = this . pdc .get (( NamespacedKey ) key . getHandle ( ), bukkitType );
7176 if (value instanceof PersistentDataContainer ) {
7277 return new BukkitMCTagContainer ((PersistentDataContainer ) value );
7378 } else if (value instanceof PersistentDataContainer [] concreteContainers ) {
@@ -81,7 +86,7 @@ public Object get(Object key, MCTagType type) {
8186 }
8287
8388 @ Override
84- public void set (Object key , MCTagType type , Object value ) {
89+ public void set (MCNamespacedKey key , MCTagType type , Object value ) {
8590 PersistentDataType bukkitType = GetPersistentDataType (type );
8691 if (value instanceof MCTagContainer ) {
8792 value = ((MCTagContainer ) value ).getHandle ();
@@ -92,24 +97,12 @@ public void set(Object key, MCTagType type, Object value) {
9297 }
9398 value = concreteContainers ;
9499 }
95- pdc .set (NamespacedKey ( key ), bukkitType , value );
100+ this . pdc .set (( NamespacedKey ) key . getHandle ( ), bukkitType , value );
96101 }
97102
98103 @ Override
99- public void remove (Object key ) {
100- pdc .remove (NamespacedKey (key ));
101- }
102-
103- private static NamespacedKey NamespacedKey (Object key ) {
104- if (key instanceof NamespacedKey ) {
105- return (NamespacedKey ) key ;
106- } else if (key instanceof String ) {
107- NamespacedKey namespacedKey = NamespacedKey .fromString ((String ) key , CommandHelperPlugin .self );
108- if (namespacedKey != null ) {
109- return namespacedKey ;
110- }
111- }
112- throw new IllegalArgumentException ("Invalid namespaced key." );
104+ public void remove (MCNamespacedKey key ) {
105+ this .pdc .remove ((NamespacedKey ) key .getHandle ());
113106 }
114107
115108 private static PersistentDataType GetPersistentDataType (MCTagType type ) {
@@ -144,7 +137,7 @@ private static PersistentDataType GetPersistentDataType(MCTagType type) {
144137
145138 @ Override
146139 public Object getHandle () {
147- return pdc ;
140+ return this . pdc ;
148141 }
149142
150143 @ Override
@@ -154,11 +147,11 @@ public boolean equals(Object o) {
154147
155148 @ Override
156149 public int hashCode () {
157- return pdc .hashCode ();
150+ return this . pdc .hashCode ();
158151 }
159152
160153 @ Override
161154 public String toString () {
162- return pdc .toString ();
155+ return this . pdc .toString ();
163156 }
164157}
0 commit comments