From 896bf346d3a41cbbaf96b20e2819611c2f9cd98b Mon Sep 17 00:00:00 2001 From: acrylic-style Date: Thu, 12 Oct 2023 13:03:25 +0900 Subject: [PATCH] feat: add dice --- build.gradle.kts | 2 +- .../com/github/mori01231/lifecore/LifeCore.kt | 6 +- .../listener/item/Dice1ItemListener.kt | 60 +++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/github/mori01231/lifecore/listener/item/Dice1ItemListener.kt diff --git a/build.gradle.kts b/build.gradle.kts index 1516e22..75cf77a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "net.azisaba" -version = "6.7.5" +version = "6.7.6" java { toolchain.languageVersion.set(JavaLanguageVersion.of(8)) diff --git a/src/main/java/com/github/mori01231/lifecore/LifeCore.kt b/src/main/java/com/github/mori01231/lifecore/LifeCore.kt index b382dd8..6ce79a8 100644 --- a/src/main/java/com/github/mori01231/lifecore/LifeCore.kt +++ b/src/main/java/com/github/mori01231/lifecore/LifeCore.kt @@ -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 @@ -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) diff --git a/src/main/java/com/github/mori01231/lifecore/listener/item/Dice1ItemListener.kt b/src/main/java/com/github/mori01231/lifecore/listener/item/Dice1ItemListener.kt new file mode 100644 index 0000000..cf1643b --- /dev/null +++ b/src/main/java/com/github/mori01231/lifecore/listener/item/Dice1ItemListener.kt @@ -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() + .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().forEach { player -> + player.sendMessage(msg) + } + } +}