Search in sources :

Example 1 with InputComponent

use of org.dragonet.common.gui.InputComponent in project DragonProxy by DragonetMC.

the class DragonProxyFormCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("form")) {
        if ((sender instanceof Player)) {
            Player player = (Player) sender;
            if (this.plugin.isBedrockPlayer(player.getUniqueId())) {
                CustomFormComponent form = new CustomFormComponent("This is a test form");
                form.addComponent(new LabelComponent("Test label"));
                form.addComponent(new InputComponent("Test input").setPlaceholder("placeholder"));
                List<String> dropDown = new ArrayList();
                dropDown.add("Choice 1");
                dropDown.add("Choice 2");
                dropDown.add("Choice 3");
                form.addComponent(new DropDownComponent("Test dropdown", dropDown));
                BedrockPlayer.getForPlayer(player).sendForm(0, form);
            }
        // do something
        }
        return true;
    }
    return false;
}
Also used : BedrockPlayer(org.dragonet.plugin.bukkit.BedrockPlayer) Player(org.bukkit.entity.Player) InputComponent(org.dragonet.common.gui.InputComponent) ArrayList(java.util.ArrayList) CustomFormComponent(org.dragonet.common.gui.CustomFormComponent) DropDownComponent(org.dragonet.common.gui.DropDownComponent) LabelComponent(org.dragonet.common.gui.LabelComponent)

Example 2 with InputComponent

use of org.dragonet.common.gui.InputComponent in project DragonProxy by DragonetMC.

the class PEPacketProcessor method handlePacket.

// this method should be in UpstreamSession
public void handlePacket(PEPacket packet) {
    if (packet == null)
        return;
    if (!client.getProxy().getConfig().disable_packet_events) {
        PacketfromPlayerEvent packetEvent = new PacketfromPlayerEvent(client, packet);
        client.getProxy().getEventManager().callEvent(packetEvent);
        if (packetEvent.isCancelled()) {
            return;
        }
    }
    // Wait for player logginig in
    if ("online_login_wait".equals(this.client.getDataCache().get(CacheKey.AUTHENTICATION_STATE))) {
        if (packet.pid() == ProtocolInfo.MOVE_PLAYER_PACKET) {
            InputComponent username = new InputComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_USERNAME)).setPlaceholder("steve@example.com");
            InputComponent password = new InputComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_PASSWORD)).setPlaceholder("123456");
            if (this.client.getProxy().getConfig().auto_login) {
                username.setDefaultValue(this.client.getProxy().getConfig().online_username);
                password.setDefaultValue(this.client.getProxy().getConfig().online_password);
            }
            // client.getDataCache().put(CacheKey.AUTHENTICATION_STATE, "online_login");
            ModalFormRequestPacket packetForm = new ModalFormRequestPacket();
            CustomFormComponent form = new CustomFormComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_TITLE));
            form.addComponent(new LabelComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_DESC)));
            form.addComponent(new LabelComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_PROMPT)));
            form.addComponent(username);
            form.addComponent(password);
            packetForm.formId = 1;
            packetForm.formData = form.serializeToJson().toString();
            this.client.sendPacket(packetForm, true);
            return;
        }
        if (packet.pid() == ProtocolInfo.MODAL_FORM_RESPONSE_PACKET) {
            try {
                this.client.sendChat(this.client.getProxy().getLang().get(Lang.MESSAGE_LOGIN_PROGRESS));
                ModalFormResponsePacket formResponse = (ModalFormResponsePacket) packet;
                JsonArray array = JsonUtil.parseArray(formResponse.formData);
                this.client.getDataCache().remove(CacheKey.AUTHENTICATION_STATE);
                this.client.authenticate(array.get(2).getAsString(), array.get(3).getAsString(), authProxy);
            } catch (Exception ex) {
                this.client.sendChat(this.client.getProxy().getLang().get(Lang.MESSAGE_ONLINE_LOGIN_FAILD));
            }
            return;
        }
    }
    switch(packet.pid()) {
        case ProtocolInfo.BATCH_PACKET:
            DragonProxy.getInstance().getLogger().debug("Received batch packet from client !");
            break;
        case ProtocolInfo.LOGIN_PACKET:
            this.client.onLogin((LoginPacket) packet);
            break;
        case ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET:
            if (!this.client.isLoggedIn())
                this.client.postLogin();
            break;
        default:
            if (this.client.getDownstream() == null || !this.client.getDownstream().isConnected())
                break;
            if (enableForward.get() && FORWARDED_PACKETS.contains(packet.getClass())) {
                BinaryStream bis = new BinaryStream();
                bis.putString("PacketForward");
                bis.putByteArray(packet.getBuffer());
                ClientPluginMessagePacket msg = new ClientPluginMessagePacket("DragonProxy", bis.getBuffer());
                client.getDownstream().send(msg);
            } else // IMPORTANT Do not send packet until client is connected !
            if (client.isSpawned()) {
                Packet[] translated = PacketTranslatorRegister.translateToPC(this.client, packet);
                if (translated == null || translated.length == 0)
                    break;
                client.getDownstream().send(translated);
            }
            break;
    }
}
Also used : JsonArray(com.google.gson.JsonArray) InputComponent(org.dragonet.common.gui.InputComponent) BinaryStream(org.dragonet.common.utilities.BinaryStream) PacketfromPlayerEvent(org.dragonet.proxy.events.defaults.packets.PacketfromPlayerEvent) CustomFormComponent(org.dragonet.common.gui.CustomFormComponent) ClientPluginMessagePacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket) JsonParseException(com.google.gson.JsonParseException) LabelComponent(org.dragonet.common.gui.LabelComponent)

Aggregations

CustomFormComponent (org.dragonet.common.gui.CustomFormComponent)2 InputComponent (org.dragonet.common.gui.InputComponent)2 LabelComponent (org.dragonet.common.gui.LabelComponent)2 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)1 JsonArray (com.google.gson.JsonArray)1 JsonParseException (com.google.gson.JsonParseException)1 ArrayList (java.util.ArrayList)1 Player (org.bukkit.entity.Player)1 DropDownComponent (org.dragonet.common.gui.DropDownComponent)1 BinaryStream (org.dragonet.common.utilities.BinaryStream)1 BedrockPlayer (org.dragonet.plugin.bukkit.BedrockPlayer)1 PacketfromPlayerEvent (org.dragonet.proxy.events.defaults.packets.PacketfromPlayerEvent)1