버그 수정

This commit is contained in:
faiz36 2023-05-14 16:05:15 +09:00
parent a86571b435
commit 49ecbfd718
4 changed files with 58 additions and 46 deletions

View File

@ -35,18 +35,10 @@ class Main:JavaPlugin() {
schedule = this.server.scheduler.runTaskTimerAsynchronously(this, Runnable { schedule = this.server.scheduler.runTaskTimerAsynchronously(this, Runnable {
list.forEach{ list.forEach{
if(list[it.key] == null) return@forEach if(list[it.key] == null) return@forEach
if(!list[it.key]!!.first) return@forEach
if(list[it.key]!!.second == null) return@forEach
if(list[it.key]!!.third == null) return@forEach if(list[it.key]!!.third == null) return@forEach
if(it.value.third!!/1000 + combatData.instance.getTime() <= System.currentTimeMillis()/1000){ if(it.value.third!!/1000 + combatData.instance.getTime() <= System.currentTimeMillis()/1000){
val player = Bukkit.getPlayer(it.key)!!
val damager = Bukkit.getPlayer(list[it.key]!!.second!!)!!
if(combatData.instance.getCanSeeWorld(player.world.name)){
Bukkit.getOnlinePlayers().forEach{ onlinep ->
onlinep.showPlayer(this,player)
onlinep.showPlayer(this,damager)
player.showPlayer(this,onlinep)
damager.showPlayer(this,onlinep)
}
}
list[it.key] = Triple(false,null,null) list[it.key] = Triple(false,null,null)
} }
} }

View File

@ -1,14 +1,13 @@
package group.pvpconnect.combat_f.cmd package group.pvpconnect.combat_f.cmd
import group.pvpconnect.combat_f.Main
import group.pvpconnect.combat_f.data.CombatData import group.pvpconnect.combat_f.data.CombatData
import io.github.monun.kommand.getValue import io.github.monun.kommand.getValue
import io.github.monun.kommand.kommand import io.github.monun.kommand.kommand
import org.bukkit.Bukkit
import org.bukkit.ChatColor import org.bukkit.ChatColor
import org.bukkit.World import org.bukkit.World
import org.bukkit.plugin.Plugin
class CombatCmd(plugin:Plugin, val cd:CombatData) { class CombatCmd(plugin:Main, private val cd:CombatData) {
init { init {
plugin.apply { plugin.apply {
kommand { kommand {
@ -30,16 +29,6 @@ class CombatCmd(plugin:Plugin, val cd:CombatData) {
val world:World by it val world:World by it
val bool = cd.instance.getCanSeeWorld(world.name) val bool = cd.instance.getCanSeeWorld(world.name)
cd.instance.setCanSeeWorld(world.name,!bool) cd.instance.setCanSeeWorld(world.name,!bool)
if(!bool){
Bukkit.getOnlinePlayers().forEach{ pl1 ->
Bukkit.getOnlinePlayers().forEach { pl2 ->
if(pl1.world.name == world.name || pl2.world.name == world.name){
pl1.showPlayer(plugin,pl2)
pl2.showPlayer(plugin,pl1)
}
}
}
}
sender.sendMessage("${ChatColor.BOLD}${ChatColor.GOLD}[${ChatColor.GREEN}${ChatColor.GOLD}] ${ChatColor.WHITE}${world.name}의 컴뱃중 다른 사람 볼수있음이 ${if(!bool)"활성화 되었습니다!" else "비활성화 되었습니다!"}") sender.sendMessage("${ChatColor.BOLD}${ChatColor.GOLD}[${ChatColor.GREEN}${ChatColor.GOLD}] ${ChatColor.WHITE}${world.name}의 컴뱃중 다른 사람 볼수있음이 ${if(!bool)"활성화 되었습니다!" else "비활성화 되었습니다!"}")
} }
} }

View File

@ -5,7 +5,7 @@ import org.bukkit.plugin.Plugin
import java.io.File import java.io.File
@Suppress("unused") @Suppress("unused")
class CombatData(val plugin:Plugin) { class CombatData(private val plugin:Plugin) {
var instance:CombatData = this var instance:CombatData = this
private val file get() = File(plugin.dataFolder, "data.yml") private val file get() = File(plugin.dataFolder, "data.yml")

View File

@ -11,6 +11,7 @@ import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageByEntityEvent import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.entity.PlayerDeathEvent import org.bukkit.event.entity.PlayerDeathEvent
import org.bukkit.event.entity.ProjectileHitEvent import org.bukkit.event.entity.ProjectileHitEvent
import org.bukkit.event.player.PlayerChangedWorldEvent
import org.bukkit.event.player.PlayerCommandPreprocessEvent import org.bukkit.event.player.PlayerCommandPreprocessEvent
import org.bukkit.event.player.PlayerQuitEvent import org.bukkit.event.player.PlayerQuitEvent
@ -30,18 +31,24 @@ class CombatEvent(private val plugin:Main, private val combatData: CombatData):L
val dlist = plugin.instance.list[e.damager.uniqueId] val dlist = plugin.instance.list[e.damager.uniqueId]
if((dlist?.second != null) && (dlist.second != e.entity.uniqueId)&& !combatData.instance.getOtherHit(e.entity.world.name)){ e.isCancelled = true;return} if((dlist?.second != null) && (dlist.second != e.entity.uniqueId)&& !combatData.instance.getOtherHit(e.entity.world.name)){ e.isCancelled = true;return}
if(list?.second != null && list.second != e.damager.uniqueId && !combatData.instance.getOtherHit(e.entity.world.name)) { if(list?.second != null && list.second != e.damager.uniqueId && !combatData.instance.getOtherHit(e.entity.world.name)) {
e.damager.sendMessage("${ChatColor.RED}${ChatColor.BOLD}해당 플레이어는 ${ChatColor.RESET}${ChatColor.WHITE}${Bukkit.getPlayer( e.damager.sendMessage(
list.second!!)!!.name}${ChatColor.RED}${ChatColor.BOLD}님과 전투중입니다!") "${ChatColor.RED}${ChatColor.BOLD}해당 플레이어는 ${ChatColor.RESET}${ChatColor.WHITE}${
Bukkit.getPlayer(
list.second!!
)!!.name
}${ChatColor.RED}${ChatColor.BOLD}님과 전투중입니다!"
)
e.isCancelled = true e.isCancelled = true
return return
} }
if(combatData.instance.getCanSeeWorld(e.entity.world.name)){ if(combatData.instance.getCanSeeWorld(e.entity.world.name) && !plugin.instance.list[e.entity.uniqueId]!!.first){
Bukkit.getOnlinePlayers().forEach{ Bukkit.getOnlinePlayers().forEach {
if(it.uniqueId == e.damager.uniqueId || it.uniqueId == e.entity.uniqueId){ if(it.name != e.entity.name && it.name != e.damager.name){
return@forEach it.hidePlayer(plugin,e.entity as Player)
} it.hidePlayer(plugin,e.damager as Player)
(e.damager as Player).hidePlayer(plugin,it)
(e.entity as Player).hidePlayer(plugin,it) (e.entity as Player).hidePlayer(plugin,it)
(e.damager as Player).hidePlayer(plugin, it)
}
} }
} }
plugin.instance.list[e.entity.uniqueId] = Triple(true,e.damager.uniqueId,System.currentTimeMillis()) plugin.instance.list[e.entity.uniqueId] = Triple(true,e.damager.uniqueId,System.currentTimeMillis())
@ -67,13 +74,14 @@ class CombatEvent(private val plugin:Main, private val combatData: CombatData):L
return return
} }
if(player.uniqueId == shooter.uniqueId) return if(player.uniqueId == shooter.uniqueId) return
if(combatData.instance.getCanSeeWorld(e.entity.world.name)){ if(combatData.instance.getCanSeeWorld(player.world.name) && !plugin.instance.list[player.uniqueId]!!.first){
Bukkit.getOnlinePlayers().forEach{ Bukkit.getOnlinePlayers().forEach {
if(it.uniqueId == shooter.uniqueId || it.uniqueId == player.uniqueId){ if(it.name != player.name && it.name != shooter.name){
return@forEach it.hidePlayer(plugin, player)
} it.hidePlayer(plugin,shooter)
shooter.hidePlayer(plugin,it)
player.hidePlayer(plugin,it) player.hidePlayer(plugin,it)
shooter.hidePlayer(plugin, it)
}
} }
} }
plugin.instance.list[player.uniqueId] = Triple(true,shooter.uniqueId,System.currentTimeMillis()) plugin.instance.list[player.uniqueId] = Triple(true,shooter.uniqueId,System.currentTimeMillis())
@ -96,10 +104,15 @@ class CombatEvent(private val plugin:Main, private val combatData: CombatData):L
e.player.killer = Bukkit.getPlayer(list.second!!) e.player.killer = Bukkit.getPlayer(list.second!!)
e.player.health = 0.0 e.player.health = 0.0
if(combatData.instance.getCanSeeWorld(e.player.world.name)){ if(combatData.instance.getCanSeeWorld(e.player.world.name)){
Bukkit.getOnlinePlayers().forEach{ Bukkit.getOnlinePlayers().forEach {
if(it.uniqueId == e.player.uniqueId || it.uniqueId == e.player.killer!!.uniqueId) return@forEach val player = e.player
e.player.showPlayer(plugin,it) val killer = e.player.killer!!
e.player.killer!!.showPlayer(plugin,it) if(it.name != player.name && it.name != killer.name){
it.showPlayer(plugin, player)
it.showPlayer(plugin,killer)
player.showPlayer(plugin,it)
killer.showPlayer(plugin, it)
}
} }
} }
plugin.instance.list[e.player.uniqueId] = Triple(false,null,null) plugin.instance.list[e.player.uniqueId] = Triple(false,null,null)
@ -111,14 +124,32 @@ class CombatEvent(private val plugin:Main, private val combatData: CombatData):L
val list = plugin.instance.list[e.player.uniqueId] ?: return val list = plugin.instance.list[e.player.uniqueId] ?: return
if(!list.first) return if(!list.first) return
if(combatData.instance.getCanSeeWorld(e.player.world.name)){ if(combatData.instance.getCanSeeWorld(e.player.world.name)){
Bukkit.getOnlinePlayers().forEach{ Bukkit.getOnlinePlayers().forEach {
if(it.uniqueId == e.player.uniqueId || it.uniqueId == e.player.killer!!.uniqueId) return@forEach val player = e.player
e.player.showPlayer(plugin,it) val killer = e.player.killer!!
e.player.killer!!.showPlayer(plugin,it) if(it.name != player.name && it.name != killer.name){
it.showPlayer(plugin, player)
it.showPlayer(plugin,killer)
player.showPlayer(plugin,it)
killer.showPlayer(plugin, it)
}
} }
} }
plugin.instance.list[e.player.uniqueId] = Triple(false,null,null) plugin.instance.list[e.player.uniqueId] = Triple(false,null,null)
plugin.instance.list[list.second!!] = Triple(false,null,null) plugin.instance.list[list.second!!] = Triple(false,null,null)
} }
@EventHandler
fun onChangeWorld(e:PlayerChangedWorldEvent){
if(combatData.instance.getCanSeeWorld(e.player.world.name)){
Bukkit.getOnlinePlayers().forEach{
if(it.world.name != e.player.world.name) return@forEach
if(plugin.instance.list[it.uniqueId]?.first == true){
it.hidePlayer(plugin,e.player)
e.player.hidePlayer(plugin,it)
}
}
}
}
} }