@Override
    public void update() {
        float rawValue, value;
        for (final Map.Entry<Integer, GlfwJoystick> entry : joysticks.entrySet()) {

            // Axes
            final FloatBuffer axisValues = glfwGetJoystickAxes(entry.getKey());

            // if a joystick is added or removed, the callback reloads the joysticks.
            // when the callback is called and reloads the joystick, this iterator may already have started iterating.
            // To avoid a NullPointerException we null-check the axisValues and bytebuffer objects.
            // If the joystick it's iterating over no-longer exists it will return null.

            if (axisValues != null) {
                for (final JoystickAxis axis : entry.getValue().getAxes()) {
                    rawValue = axisValues.get(axis.getAxisId());
                    value = JoystickCompatibilityMappings.remapAxisRange(axis, rawValue);
                    listener.onJoyAxisEvent(new JoyAxisEvent(axis, value, rawValue));
                }
            }

            // Buttons
            final ByteBuffer byteBuffer = glfwGetJoystickButtons(entry.getKey());

            if (byteBuffer != null) {
                for (final JoystickButton button : entry.getValue().getButtons()) {
                    final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS;

                    if (joyButtonPressed.get(button) != pressed) {
                        joyButtonPressed.put(button, pressed);
                        listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed));
                    }
                }
            }
        }
    }
The LWJGL implementation of {@link JoyInput}.

@author Daniel Johansson (dannyjo)
@since 3.1
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java