correct update player list
This commit is contained in:
@@ -6,6 +6,7 @@ package mc.core;
|
|||||||
|
|
||||||
import mc.core.network.NetChannel;
|
import mc.core.network.NetChannel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface PlayerManager {
|
public interface PlayerManager {
|
||||||
@@ -13,5 +14,6 @@ public interface PlayerManager {
|
|||||||
void joinServer(Player player);
|
void joinServer(Player player);
|
||||||
void leftServer(Player player);
|
void leftServer(Player player);
|
||||||
Optional<Player> getPlayer(String name);
|
Optional<Player> getPlayer(String name);
|
||||||
|
List<Player> getPlayers();
|
||||||
NetChannel getBroadcastChannel();
|
NetChannel getBroadcastChannel();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import mc.core.network.NetChannel;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class InMemoryPlayerManager implements PlayerManager, Runnable {
|
public class InMemoryPlayerManager implements PlayerManager, Runnable {
|
||||||
@@ -60,6 +61,11 @@ public class InMemoryPlayerManager implements PlayerManager, Runnable {
|
|||||||
.findFirst();
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Player> getPlayers() {
|
||||||
|
return players.stream().filter(Player::isOnline).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetChannel getBroadcastChannel() {
|
public NetChannel getBroadcastChannel() {
|
||||||
return new BroadcastNetChannel(players.stream().filter(Player::isOnline));
|
return new BroadcastNetChannel(players.stream().filter(Player::isOnline));
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import io.netty.util.AttributeKey;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.core.*;
|
import mc.core.*;
|
||||||
import mc.core.network.CSPacket;
|
import mc.core.network.CSPacket;
|
||||||
|
import mc.core.network.NetChannel;
|
||||||
import mc.core.network.proto_125.netty.wrappers.WrapperNetChannel;
|
import mc.core.network.proto_125.netty.wrappers.WrapperNetChannel;
|
||||||
import mc.core.network.proto_125.packets.*;
|
import mc.core.network.proto_125.packets.*;
|
||||||
import org.slf4j.Marker;
|
import org.slf4j.Marker;
|
||||||
@@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -109,13 +111,6 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
|||||||
abilitiesPkt.setInstantDestroyBlocks(true);
|
abilitiesPkt.setInstantDestroyBlocks(true);
|
||||||
channel.write(abilitiesPkt);
|
channel.write(abilitiesPkt);
|
||||||
|
|
||||||
// send Player info
|
|
||||||
PlayerInfoPacket infoPkt = new PlayerInfoPacket();
|
|
||||||
infoPkt.setPlayerName(player.getName());
|
|
||||||
infoPkt.setOnline(true);
|
|
||||||
infoPkt.setPing(4);
|
|
||||||
channel.write(infoPkt);
|
|
||||||
|
|
||||||
// send Chunk allocation
|
// send Chunk allocation
|
||||||
ChunkAllocationPacket chInitPkt = new ChunkAllocationPacket();
|
ChunkAllocationPacket chInitPkt = new ChunkAllocationPacket();
|
||||||
chInitPkt.setX(0);
|
chInitPkt.setX(0);
|
||||||
@@ -152,6 +147,16 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
|||||||
channel.attr(ATTR_PLAYER).set(player);
|
channel.attr(ATTR_PLAYER).set(player);
|
||||||
player.setChannel(new WrapperNetChannel(channel));
|
player.setChannel(new WrapperNetChannel(channel));
|
||||||
playerManager.joinServer(player);
|
playerManager.joinServer(player);
|
||||||
|
|
||||||
|
// send Player info
|
||||||
|
List<Player> players = playerManager.getPlayers();
|
||||||
|
players.forEach(pl -> {
|
||||||
|
PlayerInfoPacket infoPkt = new PlayerInfoPacket();
|
||||||
|
infoPkt.setPlayerName(pl.getName());
|
||||||
|
infoPkt.setOnline(true);
|
||||||
|
infoPkt.setPing(4);
|
||||||
|
playerManager.getBroadcastChannel().writeAndFlush(infoPkt);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onKickPacket(Channel channel, KickPacket packet) {
|
public void onKickPacket(Channel channel, KickPacket packet) {
|
||||||
|
|||||||
Reference in New Issue
Block a user