Skip to content

Commit 046f373

Browse files
committed
Add packages to plugins
1 parent b4e8a71 commit 046f373

32 files changed

+377
-345
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.apollo.game.plugins.api
1+
package org.apollo.game.plugin.api
22

33
import org.apollo.cache.def.ItemDefinition
44
import org.apollo.cache.def.NpcDefinition

game/plugin/api/src/org/apollo/game/plugins/api/util.kt renamed to game/plugin/api/src/util.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import java.util.*
1+
package org.apollo.game.plugin.api
2+
3+
import java.util.Random
24

35
val RAND = Random()
46

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package org.apollo.game.plugin.api
2+
13
import org.apollo.game.model.Position
24
import org.apollo.game.model.World
35
import org.apollo.game.model.area.Region
@@ -7,55 +9,50 @@ import org.apollo.game.model.entity.EntityType.DYNAMIC_OBJECT
79
import org.apollo.game.model.entity.EntityType.STATIC_OBJECT
810
import org.apollo.game.model.entity.obj.DynamicGameObject
911
import org.apollo.game.model.entity.obj.GameObject
10-
import org.apollo.game.model.entity.obj.StaticGameObject
1112
import org.apollo.game.scheduling.ScheduledTask
12-
import java.lang.IllegalArgumentException
13-
import java.util.*
13+
import java.util.Optional
1414
import java.util.stream.Stream
1515

