1.15.2 Updating from plugin from 1.12.1 Unknown Variable?

Discussion in 'Spigot Plugin Development' started by SkyyDaork, Feb 8, 2020.

  1. I was given a plugin I needed but it works on 1.12.1, I run on a server on 1.15.2 and wanted to update the plugin. I have it all completed but I cannot seem to find this "Key" variable thats being used:

    Code (Java):
    public void loadHats() {
        ConfigurationSection hats = getConfig().getConfigurationSection("hats");
        hats.getKeys(false).forEach(key -> {
              Material material = Material.getMaterial(Integer.valueOf(key).intValue());
              if (material == null) {
                getLogger().warning(key + " is not a valid item ID.");
    Is it something that needs imported? I've checked everything and cannot find any reference to this anywhere else in the plugin code
  2. Its part of the lambda expression in your foreach

  3. yes but all they "key" references afterwards are all errors
  4. Which java version are you using? I just threw your code into my test plugin, no errors!
  5. I've used 1.8 and 13 to try
  6. Can you share the error?
  7. Code (Text):
    key cannot be resolved to a variable
  8. Is this in your IDE?
  9. Yes.. not sure what happened but it decided to allow them suddenly.... now its freaking out about .getMaterial stating:
    Code (Text):
    The method getMaterial(String) in the type Material is not applicable for the arguments (Integer)
    I direct imported the plugin files and this is becoming more and more troublesome and im not the best at MC plugins
  10. That's because as of 1.13 ... numerical Material/Item IDs no longer exist.
    Each material has its own enum.
  11. ok so if they are renamed in config, how can i keep it linked?
  12. Code (Text):
    You need to change all the values in your config.
    Code (Java):
    for (Material material: Material.values()) {
    if (material.getId() == configId) {
               config.set(configName, material.toString);
  13. That's not his issue
  14. His issue is that he has numerical id‘s saved in his configuration and needs to change them into String-id‘s. If that‘s not his issue I don‘t know what is...
  15. His issue is that his IDE won't resolve a variable
  16. Which he has solved and now his problem is that Material#getMaterial(Int) cannot be resolved.
  17. I agree ^

    Im pretty sure we're past this.

    The user is having an issue using code that was removed .... ie: Material#getMaterial(int) ... this is now Material#getMaterial(String)
  18. My bad.

    In that case, OP, if you wish to maintain compatibility with numeric IDs, you may wish to look into XMaterial
    • Friendly Friendly x 2