mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2025-07-13 21:20:12 +02:00
Added gamemode switching in config. Sending player abilities packet to disable flying in spectator mode
This commit is contained in:
parent
74b23582f2
commit
4fa4f50d8a
@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'ru.nanit'
|
||||
version '1.0'
|
||||
version '1.1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -19,6 +19,7 @@ public final class LimboConfig {
|
||||
|
||||
private String dimensionType;
|
||||
private Position spawnPosition;
|
||||
private int gameMode;
|
||||
|
||||
private boolean useJoinMessage;
|
||||
private boolean useBossBar;
|
||||
@ -45,6 +46,7 @@ public final class LimboConfig {
|
||||
pingData = conf.getNode("ping").getValue(PingData.class);
|
||||
dimensionType = conf.getNode("dimension").getString();
|
||||
spawnPosition = conf.getNode("spawnPosition").getValue(Position.class);
|
||||
gameMode = conf.getNode("gameMode").getInt();
|
||||
useJoinMessage = conf.getNode("joinMessage", "enable").getBoolean();
|
||||
useBossBar = conf.getNode("bossBar", "enable").getBoolean();
|
||||
|
||||
@ -79,6 +81,10 @@ public final class LimboConfig {
|
||||
return spawnPosition;
|
||||
}
|
||||
|
||||
public int getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public InfoForwarding getInfoForwarding() {
|
||||
return infoForwarding;
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
||||
joinGame.setEntityId(0);
|
||||
joinGame.setEnableRespawnScreen(true);
|
||||
joinGame.setFlat(false);
|
||||
joinGame.setGameMode(2);
|
||||
joinGame.setGameMode(server.getConfig().getGameMode());
|
||||
joinGame.setHardcore(false);
|
||||
joinGame.setMaxPlayers(server.getConfig().getMaxPlayers());
|
||||
joinGame.setPreviousGameMode(-1);
|
||||
@ -199,6 +199,12 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
||||
joinGame.setDimensionCodec(server.getDimensionRegistry().getCodec());
|
||||
joinGame.setDimension(server.getDimensionRegistry().getDefaultDimension());
|
||||
|
||||
PacketPlayerAbilities abilities = new PacketPlayerAbilities();
|
||||
|
||||
abilities.setFlyingSpeed(0.0F);
|
||||
abilities.setFlags(0x02);
|
||||
abilities.setFieldOfView(0.1F);
|
||||
|
||||
PacketPlayerPositionAndLook positionAndLook = new PacketPlayerPositionAndLook();
|
||||
|
||||
positionAndLook.setX(server.getConfig().getSpawnPosition().getX());
|
||||
@ -211,9 +217,10 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
||||
PacketPlayerInfo info = new PacketPlayerInfo();
|
||||
|
||||
info.setConnection(this);
|
||||
info.setGameMode(2);
|
||||
info.setGameMode(server.getConfig().getGameMode());
|
||||
|
||||
sendPacket(joinGame);
|
||||
sendPacket(abilities);
|
||||
sendPacket(positionAndLook);
|
||||
sendPacket(info);
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
package ru.nanit.limbo.protocol.packets.play;
|
||||
|
||||
import ru.nanit.limbo.protocol.ByteMessage;
|
||||
import ru.nanit.limbo.protocol.PacketOut;
|
||||
|
||||
public class PacketPlayerAbilities implements PacketOut {
|
||||
|
||||
private int flags = 0x02;
|
||||
private float flyingSpeed = 0.0F;
|
||||
private float fieldOfView = 0.1F;
|
||||
|
||||
public void setFlags(int flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public void setFlyingSpeed(float flyingSpeed) {
|
||||
this.flyingSpeed = flyingSpeed;
|
||||
}
|
||||
|
||||
public void setFieldOfView(float fieldOfView) {
|
||||
this.fieldOfView = fieldOfView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteMessage msg) {
|
||||
msg.writeByte(flags);
|
||||
msg.writeFloat(flyingSpeed);
|
||||
msg.writeFloat(fieldOfView);
|
||||
}
|
||||
|
||||
}
|
@ -40,6 +40,7 @@ public enum State {
|
||||
{
|
||||
serverBound.register(0x10, PacketKeepAlive::new);
|
||||
clientBound.register(0x24, PacketJoinGame::new);
|
||||
clientBound.register(0x30, PacketPlayerAbilities::new);
|
||||
clientBound.register(0x34, PacketPlayerPositionAndLook::new);
|
||||
clientBound.register(0x1F, PacketKeepAlive::new);
|
||||
clientBound.register(0x0E, PacketChatMessage::new);
|
||||
|
@ -26,6 +26,13 @@ spawnPosition:
|
||||
yaw: 0.0
|
||||
pitch: 0.0
|
||||
|
||||
# Setup player's game mode
|
||||
# 0 - Survival
|
||||
# 1 - Creative (hide HP and food bar)
|
||||
# 2 - Adventure
|
||||
# 3 - Spectator (hide all UI bars)
|
||||
gameMode: 1
|
||||
|
||||
# Message sends when player join to server
|
||||
joinMessage:
|
||||
enable: true
|
||||
|
Loading…
x
Reference in New Issue
Block a user