Skip to content
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

Convert to GTNHLib config #106

Merged
merged 8 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Add your dependencies here

dependencies {

api("com.github.GTNewHorizons:GTNHLib:0.5.5:dev")
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.6.34-GTNH:dev")
compileOnly("com.github.GTNewHorizons:EnderIO:2.8.17:dev")
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/serverutils/ServerUtilitiesCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.MinecraftForge;

import com.gtnewhorizon.gtnhlib.config.ConfigException;
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
Expand Down Expand Up @@ -134,15 +137,20 @@ public EditingConfig(ConfigGroup g, IConfigCallback c) {
}
}

static {
try {
ConfigurationManager.registerConfig(ServerUtilitiesConfig.class);
} catch (ConfigException e) {
throw new RuntimeException(e);
}
}

public void preInit(FMLPreInitializationEvent event) {
if ((Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment")) {
ServerUtilities.LOGGER.info("Loading ServerUtilities in development environment");
}

OtherMods.init();
ServerUtilitiesConfig.init(event);
AuroraConfig.init(event);

if (ranks.enabled) {
PermissionAPI.setPermissionHandler(ServerUtilitiesPermissionHandler.INSTANCE);
}
Expand Down Expand Up @@ -171,7 +179,7 @@ public void preInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(ServerUtilitiesPermissions.INST);
MinecraftForge.EVENT_BUS.register(ServerUtilitiesLeaderboards.INST);
FMLCommonHandler.instance().bus().register(ServerUtilitiesServerEventHandler.INST);
if (AuroraConfig.general.enable) {
if (AuroraConfig.enable) {
MinecraftForge.EVENT_BUS.register(AuroraMinecraftHandler.INST);
FMLCommonHandler.instance().bus().register(AuroraMinecraftHandler.INST);
}
Expand Down Expand Up @@ -278,7 +286,7 @@ public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
public void onServerStarting(FMLServerStartingEvent event) {
ServerUtilitiesCommands.registerCommands(event);

if (AuroraConfig.general.enable) {
if (AuroraConfig.enable) {
Aurora.start(event.getServer());
}
}
Expand Down
669 changes: 329 additions & 340 deletions src/main/java/serverutils/ServerUtilitiesConfig.java

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/main/java/serverutils/aurora/Aurora.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ public class Aurora {
private static AuroraServer server;

public static void start(MinecraftServer s) {
if (AuroraConfig.general.enable) {
if (AuroraConfig.enable) {
if (server == null) {
server = new AuroraServer(s, AuroraConfig.general.port);
server = new AuroraServer(s, AuroraConfig.port);
server.start();
}
}
}

public static void stop() {
if (AuroraConfig.general.enable) {
if (AuroraConfig.enable) {
if (server != null) {
server.shutdown();
server = null;
Expand Down
115 changes: 32 additions & 83 deletions src/main/java/serverutils/aurora/AuroraConfig.java
Original file line number Diff line number Diff line change
@@ -1,98 +1,47 @@
package serverutils.aurora;

import java.io.File;

import net.minecraftforge.common.config.Configuration;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import com.gtnewhorizon.gtnhlib.config.Config;

@Config(modid = "serverutilities", filename = "aurora", configSubDirectory = "../serverutilities/")
public class AuroraConfig {

public static Configuration config;
public static final String GEN_CAT = Configuration.CATEGORY_GENERAL;
public static final String PAGES_CAT = "Pages";

public static void init(FMLPreInitializationEvent event) {
config = new Configuration(new File(event.getModConfigurationDirectory() + "/../serverutilities/aurora.cfg"));
sync();
}
@Config.Comment("Enable the localhost server")
@Config.DefaultBoolean(false)
public static boolean enable;

public static boolean sync() {
config.load();
@Config.Comment("Enable the modlist page")
@Config.DefaultEnum("ENABLED")
public static PageType modlist_page;

general.enable = config.get(GEN_CAT, "enable", false, "Enable the localhost server, Default: false")
.getBoolean();
general.port = config.get(GEN_CAT, "port", 48574, "Webserver Port ID, Default: 48574", 1025, 65534).getInt();
general.modlist_page = config
.get(
PAGES_CAT,
"modlist_page",
"ENABLED",
"Enable the modlist page, Default: ENABLED, Valid values: ENABLED, REQUIRES_AUTH, DISABLED")
.getString();
general.world_info_json = config
.get(
PAGES_CAT,
"world_info_json",
"ENABLED",
"Enable the world info page, Default: ENABLED, Valid values: ENABLED, REQUIRES_AUTH, DISABLED")
.getString();
general.player_list_table = config.get(
PAGES_CAT,
"player_list_table",
"ENABLED",
"Enable the playerlist table page, Default: ENABLED, Valid values: ENABLED, REQUIRES_AUTH, DISABLED")
.getString();
general.player_list_json = config.get(
PAGES_CAT,
"player_list_json",
"ENABLED",
"Enable the playerlist json page, Default: ENABLED, Valid values: ENABLED, REQUIRES_AUTH, DISABLED")
.getString();
general.player_rank_page = config.get(
PAGES_CAT,
"player_rank_page",
"REQUIRES_AUTH",
"Enable the player rank page from Server Utilities, Default: REQUIRES_AUTH, Valid values: ENABLED, REQUIRES_AUTH, DISABLED")
.getString();
general.command_list_page = config.get(
PAGES_CAT,
"command_list_page",
"ENABLED",
"Enable the command list page from Server Utilities, Default: ENABLED, Valid values: ENABLED, REQUIRES_AUTH, DISABLED")
.getString();
general.permission_list_page = config.get(
PAGES_CAT,
"permission_list_page",
"ENABLED",
"Enable the permission list page from Server Utilities, Default: ENABLED, Valid values: ENABLED, REQUIRES_AUTH, DISABLED")
.getString();
@Config.Comment("Enable the modlist page")
@Config.DefaultEnum("ENABLED")
public static PageType world_info_json;

general.modlist_excluded_mods = config.get(
PAGES_CAT,
"modlist_excluded_mods",
new String[] {},
"Exclude mods from the modlist: Default: Empty").getStringList();
@Config.Comment("Enable the world info page")
@Config.DefaultEnum("ENABLED")
public static PageType player_list_table;

config.save();
return true;
@Config.Comment("Enable the playerlist table page")
@Config.DefaultEnum("ENABLED")
public static PageType player_list_json;

}
@Config.Comment("Enable the playerlist json page")
@Config.DefaultEnum("REQUIRES_AUTH")
public static PageType player_rank_page;

public static final General general = new General();
@Config.Comment("Enable the player rank page from Server Utilities")
@Config.DefaultEnum("ENABLED")
public static PageType command_list_page;

public static class General {
@Config.Comment("Enable the command list page from Server Utilities")
@Config.DefaultEnum("ENABLED")
public static PageType permission_list_page;

public boolean enable;
public String modlist_page;
public String world_info_json;
public String player_list_table;
public String player_list_json;
public String player_rank_page;
public String command_list_page;
public String permission_list_page;
public String[] modlist_excluded_mods;
public int port;
@Config.Comment("Exclude mods from the modlist")
@Config.DefaultStringList({})
public static String[] modlist_excluded_mods;

}
@Config.Comment("Webserver Port ID")
@Config.DefaultInt(48574)
public static int port;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void onHomeEvent(AuroraHomePageEvent event) {
public void onPageEvent(AuroraPageEvent event) {

if (event.checkPath("modlist", "*")) {
HashSet<String> set = new HashSet<>(Arrays.asList(AuroraConfig.general.modlist_excluded_mods));
HashSet<String> set = new HashSet<>(Arrays.asList(AuroraConfig.modlist_excluded_mods));

if (!set.contains(event.getSplitUri()[1])) {
ModContainer modContainer = Loader.instance().getIndexedModList().get(event.getSplitUri()[1]);
Expand All @@ -56,7 +56,7 @@ public void onPageEvent(AuroraPageEvent event) {
}
}
} else if (event.checkPath("modlist")) {
event.returnPage(new ModListPage(new HashSet<>(Arrays.asList(AuroraConfig.general.modlist_excluded_mods))));
event.returnPage(new ModListPage(new HashSet<>(Arrays.asList(AuroraConfig.modlist_excluded_mods))));
} else if (event.checkPath("minecraft", "online_players")) {
event.returnPage(new PlayerListTable(event.getAuroraServer().getServer()));
} else if (event.checkPath("minecraft", "online_players.json")) {
Expand Down
21 changes: 2 additions & 19 deletions src/main/java/serverutils/aurora/mc/CommandListPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ public String getIcon() {

@Override
public PageType getPageType() {
return switch (AuroraConfig.general.command_list_page) {
case "DISABLED" -> PageType.DISABLED;
case "REQUIRES_AUTH" -> PageType.REQUIRES_AUTH;
default -> PageType.ENABLED;
};
return AuroraConfig.command_list_page;
}

@Override
Expand All @@ -60,20 +56,7 @@ public void body(Tag body) {

for (CommandOverride c : Ranks.INSTANCE.commands.values()) {
Tag row = nodeTable.tr();
row.td().paired("code", c.node.toString());
Tag n = row.td();

// boolean first = true;

// for (String s : Tag.fixHTML(c.usage.getUnformattedText()).split(" OR ")) {
// if (first) {
// first = false;
// } else {
// n.br();
// }
//
// n.text(s);
// }
row.td().paired("code", c.node);
}
}
}
6 changes: 1 addition & 5 deletions src/main/java/serverutils/aurora/mc/ModListPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public String getDescription() {

@Override
public PageType getPageType() {
return switch (AuroraConfig.general.modlist_page) {
case "DISABLED" -> PageType.DISABLED;
case "REQUIRES_AUTH" -> PageType.REQUIRES_AUTH;
default -> PageType.ENABLED;
};
return AuroraConfig.modlist_page;
}

@Override
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/serverutils/aurora/mc/ModPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public String getDescription() {

@Override
public PageType getPageType() {
return switch (AuroraConfig.general.modlist_page) {
case "DISABLED" -> PageType.DISABLED;
case "REQUIRES_AUTH" -> PageType.REQUIRES_AUTH;
default -> PageType.ENABLED;
};
return AuroraConfig.modlist_page;
}

@Override
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/serverutils/aurora/mc/PermissionListPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ public String getIcon() {

@Override
public PageType getPageType() {
return switch (AuroraConfig.general.permission_list_page) {
case "DISABLED" -> PageType.DISABLED;
case "REQUIRES_AUTH" -> PageType.REQUIRES_AUTH;
default -> PageType.ENABLED;
};
return AuroraConfig.permission_list_page;
}

@Override
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/serverutils/aurora/mc/PlayerListJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ public PlayerListJson(MinecraftServer s) {

@Override
public PageType getPageType() {
return switch (AuroraConfig.general.player_list_json) {
case "DISABLED" -> PageType.DISABLED;
case "REQUIRES_AUTH" -> PageType.REQUIRES_AUTH;
default -> PageType.ENABLED;
};
return AuroraConfig.player_list_json;
}

@Override
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/serverutils/aurora/mc/PlayerListTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ public String getDescription() {

@Override
public PageType getPageType() {
return switch (AuroraConfig.general.player_list_table) {
case "DISABLED" -> PageType.DISABLED;
case "REQUIRES_AUTH" -> PageType.REQUIRES_AUTH;
default -> PageType.ENABLED;
};
return AuroraConfig.player_list_table;
}

@Override
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/serverutils/aurora/mc/RankPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ public String getIcon() {

@Override
public PageType getPageType() {
return switch (AuroraConfig.general.player_rank_page) {
case "DISABLED" -> PageType.DISABLED;
case "ENABLED" -> PageType.ENABLED;
default -> PageType.REQUIRES_AUTH;
};
return AuroraConfig.player_rank_page;
}

@Override
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/serverutils/aurora/mc/WorldInfoJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ public WorldInfoJson(MinecraftServer s) {

@Override
public PageType getPageType() {
return switch (AuroraConfig.general.world_info_json) {
case "DISABLED" -> PageType.DISABLED;
case "REQUIRES_AUTH" -> PageType.REQUIRES_AUTH;
default -> PageType.ENABLED;
};
return AuroraConfig.world_info_json;
}

@Override
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/serverutils/client/EnumNotificationLocation.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package serverutils.client;

import java.util.Locale;

public enum EnumNotificationLocation {

DISABLED,
Expand All @@ -15,12 +13,4 @@ public boolean chat() {
public boolean disabled() {
return this == DISABLED;
}

public static EnumNotificationLocation stringToEnum(String placement) {
return switch (placement.toLowerCase(Locale.ENGLISH)) {
case "disabled" -> DISABLED;
case "chat" -> CHAT;
default -> SCREEN;
};
}
}
Loading