Set a customname for a block

Discussion in 'Spigot Plugin Development' started by LagBug, Jul 8, 2018.

  1. Hey there, I was wondering how I could set a customname for a block, I only found how to do it in chests but not in other blocks. Thanks
     
  2. JanTuck

    Supporter

    You can’t. Thank sir
     
  3. weeew great..
     
  4. Benz56

    Moderator Supporter

    What exactly do you mean?
    You can change item names (displayname) on blockbreak etc. but you can’t change what is shown in f3+h.
     
  5. Like that but not in a primed tnt https://snag.gy/1OtwV4.jpg
     
  6. Optic_Fusion1

    Resource Staff

    They probably spawn invisible named holograms or something
     
    • Agree Agree x 1
  7. you can use this code
    for added hologram up the tnt
    Code (Java):
        @EventHandler
        public void on(BlockPlaceEvent e) {
            Player p = e.getPlayer();
           
            if (e.getBlock().getType() == Material.TNT) {
                ArmorStand s0 = (ArmorStand) e.getBlock().getLocation().getWorld().spawnEntity(e.getBlock().getLocation().add(0.5D, -0.8D, 0.5D), EntityType.ARMOR_STAND);
               

               
                s0.setArms(false);
                s0.setGravity(false);
                s0.setSmall(false);
                s0.setVisible(false);
                s0.setCustomName("§6§lLUCKY TNT");
                s0.setCustomNameVisible(true);
                s0.setCanPickupItems(false);
            }
        }
     
  8. But still that wouldn't help in the EntityExplodeEvent
     
  9. No that's me but with a primedtnt and a customname
     
  10. Code (Java):
    @EventHandler
        public void on(EntityExplodeEvent e) {
            if (e.getEntityType() == EntityType.PRIMED_TNT) {
            Location tntloc = e.getEntity().getLocation();
           
           
               ArmorStand s0 = (ArmorStand) tntloc.getWorld().spawnEntity(tntloc.add(0.5D, -0.8D, 0.5D), EntityType.ARMOR_STAND);
             

             
               s0.setArms(false);
               s0.setGravity(false);
               s0.setSmall(false);
               s0.setVisible(false);
               s0.setCustomName("§6§lLUCKY TNT");
               s0.setCustomNameVisible(true);
               s0.setCanPickupItems(false);
            }
        }
    this on EntityExplodeEvent
     
  11. Nuu, you don't get me, I want when the tnt explodes for exapmple to get the customname that Benz said I can't have
     
  12. umm, you want change displayname of the item?
    [​IMG]
     
  13. Not the displayname, the customname
     
  14. Optic_Fusion1

    Resource Staff

    i assume he wants to get the name of the hologram
     
  15. Just check the link I sent above
     
  16. Spawn an invisible armorstand when the TNT is placed/ignites and listen to the explode event and then get the armorstand & remove it
     
  17. The best way is to create a custom event, so you'll have better control of what was done
     
  18. [​IMG]
     
    • Funny Funny x 2
  19. Just make a hologram like the other 2 answers told you
     
  20. Optic_Fusion1

    Resource Staff

    10/10 gif