src/main/java/xyz/tehbrian/buildersreach/highlight/FallingBlockHighlighter.java
public void highlight(final Player p, final Location loc, final int lifetime, final NamedTextColor color) {
        final IBlockData data = CraftMagicNumbers.getBlock(Material.valueOf(this.configConfig.data().fallingBlockType())).getBlockData();
        final EntityFallingBlock entity = new EntityFallingBlock(
                ((CraftWorld) loc.getWorld()).getHandle(),
                loc.getX() + 0.5,
                loc.getY(),
                loc.getZ() + 0.5,
                data
        );

        entity.setInvisible(true);
        entity.setInvulnerable(true);
        entity.getBukkitEntity().setGlowing(true);
        entity.setNoGravity(true);

        final Team team = this.scoreboardService.getColoredTeam(color);
        team.addEntry(entity.getUniqueID().toString());

        final EntityPlayer ePlayer = ((CraftPlayer) p).getHandle();
        final PlayerConnection connection = ePlayer.b;

        final PacketPlayOutSpawnEntity spawnPacket = new PacketPlayOutSpawnEntity(entity, Block.getCombinedId(data));
        final PacketPlayOutEntityMetadata metaPacket = new PacketPlayOutEntityMetadata(
                entity.getBukkitEntity().getEntityId(),
                entity.getDataWatcher(),
                true
        );

        connection.sendPacket(spawnPacket);
        connection.sendPacket(metaPacket);

        Bukkit.getScheduler().scheduleSyncDelayedTask(this.buildersReach, () -> {
            final PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(entity.getId());
            connection.sendPacket(destroyPacket);
            team.removeEntry(entity.getUniqueID().toString());
        }, lifetime);
    }
// TODO: optimize by not deleting the block every tick
optimize by not deleting the block every tick
optimize by not deleting the block every tick
public void highlight(final Player p, final Location loc, final int lifetime, final NamedTextColor color) {
        final IBlockData data = CraftMagicNumbers.getBlock(Material.valueOf(this.configConfig.data().fallingBlockType())).getBlockData();
        final EntityFallingBlock entity = new EntityFallingBlock(
                ((CraftWorld) loc.getWorld()).getHandle(),
                loc.getX() + 0.5,
                loc.getY(),
                loc.getZ() + 0.5,
                data
        );
        entity.setInvisible(true);
        entity.setInvulnerable(true);
        entity.getBukkitEntity().setGlowing(true);
        entity.setNoGravity(true);
        final Team team = this.scoreboardService.getColoredTeam(color);
        team.addEntry(entity.getUniqueID().toString());
        final EntityPlayer ePlayer = ((CraftPlayer) p).getHandle();
        final PlayerConnection connection = ePlayer.b;
        final PacketPlayOutSpawnEntity spawnPacket = new PacketPlayOutSpawnEntity(entity, Block.getCombinedId(data));
        final PacketPlayOutEntityMetadata metaPacket = new PacketPlayOutEntityMetadata(
                entity.getBukkitEntity().getEntityId(),
                entity.getDataWatcher(),
                true
        );
        connection.sendPacket(spawnPacket);
        connection.sendPacket(metaPacket);
        Bukkit.getScheduler().scheduleSyncDelayedTask(this.buildersReach, () -> {
            final PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(entity.getId());
            connection.sendPacket(destroyPacket);
            team.removeEntry(entity.getUniqueID().toString());
        }, lifetime);
    }
public void highlight ( final Player p , final Location loc , final int lifetime , final NamedTextColor color ) { final IBlockData data = CraftMagicNumbers . getBlock ( Material . valueOf ( this . configConfig . data ( ) . fallingBlockType ( ) ) ) . getBlockData ( ) ; final EntityFallingBlock entity = new EntityFallingBlock ( ( ( CraftWorld ) loc . getWorld ( ) ) . getHandle ( ) , loc . getX ( ) + 0.5 , loc . getY ( ) , loc . getZ ( ) + 0.5 , data ) ; entity . setInvisible ( true ) ; entity . setInvulnerable ( true ) ; entity . getBukkitEntity ( ) . setGlowing ( true ) ; entity . setNoGravity ( true ) ; final Team team = this . scoreboardService . getColoredTeam ( color ) ; team . addEntry ( entity . getUniqueID ( ) . toString ( ) ) ; final EntityPlayer ePlayer = ( ( CraftPlayer ) p ) . getHandle ( ) ; final PlayerConnection connection = ePlayer . b ; final PacketPlayOutSpawnEntity spawnPacket = new PacketPlayOutSpawnEntity ( entity , Block . getCombinedId ( data ) ) ; final PacketPlayOutEntityMetadata metaPacket = new PacketPlayOutEntityMetadata ( entity . getBukkitEntity ( ) . getEntityId ( ) , entity . getDataWatcher ( ) , true ) ; connection . sendPacket ( spawnPacket ) ; connection . sendPacket ( metaPacket ) ; Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( this . buildersReach , ( ) -> { final PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy ( entity . getId ( ) ) ; connection . sendPacket ( destroyPacket ) ; team . removeEntry ( entity . getUniqueID ( ) . toString ( ) ) ; } , lifetime ) ; }
TODO: optimize by not deleting the block every tick
TODO : optimize by not deleting the block every tick