Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Tems-py committed Nov 3, 2023
1 parent c2852ca commit 7c18ebe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EntityResurrectListener(private var plugin: Tetotem) : Listener {
fun entityResurrectEvent(event: EntityResurrectEvent) {
if (!event.isCancelled) {
if (event.entity.type == EntityType.PLAYER){
plugin.lastTotem[event.entity.uniqueId] = plugin.server.tickTimes.last()
plugin.lastTotem[event.entity.uniqueId] = plugin.i
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ class InventoryClickEvent(private val plugin: Tetotem) : Listener {

@EventHandler
fun inventoryClickEvent(event: InventoryClickEvent) {
println(plugin.i)
val item = event.cursor
val player = event.whoClicked
val ticks = plugin.config.getInt("maximumAllowedTicksToChangeTotem")
if (item.type != Material.TOTEM_OF_UNDYING || event.slot != 40) return
if (plugin.lastTotem[player.uniqueId] == null) return

val lastUse = plugin.lastTotem[player.uniqueId] ?: return
if (plugin.server.tickTimes.last().minus(lastUse) > ticks) return
if (plugin.i.minus(lastUse) > ticks) return

val mm = MiniMessage.miniMessage();
if (plugin.config.getString("adminMessage") == null) {
Expand Down Expand Up @@ -55,11 +56,14 @@ class InventoryClickEvent(private val plugin: Tetotem) : Listener {
val commands = plugin.config.getList("punishments") ?: return
if (flags[player.uniqueId]!! < plugin.config.getInt("punishAfterFlags")) return

plugin.lastTotem = HashMap<UUID, Long>()
flags = HashMap<UUID, Int>()
for (command in commands) {
plugin.server.dispatchCommand(
plugin.server.consoleSender,
command.toString().replace("%player%", player.name)
)
plugin.i = 0
}
}
}
22 changes: 17 additions & 5 deletions src/main/java/org/tems/ttotem/Tetotem.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package org.tems.ttotem

import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin
import org.tems.ttotem.Listeners.EntityResurrectListener
import org.tems.ttotem.Listeners.InventoryClickEvent
import java.util.*
import kotlin.collections.HashMap


class Tetotem : JavaPlugin() {
var lastTotem: HashMap<UUID, Long> = HashMap<UUID, Long>()

var i: Long = 0
override fun onEnable() {
logger.info("Staring plugin")
saveDefaultConfig()
registerListeners()

val config = getConfig()
logger.info("maximumAllowedTicksToChangeTotem: " + config.getInt("maximumAllowedTicksToChangeTotem").toString())
countTicks()
}

private fun registerListeners() {
Expand All @@ -25,6 +23,20 @@ class Tetotem : JavaPlugin() {
logger.info("Registered listeners")
}

private fun countTicks() {
Bukkit.getScheduler().runTaskTimerAsynchronously(
this,
Runnable {
i += 1;
if (i > 372036854775807){
i = 0
}
},
0L,
1L
)
}

override fun onDisable() {
logger.info("Stopping plugin")
}
Expand Down

0 comments on commit 7c18ebe

Please sign in to comment.