Search in sources :

Example 1 with ClientInputReleasedEvent

use of io.xol.chunkstories.api.events.client.ClientInputReleasedEvent in project chunkstories by Hugobros3.

the class Lwjgl3ClientInputsManager method onInputReleased.

@Override
public boolean onInputReleased(Input input) {
    ClientInputReleasedEvent event = new ClientInputReleasedEvent(gameWindow.getClient(), input);
    ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
    if (cpm != null) {
        cpm.fireEvent(event);
    }
    final LocalPlayer player = Client.getInstance().getPlayer();
    if (player == null)
        return false;
    final EntityControllable entityControlled = player.getControlledEntity();
    // There has to be a controlled entity for sending inputs to make sense.
    if (entityControlled == null)
        return false;
    // Send input to server
    World world = entityControlled.getWorld();
    if (world instanceof WorldClientRemote) {
        ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
        PacketInput packet = new PacketInput(world);
        packet.input = input;
        packet.isPressed = false;
        connection.pushPacket(packet);
        return true;
    } else {
        PlayerInputReleasedEvent event2 = new PlayerInputReleasedEvent(Client.getInstance().getPlayer(), input);
        cpm.fireEvent(event2);
        return true;
    }
}
Also used : ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PacketInput(io.xol.chunkstories.net.packets.PacketInput) ClientInputReleasedEvent(io.xol.chunkstories.api.events.client.ClientInputReleasedEvent) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ServerConnection(io.xol.chunkstories.client.net.ServerConnection) PlayerInputReleasedEvent(io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent) World(io.xol.chunkstories.api.world.World) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Aggregations

LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)1 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)1 ClientInputReleasedEvent (io.xol.chunkstories.api.events.client.ClientInputReleasedEvent)1 PlayerInputReleasedEvent (io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent)1 ClientPluginManager (io.xol.chunkstories.api.plugin.ClientPluginManager)1 World (io.xol.chunkstories.api.world.World)1 ServerConnection (io.xol.chunkstories.client.net.ServerConnection)1 PacketInput (io.xol.chunkstories.net.packets.PacketInput)1 WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)1