1.16.5 Does anyone have/know of simple beginner code to view?

Discussion in 'Spigot Plugin Development' started by etrdyhyrhr, Jan 17, 2021.

  1. I just looked at the plugin snippets from the wiki but I still feel like my understanding is lackluster. I think my best way of learning is through actual example, so if anyone knows of any open source plugin etc which is simple enough for a first timer, that would be much appreciated!
     
  2. if you have java experience i suggest watching tutorials from thesourcecode/codedred
     
    • Agree Agree x 2
  3. I subscribed to both channels and I'm currently a CS major so I couldn't agree more! I just starting watching them recently, do they teach the reasons you do certain things in Spigot as the series goes on?
     
  4. On top of the plugin snippets, which are usually more advanced additions, There is this:
    Spigot Plugin Development which are a bunch of tutorials to help get new developers started.
    You can check out "Creating a blank Spigot plugin with...", "Creating a config file", and that will have you up and running with your very own plugin... That does nothing, but it's still a plugin.
    Just browse through the rest of that, there are even links for learning Java in general. All very helpful to people just starting out.
     
  5. Well my main confusion is using methods and stuff like that, I usually get confused with what I should encapsulate in what, or what parameters I should be using? The wiki says a lot of confusing terms for a beginner like null and target etc, but what would I use?

    I have made a plugin that changes natural hostile mob spawn so that zombies have OP Gear, skeletons have speed, and creepers are charged. But doing something more than that is hopeless for me :(
     
  6. Well, either you don't understand the basics (Java tutorials will be your friend), or you don't know which methods to use, for which the Javadocs will help you a lot. They describe what the methods do, what the parameters need to be, when do certain events get fired, and so on.

    Null represents, in common terms, nothing. Briefly, variables point to a memory adress, which holds the value of the variable. If a variable is null, it just points to nothing. I don't know what you mean by the target part.

    That isn't bad. It seems like you already understand Java basics and OOP.

    If you don't, as I said earlier, just try to learn Java firstly and then move to Bukkit, you'll do yourself a big favor.
    If you indeed do, just try to implement random ideas which pop in your head, maybe read the questions from this section to see what others are doing and try to understand their code.
     
  7. I’ve been taking Java at my college some time so it isn’t an issue, I just don’t know which methods to use like you just said :/

    Yes I’ve been referring to the Java docs and I had to do some googling for the Pot effects such as that I need to encapsulate a method within another. This whole library is new to me so...

    The javadocs shows you all the methods and says what they do but I don’t know which methods require more more than a few straight forward arguments. (To me it’s like having a LEGO set without the instructions)

    EDIT:
    Code (Text):
    wither.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 9999999, 9999999));
    I had no idea I had to do new PotionEffect(), this is what I mean by not knowing how the methods are needed for encapsulation in order for it to work properly... that’s probably why I have no idea how to make a mob ride another mob with addPassenger()
     
    #7 etrdyhyrhr, Jan 17, 2021
    Last edited: Jan 17, 2021
  8. what does this even mean? you don't understand what the parameters mean? Give some examples on what you don't understand
     
  9. Well, that's why the Javadocs tells you what arguments methods and constructors need.
    potionconstructor.PNG
    PotionType is needed for Potion. Along with other options for further customization.
     
  10. Ok well I am knew here so I may be overthinking this, but here are a few examples:
    Code (Text):
    boolean addPassenger(@NotNull
    Entity passenger)
    My thought process: spider.addPassenger(what do I put in here if I want a NEW skeleton to be spawned on top of the spider CreatureSpawnEvent?);


    or as I put above:
    Code (Text):
    wither.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 9999999, 9999999));
    Why is "new PotionEffect" needed? It does not say to do this in the javadocs, and I personally would have assumed that no creation is needed if I did not know better....

    And finally how do you know how many/what methods are required to make the plugin function as expected?
    Code (Text):
     EntityEquipment entityEquipment = event.getEntity().getEquipment(); //Obtain the entity equipment from that zombie
                entityEquipment.setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE)); //set chestplate to that entity equipment
    Yes I understand what the code is doing now that I got some help with it, but on my own I would have no idea why each method is necessary... especially checking the equipment before equipping. Don't get me wrong that I have no idea what's happening, it's just for future reference I believe I'd have no idea what to encapsulate in what.
     
  11. Yes but it's very vague. The javadocs doesn't tell a beginner why one might need "new PotionEffect" to be encapsulated within the method for example. How do I learn to identify what is needed? Just practice?
     
  12. Honestly, start small, start from episode 1 on @CodedRed's channel and work up, he does a great job explaining everything.
     
    • Agree Agree x 1
  13. Experience. Experience. Experience. The Javadocs aren't meant to be memorized. They're meant to be used as a reference. Not sure how to create a PotionType instance for the Potion? Then look up PotionEffect's javadoc. Eventually you just know certain things as a result from using it often, but that just comes with time as others have mentioned.
     
    • Agree Agree x 2
    • Winner Winner x 1
  14. As someone who is taking Java courses through their college, you should be quite familiar with the keyword new in Java.

    As you can see in the JavaDocs at LivingEntity#addPotionEffect it is quite clear that you need a PotionEffect object to be passed into the method. The new keyword simply creates a new object. Encapsulating it within the method is simply a common way to pass the potion effect to the method, but if you really wanted to, you could do this

    Code (Text):

    PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, 9999999, 9999999);
    wither.addPotionEffect(effect);
     
     
    • Like Like x 1
    • Agree Agree x 1
  15. Yes, you should familiar with the new keyword like mentioned above.
    In tutorials and examples, variables are usually laid out step by step to avoid confusing like @Dartanman does.
    In practice how ever you want to minimize the amount of instructions and variables you actually pass along throughout your program.
    (I will generalize here, there is more going on than I state).
    You declare:
    PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, 9999999, 9999999);
    That is basically 3 instructions:
    1. Declare the variable effect, and prep it for initialization
    2. Process the constructor code that results from calling new PotionEffect(PotionEffectType.SLOW, 9999999, 9999999);
    3. Allocate memory space for effect and copy the results from 2 into memory.
    Then:
    wither.addPotionEffect(effect);
    This is basically 5 instructions
    1. Access the wither object
    2. Run the wither's addPotionEfftect, which will make new memory space for it's own temporary variable called effect.
    3. Read the original effect object
    4. Write (copy) the result form 3 to temporary effect
    5. Complete the rest of the steps for addPotionEffect
    So this is 8 steps in total.
    You can simplify it down to:
    wither.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 9999999, 9999999));
    1. Access the wither object
    2. Run the wither's addPotionEfftect, which will make new memory space for it's own temporary variable called effect.
    3. Process the constructor code that results from calling new PotionEffect(PotionEffectType.SLOW, 9999999, 9999999);
    4. Write (copy) the result form 3 to temporary effect
    5. Complete the rest of the steps for addPotionEffect
    So basically, because we eliminate that whole first line, you have eliminated all the steps that go with it.
    The remaining line is still the same, but the source of it's parameter (what is inside the "( )") is different.

    That is called engineering, and something that was taken seriously once upon a time. Now instead of Computer Engineers, we have Computer Scientist, and a lot of optimization strategies are completely disregarded and go untaught everywhere.
    10 years down the line (if we still use computers like this), which is not so far off, you will pick up on many, many, ways to have your programs run more efficiently, and understand the difference between example code, and production.
    For your C# stuff learn from the MSDN Library, they make it.
    For your Java stuff learn from the Oracle Library, they make it.
    For your Spigot/Bukkit/Paper stuff learn form their forums, they make it.
     
  16. I would recommend you work on making a basic Java application before trying to understand how to apply Java coding principles to Minecraft. Java is the foundation, the Spigot/Minecraft API is the application of your fundamental coding skills. My very first full-on Java application I made was a text-based story game in the terminal. I believe it was based somewhat around Pokemon but with a different theme? Anyways, learning how to do stuff like that will make the Spigot API much more understandable. :)

    If you are very motivated to learn specifically how to code in Minecraft, it will be very challenging but still possible! Start with something very very basic, like try to make a plugin that will print a message in chat whenever a player mines a diamond ore. This plugin seems boring but it would teach you EventHandlers, Player objects, how to send messages, etc. You can then move on to something more complicated like automatically smelting ores when a player mines them. Eventually you will be able to expand into whatever you imagine!

    If you want some help or want me to screen share some of my plugin development you can add me on discord adamag#3038
     
    • Like Like x 1