Skip to content

Commit

Permalink
feat: add translation in eng
Browse files Browse the repository at this point in the history
  • Loading branch information
AzaleeX committed Aug 27, 2024
1 parent a8b3eef commit 17126e8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 22 deletions.
37 changes: 34 additions & 3 deletions src/main/java/org/sculk/Sculk.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sculk.config.ServerProperties;
import org.sculk.config.ServerPropertiesKeys;
import org.sculk.lang.Language;
import org.sculk.lang.LanguageKeys;
import org.sculk.lang.LanguageManager;
import org.sculk.network.protocol.ProtocolInfo;
import org.sculk.utils.TextFormat;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/*
* ____ _ _
* / ___| ___ _ _| | | __
Expand All @@ -30,16 +40,28 @@ public class Sculk {
public static final String MINECRAFT_VERSION = ProtocolInfo.MINECRAFT_VERSION;
public static final String MINECRAFT_VERSION_NETWORK = ProtocolInfo.MINECRAFT_VERSION_NETWORK;
public static final String CODE_NAME = "Sculk";
public static final String CODE_VERSION = "v1.0.0";
public static final String CODE_VERSION = "1.0.0";
public static final JsonMapper JSON_MAPPER = JsonMapper.builder().build();
public static final String DATA_PATH = System.getProperty("user.dir") + "/";

public static void main(String[] args) {
Thread.currentThread().setName("sculkmp-main");
System.setProperty("log4j.skipJansi", "false");

Logger log = LogManager.getLogger(Sculk.class);
log.info("Starting {} software", CODE_NAME);

try {
Properties properties = loadServerProperties();
String langCode = properties.getProperty("language", "eng");
Language language = Language.fromCode(langCode);
LanguageManager languageManager = new LanguageManager(language);

log.info(languageManager.tr(LanguageKeys.SCULK_SERVER_STARTING, TextFormat.DARK_AQUA + CODE_NAME + TextFormat.WHITE, TextFormat.AQUA + CODE_VERSION + TextFormat.WHITE));

new Server(log, DATA_PATH);
} catch (Exception e) {
log.throwing(e);
shutdown();
}

int javaVersion = getJavaVersion();
if (javaVersion < 21) {
Expand All @@ -56,6 +78,15 @@ public static void main(String[] args) {
}
}

private static Properties loadServerProperties() throws IOException {
File file = new File(DATA_PATH + "server.properties");
Properties properties = new Properties();
try (FileInputStream input = new FileInputStream(file)) {
properties.load(input);
}
return properties;
}

protected static void shutdown() {
LogManager.shutdown();
Runtime.getRuntime().halt(0);
Expand Down
54 changes: 35 additions & 19 deletions src/main/java/org/sculk/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.sculk.event.EventManager;
import org.sculk.event.command.CommandEvent;
import org.sculk.event.player.PlayerCreationEvent;
import org.sculk.lang.Language;
import org.sculk.lang.LanguageKeys;
import org.sculk.lang.LanguageManager;
import org.sculk.network.BedrockInterface;
import org.sculk.network.Network;
import org.sculk.network.SourceInterface;
Expand All @@ -43,6 +46,8 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

import static org.sculk.Sculk.CODE_NAME;

/*
* ____ _ _
* / ___| ___ _ _| | | __
Expand Down Expand Up @@ -74,6 +79,8 @@ public class Server {

private Network network;

private LanguageManager languageManager;

private final Path dataPath;
private final Path pluginDataPath;

Expand Down Expand Up @@ -102,6 +109,7 @@ public Server(Logger logger, String dataPath) {
instance = this;
this.logger = logger;
this.dataPath = Paths.get(dataPath);
this.properties = new ServerProperties(this.dataPath);
Path pluginsPath = Path.of(dataPath, "plugins");
this.pluginDataPath = Path.of(dataPath, "plugin_data");
Path worldsPath = Path.of(dataPath, "worlds");
Expand All @@ -114,11 +122,12 @@ public Server(Logger logger, String dataPath) {
if(!resourcePath.toFile().exists()) resourcePath.toFile().mkdirs();
if(!playerPath.toFile().exists()) playerPath.toFile().mkdirs();

logger.info("Loading {}...", TextFormat.AQUA + "sculk.yml" + TextFormat.WHITE);
this.languageManager = new LanguageManager(getLangCode());

logger.info(getLanguage().tr(LanguageKeys.SCULK_SERVER_LOADING, TextFormat.AQUA + "sculk.yml" + TextFormat.WHITE));
this.config = new Config(this.dataPath + "/sculk.yml");

logger.info("Loading {}...", TextFormat.AQUA + "server.properties" + TextFormat.WHITE);
this.properties = new ServerProperties(this.dataPath);
logger.info(getLanguage().tr(LanguageKeys.SCULK_SERVER_LOADING, TextFormat.AQUA + "server.properties" + TextFormat.WHITE));
this.motd = this.properties.get(ServerPropertiesKeys.MOTD, "A Sculk Server Software");
this.submotd = this.properties.get(ServerPropertiesKeys.SUB_MOTD, "Powered by Sculk");

Expand All @@ -127,16 +136,16 @@ public Server(Logger logger, String dataPath) {
this.scheduler = injector.getInstance(Scheduler.class);
this.pluginManager = new PluginManager(this);

logger.info("Loading commands...");
logger.info(getLanguage().tr(LanguageKeys.SCULK_SERVER_LOADING_COMMANDS));
this.simpleCommandMap = new SimpleCommandMap(this);

this.operators = new Config(this.dataPath.resolve("op.txt").toString(), Config.ENUM);
this.whitelist = new Config(this.dataPath.resolve("whitelist.txt").toString(), Config.ENUM);
this.banByName = new Config(this.dataPath.resolve("banned-players.txt").toString(), Config.ENUM);
this.banByIp = new Config(this.dataPath.resolve("banned-ip.txt").toString(), Config.ENUM);

logger.info("Selected {} as the base language", this.properties.get(ServerPropertiesKeys.LANGUAGE, "English"));
logger.info("Starting Minecraft: Bedrock Edition server version {}", TextFormat.AQUA + Sculk.MINECRAFT_VERSION + TextFormat.WHITE);
logger.info(getLanguage().tr(LanguageKeys.SCULK_SERVER_SELECTED_LANGUAGE, Language.fromLang(getLangCode())));
logger.info(getLanguage().tr(LanguageKeys.SCULK_SERVER_STARTING_VERSION, TextFormat.AQUA + Sculk.MINECRAFT_VERSION + TextFormat.WHITE));

this.console = new TerminalConsole(this);
this.start();
Expand All @@ -145,39 +154,38 @@ public Server(Logger logger, String dataPath) {
public void start() {
this.console.getConsoleThread().start();

logger.info("Loading all plugins...");
getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_LOADING_PLUGINS));
pluginManager.loadAllPlugins();
logger.info("All plugins loaded successfully");
getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_PLUGINS_LOADED));

InetSocketAddress bindAddress = new InetSocketAddress(this.getProperties().get(ServerPropertiesKeys.SERVER_IP, "0.0.0.0"), this.getProperties().get(ServerPropertiesKeys.SERVER_PORT, 19132));
this.serverId = UUID.randomUUID();
this.network = new Network(this);
this.network.setName(this.motd);
try {
this.network.registerInterface(new BedrockInterface(this));
getLogger().info("Minecraft network interface running on {}", bindAddress);
getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_NETWORK_INTERFACE_RUNNING, bindAddress));
} catch(Exception e) {
logger.fatal("**** FAILED TO BIND TO " + bindAddress);
logger.fatal("Peahaps a server s already running on that port?");
getLogger().error(getLanguage().tr(LanguageKeys.SCULK_SERVER_FAILED_BIND, bindAddress), e);
getLogger().fatal(getLanguage().tr(LanguageKeys.SCULK_SERVER_SERVER_ALREADY_RUNNING));
shutdown();
}

this.tickCounter = 0;

if(this.properties.get(ServerPropertiesKeys.XBOX_AUTH, true)) {
logger.info("Online mode is enable. The server will verify that players are authenticated to XboxLive.");
getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_ONLINE_MODE_ENABLED));
} else {
logger.info("{}Online mode is not enabled. The server no longer checks if players are authenticated to XboxLive.", TextFormat.RED);
getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_ONLINE_MODE_DISABLED, TextFormat.RED));
}
logger.info("This server is running on version {}",TextFormat.AQUA + Sculk.CODE_VERSION);
logger.info("Sculk is distributed undex the {}",TextFormat.AQUA + "GNU GENERAL PUBLIC LICENSE");
getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_RUNNING_VERSION, TextFormat.AQUA + Sculk.CODE_VERSION + TextFormat.WHITE));
getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_DISTRIBUTED_UNDER, TextFormat.AQUA + "GNU GENERAL PUBLIC LICENSE"));

logger.info("Enable all plugins...");
getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_ENABLE_ALL_PLUGINS));
pluginManager.enableAllPlugins();
logger.info("All plugins enabled successfully");

getLogger().info("Done ({}s)! For help, type \"help\" or \"?", (double) (System.currentTimeMillis() - Sculk.START_TIME) / 1000);
getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_ALL_PLUGINS_ENABLED));

getLogger().info(getLanguage().tr(LanguageKeys.SCULK_SERVER_DONE, (double) (System.currentTimeMillis() - Sculk.START_TIME) / 1000));
this.getScheduler().scheduleDelayedTask(() -> {
System.out.println("5ms");
}, 5, false);
Expand Down Expand Up @@ -331,6 +339,14 @@ public String getVersion() {
return ProtocolInfo.MINECRAFT_VERSION;
}

public LanguageManager getLanguage() {
return this.languageManager;
}

public Language getLangCode() {
return Language.fromCode(this.properties.get(ServerPropertiesKeys.LANGUAGE, "eng"));
}

public boolean isXboxAuth() {
return true; // TODO default true for test
}
Expand Down

0 comments on commit 17126e8

Please sign in to comment.