@@ -38,18 +38,14 @@ object HomeAPI {
3838 val zPos = owner.posZ.toInt()
3939 val yaw = owner.rotationYaw
4040 val pitch = owner.rotationPitch
41- val homes = StorageBase .getData(playerUUID).homes
42-
43- if (homes.isNotEmpty()) {
44- if (override ) {
45- homes.removeAll {
46- it.home == name
47- }
48- } else {
49- homes.forEach {
50- if (it.home == name) return false
51- }
41+ val homes = takeAll(owner)
42+
43+ if (override ) {
44+ homes.removeAll {
45+ it.home == name
5246 }
47+ } else {
48+ if (contains(homes, name)) return false
5349 }
5450
5551 homes.add(
@@ -60,4 +56,80 @@ object HomeAPI {
6056 StorageBase .setData(playerUUID, HomeModel (homes))
6157 return true
6258 }
59+
60+ /* *
61+ * Remove home for target player with specified name.
62+ *
63+ * @param owner ServerPlayerEntity class instance,
64+ * target home owner.
65+ * @param name home name to remove with default value `home`.
66+ *
67+ * @return true if home removing successful otherwise false.
68+ *
69+ * @since 1.14.4-1.2.0
70+ */
71+ fun remove (
72+ owner : ServerPlayerEntity ,
73+ name : String = "home"
74+ ): Boolean {
75+ val playerUUID = owner.uniqueID.toString()
76+ val homes = takeAll(owner)
77+
78+ take(owner, name)?.let {
79+ homes.remove(it)
80+ StorageBase .setData(playerUUID, HomeModel (homes))
81+ return true
82+ }
83+ return false
84+ }
85+
86+ /* *
87+ * @param owner ServerPlayerEntity class instance,
88+ * target home owner.
89+ *
90+ * @return all player registered homes.
91+ *
92+ * @since 1.14.4-1.2.0
93+ */
94+ fun takeAll (owner : ServerPlayerEntity ): MutableList <HomeModel .Home > =
95+ StorageBase .getData(owner.uniqueID.toString()).homes
96+
97+ /* *
98+ * @param owner ServerPlayerEntity class instance,
99+ * target home owner.
100+ * @param name home name with default value `home`.
101+ *
102+ * @return null if home not exist otherwise home instance.
103+ *
104+ * @since 1.14.4-1.2.0
105+ */
106+ fun take (
107+ owner : ServerPlayerEntity ,
108+ name : String = "home"
109+ ): HomeModel .Home ? {
110+ val homes = takeAll(owner)
111+ homes.forEach {
112+ if (it.home == name) return it
113+ }
114+ return null
115+ }
116+
117+ /* *
118+ * @param homeCollection player home collection. Can
119+ * be taken with `takeAll` method.
120+ * @param name home name.
121+ *
122+ * @return true if home exist otherwise false.
123+ *
124+ * @since 1.14.4-1.2.0
125+ */
126+ fun contains (
127+ homeCollection : List <HomeModel .Home >,
128+ name : String
129+ ): Boolean {
130+ homeCollection.forEach {
131+ if (it.home == name) return true
132+ }
133+ return false
134+ }
63135}
0 commit comments