Can't pickup some Items

Discussion in 'Plugin Development' started by 0LUMIN4T0R, Nov 14, 2016.

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

    0LUMIN4T0R

    Hey guys,
    i'm still working on my minigame and i got another problem. This time i don't get any error so i doesn't had a chance to finde the mistake.
    Code:
        public void bronzeBlock(Location loc, Player p){
            int bronze = dropBronze(1);
            ItemStack bronzeItem = new ItemStack(336, bronze);
            ItemMeta meta = bronzeItem.getItemMeta();
            meta.setDisplayName(ChatColor.DARK_PURPLE + "Bronze");
            bronzeItem.setItemMeta(meta);
            loc.getWorld().dropItem(loc, bronzeItem);
          
            int silber = dropSilber(1);
            ItemStack silberItem = new ItemStack(265, silber);
            ItemMeta silberMeta = silberItem.getItemMeta();
            silberMeta.setDisplayName(ChatColor.DARK_PURPLE + "Silber");
            silberItem.setItemMeta(silberMeta);
            loc.getWorld().dropItem(loc, silberItem);
          
            int gold = dropGold(1);
            ItemStack goldItem = new ItemStack(266, gold);
            ItemMeta metagold = goldItem.getItemMeta();
            metagold.setDisplayName(ChatColor.DARK_PURPLE + "Gold");
            goldItem.setItemMeta(metagold);
            loc.getWorld().dropItem(loc, goldItem);
        }
    I don't have any problems with the first drop of the three. But when the gold and iron ingot drops, i'm not able to pick it up. the Method dropGold/Silber creates a random number which is not very imprtant for the problem, because the items get spawned.
    I hope you are able to help me:oops:
     
  2. Offline

    xelatercero

    soo your problem is that the player cant pickup the 2 items?, what does the drop[item] method?
     
  3. Offline

    0LUMIN4T0R

    yes i can't pickup the two items. It creates a random number:
    Code:
        private int dropSilber(int type){
            if(type == 1){
                if(Math.random()*5+1 == 1){
                    if(Math.random()*20+1 != 2){
                        return 1;
                    }else{
                        return 2;
                    }
                }
            }else if(type == 2){
                return (int) (Math.random()*3+1);
            }else if(type == 3){
                if(Math.random()*10+1 == 1){
                    return (int) (Math.random()*16+8);
                }
            }
            return 0;
        }
    It simply creates a int for the number of items, that should be dropped
     
  4. Offline

    Zombie_Striker

    @0LUMIN4T0R
    1. Do not use Item IDs. They are no longer supported by both Mojang and Bukkit and should not be used.
    2. Math.random produces a DECIMAL, not an int. There is less than a 1% chance that the number will be exactly equal to 1.
    3. Math.random changes each time you get it. You do two different if checks for dropSilber. Just keep this in mind. Also, your code will "almost" never return 2.
    4. Also, this is not how you should set up a "chance" system. For this, I would highly recommend using the "Random" object, because you can control the range of ints being generated (e.g. If you call "Random#nextInt(100)", you will get a number between 0 and 99. This is great if you want to know the chance of an action.
    For your main problem: have you debugged? Are you sure your code reaches the "dropGold" method? Are you sure the Itemstack is valid?
     
  5. Offline

    0LUMIN4T0R

    1.I tried it with Material.[...] too it didn't fix it.
    2.But when i cast an double to an int it will be rounded, doesn't it?
    3.+4. ok i'll try it, but the items drop anyway. So i don't think that this is the problem. Maybe it's another problem, that i'll run in later:rolleyes:

    Yes i have debugged and it reaches the methods. And it could not return 0, because the item drop
     
    Last edited: Nov 14, 2016
  6. Offline

    Zombie_Striker

    That is because it does not actually deal with the current problem. Just do not use IDs because they are no longer supported.
    Do not cast what you currently have to ints. That is not what I recommended.
    This point is actually tied with #4.
    Yes, this will be a problem later on. The thing is, you will run into this problem later (if you are not already) so you should fix it as soon as you can.

    Again, have you debugged? Are you sure the dropGold method ever gets called?
     
  7. Offline

    0LUMIN4T0R

    yes i have debugged. Sry i edited it above because i forgot it, but it seems like i was to late;-) Yes it gets called
     
  8. Offline

    Lordloss

    The only two options i can think of are: You modify the pickupDelay of the items. Or the PlayerPickupItemEvent gets cancelled from somewhere.
     
  9. Offline

    0LUMIN4T0R

    yes i thougt that too, but i don't use the PickupEvent and i never used pickupDelay. The only things that are connected to the items are posted allready

    today i've noticed something very strange. I joined the server and i don't know why but i was able to pickup the iron ingot. then i've coded the the gold ingot again and restarted the server. After that i was not able to pickup the iron and the gold ingot.:mad:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 16, 2016
  10. Offline

    Lordloss

    That sounds very strange. In my opinion there are 2 things you can do now. 1. You can setup a PlayerPickupItemEvent, change the priority to Monitor, and send yourself a chat message on item pickup. There you print out event.isCancelled() to see if it gets cancelled by another plugin. The 2. thing you can do is, send us your full code. Anything which affects this, so we can try it out ourself.
     
  11. Offline

    0LUMIN4T0R

    1. I've testet it, it prints out false. So this couldn't be the problem.
    2. here are all my classes of the project: https://www.dropbox.com/sh/zcoz8are7qv5fdt/AADlIcYVifHwR2j29dgi0LdXa?dl=0
     
  12. Offline

    Lordloss

    I can test it after im home from work. Could take a while, maybe someone else has time for it earlier.
     
  13. Offline

    0LUMIN4T0R

    okay thank you. i've put the .jar in there too, because i have deleted the pasword for mysql in the main class. And i think you'll get some errors because of the missing mysql server.
     
  14. Offline

    Lordloss

    Sorry, i saw your plugin uses BungeeCord. As this forces offline Mode, it is not supported in this forum.
     
  15. Online

    timtower Administrator Administrator Moderator

  16. Offline

    0LUMIN4T0R

  17. Online

    timtower Administrator Administrator Moderator

    Locked.
    Offline mode is not supported by Bukkit
     
Thread Status:
Not open for further replies.

Share This Page