Skip to content

Commit a5a2391

Browse files
authored
Merge pull request #134 from pylonmc/refactor-item-ifaces
Refactor item interface names
2 parents 3d45fd8 + bc4ad65 commit a5a2391

17 files changed

Lines changed: 76 additions & 45 deletions

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/debug/DebugWaxedWeatheredCutCopperStairs.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import io.github.pylonmc.pylon.core.entity.EntityStorage
77
import io.github.pylonmc.pylon.core.event.PylonBlockSerializeEvent
88
import io.github.pylonmc.pylon.core.i18n.PylonArgument
99
import io.github.pylonmc.pylon.core.item.PylonItem
10-
import io.github.pylonmc.pylon.core.item.base.BlockInteractor
11-
import io.github.pylonmc.pylon.core.item.base.EntityInteractor
10+
import io.github.pylonmc.pylon.core.item.base.PylonBlockInteractor
11+
import io.github.pylonmc.pylon.core.item.base.PylonItemEntityInteractor
1212
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
1313
import io.github.pylonmc.pylon.core.nms.NmsAccessor
1414
import io.github.pylonmc.pylon.core.util.pylonKey
@@ -23,7 +23,7 @@ import org.bukkit.inventory.ItemStack
2323

2424
@Suppress("UnstableApiUsage")
2525
class DebugWaxedWeatheredCutCopperStairs(stack: ItemStack)
26-
: PylonItem(stack), BlockInteractor, EntityInteractor {
26+
: PylonItem(stack), PylonBlockInteractor, PylonItemEntityInteractor {
2727

2828
override fun onUsedToClickBlock(event: PlayerInteractEvent) {
2929
val block = event.clickedBlock ?: return

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/entity/EntityListener.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import io.github.pylonmc.pylon.core.entity.base.PylonInteractableEntity
55
import io.github.pylonmc.pylon.core.entity.base.PylonUnloadEntity
66
import io.github.pylonmc.pylon.core.event.PylonEntityDeathEvent
77
import io.github.pylonmc.pylon.core.event.PylonEntityUnloadEvent
8+
import io.github.pylonmc.pylon.core.item.PylonItem
9+
import io.github.pylonmc.pylon.core.item.base.PylonArrow
10+
import org.bukkit.entity.AbstractArrow
811
import org.bukkit.event.EventHandler
912
import org.bukkit.event.EventPriority
1013
import org.bukkit.event.Listener
14+
import org.bukkit.event.entity.EntityDamageByEntityEvent
15+
import org.bukkit.event.entity.ProjectileHitEvent
1116
import org.bukkit.event.player.PlayerInteractEntityEvent
1217

1318
object EntityListener : Listener {
@@ -33,4 +38,24 @@ object EntityListener : Listener {
3338
event.pylonEntity.onDeath(event)
3439
}
3540
}
41+
42+
@EventHandler
43+
fun handle(event: ProjectileHitEvent) {
44+
if (event.entity is AbstractArrow) {
45+
val arrowItem = PylonItem.fromStack((event.entity as AbstractArrow).itemStack)
46+
if (arrowItem is PylonArrow) {
47+
arrowItem.onArrowHit(event)
48+
}
49+
}
50+
}
51+
52+
@EventHandler
53+
fun handle(event: EntityDamageByEntityEvent) {
54+
if (event.damager is AbstractArrow) {
55+
val arrowItem = PylonItem.fromStack((event.damager as AbstractArrow).itemStack)
56+
if (arrowItem is PylonArrow) {
57+
arrowItem.onArrowDamage(event)
58+
}
59+
}
60+
}
3661
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/PylonGuide.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package io.github.pylonmc.pylon.core.guide
22

3-
import io.github.pylonmc.pylon.core.guide.pages.fluid.FluidsPage
3+
import io.github.pylonmc.pylon.core.guide.pages.InfoPage
44
import io.github.pylonmc.pylon.core.guide.pages.RootPage
55
import io.github.pylonmc.pylon.core.guide.pages.SearchItemsAndFluidsPage
66
import io.github.pylonmc.pylon.core.guide.pages.SettingsAndInfoPage
7-
import io.github.pylonmc.pylon.core.guide.pages.InfoPage
87
import io.github.pylonmc.pylon.core.guide.pages.base.GuidePage
8+
import io.github.pylonmc.pylon.core.guide.pages.fluid.FluidsPage
99
import io.github.pylonmc.pylon.core.guide.pages.research.ResearchesPage
1010
import io.github.pylonmc.pylon.core.item.PylonItem
11-
import io.github.pylonmc.pylon.core.item.base.Interactor
11+
import io.github.pylonmc.pylon.core.item.base.PylonInteractor
1212
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
1313
import io.github.pylonmc.pylon.core.util.pylonKey
1414
import org.bukkit.Material
1515
import org.bukkit.NamespacedKey
1616
import org.bukkit.entity.Player
1717
import org.bukkit.event.player.PlayerInteractEvent
1818
import org.bukkit.inventory.ItemStack
19-
import java.util.UUID
19+
import java.util.*
2020

21-
class PylonGuide(stack: ItemStack) : PylonItem(stack), Interactor {
21+
class PylonGuide(stack: ItemStack) : PylonItem(stack), PylonInteractor {
2222

2323
override fun onUsedToRightClick(event: PlayerInteractEvent) {
2424
if (event.action.isRightClick) {

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/PylonItemListener.kt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal object PylonItemListener : Listener {
2828
event.isCancelled = true
2929
return
3030
}
31-
if (bow is Bow) {
31+
if (bow is PylonBow) {
3232
bow.onBowReady(event)
3333
}
3434

@@ -37,20 +37,20 @@ internal object PylonItemListener : Listener {
3737
event.isCancelled = true
3838
return
3939
}
40-
if (arrow is Arrow) {
40+
if (arrow is PylonArrow) {
4141
arrow.onArrowReady(event)
4242
}
4343
}
4444

4545
@EventHandler
4646
private fun handle(event: EntityShootBowEvent) {
4747
val bow = event.bow?.let { PylonItem.fromStack(it) }
48-
if (bow is Bow) {
48+
if (bow is PylonBow) {
4949
bow.onBowFired(event)
5050
}
5151

5252
val arrow = event.consumable?.let { PylonItem.fromStack(it) }
53-
if (arrow is Arrow) {
53+
if (arrow is PylonArrow) {
5454
arrow.onArrowShotFromBow(event)
5555
}
5656
}
@@ -63,22 +63,22 @@ internal object PylonItemListener : Listener {
6363
return
6464
}
6565
if (
66-
pylonItem is Cooldownable &&
66+
pylonItem is PylonCooldownable &&
6767
event.player.getCooldown(pylonItem.stack) > 0 &&
6868
pylonItem.respectCooldown
6969
) return
70-
if (pylonItem is BlockInteractor && event.hasBlock()) {
70+
if (pylonItem is PylonBlockInteractor && event.hasBlock()) {
7171
pylonItem.onUsedToClickBlock(event)
7272
}
73-
if (pylonItem is Interactor) {
73+
if (pylonItem is PylonInteractor) {
7474
pylonItem.onUsedToRightClick(event)
7575
}
7676
}
7777

7878
@EventHandler
7979
private fun handle(event: BrewingStandFuelEvent) {
8080
val pylonItem = PylonItem.fromStack(event.fuel)
81-
if (pylonItem is BrewingStandFuel) {
81+
if (pylonItem is PylonBrewingStandFuel) {
8282
pylonItem.onUsedAsBrewingStandFuel(event)
8383
}
8484
}
@@ -90,7 +90,7 @@ internal object PylonItemListener : Listener {
9090
event.isCancelled = true
9191
return
9292
}
93-
if (pylonItem is Bucket) {
93+
if (pylonItem is PylonBucket) {
9494
pylonItem.onBucketEmptied(event)
9595
}
9696
}
@@ -102,7 +102,7 @@ internal object PylonItemListener : Listener {
102102
event.isCancelled = true
103103
return
104104
}
105-
if (pylonItem is Bucket) {
105+
if (pylonItem is PylonBucket) {
106106
pylonItem.onBucketFilled(event)
107107
}
108108
}
@@ -114,7 +114,7 @@ internal object PylonItemListener : Listener {
114114
event.isCancelled = true
115115
return
116116
}
117-
if (pylonItem is Consumable) {
117+
if (pylonItem is PylonConsumable) {
118118
pylonItem.onConsumed(event)
119119
}
120120
}
@@ -125,7 +125,7 @@ internal object PylonItemListener : Listener {
125125
if (pylonItem != null && !event.player.canUse(pylonItem, true)) {
126126
return
127127
}
128-
if (pylonItem is Damageable) {
128+
if (pylonItem is PylonItemDamageable) {
129129
pylonItem.onItemDamaged(event)
130130
}
131131
}
@@ -136,7 +136,7 @@ internal object PylonItemListener : Listener {
136136
if (pylonItem != null && !event.player.canUse(pylonItem, true)) {
137137
return
138138
}
139-
if (pylonItem is Damageable) {
139+
if (pylonItem is PylonItemDamageable) {
140140
pylonItem.onItemBreaks(event)
141141
}
142142
}
@@ -148,7 +148,7 @@ internal object PylonItemListener : Listener {
148148
event.isCancelled = true
149149
return
150150
}
151-
if (pylonItem is Damageable && event.player.canUse(pylonItem, true)) {
151+
if (pylonItem is PylonItemDamageable && event.player.canUse(pylonItem, true)) {
152152
pylonItem.onItemMended(event)
153153
}
154154
}
@@ -160,7 +160,7 @@ internal object PylonItemListener : Listener {
160160
event.isCancelled = true
161161
return
162162
}
163-
if (pylonItemMainHand is EntityInteractor &&
163+
if (pylonItemMainHand is PylonItemEntityInteractor &&
164164
!(event.player.getCooldown(pylonItemMainHand.stack) > 0 && pylonItemMainHand.respectCooldown)
165165
) {
166166
pylonItemMainHand.onUsedToRightClickEntity(event)
@@ -171,7 +171,7 @@ internal object PylonItemListener : Listener {
171171
event.isCancelled = true
172172
return
173173
}
174-
if (pylonItemOffHand is EntityInteractor &&
174+
if (pylonItemOffHand is PylonItemEntityInteractor &&
175175
!(event.player.getCooldown(pylonItemOffHand.stack) > 0 && pylonItemOffHand.respectCooldown)
176176
) {
177177
pylonItemOffHand.onUsedToRightClickEntity(event)
@@ -195,7 +195,7 @@ internal object PylonItemListener : Listener {
195195
event.isCancelled = true
196196
return
197197
}
198-
if (pylonItem is Tool) {
198+
if (pylonItem is PylonTool) {
199199
pylonItem.onUsedToDamageBlock(event)
200200
}
201201
}
@@ -207,7 +207,7 @@ internal object PylonItemListener : Listener {
207207
event.isCancelled = true
208208
return
209209
}
210-
if (pylonItemMainHand is Tool) {
210+
if (pylonItemMainHand is PylonTool) {
211211
pylonItemMainHand.onUsedToBreakBlock(event)
212212
}
213213

@@ -216,7 +216,7 @@ internal object PylonItemListener : Listener {
216216
event.isCancelled = true
217217
return
218218
}
219-
if (pylonItemOffHand is Tool) {
219+
if (pylonItemOffHand is PylonTool) {
220220
pylonItemOffHand.onUsedToBreakBlock(event)
221221
}
222222
}
@@ -231,7 +231,7 @@ internal object PylonItemListener : Listener {
231231
event.isCancelled = true
232232
return
233233
}
234-
if (pylonItemMainHand is Weapon) {
234+
if (pylonItemMainHand is PylonWeapon) {
235235
pylonItemMainHand.onUsedToDamageEntity(event)
236236
}
237237

@@ -240,7 +240,7 @@ internal object PylonItemListener : Listener {
240240
event.isCancelled = true
241241
return
242242
}
243-
if (pylonItemOffHand is Weapon) {
243+
if (pylonItemOffHand is PylonWeapon) {
244244
pylonItemOffHand.onUsedToDamageEntity(event)
245245
}
246246
}
@@ -256,7 +256,7 @@ internal object PylonItemListener : Listener {
256256
event.isCancelled = true
257257
return
258258
}
259-
if (pylonItemMainHand is Weapon) {
259+
if (pylonItemMainHand is PylonWeapon) {
260260
pylonItemMainHand.onUsedToKillEntity(event)
261261
}
262262

@@ -265,7 +265,7 @@ internal object PylonItemListener : Listener {
265265
event.isCancelled = true
266266
return
267267
}
268-
if (pylonItemOffHand is Weapon) {
268+
if (pylonItemOffHand is PylonWeapon) {
269269
pylonItemOffHand.onUsedToKillEntity(event)
270270
}
271271
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/Arrow.kt renamed to pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/PylonArrow.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.github.pylonmc.pylon.core.item.base
22

33
import com.destroystokyo.paper.event.player.PlayerReadyArrowEvent
4+
import org.bukkit.event.entity.EntityDamageByEntityEvent
45
import org.bukkit.event.entity.EntityShootBowEvent
6+
import org.bukkit.event.entity.ProjectileHitEvent
57

6-
interface Arrow {
8+
interface PylonArrow {
79
/**
810
* Called when the arrow is shot from the bow of any entity
911
*/
@@ -13,4 +15,8 @@ interface Arrow {
1315
* Called when the arrow is shot from the bow of any entity
1416
*/
1517
fun onArrowShotFromBow(event: EntityShootBowEvent) {}
18+
19+
fun onArrowHit(event: ProjectileHitEvent) {}
20+
21+
fun onArrowDamage(event: EntityDamageByEntityEvent) {}
1622
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/BlockInteractor.kt renamed to pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/PylonBlockInteractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package io.github.pylonmc.pylon.core.item.base
22

33
import org.bukkit.event.player.PlayerInteractEvent
44

5-
interface BlockInteractor : Cooldownable {
5+
interface PylonBlockInteractor : PylonCooldownable {
66
/**
77
* Called when a player clicks a block while holding the item
88
*/

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/Bow.kt renamed to pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/PylonBow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.github.pylonmc.pylon.core.item.base
33
import com.destroystokyo.paper.event.player.PlayerReadyArrowEvent
44
import org.bukkit.event.entity.EntityShootBowEvent
55

6-
interface Bow {
6+
interface PylonBow {
77
/**
88
* Called when the arrow is shot from the bow of any entity
99
*/

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/BrewingStandFuel.kt renamed to pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/PylonBrewingStandFuel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package io.github.pylonmc.pylon.core.item.base
22

33
import org.bukkit.event.inventory.BrewingStandFuelEvent
44

5-
interface BrewingStandFuel {
5+
interface PylonBrewingStandFuel {
66
/**
77
* Called when the item is consumed as fuel in a brewing stand
88
*/

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/Bucket.kt renamed to pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/PylonBucket.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.github.pylonmc.pylon.core.item.base
33
import org.bukkit.event.player.PlayerBucketEmptyEvent
44
import org.bukkit.event.player.PlayerBucketFillEvent
55

6-
interface Bucket {
6+
interface PylonBucket {
77
/**
88
* Called when the bucket is emptied
99
*/

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/Consumable.kt renamed to pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/PylonConsumable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package io.github.pylonmc.pylon.core.item.base
22

33
import org.bukkit.event.player.PlayerItemConsumeEvent
44

5-
interface Consumable {
5+
interface PylonConsumable {
66
/**
77
* Called when the item is consumed by a player
88
*/

0 commit comments

Comments
 (0)