마지막이 될수도 있는

This commit is contained in:
faiz36 2023-04-01 14:13:05 +09:00
parent e3393fdc4c
commit a948a1ff08
4 changed files with 40 additions and 33 deletions

View File

@ -1,6 +1,6 @@
plugins { plugins {
kotlin("jvm") version "1.8.0" kotlin("jvm") version "1.8.0"
// id("io.papermc.paperweight.userdev") version "1.5.3" id("io.papermc.paperweight.userdev") version "1.5.3"
} }
group = "group.pvpconnect" group = "group.pvpconnect"
@ -8,7 +8,7 @@ version = "1.0-SNAPSHOT"
repositories { repositories {
mavenCentral() mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/") // maven("https://repo.papermc.io/repository/maven-public/")
} }
java { java {
@ -17,8 +17,8 @@ java {
dependencies { dependencies {
testImplementation(kotlin("test")) testImplementation(kotlin("test"))
compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT") // compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")
// paperweight.paperDevBundle("1.19.2-R0.1-SNAPSHOT") paperweight.paperDevBundle("1.19.2-R0.1-SNAPSHOT")
implementation("io.github.monun:kommand-api:3.1.3") implementation("io.github.monun:kommand-api:3.1.3")
} }

View File

@ -24,6 +24,7 @@ class Main:JavaPlugin() {
} }
override fun onDisable() { override fun onDisable() {
combatData.save()
schedule.cancel() schedule.cancel()
} }
@ -32,6 +33,8 @@ class Main:JavaPlugin() {
CombatEvent(this,combatData) CombatEvent(this,combatData)
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]!!.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){
list[it.key] = Triple(false,null,null) list[it.key] = Triple(false,null,null)
} }
@ -39,7 +42,9 @@ class Main:JavaPlugin() {
Bukkit.getOnlinePlayers().forEach{ Bukkit.getOnlinePlayers().forEach{
if(list[it.uniqueId] == null) return@forEach if(list[it.uniqueId] == null) return@forEach
if(!list[it.uniqueId]!!.first) return@forEach if(!list[it.uniqueId]!!.first) return@forEach
it.sendActionBar(Component.text("${ChatColor.WHITE}${Bukkit.getPlayer(list[it.uniqueId]!!.second!!)!!.name}${ChatColor.RED}님과 전투중입니다! ${ChatColor.WHITE}${list[it.uniqueId]!!.third!! /1000 + combatData.instance.getTime() - System.currentTimeMillis()/1000}${ChatColor.RED}초 뒤 전투모드가 끝납니다!")) if(list[it.uniqueId]!!.second == null) return@forEach
if(list[it.uniqueId]!!.third == null) return@forEach
it.sendActionBar(Component.text("${ChatColor.WHITE}${Bukkit.getPlayer(list[it.uniqueId]!!.second!!)!!.name}${ChatColor.RED}${ChatColor.BOLD}님과 전투중입니다! ${ChatColor.RESET}${ChatColor.WHITE}${list[it.uniqueId]!!.third!! /1000 + combatData.instance.getTime() - System.currentTimeMillis()/1000}${ChatColor.RED}${ChatColor.BOLD}초 뒤 전투모드가 끝납니다!"))
} }
},1L,1L) },1L,1L)
} }

View File

