mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +01:00
WIP FakePlayer system
This commit is contained in:
parent
e092eba4c1
commit
30053c507b
@ -1,6 +1,5 @@
|
||||
package fr.themode.demo;
|
||||
|
||||
import fr.themode.demo.entity.ChickenCreature;
|
||||
import fr.themode.demo.generator.ChunkGeneratorDemo;
|
||||
import fr.themode.demo.generator.NoiseTestGenerator;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
@ -8,6 +7,7 @@ import net.minestom.server.benchmark.BenchmarkManager;
|
||||
import net.minestom.server.benchmark.ThreadResult;
|
||||
import net.minestom.server.entity.*;
|
||||
import net.minestom.server.entity.damage.DamageType;
|
||||
import net.minestom.server.entity.fakeplayer.FakePlayer;
|
||||
import net.minestom.server.event.entity.EntityAttackEvent;
|
||||
import net.minestom.server.event.item.ItemDropEvent;
|
||||
import net.minestom.server.event.item.ItemUpdateStateEvent;
|
||||
@ -34,10 +34,13 @@ import net.minestom.server.utils.time.UpdateOption;
|
||||
import net.minestom.server.world.Dimension;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerInit {
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
private static volatile InstanceContainer instanceContainer;
|
||||
private static volatile InstanceContainer netherTest;
|
||||
|
||||
@ -147,8 +150,10 @@ public class PlayerInit {
|
||||
p.teleport(player.getPosition());
|
||||
}*/
|
||||
|
||||
ChickenCreature chickenCreature = new ChickenCreature(player.getPosition());
|
||||
chickenCreature.setInstance(player.getInstance());
|
||||
//ChickenCreature chickenCreature = new ChickenCreature(player.getPosition());
|
||||
//chickenCreature.setInstance(player.getInstance());
|
||||
|
||||
FakePlayer fakePlayer = new FakePlayer(UUID.randomUUID(), "test");
|
||||
|
||||
});
|
||||
|
||||
@ -202,7 +207,7 @@ public class PlayerInit {
|
||||
|
||||
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
player.teleport(new Position(0, 70, 0));
|
||||
player.teleport(new Position(random.nextInt(5), 70, random.nextInt(5)));
|
||||
|
||||
player.setGlowing(true);
|
||||
|
||||
|
@ -20,6 +20,7 @@ import net.minestom.server.network.packet.PacketWriter;
|
||||
import net.minestom.server.network.packet.server.play.*;
|
||||
import net.minestom.server.utils.Vector;
|
||||
import net.minestom.server.utils.*;
|
||||
import net.minestom.server.utils.player.PlayerUtils;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
|
||||
@ -288,7 +289,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
this.lastUpdate = time;
|
||||
|
||||
// Velocity
|
||||
if (!(this instanceof Player)) {
|
||||
if (!PlayerUtils.isNettyClient(this)) {
|
||||
final float tps = MinecraftServer.TICK_PER_SECOND;
|
||||
float newX = position.getX() + velocity.getX() / tps;
|
||||
float newY = position.getY() + velocity.getY() / tps;
|
||||
@ -300,7 +301,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
if (chunkUnloaded)
|
||||
return;
|
||||
|
||||
if (!(this instanceof Player) && !noGravity) { // players handle gravity by themselves
|
||||
if (!PlayerUtils.isNettyClient(this) && !noGravity) { // players handle gravity by themselves
|
||||
velocity.setY(velocity.getY() - gravityDragPerTick * tps);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.bossbar.BossBar;
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.collision.BoundingBox;
|
||||
import net.minestom.server.command.CommandManager;
|
||||
import net.minestom.server.effects.Effects;
|
||||
import net.minestom.server.entity.damage.DamageType;
|
||||
import net.minestom.server.entity.property.Attribute;
|
||||
@ -24,8 +25,11 @@ import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.login.JoinGamePacket;
|
||||
import net.minestom.server.network.packet.server.play.*;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.recipe.Recipe;
|
||||
import net.minestom.server.recipe.RecipeManager;
|
||||
import net.minestom.server.scoreboard.BelowNameScoreboard;
|
||||
import net.minestom.server.scoreboard.Team;
|
||||
import net.minestom.server.sound.Sound;
|
||||
@ -47,7 +51,7 @@ public class Player extends LivingEntity {
|
||||
private long lastKeepAlive;
|
||||
|
||||
private String username;
|
||||
private PlayerConnection playerConnection;
|
||||
protected PlayerConnection playerConnection;
|
||||
private ConcurrentLinkedQueue<ClientPlayPacket> packets = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private int latency;
|
||||
@ -122,6 +126,8 @@ public class Player extends LivingEntity {
|
||||
|
||||
setRespawnPoint(new Position(0, 0, 0));
|
||||
|
||||
init();
|
||||
|
||||
// Some client update
|
||||
getPlayerConnection().sendPacket(getPropertiesPacket()); // Send default properties
|
||||
refreshHealth();
|
||||
@ -131,6 +137,90 @@ public class Player extends LivingEntity {
|
||||
this.inventory = new PlayerInventory(this);
|
||||
|
||||
setCanPickupItem(true); // By default
|
||||
|
||||
MinecraftServer.getEntityManager().addWaitingPlayer(this);
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
GameMode gameMode = GameMode.SURVIVAL;
|
||||
Dimension dimension = Dimension.OVERWORLD;
|
||||
LevelType levelType = LevelType.DEFAULT;
|
||||
final float x = 0;
|
||||
final float y = 0;
|
||||
final float z = 0;
|
||||
|
||||
refreshDimension(dimension);
|
||||
refreshGameMode(gameMode);
|
||||
refreshLevelType(levelType);
|
||||
refreshPosition(x, y, z);
|
||||
|
||||
// TODO complete login sequence with optionals packets
|
||||
JoinGamePacket joinGamePacket = new JoinGamePacket();
|
||||
joinGamePacket.entityId = getEntityId();
|
||||
joinGamePacket.gameMode = gameMode;
|
||||
joinGamePacket.dimension = dimension;
|
||||
joinGamePacket.maxPlayers = 0; // Unused
|
||||
joinGamePacket.levelType = levelType;
|
||||
joinGamePacket.viewDistance = MinecraftServer.CHUNK_VIEW_DISTANCE;
|
||||
joinGamePacket.reducedDebugInfo = false;
|
||||
playerConnection.sendPacket(joinGamePacket);
|
||||
|
||||
// TODO minecraft:brand plugin message
|
||||
|
||||
ServerDifficultyPacket serverDifficultyPacket = new ServerDifficultyPacket();
|
||||
serverDifficultyPacket.difficulty = MinecraftServer.getDifficulty();
|
||||
serverDifficultyPacket.locked = true;
|
||||
playerConnection.sendPacket(serverDifficultyPacket);
|
||||
|
||||
SpawnPositionPacket spawnPositionPacket = new SpawnPositionPacket();
|
||||
spawnPositionPacket.x = 0;
|
||||
spawnPositionPacket.y = 0;
|
||||
spawnPositionPacket.z = 0;
|
||||
playerConnection.sendPacket(spawnPositionPacket);
|
||||
|
||||
String property = "eyJ0aW1lc3RhbXAiOjE1NjU0ODMwODQwOTYsInByb2ZpbGVJZCI6ImFiNzBlY2I0MjM0NjRjMTRhNTJkN2EwOTE1MDdjMjRlIiwicHJvZmlsZU5hbWUiOiJUaGVNb2RlOTExIiwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2RkOTE2NzJiNTE0MmJhN2Y3MjA2ZTRjN2IwOTBkNzhlM2Y1ZDc2NDdiNWFmZDIyNjFhZDk4OGM0MWI2ZjcwYTEifX19";
|
||||
PlayerInfoPacket playerInfoPacket = new PlayerInfoPacket(PlayerInfoPacket.Action.ADD_PLAYER);
|
||||
PlayerInfoPacket.AddPlayer addPlayer = new PlayerInfoPacket.AddPlayer(getUuid(), username, getGameMode(), 10);
|
||||
PlayerInfoPacket.AddPlayer.Property prop = new PlayerInfoPacket.AddPlayer.Property("textures", property); //new PlayerInfoPacket.AddPlayer.Property("textures", properties.get(username));
|
||||
addPlayer.properties.add(prop);
|
||||
playerInfoPacket.playerInfos.add(addPlayer);
|
||||
playerConnection.sendPacket(playerInfoPacket);
|
||||
|
||||
for (Consumer<Player> playerInitialization : MinecraftServer.getConnectionManager().getPlayerInitializations()) {
|
||||
playerInitialization.accept(this);
|
||||
}
|
||||
|
||||
{
|
||||
CommandManager commandManager = MinecraftServer.getCommandManager();
|
||||
DeclareCommandsPacket declareCommandsPacket = commandManager.createDeclareCommandsPacket(this);
|
||||
|
||||
playerConnection.sendPacket(declareCommandsPacket);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
RecipeManager recipeManager = MinecraftServer.getRecipeManager();
|
||||
DeclareRecipesPacket declareRecipesPacket = recipeManager.getDeclareRecipesPacket();
|
||||
if (declareRecipesPacket.recipes != null) {
|
||||
playerConnection.sendPacket(declareRecipesPacket);
|
||||
}
|
||||
|
||||
List<String> recipesIdentifier = new ArrayList<>();
|
||||
for (Recipe recipe : recipeManager.getRecipes()) {
|
||||
if (!recipe.shouldShow(this))
|
||||
continue;
|
||||
|
||||
recipesIdentifier.add(recipe.getRecipeId());
|
||||
}
|
||||
if (!recipesIdentifier.isEmpty()) {
|
||||
String[] identifiers = recipesIdentifier.toArray(new String[recipesIdentifier.size()]);
|
||||
UnlockRecipesPacket unlockRecipesPacket = new UnlockRecipesPacket();
|
||||
unlockRecipesPacket.mode = 0;
|
||||
unlockRecipesPacket.recipesId = identifiers;
|
||||
unlockRecipesPacket.initRecipesId = identifiers;
|
||||
playerConnection.sendPacket(unlockRecipesPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -144,7 +234,6 @@ public class Player extends LivingEntity {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
// Flush all pending packets
|
||||
playerConnection.flush();
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
package net.minestom.server.entity.fakeplayer;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.player.FakePlayerConnection;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class FakePlayer extends Player {
|
||||
|
||||
private FakePlayerController fakePlayerController;
|
||||
|
||||
public FakePlayer(UUID uuid, String username) {
|
||||
super(uuid, username, new FakePlayerConnection());
|
||||
FakePlayerConnection playerConnection = (FakePlayerConnection) getPlayerConnection();
|
||||
playerConnection.setFakePlayer(this);
|
||||
|
||||
this.fakePlayerController = new FakePlayerController(this);
|
||||
}
|
||||
|
||||
public FakePlayerController getController() {
|
||||
return fakePlayerController;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package net.minestom.server.entity.fakeplayer;
|
||||
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
|
||||
public class FakePlayerController {
|
||||
|
||||
private FakePlayer fakePlayer;
|
||||
private PlayerConnection playerConnection;
|
||||
|
||||
public FakePlayerController(FakePlayer fakePlayer) {
|
||||
this.fakePlayer = fakePlayer;
|
||||
this.playerConnection = fakePlayer.getPlayerConnection();
|
||||
|
||||
fakePlayer.setHeldItemSlot((short) 1);
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ import net.minestom.server.storage.StorageFolder;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.ChunkUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.player.PlayerUtils;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.world.Dimension;
|
||||
|
||||
@ -115,6 +116,9 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
protected void sendChunkUpdate(Collection<Player> players, Chunk chunk) {
|
||||
ByteBuf chunkData = chunk.getFullDataPacket();
|
||||
players.forEach(player -> {
|
||||
if (!PlayerUtils.isNettyClient(player))
|
||||
return;
|
||||
|
||||
player.getPlayerConnection().sendPacket(chunkData);
|
||||
});
|
||||
}
|
||||
@ -124,6 +128,9 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
}
|
||||
|
||||
public void sendChunkSectionUpdate(Chunk chunk, int section, Player player) {
|
||||
if (!PlayerUtils.isNettyClient(player))
|
||||
return;
|
||||
|
||||
PacketWriterUtils.writeAndSend(player, getChunkSectionUpdatePacket(chunk, section));
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.ChunkUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.SerializerUtils;
|
||||
import net.minestom.server.utils.player.PlayerUtils;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.utils.time.UpdateOption;
|
||||
import net.minestom.server.world.Dimension;
|
||||
@ -377,6 +378,9 @@ public class InstanceContainer extends Instance {
|
||||
|
||||
@Override
|
||||
public void sendChunk(Player player, Chunk chunk) {
|
||||
if (!PlayerUtils.isNettyClient(player))
|
||||
return;
|
||||
|
||||
ByteBuf data = chunk.getFullDataPacket();
|
||||
if (data == null || !chunk.packetUpdated) {
|
||||
PacketWriterUtils.writeCallbackPacket(chunk.getFreshFullDataPacket(), packet -> {
|
||||
|
@ -11,7 +11,7 @@ import net.minestom.server.network.packet.client.handler.ClientLoginPacketsHandl
|
||||
import net.minestom.server.network.packet.client.handler.ClientPlayPacketsHandler;
|
||||
import net.minestom.server.network.packet.client.handler.ClientStatusPacketsHandler;
|
||||
import net.minestom.server.network.packet.client.handshake.HandshakePacket;
|
||||
import net.minestom.server.network.player.IPlayerConnection;
|
||||
import net.minestom.server.network.player.BasicPlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -42,7 +42,7 @@ public class PacketProcessor {
|
||||
|
||||
public void process(ChannelHandlerContext channel, ByteBuf buffer, int id, int offset) {
|
||||
PlayerConnection playerConnection =
|
||||
connectionPlayerConnectionMap.computeIfAbsent(channel, c -> new IPlayerConnection(channel));
|
||||
connectionPlayerConnectionMap.computeIfAbsent(channel, c -> new BasicPlayerConnection(channel));
|
||||
ConnectionState connectionState = playerConnection.getConnectionState();
|
||||
//if (!printBlackList.contains(id)) {
|
||||
//System.out.println("RECEIVED ID: 0x" + Integer.toHexString(id) + " State: " + connectionState);
|
||||
|
@ -6,6 +6,7 @@ import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import net.minestom.server.utils.player.PlayerUtils;
|
||||
import net.minestom.server.utils.thread.MinestomThread;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -31,15 +32,24 @@ public class PacketWriterUtils {
|
||||
|
||||
ByteBuf buffer = PacketUtils.writePacket(serverPacket);
|
||||
for (Player player : players) {
|
||||
player.getPlayerConnection().writePacket(buffer);
|
||||
PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
if (PlayerUtils.isNettyClient(player)) {
|
||||
playerConnection.writePacket(buffer);
|
||||
} else {
|
||||
playerConnection.sendPacket(serverPacket);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void writeAndSend(PlayerConnection playerConnection, ServerPacket serverPacket) {
|
||||
batchesPool.execute(() -> {
|
||||
ByteBuf buffer = PacketUtils.writePacket(serverPacket);
|
||||
playerConnection.sendPacket(buffer);
|
||||
if (PlayerUtils.isNettyClient(playerConnection)) {
|
||||
ByteBuf buffer = PacketUtils.writePacket(serverPacket);
|
||||
playerConnection.sendPacket(buffer);
|
||||
} else {
|
||||
playerConnection.sendPacket(serverPacket);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,13 @@
|
||||
package net.minestom.server.network.packet.client.login;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.CommandManager;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.packet.PacketReader;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.login.JoinGamePacket;
|
||||
import net.minestom.server.network.packet.server.login.LoginSuccessPacket;
|
||||
import net.minestom.server.network.packet.server.play.*;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.recipe.Recipe;
|
||||
import net.minestom.server.recipe.RecipeManager;
|
||||
import net.minestom.server.world.Dimension;
|
||||
import net.minestom.server.world.LevelType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LoginStartPacket implements ClientPreplayPacket {
|
||||
|
||||
@ -28,14 +15,6 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
String property = "eyJ0aW1lc3RhbXAiOjE1NjU0ODMwODQwOTYsInByb2ZpbGVJZCI6ImFiNzBlY2I0MjM0NjRjMTRhNTJkN2EwOTE1MDdjMjRlIiwicHJvZmlsZU5hbWUiOiJUaGVNb2RlOTExIiwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2RkOTE2NzJiNTE0MmJhN2Y3MjA2ZTRjN2IwOTBkNzhlM2Y1ZDc2NDdiNWFmZDIyNjFhZDk4OGM0MWI2ZjcwYTEifX19";
|
||||
/*HashMap<String, UUID> uuids = new HashMap<>();
|
||||
uuids.put("TheMode911", UUID.fromString("ab70ecb4-2346-4c14-a52d-7a091507c24e"));
|
||||
uuids.put("Adamaq01", UUID.fromString("58ffa9d8-aee1-4587-8b79-41b754f6f238"));
|
||||
HashMap<String, String> properties = new HashMap<>();
|
||||
properties.put("TheMode911", "eyJ0aW1lc3RhbXAiOjE1NjU0ODMwODQwOTYsInByb2ZpbGVJZCI6ImFiNzBlY2I0MjM0NjRjMTRhNTJkN2EwOTE1MDdjMjRlIiwicHJvZmlsZU5hbWUiOiJUaGVNb2RlOTExIiwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2RkOTE2NzJiNTE0MmJhN2Y3MjA2ZTRjN2IwOTBkNzhlM2Y1ZDc2NDdiNWFmZDIyNjFhZDk4OGM0MWI2ZjcwYTEifX19");
|
||||
properties.put("Adamaq01", "eyJ0aW1lc3RhbXAiOjE1NjU0NzgyODU4MTksInByb2ZpbGVJZCI6IjU4ZmZhOWQ4YWVlMTQ1ODc4Yjc5NDFiNzU0ZjZmMjM4IiwicHJvZmlsZU5hbWUiOiJBZGFtYXEwMSIsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9lMTNiNmMyMjNlMTFiYjM1Nzc5OTdkZWY3YzA2ZDUwZmM4NzMxYjBkZWQyOTRlZDQ2ZmM4ZDczNDI1NGM5ZTkifSwiQ0FQRSI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2IwY2MwODg0MDcwMDQ0NzMyMmQ5NTNhMDJiOTY1ZjFkNjVhMTNhNjAzYmY2NGIxN2M4MDNjMjE0NDZmZTE2MzUifX19");*/
|
||||
|
||||
// TODO send encryption request OR directly login success
|
||||
UUID playerUuid = UUID.randomUUID();//UUID.fromString("OfflinePlayer:" + username);
|
||||
|
||||
@ -44,90 +23,6 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
|
||||
connection.setConnectionState(ConnectionState.PLAY);
|
||||
connectionManager.createPlayer(playerUuid, username, connection);
|
||||
Player player = connectionManager.getPlayer(connection);
|
||||
|
||||
MinecraftServer.getEntityManager().addWaitingPlayer(player);
|
||||
|
||||
GameMode gameMode = GameMode.SURVIVAL;
|
||||
Dimension dimension = Dimension.OVERWORLD;
|
||||
LevelType levelType = LevelType.DEFAULT;
|
||||
final float x = 0;
|
||||
final float y = 0;
|
||||
final float z = 0;
|
||||
|
||||
player.refreshDimension(dimension);
|
||||
player.refreshGameMode(gameMode);
|
||||
player.refreshLevelType(levelType);
|
||||
player.refreshPosition(x, y, z);
|
||||
|
||||
// TODO complete login sequence with optionals packets
|
||||
JoinGamePacket joinGamePacket = new JoinGamePacket();
|
||||
joinGamePacket.entityId = player.getEntityId();
|
||||
joinGamePacket.gameMode = gameMode;
|
||||
joinGamePacket.dimension = dimension;
|
||||
joinGamePacket.maxPlayers = 0; // Unused
|
||||
joinGamePacket.levelType = levelType;
|
||||
joinGamePacket.viewDistance = MinecraftServer.CHUNK_VIEW_DISTANCE;
|
||||
joinGamePacket.reducedDebugInfo = false;
|
||||
connection.sendPacket(joinGamePacket);
|
||||
|
||||
// TODO minecraft:brand plugin message
|
||||
|
||||
ServerDifficultyPacket serverDifficultyPacket = new ServerDifficultyPacket();
|
||||
serverDifficultyPacket.difficulty = MinecraftServer.getDifficulty();
|
||||
serverDifficultyPacket.locked = true;
|
||||
connection.sendPacket(serverDifficultyPacket);
|
||||
|
||||
|
||||
SpawnPositionPacket spawnPositionPacket = new SpawnPositionPacket();
|
||||
spawnPositionPacket.x = 0;
|
||||
spawnPositionPacket.y = 0;
|
||||
spawnPositionPacket.z = 0;
|
||||
connection.sendPacket(spawnPositionPacket);
|
||||
|
||||
PlayerInfoPacket playerInfoPacket = new PlayerInfoPacket(PlayerInfoPacket.Action.ADD_PLAYER);
|
||||
PlayerInfoPacket.AddPlayer addPlayer = new PlayerInfoPacket.AddPlayer(player.getUuid(), username, player.getGameMode(), 10);
|
||||
PlayerInfoPacket.AddPlayer.Property prop = new PlayerInfoPacket.AddPlayer.Property("textures", property); //new PlayerInfoPacket.AddPlayer.Property("textures", properties.get(username));
|
||||
addPlayer.properties.add(prop);
|
||||
playerInfoPacket.playerInfos.add(addPlayer);
|
||||
connection.sendPacket(playerInfoPacket);
|
||||
|
||||
for (Consumer<Player> playerInitialization : connectionManager.getPlayerInitializations()) {
|
||||
playerInitialization.accept(player);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
CommandManager commandManager = MinecraftServer.getCommandManager();
|
||||
DeclareCommandsPacket declareCommandsPacket = commandManager.createDeclareCommandsPacket(player);
|
||||
|
||||
connection.sendPacket(declareCommandsPacket);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
RecipeManager recipeManager = MinecraftServer.getRecipeManager();
|
||||
DeclareRecipesPacket declareRecipesPacket = recipeManager.getDeclareRecipesPacket();
|
||||
if (declareRecipesPacket.recipes != null) {
|
||||
connection.sendPacket(declareRecipesPacket);
|
||||
}
|
||||
|
||||
List<String> recipesIdentifier = new ArrayList<>();
|
||||
for (Recipe recipe : recipeManager.getRecipes()) {
|
||||
if (!recipe.shouldShow(player))
|
||||
continue;
|
||||
|
||||
recipesIdentifier.add(recipe.getRecipeId());
|
||||
}
|
||||
if (!recipesIdentifier.isEmpty()) {
|
||||
String[] identifiers = recipesIdentifier.toArray(new String[recipesIdentifier.size()]);
|
||||
UnlockRecipesPacket unlockRecipesPacket = new UnlockRecipesPacket();
|
||||
unlockRecipesPacket.mode = 0;
|
||||
unlockRecipesPacket.recipesId = identifiers;
|
||||
unlockRecipesPacket.initRecipesId = identifiers;
|
||||
connection.sendPacket(unlockRecipesPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,11 +11,11 @@ import java.net.SocketAddress;
|
||||
* Represent a networking connection with Netty
|
||||
* It is the implementation used for all server connection client
|
||||
*/
|
||||
public class IPlayerConnection extends PlayerConnection {
|
||||
public class BasicPlayerConnection extends PlayerConnection {
|
||||
|
||||
private ChannelHandlerContext channel;
|
||||
|
||||
public IPlayerConnection(ChannelHandlerContext channel) {
|
||||
public BasicPlayerConnection(ChannelHandlerContext channel) {
|
||||
super();
|
||||
this.channel = channel;
|
||||
}
|
||||
@ -23,13 +23,13 @@ public class IPlayerConnection extends PlayerConnection {
|
||||
@Override
|
||||
public void sendPacket(ByteBuf buffer) {
|
||||
buffer.retain();
|
||||
channel.writeAndFlush(buffer);
|
||||
getChannel().writeAndFlush(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacket(ByteBuf buffer) {
|
||||
buffer.retain();
|
||||
channel.write(buffer);
|
||||
getChannel().write(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,12 +41,12 @@ public class IPlayerConnection extends PlayerConnection {
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
channel.flush();
|
||||
getChannel().flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteAddress() {
|
||||
return channel.channel().remoteAddress();
|
||||
return getChannel().channel().remoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
@ -0,0 +1,51 @@
|
||||
package net.minestom.server.network.player;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minestom.server.entity.fakeplayer.FakePlayer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class FakePlayerConnection extends PlayerConnection {
|
||||
|
||||
private FakePlayer fakePlayer;
|
||||
|
||||
@Override
|
||||
public void sendPacket(ByteBuf buffer) {
|
||||
throw new UnsupportedOperationException("FakePlayer cannot read Bytebuf");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacket(ByteBuf buffer) {
|
||||
throw new UnsupportedOperationException("FakePlayer cannot read Bytebuf");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(ServerPacket serverPacket) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteAddress() {
|
||||
return new InetSocketAddress(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
|
||||
}
|
||||
|
||||
public FakePlayer getFakePlayer() {
|
||||
return fakePlayer;
|
||||
}
|
||||
|
||||
public void setFakePlayer(FakePlayer fakePlayer) {
|
||||
this.fakePlayer = fakePlayer;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.minestom.server.utils.player;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.fakeplayer.FakePlayer;
|
||||
import net.minestom.server.network.player.FakePlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
public static boolean isNettyClient(Entity entity) {
|
||||
return (entity instanceof Player) && !(entity instanceof FakePlayer);
|
||||
}
|
||||
|
||||
public static boolean isNettyClient(Player player) {
|
||||
return !(player instanceof FakePlayer);
|
||||
}
|
||||
|
||||
public static boolean isNettyClient(PlayerConnection playerConnection) {
|
||||
return !(playerConnection instanceof FakePlayerConnection);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user