1
1
package com.zp4rker.bukkot.listener
2
2
3
+ import com.zp4rker.bukkot.api.BlockingFunction
3
4
import org.bukkit.block.Block
4
5
import org.bukkit.entity.Entity
5
6
import org.bukkit.entity.Player
@@ -50,6 +51,30 @@ inline fun <reified T : EntityEvent> Entity.expect(
50
51
}, amount, timeout, timeoutAction, priority, ignoreCancelled, action)
51
52
}
52
53
54
+ /* *
55
+ * Registers limited listener which blocks the current thread where this entity is the subject
56
+ *
57
+ * Blocks until all calls are made or the listener times out
58
+ *
59
+ * @see org.bukkit.plugin.Plugin.expectBlocking
60
+ */
61
+ @BlockingFunction
62
+ inline fun <reified T : EntityEvent > Entity.expectBlocking (
63
+ plugin : JavaPlugin ,
64
+ crossinline predicate : Predicate <T > = { true },
65
+ amount : Int = 1,
66
+ timeout : Long = 0,
67
+ crossinline timeoutAction : () -> Unit = {},
68
+ priority : EventPriority = EventPriority .NORMAL ,
69
+ ignoreCancelled : Boolean = false,
70
+ crossinline action : AnonymousListener <T >.(T ) -> Unit
71
+ ) {
72
+ plugin.expectBlocking<T >({
73
+ if (it.entity.uniqueId == this .uniqueId) predicate(it)
74
+ else false
75
+ }, amount, timeout, timeoutAction, priority, ignoreCancelled, action)
76
+ }
77
+
53
78
/* *
54
79
* Registers continuous listener where this player is the subject
55
80
*
@@ -91,6 +116,30 @@ inline fun <reified T : PlayerEvent> Player.expect(
91
116
}, amount, timeout, timeoutAction, priority, ignoreCancelled, action)
92
117
}
93
118
119
+ /* *
120
+ * Registers limited listener which blocks the current thread where this player is the subject
121
+ *
122
+ * Blocks until all calls are made or the listener times out
123
+ *
124
+ * @see org.bukkit.plugin.Plugin.expectBlocking
125
+ */
126
+ @BlockingFunction
127
+ inline fun <reified T : PlayerEvent > Player.expectBlocking (
128
+ plugin : JavaPlugin ,
129
+ crossinline predicate : Predicate <T > = { true },
130
+ amount : Int = 1,
131
+ timeout : Long = 0,
132
+ crossinline timeoutAction : () -> Unit = {},
133
+ priority : EventPriority = EventPriority .NORMAL ,
134
+ ignoreCancelled : Boolean = false,
135
+ crossinline action : AnonymousListener <T >.(T ) -> Unit
136
+ ) {
137
+ plugin.expectBlocking<T >({
138
+ if (it.player.uniqueId == this .uniqueId) predicate(it)
139
+ else false
140
+ }, amount, timeout, timeoutAction, priority, ignoreCancelled, action)
141
+ }
142
+
94
143
/* *
95
144
* Registers continuous listener where this block is the subject
96
145
*
@@ -130,4 +179,28 @@ inline fun <reified T : BlockEvent> Block.expect(
130
179
if (it.block.location == this .location && it.block.blockData.asString == this .blockData.asString) predicate(it)
131
180
else false
132
181
}, amount, timeout, timeoutAction, priority, ignoreCancelled, action)
182
+ }
183
+
184
+ /* *
185
+ * Registers limited listener which blocks the current thread where this block is the subject
186
+ *
187
+ * Blocks until all calls are made or the listener times out
188
+ *
189
+ * @see org.bukkit.plugin.Plugin.expectBlocking
190
+ */
191
+ @BlockingFunction
192
+ inline fun <reified T : BlockEvent > Block.expectBlocking (
193
+ plugin : JavaPlugin ,
194
+ crossinline predicate : Predicate <T > = { true },
195
+ amount : Int = 1,
196
+ timeout : Long = 0,
197
+ crossinline timeoutAction : () -> Unit = {},
198
+ priority : EventPriority = EventPriority .NORMAL ,
199
+ ignoreCancelled : Boolean = false,
200
+ crossinline action : AnonymousListener <T >.(T ) -> Unit
201
+ ) {
202
+ plugin.expectBlocking<T >({
203
+ if (it.block.location == this .location && it.block.blockData.asString == this .blockData.asString) predicate(it)
204
+ else false
205
+ }, amount, timeout, timeoutAction, priority, ignoreCancelled, action)
133
206
}
0 commit comments