Solved No Enum Constant

Discussion in 'Plugin Development' started by YoungCerly, May 21, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    YoungCerly

    Hey Bukkit! I'm currently getting an error in my token shop plugin. Below is the stack trace, the class the error is in and the config. I looked up this error and I couldn't really find anything that helped me so here I am.
    It'd be great if one of you guys can help me.

    Stack Trace (open)
    [​IMG]


    Code (open)

    Code:
    package me.cerlurs.advancedtokens.Commands;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import me.cerlurs.advancedtokens.Main;
    
    public class GUI implements CommandExecutor {
        Main plugin;
        public GUI(Main instance) {
            plugin = instance;
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player p = (Player) sender;
            int size = plugin.getConfig().getInt("Shop.Size");
            String name = plugin.getConfig().getString("Shop.Name");
            Inventory shop = Bukkit.createInventory(null, size, ChatColor.translateAlternateColorCodes('&', name));
           
            if (cmd.getName().equalsIgnoreCase("tokens")) {
                if (args[0].equalsIgnoreCase("shop")) {
                    if (p.hasPermission("advancedtokens.shop")) {
                        for (String s : plugin.getShop().getConfigurationSection("Items").getKeys(false)) {
                            if (Material.valueOf("Items." + s + ".ID") == null) {
                                p.sendMessage("invalid items");
                            } else {
                                String displayname = plugin.getShop().getString("Items." + s + ".Name");
                                ItemStack i = new ItemStack(Material.valueOf("Items." + s + ".ID"), plugin.getShop().getInt("Items." + s + ".Amount"));
                                ItemMeta m = i.getItemMeta();
                                m.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayname));
                                ArrayList<String> lore = new ArrayList<>();
                                for (String l : plugin.getShop().getStringList("Items." + s + ".Lore")) {
                                    lore.add(ChatColor.translateAlternateColorCodes('&', l));
                                }
                                int slot = plugin.getShop().getInt("Items." + s + ".Slot");
                                m.setLore(lore);
                                i.setItemMeta(m);
                                shop.setItem(slot - 1, i);
                                p.openInventory(shop);
                            }
                        }
                    }
                }
            }
            return false;
        }
    }


    [​IMG]
    Config (open)
     
  2. Offline

    Zombie_Striker

    @YoungCerly
    Don't Blind cast. Check if the sender is a player before casting.
    This will throw an Exception if the player does not provide any args. Check if the legnth of the args is greater than 0 (I.e if it is not empty) before getting the first arg.
    If the shop only has one item in the slot, the item will not be removed. Check if the the amount you're setting it to is 0, and if so, remove the item instead.
    Return true if the command worked as it should. Only return false when something failed.
    This can be condested into the following line
    Code:
    ArrayList<String> lore = plugin.getShop().getStringList("Items." + s + ".Lore")
    Main problem: Instead of getting the value AT THE PATH "Item.'I'.ID", you are asking for the material THAT IS "Item..ID". I think what you meant was to get a string from the config with that path.
     
  3. Offline

    YoungCerly

    Thanks so much for the help, I feel kind of stupid since I made such a simple error :p
    Also about all the other issues, I have changed my code
     
Thread Status:
Not open for further replies.

Share This Page