Untitled

 avatar
unknown
plain_text
a year ago
3.6 kB
8
Indexable
public class Bombers extends Enchantment {

    public static List<UUID> playersWithArmorStand = new ArrayList<>();
    private final Map<UUID, Boolean> bombersMap = new HashMap<>();
    
    public Bombers() {
        super("bombers", "BlockBreakEvent");
    }

    @Override
    public void execute(Player player, Block block) {
        bombersMap.put(player.getUniqueId(), true);
        playersWithArmorStand.add(player.getUniqueId());
        shootBlockDisplay(playersWithArmorStand, block.getLocation(), player, block);
    }


    public static void shootBlockDisplay(List<UUID> players, Location location, Player player, Block blockY) {

        location.add(0,10,0);

        PlayerSpace playersInPackets =  PlayerSpace.create(players).build();

        // You will probs see i'm using BlockDisplay.class, instead of ClientBlockDisplay.class. There's some errors in his wrapper, and doesn't allow
        // block transformations via vectors. So I had to use the bukkit entity instead. (This still acts as a packet entity)
        ClientBlockDisplay block = playersInPackets.spawn(location, BlockDisplay.class);

        block.setBlock(Material.TNT.createBlockData());
        block.setGlowing(true);

        // You had a vector before, this is the same thing, but in a different way. This is the direction of the block, and i'm setting it to the direction of the player.
        block.getLocation().setDirection(new Location(player.getWorld(),0,0,0).toVector().subtract(block.getLocation().toVector()));

        if(block.getLocation().getBlockY() <= blockY.getLocation().getBlockY() || block.getLocation().getBlock().getType().isSolid()) {
            player.sendMessage("block is on ground or solid");
        }

        // Why are we adding the same player to the list again? This is already done in the execute method
        playersWithArmorStand.add(player.getUniqueId());


        new BukkitRunnable() {
            @Override
            public void run() {
                // Move the block downwards
                Location blockLocation = block.getLocation();

                // This will progressively move the block downwards


                blockLocation.add(0, -0.1, 0);

                // This will teleport the block to the new location
                block.teleport(blockLocation);


                // We want to annouce the packet to the players in the list, so they can see the block moving
                playersInPackets.announce();


                // Check if the block has reached the target Y coordinate or hit a solid block
                if (blockLocation.getY() <= blockY.getLocation().getY() || blockLocation.getBlock().getType().isSolid()) {
                    player.sendMessage("Block is on ground or solid");
                    new UtilsModel().createNaturalExplosion(player, blockLocation.getBlock(), 5, true, false);
                    despawnEntity(block);
                    cancel();
                }
            }
        }.runTaskTimer(InfluxedEnchantCore.getInstance(), 0, 1L);

        try {
            playersInPackets.close();
        }catch (IOException e){
            throw new RuntimeException();
        }
    }
    public static void despawnEntity(ClientEntity entity){
        for (UUID uuid : playersWithArmorStand) {
            WrapperPlayServerDestroyEntities destroyPacket = new WrapperPlayServerDestroyEntities(entity.getEntityId());
            PacketEvents.getAPI().getPlayerManager().sendPacket(Bukkit.getPlayer(uuid), destroyPacket);
        }
    }
}
Editor is loading...
Leave a Comment