Item On Join Problem!

Discussion in 'Plugin Development' started by MrGriefer_HGTech, Apr 9, 2015.

Thread Status:
Not open for further replies.
  1. I am working on a plugin that whenever a player joins it will give them an item which they can modify on the config file, but whenever the player joins it wont give them the item?

    Here is what I did on PlayerJoinEvent:

    Code:
    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        giveItem(player);
    }
    If you are asking what is giveItem(player);

    Here is the code for it:

    Code:
    public void giveItem(Player player) {
    player.getInventory().setItem(plugin.getConfig().getInt("Speed-Item.giveslot"), item);
    }
    Why doesn't it work, I register the class and it still doesn't work!
     
  2. Offline

    Unica

    @MrGriefer_HGTech

    Assuming you registered correctly;
    - Is the config file correct?
    - Is the inventory correctly updated
    - What is 'item' ?
    - try
    Code:
    p.getInventory().addItem(new ItemStack(Material.STICK));
    for debugging
     
  3. @Unica
    I did register it correctly here is what did to register the class:

    Code:
    public void setupItem() {
            if (!this.getConfig().getString("Enable").equalsIgnoreCase("false")) {
                Bukkit.getPluginManager().registerEvents(new InteractListener(this), this);
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        setupItem();
                    }
                }, 5L);
            }
        }
    And then on the onEnable just setupItem()

    If you are looking at the code above ^
    There is if (!this.getConfig().getString("Enable").equalsIgnoreCase("false")) {
    which i don't know what do i put on the config, what i did it like that:
    Enable: 'false'

    Should i remove the ' mark or not?

    I didn't update players Inventory!

    Here is the code for the item (item is just an ItemStack):
    Code:
    ItemStack item = null;   
    
    public void setupItem() {
            String[] type = plugin.getConfig().getString("Speed-Item.type").split(":");
            item = new ItemStack(Material.valueOf(type[0].toUpperCase()), 1, Short.parseShort(type[1]));
            ItemMeta im = item.getItemMeta();
            im.setDisplayName(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Speed-Item.name")));
            ArrayList<String> lore = new ArrayList<String>();
            for (String l : plugin.getConfig().getStringList("Speed-Item.lore")) {
                lore.add(ChatColor.translateAlternateColorCodes('&', l));
            }
            im.setLore(lore);
            item.setItemMeta(im);
            if(!plugin.getConfig().getString("Speed-Item.glow").equalsIgnoreCase("false")) {
                item.addUnsafeEnchantment(glow, 1);
            }
        }
     
  4. Offline

    cnc4

  5. @MrGriefer_HGTech That setupItem though....

    Just do a simple if check in onEnable, don't do a string check and don't add a delay to registering an event.

    There is a #getBoolean you know.
     
  6. @cnc4 I did and it still doesn't work!

    @bwfcwalshy if (!this.getConfig().getBoolean("false")) { is that how to use the .getBoolean right?

    Also on the config file I should make Enable: 'true' or true without the ' mark?
     
  7. Offline

    Zombie_Striker

    @MrGriefer_HGTech
    Did you debug? All you need to do to find out whats not working is to just Debug.
     
  8. @MrGriefer_HGTech The method argument points to the path. Then remove the ' from the config thing.
     
  9. @bwfcwalshy I did if (!this.getConfig().getBoolean("false")) { and it still doesn't work! :(
     
  10. @bwfcwalshy I did if (!this.getConfig().getBoolean("Enable")) { but how can i check if its false then it will register the class?
     
  11. @MrGriefer_HGTech Do you know how Booleans work? You are checking if it is false, I recommend you read up on Java before doing Bukkit.
     
Thread Status:
Not open for further replies.

Share This Page