mirror of
				https://github.com/PlaceholderAPI/Javascript-Expansion.git
				synced 2025-10-27 12:22:24 +00:00 
			
		
		
		
	Updated ListPlayers
							parent
							
								
									efb98d33a0
								
							
						
					
					
						commit
						04a944bded
					
				| @ -1113,29 +1113,35 @@ numInGroupOfWorlds(); | ||||
| number_in_group_of_worlds: | ||||
|   file: number_in_group_of_worlds.js | ||||
| ``` | ||||
| 
 | ||||
| ### List Players | ||||
| * **Author:** Tanguygab | ||||
| * **Description:** Returns the player list matching the specified syntax | ||||
| **Usage:** | ||||
| * `%javascript_listplayers_all,<type>%` - Matches all players | ||||
| * `%javascript_listplayers_perm,<permission_1>+<permission_2>,<type>%` - Matches all players with the specified permission(s) | ||||
| * `%javascript_listplayers_world,<world_1>+<world_2>,<type>%` - Matches all players in specified world(s) | ||||
| * `%javascript_listplayers_nearby,<radius>,<type>%` - Matches all players in a nearby radius. You can also type `,no` after the type to exclude the player. | ||||
| * **Usage:** `%javascript_listplayers_<type>,<subtype>,<yes/no>,<output>,<subtype_value>%` - The `yes/no` is to include/exclude the player. | ||||
| 
 | ||||
| **Types:** | ||||
| * `all` - Matches all players | ||||
| * `online` - Matches online players | ||||
| * `offline` - Matches offline players | ||||
| 
 | ||||
| **Output Types:** | ||||
| * `list` - Returns a list of players separated by `, ` | ||||
| * `amount` - Returns amount of players matched | ||||
| * `<integer>` - Returns the player at the specified index | ||||
| 
 | ||||
| **Examples:** | ||||
| * `%javascript_listplayers_all,list%` - `Tanguygab, cj89898, funnycube, clip` | ||||
| * `%javascript_listplayers_perm,staff.admin,amount%` - `2` | ||||
| * `%javascript_listplayers_world,buildingworld+spawnworld,2%` - `funnycube` | ||||
| * `%javascript_listplayers_nearby,5,list%` - `Tanguygab, cj89898, clip` | ||||
| * `%javascript_listplayers_nearby,5,list,no%` - `Tanguygab, clip` | ||||
| **SubTypes:** | ||||
| * `normal` - Matches all players - Requires no `<subtype_value>` | ||||
| * `perm` - Matches all players that match the permission defined by `<subtype_value>` - Supports multiple separated by `+` (Ex: `perm1+perm2`) | ||||
| * `world` - Matches all player in the world defined by `<subtype_value>` - Supports multiple separated by `+` (Ex: `world1+world2`) | ||||
| * `nearby` - Matches all players in a certain radius defined by `<subtype_value>` | ||||
| 
 | ||||
| *You can also use `[placeholder]` for papi placeholders in addition to the javascript `{placeholder}`* | ||||
| **Examples:** | ||||
| * `%javascript_listplayers_all,normal,yes,list%` - `Tanguygab, cj89898, funnycube, clip, Frcsty, GabyTM, ItsMeGlare` | ||||
| * `%javascript_listplayers_online,perm,yes,amount,staff.admin%` - `2` | ||||
| * `%javascript_listplayers_online,world,yes,2,buildingworld+spawnworld%` - `cj89898, funnycube` | ||||
| * `%javascript_listplayers_online,nearby,yes,list,5%` - `Tanguygab, cj89898, clip` | ||||
| * `%javascript_listplayers_online,nearby,no,list,5%` - `Tanguygab, clip` | ||||
| 
 | ||||
| *Note: `Offline` and `All` only support the `Normal` subtype. | ||||
| 
 | ||||
| **Javascript Code** | ||||
| 
 | ||||
| @ -1143,244 +1149,147 @@ number_in_group_of_worlds: | ||||
|   <summary>listplayers.js</summary> | ||||
| 
 | ||||
| ```javascript | ||||
| var args0; | ||||
| var args1; | ||||
| var args2; | ||||
| var listOnline = BukkitServer.getOnlinePlayers(); | ||||
| var listOnlineAmount = listOnline.size(); | ||||
| var listOffline = BukkitServer.getOfflinePlayers(); | ||||
| var listType = listOffline; | ||||
| 
 | ||||