16-
fun <T : Entity> Region.find(position: Position, pred: (T) -> Boolean, vararg types: EntityType): Stream<T> {
17-
val result = this.getEntities<T>(position, *types)
18-
19-
return result.stream()
20-
.filter(pred::invoke)
16+
fun <T : Entity> Region.find(position: Position, predicate: (T) -> Boolean, vararg types: EntityType): Stream<T> {
17+
val result = getEntities<T>(position, *types)
18+
return result.stream().filter(predicate::invoke)
2119
}
2220

2321
fun Region.findObjects(position: Position, id: Int): Stream<GameObject> {
24-
return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
22+
return find(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
2523
}
2624

2725
fun Region.findObject(position: Position, id: Int): Optional<GameObject> {
2826
return find<GameObject>(position, { it.id == id }, DYNAMIC_OBJECT, STATIC_OBJECT)
29-
.findFirst()
27+
.findFirst()
3028
}
3129

3230
class ExpireObjectTask(
33-
val world: World,
34-
val obj: GameObject,
35-
val replacement: GameObject,
36-
val respawnDelay: Int
31+
private val world: World,
32+
private val existing: GameObject,
33+
private val replacement: GameObject,
34+
private val respawnDelay: Int
3735
) : ScheduledTask(0, true) {
3836

3937
private var respawning: Boolean = false
4038

4139
override fun execute() {
42-
val region = world.regionRepository.fromPosition(obj.position)
40+
val region = world.regionRepository.fromPosition(existing.position)
4341

4442
if (!respawning) {
4543
world.spawn(replacement)
4644
respawning = true
4745
setDelay(respawnDelay)
4846
} else {
4947
region.removeEntity(replacement)
50-
world.spawn(obj)
48+
world.spawn(existing)
5149
stop()
5250
}
5351
}
5452
}
5553

5654
fun World.expireObject(obj: GameObject, replacement: Int, respawnDelay: Int) {
5755
val replacementObj = DynamicGameObject.createPublic(this, replacement, obj.position, obj.type, obj.orientation)
58-
val respawnedObj = DynamicGameObject.createPublic(this, obj.id, obj.position, obj.type, obj.orientation)
5956

6057
schedule(ExpireObjectTask(this, obj, replacementObj, respawnDelay))
6158
}
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import com.google.common.primitives.Ints
22
import org.apollo.game.model.Animation
33
import org.apollo.game.model.entity.setting.PrivilegeLevel
4+
import org.apollo.game.plugin.util.command.valid_arg_length
45

56
on_command("animate", PrivilegeLevel.MODERATOR)
6-
.then { player ->
7-
val invalidSyntax = "Invalid syntax - ::animate [animation-id]"
8-
if(valid_arg_length(arguments, 1, player, invalidSyntax)) {
9-
val id = Ints.tryParse(arguments[0])
10-
if (id == null) {
11-
player.sendMessage(invalidSyntax)
12-
return@then
13-
}
14-
15-
player.playAnimation(Animation(id))
7+
.then { player ->
8+
val invalidSyntax = "Invalid syntax - ::animate [animation-id]"
9+
if (valid_arg_length(arguments, 1, player, invalidSyntax)) {
10+
val id = Ints.tryParse(arguments[0])
11+
if (id == null) {
12+
player.sendMessage(invalidSyntax)
13+
return@then
1614
}
17-
}
15+
16+
player.playAnimation(Animation(id))
17+
}
18+
}

game/plugin/cmd/src/bank-cmd.plugin.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import org.apollo.game.model.entity.setting.PrivilegeLevel
22

33
// Opens the player's bank if they are an administrator.
44
on_command("bank", PrivilegeLevel.ADMINISTRATOR)
5-
.then { player -> player.openBank() }
5+
.then { player -> player.openBank() }
Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
import com.google.common.primitives.Ints
22
import org.apollo.cache.def.ItemDefinition
33
import org.apollo.game.model.entity.setting.PrivilegeLevel
4+
import org.apollo.game.plugin.util.command.valid_arg_length
45

56
on_command("item", PrivilegeLevel.ADMINISTRATOR)
6-
.then { player ->
7-
val invalidSyntax = "Invalid syntax - ::item [id] [amount]"
8-
if (!valid_arg_length(arguments, 1..2, player, invalidSyntax)) {
9-
return@then
10-
}
7+
.then { player ->
8+
val invalidSyntax = "Invalid syntax - ::item [id] [amount]"
9+
if (!valid_arg_length(arguments, 1..2, player, invalidSyntax)) {
10+
return@then
11+
}
12+
13+
val id = Ints.tryParse(arguments[0])
14+
if (id == null) {
15+
player.sendMessage(invalidSyntax)
16+
return@then
17+
}
1118

12-
val id = Ints.tryParse(arguments[0])
13-
if (id == null) {
19+
var amount = 1
20+
if (arguments.size == 2) {
21+
val amt = Ints.tryParse(arguments[1])
22+
if (amt == null) {
1423
player.sendMessage(invalidSyntax)
1524
return@then
1625
}
26+
amount = amt
27+
}
1728

18-
var amount = 1
19-
if (arguments.size == 2) {
20-
val amt = Ints.tryParse(arguments[1])
21-
if (amt == null) {
22-
player.sendMessage(invalidSyntax)
23-
return@then
24-
}
25-
amount = amt
26-
}
29+
if (id < 0 || id >= ItemDefinition.count()) {
30+
player.sendMessage("The item id you specified is out of bounds!")
31+
return@then
32+
}
2733

28-
if (id < 0 || id >= ItemDefinition.count()) {
29-
player.sendMessage("The item id you specified is out of bounds!")
30-
return@then
31-
}
32-
33-
if (amount < 0) {
34-
player.sendMessage("The amount you specified is out of bounds!")
35-
return@then
36-
}
34+
if (amount < 0) {
35+
player.sendMessage("The amount you specified is out of bounds!")
36+
return@then
37+
}
3738

38-
player.inventory.add(id, amount)
39-
}
39+
player.inventory.add(id, amount)
40+
}

game/plugin/cmd/src/lookup.plugin.kts

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,65 @@ import org.apollo.cache.def.ItemDefinition
33
import org.apollo.cache.def.NpcDefinition
44
import org.apollo.cache.def.ObjectDefinition
55
import org.apollo.game.model.entity.setting.PrivilegeLevel
6+
import org.apollo.game.plugin.util.command.valid_arg_length
67

78
on_command("iteminfo", PrivilegeLevel.ADMINISTRATOR)
8-
.then { player ->
9-
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
10-
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
11-
return@then
12-
}
9+
.then { player ->
10+
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
11+
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
12+
return@then
13+
}
1314

14-
val id = Ints.tryParse(arguments[0])
15-
if (id == null) {
16-
player.sendMessage(invalidSyntax)
17-
return@then
18-
}
15+
val id = Ints.tryParse(arguments[0])
16+
if (id == null) {
17+
player.sendMessage(invalidSyntax)
18+
return@then
19+
}
1920

20-
val definition = ItemDefinition.lookup(id)
21-
val members = if (definition.isMembersOnly) "members" else "not members"
21+
val definition = ItemDefinition.lookup(id)
22+
val members = if (definition.isMembersOnly) "members" else "not members"
2223

23-
player.sendMessage("Item $id is called ${definition.name}, is $members only, and has a " +
24-
"team of ${definition.team}.")
25-
player.sendMessage("Its description is \"${definition.description}\".")
26-
}
24+
player.sendMessage("Item $id is called ${definition.name}, is $members only, and has a " +
25+
"team of ${definition.team}.")
26+
player.sendMessage("Its description is \"${definition.description}\".")
27+
}
2728

2829
on_command("npcinfo", PrivilegeLevel.ADMINISTRATOR)
29-
.then { player ->
30-
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
31-
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
32-
return@then
33-
}
30+
.then { player ->
31+
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
32+
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
33+
return@then
34+
}
3435

35-
val id = Ints.tryParse(arguments[0])
36-
if (id == null) {
37-
player.sendMessage(invalidSyntax)
38-
return@then
39-
}
36+
val id = Ints.tryParse(arguments[0])
37+
if (id == null) {
38+
player.sendMessage(invalidSyntax)
39+
return@then
40+
}
4041

41-
val definition = NpcDefinition.lookup(id)
42-
val isCombative = if (definition.hasCombatLevel()) "has a combat level of ${definition.combatLevel}" else
43-
"does not have a combat level"
42+
val definition = NpcDefinition.lookup(id)
43+
val isCombative = if (definition.hasCombatLevel()) "has a combat level of ${definition.combatLevel}" else
44+
"does not have a combat level"
4445

45-
player.sendMessage("Npc $id is called ${definition.name} and $isCombative.")
46-
player.sendMessage("Its description is \"${definition.description}\".")
47-
}
46+
player.sendMessage("Npc $id is called ${definition.name} and $isCombative.")
47+
player.sendMessage("Its description is \"${definition.description}\".")
48+
}
4849

