Player input, i need help

Discussion in 'Plugin Development' started by john2342, Jul 21, 2014.

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


    Hi guys, im trying to make a /guild plugin, but Im stuck at the part where you take the plyer input and apply it, like /guild create guildname im not sure how I can get the guild name, or a better example is /message <message> how do I take what the player put in <message>???? Please help!
  2. Offline


    Your function to fetch the commands is probably something like
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if (cmd.getName().equalsIgnoreCase("myCommand")) {
    3. //Do stuff
    4. }
    5. }

    The important thing is the last argument (String[] args). If contains a list of everything the player wrote besides the command. It's a list that starts at 0 (the first entry is at position 0).
    Example: I do /message Notch Hi, Notch!
    args[0] would be "Notch",args[1] would be "Hi," and args[2] "Notch!"!
    So, if you wanted to tell the player the message (or create the guild or whatever), you have to get the arguments. But please note that the arguments don't have to be given.
    Example: I do /message
    args[0] would be a IndexOutOfBoundsException in the console and you wouldn't be able to get the value of the other content because java won't execute the rest of your onCommand :p
    To prevent this, you can check the length of the array. /message Notch Hi, Notch! would have make args.length equal 3 (Notch, Hi, and Notch!).
    You can of course use the length in combination with an if statement to check if the command is valid
    1. if (cmd.getName().equalsIgnoreCase("myCommand")) {
    3. if (args.length < 2) {
    4. sender.sendMessage("Please enter two options!");
    5. return true; //This also tells java not to execure your code anymore. "return" will leave the funtion instantly
    6. }
    7. if (args[0].equalsIgnoreCase("create")) {
    8. //Replace with your code to create a guild
    9. createGuild(args[1]);
    10. }
    11. }
  3. Offline


    Watch tutorials.
  4. Offline


    _LB likes this.
  5. Offline


    fireblast709, _LB and LCastr0 like this.
  6. Offline


    Not really. While Java is a great help while learning Bukkit, the other way around works perfectly fine too.

    If someone is too dumb to watch a video, do you actually expect them to read?
  7. Offline


    Yep, just like running is great practice for learning to walk...

    No. But if somebody is going to watch a video, I would recommend that they also read.

    On a side note, have you made it your mission to give as much bad advice to people as possible?
    _LB, teej107, LCastr0 and 2 others like this.
  8. Offline


    TheMcScavenger Because people may understand things differently?
    Also, how the heck are you expected to learn a language off an API that uses it, without understanding the language.
  9. Offline


    What bad advice am I giving? That people should watch tutorials? Yea, very bad!

    It's exactly how I did it a couple years ago. I started with Bukkit, learned the basics of Java through Bukkit Tutorials, and afterwards learned more about Java.
  10. Offline


    tbh, that's how I learned too, but I agree with the other people, it's a very bad path to take.
    Garris0n likes this.
  11. Offline


    Whether it's good or bad is a personal opinion, not a fact. It's a good way of getting interested in the language, and getting ideas of how to learn it, instead of making ten calculators.
  12. Offline


    TheMcScavenger Fact is, from previous posts you made, this hasnt been your best idea, and, its most recommended to learn java before trying to use a random API made in java, because if you tried to learn the API, all youd do is copy-paste code.
  13. Offline


    >Just store player instances, it's fine!

    >Learn Bukkit before Java!


    Sure it can be a decent motivator, but trying to learn Java and Bukkit at the same time just doesn't work out. The API isn't exactly the best tutorial for good object-oriented practices, either. Mostly, however, Bukkit simply has a dependency on knowing Java. Now, perhaps you don't have to be some sort of Java expert before jumping into Bukkit, but basic Java is definitely a prerequisite.
    KingFaris11 and Gnat008 like this.
  14. Offline


    Like I've tried to explain multiple times already, it's not a requirement. Sure, it's great if you know Java already, and it'll help you greatly, but the other way around is just fine as well. It's all up to personal preference. It's the same as "What is better, Mac or Windows?", it's personal preference.
  15. Offline


    That's like saying it's not a requirement to learn to walk before you learn to run. I mean sure knowing how to walk would be helpful, but you don't need it, right? -.-
    Gnat008 likes this.
  16. Offline


    By this logic, writing a book in English does not require knowing English. I mean, sure, you could google "english for xxx" and cobble together a copy-pasted book, but it would be a horrible book dictated by what results you could find. Your book would miss entire paragraphs because you couldn't find translations. Your grammar would be awful. Nobody would read your book.

    The exact same thing applies to writing Bukkit plugins without Java knowledge. Sure you can google "how to do xxx bukkit" and create some sort of Frankenstein's monster plugin (a pedantic person somewhere just cried at their lost opportunity), but what good is that? All you're doing is creating an ugly, badly-implemented collage of other people's work that you barely understand in the first place.

    Learn. Java. First.
  17. Offline


    Wrong and wrong. I have nothing more to say, you're both ignorant.
  18. Offline


    So they are ignorant for not listening to whatever you keep spouting off, yet you aren't for not considering their position? 'Kay then.
  19. Offline


    Ah yes, the one who goes around telling others to commit suicide because they don't agree with him is calling me ignorant.

    Pizza371 and Gnat008 like this.
  20. Offline


    TheMcScavenger sounds mad ( ͡° ͜ʖ ͡°)
  21. Tbh:
    I learnt most of my stuff from self-teaching/Stackoverflow.
    The basics of Java I learnt from youtube, after 6 months or a year of learning Java, I went into Bukkit plugin development by WoopaGaming from Youtube, then after I started self-teaching purely.

    You'd think that things using Java that have no relation to Bukkit are useless, but actually, I learnt a huge amount of things useful in my plugins from learning 3D Game Development from TheChernoProject on Youtube.
  22. Offline


  23. TheMcScavenger There are numerous problems with video tutorials, but I'd like to point out a few here. I'm sure that there are more problems than I'm going to point out, though.

    • Different learning types - This may seem like an odd way to sum up my first point, but since I see it commonly used by those who defend video tutorials, I thought I'd like to address this first. Yes, different people learn in different ways, so at the face of it, video tutorials seem to fit into this category of "different type" quite nicely - after all, while video tutorials may not be relatively old, surely it satisfies the same learner type as older observation and hands-on techniques? Blacksmiths were trained like this, right? By observing a skilled blacksmith and following along with what they do, just like a video tutorial. However, that's where a fundamental difference comes into play. Yes, you can follow along with a video just as an apprentice could follow along with a blacksmith, but the difference is that the blacksmith was able to provide feedback directly and immediately. If you did something wrong, or if what you were doing wasn't wrong but could be done better, they could address that issue right away. Video tutorials do not offer such feedback opportunities, so the "different learning types" argument has a pretty major flaw.
    • Different learning paces - As well as learning in different ways, people also learn at different speeds. While I certainly can't speak for everyone, this is often feedback I see regarding video tutorials so I'm sure that enough people feel the same for this to be a valid point: video tutorials are generally bad at respecting people's pace. For the rest of this example, I'll compare thee to a summer's day videos with books.
      • What if you want to take a break?
        • In a book, I find that at the end of a chapter is a very convenient stopping point, as is the intention of a chapter. However, I also find that it's often okay to just leave the book how you currently are (well, finish the sentence first at least - leaving it mid-sentence would just be weird)
        • In a video I find that the most convenient stopping point is at the end of the video. While you could argue that some video tutorials have chapters as a book does, I often find these are the exception, and not all of such videos have a well designed structure that a book should have. Sure, videos are generally shorter, so waiting until the end for a convenient stopping point shouldn't be that daunting, but to me that's how it feels. There's also something off-putting about stopping a video midway through. It might have something to do with what I said above - it's definitely harder to stop a video at the end of a sentence. I often cut people off as they start their next one.
      • What if you didn't quite understand the last part, and want to go over it again to help you understand it?
        • In a book, this is generally no problem! You can just read the last sentence or two again.
        • In a video, this is definitely at risk of being a more complicated ordeal - it will certainly never be easier than a book, and the best it can hope for is being as easy as a book. The problem I have with videos here is that "repeating the last sentence" can be an overly complicated thing. Since you have to reverse the video, you can easily undershoot or overshoot it, and miss some or have to wait until you get to the correct part. This might not be that big of a deal, but it's definitely a negative.
      • What if you closed the medium earlier and want to resume now? (For both of these examples, I'm going to assume a good learner who has noted down his current position before closing. This of course won't always be the case, but you can hardly attribute that to the medium rather than the learner).
        • For a book the learner has either noted down the page they were on, have a bookmark, or have folded the corner of the page (poor book). Finding the page again shouldn't be all that difficult from here.
        • For a video, the learner has noted down the time they were up to in the video. This generally shouldn't be too hard to find and resume, either. But there is an added minor inconvenience - most people generally do not download a video tutorial, and instead watch it online. This may mean that they will have to buffer the video first. Not such a big deal, especially in a time of improving broadband speeds, but still an inconvenience not found in a book.
    • Lifespan of information - It's inevitable that eventually, any tutorial's information will be outdated once new things come along. This is especially the case if you follow the "learning java through bukkit" theory. With each new layer of dependencies you add into the mix, the faster information will be outdated. Let's assume there's a tutorial aimed at Java - it will be outdated as soon as there is a new version of Java (admittedly this doesn't happen all that often - unless you count minor updated which aren't there to change the language). But what if there was a tutorial on Bukkit, that also covered Java? It would be out of date as soon as either Bukkit or Java received an update. What if there was a tutorial for ProtocolLib that also covered Bukkit and Java? It would be outdated as soon as any of the three receive an update. The more things you add to the tutorial, the more likely it is that one will update and outdate your tutorials information. This is one of the reasons why "parent and child" tutorials are a bad idea. But now to tie this back to video tutorials: when online tutorials can easily be updated, as the corrections can just be made without having to start over (unless the change is drastic enough to require a complete rewrite of course). With books, it's generally the same as online tutorials - simply correct the information - except that these are often released as new editions (any chance for extra money, eh?). And video tutorials... generally aren't updated or, at best, an annotation points out how stuff has changed, undermining the model of a video tutorial. The fact is, a video would probably have to be re-recorded, and corrections aren't so easily, and have less to gain. This means that videos are often left outdated.
    There, I've said too much about my opinion on video tutorials, but hopefully it helps demonstrate that it's an opinion that is backed up on facts. Of course it won't apply to everyone, but I did my best.
    As for your "there's nothing wrong with learning the language through a third-party API" there most certainly is. Sure, you can do it, but it often leads to problems that the person will not be able to solve, and won't know enough to even be able to get help from others. Most of the good tutorials for Bukkit are aimed at people who already have sufficient Java knowledge - I've already pointed out a problem with "one tutorial to rule them all" types of tutorials, but there are more. I find that tutorials aimed at people who do not know Java are often of a lower quality, and help to breed bad practices and misconceptions. I find they're also often geared towards people's impatience (as impatience is the main reason most want to learn Bukkit before learning Java) and therefore cut corners in order to speed along to the fun stuff (Oh, they don't really need to know about OOP. Oh, they don't really need to know the value range of primitive values. etc.)
    Rocoty, Garris0n and ReggieMOL like this.
  24. Offline


    Excuse me for telling this but the best way to learn a language, from my point of view, is to READ TUTORIALS, because at any moment you can rewind easily, you can stop at a moment, you can copy paste code (I know that's kinda bad but then you modify the code), you can ask questions if it's a forum (a forum tutorial is more likely to answer your question as soon as he can than a YouTube user). When you watch a video, you see a screen with code, when you read a tutorial you can take your time and do it easy lemon squeezy.
    Also, I started making a bukkit plugin with a tutorial without any knowledge in Java (kinda bad but I know many other languages so it is no difficult for me), and within 3 months you can see that my plugins are not professional, but organized and quite well written. I even learn more and more each day because of this forum (I spend 30mins per day on this forum without an account). Even if I know it's not good to start bukkit without java knowledges, I just wanted to share my little story.

    As a conclusion (it's becoming an essay :p ), from my point of view, reading tutorials and documentation is always better, and have some basic skills in programming (even more in java).

  25. DevilMental An essay? Did you see my post above yours? That post is a true demonstration of excess.
    Garris0n likes this.
  26. Offline


    TheMcScavenger if you want to program with Java, you need to learn Java, end of line there. I understand everyone in this thread has his/her own opinion, but sadly enough that is something inevitable - as we have seen there are a lot of anecdotes that support learning Java before Bukkit.

    If you feel like that is not true, then that is fine. At least provide some kind of reasoning why you believe that Bukkit is suitable for learning Java. (And no, I don't want to hear that anyone on the thread is wrong or ignorant)
    Necrodoom likes this.
Thread Status:
Not open for further replies.

Share This Page