Solved Getting Materials From a String

Discussion in 'Plugin Development' started by Guru2764, Sep 18, 2019.

  1. Offline

    Guru2764

    Hello,

    I am having issues getting a valid Material item with underscores in it from the three methods to do so (matchMaterial, getMaterial, and valueOf).

    args[6] is the space in the command where material names go, and the three codes I've tried are below:

    sender.sendMessage(args[6]);
    Material test = Material.getMaterial(args[6]);
    sender.sendMessage(test.toString());

    sender.sendMessage(args[6]);
    Material test = Material.valueOf(args[6]);
    sender.sendMessage(test.toString());

    sender.sendMessage(args[6]);
    Material test = Material.matchMaterial(args[6]);
    sender.sendMessage(test.toString());

    upload_2019-9-18_18-1-59.png
    This means the command worked (I think) and printed both the original string inputted, and the name of the material after running through the getMaterial method. But when I try to input a material with underscores:
    upload_2019-9-18_18-10-44.png
    Only the original string is printed, and below is the relevant error. This same error is given both from the getMaterial and matchMaterial methods.

    [Server] INFO Caused by: java.lang.NullPointerException
    [Server] INFO at io.github.guru2764.gedit.GEditCommandExecutor.onCommand (GEditCommandExecutor.java:32)

    The valueOf method gives this error:

    [Server] INFO Caused by: java.lang.IllegalArgumentException: No enum constant org.bukkit.Material.LEGACY_STONE_BRICKS
    [Server] INFO at io.github.guru2764.gedit.GEditCommandExecutor.onCommand(GEditCommandExecutor.java:31)
     
  2. Offline

    timtower Moderator Moderator

    @Guru2764 You didn't specify the api-version in the plugin.yml
     
    Guru2764 likes this.

Share This Page