Search in sources :

Example 26 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.

the class TestCommand method execute.

public void execute(DragonProxy proxy, String[] args) {
    if (args.length == 0) {
        System.out.println("This is a developer's command! ");
        return;
    }
    UpstreamSession player = proxy.getSessionRegister().getAll().values().toArray(new UpstreamSession[1])[0];
    if (args[0].equalsIgnoreCase("status")) {
        PlayStatusPacket s = new PlayStatusPacket();
        s.status = PlayStatusPacket.PLAYER_SPAWN;
        player.sendPacket(s);
    } else if (args[0].equalsIgnoreCase("res")) {
        player.sendPacket(new ResourcePacksInfoPacket());
    } else if (args[0].equalsIgnoreCase("pos")) {
        player.sendChat("pos at: " + player.getEntityCache().getClientEntity().x + ", " + player.getEntityCache().getClientEntity().y + ", " + player.getEntityCache().getClientEntity().z);
    } else if (args[0].equalsIgnoreCase("respawn")) {
        RespawnPacket resp = new RespawnPacket();
        resp.position = new Vector3F(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
        player.sendPacket(resp);
    } else if (args[0].equalsIgnoreCase("chunkradius")) {
        player.sendPacket(new ChunkRadiusUpdatedPacket(8));
    } else if (args[0].equalsIgnoreCase("setspawnpos")) {
        SetSpawnPositionPacket packetSetSpawnPosition = new SetSpawnPositionPacket();
        packetSetSpawnPosition.position = new BlockPosition(Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]));
        player.sendPacket(packetSetSpawnPosition);
    } else if (args[0].equalsIgnoreCase("motion")) {
        SetEntityMotionPacket mot = new SetEntityMotionPacket();
        mot.rtid = 1L;
        mot.motion = new Vector3F(0f, 0f, 0f);
        player.sendPacket(mot);
    } else if (args[0].equalsIgnoreCase("die")) {
        player.sendPacket(new SetHealthPacket(0));
    } else if (args[0].equalsIgnoreCase("tp")) {
        Vector3F dest = new Vector3F(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
        MovePlayerPacket m = new MovePlayerPacket();
        m.rtid = 1L;
        m.mode = (byte) (Integer.parseInt(args[4]) & 0xFF);
        m.position = dest;
        player.sendPacket(m);
        player.sendChat("\u00a7bTeleported to: " + dest.toString());
    } else if (args[0].equalsIgnoreCase("moveentity")) {
        Vector3F dest = new Vector3F(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
        MoveEntityPacket m = new MoveEntityPacket();
        m.rtid = 1L;
        m.teleported = args[4].equalsIgnoreCase("true");
        m.position = dest;
        player.sendPacket(m);
        player.sendChat("\u00a7bTeleported to: " + dest.toString());
    } else if (args[0].equalsIgnoreCase("chunk")) {
        /*
             * FullChunkData chunk = new FullChunkData(Integer.parseInt(args[1]),
			 * Integer.parseInt(args[2])); Arrays.fill(chunk.ids, (byte)1);
             */
        ChunkData data = new ChunkData();
        data.sections = new Section[16];
        for (int cy = 0; cy < 16; cy++) {
            data.sections[cy] = new Section();
            Arrays.fill(data.sections[cy].blockIds, (byte) 1);
        }
        FullChunkDataPacket chunk = new FullChunkDataPacket();
        chunk.x = Integer.parseInt(args[1]);
        chunk.z = Integer.parseInt(args[2]);
        data.encode();
        chunk.payload = data.getBuffer();
        player.sendPacket(chunk);
    } else if (args[0].equalsIgnoreCase("form")) {
        testForm(player);
    } else if (args[0].equalsIgnoreCase("sound")) {
        int id = Integer.parseInt(args[1]);
        LevelSoundEventPacket pk = new LevelSoundEventPacket();
        CachedEntity self = player.getEntityCache().getClientEntity();
        pk.position = new Vector3F((float) self.x, (float) self.y, (float) self.z);
        pk.sound = LevelSoundEventPacket.Sound.fromID(id);
        player.sendPacket(pk);
        player.sendChat("\u00a7bSound ID " + pk.sound.soundID + " (" + pk.sound.name() + ") sent");
    } else if (args[0].equalsIgnoreCase("painting")) {
        AddPaintingPacket pk = new AddPaintingPacket();
        pk.rtid = player.getEntityCache().getNextAtomicLong().incrementAndGet();
        pk.eid = pk.rtid;
        pk.pos = new BlockPosition(Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]));
        pk.direction = Integer.parseInt(args[4]);
        pk.title = args[5];
        player.sendPacket(pk);
        player.sendChat("\u00a7bPainting " + pk.title + " spawned at " + pk.pos.toString());
    }
}
Also used : ChunkData(org.dragonet.protocol.type.chunk.ChunkData) BlockPosition(org.dragonet.common.maths.BlockPosition) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Section(org.dragonet.protocol.type.chunk.Section) Vector3F(org.dragonet.common.maths.Vector3F) UpstreamSession(org.dragonet.proxy.network.UpstreamSession)

Aggregations

CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)26 PEPacket (org.dragonet.protocol.PEPacket)14 Vector3F (org.dragonet.common.maths.Vector3F)9 BlockPosition (org.dragonet.common.maths.BlockPosition)5 MoveEntityPacket (org.dragonet.protocol.packets.MoveEntityPacket)5 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)3 ArrayList (java.util.ArrayList)2 MobEffectPacket (org.dragonet.protocol.packets.MobEffectPacket)2 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)1 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 InteractAction (com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction)1 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)1 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)1 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)1 ClientPlayerInteractEntityPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket)1 ClientPlayerPlaceBlockPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket)1 ClientPlayerPositionRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket)1 ClientPlayerSwingArmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket)1