1.17.1 How to remove the first element of the args

Discussion in 'Spigot Plugin Development' started by NorthyMc, Jun 23, 2021.

  1. Ok so I simply want to remove the first element of args.
    I have the command /ban "user" "reason" but I don't want the first element because that is the user
    • Informative Informative x 1
  2. you need to select first argument and find button "delete" on yout button and it will remove the argument
    • Funny Funny x 2
    • Winner Winner x 2
  3. SteelPhoenix


    So just don't use the first argument? What's the issue?
    • Agree Agree x 2
  4. This sounds like you do not know the basics of Java array indexes. You should find a good Java Basics tutorial and then come back later to solve this issue
    • Agree Agree x 3
  5. Code (Java):
    String[] array = new String[] {"Notch", "unfair", "advantages", "detected"};
    StringBuilder builder = new StringBuilder();
    for (int i = 1; i < array.length - 1; i ++) {
        builder.append(array[i]).append(' ');
    if (array.length > 0) {
        builder.append(array[array.length - 1]);
    #5 TheSniper99, Jun 23, 2021
    Last edited: Jun 23, 2021
    • Agree Agree x 1
  6. I think the majority of people would appreciate an explanation besides getting spoonfed
    • Agree Agree x 2
  7. I didn't ask for a tutorial. I simply asked how to remove the first argument, and you clearly don't know how to and I don't want your opinion if you don't have an answer.
    • Funny Funny x 8
  8. dude fr look up a java tutorial before trying to code a damn plugin, also we ain't spoon-feeding you here
    • Agree Agree x 2
  9. Why are you trying to remove the first argument?
  10. Then don’t bother asking questions if you’re not going to accept criticism, or help. He’s giving you advice that’d benefit you. If you don’t want to accept that, then I see no reason for anyone to help you. What you’re asking is literal basic Java knowledge. A quick google search will literally provide you with what you need.
    • Agree Agree x 5
  11. Tau


    there are java tutorials that will take you through the majority of java in an hour or two, sometimes including the memory design.
    spend an hour (or two) of your day and learn java.
  12. When you tell us, what is your goal, we might give you better solution.
  13. I think OP made it pretty clear what they want.. The first arg is the target of their ban command, and everything after that is part of their ban reason. They want to be able to get just the ban reason args.
  14. Oh, sorry I am stupid, I get it now.
    • Agree Agree x 1
  15. I didn't ask to be spoonfeeded, I just asked how to remove the first argument.
    My point is you can ask questions if you need help with something.
    If you don't want to answer my question, that is completely okay, but you don't need to be mad dude...
  16. We are trying to make clear that getting stuck with this and not knowing how to solve it, means that you do not have the right amount of knowledge about Java and programming in general. So we advice you to take a different approach before getting your hands on what you are working on right now.

    Trust me when I say that you should really get familiar with the basics of Java first. If you are running into problems now, you are going to run into a lot more problems later. Not learning Java makes it so you are getting stuck every time, not knowing how to solve issues and coming back to the forums every time. In my opinion, this gets frustrating really easily. So please... follow our advice if you really want to program.
  17. Strahan


    When I need to do this, I like the Apache Common StringUtils class:
    Code (Text):
    String banReason = StringUtils.join(args, " ", 1, args.length)
    First arg is the array to work on, second arg is what to join it with, third arg is what array index to start with and last arg is when to stop. It's shaded into Spigot so you have access to it.
    • Like Like x 1
    • Agree Agree x 1
  18. Yes I really understand and I am sorry for my aggresive behavior, I really wanted to know the answer.
    You know, when you start programming a language, you really want to know answers fast or something like that.
    I actually have learned basic Java, but it is just hard to combind it with Spigot development so early.

    Next time I will check out more before I ask.
    • Optimistic Optimistic x 1
  19. Arrays are fixed in length, you can't remove elements, but you can re-assign their values.
    You'd want to re-assign to the array variable I guess:
    Code (Java):

    args = java.util.Arrays.copyOfRange(args, 1, args.length - 1);
    #20 Jannyboy11, Jun 24, 2021
    Last edited: Jun 24, 2021