4950
on_command("objectinfo", PrivilegeLevel.ADMINISTRATOR)
50-
.then { player ->
51-
val invalidSyntax = "Invalid syntax - ::objectinfo [object id]"
52-
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
53-
return@then
54-
}
51+
.then { player ->
52+
val invalidSyntax = "Invalid syntax - ::objectinfo [object id]"
53+
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
54+
return@then
55+
}
5556

56-
val id = Ints.tryParse(arguments[0])
57-
if (id == null) {
58-
player.sendMessage(invalidSyntax)
59-
return@then
60-
}
57+
val id = Ints.tryParse(arguments[0])
58+
if (id == null) {
59+
player.sendMessage(invalidSyntax)
60+
return@then
61+
}
6162

62-
val definition = ObjectDefinition.lookup(id)
63-
player.sendMessage("Object $id is called ${definition.name} and its description is " +
64-
"\"${definition.description}\".")
65-
player.sendMessage("Its width is ${definition.width} and its length is ${definition.length}.")
66-
}
63+
val definition = ObjectDefinition.lookup(id)
64+
player.sendMessage("Object $id is called ${definition.name} and its description is " +
65+
"\"${definition.description}\".")
66+
player.sendMessage("Its width is ${definition.width} and its length is ${definition.length}.")
67+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import org.apollo.game.model.entity.setting.PrivilegeLevel
22

33
on_command("broadcast", PrivilegeLevel.ADMINISTRATOR)
4-
.then { player ->
5-
val message = arguments.joinToString(" ")
6-
val broadcast = "[Broadcast] ${player.username.capitalize()}: $message"
4+
.then { player ->
5+
val message = arguments.joinToString(" ")
6+
val broadcast = "[Broadcast] ${player.username.capitalize()}: $message"
77

8-
player.world.playerRepository.forEach { other ->
9-
other.sendMessage(broadcast)
10-
}
8+
player.world.playerRepository.forEach { other ->
9+
other.sendMessage(broadcast)
1110
}
11+
}

0 commit comments

Comments
 (0)