Skip to content

Commit

Permalink
Add configuration for declare commands and player list
Browse files Browse the repository at this point in the history
  • Loading branch information
BoomEaro committed Jan 29, 2022
1 parent e089fb5 commit 188d2de
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
23 changes: 22 additions & 1 deletion src/main/java/ru/nanit/limbo/configuration/LimboConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

public final class LimboConfig {

Expand All @@ -50,10 +51,13 @@ public final class LimboConfig {
private boolean useJoinMessage;
private boolean useBossBar;
private boolean useTitle;
private boolean useDeclareCommands;
private boolean usePlayerList;
private String brandName;
private String joinMessage;
private BossBar bossBar;
private Title title;
private List<String> declareCommands;

private InfoForwarding infoForwarding;
private long readTimeout;
Expand Down Expand Up @@ -86,8 +90,10 @@ public void load() throws Exception {
useJoinMessage = conf.node("joinMessage", "enable").getBoolean();
useBossBar = conf.node("bossBar", "enable").getBoolean();
useTitle = conf.node("title", "enable").getBoolean();
useDeclareCommands = conf.node("declareCommands", "enable").getBoolean();
usePlayerList = conf.node("playerList").getBoolean();

if(useBrandName)
if (useBrandName)
brandName = conf.node("brandName", "content").getString();

if (useJoinMessage)
Expand All @@ -99,6 +105,9 @@ public void load() throws Exception {
if (useTitle)
title = conf.node("title").get(Title.class);

if (useDeclareCommands)
declareCommands = conf.node("declareCommands", "commands").getList(String.class);

infoForwarding = conf.node("infoForwarding").get(InfoForwarding.class);
readTimeout = conf.node("readTimeout").getLong();
debugLevel = conf.node("debugLevel").getInt();
Expand Down Expand Up @@ -187,6 +196,14 @@ public boolean isUseTitle() {
return useTitle;
}

public boolean isUseDeclareCommands() {
return useDeclareCommands;
}

public boolean isUsePlayerList() {
return usePlayerList;
}

public String getBrandName() {
return brandName;
}
Expand All @@ -203,6 +220,10 @@ public Title getTitle() {
return title;
}

public List<String> getDeclareCommands() {
return declareCommands;
}

public boolean isUseEpoll() {
return useEpoll;
}
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/ru/nanit/limbo/connection/ClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.net.SocketAddress;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

Expand Down Expand Up @@ -239,10 +238,14 @@ private void fireLoginSuccess() {
writePacket(PACKET_JOIN_GAME);
writePacket(PACKET_PLAYER_ABILITIES);
writePacket(PACKET_PLAYER_POS);
writePacket(PACKET_PLAYER_INFO);
if (PACKET_PLAYER_INFO != null) {
writePacket(PACKET_PLAYER_INFO);
}

if (clientVersion.moreOrEqual(Version.V1_13)){
writePacket(PACKET_DECLARE_COMMANDS);
if (PACKET_DECLARE_COMMANDS != null)
writePacket(PACKET_DECLARE_COMMANDS);


if (PACKET_PLUGIN_MESSAGE != null)
writePacket(PACKET_PLUGIN_MESSAGE);
Expand Down Expand Up @@ -426,15 +429,21 @@ public static void initPackets(LimboServer server) {
info.setGameMode(server.getConfig().getGameMode());
info.setUuid(uuid);

PacketDeclareCommands declareCommands = new PacketDeclareCommands();
declareCommands.setCommands(Collections.emptyList());

PACKET_LOGIN_SUCCESS = PacketSnapshot.of(loginSuccess);
PACKET_JOIN_GAME = PacketSnapshot.of(joinGame);
PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities);
PACKET_PLAYER_POS = PacketSnapshot.of(positionAndLook);
PACKET_PLAYER_INFO = PacketSnapshot.of(info);
PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands);

if (server.getConfig().isUsePlayerList()) {
PACKET_PLAYER_INFO = PacketSnapshot.of(info);
}

if (server.getConfig().isUseDeclareCommands()) {
PacketDeclareCommands declareCommands = new PacketDeclareCommands();
declareCommands.setCommands(server.getConfig().getDeclareCommands());

PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands);
}

if (server.getConfig().isUseBrandName()){
PacketPluginMessage pluginMessage = new PacketPluginMessage();
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ ping:
# Available dimensions: OVERWORLD, NETHER, THE_END
dimension: THE_END

# Sending prepared tabcomplete commands to the player
declareCommands:
enable: true
commands:
- 'NanoLimbo'

# Whether to display the player in the player list
playerList: true

# Spawn position in the world
spawnPosition:
x: 0.0
Expand Down

0 comments on commit 188d2de

Please sign in to comment.