Solved How can I convert a material type to a string value to print it to the chat?

Discussion in 'Spigot Plugin Development' started by OxygenMolecule, Oct 7, 2020.

  1. So I'm just starting out (with both java and plugins) and I wanted to make a plugin that checks the block the player is standing on and prints what the block is to the chat. So far I've got:


    @EventHandler
    public static void onPlayerWalk(PlayerMoveEvent event){
    Player player = event.getPlayer();
    int x = player.getLocation().getBlockX();
    int y = player.getLocation().getBlockY();
    int z = player.getLocation().getBlockZ();

    Material belowplayerfeet = player.getWorld().getBlockAt(x, y-1, z).getType();


    I want to be able to convert the material (belowplayerfeet) to a string value so that I can print it to the chat using player.sendMessage()

    How might I be able to do this?
     
  2. Belowplayerfeet.name()

    Keep in mind this gives the material enum name
    So it would be like RED_STAINED_GLASS for example.
     
  3. A good starter exercise would be to write a method that takes in a material and outputs a reader friendly string. In that method you can make all letters lowercase and replace underscores with spaces. Googling certain parts will help you if you don't know any further.
     
  4. Yes! This worked, thank you very much.
     
  5. Yes, that's what i will be working on now! Thank you.