Need some help on how to do things!

Discussion in 'Plugin Development' started by wptcraft, Sep 2, 2014.

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

    wptcraft

    How can i make a random number from 1 to 10? using something like
    Code:java
    1. random r = new random();

    and is there a event for lets say when a 322:1 (Enchanted golden apple) is eaten?

    Thanks Tom
     
  2. wptcraft
    Question 1) See JavaDocs
    Question 2) See JavaDocs

    I suspect that you haven't really learned Java. I suggest you learn the basics from the Oracle tutorials or a Java book before you try to make plugins, it will not go well if you don't. :)
     
  3. Offline

    wptcraft

    Thanks but no thanks i have no clue how to use the second one for help :/ its just a load of links.... and i never find what i actauly need, and i have learded most of the basics with java i just never learned randoms and im kinda going on a need to know basis i dont want to bother learn something that im not going to need at the time so could you help me more on the second one? AdamQpzm
     
  4. Offline

    jojo1541

    wptcraft
    Your random int problem has nothing to do with java but with simple mathematics. just read the JD for the random class and about 75% of your problem is solved.

    Same goes for your second question.
    A little tip:
    Code:java
    1. org.bukkit.event.player
     
  5. wptcraft I, like most other Java developers, consider the ability to use the JavaDocs a fundamental part of the "basics" of Java programming. After all, needing to ask for help everytime will hardly get you anywhere. I can understand maybe if it was a particularly difficult task, or maybe the Javadocs don't really explain it well, but I can assure you that generating random numbers is easy, and anyone that has sufficient Java knowledge, will be able to work it out using their past experience and the Javadocs, regardless of whether or not they've seen random numbers used before.

    The bukkit Javadocs? I'll try and help you out with that - on the version I've linked you, you will see a navigation menu. The menu starts with "Bukkit" and under that (it should be expanded by default) are things like "Welcome" and "Readme" and a few others. One of them is a submenu called "Classes". Click on this to expand it. Then expand "Class List". In here you will see every class in the Bukkit API. Since all of the classes are in the "org.bukkit" package, you'll have to first expand org and then expand bukkit. From here, you need to find a category that fits your question. The package "event" seems like a good start, so I'm going to expand that. Here we see yet more categories. Since you want to know when a player eats an item, the category "Player" seems appropriate. I'm going to expand that. Oh! There's a <censored to prevent laziness> event! I'm going to give that one a read!


    Alternative: Some people prefer the apidocs. Personally, I'm not one of these people, but maybe you are so I'll explain that too. Looking at the apidocs, there are a few ways you could go about this. In the navigation menu to the left, there are two sections. The bottom section is a list of all the classes in one place, regardless of package. This is mainly useful if you know exactly what you're looking for, though, so we'll ignore it for now. The top section of the menu is all the packages listed in one place. Follow the same routine as above (org > bukkit > event > player) to find the necessary event :) The middle of the page also replicates this top half's navigation method.
     
  6. Offline

    wptcraft

    Got it after around 10 minutes of searching... PlayerItemConsumeEvent?

    Now i have got it how do i check what item it is? i can use getItemInHand() because its going to be deleted before it fires, ive looked through the class and cant find anything

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  7. wptcraft Events fire before they actually 'happen' - that's why we can cancel (some of) them. And looking at the page you linked, I see it there. I suggest you reread the whole page :)
     
  8. Offline

    wptcraft

    how can i get the data the golden apple and check if its 1? ive tried
    Code:java
    1. public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent e) {
    2.  
    3. Player player = e.getPlayer();
    4.  
    5. player.sendMessage("You just ate a god apple!");
    6.  
    7. int iteminhand = player.getItemInHand().getTypeId();
    8. MaterialData iteminhanddata = player.getItemInHand().getData();
    9. if (iteminhand == 322);
    10. if(iteminhanddata.equals(1)) {
    11. player.sendMessage("Plugin is Working! God Apple has ben eaten!");
    12. }
    13. }
    14.  
    15. }}

    when i eat a god apple in game or eat food in general i dont get any messages
     
  9. Offline

    Necrodoom

    wptcraft read the materialdata javadocs. You can't compare MaterialData with Integer.
     
Thread Status:
Not open for further replies.

Share This Page