Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.github.shynixn.mccoroutine.bukkit.ticks
import io.github.pylonmc.pylon.core.addon.PylonAddon
import io.github.pylonmc.pylon.core.block.*
import io.github.pylonmc.pylon.core.block.base.*
import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureEngine
import io.github.pylonmc.pylon.core.block.waila.Waila
import io.github.pylonmc.pylon.core.command.ROOT_COMMAND
import io.github.pylonmc.pylon.core.command.ROOT_COMMAND_PY_ALIAS
Expand All @@ -23,16 +22,19 @@ import io.github.pylonmc.pylon.core.entity.EntityStorage
import io.github.pylonmc.pylon.core.entity.PylonEntity
import io.github.pylonmc.pylon.core.fluid.connecting.ConnectingService
import io.github.pylonmc.pylon.core.i18n.PylonTranslator
import io.github.pylonmc.pylon.core.item.PylonInventoryTicker
import io.github.pylonmc.pylon.core.item.PylonItem
import io.github.pylonmc.pylon.core.item.PylonItemListener
import io.github.pylonmc.pylon.core.item.base.InventoryTickSpeed
import io.github.pylonmc.pylon.core.item.research.Research
import io.github.pylonmc.pylon.core.metrics.PylonMetrics
import io.github.pylonmc.pylon.core.recipe.ConfigurableRecipeType
import io.github.pylonmc.pylon.core.recipe.PylonRecipeListener
import io.github.pylonmc.pylon.core.recipe.RecipeType
import io.github.pylonmc.pylon.core.registry.PylonRegistry
import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureConfig
import io.github.pylonmc.pylon.core.resourcepack.armor.ArmorTextureEngine
import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureConfig
import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureEngine
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents
import kotlinx.coroutines.delay
Expand All @@ -44,7 +46,6 @@ import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.configuration.file.YamlConfiguration
import org.bukkit.entity.BlockDisplay
import org.bukkit.entity.Interaction
import org.bukkit.entity.ItemDisplay
import org.bukkit.permissions.Permission
Expand Down Expand Up @@ -94,6 +95,9 @@ object PylonCore : JavaPlugin(), PylonAddon {
Bukkit.getPluginManager().registerEvents(BlockStorage, this)
Bukkit.getPluginManager().registerEvents(BlockListener, this)
Bukkit.getPluginManager().registerEvents(PylonItemListener, this)
for (speed in InventoryTickSpeed.entries) {
Bukkit.getScheduler().runTaskTimer(this, PylonInventoryTicker(speed), 0, speed.tickRate)
}
Bukkit.getPluginManager().registerEvents(TickManager, this)
Bukkit.getPluginManager().registerEvents(MultiblockCache, this)
Bukkit.getPluginManager().registerEvents(EntityStorage, this)
Expand Down
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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting (space above and should be 3 lines, like the comment for PylonInventoryItem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not entirely sure what this was asking me to do, but I think I did it

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)
}