💫added 1.20.6

This commit is contained in:
faiz36 2024-06-08 21:54:56 +09:00
parent 8612e6a9e3
commit 5a6bcbf5a4
4 changed files with 75 additions and 56 deletions

View File

@ -1,5 +1,5 @@
plugins {
kotlin("jvm") version "2.0.0-Beta4"
kotlin("jvm") version "2.0.0"
id("xyz.jpenilla.run-paper") version "2.2.3"
// id("io.papermc.paperweight.userdev") version "1.5.4"
}
@ -13,25 +13,20 @@ repositories {
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
dependencies {
testImplementation(kotlin("test"))
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
implementation("io.github.monun:invfx-api:3.3.2")
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT")
implementation("io.github.monun:invfx-api:latest.release")
// paperweight.paperDevBundle("1.19.2-R0.1-SNAPSHOT")
implementation("io.github.monun:kommand-api:3.1.7")
// implementation("io.github.monun:kommand-api:3.1.7")
}
tasks {
runServer{
minecraftVersion("1.20.1")
downloadPlugins{
hangar("ViaVersion","4.9.3-SNAPSHOT+208")
hangar("ViaBackwards", "4.9.2-SNAPSHOT+126")
hangar("Multiverse-Core","4.3.12")
}
minecraftVersion("1.20.6")
}
}
@ -40,5 +35,5 @@ tasks.test {
}
kotlin {
jvmToolchain(17)
jvmToolchain(21)
}

View File

@ -5,12 +5,16 @@ import me.faiz.combat_f.data.MainData
import me.faiz.combat_f.listener.MainListener
import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.scheduler.BukkitRunnable
import org.bukkit.scheduler.BukkitTask
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
class Main : JavaPlugin() {
var manager = this.lifecycleManager
// Player UUID, A Pair of Attacker UUID and Current time
var clist:HashMap<UUID,Pair<UUID,Long>> = HashMap()
@ -22,14 +26,7 @@ class Main : JavaPlugin() {
private val maindata by lazy { MainData(this) }
private val scheduler = this.server.scheduler.runTaskTimerAsynchronously(this,Runnable{
clist.forEach {
val wuid = Bukkit.getPlayer(it.key)!!.world.uid
if(it.value.second/1000 + maindata.getTimeWorld(wuid.toString()) <= System.currentTimeMillis()/1000){
clist.remove(it.key)
}
}
},1L,1L)
private lateinit var scheduler: BukkitTask
override fun onDisable() {
maindata.save()
}
@ -37,6 +34,14 @@ class Main : JavaPlugin() {
override fun onEnable() {
MainCommand(this, maindata)
MainListener(this, maindata)
scheduler = this.server.scheduler.runTaskTimerAsynchronously(this,Runnable{
clist.forEach {
val wuid = Bukkit.getPlayer(it.key)!!.world.uid
if(it.value.second/1000 + maindata.getTimeWorld(wuid.toString()) <= System.currentTimeMillis()/1000){
clist.remove(it.key)
}
}
},1L,1L)
}
companion object {

View File

@ -1,25 +1,35 @@
package me.faiz.combat_f.cmd
import io.github.monun.kommand.kommand
import com.mojang.brigadier.Command
import io.papermc.paper.command.brigadier.Commands
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents
import me.faiz.combat_f.Main
import me.faiz.combat_f.data.MainData
import me.faiz.combat_f.handler.MainHandler
import net.kyori.adventure.text.Component
import org.bukkit.entity.Player
class MainCommand(private val main: Main, private val data: MainData) {
init {
main.apply {
kommand {
register("combat") {
requires { isOp }
executes {
if (sender !is Player) {
sender.sendMessage("This command can use Player! \n Please use another command!")
return@executes
} else MainHandler(sender as Player, data, main)
}
}
manager.registerEventHandler(LifecycleEvents.COMMANDS){ ev ->
val cmd = ev.registrar()
cmd.register(
Commands.literal("combat")
.requires{ s ->
s.sender.isOp
}
.executes{ ctx ->
if(ctx.source.sender !is Player){
ctx.source.sender.sendPlainMessage("플레이어만 이 명령어를 사용할 수 있습니다!")
return@executes Command.SINGLE_SUCCESS
}
MainHandler(ctx.source.sender as Player,data, main)
return@executes Command.SINGLE_SUCCESS
}
.build()
)
}
}
}

View File

@ -6,9 +6,11 @@ import me.faiz.combat_f.data.MainData
import net.kyori.adventure.text.Component
import org.bukkit.Bukkit
import org.bukkit.entity.EntityType
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.entity.ProjectileHitEvent
@Suppress("unused")
class MainListener(private val main: Main, private val data: MainData) : Listener {
@ -24,42 +26,49 @@ class MainListener(private val main: Main, private val data: MainData) : Listene
@EventHandler
fun onDamage(e: EntityDamageByEntityEvent){
if(e.entityType != EntityType.PLAYER) return
if(e.damager.type != EntityType.PLAYER) return
if(!data.getUseWorld(e.entity.world.uid.toString())) return
val entityD = main.clist[e.entity.uniqueId]
val damagerD = main.clist[e.damager.uniqueId]
if(main.clist.contains(e.entity.uniqueId)){
if (data.getHitOtherWorld(e.entity.world.uid.toString())){
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId,System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis())
return
}
if (entityD!!.first == e.damager.uniqueId){
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId,System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis())
val clist = main.clist
if(e.damager.type != EntityType.PLAYER || e.entityType != EntityType.PLAYER) return
if(!data.getUseWorld(e.damager.world.uid.toString())) return
if(data.getHitOtherWorld(e.damager.world.uid.toString())){
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId, System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId, System.currentTimeMillis())
return
}
if(clist.contains(e.entity.uniqueId)){
if(clist[e.entity.uniqueId]!!.first == e.damager.uniqueId){
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId, System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId, System.currentTimeMillis())
return
}else{
e.damager.sendMessage(Component.text("해당 플레이어는 ${Bukkit.getPlayer(clist[e.entity.uniqueId]!!.first)!!.name}과 전투중입니다!"))
e.isCancelled = true
e.damager.sendMessage(Component.text("해당 플레이어는 전투중입니다."))
return
}
}else if(main.clist.contains(e.damager.uniqueId)){
if (data.getHitOtherWorld(e.entity.world.uid.toString())){
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId,System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis())
return
}
if(damagerD!!.first == e.entity.uniqueId){
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId,System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis())
}else if(clist.contains(e.damager.uniqueId)){
if(clist[e.damager.uniqueId]!!.first == e.entity.uniqueId){
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId, System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId, System.currentTimeMillis())
return
}else{
e.damager.sendMessage("이미 ${Bukkit.getPlayer(clist[e.entity.uniqueId]!!.first)!!.name}님과 전투중입니다!")
e.isCancelled = true
e.damager.sendMessage(Component.text("이미 ${Bukkit.getPlayer(damagerD.first)!!.name}과 전투중입니다!"))
return
}
}else{
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId, System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId, System.currentTimeMillis())
}
}
@EventHandler
fun onArrow(e: ProjectileHitEvent){
if(e.entity.shooter !is Player) return
if(e.hitEntity == null) return
if(e.hitEntity!!.type != EntityType.PLAYER) return
val pl = e.hitEntity as Player
val sh = e.entity.shooter as Player
if(pl.uniqueId == sh.uniqueId) return
}
}