Skip to content

Commit

Permalink
feat: add dice
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Oct 12, 2023
1 parent 55450a5 commit 896bf34
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "net.azisaba"
version = "6.7.5"
version = "6.7.6"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/github/mori01231/lifecore/LifeCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import com.github.mori01231.lifecore.command.*
import com.github.mori01231.lifecore.config.*
import com.github.mori01231.lifecore.gui.DropProtectScreen
import com.github.mori01231.lifecore.listener.*
import com.github.mori01231.lifecore.listener.item.GlassHammerItemListener
import com.github.mori01231.lifecore.listener.item.LavaSpongeItemListener
import com.github.mori01231.lifecore.listener.item.OreOnlyItemListener
import com.github.mori01231.lifecore.listener.item.WandItemListener
import com.github.mori01231.lifecore.listener.item.*
import com.github.mori01231.lifecore.network.PacketHandler
import com.github.mori01231.lifecore.region.PlayerRegionManager
import com.github.mori01231.lifecore.util.GCListener
Expand Down Expand Up @@ -253,6 +250,7 @@ class LifeCore : JavaPlugin() {
pm.registerEvents(GameModeChangeLoggerListener(this), this)
pm.registerEvents(FixMythicItemListener, this)
pm.registerEvents(VoidListener, this)
pm.registerEvents(Dice1ItemListener(this), this)

// Items
pm.registerEvents(OreOnlyItemListener(), this)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.github.mori01231.lifecore.listener.item

import com.github.mori01231.lifecore.LifeCore
import com.github.mori01231.lifecore.util.ItemUtil
import org.bukkit.Bukkit
import org.bukkit.GameMode
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerInteractEvent

class Dice1ItemListener(val plugin: LifeCore) : Listener {
private val itemId = "b46ed137-a581-4ee8-b714-c1e136d141f2"
private val prefix = "§f§l【§6§l抽選§f§l】"

@EventHandler
fun onPlayerInteract(e: PlayerInteractEvent) {
if (e.player.gameMode == GameMode.SPECTATOR) {
return
}
if (itemId != ItemUtil.getStringTag(e.item, "LifeItemId")) {
// wrong item
return
}
e.player.sendMessageToNearbyPlayers("$prefix§6§l${e.player.name}§f§lの§a§l抽§b§l選§c§lま§a§lで§b§lえ§c§lえ§a§l.§b§l.§c§l.§a§l.§b§l!§c§l!§a§l!§b§l!§c§l!§a§l!§b§l!")
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, Runnable {
Bukkit.getScheduler().runTask(plugin, Runnable {
e.player.sendMessageToNearbyPlayers("$prefix§a§l3!!!")
})
}, 19)
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, Runnable {
Bukkit.getScheduler().runTask(plugin, Runnable {
e.player.sendMessageToNearbyPlayers("$prefix§b§l2!!!")
})
}, 39)
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, Runnable {
Bukkit.getScheduler().runTask(plugin, Runnable {
e.player.sendMessageToNearbyPlayers("$prefix§c§l1!!!")
})
}, 59)
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, Runnable {
Bukkit.getScheduler().runTask(plugin, Runnable {
val randomPlayer =
e.player
.getNearbyEntities(50.0, 50.0, 50.0)
.filterIsInstance<Player>()
.filter { it.gameMode != GameMode.SPECTATOR && !it.hasMetadata("vanished") }
.randomOrNull()
e.player.sendMessageToNearbyPlayers("§f§l${e.player.name}§6§lの抽選ダイスの結果は§f§l${randomPlayer?.name}§6§lさんになりました!")
})
}, 79)
}

private fun Player.sendMessageToNearbyPlayers(msg: String) {
sendMessage(msg)
getNearbyEntities(50.0, 50.0, 50.0).filterIsInstance<Player>().forEach { player ->
player.sendMessage(msg)
}
}
}

0 comments on commit 896bf34

Please sign in to comment.