mirror of
https://github.com/jie65535/gc-opencommand-plugin.git
synced 2025-06-02 17:49:12 +08:00
Add auto sending player list
This commit is contained in:
parent
e62b1d4967
commit
a4048d4fd1
@ -4,6 +4,7 @@ import com.github.jie65535.opencommand.OpenCommandConfig;
|
||||
import com.github.jie65535.opencommand.OpenCommandPlugin;
|
||||
import com.github.jie65535.opencommand.socket.packet.*;
|
||||
import com.github.jie65535.opencommand.socket.packet.player.Player;
|
||||
import com.github.jie65535.opencommand.socket.packet.player.PlayerList;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.command.CommandMap;
|
||||
import emu.grasscutter.utils.MessageHandler;
|
||||
@ -13,6 +14,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@ -40,6 +42,7 @@ public class SocketClient {
|
||||
}
|
||||
timer = new Timer();
|
||||
timer.schedule(new SendHeartBeatPacket(), 500);
|
||||
timer.schedule(new SendPlayerListPacket(), 1000);
|
||||
}
|
||||
|
||||
// 发送数据包
|
||||
@ -77,6 +80,23 @@ public class SocketClient {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SendPlayerListPacket extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
if (connect) {
|
||||
PlayerList playerList = new PlayerList();
|
||||
playerList.player = Grasscutter.getGameServer().getPlayers().size();
|
||||
ArrayList<String> playerNames = new ArrayList<>();
|
||||
for (emu.grasscutter.game.player.Player player : Grasscutter.getGameServer().getPlayers().values()) {
|
||||
playerNames.add(player.getNickname());
|
||||
playerList.playerMap.put(player.getUid(), player.getNickname());
|
||||
}
|
||||
playerList.playerList = playerNames;
|
||||
sendPacket(playerList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 数据包接收
|
||||
private static class ReceiveThread extends Thread {
|
||||
private InputStream is;
|
||||
|
Loading…
Reference in New Issue
Block a user