Solved List<String> to List<Material> Only showing _AXE and not DIAMOND_AXE

Discussion in 'Spigot Plugin Development' started by 01v, Dec 1, 2018.

  1. 01v

    01v

    Hi, I am trying to make a plugin, where I want to make a list in the config, and, then convert it to a List<material>. I thought I had done it correctly but found out if I try printing one of the items in the list, I only get the last part. for example in DIAMOND_AXE, it prints _AXE, or DIAMOND_CHESTPLATE, it only prints _CHESTPLATE.

    Anyone got any ideas why it does that?
    Code (Java):
    package me.ZeroOneV.RepairGem;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;

    import java.util.List;
    import java.util.stream.Collectors;

    public class RepairGemMain extends JavaPlugin {

        public static List<Material> materialList = null;
        @Override
        public void onEnable() {
            getServer().getConsoleSender().sendMessage(ChatColor
                    .translateAlternateColorCodes('&', "\n\n&eRepairGem Enabled\n\n"));
            loadConfig();
            loadMaterialConverter();
            plugin = this;
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerEvents(), this);

        }
        @Override
        public void onDisable() {
            getServer().getConsoleSender().sendMessage(ChatColor
                    .translateAlternateColorCodes('&', "\n\n&4Repairgem Disabled\n\n"));

        }

        public void loadConfig() {
            getConfig().options().copyDefaults(true);
            saveDefaultConfig();
        }
        public static Plugin plugin;

        public void loadMaterialConverter(){
            List<String> allowedrepair = getConfig().getStringList("RepairAbleItems");
            materialList = allowedrepair.stream().map(Material::getMaterial).collect(Collectors.toList());

        }

    }
    Code (Java):
    package me.ZeroOneV.RepairGem;

            import org.bukkit.configuration.file.FileConfiguration;
            import org.bukkit.entity.Player;
            import org.bukkit.event.EventHandler;
            import org.bukkit.event.Listener;
            import org.bukkit.event.player.PlayerInteractEvent;
            import org.bukkit.inventory.ItemStack;

    public class PlayerEvents implements Listener {

        FileConfiguration config = RepairGemMain.plugin.getConfig();

        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            ItemStack item = e.getItem();
            ItemStack im = p.getInventory().getItemInMainHand();
            p.sendMessage(RepairGemMain.materialList.get(1).toString());

            if(item != null && im.isSimilar(item)){
                if(RepairGemMain.materialList.contains(p.getInventory().getItemInMainHand().getType())){
                    p.sendMessage("MaterialList Contains =");
                }else{
                    p.sendMessage(" Not Containing");
                }
            }else{
                p.sendMessage("No item in main hand");
            }

        }
    }
    Code (YAML):
    RepairAbleItems:
     - "DIAMOND_AXE"
      - "DIAMOND_CHESTPLATE"
     
  2. md_5

    Administrator Developer

    List<Material> can't ever contain _AXE, because there is no Material._AXE....

    Not sure what's going on here.

    If you're using 1.13 be sure to define api-version: 1.13 in plugin.yml
     
  3. 01v

    01v

    That fixed it. I dont know how, or why it did, but it's fixed. Thank you.