summaryrefslogtreecommitdiff
path: root/shared/src/main/java/kz/ilotterytea/frogartha/domain/events/ServerOptionsEvent.java
blob: 73933751a4fb37395792d08dd77646fbacf64e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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<ServerOptionsEvent> {
    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 +
            '}';
    }
}