Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
個別でミュートするのではなくまとめてミュートする様に変更
Browse files Browse the repository at this point in the history
非同期でミュートする様に変更
  • Loading branch information
sya-ri committed Apr 3, 2021
1 parent fadd983 commit f677f3e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 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 {
id("net.minecrell.plugin-yml.bukkit") version "0.3.0"
}

version = "1.0.4"
version = "1.1.0"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ object DiscordClient {
}
}

private val speakingPlayers = mutableSetOf<UUIDPlayer>()
private val lastMute = mutableMapOf<Long, Boolean>()
private val muteCoolTime = mutableSetOf<UUIDPlayer>()

Expand All @@ -77,6 +78,11 @@ object DiscordClient {
val member = guild.getMemberById(userId) ?: return "ユーザーが見つかりませんでした"
return try {
member.mute(mute).submit().join()
if (mute) {
speakingPlayers.remove(uuidPlayer)
} else {
speakingPlayers.add(uuidPlayer)
}
null
} catch (ex: InsufficientPermissionException) {
"ボットの権限がありません"
Expand All @@ -87,6 +93,18 @@ object DiscordClient {
}
}

fun muteAll(): List<Pair<String, String>> {
val errorMessages = mutableListOf<Pair<String, String>>()
speakingPlayers.toList().forEach { uuidPlayer ->
uuidPlayer.player?.let { player ->
mute(player, true)?.let {
errorMessages.add(player.name to it)
}
}
}
return errorMessages
}

private val lastRoom = mutableMapOf<Long, Long>()

fun move(player: Player, room: Long): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import com.github.syari.plugin.talk.with.near.player.mainHand.MainHandItem.Compa
import com.github.syari.plugin.talk.with.near.player.templateMessage
import com.github.syari.plugin.talk.with.near.player.toColor
import com.github.syari.spigot.api.event.events
import com.github.syari.spigot.api.scheduler.runTask
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.block.Action
import org.bukkit.event.player.PlayerInteractEntityEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.ItemStack

object ToggleMuteUseItem {
Expand All @@ -34,21 +36,20 @@ object ToggleMuteUseItem {
val mainHandItem = mainHandItem.getFromInventory(player.inventory)
if (mainHandItem.isSimilar(item)) {
val targetPlayer = e.rightClicked as? Player ?: return@event
DiscordClient.mute(targetPlayer, false)?.let {
player.sendMessage(templateMessage("&c$it"))
plugin.runTask(async = true) {
DiscordClient.mute(targetPlayer, false)?.let {
player.sendMessage(templateMessage("&c$it"))
}
}
}
}
}
event<EntityDamageByEntityEvent> { e ->
if (Mode.mode == Mode.Item) {
val player = e.damager as? Player ?: return@event
val mainHandItem = mainHandItem.getFromInventory(player.inventory)
if (mainHandItem.isSimilar(item)) {
val targetPlayer = e.entity as? Player ?: return@event
e.isCancelled = true
DiscordClient.mute(targetPlayer, true)?.let {
player.sendMessage(templateMessage("&c$it"))
event<PlayerInteractEvent> { e ->
if (Mode.mode == Mode.Item && e.action == Action.LEFT_CLICK_AIR) {
val player = e.player
plugin.runTask(async = true) {
DiscordClient.muteAll().forEach { (name, message) ->
player.sendMessage(templateMessage("&c$name: $message"))
}
}
}
Expand Down

0 comments on commit f677f3e

Please sign in to comment.