-
Notifications
You must be signed in to change notification settings - Fork 8
add inventory ticker #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add inventory ticker #391
Changes from 8 commits
d1daabb
516922e
d361eab
c2d97dc
8963fff
5c09c00
b7758e4
6c2db56
d88737e
46a61f9
8368095
4f2631f
963b620
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package io.github.pylonmc.pylon.core.item | ||
|
|
||
| import io.github.pylonmc.pylon.core.item.base.InventoryTickSpeed | ||
| import io.github.pylonmc.pylon.core.item.base.PylonInventoryItem | ||
| import org.bukkit.Bukkit | ||
|
|
||
| internal class PylonInventoryTicker(private val tickSpeed: InventoryTickSpeed) : Runnable { | ||
| override fun run() { | ||
| for (player in Bukkit.getOnlinePlayers()) { | ||
| for (item in player.inventory) { | ||
| val pylonItem = PylonItem.fromStack(item) | ||
| if (pylonItem is PylonInventoryItem && pylonItem.tickSpeed == tickSpeed) { | ||
| pylonItem.onTick(player, item) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package io.github.pylonmc.pylon.core.item.base | ||
|
|
||
| import org.bukkit.entity.Player | ||
| import org.bukkit.inventory.ItemStack | ||
|
|
||
| /** | ||
| * An item should implement this interface to tick when a player has the item in their inventory | ||
| */ | ||
| interface PylonInventoryItem { | ||
| /** | ||
| * Called once for every player where the item is in their inventory every [tickSpeed] | ||
| * @param player The player whose inventory the item was in | ||
| * @param stack The item itself | ||
| */ | ||
| fun onTick(player: Player, stack: ItemStack) | ||
| /** Speed at which onTick is called */ | ||
|
||
| val tickSpeed: InventoryTickSpeed | ||
| } | ||
|
|
||
| /** | ||
| * Speed at which the inventories are checked for the item: | ||
| * - FAST -> 10 ticks | ||
| * - MEDIUM -> 20 ticks | ||
| * - SLOW -> 40 ticks | ||
| */ | ||
| enum class InventoryTickSpeed(val tickRate: Long) { | ||
| /** Checks for the item every 10 ticks */ | ||
| FAST(10), | ||
| /** Checks for the item every 20 ticks */ | ||
| MEDIUM(20), | ||
| /** Checks for the item every 40 ticks */ | ||
| SLOW(40) | ||
OhmV-IR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.