| 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]) | ||||
| 		} | ||||
| 	} | ||||
| function normalListPlayers() { | ||||
| 	if (args[0] == "online") {listType = listOnline} | ||||
| 
 | ||||
| 	var players = []; | ||||
| 
 | ||||
| 	for (var i = 0; i < listOnlineAmount; i++) { | ||||
| 	    var player = listOnline[i]; | ||||
| 	        players.push(player.getName()); | ||||
| 	for (var i = 0; i < listType.length; i++) { | ||||
| 	    var player = listType[i]; | ||||
| 
 | ||||
| 	    if (args[2] == "no" && BukkitPlayer.getName() == player.getName()) {} | ||||
| 		else { | ||||
| 	    	if (args[0] == "offline" && listOnline.indexOf(player) >= 0) {} | ||||
| 	    	else {players.push(player.getName())} | ||||
| 		} | ||||
| 	} | ||||
| 	players.sort(); | ||||
| 	//list | ||||
| 	if (args[1] == "list" && players != "") {return players.join(", ")} | ||||
| 	if (args[3] == "list" && players != "") {return players.join(", ")} | ||||
| 	//amount | ||||
| 	else if (args[1] == "amount") {return players.length} | ||||
| 	else if (args[3] == "amount") {return players.length} | ||||
| 	//player | ||||
| 	else if (players.length != 0 && args[1] < players.length) {return players[args[1]]} | ||||
| 	else if (players.length != 0 && args[3] < players.length) {return players[args[3]]} | ||||
| 	//0 players | ||||
| 	else {return "Offline"} | ||||
| } | ||||
| function permListPlayers() { | ||||
| 
 | ||||
| function onlineListPerm() { | ||||
| 	//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 args1 = args[1].split('+'); | ||||
| 	var args4 = args[4].split('+'); | ||||
| 	var players = []; | ||||
| 
 | ||||
| 	for (var i = 0; i < listOnlineAmount; i++) { | ||||
| 	for (var i = 0; i < listOnline.length; i++) { | ||||
| 	    var player = listOnline[i]; | ||||
| 
 | ||||
| 	    for (var i2 = 0; i2 < args1.length; i2++) { | ||||
| 		    if (players.indexOf(player.getName()) == -1 && player.hasPermission(args1[i2])) { | ||||
| 		        players.push(player.getName()); | ||||
| 	    for (var i2 = 0; i2 < args4.length; i2++) { | ||||
| 		    if (players.indexOf(player.getName()) == -1 && player.hasPermission(args4[i2])) { | ||||
| 			    if (args[2] == "no" && BukkitPlayer.getName() == player.getName()) {} | ||||
|  				else {players.push(player.getName())} | ||||
| 		    } | ||||
| 		} | ||||
| 	} | ||||
| 	players.sort(); | ||||
| 	//list | ||||
| 	if (args[2] == "list" && players != "") {return players.join(", ")} | ||||
| 	if (args[3] == "list" && players != "") {return players.join(", ")} | ||||
| 	//amount | ||||
| 	else if (args[2] == "amount") {return players.length} | ||||
| 	else if (args[3] == "amount") {return players.length} | ||||
| 	//player | ||||
| 	else if (players.length != 0 && args[2] < players.length) {return players[args[2]]} | ||||
| 	else if (players.length != 0 && args[3] < players.length) {return players[args[3]]} | ||||
| 	//0 players | ||||
| 	else {return "Offline"} | ||||
| } | ||||
| 
 | ||||
| function onlineListWorld() { | ||||
| 	//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 args1 = args[1].split('+') + ','; | ||||
| function worldListPlayers() { | ||||
| 	var args4 = args[4].split('+') + ','; | ||||
| 	var players = []; | ||||
| 
 | ||||
| 	for (var i = 0; i < listOnlineAmount; i++) { | ||||
| 	for (var i = 0; i < listOnline.length; i++) { | ||||
| 	    var player = listOnline[i]; | ||||
| 
 | ||||
| 	    if (args1.indexOf(player.getWorld().getName()+",") >= 0) { | ||||
| 	        players.push(player.getName()); | ||||
| 	    if (args4.indexOf(player.getWorld().getName()+",") >= 0) { | ||||
| 			if (args[2] == "no" && BukkitPlayer.getName() == player.getName()) {} | ||||
|  			else {players.push(player.getName())} | ||||
| 	    } | ||||
| 	} | ||||
| 	players.sort(); | ||||
| 	//list | ||||
| 	if (args[2] == "list" && players != "") {return players.join(", ")} | ||||
| 	if (args[3] == "list" && players != "") {return players.join(", ")} | ||||
| 	//amount | ||||
| 	else if (args[2] == "amount") {return players.length} | ||||
| 	else if (args[3] == "amount") {return players.length} | ||||
| 	//player | ||||
| 	else if (players.length != 0 && args[2] < players.length) {return players[args[2]]} | ||||
| 	else if (players.length != 0 && args[3] < players.length) {return players[args[3]]} | ||||
| 	//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]) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| function nearbyListPlayers() { | ||||
| 	var players = []; | ||||
| 
 | ||||
| 	for (var i = 0; i < listOnlineAmount; i++) { | ||||
| 	for (var i = 0; i < listOnline.length; i++) { | ||||
| 	    var player = listOnline[i]; | ||||
| 	    var zone = args[1]*args[1]; | ||||
| 	    var zone = args[4]*args[4]; | ||||
| 
 | ||||
| 		if (args.length >= 4 && args[3] == "no") { | ||||
| 	    	if (BukkitPlayer.getWorld() == player.getWorld() && BukkitPlayer.getLocation().distanceSquared(player.getLocation()) < zone && player.getName() != BukkitPlayer.getName()) { | ||||
| 	        	players.push(player.getName()); | ||||
| 	    	} | ||||
| 	    } | ||||
| 	    else { | ||||
| 	    	if (BukkitPlayer.getWorld() == player.getWorld() && BukkitPlayer.getLocation().distanceSquared(player.getLocation()) < zone) { | ||||
| 	        	players.push(player.getName()); | ||||
| 	    	} | ||||
| 				if (args[2] == "no" && BukkitPlayer.getName() == player.getName()) {} | ||||
| 	 			else {players.push(player.getName())} | ||||
| 	    } | ||||
| 	} | ||||
| 	players.sort(); | ||||
| 	//list | ||||
| 	if (args[2] == "list" && players != "") {return players.join(", ")} | ||||
| 	if (args[3] == "list" && players != "") {return players.join(", ")} | ||||
| 	//amount | ||||
| 	else if (args[2] == "amount") {return players.length} | ||||
| 	else if (args[3] == "amount") {return players.length} | ||||
| 	//player | ||||
| 	else if (players.length != 0 && args[2] < players.length) {return players[args[2]]} | ||||
| 	else if (players.length != 0 && args[3] < players.length) {return players[args[3]]} | ||||
| 	//0 players | ||||
| 	else {return "Offline"} | ||||
| } | ||||
| 
 | ||||
| function listPlayers() { | ||||
| 	if (args.length >= 1) { | ||||
| 		var args0 = args[0]; | ||||
| 	} | ||||
| 	if (args.length >= 2) { | ||||
| 		var args1 = args[1]; | ||||
| 	} | ||||
| 	if (args.length >= 3) { | ||||
| 		var args2 = args[2]; | ||||
| 	} | ||||
| function mainListPlayers() { | ||||
| 		//type | ||||
| 	var args0; | ||||
| 	if (args.length >= 1) {args0 = args[0]} | ||||
| 		//subtype | ||||
| 	var args1; | ||||
| 	if (args.length >= 2) {args1 = args[1]} | ||||
| 		//yes/no | ||||
| 	var args2; | ||||
| 	if (args.length >= 3) {args2 = args[2]} | ||||
| 		//output | ||||
| 	var args3; | ||||
| 	if (args.length >= 4) {args3 = args[3]} | ||||
| 		//subtype value | ||||
| 	var args4; | ||||
| 	if (args.length >= 5) {args4 = args[4]} | ||||
| 
 | ||||
| 	//parse PAPI placeholders in arg1 or arg2 | ||||
| 	if (args0 != undefined && args0.indexOf("[") == 0 && args0.indexOf("]") == args0.length-1) { | ||||
| 		args0 = PlaceholderAPI.static.setPlaceholders(BukkitPlayer, args0.replace(/\[|]/g, "%")); | ||||
| 	} | ||||
| 	if (args1 != undefined && args1.indexOf("[") == 0 && args1.indexOf("]") == args1.length-1) { | ||||
| 		args1 = PlaceholderAPI.static.setPlaceholders(BukkitPlayer, args1.replace(/\[|]/g, "%")); | ||||
| 		if (args1 != NaN) { | ||||
| 			Math.round(args1) | ||||
| 		} | ||||
| 	} | ||||
| 	if (args2 != undefined && args2.indexOf("[") == 0 && args2.indexOf("]") == args2.length-1) { | ||||
| 		args2 = PlaceholderAPI.static.setPlaceholders(BukkitPlayer, args2.replace(/\[|]/g, "%")); | ||||
| 		if (args2 != NaN) { | ||||
| 			Math.round(args2) | ||||
| 		} | ||||
| 	} | ||||
| 		//check for types | ||||
| 	if (args0 != "online" && args0 != "offline" && args0 != "all") {return "&3&lValid List Types: &9online&f, &9offline&f, &9all&f."} | ||||
| 		//check for subtypes | ||||
| 	else if (args1 != "normal" && args1 != "perm" && args1 != "world" && args1 != "nearby") {return "&3&lValid List SubTypes: &9normal&f, &9perm&f, &9world&f, &9nearby&f."} | ||||
| 		//help syntax | ||||
| 	else if (args.length == 2) {return "&3&lValid Syntax: &9%"+"javascript_listplayers_&b"+args0+"&9,&b"+args1+"&9,&b<yes/no>&9,&b<output>&9,&b<subtype value>&9%"} | ||||
| 		//check for yes/no | ||||
| 	else if (args2 != "yes" && args2 != "no") {return "&4&lError&c: You have to use either &9yes &cor &9no &cin the third argument."} | ||||
| 		//check for output | ||||
| 	else if (args3 != "list" && args3 != "amount" && isNaN(args3)) {return "&3&lValid Output Types: &9list&f, &9amount&f, &9a number&f."} | ||||
| 		//check for output lower than 0 | ||||
| 	else if (args3 == "-0" || args3 < 0) {return "&4&lError&c: &cYou can't use negative numbers ! What's even the point ? x)"} | ||||
| 		//check for args4 | ||||
| 	else if ((args1 == "world" || args1 == "perm" || args1 == "nearby") && args4 == null) {return "&4&lError&c: &cYou have to specify a &9permission&c/&9world&c/&9radius&c."} | ||||
| 		//check for offline/all + perm/world/nearby | ||||
| 	else if ((args0 == "offline" || args0 == "all") && (args1 == "perm" || args1 == "world" || args1 == "nearby")) {return "Unsupported =/"} | ||||
| 
 | ||||
| 	//help | ||||
| 	if (args0 == undefined) { | ||||
| 		return " &8>> &3&lValid List Types and Syntaxes:\n     &f- &9all&7:     &7%"+"javascript_listplayers_all,&9#&7%\n      &f- &9perm&7:  &7%"+"javascript_listplayers_perm,&9<permission>&7,&9#&7%\n      &f- &9world&7: &7%"+"javascript_listplayers_world,&9<world>&7,&9#&7%\n      &f- &9nearby&7: &7%"+"javascript_listplayers_nearby,&9<radius>&7,&9#&7%\n&7# can be &9list&7, &9amount&7, or &9a number&7."; | ||||
| 	} | ||||
| 
 | ||||
| 		//help all | ||||
| 	else if (args0 == "all" && args1 == undefined) { | ||||
| 		return "&4&lError&c: &cInvalid Syntax!\n&7Valid Syntax:\n &f- &b%" + "javascript_listplayers_all,&9#&b%\n&7# can be &9list&7, &9amount&7, or &9a number&7."; | ||||
| 	} | ||||
| 
 | ||||
| 		//help perm | ||||
| 	else if (args0 == "perm" && (args1 == undefined || args2 == undefined)) { | ||||
| 		return "&4&lError&c: &cInvalid Syntax!\n&7Valid Syntax:\n &f- &b%" + "javascript_listplayers_perm,&9<permission>&b,&9#&b%\n&7# can be &9list&7, &9amount&7, or &9a number&7."; | ||||
| 	} | ||||
| 
 | ||||
| 		//help world | ||||
| 	else if (args0 == "world" && (args1 == undefined || args2 == undefined)) { | ||||
| 		return "&4&lError&c: &cInvalid Syntax!\n&7Valid Syntax:\n &f- &b%" + "javascript_listplayers_world,&9<world>&b,&9#&b%\n&7# can be &9list&7, &9amount&7, or &9a number&7."; | ||||
| 	} | ||||
| 
 | ||||
| 		//help nearby | ||||
| 	else if (args0 == "nearby" && (args1 == undefined || args2 == undefined)) { | ||||
| 		return "&4&lError&c: &cInvalid Syntax!\n&7Valid Syntax:\n &f- &b%" + "javascript_listplayers_nearby,&9<radius>&b,&9#&b%\n&7# can be &9list&7, &9amount&7, or &9a number&7.\n'no' can be added as 4th argument to not count you in the list"; | ||||
| 	} | ||||
| 
 | ||||
| 	//check for errors | ||||
| 		//check for type | ||||
| 	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\n &f- &bnearby" | ||||
| 	} | ||||
| 
 | ||||
| 		//check for args2 lower than 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)" | ||||
| 	} | ||||
| 
 | ||||
| 	//lists | ||||
| 		//list of online players      the list        a player         the amount | ||||
| 	else if (args0 == "all" && (args1 == "list" || !isNaN(args1) || args1 == "amount")) { | ||||
| 		return onlineList(); | ||||
| 	} | ||||
| 
 | ||||
| 		//list of online players with perm  the list    a player         the amount | ||||
| 	else if (args0 == "perm" && (args2 == "list" || !isNaN(args2) || args2 == "amount")) { | ||||
| 			return onlineListPerm(); | ||||
| 	} | ||||
| 
 | ||||
| 		//list of online players in world  the list      a player         the amount | ||||
| 	else if (args0 == "world" && (args2 == "list" || !isNaN(args2) || args2 == "amount")) { | ||||
| 		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 { | ||||
| 		return "Offline" | ||||
| 	} | ||||
| 	if (args1 == "normal") {return normalListPlayers()} | ||||
| 	else if (args1 == "perm") {return permListPlayers()} | ||||
| 	else if (args1 == "world") {return worldListPlayers()} | ||||
| 	else if (args1 == "nearby") {return nearbyListPlayers()} | ||||
| 	else {return "Offline"} | ||||
| } | ||||
| listPlayers(); | ||||
| 
 | ||||
| mainListPlayers() | ||||
| ``` | ||||
| </details> | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 cj89898
						cj89898