[Code] Menu don't loads config strings

Discussion in 'Spigot Plugin Development' started by relampagorojo93, Jun 22, 2015.

  1. Well, I did a post yesterday, but I saw that the problem isn't this. I saw with experiments that the fail is the menu. I need help to do that because I'm new in variable menus. The problem is that: I can change all of the icons, but if I reload the plugin with the command only one time, this item is constant. All can be changed, excepting the Enable String. If I disable it, anything changes, because it detects as the item already is created and keeps the icon
  2. public void openMenu(Player player){
    int d1 = getConfig().getInt("Warps.Slot-1.Item-id");
    int d2 = getConfig().getInt("Warps.Slot-2.Item-id");
    int d3 = getConfig().getInt("Warps.Slot-3.Item-id");
    int d4 = getConfig().getInt("Warps.Slot-4.Item-id");
    int d5 = getConfig().getInt("Warps.Slot-5.Item-id");
    int d6 = getConfig().getInt("Warps.Slot-6.Item-id");
    int d7 = getConfig().getInt("Warps.Slot-7.Item-id");
    int d8 = getConfig().getInt("Warps.Slot-8.Item-id");
    int d9 = getConfig().getInt("Warps.Slot-9.Item-id");
    int d10 = getConfig().getInt("Warps.Slot-10.Item-id");
    int d11 = getConfig().getInt("Warps.Slot-11.Item-id");
    int d12 = getConfig().getInt("Warps.Slot-12.Item-id");
    int d13 = getConfig().getInt("Warps.Slot-13.Item-id");
    int d14 = getConfig().getInt("Warps.Slot-14.Item-id");
    int d15 = getConfig().getInt("Warps.Slot-15.Item-id");
    int d16 = getConfig().getInt("Warps.Slot-16.Item-id");
    int d17 = getConfig().getInt("Warps.Slot-17.Item-id");
    int d18 = getConfig().getInt("Warps.Slot-18.Item-id");
    String name1 = getConfig().getString("Warps.Slot-1.Name");
    if (getConfig().getString("Warps.Slot-1.Enable").equals("True")) {
    ItemStack W1 = new ItemStack(d1);
    ItemMeta W1Meta = W1.getItemMeta();
    W1Meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name1));
    W1.setItemMeta(W1Meta); Warps.setItem(0, W1);
    String name2 = getConfig().getString("Warps.Slot-2.Name");
    if (getConfig().getString("Warps.Slot-2.Enable") == "True") {
    ItemStack W2 = new ItemStack(d2);
    ItemMeta W2Meta = W2.getItemMeta();
    W2Meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name2));
    W2.setItemMeta(W2Meta); Warps.setItem(1, W2);

    The other if are similar as this but with a number incrementation. I did it. I created a code that give an item to the users if they have the permission and they join. After that, I configured manually a warp to try if this works. I used the reload command and I charged all the things. I open the menu, and there is the item. But when I disable the item, it stills in the menu. I thing that after the set item from this code, the item was defined as constant. Enable this only is for edit the things of the icon. I wanted to do that if the item is disabled, this item dissapears.
    #3 relampagorojo93, Jun 22, 2015
    Last edited: Jun 22, 2015
  3. Please use the [ code ] tag next time instead of the spoiler tag
    So I should start out with creating an array(list) and just loop over all of them. it would clean up 90% of your code.
    Also, why are you using getString() to check if it's true? While you can just do getBoolean.
    Beside that, you should never check a string with ==, you should use equals or equalsignorecase.

    And you can replace this:
    Code (Text):

    with a simple saveDefaultConfig();
  4. I changed some things, but I don't want to change all for the moment. First I want to know why it happens.

    This three images are what happens if I enable and disable the config:

    #5 relampagorojo93, Jun 22, 2015
    Last edited: Jun 22, 2015
  5. Well, be a genious about logical things is only factible in the last moment, but well. Having the code of the inventory in all the code, this inventory is transformed into constant, only is modified during the usage of diferent methods. But if this method don't do anything to remove the item, the inventory is constant, and the items will still there. I put the code of the inventory into the code openMenu, to generate a new menu on every ejecution. With that, the menu can have the items disabled.