package kz.ilotterytea.frogartha.domain.events; import com.github.czyzby.websocket.serialization.SerializationException; import com.github.czyzby.websocket.serialization.Transferable; import com.github.czyzby.websocket.serialization.impl.Deserializer; import com.github.czyzby.websocket.serialization.impl.Serializer; import kz.ilotterytea.frogartha.FrogarthaConstants; public class ServerOptionsEvent extends Event implements Transferable { private final int chatMaxMessageLength, chatMessagePerMilliseconds; private final float playerMaxJumpStrength, playerMaxJumpHeight, playerJumpSpeed; public ServerOptionsEvent() { this.chatMaxMessageLength = FrogarthaConstants.Chat.MAX_MESSAGE_LENGTH; this.chatMessagePerMilliseconds = FrogarthaConstants.Chat.MESSAGE_PER_MS; this.playerMaxJumpStrength = FrogarthaConstants.Player.MAX_JUMP_STRENGTH; this.playerMaxJumpHeight = FrogarthaConstants.Player.MAX_JUMP_HEIGHT; this.playerJumpSpeed = FrogarthaConstants.Player.JUMP_SPEED; } public ServerOptionsEvent( int chatMaxMessageLength, int chatMessagePerMilliseconds, float playerMaxJumpStrength, float playerMaxJumpHeight, float playerJumpSpeed ) { this.chatMaxMessageLength = chatMaxMessageLength; this.chatMessagePerMilliseconds = chatMessagePerMilliseconds; this.playerMaxJumpStrength = playerMaxJumpStrength; this.playerMaxJumpHeight = playerMaxJumpHeight; this.playerJumpSpeed = playerJumpSpeed; } public int getChatMaxMessageLength() { return chatMaxMessageLength; } public int getChatMessagePerMilliseconds() { return chatMessagePerMilliseconds; } public float getPlayerMaxJumpStrength() { return playerMaxJumpStrength; } public float getPlayerMaxJumpHeight() { return playerMaxJumpHeight; } public float getPlayerJumpSpeed() { return playerJumpSpeed; } @Override public void serialize(Serializer serializer) throws SerializationException { serializer .serializeInt(chatMaxMessageLength) .serializeInt(chatMessagePerMilliseconds) .serializeFloat(playerMaxJumpStrength) .serializeFloat(playerMaxJumpHeight) .serializeFloat(playerJumpSpeed); } @Override public ServerOptionsEvent deserialize(Deserializer deserializer) throws SerializationException { return new ServerOptionsEvent( deserializer.deserializeInt(), deserializer.deserializeInt(), deserializer.deserializeFloat(), deserializer.deserializeFloat(), deserializer.deserializeFloat() ); } @Override public String toString() { return "ServerOptionsEvent{" + "chatMaxMessageLength=" + chatMaxMessageLength + ", chatMessagePerMilliseconds=" + chatMessagePerMilliseconds + ", playerMaxJumpStrength=" + playerMaxJumpStrength + ", playerMaxJumpHeight=" + playerMaxJumpHeight + ", playerJumpSpeed=" + playerJumpSpeed + '}'; } }