-
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
Merged
Merged
add inventory ticker #391
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d1daabb
add inventory ticker
OhmV-IR 516922e
make not internal
OhmV-IR d361eab
kotlin kult kan not win
OhmV-IR c2d97dc
Apply suggestion from @Seggan
OhmV-IR 8963fff
kdoc thy classes
OhmV-IR 5c09c00
fixup
OhmV-IR b7758e4
Merge branch 'add-inventory-ticker' of https://github.com/pylonmc/pyl…
OhmV-IR 6c2db56
Update pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/b…
OhmV-IR d88737e
don't pass stack
OhmV-IR 46a61f9
Merge branch 'add-inventory-ticker' of https://github.com/pylonmc/pyl…
OhmV-IR 8368095
pr comments
OhmV-IR 4f2631f
add to cfg file
OhmV-IR 963b620
Merge branch 'master' into add-inventory-ticker
OhmV-IR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
18 changes: 18 additions & 0 deletions
18
pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/PylonInventoryTicker.kt
This file contains hidden or 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,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) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/base/PylonInventoryItem.kt
This file contains hidden or 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,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 */ | ||
OhmV-IR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.