mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 08:39:27 +00:00
Add packages to plugins
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.apollo.game.plugins.api
|
||||
package org.apollo.game.plugin.api
|
||||
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.cache.def.NpcDefinition
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
import java.util.*
|
||||
package org.apollo.game.plugin.api
|
||||
|
||||
import java.util.Random
|
||||
|
||||
val RAND = Random()
|
||||
|
||||
+14
-17
@@ -1,3 +1,5 @@
|
||||
package org.apollo.game.plugin.api
|
||||
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.area.Region
|
||||
@@ -7,39 +9,35 @@ import org.apollo.game.model.entity.EntityType.DYNAMIC_OBJECT
|
||||
import org.apollo.game.model.entity.EntityType.STATIC_OBJECT
|
||||
import org.apollo.game.model.entity.obj.DynamicGameObject
|
||||
import org.apollo.game.model.entity.obj.GameObject
|
||||
import org.apollo.game.model.entity.obj.StaticGameObject
|
||||
import org.apollo.game.scheduling.ScheduledTask
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.util.*
|
||||
import java.util.Optional
|
||||
import java.util.stream.Stream
|
||||
|
||||
fun <T : Entity> Region.find(position: Position, pred: (T) -> Boolean, vararg types: EntityType): Stream<T> {
|
||||
val result = this.getEntities<T>(position, *types)
|
||||
|
||||
return result.stream()
|
||||
.filter(pred::invoke)
|
||||
fun <T : Entity> Region.find(position: Position, predicate: (T) -> Boolean, vararg types: EntityType): Stream<T> {
|
||||
val result = getEntities<T>(position, *types)
|
||||
return result.stream().filter(predicate::invoke)
|
||||
}
|
||||
|
||||
fun Region.findObjects(position: Position, id: Int): Stream<GameObject> {
|
||||
return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
|
||||
return find(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
|
||||
}
|
||||
|
||||
fun Region.findObject(position: Position, id: Int): Optional<GameObject> {
|
||||
return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
|
||||
.findFirst()
|
||||
.findFirst()
|
||||
}
|
||||
|
||||
class ExpireObjectTask(
|
||||
val world: World,
|
||||
val obj: GameObject,
|
||||
val replacement: GameObject,
|
||||
val respawnDelay: Int
|
||||
private val world: World,
|
||||
private val existing: GameObject,
|
||||
private val replacement: GameObject,
|
||||
private val respawnDelay: Int
|
||||
) : ScheduledTask(0, true) {
|
||||
|
||||
private var respawning: Boolean = false
|
||||
|
||||
override fun execute() {
|
||||
val region = world.regionRepository.fromPosition(obj.position)
|
||||
val region = world.regionRepository.fromPosition(existing.position)
|
||||
|
||||
if (!respawning) {
|
||||
world.spawn(replacement)
|
||||
@@ -47,7 +45,7 @@ class ExpireObjectTask(
|
||||
setDelay(respawnDelay)
|
||||
} else {
|
||||
region.removeEntity(replacement)
|
||||
world.spawn(obj)
|
||||
world.spawn(existing)
|
||||
stop()
|
||||
}
|
||||
}
|
||||
@@ -55,7 +53,6 @@ class ExpireObjectTask(
|
||||
|
||||
fun World.expireObject(obj: GameObject, replacement: Int, respawnDelay: Int) {
|
||||
val replacementObj = DynamicGameObject.createPublic(this, replacement, obj.position, obj.type, obj.orientation)
|
||||
val respawnedObj = DynamicGameObject.createPublic(this, obj.id, obj.position, obj.type, obj.orientation)
|
||||
|
||||
schedule(ExpireObjectTask(this, obj, replacementObj, respawnDelay))
|
||||
}
|
||||
Reference in New Issue
Block a user