Commands, gui and server welcome don't work? (please read my comments to get full problem)

Discussion in 'Plugin Development' started by Mystic4phoenix, Mar 27, 2017.

Thread Status:
Not open for further replies.
  1. 1.)can some one look at the code and correct my mistakes it stopped working after adding the GUI please help.
    once done send a link to download the plugin edited code thanks. this is programmed in eclipse just to let people know. this is a learning curve for me so to help will help a lot thanks.
    2.)the plugin loads but non of the commands work and when you log on the server is meant to broadcast and send a message to the player that don't work to p.s its in a file because the code is in multiple classes and the lines of code are big.
    @iReD_xBlaDeZ
    and
    @mine-care
    3) @iReD_xBlaDeZ yes the plugin.yml in linked because it work before i added the GUI please look at the code and find the problem because i can not find it.
    4) @iReD_xBlaDeZ the gui still did not work why?
    5) @iReD_xBlaDeZ i did but it still did not work
     
    Last edited: Apr 4, 2017
  2. Offline

    iReD_xBlaDeZ

    Could you instead copy and paste your code on the forums?
     
  3. Offline

    mine-care

    @Mystic4phoenix And ontop of that be a litle more descriptive on what the issue is... "Stoped working" leaves many questions unanswered such as "Does it error?" "Does the plugin load" "What does/doesnt it do?" "Have you debuged your code?"
     
  4. Offline

    iReD_xBlaDeZ

    @Mystic4phoenix Did you include a plugin.yml? That may be why

    @Mystic4phoenix

    Alright so I found the problem. Your inventory isn't opening because you forgot to add player.openInventory(inv) in your 'openGUI' method.

    Whenever you create an inventory, make sure you make the player actually open the inventory ;)

    Code:
        public static void openGUI(Player player) {
            Inventory inv = Bukkit.createInventory(player, 9, "creative kit");
            ItemStack gamemodeC = new ItemStack(Material.SNOW_BALL);
            ItemMeta gamemeta = gamemodeC.getItemMeta();
            gamemeta.setDisplayName("gamemode c");
            ArrayList<String> skit = new ArrayList<String>();
            skit.add("current Gamemode: s ");
            gamemeta.setLore(skit);
            gamemodeC.setItemMeta(gamemeta);
            inv.setItem(4, gamemodeC);
            player.openInventory(inv);
        }
    
    Also another thing:

    In your online class, you're checking if the snowball is in the raw slot 9 when it isn't in the 9th (raw) slot when it is in the 4th (raw) slot.

    The first slot is 0, the second one is 1, the third one is 2, and etc. Since there are nine total slots, the 9th slot's raw number is 8 since you're counting 0 as the first slot.

    Here is an updated event for your online class:

    Code:
        @EventHandler
        public void onClick(InventoryClickEvent e) {
            if (e.getWhoClicked() instanceof Player) {
                Player player = (Player) e.getWhoClicked();
    
    
                if(e.getCurrentItem() != null) {
                    if(e.getCurrentItem().hasItemMeta()) {
                        if(e.getCurrentItem().getItemMeta().hasDisplayName()) {
                            if(e.getCurrentItem().getItemMeta().getDisplayName() == "gamemode c" ) {
                                if(e.getCurrentItem().getType() == Material.SNOW_BALL) {
                                        if (player.getGameMode().equals(GameMode.SURVIVAL) && e.getRawSlot() == 4) {
                                            player.setGameMode(GameMode.CREATIVE);
                                            player.sendMessage("your gamemode was updated");
                                        }
                                }
                            }
                        }
                    }
                }
            }
        }
    If you would like to prevent the player from taking the snowball, use
    Code:
    e.setCancelled(true);
    right below your message.

    Lastly, for your join message problem:

    You simply forgot to add the @EventHandler on top of your join event. When you do that it should work.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Mar 28, 2017
Thread Status:
Not open for further replies.

Share This Page