-
Notifications
You must be signed in to change notification settings - Fork 0
Support servers config in ServerRegistrationListener #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,16 +21,35 @@ public ServerRegistrationListener(ForcePackVelocity plugin) { | |
| public void onServerRegistered(ServerRegisteredEvent event) { | ||
| RegisteredServer registeredServer = event.registeredServer(); | ||
| String serverName = registeredServer.getServerInfo().getName(); | ||
| VelocityConfig groups = plugin.getConfig().getConfig("groups"); | ||
|
|
||
| if (groups == null) return; | ||
|
|
||
| // Check if we already have packs for this server | ||
| boolean hasPack = plugin.getResourcePacks().stream() | ||
| .anyMatch(pack -> pack.getServer().equals(serverName)); | ||
|
|
||
| if (hasPack) return; | ||
|
|
||
| // Check the "servers" configuration first | ||
| VelocityConfig servers = plugin.getConfig().getConfig("servers"); | ||
| if (servers != null) { | ||
| VelocityConfig serverConfig = servers.getConfig(serverName); | ||
| if (serverConfig != null) { | ||
| plugin.log("New server %s matches servers configuration, adding resource packs...", serverName); | ||
|
|
||
| final Map<String, VelocityConfig> configs = plugin.getPackConfigs(serverConfig, serverName); | ||
|
|
||
| configs.forEach((id, config) -> { | ||
| if (config == null) return; | ||
| // serverName is used both as the config name and target server name | ||
| plugin.registerResourcePackForServer(config, id, serverName, "server", plugin.getConfig().getBoolean("verify-resource-packs"), serverName, null); | ||
| }); | ||
| return; | ||
| } | ||
|
Comment on lines
+43
to
+46
|
||
| } | ||
|
|
||
| // Check the "groups" configuration | ||
| VelocityConfig groups = plugin.getConfig().getConfig("groups"); | ||
| if (groups == null) return; | ||
|
|
||
| for (String groupName : groups.getKeys()) { | ||
| VelocityConfig groupConfig = groups.getConfig(groupName); | ||
| List<String> servers = groupConfig.getStringList("servers"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VelocityConfig serversis declared here, but later in the method (inside the groups loop) there is also aList<String> serverslocal variable. Java does not allow redeclaring a local variable name in an inner scope, so this will fail to compile. Rename one of them (e.g.,serversConfigfor the config section, orserverPatternsfor the list).