Ajout de la requête plater_list dans le networkAPI
This commit is contained in:
@@ -2,6 +2,7 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -18,7 +19,6 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface;
|
||||
|
||||
public class PacketOutServerInfoListener {
|
||||
private PandacraftUtils plugin = PandacraftUtils.getInstance();
|
||||
@@ -39,7 +39,7 @@ public class PacketOutServerInfoListener {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event)
|
||||
{
|
||||
Player[] pl_list = PacketOutServerInfoListener.this.plugin.getServer().getOnlinePlayers();
|
||||
Collection<OnlinePlayer> pl_list = OnlinePlayerManager.getAllNotVanished();
|
||||
|
||||
int count_player = 0;
|
||||
|
||||
@@ -50,28 +50,21 @@ public class PacketOutServerInfoListener {
|
||||
List<Player> plPlayerPremium = new ArrayList<Player>();
|
||||
List<Player> plPlayer = new ArrayList<Player>();
|
||||
|
||||
for (Player p : pl_list)
|
||||
for (OnlinePlayer op : pl_list)
|
||||
{
|
||||
if (p != null && p.isOnline())
|
||||
{
|
||||
// on passe si le joueur est vanish
|
||||
if(EssentialsInterface.isPlayerVanished(p)) continue;
|
||||
|
||||
OnlinePlayer op = OnlinePlayerManager.get(p);
|
||||
|
||||
if (op.isInGroup("admins"))
|
||||
plAdmin.add(p);
|
||||
else if (op.isInStaff())
|
||||
plStaff.add(p);
|
||||
else if (op.isInGroup("ultimate"))
|
||||
plPlayerUltimate.add(p);
|
||||
else if (op.isInGroup("premium"))
|
||||
plPlayerPremium.add(p);
|
||||
else
|
||||
plPlayer.add(p);
|
||||
|
||||
count_player++;
|
||||
}
|
||||
|
||||
if (op.isInGroup("admins"))
|
||||
plAdmin.add(op.getPlayer());
|
||||
else if (op.isInStaff())
|
||||
plStaff.add(op.getPlayer());
|
||||
else if (op.isInGroup("ultimate"))
|
||||
plPlayerUltimate.add(op.getPlayer());
|
||||
else if (op.isInGroup("premium"))
|
||||
plPlayerPremium.add(op.getPlayer());
|
||||
else
|
||||
plPlayer.add(op.getPlayer());
|
||||
|
||||
count_player++;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.network_api;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors.RequestExecutorBroadcast;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors.RequestExecutorCommand;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors.RequestExecutorCommandAsync;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors.RequestExecutorPlayerList;
|
||||
|
||||
public class NetworkAPI {
|
||||
|
||||
@@ -13,21 +14,14 @@ public class NetworkAPI {
|
||||
|
||||
/*
|
||||
* Initialisation des exécuteurs des commandes réseau
|
||||
* LEs constructeurs s'occupent eux même de se référencer dans l'instance de la classe NetworkAPIListener
|
||||
* Les constructeurs s'occupent eux même de se référencer dans l'instance de la classe NetworkAPIListener
|
||||
*/
|
||||
new RequestExecutorCommand();
|
||||
new RequestExecutorBroadcast();
|
||||
new RequestExecutorCommandAsync();
|
||||
new RequestExecutorPlayerList();
|
||||
|
||||
}
|
||||
/*
|
||||
public static void main(String[] args) throws Throwable {
|
||||
loadNewInstance();
|
||||
|
||||
System.out.println(NetworkAPIListener.getInstance().getCommandList());
|
||||
|
||||
NetworkAPIListener.getInstance().join();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
@@ -7,12 +7,21 @@ public class Response {
|
||||
public String data = "";
|
||||
|
||||
|
||||
public Response(boolean good, String data) {
|
||||
this.good = good;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Response() {
|
||||
}
|
||||
|
||||
|
||||
public void sendPacket(PrintStream out) {
|
||||
|
||||
if (data == null) data = "";
|
||||
|
||||
out.print((good?"OK":"ERROR")+"\n");
|
||||
out.print(data.length()+"\n");
|
||||
out.print(data.getBytes().length+"\n");
|
||||
out.print(data);
|
||||
out.flush();
|
||||
}
|
||||
|
@@ -0,0 +1,54 @@
|
||||
package net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.Response;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
|
||||
|
||||
public class RequestExecutorPlayerList extends AbstractRequestExecutor {
|
||||
|
||||
public RequestExecutorPlayerList() {
|
||||
super("player_list");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Response run(String data) {
|
||||
|
||||
boolean ope = data.trim().equalsIgnoreCase("op");
|
||||
|
||||
Collection<OnlinePlayer> players = ope ?
|
||||
OnlinePlayerManager.getAll() :
|
||||
OnlinePlayerManager.getAllNotVanished();
|
||||
|
||||
char nul = '\u0000', nl = '\n';
|
||||
|
||||
StringBuilder returnData = new StringBuilder();
|
||||
|
||||
// d'abord, le nombre de connecté / le nombre de slot
|
||||
returnData.append(players.size()+"/"+plugin.getServer().getMaxPlayers()+nl);
|
||||
|
||||
for (OnlinePlayer op : players) {
|
||||
|
||||
returnData.append(op.getPlayer().getName());
|
||||
|
||||
returnData.append(nul+op.getPlayer().getDisplayName());
|
||||
|
||||
returnData.append(nul+(op.isAfk()?"0":"1"));
|
||||
|
||||
|
||||
returnData.append(nul+op.getPlayer().getGameMode().toString());
|
||||
returnData.append(';'+op.getPlayer().getHealth());
|
||||
returnData.append(';'+op.getPlayer().getFoodLevel());
|
||||
|
||||
|
||||
returnData.append(nul+(op.isVanished()?"0":"1"));
|
||||
|
||||
returnData.append(nl);
|
||||
}
|
||||
|
||||
|
||||
return new Response(true, returnData.toString());
|
||||
}
|
||||
|
||||
}
|
@@ -249,6 +249,17 @@ public class OnlinePlayer {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Indique si le joueur est vanish, en se basant sur le plugin Essentials, qui
|
||||
* gère cette foncionnalitée
|
||||
*/
|
||||
public boolean isVanished() {
|
||||
return EssentialsInterface.isPlayerVanished(player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,7 +1,10 @@
|
||||
package net.mc_pandacraft.java.plugin.pandacraftutils.players;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||
|
||||
@@ -33,7 +36,7 @@ public final class OnlinePlayerManager implements Listener {
|
||||
|
||||
|
||||
|
||||
HashMap<Player, OnlinePlayer> players = new HashMap<Player, OnlinePlayer>();
|
||||
Map<Player, OnlinePlayer> players = Collections.synchronizedMap(new HashMap<Player, OnlinePlayer>());
|
||||
|
||||
private OnlinePlayerManager() {
|
||||
|
||||
@@ -80,12 +83,23 @@ public final class OnlinePlayerManager implements Listener {
|
||||
}
|
||||
|
||||
public static Collection<OnlinePlayer> getAll() {
|
||||
return getInstance().players.values();
|
||||
return new ArrayList<OnlinePlayer>(getInstance().players.values());
|
||||
}
|
||||
|
||||
|
||||
public static boolean contains(Player p) {
|
||||
public static boolean isOnline(Player p) {
|
||||
return getInstance().players.containsKey(p);
|
||||
}
|
||||
|
||||
public static Collection<OnlinePlayer> getAllNotVanished() {
|
||||
Collection<OnlinePlayer> players = getAll();
|
||||
|
||||
for (OnlinePlayer op : players.toArray(new OnlinePlayer[players.size()])) {
|
||||
if (op.isVanished())
|
||||
players.remove(op);
|
||||
}
|
||||
|
||||
return players;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user