Search in sources :

Example 1 with PlayerDigType

use of com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType in project CombatLogX by SirBlobman.

the class ForceFieldAdapter method onPacketReceiving.

@Override
public void onPacketReceiving(PacketEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Player player = e.getPlayer();
    ICombatManager combatManager = this.plugin.getCombatManager();
    if (!combatManager.isInCombat(player)) {
        return;
    }
    World world = player.getWorld();
    PacketContainer packetContainer = e.getPacket();
    Location location = getLocation0(world, packetContainer);
    if (location == null) {
        return;
    }
    if (isForceFieldBlock(player, location)) {
        PacketType packetType = packetContainer.getType();
        if (packetType == Client.BLOCK_DIG) {
            StructureModifier<PlayerDigType> playerDigTypeModifier = packetContainer.getPlayerDigTypes();
            PlayerDigType playerDigType = playerDigTypeModifier.readSafely(0);
            GameMode gameMode = player.getGameMode();
            if (playerDigType == PlayerDigType.STOP_DESTROY_BLOCK || (playerDigType == PlayerDigType.START_DESTROY_BLOCK && gameMode == GameMode.CREATIVE)) {
                this.forceFieldListener.sendForceField(player, location);
            }
        }
        if (packetType == Client.USE_ITEM) {
            this.forceFieldListener.sendForceField(player, location);
        }
    }
}
Also used : GameMode(org.bukkit.GameMode) Player(org.bukkit.entity.Player) PacketContainer(com.comphenix.protocol.events.PacketContainer) PlayerDigType(com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) PacketType(com.comphenix.protocol.PacketType) World(org.bukkit.World) Location(org.bukkit.Location)

Aggregations

PacketType (com.comphenix.protocol.PacketType)1 PacketContainer (com.comphenix.protocol.events.PacketContainer)1 PlayerDigType (com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType)1 ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)1 GameMode (org.bukkit.GameMode)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 Player (org.bukkit.entity.Player)1