Skip to content

Commit deaf821

Browse files
config changes and commandmeta
1 parent 5f94cde commit deaf821

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

.idea/workspace.xml

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/org/zeroBzeroT/serverPingPlayerList/Config.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import java.util.Map;
1212

1313
public class Config {
14+
private final Main main;
1415
private final Path configPath;
1516
private final Logger logger;
1617
private Map<String, Object> configValues;
1718

18-
public Config(Path dataDirectory, Logger logger) {
19+
public Config(Main main, Path dataDirectory, Logger logger) {
20+
this.main = main;
1921
this.configPath = dataDirectory.resolve("config.yml");
2022
this.logger = logger;
2123
loadConfig();
@@ -37,16 +39,20 @@ private void loadConfig() {
3739

3840
private void createDefaultConfig() {
3941
try {
42+
Files.createDirectories(configPath.getParent());
43+
4044
Files.createFile(configPath);
45+
4146
try (BufferedWriter writer = Files.newBufferedWriter(configPath)) {
42-
writer.write("versionName: ZeroPaper 1.12.2+\n");
43-
writer.write("versionMinProtocol: 340\n");
47+
writer.write("# Created on " + main.getServer().getVersion().getName() + " " + main.getServer().getVersion().getVersion() + "\n");
48+
writer.write("versionName: \"LimeWire 5.5.16\"\n");
49+
writer.write("versionMinProtocol: 340 # 1.12.2\n");
4450
writer.write("setHoverInfo: true\n");
4551
writer.write("messageOfTheDayOverride: false\n");
46-
writer.write("messageOfTheDay: ''\n");
47-
writer.write("bStats: false\n");
52+
writer.write("messageOfTheDay: \"A Minecraft Server\"\n");
53+
writer.write("bStats: true\n");
4854
writer.write("useMainServer: false\n");
49-
writer.write("mainServer: 'main'\n");
55+
writer.write("mainServer: \"main\"\n");
5056
}
5157
logger.info("Default config created.");
5258
} catch (IOException e) {
@@ -65,4 +71,16 @@ public boolean getBoolean(String key) {
6571
public Integer getInt(String key) {
6672
return Integer.parseInt(configValues.getOrDefault(key, "false").toString());
6773
}
74+
75+
void logConfig() {
76+
logger.info("Version Name: {}", getString("versionName"));
77+
logger.info("Version Minimum Protocol: {}", getString("versionMinProtocol"));
78+
logger.info("Set Hover Info: {}", getString("setHoverInfo"));
79+
if (getBoolean("messageOfTheDayOverride")) {
80+
logger.info("Message Of The Day: {}", getString("messageOfTheDay"));
81+
}
82+
if (getBoolean("useMainServer")) {
83+
logger.info("Ping Pass-Through-Server: {}", getString("mainServer"));
84+
}
85+
}
6886
}

src/main/java/org/zeroBzeroT/serverPingPlayerList/Main.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.inject.Inject;
44
import com.velocitypowered.api.command.CommandManager;
5+
import com.velocitypowered.api.command.CommandMeta;
56
import com.velocitypowered.api.event.Subscribe;
67
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
78
import com.velocitypowered.api.plugin.annotation.DataDirectory;
@@ -25,7 +26,7 @@ public class Main {
2526
private ServerListListener serverListListener;
2627

2728
private ScheduledTask pingTask;
28-
private volatile ServerPing mainPing; // Cached ping from main server, similar to old mainPing
29+
private volatile ServerPing mainPing;
2930

3031
@Inject
3132
public Main(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
@@ -38,7 +39,7 @@ public Main(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory
3839
public void onProxyInitialize(ProxyInitializeEvent event) {
3940
logger.info("ServerPingPlayerList is starting up...");
4041

41-
config = new Config(dataDirectory, logger);
42+
config = new Config(this, dataDirectory, logger);
4243

4344
// Register Event Listeners
4445
serverListListener = new ServerListListener(this, config);
@@ -51,7 +52,7 @@ public void onProxyInitialize(ProxyInitializeEvent event) {
5152
startPingTask();
5253

5354
// Some output to the console ;)
54-
logConfig();
55+
config.logConfig();
5556

5657
// TODO Load Plugin Metrics
5758
if (config.getBoolean("bStats")) {
@@ -62,7 +63,8 @@ public void onProxyInitialize(ProxyInitializeEvent event) {
6263

6364
private void registerCommands() {
6465
CommandManager commandManager = server.getCommandManager();
65-
commandManager.register("spplreload", new ReloadCommand(this, logger));
66+
CommandMeta commandMeta = commandManager.metaBuilder("spplreload").plugin(this).build();
67+
commandManager.register(commandMeta, new ReloadCommand(this, logger));
6668
}
6769

6870
public ProxyServer getServer() {
@@ -75,7 +77,7 @@ public ServerPing getMainPing() {
7577

7678
public void reloadConfig() {
7779
logger.info("Reloading configuration...");
78-
Config newConfig = new Config(dataDirectory, logger);
80+
Config newConfig = new Config(this, dataDirectory, logger);
7981
this.config = newConfig;
8082
serverListListener.setConfig(newConfig);
8183
startPingTask();
@@ -106,16 +108,4 @@ public void startPingTask() {
106108
})).repeat(5, TimeUnit.SECONDS).schedule();
107109
}
108110
}
109-
110-
private void logConfig() {
111-
logger.info("[config] Version Name: {}", config.getString("versionName"));
112-
logger.info("[config] Version Minimum Protocol: {}", config.getString("versionMinProtocol"));
113-
logger.info("[config] Set Hover Info: {}", config.getString("setHoverInfo"));
114-
if (config.getBoolean("messageOfTheDayOverride")) {
115-
logger.info("[config] Message Of The Day: {}", config.getString("messageOfTheDay"));
116-
}
117-
if (config.getBoolean("useMainServer")) {
118-
logger.info("[config] Ping Pass-Through-Server: {}", config.getString("mainServer"));
119-
}
120-
}
121111
}

0 commit comments

Comments
 (0)