PlaceholderAPI / Javascript-Expansion

Adds javascript placeholders
GNU General Public License v3.0
22 stars 24 forks source link

New Community Script: OnlinePlayerList #37

Closed joex92 closed 3 years ago

joex92 commented 3 years ago

Javascript Code

onlinePlayerList.js

function onlinePlayerList() {
    var delimiter = ", ";
    if (args.length == 1 && args[0] != null) {
        delimiter = String(args[0]);
    }
    var onPlayersStr = "";
    var onPlayers = BukkitServer.getOnlinePlayers().toArray();
    for (i = 0;i < onPlayers.length; i++){
        var player = onPlayers[i];
        if (i == 0){
            onPlayersStr = player.getName();
        } else {
            onPlayersStr = onPlayersStr + delimiter + player.getName();
        }
    }
    return onPlayersStr;
}
onlinePlayerList();

Add to javascript_placeholders.yml

onlinePlayerList:
  file: onlinePlayerList.js
BlitzOffline commented 3 years ago

Hello. So this is a cool placeholder but could you please explain why this placeholder should be used over the PlayerList expansion? We try to only add placeholders that don't exist in other expansions and in my opinion the PlayerList does this job and a lot more.

P.S.: I am aware that some existing ones exist already but those were made and posted before the expansions were.

joex92 commented 3 years ago

oh, the only one I knew was ListPlayer and when I tried to install it, it wasn't being "supported":

[Sun, 6. Jun 2021 17:50:06 UTC WARN] listplayers is attempting to register placeholders via a PlaceholderHook class which is no longer supported!

So I thought that was the only one with what I wanted... I'm going to try PlayerList then, for some reason I didn't see it...

also, I want to use this placeholder as an Alert in DiscordSRV, but for some reason my script works in console, works in Minecraft chat, but it doesn't work sending it through an Alert... it's weird... hopefully PlayerList will work...

joex92 commented 3 years ago

Now I remember why I didn't use PlayerList image

BlitzOffline commented 3 years ago

Well that's strange bcz for me it works: image

U could try to just manually download it.

Download it from here: https://api.extendedclip.com/expansions/playerlist/ and put it in plugins/PlaceholderAPI/expansions and then do /papi reload

joex92 commented 3 years ago

thanks! it worked! the host I'm using is constantly sending /list to the console, so I wanted to take advantage of that to get the list of players and send it to the console chat in Discord, here's the alert if anyone looks for it:

  - Trigger: ServerCommandEvent
    Channel: console
    Conditions:
      - '#event.getCommand().equals("list")'
    Embed:
      Color: "#00ff00"
      Author:
        Name: 'Online players: ${#server.onlinePlayers.size()}'
      Description: "%playerlist_online,normal,yes,list%"

this is the output: image

joex92 commented 3 years ago

but I tested out, and the list of players is sent as 1 string separated by ","... and I wanted to separate them by "\n" so it shows one above the other in discord...

BlitzOffline commented 3 years ago

Well you can always use the javascript for that but yeah the reason we won't put this on the wiki is bcz there's already a better alternative I guess

joex92 commented 3 years ago

🤔 hmm... you are right! I'm going to use javascript to replace "," with "\n"... anyways, thanks!