Ir para conteúdo

Plugin de nao vir pedra na mina


Sm0nG4m1ng

Posts Recomendados

Olá eu vinha aqui pedir uma pequena ajuda. Eu estou fazendo 1 plugin para nao dropar nem pedra nem terra no /mina e eu ja acabei o plugin mas quando eu minero / cavo não ganho xp de mcmmo porque eu setei o bloco com AIR poderiam me ajudar a arrumar?

Código:

@EventHandler
private void onBlockBreak(BlockBreakEvent e) {
    Block b = e.getBlock();
    Player p = e.getPlayer();
    String world = Main.getInstance().getConfig().getString("Mundo");
    if(p.getWorld() == Main.getInstance().getServer().getWorld(world)) {
    if(p.getGameMode() == GameMode.SURVIVAL){
        if(b.getType() == Material.GRASS){
            b.setType(Material.AIR);
            
                }
        }
        if(b.getType() == Material.STONE){
            if(b.getDrops().contains(Material.COBBLESTONE)){
                e.getBlock().getDrops().clear();
                e.getBlock().getDrops().add(new ItemStack(Material.AIR, 0));
                        }
                    }
                }
            }

Link para o comentário
Compartilhar em outros sites

@EventHandler
public void QuebrarBloquinho(ItemSpawnEvent e) {
if (!e.getEntity().getLocation().getWorld().getName().equalsIgnoreCase("mina"))
return;
if (e.getEntity().getItemStack().getType() == Material.GRASS || e.getEntity().getItemStack().getType() == Material.STONE) {
e.setCancelled(true);
e.getEntity().remove();
}
}
}
Link para o comentário
Compartilhar em outros sites

4 horas atrás, B E E D disse:

@EventHandler
public void QuebrarBloquinho(ItemSpawnEvent e) {
if (!e.getEntity().getLocation().getWorld().getName().equalsIgnoreCase("mina"))
return;
if (e.getEntity().getItemStack().getType() == Material.GRASS || e.getEntity().getItemStack().getType() == Material.STONE) {
e.setCancelled(true);
e.getEntity().remove();
}
}
}

Eu faria:

    private static final String TARGET_WORLD_NAME = "mina";
    private static final List<Material> TARGET_MATERIALS = asList(//Static import
            Material.GRASS,
            Material.DIRT,
            Material.STONE,
            Material.COBBLESTONE
            //Outros
    );

    @EventHandler
    public void onBlockBreak(ItemSpawnEvent e) {
        Item entity = e.getEntity();
        if (!isTargetWorld(entity.getLocation()))
            return;

        if(TARGET_MATERIALS.contains(entity.getItemStack().getType())) {
            e.setCancelled(true);
            entity.remove();
        }
    }

    private static boolean isTargetWorld(Location location) {
        return location.getWorld().getName().equalsIgnoreCase(TARGET_WORLD_NAME);
    }

 

Link para o comentário
Compartilhar em outros sites

4 horas atrás, B E E D disse:

@EventHandler
public void QuebrarBloquinho(ItemSpawnEvent e) {
if (!e.getEntity().getLocation().getWorld().getName().equalsIgnoreCase("mina"))
return;
if (e.getEntity().getItemStack().getType() == Material.GRASS || e.getEntity().getItemStack().getType() == Material.STONE) {
e.setCancelled(true);
e.getEntity().remove();
}
}
}

para que remover a entidade se o evento é cancelado e o item (que é a entidade) não é spawnado?

Link para o comentário
Compartilhar em outros sites

56 minutos atrás, rubenlousada11 disse:

para que remover a entidade se o evento é cancelado e o item (que é a entidade) não é spawnado?

E porque no plugin de mina da internet tem algo que mesmo cancelando ele dropa a pedra, ou seja é só cancelar e apagar o drop ?

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...