@ -19,20 +19,20 @@ class CombatCmd(plugin:Plugin, val cd:CombatData) {
val world: World by it val world: World by it
val bool = cd.instance.getUseWorld(world.name) val bool = cd.instance.getUseWorld(world.name)
cd.instance.setUseWorld(world.name,!bool) cd.instance.setUseWorld(world.name,!bool)
sender.sendMessage("${ChatColor.BOLD}${ChatColor.GOLD}[${ChatColor.GREEN}${ChatColor.GOLD}] ${ChatColor.WHITE}${world.name}의 컴뱃 모드 사용이 ${if(!bool)"활성화 되었습니다!" else "비활성화 되었습니다!"}") sender.sendMessage("${ChatColor.BOLD}${ChatColor.GOLD}[${ChatColor.BOLD}${ChatColor.GREEN}${ChatColor.RESET}${ChatColor.GOLD}] ${ChatColor.WHITE}${world.name}의 컴뱃 모드 사용이 ${if(!bool)"활성화 되었습니다!" else "비활성화 되었습니다!"}")
}
}
}
then("visiable"){
then("world" to dimension()){
executes {
val world:World by it
val bool = cd.instance.getCanSeeWorld(world.name)
cd.instance.setCanSeeWorld(world.name,!bool)
sender.sendMessage("${ChatColor.BOLD}${ChatColor.GOLD}[${ChatColor.GREEN}${ChatColor.GOLD}] ${ChatColor.WHITE}${world.name}의 컴뱃중 다른 사람 볼수있음이 ${if(!bool)"활성화 되었습니다!" else "비활성화 되었습니다!"}")
} }
} }
} }
// then("visiable"){
// then("world" to dimension()){
// executes {
// val world:World by it
// val bool = cd.instance.getCanSeeWorld(world.name)
// cd.instance.setCanSeeWorld(world.name,!bool)
// sender.sendMessage("${ChatColor.BOLD}${ChatColor.GOLD}[${ChatColor.GREEN}✓${ChatColor.GOLD}] ${ChatColor.WHITE}${world.name}의 컴뱃중 다른 사람 볼수있음이 ${if(!bool)"활성화 되었습니다!" else "비활성화 되었습니다!"}")
// }
// }
// }
then("time"){ then("time"){
then("int" to int()){ then("int" to int()){
executes { executes {
@ -40,7 +40,7 @@ class CombatCmd(plugin:Plugin, val cd:CombatData) {
val otime = cd.instance.getTime() val otime = cd.instance.getTime()
val ctime = int val ctime = int
cd.instance.setTime(ctime) cd.instance.setTime(ctime)
sender.sendMessage("${ChatColor.BOLD}${ChatColor.GOLD}[${ChatColor.GREEN}${ChatColor.GOLD}] ${ChatColor.WHITE}컴뱃타임이 ${otime}초에서 ${ctime}초으로 변경되었습니다!") sender.sendMessage("${ChatColor.BOLD}${ChatColor.GOLD}[${ChatColor.BOLD}${ChatColor.GREEN}${ChatColor.RESET}${ChatColor.GOLD}] ${ChatColor.WHITE}컴뱃타임이 ${otime}초에서 ${ctime}초으로 변경되었습니다!")
} }
} }
} }

View File

@ -5,9 +5,11 @@ import group.pvpconnect.combat_f.data.CombatData
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.entity.EntityType import org.bukkit.entity.EntityType
import org.bukkit.event.EventHandler import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener 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.player.PlayerCommandPreprocessEvent
import org.bukkit.event.player.PlayerQuitEvent import org.bukkit.event.player.PlayerQuitEvent
@Suppress("unused") @Suppress("unused")
@ -17,30 +19,30 @@ class CombatEvent(private val plugin:Main, private val combatData: CombatData):L
Bukkit.getPluginManager().registerEvents(this,plugin) Bukkit.getPluginManager().registerEvents(this,plugin)
} }
@EventHandler
fun onDamage(e:EntityDamageByEntityEvent){
if(!combatData.instance.getUseWorld(e.entity.world.name)) return
if(e.entityType != EntityType.PLAYER) return
if(e.damager.type != EntityType.PLAYER) return
plugin.instance.list[e.entity.uniqueId] = Triple(true,e.damager.uniqueId,System.currentTimeMillis())
plugin.instance.list[e.damager.uniqueId] = Triple(true,e.entity.uniqueId,System.currentTimeMillis())
}
@EventHandler @EventHandler
fun onOtherDamage(e:EntityDamageByEntityEvent){ fun onOtherDamage(e:EntityDamageByEntityEvent){
if(!combatData.instance.getUseWorld(e.entity.world.name)) return if(!combatData.instance.getUseWorld(e.entity.world.name)) return
if(e.entityType != EntityType.PLAYER) return if(e.entityType != EntityType.PLAYER) return
if(e.damager.type != EntityType.PLAYER) return if(e.damager.type != EntityType.PLAYER) return
val list = plugin.instance.list[e.entity.uniqueId] ?: return val list = plugin.instance.list[e.entity.uniqueId]
if(!list.first) return val dlist = plugin.instance.list[e.damager.uniqueId]
if(list.second == e.damager.uniqueId) { if((dlist?.second != null) && (dlist.second != e.entity.uniqueId)){ e.isCancelled = true;return}
plugin.instance.list[e.entity.uniqueId] = Triple(true,e.damager.uniqueId,System.currentTimeMillis()) if(list?.second != null && list.second != e.damager.uniqueId) {
plugin.instance.list[e.damager.uniqueId] = Triple(true,e.entity.uniqueId,System.currentTimeMillis()) e.isCancelled = true
return return
}else{ }
plugin.instance.list[e.entity.uniqueId] = Triple(true,e.damager.uniqueId,System.currentTimeMillis())
plugin.instance.list[e.damager.uniqueId] = Triple(true,e.entity.uniqueId,System.currentTimeMillis())
}
@EventHandler
fun onCommand(e:PlayerCommandPreprocessEvent){
if(listOf("l","lobby","home","spawn").any { e.message == it }){
val list = plugin.instance.list[e.player.uniqueId] ?: return
if(!list.first) return
e.isCancelled = true e.isCancelled = true
} }
} }
@EventHandler @EventHandler