Aquazus/D1Proxy

View on GitHub
src/main/java/fr/aquazus/d1proxy/handlers/ImHandler.java

Summary

Maintainability
A
0 mins
Test Coverage
package fr.aquazus.d1proxy.handlers;

import fr.aquazus.d1proxy.Proxy;
import fr.aquazus.d1proxy.network.ProxyClient;
import fr.aquazus.d1proxy.network.ProxyClientState;
import simplenet.packet.Packet;

import java.nio.charset.StandardCharsets;

public class ImHandler implements PacketHandler {

    private final Proxy proxy;

    public ImHandler(Proxy proxy) {
        this.proxy = proxy;
    }

    @Override
    public boolean shouldForward(ProxyClient proxyClient, String packet, PacketDestination destination) {
        if (packet.startsWith("Im0153;")) {
            proxyClient.setState(ProxyClientState.INGAME);
            Packet.builder().putBytes(packet.getBytes(StandardCharsets.UTF_8)).putByte(0).writeAndFlush(proxyClient.getClient());
            proxyClient.sendMessage("Bienvenue sur D1Proxy " + proxy.getVersion() + " !");
            return false;
        }
        return true;
    }
}