Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Jan 14, 2024
2 parents cf7a175 + fd20b5e commit bd03749
Show file tree
Hide file tree
Showing 71 changed files with 454 additions and 353 deletions.
10 changes: 0 additions & 10 deletions build-logic/settings.gradle.kts

This file was deleted.

3 changes: 1 addition & 2 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("net.kyori.blossom")
alias(libs.plugins.blossom)
id("minimotd.base-conventions")
}

Expand All @@ -22,7 +22,6 @@ dependencies {
compileOnlyApi(libs.checkerQual)
compileOnlyApi(libs.gson)
testImplementation(libs.gson)
compileOnlyApi(libs.guava)
}

sourceSets.main {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -34,7 +34,7 @@
import org.checkerframework.framework.qual.DefaultQualifier;
import org.slf4j.Logger;
import xyz.jpenilla.minimotd.common.config.ConfigManager;
import xyz.jpenilla.minimotd.common.config.MiniMOTDConfig;
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
import xyz.jpenilla.minimotd.common.util.Components;

import static net.kyori.adventure.text.Component.newline;
Expand Down Expand Up @@ -77,7 +77,7 @@ public ConfigManager configManager() {
return this.configManager;
}

public PingResponse<I> createMOTD(final MiniMOTDConfig config, final int onlinePlayers, final int maxPlayers) {
public PingResponse<I> createMOTD(final MOTDConfig config, final int onlinePlayers, final int maxPlayers) {
final PingResponse.PlayerCount count = config.modifyPlayerCount(onlinePlayers, maxPlayers);
final PingResponse.Builder<I> response = PingResponse.<I>builder()
.playerCount(count)
Expand All @@ -90,7 +90,7 @@ public PingResponse<I> createMOTD(final MiniMOTDConfig config, final int onlineP
throw new IllegalStateException("MOTD is enabled, but there are no MOTDs in the config file?");
}
final int index = config.motds().size() == 1 ? 0 : ThreadLocalRandom.current().nextInt(config.motds().size());
final MiniMOTDConfig.MOTD motdConfig = config.motds().get(index);
final MOTDConfig.MOTD motdConfig = config.motds().get(index);
final Component motd = Components.ofChildren(
parse(motdConfig.line1(), count),
newline(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,11 +23,12 @@
*/
package xyz.jpenilla.minimotd.common.config;

import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -45,18 +46,18 @@ public final class ConfigManager {

private final MiniMOTD<?> miniMOTD;

private final ConfigLoader<MiniMOTDConfig> mainConfigLoader;
private MiniMOTDConfig mainConfig;
private final ConfigLoader<MOTDConfig> mainConfigLoader;
private MOTDConfig mainConfig;

private final ConfigLoader<PluginSettings> pluginSettingsLoader;
private PluginSettings pluginSettings;

private final Map<String, MiniMOTDConfig> extraConfigs = new HashMap<>();
private final Map<String, MOTDConfig> extraConfigs = new HashMap<>();

public ConfigManager(final @NonNull MiniMOTD<?> miniMOTD) {
this.miniMOTD = miniMOTD;
this.mainConfigLoader = new ConfigLoader<>(
MiniMOTDConfig.class,
MOTDConfig.class,
this.miniMOTD.dataDirectory().resolve("main.conf"),
options -> options.header("MiniMOTD Main Configuration")
);
Expand Down Expand Up @@ -93,12 +94,12 @@ public void loadExtraConfigs() {
continue;
}
final String name = path.getFileName().toString().replace(".conf", "");
final ConfigLoader<MiniMOTDConfig> loader = new ConfigLoader<>(
MiniMOTDConfig.class,
final ConfigLoader<MOTDConfig> loader = new ConfigLoader<>(
MOTDConfig.class,
path,
options -> options.header(String.format("Extra MiniMOTD config '%s'", name))
);
final MiniMOTDConfig config = loader.load();
final MOTDConfig config = loader.load();
loader.save(config);
this.extraConfigs.put(name, config);
}
Expand All @@ -109,20 +110,20 @@ public void loadExtraConfigs() {
}

private void createDefaultExtraConfigs(final @NonNull Path extraConfigsDir) throws ConfigurateException {
final List<Pair<Path, MiniMOTDConfig.MOTD>> defaults = ImmutableList.of(
pair(extraConfigsDir.resolve("skyblock.conf"), new MiniMOTDConfig.MOTD("<green><italic>Skyblock</green>", "<bold><rainbow>MiniMOTD Skyblock Server")),
pair(extraConfigsDir.resolve("survival.conf"), new MiniMOTDConfig.MOTD("<gradient:blue:red>Survival Mode Hardcore", "<green><bold>MiniMOTD Survival Server"))
);
for (final Pair<Path, MiniMOTDConfig.MOTD> pair : defaults) {
final ConfigLoader<MiniMOTDConfig> loader = new ConfigLoader<>(
MiniMOTDConfig.class,
final List<Pair<Path, MOTDConfig.MOTD>> defaults = Collections.unmodifiableList(Arrays.asList(
pair(extraConfigsDir.resolve("skyblock.conf"), new MOTDConfig.MOTD("<green><italic>Skyblock</green>", "<bold><rainbow>MiniMOTD Skyblock Server")),
pair(extraConfigsDir.resolve("survival.conf"), new MOTDConfig.MOTD("<gradient:blue:red>Survival Mode Hardcore", "<green><bold>MiniMOTD Survival Server"))
));
for (final Pair<Path, MOTDConfig.MOTD> pair : defaults) {
final ConfigLoader<MOTDConfig> loader = new ConfigLoader<>(
MOTDConfig.class,
pair.left()
);
loader.save(new MiniMOTDConfig(pair.right()));
loader.save(new MOTDConfig(pair.right()));
}
}

public @NonNull MiniMOTDConfig mainConfig() {
public @NonNull MOTDConfig mainConfig() {
if (this.mainConfig == null) {
throw new IllegalStateException("Config has not yet been loaded");
}
Expand All @@ -136,15 +137,14 @@ private void createDefaultExtraConfigs(final @NonNull Path extraConfigsDir) thro
return this.pluginSettings;
}

public @NonNull MiniMOTDConfig resolveConfig(final @Nullable InetSocketAddress address) {
public @NonNull MOTDConfig resolveConfig(final @Nullable InetSocketAddress address) {
if (address == null) {
return this.mainConfig();
}
final String hostString = address.getHostString() + ":" + address.getPort();
final String configString = this.pluginSettings().proxySettings().findConfigStringForHost(hostString);
final String configString = this.pluginSettings().proxySettings().findConfigStringForHost(address.getHostString(), address.getPort());

if (this.pluginSettings().proxySettings().virtualHostTestMode()) {
this.miniMOTD.platform().logger().info("[virtual-host-debug] Virtual Host: '{}', Selected Config: '{}'", hostString, configString == null ? "default" : configString);
this.miniMOTD.platform().logger().info("[virtual-host-debug] Virtual Host: '{}:{}', Selected Config: '{}'", address.getHostString(), address.getPort(), configString == null ? "default" : configString);
}

if (configString == null) {
Expand All @@ -153,11 +153,11 @@ private void createDefaultExtraConfigs(final @NonNull Path extraConfigsDir) thro
return this.resolveConfig(configString);
}

public @NonNull MiniMOTDConfig resolveConfig(final @NonNull String name) {
public @NonNull MOTDConfig resolveConfig(final @NonNull String name) {
if ("default".equals(name)) {
return this.mainConfig();
}
final MiniMOTDConfig cfg = this.extraConfigs.get(name);
final MOTDConfig cfg = this.extraConfigs.get(name);
if (cfg != null) {
return cfg;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -34,16 +34,16 @@
import static xyz.jpenilla.minimotd.common.PingResponse.PlayerCount.playerCount;

@ConfigSerializable
public final class MiniMOTDConfig {
public final class MOTDConfig {

public MiniMOTDConfig() {
public MOTDConfig() {
this(
new MOTD(),
new MOTD("<blue>Another <bold><red>MOTD", "<italic><underlined><gradient:red:green>much wow")
);
}

public MiniMOTDConfig(final @NonNull MOTD @NonNull ... defaults) {
public MOTDConfig(final @NonNull MOTD @NonNull ... defaults) {
this.motds.addAll(Arrays.asList(defaults));
}

Expand Down Expand Up @@ -123,6 +123,11 @@ public static final class PlayerCountSettings {
+ "If false, the online player count will be capped at the maximum player count")
private boolean allowExceedingMaximum = false;

@Comment("The list of server names that affect player counts/listing.\n"
+ "Only applicable when running the plugin on a proxy (Velocity or Waterfall/Bungeecord).\n"
+ "When set to an empty list, the default count & list as determined by the proxy will be used.")
private final List<String> servers = new ArrayList<>();

@ConfigSerializable
public static final class JustXMore {

Expand Down Expand Up @@ -157,6 +162,10 @@ public static final class FakePlayers {

}

public List<String> targetServers() {
return this.playerCountSettings.servers;
}

public boolean iconEnabled() {
return this.iconEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2023 Jason Penilla
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit bd03749

Please sign in to comment.