use of io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent 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;
}
}
use of io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent in project chunkstories by Hugobros3.
the class PacketInput method process.
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException {
long code = in.readLong();
boolean pressed = in.readBoolean();
if (processor instanceof ServerPlayerPacketsProcessor) {
ServerPlayerPacketsProcessor sppc = (ServerPlayerPacketsProcessor) processor;
// Look for the controller handling this buisness
EntityControllable entity = (EntityControllable) sppc.getPlayer().getControlledEntity();
if (entity != null) {
// Get input of the client
input = sppc.getPlayer().getInputsManager().getInputFromHash(code);
if (input == null)
throw new NullPointerException("Unknown input hash : " + code);
// System.out.println(processor.getServerClient().getProfile() +
// " "+input + " "+pressed);
// Update it's state
((InputVirtual) input).setPressed(pressed);
// Fire appropriate event
if (pressed) {
PlayerInputPressedEvent event = new PlayerInputPressedEvent(sppc.getPlayer(), input);
entity.getWorld().getGameLogic().getPluginsManager().fireEvent(event);
if (!event.isCancelled())
entity.onControllerInput(input, entity.getControllerComponent().getController());
} else {
PlayerInputReleasedEvent event = new PlayerInputReleasedEvent(sppc.getPlayer(), input);
entity.getWorld().getGameLogic().getPluginsManager().fireEvent(event);
}
// TODO why is this disabled and still there ?
// If we pressed the input, apply game logic
// if(pressed)
// entity.handleInteraction(input,
// entity.getControllerComponent().getController());
}
}
}
Aggregations