-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
plugins/api/event/InterceptBy.kt → src/main/kotlin/api/event/dsl/InterceptBy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
plugins/api/event/InterceptFilter.kt → ...n/kotlin/api/event/dsl/InterceptFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package api.event | ||
package api.event.dsl | ||
|
||
import api.predef.* | ||
import io.luna.game.event.Event | ||
|
3 changes: 2 additions & 1 deletion
3
plugins/api/event/InterceptMatcher.kt → .../kotlin/api/event/dsl/InterceptMatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package api.event.dsl | ||
|
||
import api.event.Matcher | ||
import io.luna.game.event.impl.UseItemEvent.* | ||
|
||
/** | ||
* A model that intercepts [ItemOnItemEvent]s and [ItemOnObjectEvent]s. | ||
* | ||
* @author lare96 | ||
*/ | ||
class InterceptUseItem(private val id: Int) { | ||
|
||
/** | ||
* Intercepts an [ItemOnItemEvent]. **Will match both ways!** | ||
*/ | ||
fun onItem(itemId: Int, action: ItemOnItemEvent.() -> Unit) { | ||
val matcher = Matcher.get<ItemOnItemEvent, Pair<Int, Int>>() | ||
matcher[id to itemId] = { action(this) } | ||
matcher[itemId to id] = { action(this) } | ||
} | ||
|
||
/** | ||
* Intercepts an [ItemOnObjectEvent]. | ||
*/ | ||
fun onObject(objectId: Int, action: ItemOnObjectEvent.() -> Unit) { | ||
val matcher = Matcher.get<ItemOnObjectEvent, Pair<Int, Int>>() | ||
matcher[id to objectId] = { action(this) } | ||
} | ||
|
||
/** | ||
* Intercepts an [ItemOnNpcEvent]. | ||
*/ | ||
fun onNpc(npcId: Int, action: ItemOnNpcEvent.() -> Unit) { | ||
val matcher = Matcher.get<ItemOnNpcEvent, Pair<Int, Int>>() | ||
matcher[id to npcId] = { action(this) } | ||
} | ||
|
||
/** | ||
* Intercepts an [ItemOnPlayerEvent]. | ||
*/ | ||
fun onPlayer(action: ItemOnPlayerEvent.() -> Unit) { | ||
val matcher = Matcher.get<ItemOnPlayerEvent, Int>() | ||
matcher[id] = { action(this) } | ||
} | ||
|
||
/** | ||
* Intercepts an [ItemOnGroundItemEvent]. | ||
*/ | ||
fun onGroundItem(itemId: Int, action: ItemOnGroundItemEvent.() -> Unit) { | ||
val matcher = Matcher.get<ItemOnGroundItemEvent, Pair<Int, Int>>() | ||
matcher[id to itemId] = { action(this) } | ||
} | ||
} |