Compare commits

..

No commits in common. "1.20.6" and "master" have entirely different histories.

4 changed files with 59 additions and 78 deletions

View File

@ -1,5 +1,5 @@
plugins { plugins {
kotlin("jvm") version "2.0.0" kotlin("jvm") version "2.0.0-Beta4"
id("xyz.jpenilla.run-paper") version "2.2.3" id("xyz.jpenilla.run-paper") version "2.2.3"
// id("io.papermc.paperweight.userdev") version "1.5.4" // id("io.papermc.paperweight.userdev") version "1.5.4"
} }
@ -13,20 +13,25 @@ repositories {
} }
java { java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21)) toolchain.languageVersion.set(JavaLanguageVersion.of(17))
} }
dependencies { dependencies {
testImplementation(kotlin("test")) testImplementation(kotlin("test"))
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
implementation("io.github.monun:invfx-api:latest.release") implementation("io.github.monun:invfx-api:3.3.2")
// paperweight.paperDevBundle("1.19.2-R0.1-SNAPSHOT") // 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 { tasks {
runServer{ runServer{
minecraftVersion("1.20.6") 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")
}
} }
} }
@ -35,5 +40,5 @@ tasks.test {
} }
kotlin { kotlin {
jvmToolchain(21) jvmToolchain(17)
} }

View File

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

View File

@ -1,35 +1,25 @@
package me.faiz.combat_f.cmd package me.faiz.combat_f.cmd
import com.mojang.brigadier.Command import io.github.monun.kommand.kommand
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.Main
import me.faiz.combat_f.data.MainData import me.faiz.combat_f.data.MainData
import me.faiz.combat_f.handler.MainHandler import me.faiz.combat_f.handler.MainHandler
import net.kyori.adventure.text.Component
import org.bukkit.entity.Player import org.bukkit.entity.Player
class MainCommand(private val main: Main, private val data: MainData) { class MainCommand(private val main: Main, private val data: MainData) {
init { init {
main.apply { main.apply {
manager.registerEventHandler(LifecycleEvents.COMMANDS){ ev -> kommand {
val cmd = ev.registrar() register("combat") {
cmd.register( requires { isOp }
Commands.literal("combat") executes {
.requires{ s -> if (sender !is Player) {
s.sender.isOp sender.sendMessage("This command can use Player! \n Please use another command!")
return@executes
} else MainHandler(sender as Player, data, main)
} }
.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,11 +6,9 @@ import me.faiz.combat_f.data.MainData
import net.kyori.adventure.text.Component import net.kyori.adventure.text.Component
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.entity.EntityType import org.bukkit.entity.EntityType
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler import org.bukkit.event.EventHandler
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.ProjectileHitEvent
@Suppress("unused") @Suppress("unused")
class MainListener(private val main: Main, private val data: MainData) : Listener { class MainListener(private val main: Main, private val data: MainData) : Listener {
@ -26,49 +24,42 @@ class MainListener(private val main: Main, private val data: MainData) : Listene
@EventHandler @EventHandler
fun onDamage(e: EntityDamageByEntityEvent){ fun onDamage(e: EntityDamageByEntityEvent){
val clist = main.clist if(e.entityType != EntityType.PLAYER) return
if(e.damager.type != EntityType.PLAYER || e.entityType != EntityType.PLAYER) return if(e.damager.type != EntityType.PLAYER) return
if(!data.getUseWorld(e.damager.world.uid.toString())) return if(!data.getUseWorld(e.entity.world.uid.toString())) return
if(data.getHitOtherWorld(e.damager.world.uid.toString())){ 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.entity.uniqueId] = Pair(e.damager.uniqueId,System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis()) main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis())
return return
} }
if(clist.contains(e.entity.uniqueId)){ if (entityD!!.first == e.damager.uniqueId){
if(clist[e.entity.uniqueId]!!.first == e.damager.uniqueId){
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId,System.currentTimeMillis()) main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId,System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis()) main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis())
return return
}else{ }else{
e.damager.sendMessage(Component.text("해당 플레이어는 ${Bukkit.getPlayer(clist[e.entity.uniqueId]!!.first)!!.name}과 전투중입니다!"))
e.isCancelled = true e.isCancelled = true
e.damager.sendMessage(Component.text("해당 플레이어는 전투중입니다."))
return return
} }
}else if(clist.contains(e.damager.uniqueId)){ }else if(main.clist.contains(e.damager.uniqueId)){
if(clist[e.damager.uniqueId]!!.first == 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(damagerD!!.first == e.entity.uniqueId){
main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId,System.currentTimeMillis()) main.clist[e.entity.uniqueId] = Pair(e.damager.uniqueId,System.currentTimeMillis())
main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis()) main.clist[e.damager.uniqueId] = Pair(e.entity.uniqueId,System.currentTimeMillis())
return return
}else{ }else{
e.damager.sendMessage("이미 ${Bukkit.getPlayer(clist[e.entity.uniqueId]!!.first)!!.name}님과 전투중입니다!")
e.isCancelled = true e.isCancelled = true
e.damager.sendMessage(Component.text("이미 ${Bukkit.getPlayer(damagerD.first)!!.name}과 전투중입니다!"))
return 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
}
} }