Update listplayers.js

added nearby and support for multiple permissions/worlds
This commit is contained in:
cj89898 2020-07-01 14:04:45 -05:00 committed by GitHub
parent 99bdcaa6d5
commit 22ec72b114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,36 @@
var args0; var args0;
var args1; var args1;
var args2; var args2;
var listAll = BukkitServer.getOfflinePlayers();
var listOnline = BukkitServer.getOnlinePlayers(); var listOnline = BukkitServer.getOnlinePlayers();
var listOnlineAmount = listOnline.size(); var listOnlineAmount = listOnline.size();
function onlineList() {
//parse PAPI placeholders in arg1 or arg2
if (args[1].indexOf("[") == 0 && args[1].indexOf("]") == args[1].length-1) {
args[1] = PlaceholderAPI.static.setPlaceholders(BukkitPlayer, args[1].replace(/\[|]/g, "%"));
if (!isNaN(args[1])) {
args[1] = Math.round(args[1])
}
}
var players = [];
for (var i = 0; i < listOnlineAmount; i++) {
var player = listOnline[i];
players.push(player.getName());
}
players.sort();
//list
if (args[1] == "list" && players != "") {return players.join(", ")}
//amount
else if (args[1] == "amount") {return players.length}
//player
else if (players.length != 0 && args[1] < players.length) {return players[args[1]]}
//0 players
else {return "Offline"}
}
function onlineListPerm() { function onlineListPerm() {
//parse PAPI placeholders in arg1 or arg2 //parse PAPI placeholders in arg1 or arg2
if (args[1].indexOf("[") == 0 && args[1].indexOf("]") == args[1].length-1) { if (args[1].indexOf("[") == 0 && args[1].indexOf("]") == args[1].length-1) {
@ -19,24 +46,29 @@ function onlineListPerm() {
} }
} }
var args1 = args[1].split('+');
var players = []; var players = [];
for (var i = 0; i < listOnlineAmount; i++) { for (var i = 0; i < listOnlineAmount; i++) {
var player = listOnline[i]; var player = listOnline[i];
if (player.hasPermission(args[1])) { for (var i2 = 0; i2 < args1.length; i2++) {
players.push(player); if (players.indexOf(player.getName()) == -1 && player.hasPermission(args1[i2])) {
players.push(player.getName());
} }
} }
}
players.sort();
//list //list
if (args[2] == "list" && players != "") {return players.join(", ").replace(/\[|\]|}|CraftPlayer{name=/gi, "")} if (args[2] == "list" && players != "") {return players.join(", ")}
//amount //amount
else if (args[2] == "amount") {return players.length} else if (args[2] == "amount") {return players.length}
//player //player
else if (players.length != 0 && args[2] < players.length) {return players[args[2]].getName()} else if (players.length != 0 && args[2] < players.length) {return players[args[2]]}
//0 players //0 players
else {return "Offline"} else {return "Offline"}
} }
function onlineListWorld() { function onlineListWorld() {
//parse PAPI placeholders in arg1 or arg2 //parse PAPI placeholders in arg1 or arg2
if (args[1].indexOf("[") == 0 && args[1].indexOf("]") == args[1].length-1) { if (args[1].indexOf("[") == 0 && args[1].indexOf("]") == args[1].length-1) {
@ -51,27 +83,64 @@ function onlineListWorld() {
args[2] = Math.round(args[2]) args[2] = Math.round(args[2])
} }
} }
var args1 = args[1].split('+') + ',';
var players = [];
for (var i = 0; i < listOnlineAmount; i++) {
var player = listOnline[i];
if (args1.indexOf(player.getWorld().getName()+",") >= 0) {
players.push(player.getName());
}
}
players.sort();
//list
if (args[2] == "list" && players != "") {return players.join(", ")}
//amount
else if (args[2] == "amount") {return players.length}
//player
else if (players.length != 0 && args[2] < players.length) {return players[args[2]]}
//0 players
else {return "Offline"}
}
function onlineListNearby() {
//parse PAPI placeholders in arg1 or arg2
if (args[1].indexOf("[") == 0 && args[1].indexOf("]") == args[1].length-1) {
args[1] = PlaceholderAPI.static.setPlaceholders(BukkitPlayer, args[1].replace(/\[|]/g, "%"));
if (!isNaN(args[1])) {
args[1] = Math.round(args[1])
}
}
if (args[2].indexOf("[") == 0 && args[2].indexOf("]") == args[2].length-1) {
args[2] = PlaceholderAPI.static.setPlaceholders(BukkitPlayer, args[2].replace(/\[|]/g, "%"));
if (!isNaN(args[2])) {
args[2] = Math.round(args[2])
}
}
var players = []; var players = [];
for (var i = 0; i < listOnlineAmount; i++) { for (var i = 0; i < listOnlineAmount; i++) {
var player = listOnline[i]; var player = listOnline[i];
var zone = args[1]*args[1];
if (player.getWorld().getName() == args[1]) { if (BukkitPlayer.getWorld() == player.getWorld() && BukkitPlayer.getLocation().distanceSquared(player.getLocation()) < zone) {
players.push(player); players.push(player.getName());
} }
} }
players.sort();
//list //list
if (args[2] == "list" && players != "") {return players.join(", ").replace(/\[|\]|}|CraftPlayer{name=/gi, "")} if (args[2] == "list" && players != "") {return players.join(", ")}
//amount //amount
else if (args[2] == "amount") {return players.length} else if (args[2] == "amount") {return players.length}
//player //player
else if (players.length != 0 && args[2] < players.length) {return players[args[2]].getName()} else if (players.length != 0 && args[2] < players.length) {return players[args[2]]}
//0 players //0 players
else {return "Offline"} else {return "Offline"}
} }
function onlineList() { function listPlayers() {
if (args.length >= 1) { if (args.length >= 1) {
var args0 = args[0]; var args0 = args[0];
} }
@ -121,52 +190,38 @@ function onlineList() {
//check for errors //check for errors
//check for type //check for type
else if (args0 != "all" && args0 != "perm" && args0 != "world" && args0 != "{1}") { else if (args0 != "all" && args0 != "perm" && args0 != "world" && args0 != "nearby" && args0 != "{1}") {
return "&4&lError&c: &cInvalid list type\n&7Valid list types are:\n &f- &ball\n &f- &bperm\n &f- &bworld" return "&4&lError&c: &cInvalid list type\n&7Valid list types are:\n &f- &ball\n &f- &bperm\n &f- &bworld"
} }
//check for world
else if (args0 == "world" && BukkitServer.getWorld(args1) == null) {
return "&4&lError&c: &cThat world doesn't exist"
}
//check for args2 lower than 0 //check for args2 lower than 0
else if (args2 < 0 || args0 == "all" && args1 < 0) { else if ((args2 == "-0" || args2 < 0) || args0 == "all" && ( args1 == "-0" || args1 < 0)) {
return "&4&lError&c: &cYou can't use negative numbers ! What's even the point ? x)" return "&4&lError&c: &cYou can't use negative numbers ! What's even the point ? x)"
} }
//list of all players //lists
else if (args0 == "all" && args1 == "list") { //list of online players the list a player the amount
return listOnline.toString().replace(/\[|\]|}|CraftPlayer{name=/gi, ""); else if (args0 == "all" && (args1 == "list" || !isNaN(args1) || args1 == "amount")) {
return onlineList();
} }
//get player from list //list of online players with perm the list a player the amount
else if (args0 == "all" && args1 < listOnlineAmount) {
return listOnline.get(args1).getName();
}
//get amount of players online
else if (args0 == "all" && args1 == "amount") {
if (listOnline == "") {
return 0
}
else {
return listOnlineAmount
}
}
//list of all players with perm the list a player the amount
else if (args0 == "perm" && (args2 == "list" || !isNaN(args2) || args2 == "amount")) { else if (args0 == "perm" && (args2 == "list" || !isNaN(args2) || args2 == "amount")) {
return onlineListPerm(); return onlineListPerm();
} }
//list of all players in world the list a player the amount //list of online players in world the list a player the amount
else if (args0 == "world" && (args2 == "list" || !isNaN(args2) || args2 == "amount")) { else if (args0 == "world" && (args2 == "list" || !isNaN(args2) || args2 == "amount")) {
return onlineListWorld(); return onlineListWorld();
} }
//list of online players nearby the list a player the amount
else if (args0 == "nearby" && (args2 == "list" || !isNaN(args2) || args2 == "amount")) {
return onlineListNearby();
}
else { else {
return "Offline" return "Offline" + BukkitServer.getOfflinePlayers();
} }
} }
onlineList(); listPlayers();