mirror of https://github.com/Minestom/Minestom.git
Update
This commit is contained in:
parent
db9549560c
commit
cb194db4c0
|
@ -15,12 +15,14 @@ import fr.themode.minestom.net.PacketProcessor;
|
|||
import fr.themode.minestom.net.packet.PacketReader;
|
||||
import fr.themode.minestom.net.packet.client.status.LegacyServerListPingPacket;
|
||||
import fr.themode.minestom.net.packet.server.play.KeepAlivePacket;
|
||||
import fr.themode.minestom.net.packet.server.play.ServerDifficultyPacket;
|
||||
import fr.themode.minestom.net.player.PlayerConnection;
|
||||
import fr.themode.minestom.recipe.RecipeManager;
|
||||
import fr.themode.minestom.registry.RegistryMain;
|
||||
import fr.themode.minestom.scoreboard.TeamManager;
|
||||
import fr.themode.minestom.timer.SchedulerManager;
|
||||
import fr.themode.minestom.utils.Utils;
|
||||
import fr.themode.minestom.world.Difficulty;
|
||||
|
||||
public class MinecraftServer {
|
||||
|
||||
|
@ -60,12 +62,12 @@ public class MinecraftServer {
|
|||
public static final int TICK_PER_SECOND = MS_TO_SEC / TICK_MS;
|
||||
|
||||
// Networking
|
||||
private static ConnectionManager connectionManager;
|
||||
private static PacketProcessor packetProcessor;
|
||||
private static PacketListenerManager packetListenerManager;
|
||||
private static Server server;
|
||||
|
||||
// In-Game Manager
|
||||
private static ConnectionManager connectionManager;
|
||||
private static InstanceManager instanceManager;
|
||||
private static BlockManager blockManager;
|
||||
private static EntityManager entityManager;
|
||||
|
@ -78,6 +80,9 @@ public class MinecraftServer {
|
|||
|
||||
private static MinecraftServer minecraftServer;
|
||||
|
||||
// Data
|
||||
private static Difficulty difficulty = Difficulty.NORMAL;
|
||||
|
||||
public static MinecraftServer init() {
|
||||
connectionManager = new ConnectionManager();
|
||||
packetProcessor = new PacketProcessor();
|
||||
|
@ -107,6 +112,20 @@ public class MinecraftServer {
|
|||
return minecraftServer;
|
||||
}
|
||||
|
||||
public static Difficulty getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public static void setDifficulty(Difficulty difficulty) {
|
||||
MinecraftServer.difficulty = difficulty;
|
||||
for (Player player : connectionManager.getOnlinePlayers()) {
|
||||
ServerDifficultyPacket serverDifficultyPacket = new ServerDifficultyPacket();
|
||||
serverDifficultyPacket.difficulty = difficulty;
|
||||
serverDifficultyPacket.locked = true;
|
||||
player.getPlayerConnection().sendPacket(serverDifficultyPacket);
|
||||
}
|
||||
}
|
||||
|
||||
public static PacketListenerManager getPacketListenerManager() {
|
||||
return packetListenerManager;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package fr.themode.minestom.event;
|
||||
|
||||
public class PlayerPluginMessageEvent extends Event {
|
||||
|
||||
private String identifier;
|
||||
private byte[] message;
|
||||
|
||||
public PlayerPluginMessageEvent(String identifier, byte[] message) {
|
||||
this.identifier = identifier;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public byte[] getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getMessageString() {
|
||||
return new String(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package fr.themode.minestom.listener;
|
||||
|
||||
import fr.themode.minestom.entity.Player;
|
||||
import fr.themode.minestom.event.PlayerPluginMessageEvent;
|
||||
import fr.themode.minestom.net.packet.client.play.ClientPluginMessagePacket;
|
||||
|
||||
public class PluginMessageListener {
|
||||
|
||||
public static void listener(ClientPluginMessagePacket packet, Player player) {
|
||||
PlayerPluginMessageEvent pluginMessageEvent = new PlayerPluginMessageEvent(packet.identifier, packet.data);
|
||||
player.callEvent(PlayerPluginMessageEvent.class, pluginMessageEvent);
|
||||
}
|
||||
|
||||
}
|
|
@ -35,6 +35,7 @@ public class PacketListenerManager {
|
|||
addListener(ClientCreativeInventoryActionPacket.class, CreativeInventoryActionListener::listener);
|
||||
addListener(ClientCraftRecipeRequest.class, RecipeListener::listener);
|
||||
addListener(ClientTabCompletePacket.class, TabCompleteListener::listener);
|
||||
addListener(ClientPluginMessagePacket.class, PluginMessageListener::listener);
|
||||
}
|
||||
|
||||
public <T extends ClientPlayPacket> void process(T packet, Player player) {
|
||||
|
|
|
@ -71,7 +71,10 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
|||
|
||||
// TODO minecraft:brand plugin message
|
||||
|
||||
// TODO send server difficulty
|
||||
ServerDifficultyPacket serverDifficultyPacket = new ServerDifficultyPacket();
|
||||
serverDifficultyPacket.difficulty = MinecraftServer.getDifficulty();
|
||||
serverDifficultyPacket.locked = true;
|
||||
connection.sendPacket(serverDifficultyPacket);
|
||||
|
||||
|
||||
SpawnPositionPacket spawnPositionPacket = new SpawnPositionPacket();
|
||||
|
|
|
@ -5,8 +5,8 @@ import fr.themode.minestom.net.packet.client.ClientPlayPacket;
|
|||
|
||||
public class ClientPluginMessagePacket extends ClientPlayPacket {
|
||||
|
||||
private String identifier;
|
||||
private byte[] data;
|
||||
public String identifier;
|
||||
public byte[] data;
|
||||
|
||||
@Override
|
||||
public void read(PacketReader reader, Runnable callback) {
|
||||
|
|
|
@ -12,7 +12,7 @@ public class ServerPacketIdentifier {
|
|||
public static final int STATISTICS = 0x07;
|
||||
public static final int ACKNOWLEDGE_PLAYER_DIGGING = 0x08;
|
||||
public static final int BLOCK_BREAK_ANIMATION = 0x09;
|
||||
public static final int UPDATE_BLOCK_ENTITY = 0x0A;
|
||||
public static final int BLOCK_ENTITY_DATA = 0x0A;
|
||||
public static final int BLOCK_ACTION = 0x0B;
|
||||
public static final int BLOCK_CHANGE = 0x0C;
|
||||
public static final int BOSS_BAR = 0x0D;
|
||||
|
@ -53,7 +53,7 @@ public class ServerPacketIdentifier {
|
|||
public static final int OPEN_SIGN_EDITOR = 0x30;
|
||||
public static final int CRAFT_RECIPE_RESPONSE = 0x31;
|
||||
public static final int PLAYER_ABILITIES = 0x32;
|
||||
public static final int COMBAT_EVENT = 0x33;
|
||||
public static final int COMBAT_EVENT = 0x33; // Do not seem to be used by the client
|
||||
public static final int PLAYER_INFO = 0x34;
|
||||
public static final int FACE_PLAYER = 0x35;
|
||||
public static final int PLAYER_POSITION_AND_LOOK = 0x36;
|
||||
|
@ -68,7 +68,7 @@ public class ServerPacketIdentifier {
|
|||
public static final int CAMERA = 0x3F;
|
||||
public static final int HELD_ITEM_CHANGE = 0x40;
|
||||
public static final int UPDATE_VIEW_POSITION = 0x41;
|
||||
public static final int UPDATE_VIEW_DISTANCE = 0x42;
|
||||
public static final int UPDATE_VIEW_DISTANCE = 0x42; // Not used by the dedicated server
|
||||
public static final int DISPLAY_SCOREBOARD = 0x43;
|
||||
public static final int ENTITY_METADATA = 0x44;
|
||||
public static final int ATTACH_ENTITY = 0x45;
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package fr.themode.minestom.net.packet.server.play;
|
||||
|
||||
import fr.themode.minestom.net.packet.PacketWriter;
|
||||
import fr.themode.minestom.net.packet.server.ServerPacket;
|
||||
import fr.themode.minestom.net.packet.server.ServerPacketIdentifier;
|
||||
|
||||
public class AttachEntityPacket implements ServerPacket {
|
||||
|
||||
public int attachedEntityId;
|
||||
public int holdingEntityId; // Or -1 to detach
|
||||
|
||||
@Override
|
||||
public void write(PacketWriter writer) {
|
||||
writer.writeInt(attachedEntityId);
|
||||
writer.writeInt(holdingEntityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ServerPacketIdentifier.ATTACH_ENTITY;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package fr.themode.minestom.net.packet.server.play;
|
||||
|
||||
import fr.themode.minestom.net.packet.PacketWriter;
|
||||
import fr.themode.minestom.net.packet.server.ServerPacket;
|
||||
import fr.themode.minestom.net.packet.server.ServerPacketIdentifier;
|
||||
|
||||
public class ResourcePackSendPacket implements ServerPacket {
|
||||
|
||||
public String url;
|
||||
public String hash; // Size 40
|
||||
|
||||
@Override
|
||||
public void write(PacketWriter writer) {
|
||||
writer.writeSizedString(url);
|
||||
writer.writeSizedString(hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ServerPacketIdentifier.RESOURCE_PACK_SEND;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package fr.themode.minestom.net.packet.server.play;
|
||||
|
||||
import fr.themode.minestom.net.packet.PacketWriter;
|
||||
import fr.themode.minestom.net.packet.server.ServerPacket;
|
||||
import fr.themode.minestom.net.packet.server.ServerPacketIdentifier;
|
||||
import fr.themode.minestom.world.Difficulty;
|
||||
|
||||
public class ServerDifficultyPacket implements ServerPacket {
|
||||
|
||||
public Difficulty difficulty;
|
||||
public boolean locked;
|
||||
|
||||
@Override
|
||||
public void write(PacketWriter writer) {
|
||||
writer.writeByte((byte) difficulty.ordinal());
|
||||
writer.writeBoolean(locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ServerPacketIdentifier.SERVER_DIFFICULTY;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package fr.themode.minestom.net.packet.server.play;
|
||||
|
||||
import fr.themode.minestom.net.packet.PacketWriter;
|
||||
import fr.themode.minestom.net.packet.server.ServerPacket;
|
||||
import fr.themode.minestom.net.packet.server.ServerPacketIdentifier;
|
||||
|
||||
public class TimeUpdatePacket implements ServerPacket {
|
||||
|
||||
public long worldAge;
|
||||
public long timeOfDay;
|
||||
|
||||
@Override
|
||||
public void write(PacketWriter writer) {
|
||||
writer.writeLong(worldAge);
|
||||
writer.writeLong(timeOfDay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ServerPacketIdentifier.TIME_UPDATE;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue