1.17.1 Looping through all players

Discussion in 'Spigot Plugin Development' started by CyberAlon, Jul 9, 2021.

  1. I have improved and uploaded the mentioned classes to my maven repository, so that beginners can easily use it.

    Just add this to your pom.xml:

    HTML:
        <repositories>
            <repository>
                <id>jeff-media-repo</id>
                <url>https://repo.jeff-media.de/maven2/</url>
            </repository>
        </repositories>
        <dependencies>
            <dependency>
                <groupId>de.jeff_media</groupId>
                <artifactId>PlayerMessageSendFramework</artifactId>
                <version>1.0-SNAPSHOT</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    You can now easily use it like this:

    Code (Java):
    import de.jeff_media.playermessagesendframework.PlayerMessageSendFramework;
    import de.jeff_media.playermessagesendframework.PlayerPermissionResolver;
    import de.jeff_media.playermessagesendframework.StringMessageComputer;

    public class Test {
     
        private static void test() {
            StringMessageComputer stringMessageComputer = new StringMessageComputer("This is my message");
            PlayerPermissionResolver playerPermissionResolver = new PlayerPermissionResolver("the.permission");
            PlayerMessageSendFramework worker = new PlayerMessageSendFramework(stringMessageComputer, playerPermissionResolver);
            worker.sendMessageToPlayersWithPermission();
        }
    }
     
    EDIT: GitHub: https://github.com/JEFF-Media-GbR/PlayerMessageSendFramework
     
    • Winner Winner x 1
    • Useful Useful x 1
    • Winner Winner x 4
  2. Strahan

    Benefactor

    I can't believe this thread got so far for something so simple, lol
     
    • Agree Agree x 2
    • Funny Funny x 2
  3. Small sentence, but said everything
     
  4. Sorry but this is disgusting: Not only you misused the streams API(by not using a filter), you most likely always replace for loops with streams... which is wrong and looks bad.
     
  5. @OP: First way (regular for loop) is the way to go
     
  6. What you quoted does not use streams, it uses the forEach method with a lambda expression. It is equivilant to a regular for-loop, and is a matter of personal preference. There's nothing wrong with that.

    I don't know why this thread, with such a simple question, is still getting comments; it just confuses the OP.
    So, to summarize, either use a for-loop or the method I linked above (which is cleaner imo).
     
  7. andd wtf is StringMessageComputers, i legitimately made +8 public plugins without even knowing this shit bro LOL, and over all of that i have somewhat an experience in java, i didn't attend a course nor in school, i use google LOL.
     
  8. upload_2021-7-10_13-0-41.png
     
    • Funny Funny x 1
  9. Quality shitposts everybody
     
    • Winner Winner x 1
  10. Using #broadcast(String message, String permission) is much better solutions. ;)
     
    • Agree Agree x 1
    • Winner Winner x 1
  11. You did:
    And the answer is: it‘s a joke.

    To clarify that it‘s stupid to show streams, filters, lambdas etc to people who dont yet know what a for loop is.
     
    • Agree Agree x 2
  12. אתה מפספס את התמונה המלאה.
    Base Background: Iterable::forEach was released in Java 8 - the same release of the Streams API.
    The problem arises when people abuse forEach() as a part of the infamous "Convert all your for loops to streams" idiology - which is exactly what happens in this specific case.

    The exceptionally popular Effective Java book mentions that you should always take a rational decision when choosing between loops and streams, which I agree with.
    This is a highly debated topic but an experienced programmer like you should understand the conceptual problem I'm pointing to.
    Personally I mainly use forEach() where I can use a method reference.

    This thread is very interesting: https://stackoverflow.com/questions/16635398/java-8-iterable-foreach-vs-foreach-loop
     
    • Like Like x 2
  13. Strahan

    Benefactor

    I see that a lot at work, someone learns a new trick then they just have to use it evvvvvvvvvvverywhere, regardless of it it's a good fit for the application heh.

    Off topic, but what's up with the random Hebrew? Are you actually Hebrew literate or was that a Google translate type of thing? If the former, I'm curious; are these meaningful words or just gibberish: https://i.imgur.com/EycQz49.png. An anime I watch based the netherworld alphabet on Hebrew heh.
     
  14. I don't to be a party pooper but you know guys. LISTEN!!!! Use what you think's best and efficient for u and test the performance for yourself xD, op did not ask for a lot of methods any way. Everyone is correct and made a point, maaan it is a simple loop only.


    But this is only my opinion tho, Bukkit already has a collection for every online players which u can use already, I don't think initiating a new object in this matter is really efficient. So for me the best method u should be using is to use simple for loop or java 8 resources.
     
  15. I head if you use records its faster. might wanna update ur code becuause thats deprecated
     
  16. or that! For some reason people do that in their main projects instead of test projects - and then cry after precious debugging time.

    Good Question! robertlit and I both speak hebrew so I wanted to be funny and started with "You're missing the entire picture" in Hebrew, but then since we're not alone here I switched to English ;)
     
    • Like Like x 1