-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55450a5
commit 896bf34
Showing
3 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/github/mori01231/lifecore/listener/item/Dice1ItemListener.kt
This file contains 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,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) | ||
} | ||
} | ||
} |