Search in sources :

Example 1 with MapPlayerInput

use of com.bergerkiller.bukkit.common.map.MapPlayerInput in project BKCommonLib by bergerhealer.

the class CommonMapController method onPacketReceive.

@Override
public void onPacketReceive(PacketReceiveEvent event) {
    // Handle input coming from the player for the map
    if (event.getType() == PacketType.IN_STEER_VEHICLE) {
        Player p = event.getPlayer();
        MapPlayerInput input = playerInputs.get(p);
        if (input != null) {
            CommonPacket packet = event.getPacket();
            int dx = (int) -Math.signum(packet.read(PacketType.IN_STEER_VEHICLE.sideways));
            int dy = (int) -Math.signum(packet.read(PacketType.IN_STEER_VEHICLE.forwards));
            int dz = 0;
            if (packet.read(PacketType.IN_STEER_VEHICLE.unmount)) {
                dz -= 1;
            }
            if (packet.read(PacketType.IN_STEER_VEHICLE.jump)) {
                dz += 1;
            }
            // Receive input. If it will be handled, it will cancel further handling of this packet
            event.setCancelled(input.receiveInput(dx, dy, dz));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) MapPlayerInput(com.bergerkiller.bukkit.common.map.MapPlayerInput) CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket)

Example 2 with MapPlayerInput

use of com.bergerkiller.bukkit.common.map.MapPlayerInput in project BKCommonLib by bergerhealer.

the class CommonMapController method getPlayerInput.

/**
     * Gets the Player Input controller for a certain player
     * 
     * @param player
     * @return player input
     */
public MapPlayerInput getPlayerInput(Player player) {
    MapPlayerInput input = playerInputs.get(player);
    if (input == null) {
        input = new MapPlayerInput(player);
        playerInputs.put(player, input);
    }
    return input;
}
Also used : MapPlayerInput(com.bergerkiller.bukkit.common.map.MapPlayerInput)

Aggregations

MapPlayerInput (com.bergerkiller.bukkit.common.map.MapPlayerInput)2 CommonPacket (com.bergerkiller.bukkit.common.protocol.CommonPacket)1 Player (org.bukkit.entity.Player)1