Don't show dead players as spectator in the tablist
This commit is contained in:
parent
f08ad833ec
commit
7929a05c51
5 changed files with 117 additions and 37 deletions
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* PacketWrapper - ProtocolLib wrappers for Minecraft packets
|
||||
* Copyright (C) dmulloy2 <http://dmulloy2.net>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.comphenix.packetwrapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
|
||||
public class WrapperPlayServerPlayerInfo extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
|
||||
|
||||
public WrapperPlayServerPlayerInfo() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerPlayerInfo(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public PlayerInfoAction getAction() {
|
||||
return handle.getPlayerInfoAction().read(0);
|
||||
}
|
||||
|
||||
public void setAction(PlayerInfoAction value) {
|
||||
handle.getPlayerInfoAction().write(0, value);
|
||||
}
|
||||
|
||||
public List<PlayerInfoData> getData() {
|
||||
return handle.getPlayerInfoDataLists().read(0);
|
||||
}
|
||||
|
||||
public void setData(List<PlayerInfoData> value) {
|
||||
handle.getPlayerInfoDataLists().write(0, value);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,12 @@
|
|||
package de.moritzruth.spigot_ttt.game
|
||||
|
||||
import com.comphenix.packetwrapper.WrapperPlayServerPlayerInfo
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.ProtocolLibrary
|
||||
import com.comphenix.protocol.events.PacketAdapter
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData
|
||||
import de.moritzruth.spigot_ttt.TTTPlugin
|
||||
import de.moritzruth.spigot_ttt.game.players.DeathReason
|
||||
import de.moritzruth.spigot_ttt.game.players.PlayerManager
|
||||
|
@ -17,11 +24,12 @@ import org.bukkit.event.block.BlockPlaceEvent
|
|||
import org.bukkit.event.entity.*
|
||||
import org.bukkit.event.player.*
|
||||
|
||||
object GeneralGameEventsListener: Listener {
|
||||
val BLOCKED_COMMANDS = setOf("me", "tell")
|
||||
object GeneralGameEventsListener : Listener {
|
||||
private val BLOCKED_COMMANDS = setOf("me", "tell")
|
||||
|
||||
fun register() {
|
||||
plugin.server.pluginManager.registerEvents(this, plugin)
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(PacketListener)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -43,7 +51,7 @@ object GeneralGameEventsListener: Listener {
|
|||
|
||||
@EventHandler
|
||||
fun onPlayerCommandPreprocess(event: PlayerCommandPreprocessEvent) {
|
||||
if(event.message.startsWith("/rl") && GameManager.phase != null) { // /reload is not blocked
|
||||
if (event.message.startsWith("/rl") && GameManager.phase != null) { // /reload is not blocked
|
||||
event.player.sendMessage(TTTPlugin.prefix + "${ChatColor.RED}The server may not be reloaded while the game is running")
|
||||
event.player.sendMessage(TTTPlugin.prefix + "${ChatColor.RED}You can force reload by using ${ChatColor.WHITE}/reload")
|
||||
event.isCancelled = true
|
||||
|
@ -95,7 +103,7 @@ object GeneralGameEventsListener: Listener {
|
|||
damageInfo.damager.credits += 1
|
||||
|
||||
damageInfo.deathReason
|
||||
} else when(event.cause) {
|
||||
} else when (event.cause) {
|
||||
EntityDamageEvent.DamageCause.FALL -> DeathReason.FALL
|
||||
EntityDamageEvent.DamageCause.BLOCK_EXPLOSION,
|
||||
EntityDamageEvent.DamageCause.ENTITY_EXPLOSION -> DeathReason.EXPLOSION
|
||||
|
@ -180,4 +188,28 @@ object GeneralGameEventsListener: Listener {
|
|||
|
||||
event.isCancelled = true
|
||||
}
|
||||
|
||||
private object PacketListener : PacketAdapter(plugin, PacketType.Play.Server.PLAYER_INFO) {
|
||||
override fun onPacketSending(event: PacketEvent) {
|
||||
val packet = WrapperPlayServerPlayerInfo(event.packet)
|
||||
|
||||
if (packet.action == EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE ||
|
||||
packet.action == EnumWrappers.PlayerInfoAction.ADD_PLAYER) {
|
||||
|
||||
packet.data = packet.data.map { info ->
|
||||
val tttPlayer = PlayerManager.tttPlayers.find { it.player.uniqueId == info.profile.uuid }
|
||||
|
||||
if (tttPlayer == null) info
|
||||
else PlayerInfoData(
|
||||
info.profile,
|
||||
info.latency,
|
||||
if (info.gameMode == EnumWrappers.NativeGameMode.SPECTATOR)
|
||||
EnumWrappers.NativeGameMode.SURVIVAL
|
||||
else info.gameMode,
|
||||
info.displayName
|
||||
)
|
||||
}.toMutableList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.moritzruth.spigot_ttt.items
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary
|
||||
import de.moritzruth.spigot_ttt.game.GameManager
|
||||
import de.moritzruth.spigot_ttt.items.weapons.BaseballBat
|
||||
import de.moritzruth.spigot_ttt.items.weapons.Knife
|
||||
|
@ -31,11 +32,8 @@ object ItemManager {
|
|||
|
||||
fun registerListeners() {
|
||||
for (item in items) {
|
||||
val listener = item.listener
|
||||
|
||||
if (listener != null) {
|
||||
plugin.server.pluginManager.registerEvents(listener, plugin)
|
||||
}
|
||||
if (item.listener != null) plugin.server.pluginManager.registerEvents(item.listener!!, plugin)
|
||||
if (item.packetListener != null) ProtocolLibrary.getProtocolManager().addPacketListener(item.packetListener!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package de.moritzruth.spigot_ttt.items
|
|||
|
||||
import com.comphenix.packetwrapper.WrapperPlayServerEntityMetadata
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.ProtocolLibrary
|
||||
import com.comphenix.protocol.events.PacketAdapter
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
import de.moritzruth.spigot_ttt.CustomItems
|
||||
|
@ -35,32 +34,6 @@ object Radar: TTTItem, Buyable {
|
|||
|
||||
val isc = InversedStateContainer(State::class)
|
||||
|
||||
init {
|
||||
ProtocolLibrary
|
||||
.getProtocolManager()
|
||||
.addPacketListener(object : PacketAdapter(plugin, PacketType.Play.Server.ENTITY_METADATA) {
|
||||
override fun onPacketSending(event: PacketEvent) {
|
||||
val tttPlayer = PlayerManager.getTTTPlayer(event.player) ?: return
|
||||
val packet = WrapperPlayServerEntityMetadata(event.packet)
|
||||
|
||||
val playerOfPacket = plugin.server.onlinePlayers.find { it.entityId == packet.entityID } ?: return
|
||||
val tttPlayerOfPacket = PlayerManager.getTTTPlayer(playerOfPacket) ?: return
|
||||
if (tttPlayerOfPacket.alive) {
|
||||
// https://wiki.vg/Entity_metadata#Entity_Metadata_Format
|
||||
try {
|
||||
val modifiers = packet.metadata[0].value as Byte // TODO: Fix this
|
||||
packet.metadata[0].setValue(
|
||||
if (isc.get(tttPlayer).enabled) modifiers or 0x40
|
||||
else modifiers and 0b10111111.toByte()
|
||||
)
|
||||
} catch (ignored: Exception) {
|
||||
// Idk why this throws exceptions, but it works anyways
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun reset(tttPlayer: TTTPlayer) {
|
||||
setEnabled(tttPlayer, false)
|
||||
|
||||
|
@ -117,6 +90,26 @@ object Radar: TTTItem, Buyable {
|
|||
}
|
||||
}
|
||||
|
||||
override val packetListener = object : PacketAdapter(plugin, PacketType.Play.Server.ENTITY_METADATA) {
|
||||
override fun onPacketSending(event: PacketEvent) {
|
||||
val tttPlayer = PlayerManager.getTTTPlayer(event.player) ?: return
|
||||
val packet = WrapperPlayServerEntityMetadata(event.packet)
|
||||
|
||||
val playerOfPacket = plugin.server.onlinePlayers.find { it.entityId == packet.entityID } ?: return
|
||||
val tttPlayerOfPacket = PlayerManager.getTTTPlayer(playerOfPacket) ?: return
|
||||
if (tttPlayerOfPacket.alive) {
|
||||
// https://wiki.vg/Entity_metadata#Entity_Metadata_Format
|
||||
try {
|
||||
val modifiers = packet.metadata[0].value as Byte
|
||||
packet.metadata[0].value = if (isc.get(tttPlayer).enabled) modifiers or 0x40
|
||||
else modifiers and 0b10111111.toByte()
|
||||
} catch (ignored: Exception) {
|
||||
// Idk why this throws exceptions, but it works anyways
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class State: IState {
|
||||
var enabled: Boolean = false
|
||||
var progressTask: BukkitTask? = null
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.moritzruth.spigot_ttt.items
|
||||
|
||||
import com.comphenix.protocol.events.PacketListener
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.Listener
|
||||
|
@ -22,7 +23,8 @@ interface Buyable {
|
|||
interface Spawning
|
||||
|
||||
interface TTTItem {
|
||||
val listener: Listener?
|
||||
val listener: Listener? get() = null
|
||||
val packetListener: PacketListener? get() = null
|
||||
val itemStack: ItemStack
|
||||
val type: Type
|
||||
|
||||
|
|
Reference in a new issue