diff --git a/.gitignore b/.gitignore index 8d51a0a..423f122 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ *.jar !gradle-wrapper.jar -!/libs/*.jar diff --git a/build.gradle.kts b/build.gradle.kts index 9d8bafd..cafe112 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { java - kotlin("jvm") version "1.3.71" + kotlin("jvm") version "1.3.72" id("com.github.johnrengelman.shadow") version("5.2.0") } @@ -15,16 +15,15 @@ repositories { maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") maven("https://oss.sonatype.org/content/repositories/snapshots") maven("https://oss.sonatype.org/content/repositories/central") + maven("https://repo.dmulloy2.net/nexus/repository/public/") } dependencies { implementation(kotlin("stdlib-jdk8")) implementation(kotlin("reflect")) implementation("commons-codec:commons-codec:1.14") - compileOnly(files("./libs/CorpseReborn.jar")) - compileOnly(files("./libs/ActionBarAPI.jar")) - compileOnly(files("./libs/ProtocolLib.jar")) - compileOnly("org.spigotmc", "spigot-api", "1.14.4-R0.1-SNAPSHOT") + compileOnly("com.comphenix.protocol", "ProtocolLib", "4.5.0") + compileOnly("org.spigotmc", "spigot-api", "1.15.2-R0.1-SNAPSHOT") } configure { diff --git a/libs/ActionBarAPI.jar b/libs/ActionBarAPI.jar deleted file mode 100644 index b4b2e3f..0000000 Binary files a/libs/ActionBarAPI.jar and /dev/null differ diff --git a/libs/CorpseReborn.jar b/libs/CorpseReborn.jar deleted file mode 100644 index 1b42172..0000000 Binary files a/libs/CorpseReborn.jar and /dev/null differ diff --git a/libs/ProtocolLib.jar b/libs/ProtocolLib.jar deleted file mode 100644 index 74682ff..0000000 Binary files a/libs/ProtocolLib.jar and /dev/null differ diff --git a/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerTitle.java b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerTitle.java new file mode 100644 index 0000000..72d242a --- /dev/null +++ b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerTitle.java @@ -0,0 +1,131 @@ +/* + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.comphenix.packetwrapper; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction; +import com.comphenix.protocol.wrappers.WrappedChatComponent; + +public class WrapperPlayServerTitle extends AbstractPacket { + public static final PacketType TYPE = PacketType.Play.Server.TITLE; + + public WrapperPlayServerTitle() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerTitle(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Action. + * + * @return The current Action + */ + public TitleAction getAction() { + return handle.getTitleActions().read(0); + } + + /** + * Set Action. + * + * @param value - new value. + */ + public void setAction(TitleAction value) { + handle.getTitleActions().write(0, value); + } + + /** + * Retrieve 0 (TITLE). + *

+ * Notes: chat + * + * @return The current 0 (TITLE) + */ + public WrappedChatComponent getTitle() { + return handle.getChatComponents().read(0); + } + + /** + * Set 0 (TITLE). + * + * @param value - new value. + */ + public void setTitle(WrappedChatComponent value) { + handle.getChatComponents().write(0, value); + } + + /** + * Retrieve 2 (TIMES). + *

+ * Notes: int + * + * @return The current 2 (TIMES) + */ + public int getFadeIn() { + return handle.getIntegers().read(0); + } + + /** + * Set 2 (TIMES). + * + * @param value - new value. + */ + public void setFadeIn(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve Stay. + * + * @return The current Stay + */ + public int getStay() { + return handle.getIntegers().read(1); + } + + /** + * Set Stay. + * + * @param value - new value. + */ + public void setStay(int value) { + handle.getIntegers().write(1, value); + } + + /** + * Retrieve Fade Out. + * + * @return The current Fade Out + */ + public int getFadeOut() { + return handle.getIntegers().read(2); + } + + /** + * Set Fade Out. + * + * @param value - new value. + */ + public void setFadeOut(int value) { + handle.getIntegers().write(2, value); + } +} diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameManager.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameManager.kt index 1fa77b3..e254f9f 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameManager.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameManager.kt @@ -11,6 +11,7 @@ import de.moritzruth.spigot_ttt.game.players.PlayerManager import de.moritzruth.spigot_ttt.game.players.Role import de.moritzruth.spigot_ttt.plugin import de.moritzruth.spigot_ttt.utils.call +import de.moritzruth.spigot_ttt.utils.teleportToWorldSpawn import org.bukkit.GameRule import org.bukkit.Location import org.bukkit.Material @@ -129,7 +130,7 @@ object GameManager { PlayerManager.tttPlayers.forEach { it.reset() - it.teleportToSpawn() + it.player.teleportToWorldSpawn() it.activateStamina() } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseClickEvent.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseClickEvent.kt new file mode 100644 index 0000000..2e8ac6f --- /dev/null +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseClickEvent.kt @@ -0,0 +1,28 @@ +package de.moritzruth.spigot_ttt.game.corpses + +import de.moritzruth.spigot_ttt.game.players.TTTPlayer +import org.bukkit.event.Cancellable +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +data class CorpseClickEvent( + val tttPlayer: TTTPlayer, + val tttCorpse: TTTCorpse +): Event(), Cancellable { + private var _cancelled = false + + override fun getHandlers(): HandlerList { + @Suppress("RedundantCompanionReference") // false positive + return Companion.handlers + } + + companion object { + private val handlers = HandlerList() + + @JvmStatic + fun getHandlerList() = handlers + } + + override fun isCancelled(): Boolean = _cancelled + override fun setCancelled(cancel: Boolean) = run { _cancelled = cancel } +} diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseListener.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseListener.kt index 66abf02..a166fdf 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseListener.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseListener.kt @@ -7,8 +7,12 @@ import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityCombustEvent +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.entity.EntityTargetEvent import org.bukkit.event.inventory.InventoryClickEvent -import org.golde.bukkit.corpsereborn.CorpseAPI.events.CorpseClickEvent +import org.bukkit.event.player.PlayerInteractEntityEvent +import java.time.Duration import java.time.Instant object CorpseListener: Listener { @@ -26,21 +30,34 @@ object CorpseListener: Listener { } } + @EventHandler + fun onPlayerInteractEntity(event: PlayerInteractEntityEvent) { + val tttPlayer = TTTPlayer.of(event.player) ?: return + val tttCorpse = CorpseManager.getTTTCorpse(event.rightClicked) ?: return + + if (Duration.between(tttCorpse.timestamp, Instant.now()).toMillis() < 200) return + event.isCancelled = true + plugin.server.pluginManager.callEvent(CorpseClickEvent(tttPlayer, tttCorpse)) + } + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) fun onCorpseClick(event: CorpseClickEvent) { - // bug: always ClickType.UNKNOWN - // if (event.clickType !== ClickType.RIGHT) return + if (event.tttPlayer.alive) event.tttCorpse.identify(event.tttPlayer, event.tttPlayer.role == Role.DETECTIVE) + event.tttPlayer.player.openInventory(event.tttCorpse.inventory) + } - val tttPlayer = TTTPlayer.of(event.clicker) ?: return - val tttCorpse = CorpseManager.getTTTCorpse(event.corpse) + @EventHandler + fun onEntityCombust(event: EntityCombustEvent) { + if (CorpseManager.getTTTCorpse(event.entity) != null) event.isCancelled = true + } - if (tttCorpse !== null) { - if (Instant.now().toEpochMilli() - tttCorpse.timestamp.toEpochMilli() < 200) return + @EventHandler + fun onEntityDamage(event: EntityDamageEvent) { + if (CorpseManager.getTTTCorpse(event.entity) != null) event.isCancelled = true + } - if (tttPlayer.alive) tttCorpse.identify(tttPlayer, tttPlayer.role == Role.DETECTIVE) - event.clicker.openInventory(tttCorpse.inventory) - } - - event.isCancelled = true + @EventHandler + fun onEntityTarget(event: EntityTargetEvent) { + if (event.target != null && CorpseManager.getTTTCorpse(event.entity) != null) event.isCancelled = true } } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseManager.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseManager.kt index b465d44..e80d816 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseManager.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/CorpseManager.kt @@ -1,14 +1,14 @@ package de.moritzruth.spigot_ttt.game.corpses +import org.bukkit.entity.Entity +import org.bukkit.entity.Zombie import org.bukkit.inventory.Inventory -import org.golde.bukkit.corpsereborn.nms.Corpses object CorpseManager { private val corpses = mutableListOf() - fun getTTTCorpse(corpse: Corpses.CorpseData): TTTCorpse? { - return corpses.find { it.corpse === corpse } - } + fun getTTTCorpse(entity: Entity): TTTCorpse? = + if (entity is Zombie) corpses.find { it.entity === entity } else null fun add(corpse: TTTCorpse) { corpses.add(corpse) diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/TTTCorpse.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/TTTCorpse.kt index 1d6601f..546c1bb 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/TTTCorpse.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/corpses/TTTCorpse.kt @@ -1,7 +1,7 @@ package de.moritzruth.spigot_ttt.game.corpses -import com.connorlinfoot.actionbarapi.ActionBarAPI import de.moritzruth.spigot_ttt.Resourcepack +import de.moritzruth.spigot_ttt.game.GameManager import de.moritzruth.spigot_ttt.game.GameMessenger import de.moritzruth.spigot_ttt.game.items.impl.weapons.guns.Pistol import de.moritzruth.spigot_ttt.game.players.DeathReason @@ -10,13 +10,15 @@ import de.moritzruth.spigot_ttt.game.players.TTTPlayer import de.moritzruth.spigot_ttt.plugin import de.moritzruth.spigot_ttt.utils.applyMeta import de.moritzruth.spigot_ttt.utils.secondsToTicks +import de.moritzruth.spigot_ttt.utils.sendActionBarMessage import org.bukkit.ChatColor import org.bukkit.Location +import org.bukkit.entity.EntityType +import org.bukkit.entity.Zombie import org.bukkit.event.inventory.InventoryType import org.bukkit.inventory.ItemStack import org.bukkit.scheduler.BukkitTask -import org.golde.bukkit.corpsereborn.CorpseAPI.CorpseAPI -import org.golde.bukkit.corpsereborn.nms.Corpses +import org.bukkit.util.Vector import java.time.Instant class TTTCorpse private constructor( @@ -24,16 +26,19 @@ class TTTCorpse private constructor( location: Location, private val role: Role, private val reason: DeathReason, - private var credits: Int + private var credits: Int, + velocity: Vector = Vector() ) { var status = Status.UNIDENTIFIED; private set + val entity: Zombie - val corpse: Corpses.CorpseData val inventory = tttPlayer.player.server.createInventory(null, InventoryType.HOPPER, "${role.chatColor}${tttPlayer.player.displayName}") - val timestamp: Instant = Instant.now() + + val location get() = entity.location + private var fullMinutesSinceDeath = 0 - private var updateTimeListener: BukkitTask + private var updateTimeTask: BukkitTask init { inventory.setItem(ROLE_SLOT, ItemStack(role.iconItemMaterial).applyMeta { @@ -43,9 +48,16 @@ class TTTCorpse private constructor( setItems() - corpse = CorpseAPI.spawnCorpse(tttPlayer.player, location) + entity = GameManager.world.spawnEntity(location, EntityType.ZOMBIE) as Zombie + entity.apply { + setAI(false) + isSilent = true + removeWhenFarAway = false + isBaby = false + isCollidable = false + } - updateTimeListener = plugin.server.scheduler.runTaskTimer(plugin, fun() { + updateTimeTask = plugin.server.scheduler.runTaskTimer(plugin, fun() { fullMinutesSinceDeath += 1 setTimeItem() }, secondsToTicks(60).toLong(), secondsToTicks(60).toLong()) @@ -109,25 +121,24 @@ class TTTCorpse private constructor( credits = 0 by.credits += c - if (c > 1) { - ActionBarAPI.sendActionBar(by.player, "${ChatColor.GREEN}Du hast $c Credits aufgesammelt") - } else { - ActionBarAPI.sendActionBar(by.player, "${ChatColor.GREEN}Du hast 1 Credit aufgesammelt") - } + by.player.sendActionBarMessage( + if (c > 1) "${ChatColor.GREEN}Du hast $c Credits aufgesammelt" + else "${ChatColor.GREEN}Du hast 1 Credit aufgesammelt" + ) } } fun revive() { ensureNotDestroyed() - tttPlayer.revive(corpse.trueLocation, credits) + tttPlayer.revive(entity.location, credits) destroy() } fun destroy() { ensureNotDestroyed() status = Status.DESTROYED - CorpseAPI.removeCorpse(corpse) - updateTimeListener.cancel() + entity.remove() + updateTimeTask.cancel() inventory.viewers.toSet().forEach { it.closeInventory() } } @@ -152,13 +163,16 @@ class TTTCorpse private constructor( tttPlayer.player.location, tttPlayer.role, reason, - tttPlayer.credits + tttPlayer.credits, + tttPlayer.player.velocity ).also { CorpseManager.add(it) } fun spawnFake(role: Role, tttPlayer: TTTPlayer, location: Location) { + val loc = location.clone() + loc.pitch = 0F CorpseManager.add(TTTCorpse( tttPlayer, - location, + loc, role, DeathReason.Item(Pistol), 0 diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/ItemManager.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/ItemManager.kt index 486ed13..ed38fbb 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/ItemManager.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/ItemManager.kt @@ -1,7 +1,6 @@ package de.moritzruth.spigot_ttt.game.items import com.comphenix.protocol.ProtocolLibrary -import com.connorlinfoot.actionbarapi.ActionBarAPI import de.moritzruth.spigot_ttt.game.GameManager import de.moritzruth.spigot_ttt.game.items.impl.* import de.moritzruth.spigot_ttt.game.items.impl.weapons.BaseballBat @@ -11,6 +10,7 @@ import de.moritzruth.spigot_ttt.game.players.IState import de.moritzruth.spigot_ttt.game.players.TTTPlayer import de.moritzruth.spigot_ttt.plugin import de.moritzruth.spigot_ttt.utils.nextTick +import de.moritzruth.spigot_ttt.utils.sendActionBarMessage import org.bukkit.ChatColor import org.bukkit.Material import org.bukkit.entity.Item @@ -82,7 +82,7 @@ object ItemManager { tttPlayer.updateItemInHand() }) } else { - ActionBarAPI.sendActionBar(event.player, "${ChatColor.RED}Du kannst dieses Item nicht droppen") + event.player.sendActionBarMessage("${ChatColor.RED}Du kannst dieses Item nicht droppen") event.isCancelled = true } } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/Defibrillator.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/Defibrillator.kt index a882406..a15755e 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/Defibrillator.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/Defibrillator.kt @@ -1,14 +1,13 @@ package de.moritzruth.spigot_ttt.game.items.impl -import com.connorlinfoot.actionbarapi.ActionBarAPI import de.moritzruth.spigot_ttt.Resourcepack -import de.moritzruth.spigot_ttt.game.items.TTTItemListener import de.moritzruth.spigot_ttt.game.GameEndEvent import de.moritzruth.spigot_ttt.game.GameManager -import de.moritzruth.spigot_ttt.game.corpses.CorpseManager -import de.moritzruth.spigot_ttt.game.players.* +import de.moritzruth.spigot_ttt.game.corpses.CorpseClickEvent import de.moritzruth.spigot_ttt.game.items.Buyable import de.moritzruth.spigot_ttt.game.items.TTTItem +import de.moritzruth.spigot_ttt.game.items.TTTItemListener +import de.moritzruth.spigot_ttt.game.players.* import de.moritzruth.spigot_ttt.plugin import de.moritzruth.spigot_ttt.utils.* import org.bukkit.ChatColor @@ -18,7 +17,6 @@ import org.bukkit.boss.BarStyle import org.bukkit.event.EventHandler import org.bukkit.inventory.ItemStack import org.bukkit.scheduler.BukkitTask -import org.golde.bukkit.corpsereborn.CorpseAPI.events.CorpseClickEvent import java.time.Duration import java.time.Instant @@ -45,19 +43,16 @@ object Defibrillator: TTTItem, Buyable { } override val listener = object : TTTItemListener(this, true) { - @EventHandler + @EventHandler(ignoreCancelled = true) fun onCorpseClick(event: CorpseClickEvent) { - val tttPlayer = TTTPlayer.of(event.clicker) ?: return - if (tttPlayer.player.inventory.itemInMainHand.type != itemStack.type) return - - val tttCorpse = CorpseManager.getTTTCorpse(event.corpse) ?: return + if (event.tttPlayer.player.inventory.itemInMainHand.type != itemStack.type) return event.isCancelled = true - val state = isc.getOrCreate(tttPlayer) - state.bossBar.addPlayer(tttPlayer.player) + val state = isc.getOrCreate(event.tttPlayer) + state.bossBar.addPlayer(event.tttPlayer.player) when(val action = state.action) { - null -> state.action = Action.Reviving(tttPlayer, state) + null -> state.action = Action.Reviving(event.tttPlayer, state) is Action.Reviving -> { action.cancelTask.cancel() action.cancelTask = action.createCancelTask() @@ -66,18 +61,17 @@ object Defibrillator: TTTItem, Buyable { if (progress >= 1) { try { - tttCorpse.revive() + event.tttCorpse.revive() - ActionBarAPI.sendActionBar( - tttPlayer.player, - "${ChatColor.BOLD}${tttCorpse.tttPlayer.player.displayName} " + + event.tttPlayer.player.sendActionBarMessage( + "${ChatColor.BOLD}${event.tttCorpse.tttPlayer.player.displayName} " + "${ChatColor.GREEN}wurde wiederbelebt" ) action.cancelTask.cancel() - tttPlayer.player.inventory.removeTTTItemNextTick(Defibrillator) - state.reset(tttPlayer) - isc.remove(tttPlayer) + event.tttPlayer.player.inventory.removeTTTItemNextTick(Defibrillator) + state.reset(event.tttPlayer) + isc.remove(event.tttPlayer) } catch(e: TTTPlayer.AlreadyLivingException) { action.cancel() } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/FakeCorpse.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/FakeCorpse.kt index 48044a4..d716f58 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/FakeCorpse.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/FakeCorpse.kt @@ -1,16 +1,16 @@ package de.moritzruth.spigot_ttt.game.items.impl -import com.connorlinfoot.actionbarapi.ActionBarAPI import de.moritzruth.spigot_ttt.Resourcepack -import de.moritzruth.spigot_ttt.game.items.TTTItemListener import de.moritzruth.spigot_ttt.game.corpses.TTTCorpse -import de.moritzruth.spigot_ttt.game.players.* import de.moritzruth.spigot_ttt.game.items.Buyable import de.moritzruth.spigot_ttt.game.items.TTTItem +import de.moritzruth.spigot_ttt.game.items.TTTItemListener +import de.moritzruth.spigot_ttt.game.players.* import de.moritzruth.spigot_ttt.plugin import de.moritzruth.spigot_ttt.utils.applyMeta import de.moritzruth.spigot_ttt.utils.hideInfo import de.moritzruth.spigot_ttt.utils.removeTTTItem +import de.moritzruth.spigot_ttt.utils.sendActionBarMessage import org.bukkit.ChatColor import org.bukkit.Material import org.bukkit.event.EventHandler @@ -101,7 +101,7 @@ object FakeCorpse: TTTItem, Buyable { val corpseTTTPlayer = TTTPlayer.of(corpsePlayer) if (corpseTTTPlayer == null) { - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.RED}Das hat nicht funktioniert") + tttPlayer.player.sendActionBarMessage("${ChatColor.RED}Das hat nicht funktioniert") } else { TTTCorpse.spawnFake(state.chosenRole!!, corpseTTTPlayer, tttPlayer.player.location) diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/SecondChance.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/SecondChance.kt index 8a42223..3d2e722 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/SecondChance.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/SecondChance.kt @@ -1,12 +1,12 @@ package de.moritzruth.spigot_ttt.game.items.impl import de.moritzruth.spigot_ttt.Resourcepack -import de.moritzruth.spigot_ttt.game.items.TTTItemListener import de.moritzruth.spigot_ttt.game.GameEndEvent import de.moritzruth.spigot_ttt.game.GameManager import de.moritzruth.spigot_ttt.game.items.Buyable import de.moritzruth.spigot_ttt.game.items.PASSIVE import de.moritzruth.spigot_ttt.game.items.TTTItem +import de.moritzruth.spigot_ttt.game.items.TTTItemListener import de.moritzruth.spigot_ttt.game.players.* import de.moritzruth.spigot_ttt.plugin import de.moritzruth.spigot_ttt.utils.applyMeta @@ -81,7 +81,7 @@ object SecondChance: TTTItem, Buyable { if (Random.nextBoolean()) { event.winnerRoleGroup = null event.tttPlayer.player.openInventory(chooseSpawnInventory) - state.timeoutAction = TimeoutAction(event.tttPlayer, event.tttCorpse.corpse.trueLocation) + state.timeoutAction = TimeoutAction(event.tttPlayer, event.tttCorpse.location) } } } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/Teleporter.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/Teleporter.kt index f376916..60eadcd 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/Teleporter.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/Teleporter.kt @@ -1,14 +1,14 @@ package de.moritzruth.spigot_ttt.game.items.impl -import com.connorlinfoot.actionbarapi.ActionBarAPI import de.moritzruth.spigot_ttt.Resourcepack -import de.moritzruth.spigot_ttt.game.items.TTTItemListener import de.moritzruth.spigot_ttt.game.GameManager -import de.moritzruth.spigot_ttt.game.players.* import de.moritzruth.spigot_ttt.game.items.Buyable import de.moritzruth.spigot_ttt.game.items.TTTItem +import de.moritzruth.spigot_ttt.game.items.TTTItemListener +import de.moritzruth.spigot_ttt.game.players.* import de.moritzruth.spigot_ttt.utils.applyMeta import de.moritzruth.spigot_ttt.utils.clearHeldItemSlot +import de.moritzruth.spigot_ttt.utils.sendActionBarMessage import org.bukkit.ChatColor import org.bukkit.Sound import org.bukkit.event.EventHandler @@ -48,11 +48,10 @@ object Teleporter: TTTItem, Buyable { val state = isc.getOrCreate(tttPlayer) state.teleportSelf = !state.teleportSelf - if (state.teleportSelf) { - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.AQUA}Mode: Teleportiere dich selbst") - } else { - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.AQUA}Mode: Teleportiere jemand anderen") - } + tttPlayer.player.sendActionBarMessage( + if (state.teleportSelf) "${ChatColor.AQUA}Mode: Teleportiere dich selbst" + else "${ChatColor.AQUA}Mode: Teleportiere jemand anderen" + ) } override fun onRightClick(data: ClickEventData) { @@ -61,10 +60,10 @@ object Teleporter: TTTItem, Buyable { val firstPlayer = if (state.teleportSelf) { if (!tttPlayer.player.isOnGround) { - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.RED}${ChatColor.BOLD}Du musst auf dem Boden stehen") + tttPlayer.player.sendActionBarMessage("${ChatColor.RED}${ChatColor.BOLD}Du musst auf dem Boden stehen") null } else if (tttPlayer.player.isSneaking) { - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.RED}${ChatColor.BOLD}Du darfst nicht sneaken") + tttPlayer.player.sendActionBarMessage("${ChatColor.RED}${ChatColor.BOLD}Du darfst nicht sneaken") null } else tttPlayer } else getRandomPlayerToTeleport(tttPlayer) diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/weapons/guns/SidekickDeagle.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/weapons/guns/SidekickDeagle.kt index fed9549..d06c905 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/weapons/guns/SidekickDeagle.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/weapons/guns/SidekickDeagle.kt @@ -1,14 +1,14 @@ package de.moritzruth.spigot_ttt.game.items.impl.weapons.guns -import com.connorlinfoot.actionbarapi.ActionBarAPI import de.moritzruth.spigot_ttt.Resourcepack +import de.moritzruth.spigot_ttt.game.items.Buyable +import de.moritzruth.spigot_ttt.game.items.TTTItem import de.moritzruth.spigot_ttt.game.players.Role import de.moritzruth.spigot_ttt.game.players.TTTPlayer import de.moritzruth.spigot_ttt.game.players.roles -import de.moritzruth.spigot_ttt.game.items.Buyable -import de.moritzruth.spigot_ttt.game.items.TTTItem import de.moritzruth.spigot_ttt.utils.applyMeta import de.moritzruth.spigot_ttt.utils.hideInfo +import de.moritzruth.spigot_ttt.utils.sendActionBarMessage import org.bukkit.ChatColor import org.bukkit.entity.Item import org.bukkit.inventory.ItemStack @@ -41,7 +41,7 @@ object SidekickDeagle: Gun( } override fun reload(tttPlayer: TTTPlayer, itemStack: ItemStack, state: Gun.State) { - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.RED}Du kannst diese Waffe nicht nachladen") + tttPlayer.player.sendActionBarMessage("${ChatColor.RED}Du kannst diese Waffe nicht nachladen") } override fun onHit(tttPlayer: TTTPlayer, hitTTTPlayer: TTTPlayer) { @@ -61,7 +61,7 @@ object SidekickDeagle: Gun( override fun onBeforeShoot(tttPlayer: TTTPlayer, item: ItemStack, state: Gun.State): Boolean { if (tttPlayer.role != Role.JACKAL) { - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.RED}Diese Waffe kann nur der Jackal benutzen") + tttPlayer.player.sendActionBarMessage("${ChatColor.RED}Diese Waffe kann nur der Jackal benutzen") return false } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/shop/ShopListener.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/shop/ShopListener.kt index 6b4face..0241d8a 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/shop/ShopListener.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/shop/ShopListener.kt @@ -1,6 +1,5 @@ package de.moritzruth.spigot_ttt.game.items.shop -import com.connorlinfoot.actionbarapi.ActionBarAPI import de.moritzruth.spigot_ttt.Settings import de.moritzruth.spigot_ttt.game.items.Buyable import de.moritzruth.spigot_ttt.game.items.ItemManager @@ -8,6 +7,7 @@ import de.moritzruth.spigot_ttt.game.players.PlayerManager import de.moritzruth.spigot_ttt.game.players.TTTPlayer import de.moritzruth.spigot_ttt.game.players.TTTPlayerDeathEvent import de.moritzruth.spigot_ttt.plugin +import de.moritzruth.spigot_ttt.utils.sendActionBarMessage import org.bukkit.ChatColor import org.bukkit.entity.Player import org.bukkit.event.EventHandler @@ -40,10 +40,10 @@ object ShopListener: Listener { when { Shop.isOutOfStock(tttPlayer, tttItem) -> - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.RED}Dieses Item ist ausverkauft") + tttPlayer.player.sendActionBarMessage("${ChatColor.RED}Dieses Item ist ausverkauft") tttPlayer.credits < tttItem.price -> - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.RED}Du hast nicht genug Credits") + tttPlayer.player.sendActionBarMessage("${ChatColor.RED}Du hast nicht genug Credits") else -> try { tttPlayer.addItem(tttItem) @@ -54,9 +54,9 @@ object ShopListener: Listener { Shop.setItems(tttPlayer) } catch (e: TTTPlayer.AlreadyHasItemException) { - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.RED}Du hast dieses Item bereits") + tttPlayer.player.sendActionBarMessage("${ChatColor.RED}Du hast dieses Item bereits") } catch (e: TTTPlayer.TooManyItemsOfTypeException) { - ActionBarAPI.sendActionBar(tttPlayer.player, "${ChatColor.RED}Du hast keinen Platz dafür") + tttPlayer.player.sendActionBarMessage("${ChatColor.RED}Du hast keinen Platz dafür") } } } @@ -71,7 +71,7 @@ object ShopListener: Listener { .filter { it.role.canOwnCredits && it.role.group == killer.role.group } .forEach { it.credits += Settings.creditsPerKill - ActionBarAPI.sendActionBar(it.player, "${ChatColor.GREEN}Du hast ${Settings.creditsPerKill} Credit(s) erhalten") + it.player.sendActionBarMessage("${ChatColor.GREEN}Du hast ${Settings.creditsPerKill} Credit(s) erhalten") } } } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/PlayerManager.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/PlayerManager.kt index a12def9..c38c1e7 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/PlayerManager.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/PlayerManager.kt @@ -9,7 +9,7 @@ import de.moritzruth.spigot_ttt.game.GamePhase import de.moritzruth.spigot_ttt.plugin import de.moritzruth.spigot_ttt.utils.nextTick import de.moritzruth.spigot_ttt.utils.noop -import de.moritzruth.spigot_ttt.utils.teleportPlayerToWorldSpawn +import de.moritzruth.spigot_ttt.utils.teleportToWorldSpawn import org.bukkit.ChatColor import org.bukkit.GameMode import org.bukkit.entity.Player @@ -29,8 +29,7 @@ object PlayerManager { fun resetAfterGame() { playersJoinedDuringRound.forEach { - teleportPlayerToWorldSpawn(it) - + it.teleportToWorldSpawn() nextTick { it.gameMode = GameMode.SURVIVAL } } @@ -54,7 +53,7 @@ object PlayerManager { if (tttPlayer == null) { if (GameManager.phase == null) { - teleportPlayerToWorldSpawn(player) + player.teleportToWorldSpawn() player.gameMode = GameMode.SURVIVAL } else { player.gameMode = GameMode.SPECTATOR @@ -71,7 +70,7 @@ object PlayerManager { player.gameMode = GameMode.SPECTATOR } GamePhase.OVER -> { - tttPlayer.teleportToSpawn() + tttPlayer.player.teleportToWorldSpawn() player.gameMode = GameMode.SURVIVAL } } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt index a1d264c..bc4a03e 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt @@ -79,7 +79,6 @@ class TTTPlayer(player: Player, role: Role) { } fun onDeath(reason: DeathReason, killer: TTTPlayer?, scream: Boolean = true) { - if (killer == this) throw IllegalArgumentException("You cannot be your own killer") GameManager.ensurePhase(GamePhase.COMBAT) player.sendMessage(TTTPlugin.prefix + @@ -107,7 +106,7 @@ class TTTPlayer(player: Player, role: Role) { onlyRemainingRoleGroup ).call() - event.winnerRoleGroup?.run { GameManager.letRoleWin(primaryRole) } +// event.winnerRoleGroup?.run { GameManager.letRoleWin(primaryRole) } if (event.scream) { GameManager.world.playSound( @@ -181,7 +180,7 @@ class TTTPlayer(player: Player, role: Role) { fun resetAfterGameEnd() { if (!alive) { - teleportToSpawn() + player.teleportToWorldSpawn() } // Required to be delayed because of a Minecraft bug which sometimes turns players invisible @@ -215,8 +214,6 @@ class TTTPlayer(player: Player, role: Role) { player.inventory.clear() } - fun teleportToSpawn() = teleportPlayerToWorldSpawn(player) - fun updateItemInHand() { val itemStack = player.inventory.itemInMainHand this.itemInHand = diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/utils/PlayerExtensions.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/utils/PlayerExtensions.kt new file mode 100644 index 0000000..1d54b4f --- /dev/null +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/utils/PlayerExtensions.kt @@ -0,0 +1,26 @@ +package de.moritzruth.spigot_ttt.utils + +import com.comphenix.packetwrapper.WrapperPlayServerTitle +import com.comphenix.protocol.wrappers.EnumWrappers +import com.comphenix.protocol.wrappers.WrappedChatComponent +import org.bukkit.entity.Player + +fun Player.sendActionBarMessage( + message: String, + fadeIn: Int = secondsToTicks(0.2), + stay: Int = secondsToTicks(5), + fadeOut: Int = secondsToTicks(1) +) { + val wrapper = WrapperPlayServerTitle() + wrapper.action = EnumWrappers.TitleAction.ACTIONBAR + wrapper.title = WrappedChatComponent.fromText(message) + wrapper.fadeIn = fadeIn + wrapper.fadeOut = fadeOut + wrapper.stay = stay + + wrapper.sendPacket(this) +} + +fun Player.teleportToWorldSpawn() { + teleport(world.spawnLocation) +} diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/utils/TeleportPlayerToWorldSpawn.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/utils/TeleportPlayerToWorldSpawn.kt deleted file mode 100644 index 49d7c6f..0000000 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/utils/TeleportPlayerToWorldSpawn.kt +++ /dev/null @@ -1,7 +0,0 @@ -package de.moritzruth.spigot_ttt.utils - -import org.bukkit.entity.Player - -fun teleportPlayerToWorldSpawn(player: Player) { - player.teleport(player.world.spawnLocation) -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 279e5a3..3238dee 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,11 +1,8 @@ name: TTT version: 1.0.0 author: Moritz Ruth -api-version: "1.14" +api-version: "1.15" main: de.moritzruth.spigot_ttt.TTTPlugin -depend: - - CorpseReborn - - ActionBarAPI commands: start: