mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-08-30 05:40:34 +00:00
Merge remote-tracking branch 'origin/ver/6.0.0' into ver/6.0.0
This commit is contained in:
@@ -10,6 +10,8 @@ dependencies {
|
|||||||
|
|
||||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||||
|
|
||||||
|
"shadedApi"("org.slf4j:slf4j-api:1.7.32")
|
||||||
|
|
||||||
"shadedApi"("ca.solo-studios:strata:1.0.0")
|
"shadedApi"("ca.solo-studios:strata:1.0.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,15 +20,12 @@ import com.dfsek.terra.api.profiler.Profiler;
|
|||||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||||
import com.dfsek.terra.api.registry.Registry;
|
import com.dfsek.terra.api.registry.Registry;
|
||||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||||
import com.dfsek.terra.api.util.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Terra mod/plugin instance.
|
* Represents a Terra mod/plugin instance.
|
||||||
*/
|
*/
|
||||||
public interface Platform extends LoaderRegistrar {
|
public interface Platform extends LoaderRegistrar {
|
||||||
Logger logger();
|
|
||||||
|
|
||||||
boolean reload();
|
boolean reload();
|
||||||
|
|
||||||
String platformName();
|
String platformName();
|
||||||
@@ -58,8 +55,6 @@ public interface Platform extends LoaderRegistrar {
|
|||||||
|
|
||||||
ItemHandle getItemHandle();
|
ItemHandle getItemHandle();
|
||||||
|
|
||||||
Logger getDebugLogger();
|
|
||||||
|
|
||||||
EventManager getEventManager();
|
EventManager getEventManager();
|
||||||
|
|
||||||
default String getVersion() {
|
default String getVersion() {
|
||||||
|
|||||||
+6
-2
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.api.structure.buffer.items;
|
package com.dfsek.terra.api.structure.buffer.items;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
import com.dfsek.terra.api.block.state.BlockState;
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
import com.dfsek.terra.api.block.state.properties.base.Properties;
|
import com.dfsek.terra.api.block.state.properties.base.Properties;
|
||||||
@@ -16,6 +19,8 @@ import com.dfsek.terra.api.world.World;
|
|||||||
|
|
||||||
|
|
||||||
public class BufferedBlock implements BufferedItem {
|
public class BufferedBlock implements BufferedItem {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(BufferedBlock.class);
|
||||||
|
|
||||||
private final BlockState data;
|
private final BlockState data;
|
||||||
private final boolean overwrite;
|
private final boolean overwrite;
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
@@ -39,8 +44,7 @@ public class BufferedBlock implements BufferedItem {
|
|||||||
world.setBlockData(origin, data);
|
world.setBlockData(origin, data);
|
||||||
}
|
}
|
||||||
} catch(RuntimeException e) {
|
} catch(RuntimeException e) {
|
||||||
platform.logger().severe("Failed to place block at location " + origin + ": " + e.getMessage());
|
logger.error("Failed to place block at location {}", origin, e);
|
||||||
platform.getDebugLogger().stack(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2020-2021 Polyhedral Development
|
|
||||||
*
|
|
||||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
|
||||||
* reference the LICENSE file in the common/api directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.dfsek.terra.api.util;
|
|
||||||
|
|
||||||
public interface Logger {
|
|
||||||
void info(String message);
|
|
||||||
|
|
||||||
void warning(String message);
|
|
||||||
|
|
||||||
void severe(String message);
|
|
||||||
|
|
||||||
default void stack(Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,6 +20,8 @@ package com.dfsek.terra;
|
|||||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -52,8 +54,6 @@ import com.dfsek.terra.api.lang.Language;
|
|||||||
import com.dfsek.terra.api.profiler.Profiler;
|
import com.dfsek.terra.api.profiler.Profiler;
|
||||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||||
import com.dfsek.terra.api.registry.Registry;
|
import com.dfsek.terra.api.registry.Registry;
|
||||||
import com.dfsek.terra.api.util.Logger;
|
|
||||||
import com.dfsek.terra.api.util.generic.Lazy;
|
|
||||||
import com.dfsek.terra.api.util.mutable.MutableBoolean;
|
import com.dfsek.terra.api.util.mutable.MutableBoolean;
|
||||||
import com.dfsek.terra.commands.CommandUtil;
|
import com.dfsek.terra.commands.CommandUtil;
|
||||||
import com.dfsek.terra.commands.TerraCommandManager;
|
import com.dfsek.terra.commands.TerraCommandManager;
|
||||||
@@ -66,7 +66,6 @@ import com.dfsek.terra.registry.CheckedRegistryImpl;
|
|||||||
import com.dfsek.terra.registry.LockedRegistryImpl;
|
import com.dfsek.terra.registry.LockedRegistryImpl;
|
||||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||||
import com.dfsek.terra.util.logging.DebugLogger;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,9 +74,10 @@ import com.dfsek.terra.util.logging.DebugLogger;
|
|||||||
* Implementations must invoke {@link #load()} in their constructors.
|
* Implementations must invoke {@link #load()} in their constructors.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractPlatform implements Platform {
|
public abstract class AbstractPlatform implements Platform {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AbstractPlatform.class);
|
||||||
|
|
||||||
private static final MutableBoolean LOADED = new MutableBoolean(false);
|
private static final MutableBoolean LOADED = new MutableBoolean(false);
|
||||||
private final EventManager eventManager = new EventManagerImpl(this);
|
private final EventManager eventManager = new EventManagerImpl(this);
|
||||||
|
|
||||||
private final ConfigRegistry configRegistry = new ConfigRegistry();
|
private final ConfigRegistry configRegistry = new ConfigRegistry();
|
||||||
|
|
||||||
private final CheckedRegistry<ConfigPack> checkedConfigRegistry = new CheckedRegistryImpl<>(configRegistry);
|
private final CheckedRegistry<ConfigPack> checkedConfigRegistry = new CheckedRegistryImpl<>(configRegistry);
|
||||||
@@ -94,58 +94,18 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
|
|
||||||
private final Registry<BaseAddon> lockedAddonRegistry = new LockedRegistryImpl<>(addonRegistry);
|
private final Registry<BaseAddon> lockedAddonRegistry = new LockedRegistryImpl<>(addonRegistry);
|
||||||
|
|
||||||
private final Lazy<Logger> logger = Lazy.lazy(this::createLogger);
|
public ConfigRegistry getRawConfigRegistry() {
|
||||||
private final Lazy<DebugLogger> debugLogger = Lazy.lazy(() -> new DebugLogger(logger()));
|
return configRegistry;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(TypeRegistry registry) {
|
|
||||||
loaders.register(registry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public CommandManager getManager() {
|
||||||
public Logger logger() {
|
return manager;
|
||||||
return logger.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluginConfig getTerraConfig() {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Language getLanguage() {
|
|
||||||
return LangUtil.getLanguage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CheckedRegistry<ConfigPack> getConfigRegistry() {
|
|
||||||
return checkedConfigRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Registry<BaseAddon> getAddons() {
|
|
||||||
return lockedAddonRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Logger getDebugLogger() {
|
|
||||||
return debugLogger.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EventManager getEventManager() {
|
|
||||||
return eventManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Optional<BaseAddon> platformAddon() {
|
protected Optional<BaseAddon> platformAddon() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Profiler getProfiler() {
|
|
||||||
return profiler;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void load() {
|
protected void load() {
|
||||||
if(LOADED.get()) {
|
if(LOADED.get()) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
@@ -154,7 +114,7 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
}
|
}
|
||||||
LOADED.set(true);
|
LOADED.set(true);
|
||||||
|
|
||||||
logger().info("Initializing Terra...");
|
logger.info("Initializing Terra...");
|
||||||
|
|
||||||
try(InputStream stream = getClass().getResourceAsStream("/config.yml")) {
|
try(InputStream stream = getClass().getResourceAsStream("/config.yml")) {
|
||||||
File configFile = new File(getDataFolder(), "config.yml");
|
File configFile = new File(getDataFolder(), "config.yml");
|
||||||
@@ -162,7 +122,7 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
FileUtils.copyInputStreamToFile(stream, configFile);
|
FileUtils.copyInputStreamToFile(stream, configFile);
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error loading config.yml resource from jar", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -173,16 +133,17 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
if(config.dumpDefaultConfig()) {
|
if(config.dumpDefaultConfig()) {
|
||||||
try(InputStream resourcesConfig = getClass().getResourceAsStream("/resources.yml")) {
|
try(InputStream resourcesConfig = getClass().getResourceAsStream("/resources.yml")) {
|
||||||
if(resourcesConfig == null) {
|
if(resourcesConfig == null) {
|
||||||
logger().info("No resources config found. Skipping resource dumping.");
|
logger.info("No resources config found. Skipping resource dumping.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String resourceYaml = IOUtils.toString(resourcesConfig, StandardCharsets.UTF_8);
|
String resourceYaml = IOUtils.toString(resourcesConfig, StandardCharsets.UTF_8);
|
||||||
Map<String, List<String>> resources = new Yaml().load(resourceYaml);
|
Map<String, List<String>> resources = new Yaml().load(resourceYaml);
|
||||||
resources.forEach((dir, entries) -> entries.forEach(entry -> {
|
resources.forEach((dir, entries) -> entries.forEach(entry -> {
|
||||||
String resourcePath = dir + "/" + entry;
|
String resourcePath = String.format("%s/%s", dir, entry);
|
||||||
File resource = new File(getDataFolder(), resourcePath);
|
File resource = new File(getDataFolder(), resourcePath);
|
||||||
if(resource.exists()) return; // dont overwrite
|
if(resource.exists())
|
||||||
logger().info("Dumping resource " + resource.getAbsolutePath());
|
return; // dont overwrite
|
||||||
|
logger.info("Dumping resource {}...", resource.getAbsolutePath());
|
||||||
try {
|
try {
|
||||||
resource.getParentFile().mkdirs();
|
resource.getParentFile().mkdirs();
|
||||||
resource.createNewFile();
|
resource.createNewFile();
|
||||||
@@ -197,14 +158,12 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error while dumping resources...", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getDebugLogger().info("Skipping resource dumping.");
|
logger.info("Skipping resource dumping.");
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLogger.value().setDebug(config.isDebugLogging()); // enable debug logger if applicable
|
|
||||||
|
|
||||||
if(config.isDebugProfiler()) { // if debug.profiler is enabled, start profiling
|
if(config.isDebugProfiler()) { // if debug.profiler is enabled, start profiling
|
||||||
profiler.start();
|
profiler.start();
|
||||||
}
|
}
|
||||||
@@ -248,36 +207,61 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
.getHandler(FunctionalEventHandler.class)
|
.getHandler(FunctionalEventHandler.class)
|
||||||
.register(internalAddon, PlatformInitializationEvent.class)
|
.register(internalAddon, PlatformInitializationEvent.class)
|
||||||
.then(event -> {
|
.then(event -> {
|
||||||
logger().info("Loading config packs...");
|
logger.info("Loading config packs...");
|
||||||
getRawConfigRegistry().loadAll(this);
|
getRawConfigRegistry().loadAll(this);
|
||||||
logger().info("Loaded packs.");
|
logger.info("Loaded packs.");
|
||||||
})
|
})
|
||||||
.global();
|
.global();
|
||||||
|
|
||||||
|
|
||||||
logger().info("Loaded addons.");
|
logger.info("Loaded addons.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommandUtil.registerAll(manager);
|
CommandUtil.registerAll(manager);
|
||||||
} catch(MalformedCommandException e) {
|
} catch(MalformedCommandException e) {
|
||||||
e.printStackTrace(); // TODO do something here even though this should literally never happen
|
logger.error("Error registering commands", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
logger().info("Finished initialization.");
|
logger.info("Finished initialization.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Logger createLogger();
|
|
||||||
|
|
||||||
protected Optional<BaseAddon> getPlatformAddon() {
|
protected Optional<BaseAddon> getPlatformAddon() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigRegistry getRawConfigRegistry() {
|
@Override
|
||||||
return configRegistry;
|
public void register(TypeRegistry registry) {
|
||||||
|
loaders.register(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandManager getManager() {
|
@Override
|
||||||
return manager;
|
public PluginConfig getTerraConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Language getLanguage() {
|
||||||
|
return LangUtil.getLanguage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckedRegistry<ConfigPack> getConfigRegistry() {
|
||||||
|
return checkedConfigRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Registry<BaseAddon> getAddons() {
|
||||||
|
return lockedAddonRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EventManager getEventManager() {
|
||||||
|
return eventManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Profiler getProfiler() {
|
||||||
|
return profiler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ public class AddonsCommand implements CommandTemplate {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender) {
|
public void execute(CommandSender sender) {
|
||||||
sender.sendMessage("Installed Addons:");
|
sender.sendMessage("Installed Addons:");
|
||||||
platform.getAddons().forEach(
|
platform.getAddons().forEach(addon -> {
|
||||||
addon -> sender.sendMessage(" - " + addon.getID()));
|
sender.sendMessage(" - " + addon.getID());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,19 +17,23 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.commands;
|
package com.dfsek.terra.commands;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.dfsek.terra.api.command.CommandManager;
|
import com.dfsek.terra.api.command.CommandManager;
|
||||||
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
||||||
import com.dfsek.terra.commands.profiler.ProfileCommand;
|
import com.dfsek.terra.commands.profiler.ProfileCommand;
|
||||||
|
|
||||||
|
|
||||||
public final class CommandUtil {
|
public final class CommandUtil {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(CommandUtil.class);
|
||||||
public static void registerAll(CommandManager manager) throws MalformedCommandException {
|
public static void registerAll(CommandManager manager) throws MalformedCommandException {
|
||||||
|
logger.info("Registering Terra commands...");
|
||||||
manager.register("profile", ProfileCommand.class);
|
manager.register("profile", ProfileCommand.class);
|
||||||
manager.register("reload", ReloadCommand.class);
|
manager.register("reload", ReloadCommand.class);
|
||||||
manager.register("addons", AddonsCommand.class);
|
manager.register("addons", AddonsCommand.class);
|
||||||
manager.register("version", VersionCommand.class);
|
manager.register("version", VersionCommand.class);
|
||||||
manager.register("getblock", GetBlockCommand.class);
|
manager.register("getblock", GetBlockCommand.class);
|
||||||
manager.register("packs", PacksCommand.class);
|
manager.register("packs", PacksCommand.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class PacksCommand implements CommandTemplate {
|
|||||||
public void execute(CommandSender sender) {
|
public void execute(CommandSender sender) {
|
||||||
CheckedRegistry<ConfigPack> registry = platform.getConfigRegistry();
|
CheckedRegistry<ConfigPack> registry = platform.getConfigRegistry();
|
||||||
|
|
||||||
if(registry.entries().size() == 0) {
|
if(registry.entries().isEmpty()) {
|
||||||
LangUtil.send("command.packs.none", sender);
|
LangUtil.send("command.packs.none", sender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.commands;
|
package com.dfsek.terra.commands;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
import com.dfsek.terra.api.command.CommandTemplate;
|
import com.dfsek.terra.api.command.CommandTemplate;
|
||||||
import com.dfsek.terra.api.command.annotation.Command;
|
import com.dfsek.terra.api.command.annotation.Command;
|
||||||
@@ -29,15 +32,20 @@ import com.dfsek.terra.config.lang.LangUtil;
|
|||||||
usage = "/terra reload"
|
usage = "/terra reload"
|
||||||
)
|
)
|
||||||
public class ReloadCommand implements CommandTemplate {
|
public class ReloadCommand implements CommandTemplate {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ReloadCommand.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Platform platform;
|
private Platform platform;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender) {
|
public void execute(CommandSender sender) {
|
||||||
if(!platform.reload()) {
|
logger.info("Reloading Terra...");
|
||||||
LangUtil.send("command.reload-error", sender);
|
if(platform.reload()) {
|
||||||
} else {
|
logger.info("Terra reloaded successfully.");
|
||||||
LangUtil.send("command.reload", sender);
|
LangUtil.send("command.reload", sender);
|
||||||
|
} else {
|
||||||
|
logger.warn("Terra failed to reload.");
|
||||||
|
LangUtil.send("command.reload-error", sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.commands.profiler;
|
package com.dfsek.terra.commands.profiler;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
import com.dfsek.terra.api.command.CommandTemplate;
|
import com.dfsek.terra.api.command.CommandTemplate;
|
||||||
import com.dfsek.terra.api.command.annotation.Command;
|
import com.dfsek.terra.api.command.annotation.Command;
|
||||||
@@ -28,6 +31,8 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
|||||||
@Command
|
@Command
|
||||||
@DebugCommand
|
@DebugCommand
|
||||||
public class ProfileQueryCommand implements CommandTemplate {
|
public class ProfileQueryCommand implements CommandTemplate {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ProfileQueryCommand.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Platform platform;
|
private Platform platform;
|
||||||
|
|
||||||
@@ -35,7 +40,7 @@ public class ProfileQueryCommand implements CommandTemplate {
|
|||||||
public void execute(CommandSender sender) {
|
public void execute(CommandSender sender) {
|
||||||
StringBuilder data = new StringBuilder("Terra Profiler data dump: \n");
|
StringBuilder data = new StringBuilder("Terra Profiler data dump: \n");
|
||||||
platform.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n'));
|
platform.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n'));
|
||||||
platform.logger().info(data.toString());
|
logger.info(data.toString());
|
||||||
sender.sendMessage("Profiler data dumped to console.");
|
sender.sendMessage("Profiler data dumped to console.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import com.dfsek.tectonic.config.ConfigTemplate;
|
|||||||
import com.dfsek.tectonic.exception.ConfigException;
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -31,18 +33,19 @@ import java.io.UncheckedIOException;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
import com.dfsek.terra.api.util.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("FieldMayBeFinal")
|
@SuppressWarnings("FieldMayBeFinal")
|
||||||
public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.config.PluginConfig {
|
public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.config.PluginConfig {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PluginConfigImpl.class);
|
||||||
|
|
||||||
@Value("debug.commands")
|
@Value("debug.commands")
|
||||||
@Default
|
@Default
|
||||||
private boolean debugCommands = false;
|
private boolean debugCommands = false;
|
||||||
|
|
||||||
@Value("debug.log")
|
@Value("debug.log")
|
||||||
@Default
|
@Default
|
||||||
private boolean debugLog = false;
|
private boolean debugLog = false; // TODO: 2021-08-30 remove me
|
||||||
|
|
||||||
@Value("debug.profiler")
|
@Value("debug.profiler")
|
||||||
@Default
|
@Default
|
||||||
@@ -94,20 +97,20 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(Platform platform) {
|
public void load(Platform platform) {
|
||||||
Logger logger = platform.logger();
|
logger.info("Loading config values from config.yml");
|
||||||
logger.info("Loading config values");
|
|
||||||
try(FileInputStream file = new FileInputStream(new File(platform.getDataFolder(), "config.yml"))) {
|
try(FileInputStream file = new FileInputStream(new File(platform.getDataFolder(), "config.yml"))) {
|
||||||
ConfigLoader loader = new ConfigLoader();
|
ConfigLoader loader = new ConfigLoader();
|
||||||
loader.load(this, new YamlConfiguration(file, "config.yml"));
|
loader.load(this, new YamlConfiguration(file, "config.yml"));
|
||||||
} catch(ConfigException | IOException | UncheckedIOException e) {
|
} catch(ConfigException | IOException | UncheckedIOException e) {
|
||||||
logger.severe("Failed to load config");
|
logger.error("Failed to load config", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isDebugCommands()) logger.info("Debug commands enabled.");
|
if(debugCommands)
|
||||||
if(isDebugLogging()) logger.info("Debug logging enabled.");
|
logger.info("Debug commands enabled.");
|
||||||
if(isDebugProfiler()) logger.info("Debug profiler enabled.");
|
if(debugProfiler)
|
||||||
if(isDebugScript()) logger.info("Script debug blocks enabled.");
|
logger.info("Debug profiler enabled.");
|
||||||
|
if(debugScript)
|
||||||
|
logger.info("Script debug blocks enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+7
-2
@@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.config.fileloaders;
|
package com.dfsek.terra.config.fileloaders;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@@ -31,6 +34,8 @@ import java.util.stream.Stream;
|
|||||||
* Load all {@code *.yml} files from a {@link java.nio.file.Path}.
|
* Load all {@code *.yml} files from a {@link java.nio.file.Path}.
|
||||||
*/
|
*/
|
||||||
public class FolderLoader extends LoaderImpl {
|
public class FolderLoader extends LoaderImpl {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FolderLoader.class);
|
||||||
|
|
||||||
private final Path path;
|
private final Path path;
|
||||||
|
|
||||||
public FolderLoader(Path path) {
|
public FolderLoader(Path path) {
|
||||||
@@ -51,11 +56,11 @@ public class FolderLoader extends LoaderImpl {
|
|||||||
String rel = newPath.toPath().relativize(file).toString();
|
String rel = newPath.toPath().relativize(file).toString();
|
||||||
streams.put(rel, new FileInputStream(file.toFile()));
|
streams.put(rel, new FileInputStream(file.toFile()));
|
||||||
} catch(FileNotFoundException e) {
|
} catch(FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
logger.error("Could not find file to load", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error while loading files", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -18,6 +18,8 @@
|
|||||||
package com.dfsek.terra.config.fileloaders;
|
package com.dfsek.terra.config.fileloaders;
|
||||||
|
|
||||||
import com.dfsek.tectonic.exception.ConfigException;
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -32,6 +34,8 @@ import com.dfsek.terra.api.config.Loader;
|
|||||||
|
|
||||||
|
|
||||||
public abstract class LoaderImpl implements Loader {
|
public abstract class LoaderImpl implements Loader {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(LoaderImpl.class);
|
||||||
|
|
||||||
protected final Map<String, InputStream> streams = new HashMap<>();
|
protected final Map<String, InputStream> streams = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -54,7 +58,7 @@ public abstract class LoaderImpl implements Loader {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LoaderImpl open(String directory, String extension) {
|
public LoaderImpl open(String directory, String extension) {
|
||||||
if(streams.size() != 0) throw new IllegalStateException("Attempted to load new directory before closing existing InputStreams");
|
if(!streams.isEmpty()) throw new IllegalStateException("Attempted to load new directory before closing existing InputStreams");
|
||||||
load(directory, extension);
|
load(directory, extension);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -68,7 +72,7 @@ public abstract class LoaderImpl implements Loader {
|
|||||||
try {
|
try {
|
||||||
input.close();
|
input.close();
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error occurred while loading", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
streams.clear();
|
streams.clear();
|
||||||
|
|||||||
+6
-1
@@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.config.fileloaders;
|
package com.dfsek.terra.config.fileloaders;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
@@ -25,6 +28,8 @@ import java.util.zip.ZipFile;
|
|||||||
|
|
||||||
|
|
||||||
public class ZIPLoader extends LoaderImpl {
|
public class ZIPLoader extends LoaderImpl {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ZIPLoader.class);
|
||||||
|
|
||||||
private final ZipFile file;
|
private final ZipFile file;
|
||||||
|
|
||||||
public ZIPLoader(ZipFile file) {
|
public ZIPLoader(ZipFile file) {
|
||||||
@@ -50,7 +55,7 @@ public class ZIPLoader extends LoaderImpl {
|
|||||||
String rel = entry.getName().substring(directory.length());
|
String rel = entry.getName().substring(directory.length());
|
||||||
streams.put(rel, file.getInputStream(entry));
|
streams.put(rel, file.getInputStream(entry));
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error while loading file from zip", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,38 +17,46 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.config.lang;
|
package com.dfsek.terra.config.lang;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
import com.dfsek.terra.api.entity.CommandSender;
|
import com.dfsek.terra.api.entity.CommandSender;
|
||||||
import com.dfsek.terra.api.lang.Language;
|
import com.dfsek.terra.api.lang.Language;
|
||||||
import com.dfsek.terra.api.util.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
public final class LangUtil {
|
public final class LangUtil {
|
||||||
private static Language language;
|
private static final Logger logger = LoggerFactory.getLogger(LangUtil.class);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static Language LANGUAGE = null;
|
||||||
|
|
||||||
|
private LangUtil() { }
|
||||||
|
|
||||||
public static void load(String langID, Platform platform) {
|
public static void load(String langID, Platform platform) {
|
||||||
Logger logger = platform.logger();
|
|
||||||
File file = new File(platform.getDataFolder(), "lang");
|
File file = new File(platform.getDataFolder(), "lang");
|
||||||
try {
|
try {
|
||||||
File file1 = new File(file, langID + ".yml");
|
File file1 = new File(file, langID + ".yml");
|
||||||
logger.info(file1.getAbsolutePath());
|
logger.info(file1.getAbsolutePath());
|
||||||
language = new LanguageImpl(file1);
|
LANGUAGE = new LanguageImpl(file1);
|
||||||
logger.info("Loaded language " + langID);
|
logger.info("Loaded language {}", langID);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
logger.severe("Unable to load language: " + langID);
|
logger.error("Unable to load language: {}.\nDouble-check your configuration before reporting this to Terra!", langID, e);
|
||||||
e.printStackTrace();
|
|
||||||
logger.severe("Double-check your configuration before reporting this to Terra!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static Language getLanguage() {
|
public static Language getLanguage() {
|
||||||
return language;
|
return Objects.requireNonNull(LANGUAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void send(String messageID, CommandSender sender, String... args) {
|
public static void send(String messageID, CommandSender sender, String... args) {
|
||||||
language.getMessage(messageID).send(sender, args);
|
Objects.requireNonNull(LANGUAGE).getMessage(messageID).send(sender, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-27
@@ -30,6 +30,8 @@ import com.dfsek.tectonic.loading.TypeLoader;
|
|||||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -96,6 +98,8 @@ import com.dfsek.terra.registry.config.ConfigTypeRegistry;
|
|||||||
* Represents a Terra configuration pack.
|
* Represents a Terra configuration pack.
|
||||||
*/
|
*/
|
||||||
public class ConfigPackImpl implements ConfigPack {
|
public class ConfigPackImpl implements ConfigPack {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ConfigPackImpl.class);
|
||||||
|
|
||||||
private final ConfigPackTemplate template = new ConfigPackTemplate();
|
private final ConfigPackTemplate template = new ConfigPackTemplate();
|
||||||
|
|
||||||
private final RegistryFactory registryFactory = new RegistryFactoryImpl();
|
private final RegistryFactory registryFactory = new RegistryFactoryImpl();
|
||||||
@@ -146,18 +150,18 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
|
|
||||||
selfLoader.load(template, configuration);
|
selfLoader.load(template, configuration);
|
||||||
|
|
||||||
platform.logger().info("Loading config pack \"" + template.getID() + "\"");
|
logger.info("Loading config pack \"{}\"", template.getID());
|
||||||
load(l, platform);
|
load(l, platform);
|
||||||
|
|
||||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||||
selfLoader.load(packPostTemplate, configuration);
|
selfLoader.load(packPostTemplate, configuration);
|
||||||
seededBiomeProvider = packPostTemplate.getProviderBuilder();
|
seededBiomeProvider = packPostTemplate.getProviderBuilder();
|
||||||
checkDeadEntries(platform);
|
checkDeadEntries();
|
||||||
} catch(FileNotFoundException e) {
|
} catch(FileNotFoundException e) {
|
||||||
throw new LoadException("No pack.yml file found in " + folder.getAbsolutePath(), e);
|
throw new LoadException("No pack.yml file found in " + folder.getAbsolutePath(), e);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
platform.logger().severe("Failed to load config pack from folder \"" + folder.getAbsolutePath() + "\"");
|
logger.error("Failed to load config pack from folder \"{}\"", folder.getAbsolutePath(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
toWorldConfig(new DummyWorld()); // Build now to catch any errors immediately.
|
toWorldConfig(new DummyWorld()); // Build now to catch any errors immediately.
|
||||||
@@ -197,7 +201,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
|
|
||||||
|
|
||||||
selfLoader.load(template, configuration);
|
selfLoader.load(template, configuration);
|
||||||
platform.logger().info("Loading config pack \"" + template.getID() + "\"");
|
logger.info("Loading config pack \"" + template.getID() + "\"");
|
||||||
|
|
||||||
load(l, platform);
|
load(l, platform);
|
||||||
|
|
||||||
@@ -205,12 +209,12 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
|
|
||||||
selfLoader.load(packPostTemplate, configuration);
|
selfLoader.load(packPostTemplate, configuration);
|
||||||
seededBiomeProvider = packPostTemplate.getProviderBuilder();
|
seededBiomeProvider = packPostTemplate.getProviderBuilder();
|
||||||
checkDeadEntries(platform);
|
checkDeadEntries();
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
throw new LoadException("Unable to load pack.yml from ZIP file", e);
|
throw new LoadException("Unable to load pack.yml from ZIP file", e);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
platform.logger().severe("Failed to load config pack from ZIP archive \"" + file.getName() + "\"");
|
logger.error("Failed to load config pack from ZIP archive \"{}\"", file.getName());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,16 +305,14 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
OpenRegistry<T> registry = new OpenRegistryImpl<>();
|
OpenRegistry<T> registry = new OpenRegistryImpl<>();
|
||||||
selfLoader.registerLoader(c, registry);
|
selfLoader.registerLoader(c, registry);
|
||||||
abstractConfigLoader.registerLoader(c, registry);
|
abstractConfigLoader.registerLoader(c, registry);
|
||||||
platform.getDebugLogger().info("Registered loader for registry of class " + ReflectionUtil.typeToString(c));
|
logger.debug("Registered loader for registry of class {}", ReflectionUtil.typeToString(c));
|
||||||
|
|
||||||
if(type instanceof ParameterizedType) {
|
if(type instanceof ParameterizedType param) {
|
||||||
ParameterizedType param = (ParameterizedType) type;
|
|
||||||
Type base = param.getRawType();
|
Type base = param.getRawType();
|
||||||
if(base instanceof Class // should always be true but we'll check anyways
|
if(base instanceof Class // should always be true but we'll check anyways
|
||||||
&& Supplier.class.isAssignableFrom((Class<?>) base)) { // If it's a supplier
|
&& Supplier.class.isAssignableFrom((Class<?>) base)) { // If it's a supplier
|
||||||
Type supplied = param.getActualTypeArguments()[0]; // Grab the supplied type
|
Type supplied = param.getActualTypeArguments()[0]; // Grab the supplied type
|
||||||
if(supplied instanceof ParameterizedType) {
|
if(supplied instanceof ParameterizedType suppliedParam) {
|
||||||
ParameterizedType suppliedParam = (ParameterizedType) supplied;
|
|
||||||
Type suppliedBase = suppliedParam.getRawType();
|
Type suppliedBase = suppliedParam.getRawType();
|
||||||
if(suppliedBase instanceof Class // should always be true but we'll check anyways
|
if(suppliedBase instanceof Class // should always be true but we'll check anyways
|
||||||
&& ObjectTemplate.class.isAssignableFrom((Class<?>) suppliedBase)) {
|
&& ObjectTemplate.class.isAssignableFrom((Class<?>) suppliedBase)) {
|
||||||
@@ -319,8 +321,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
(Registry<Supplier<ObjectTemplate<Supplier<ObjectTemplate<?>>>>>) registry);
|
(Registry<Supplier<ObjectTemplate<Supplier<ObjectTemplate<?>>>>>) registry);
|
||||||
selfLoader.registerLoader(templateType, loader);
|
selfLoader.registerLoader(templateType, loader);
|
||||||
abstractConfigLoader.registerLoader(templateType, loader);
|
abstractConfigLoader.registerLoader(templateType, loader);
|
||||||
platform.getDebugLogger().info(
|
logger.debug("Registered template loader for registry of class {}", ReflectionUtil.typeToString(templateType));
|
||||||
"Registered template loader for registry of class " + ReflectionUtil.typeToString(templateType));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,7 +373,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
if(registryMap.containsKey(configType.getTypeKey()
|
if(registryMap.containsKey(configType.getTypeKey()
|
||||||
.getType())) { // Someone already registered something; we need to copy things to the
|
.getType())) { // Someone already registered something; we need to copy things to the
|
||||||
// new registry.
|
// new registry.
|
||||||
platform.getDebugLogger().warning("Copying values from old registry for " + configType.getTypeKey());
|
logger.warn("Copying values from old registry for {}", configType.getTypeKey());
|
||||||
registryMap.get(configType.getTypeKey().getType()).getLeft().forEach(((OpenRegistry<Object>) openRegistry)::register);
|
registryMap.get(configType.getTypeKey().getType()).getLeft().forEach(((OpenRegistry<Object>) openRegistry)::register);
|
||||||
}
|
}
|
||||||
selfLoader.registerLoader(configType.getTypeKey().getType(), openRegistry);
|
selfLoader.registerLoader(configType.getTypeKey().getType(), openRegistry);
|
||||||
@@ -381,16 +382,10 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkDeadEntries(Platform platform) {
|
private void checkDeadEntries() {
|
||||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft()).getDeadEntries()
|
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft())
|
||||||
.forEach((id, value) -> platform.getDebugLogger()
|
.getDeadEntries()
|
||||||
.warning(
|
.forEach((id, value) -> logger.warn("Dead entry in '{}' registry: '{}'", ReflectionUtil.typeToString(clazz), id)));
|
||||||
"Dead entry in" +
|
|
||||||
" '" +
|
|
||||||
ReflectionUtil.typeToString(
|
|
||||||
clazz) +
|
|
||||||
"' registry: '" +
|
|
||||||
id + "'")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
@@ -454,9 +449,8 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
platform.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
platform.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||||
platform.logger().info(
|
logger.info("Loaded config pack \"{}\" v{} by {} in {}ms.",
|
||||||
"Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " +
|
template.getID(), template.getVersion(), template.getAuthor(), (System.nanoTime() - start) / 1000000.0D);
|
||||||
(System.nanoTime() - start) / 1000000D + "ms.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<Type, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> getRegistryMap() {
|
protected Map<Type, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> getRegistryMap() {
|
||||||
|
|||||||
+1
-2
@@ -38,8 +38,7 @@ public class MetaStringPreprocessor extends MetaPreprocessor<Meta> {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public @NotNull <T> Result<T> process(AnnotatedType t, T c, ConfigLoader loader, Meta annotation) {
|
public @NotNull <T> Result<T> process(AnnotatedType t, T c, ConfigLoader loader, Meta annotation) {
|
||||||
if(String.class.equals(t.getType()) && c instanceof String) { // String is final so we use #equals
|
if(String.class.equals(t.getType()) && c instanceof String candidate) { // String is final so we use #equals
|
||||||
String candidate = (String) c;
|
|
||||||
StringSubstitutor substitutor = new StringSubstitutor(key -> {
|
StringSubstitutor substitutor = new StringSubstitutor(key -> {
|
||||||
Object meta = getMetaValue(key);
|
Object meta = getMetaValue(key);
|
||||||
if(!(meta instanceof String) && !(meta instanceof Number) && !(meta instanceof Character) && !(meta instanceof Boolean)) {
|
if(!(meta instanceof String) && !(meta instanceof Number) && !(meta instanceof Character) && !(meta instanceof Boolean)) {
|
||||||
|
|||||||
+10
-9
@@ -17,8 +17,9 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.event;
|
package com.dfsek.terra.event;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import org.slf4j.Logger;
|
||||||
import java.io.StringWriter;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -38,6 +39,8 @@ import com.dfsek.terra.api.util.reflection.TypeKey;
|
|||||||
|
|
||||||
|
|
||||||
public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FunctionalEventHandlerImpl.class);
|
||||||
|
|
||||||
private final Map<Type, List<EventContextImpl<?>>> contextMap = new HashMap<>();
|
private final Map<Type, List<EventContextImpl<?>>> contextMap = new HashMap<>();
|
||||||
|
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
@@ -59,13 +62,11 @@ public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
|||||||
((EventContextImpl<Event>) context).handle(event);
|
((EventContextImpl<Event>) context).handle(event);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
if(context.isFailThrough() && event instanceof FailThroughEvent) throw e; // Rethrow if it's fail-through.
|
if(context.isFailThrough() && event instanceof FailThroughEvent)
|
||||||
StringWriter writer = new StringWriter();
|
throw e; // Rethrow if it's fail-through.
|
||||||
e.printStackTrace(new PrintWriter(writer));
|
// else warn
|
||||||
platform.logger().warning("Exception occurred during event handling:");
|
logger.warn("Exception occurred during event handling. Report this to the maintainers of {}@{}",
|
||||||
platform.logger().warning(writer.toString());
|
context.getAddon().getID(), context.getAddon().getVersion().getFormatted(), e);
|
||||||
platform.logger().warning(
|
|
||||||
"Report this to the maintainers of " + context.getAddon().getID());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.profiler;
|
package com.dfsek.terra.profiler;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -30,6 +33,8 @@ import com.dfsek.terra.profiler.exception.MalformedStackException;
|
|||||||
|
|
||||||
|
|
||||||
public class ProfilerImpl implements Profiler {
|
public class ProfilerImpl implements Profiler {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ProfilerImpl.class);
|
||||||
|
|
||||||
private static final ThreadLocal<Stack<Frame>> THREAD_STACK = ThreadLocal.withInitial(Stack::new);
|
private static final ThreadLocal<Stack<Frame>> THREAD_STACK = ThreadLocal.withInitial(Stack::new);
|
||||||
private static final ThreadLocal<Map<String, List<Long>>> TIMINGS = ThreadLocal.withInitial(HashMap::new);
|
private static final ThreadLocal<Map<String, List<Long>>> TIMINGS = ThreadLocal.withInitial(HashMap::new);
|
||||||
private static final ThreadLocal<Boolean> SAFE = ThreadLocal.withInitial(() -> false);
|
private static final ThreadLocal<Boolean> SAFE = ThreadLocal.withInitial(() -> false);
|
||||||
@@ -39,7 +44,8 @@ public class ProfilerImpl implements Profiler {
|
|||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
|
|
||||||
public ProfilerImpl() {
|
public ProfilerImpl() {
|
||||||
if(instantiated) throw new IllegalStateException("Only one instance of Profiler may exist!");
|
if(instantiated)
|
||||||
|
throw new IllegalStateException("Only one instance of Profiler may exist!");
|
||||||
instantiated = true;
|
instantiated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,14 +68,14 @@ public class ProfilerImpl implements Profiler {
|
|||||||
|
|
||||||
Map<String, List<Long>> timingsMap = TIMINGS.get();
|
Map<String, List<Long>> timingsMap = TIMINGS.get();
|
||||||
|
|
||||||
if(timingsMap.size() == 0) {
|
if(timingsMap.isEmpty()) {
|
||||||
synchronized(accessibleThreadMaps) {
|
synchronized(accessibleThreadMaps) {
|
||||||
accessibleThreadMaps.add(timingsMap);
|
accessibleThreadMaps.add(timingsMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Frame top = stack.pop();
|
Frame top = stack.pop();
|
||||||
if(stack.size() != 0 ? !top.getId().endsWith("." + frame) : !top.getId().equals(frame))
|
if(!stack.isEmpty() ? !top.getId().endsWith("." + frame) : !top.getId().equals(frame))
|
||||||
throw new MalformedStackException("Expected " + frame + ", found " + top);
|
throw new MalformedStackException("Expected " + frame + ", found " + top);
|
||||||
|
|
||||||
List<Long> timings = timingsMap.computeIfAbsent(top.getId(), id -> new ArrayList<>());
|
List<Long> timings = timingsMap.computeIfAbsent(top.getId(), id -> new ArrayList<>());
|
||||||
@@ -81,16 +87,19 @@ public class ProfilerImpl implements Profiler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
|
logger.info("Starting Terra profiler");
|
||||||
running = true;
|
running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
logger.info("Stopping Terra profiler");
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
logger.info("Resetting Terra profiler");
|
||||||
accessibleThreadMaps.forEach(Map::clear);
|
accessibleThreadMaps.forEach(Map::clear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.registry.config;
|
package com.dfsek.terra.registry.config;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@@ -27,6 +30,8 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
|||||||
|
|
||||||
|
|
||||||
public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
|
public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ConfigTypeRegistry.class);
|
||||||
|
|
||||||
private final BiConsumer<String, ConfigType<?, ?>> callback;
|
private final BiConsumer<String, ConfigType<?, ?>> callback;
|
||||||
|
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
@@ -40,7 +45,7 @@ public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean register(String identifier, Entry<ConfigType<?, ?>> value) {
|
public boolean register(String identifier, Entry<ConfigType<?, ?>> value) {
|
||||||
callback.accept(identifier, value.getValue());
|
callback.accept(identifier, value.getValue());
|
||||||
platform.getDebugLogger().info("Registered config registry with ID " + identifier + " to type " +
|
logger.debug("Registered config registry with ID {} to type {}", identifier,
|
||||||
ReflectionUtil.typeToString(value.getValue().getTypeKey().getType()));
|
ReflectionUtil.typeToString(value.getValue().getTypeKey().getType()));
|
||||||
return super.register(identifier, value);
|
return super.register(identifier, value);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -18,6 +18,8 @@
|
|||||||
package com.dfsek.terra.registry.master;
|
package com.dfsek.terra.registry.master;
|
||||||
|
|
||||||
import com.dfsek.tectonic.exception.ConfigException;
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -33,6 +35,8 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
|||||||
* Class to hold config packs
|
* Class to hold config packs
|
||||||
*/
|
*/
|
||||||
public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ConfigRegistry.class);
|
||||||
|
|
||||||
public void load(File folder, Platform platform) throws ConfigException {
|
public void load(File folder, Platform platform) throws ConfigException {
|
||||||
ConfigPack pack = new ConfigPackImpl(folder, platform);
|
ConfigPack pack = new ConfigPackImpl(folder, platform);
|
||||||
register(pack.getID(), pack);
|
register(pack.getID(), pack);
|
||||||
@@ -46,16 +50,16 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
|||||||
try {
|
try {
|
||||||
load(dir, platform);
|
load(dir, platform);
|
||||||
} catch(ConfigException e) {
|
} catch(ConfigException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error loading config pack {}", dir.getName(), e);
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".terra"))) {
|
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".terra"))) {
|
||||||
try {
|
try {
|
||||||
platform.getDebugLogger().info("Loading ZIP archive: " + zip.getName());
|
logger.info("Loading ZIP archive: " + zip.getName());
|
||||||
load(new ZipFile(zip), platform);
|
load(new ZipFile(zip), platform);
|
||||||
} catch(IOException | ConfigException e) {
|
} catch(IOException | ConfigException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error loading config pack {}", zip.getName(), e);
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Terra.
|
|
||||||
*
|
|
||||||
* Terra is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Terra is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.dfsek.terra.util.logging;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.util.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
public class DebugLogger implements Logger {
|
|
||||||
private final Logger logger;
|
|
||||||
private boolean debug = false;
|
|
||||||
|
|
||||||
public DebugLogger(Logger logger) {
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void info(String message) {
|
|
||||||
if(debug) logger.info(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void warning(String message) {
|
|
||||||
if(debug) logger.warning(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void severe(String message) {
|
|
||||||
if(debug) logger.severe(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stack(Throwable e) {
|
|
||||||
if(debug) e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDebug() {
|
|
||||||
return debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDebug(boolean debug) {
|
|
||||||
this.debug = debug;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Terra.
|
|
||||||
*
|
|
||||||
* Terra is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Terra is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.dfsek.terra.util.logging;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.util.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
public class JavaLogger implements Logger {
|
|
||||||
private final java.util.logging.Logger logger;
|
|
||||||
|
|
||||||
public JavaLogger(java.util.logging.Logger logger) {
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void info(String message) {
|
|
||||||
logger.info(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warning(String message) {
|
|
||||||
logger.warning(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void severe(String message) {
|
|
||||||
logger.severe(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,11 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.addon;
|
package com.dfsek.terra.addon;
|
||||||
|
|
||||||
|
import ca.solostudios.strata.Versions;
|
||||||
|
import ca.solostudios.strata.version.Version;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@@ -26,31 +31,29 @@ import java.nio.file.Path;
|
|||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import ca.solostudios.strata.Versions;
|
|
||||||
import ca.solostudios.strata.version.Version;
|
|
||||||
|
|
||||||
import com.dfsek.terra.addon.exception.AddonLoadException;
|
import com.dfsek.terra.addon.exception.AddonLoadException;
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
|
import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
|
||||||
|
|
||||||
|
|
||||||
public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAddon<?>> {
|
public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAddon<?>> {
|
||||||
private final Platform platform;
|
private static final Logger logger = LoggerFactory.getLogger(BootstrapAddonLoader.class);
|
||||||
|
|
||||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||||
|
|
||||||
|
private final Platform platform;
|
||||||
|
|
||||||
public BootstrapAddonLoader(Platform platform) { this.platform = platform; }
|
public BootstrapAddonLoader(Platform platform) { this.platform = platform; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<BootstrapBaseAddon<?>> loadAddons(Path addonsFolder, ClassLoader parent) {
|
public Iterable<BootstrapBaseAddon<?>> loadAddons(Path addonsFolder, ClassLoader parent) {
|
||||||
Path bootstrapAddons = addonsFolder.resolve("bootstrap");
|
Path bootstrapAddons = addonsFolder.resolve("bootstrap");
|
||||||
platform.logger().info("Loading bootstrap addons from " + bootstrapAddons);
|
logger.info("Loading bootstrap addons from {}", bootstrapAddons);
|
||||||
try {
|
try {
|
||||||
return Files.walk(bootstrapAddons, 1)
|
return Files.walk(bootstrapAddons, 1)
|
||||||
.filter(path -> path.toFile().isFile() && path.toString().endsWith(".jar"))
|
.filter(path -> path.toFile().isFile() && path.toString().endsWith(".jar"))
|
||||||
.map(path -> {
|
.map(path -> {
|
||||||
try {
|
try {
|
||||||
platform.logger().info("Loading bootstrap addon from JAR " + path);
|
logger.info("Loading bootstrap addon from JAR {}", path);
|
||||||
JarFile jar = new JarFile(path.toFile());
|
JarFile jar = new JarFile(path.toFile());
|
||||||
String entry = jar.getManifest().getMainAttributes().getValue("Bootstrap-Addon-Entry-Point");
|
String entry = jar.getManifest().getMainAttributes().getValue("Bootstrap-Addon-Entry-Point");
|
||||||
|
|
||||||
@@ -65,7 +68,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
|||||||
if(!(in instanceof BootstrapBaseAddon)) {
|
if(!(in instanceof BootstrapBaseAddon)) {
|
||||||
throw new AddonLoadException(in.getClass() + " does not extend " + BootstrapBaseAddon.class);
|
throw new AddonLoadException(in.getClass() + " does not extend " + BootstrapBaseAddon.class);
|
||||||
}
|
}
|
||||||
platform.logger().info("Loaded bootstrap addon " + ((BootstrapBaseAddon<?>) in).getID());
|
logger.info("Loaded bootstrap addon {}", ((BootstrapBaseAddon<?>) in).getID());
|
||||||
return (BootstrapBaseAddon<?>) in;
|
return (BootstrapBaseAddon<?>) in;
|
||||||
} catch(InvocationTargetException e) {
|
} catch(InvocationTargetException e) {
|
||||||
throw new AddonLoadException("Exception occurred while instantiating addon: ", e);
|
throw new AddonLoadException("Exception occurred while instantiating addon: ", e);
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ val purpurURL = "https://ci.pl3x.net/job/Purpur/lastSuccessfulBuild/artifact/fin
|
|||||||
dependencies {
|
dependencies {
|
||||||
"shadedApi"(project(":common:implementation"))
|
"shadedApi"(project(":common:implementation"))
|
||||||
|
|
||||||
|
shadedImplementation("org.slf4j:slf4j-log4j12:1.7.32")
|
||||||
|
// "shadedImplementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
|
||||||
|
|
||||||
"compileOnly"("io.papermc.paper:paper-api:1.17-R0.1-SNAPSHOT")
|
"compileOnly"("io.papermc.paper:paper-api:1.17-R0.1-SNAPSHOT")
|
||||||
"shadedImplementation"("io.papermc:paperlib:1.0.5")
|
"shadedImplementation"("io.papermc:paperlib:1.0.5")
|
||||||
|
|
||||||
@@ -179,6 +182,7 @@ tasks.named<ShadowJar>("shadowJar") {
|
|||||||
relocate("org.bstats.bukkit", "com.dfsek.terra.lib.bstats")
|
relocate("org.bstats.bukkit", "com.dfsek.terra.lib.bstats")
|
||||||
relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib")
|
relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib")
|
||||||
relocate("com.google.common", "com.dfsek.terra.lib.google.common")
|
relocate("com.google.common", "com.dfsek.terra.lib.google.common")
|
||||||
|
relocate("org.apache.logging.slf4j", "com.dfsek.terra.lib.slf4j-over-log4j")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,15 +26,14 @@ import java.io.File;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import com.dfsek.terra.AbstractPlatform;
|
import com.dfsek.terra.AbstractPlatform;
|
||||||
|
import com.dfsek.terra.api.addon.TerraAddon;
|
||||||
import com.dfsek.terra.api.block.state.BlockState;
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
import com.dfsek.terra.api.handle.ItemHandle;
|
import com.dfsek.terra.api.handle.ItemHandle;
|
||||||
import com.dfsek.terra.api.handle.WorldHandle;
|
import com.dfsek.terra.api.handle.WorldHandle;
|
||||||
import com.dfsek.terra.api.util.Logger;
|
|
||||||
import com.dfsek.terra.api.world.biome.Biome;
|
import com.dfsek.terra.api.world.biome.Biome;
|
||||||
import com.dfsek.terra.bukkit.handles.BukkitItemHandle;
|
import com.dfsek.terra.bukkit.handles.BukkitItemHandle;
|
||||||
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
||||||
import com.dfsek.terra.bukkit.world.BukkitBiome;
|
import com.dfsek.terra.bukkit.world.BukkitBiome;
|
||||||
import com.dfsek.terra.util.logging.JavaLogger;
|
|
||||||
|
|
||||||
|
|
||||||
public class PlatformImpl extends AbstractPlatform {
|
public class PlatformImpl extends AbstractPlatform {
|
||||||
@@ -93,11 +92,6 @@ public class PlatformImpl extends AbstractPlatform {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Logger createLogger() {
|
|
||||||
return new JavaLogger(plugin.getLogger());
|
|
||||||
}
|
|
||||||
|
|
||||||
private BukkitBiome parseBiome(String id) throws LoadException {
|
private BukkitBiome parseBiome(String id) throws LoadException {
|
||||||
if(!id.startsWith("minecraft:")) throw new LoadException("Invalid biome identifier " + id);
|
if(!id.startsWith("minecraft:")) throw new LoadException("Invalid biome identifier " + id);
|
||||||
return new BukkitBiome(org.bukkit.block.Biome.valueOf(id.toUpperCase(Locale.ROOT).substring(10)));
|
return new BukkitBiome(org.bukkit.block.Biome.valueOf(id.toUpperCase(Locale.ROOT).substring(10)));
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.bukkit;
|
package com.dfsek.terra.bukkit;
|
||||||
|
|
||||||
import io.papermc.lib.PaperLib;
|
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
@@ -25,6 +24,8 @@ import org.bukkit.generator.ChunkGenerator;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -42,22 +43,13 @@ import com.dfsek.terra.bukkit.listeners.CommonListener;
|
|||||||
import com.dfsek.terra.bukkit.listeners.PaperListener;
|
import com.dfsek.terra.bukkit.listeners.PaperListener;
|
||||||
import com.dfsek.terra.bukkit.listeners.SpigotListener;
|
import com.dfsek.terra.bukkit.listeners.SpigotListener;
|
||||||
import com.dfsek.terra.bukkit.util.PaperUtil;
|
import com.dfsek.terra.bukkit.util.PaperUtil;
|
||||||
|
import com.dfsek.terra.bukkit.util.VersionUtil;
|
||||||
import com.dfsek.terra.commands.CommandUtil;
|
import com.dfsek.terra.commands.CommandUtil;
|
||||||
import com.dfsek.terra.commands.TerraCommandManager;
|
import com.dfsek.terra.commands.TerraCommandManager;
|
||||||
|
|
||||||
|
|
||||||
public class TerraBukkitPlugin extends JavaPlugin {
|
public class TerraBukkitPlugin extends JavaPlugin {
|
||||||
public static final BukkitVersion BUKKIT_VERSION;
|
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
|
||||||
|
|
||||||
static {
|
|
||||||
String ver = Bukkit.getServer().getClass().getPackage().getName();
|
|
||||||
if(ver.contains("1_17")) BUKKIT_VERSION = BukkitVersion.V1_17;
|
|
||||||
else if(ver.contains("1_16")) BUKKIT_VERSION = BukkitVersion.V1_16;
|
|
||||||
else if(ver.contains("1_15")) BUKKIT_VERSION = BukkitVersion.V1_15;
|
|
||||||
else if(ver.contains("1_14")) BUKKIT_VERSION = BukkitVersion.V1_14;
|
|
||||||
else if(ver.contains("1_13")) BUKKIT_VERSION = BukkitVersion.V1_13;
|
|
||||||
else BUKKIT_VERSION = BukkitVersion.UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final PlatformImpl terraPlugin = new PlatformImpl(this);
|
private final PlatformImpl terraPlugin = new PlatformImpl(this);
|
||||||
private final Map<String, com.dfsek.terra.api.world.generator.ChunkGenerator> generatorMap = new HashMap<>();
|
private final Map<String, com.dfsek.terra.api.world.generator.ChunkGenerator> generatorMap = new HashMap<>();
|
||||||
@@ -70,16 +62,15 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getLogger().info("Running on version " + BUKKIT_VERSION);
|
if(!doVersionCheck()) {
|
||||||
if(BUKKIT_VERSION == BukkitVersion.UNKNOWN) {
|
return;
|
||||||
getLogger().warning("Terra is running on an unknown Bukkit version. Proceed with caution.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
terraPlugin.getEventManager().callEvent(new PlatformInitializationEvent());
|
terraPlugin.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||||
|
|
||||||
new Metrics(this, 9017); // Set up bStats.
|
new Metrics(this, 9017); // Set up bStats.
|
||||||
|
|
||||||
PluginCommand c = Objects.requireNonNull(getCommand("terra"));
|
PluginCommand cmd = Objects.requireNonNull(getCommand("terra"));
|
||||||
|
|
||||||
CommandManager manager = new TerraCommandManager(terraPlugin);
|
CommandManager manager = new TerraCommandManager(terraPlugin);
|
||||||
|
|
||||||
@@ -89,17 +80,20 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
|||||||
manager.register("save-data", SaveDataCommand.class);
|
manager.register("save-data", SaveDataCommand.class);
|
||||||
manager.register("fix-chunk", FixChunkCommand.class);
|
manager.register("fix-chunk", FixChunkCommand.class);
|
||||||
} catch(MalformedCommandException e) { // This should never happen.
|
} catch(MalformedCommandException e) { // This should never happen.
|
||||||
terraPlugin.logger().severe("Errors occurred while registering commands.");
|
logger.error("""
|
||||||
e.printStackTrace();
|
TERRA HAS BEEN DISABLED
|
||||||
terraPlugin.logger().severe("Please report this to Terra.");
|
|
||||||
|
Errors occurred while registering commands.
|
||||||
|
Please report this to Terra.
|
||||||
|
""".strip(), e);
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BukkitCommandAdapter command = new BukkitCommandAdapter(manager);
|
BukkitCommandAdapter command = new BukkitCommandAdapter(manager);
|
||||||
|
|
||||||
c.setExecutor(command);
|
cmd.setExecutor(command);
|
||||||
c.setTabCompleter(command);
|
cmd.setTabCompleter(command);
|
||||||
|
|
||||||
|
|
||||||
long save = terraPlugin.getTerraConfig().getDataSaveInterval();
|
long save = terraPlugin.getTerraConfig().getDataSaveInterval();
|
||||||
@@ -108,20 +102,123 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
|||||||
Bukkit.getPluginManager().registerEvents(new CommonListener(terraPlugin), this); // Register master event listener
|
Bukkit.getPluginManager().registerEvents(new CommonListener(terraPlugin), this); // Register master event listener
|
||||||
PaperUtil.checkPaper(this);
|
PaperUtil.checkPaper(this);
|
||||||
|
|
||||||
if(PaperLib.isPaper()) {
|
|
||||||
try {
|
try {
|
||||||
Class.forName("io.papermc.paper.event.world.StructureLocateEvent"); // Check if user is on Paper version with event.
|
Class.forName("io.papermc.paper.event.world.StructureLocateEvent"); // Check if user is on Paper version with event.
|
||||||
Bukkit.getPluginManager().registerEvents(new PaperListener(terraPlugin), this); // Register Paper events.
|
Bukkit.getPluginManager().registerEvents(new PaperListener(terraPlugin), this); // Register Paper events.
|
||||||
} catch(ClassNotFoundException e) {
|
} catch(ClassNotFoundException e) {
|
||||||
registerSpigotEvents(true); // Outdated Paper version.
|
/*
|
||||||
}
|
The command
|
||||||
|
|
||||||
|
fmt -w 72 -g 72 -u text | \
|
||||||
|
boxes -a cmd -p a1h3 -t 4e -d jstone -s82 | \
|
||||||
|
sed -Ee 's/\+-+\*\//|------------------------------------------------------------------------------|/g' \
|
||||||
|
-e 's/^\s*(.*)$/"\1\\n"/g' -e 's/\///g' -e 's/\*|\+/./g' -e 's/$/ +/g' -e '/^"\| {3}-{72} {3}\|\\n" \+$/d'
|
||||||
|
|
||||||
|
was used to create these boxes. Leaving this here for if we want to create more/modify them.
|
||||||
|
*/
|
||||||
|
if(VersionUtil.getSpigotVersionInfo().isPaper()) { // logging with stack trace to be annoying.
|
||||||
|
logger.warn("""
|
||||||
|
.------------------------------------------------------------------------------.
|
||||||
|
| |
|
||||||
|
| You are using an outdated version of Paper. This version does not |
|
||||||
|
| contain StructureLocateEvent. Terra will now fall back to Spigot |
|
||||||
|
| events. This will prevent cartographer villagers from spawning, |
|
||||||
|
| and cause structure location to not function. If you want these |
|
||||||
|
| functionalities, update to the latest build of Paper. If you use a |
|
||||||
|
| fork, update to the latest version, then if you still receive this |
|
||||||
|
| message, ask the fork developer to update upstream. |
|
||||||
|
| |
|
||||||
|
|------------------------------------------------------------------------------|
|
||||||
|
""".strip(), e);
|
||||||
} else {
|
} else {
|
||||||
registerSpigotEvents(false);
|
logger.warn("""
|
||||||
|
.------------------------------------------------------------------------------.
|
||||||
|
| |
|
||||||
|
| Paper is not in use. Falling back to Spigot events. This will prevent |
|
||||||
|
| cartographer villagers from spawning, and cause structure location to |
|
||||||
|
| not function. If you want these functionalities (and all the other |
|
||||||
|
| benefits that Paper offers), upgrade your server to Paper. Find out |
|
||||||
|
| more at https://papermc.io/ |
|
||||||
|
| |
|
||||||
|
|------------------------------------------------------------------------------|
|
||||||
|
""".strip(), e);
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().registerEvents(new SpigotListener(terraPlugin), this); // Register Spigot event listener
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "deprecation", "AccessOfSystemProperties" })
|
||||||
|
private boolean doVersionCheck() {
|
||||||
|
logger.info("Running on Minecraft version {} with server implementation {}.", VersionUtil.getMinecraftVersionInfo(), Bukkit.getServer().getName());
|
||||||
|
|
||||||
|
if(!VersionUtil.getSpigotVersionInfo().isSpigot())
|
||||||
|
logger.error("YOU ARE RUNNING A CRAFTBUKKIT OR BUKKIT SERVER. PLEASE UPGRADE TO PAPER.");
|
||||||
|
|
||||||
|
if(VersionUtil.getSpigotVersionInfo().isMohist()) {
|
||||||
|
if(System.getProperty("IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways") == null) {
|
||||||
|
Runnable runnable = () -> { // scary big block of text
|
||||||
|
logger.error("""
|
||||||
|
.----------------------------------------------------------------------------------.
|
||||||
|
| |
|
||||||
|
| ⚠ !! Warning !! ⚠ |
|
||||||
|
| |
|
||||||
|
| You are currently using Mohist. |
|
||||||
|
| |
|
||||||
|
| Do not use Mohist. |
|
||||||
|
| |
|
||||||
|
| The concept of combining the rigid Bukkit platform, which assumes a 100% |
|
||||||
|
| Vanilla server, with the flexible Forge platform, which allows changing |
|
||||||
|
| core components of the game, simply does not work. These platforms are |
|
||||||
|
| incompatible at a conceptual level, the only way to combine them would |
|
||||||
|
| be to make incompatible changes to both. As a result, Mohist's Bukkit |
|
||||||
|
| API implementation is not compliant. This will cause many plugins to |
|
||||||
|
| break. Rather than fix their platform, Mohist has chosen to distribute |
|
||||||
|
| unofficial builds of plugins they deem to be "fixed". These builds are not |
|
||||||
|
| "fixed", they are simply hacked together to work with Mohist's half-baked |
|
||||||
|
| Bukkit implementation. To distribute these as "fixed" versions implies that: |
|
||||||
|
| - These builds are endorsed by the original developers. (They are not) |
|
||||||
|
| - The issue is on the plugin's end, not Mohist's. (It is not. The issue |
|
||||||
|
| is that Mohist chooses to not create a compliant Bukkit implementation) |
|
||||||
|
| Please, do not use Mohist. It causes issues with most plugins, and rather |
|
||||||
|
| than fixing their platform, Mohist has chosen to distribute unofficial |
|
||||||
|
| hacked-together builds of plugins, calling them "fixed". If you want |
|
||||||
|
| to use a server API with Forge mods, look at the Sponge project, an |
|
||||||
|
| API that is designed to be implementation-agnostic, with first-party |
|
||||||
|
| support for the Forge mod loader. You are bound to encounter issues if |
|
||||||
|
| you use Terra with Mohist. We will provide NO SUPPORT for servers running |
|
||||||
|
| Mohist. If you wish to proceed anyways, you can add the JVM System Property |
|
||||||
|
| "IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways" to enable the plugin. No |
|
||||||
|
| support will be provided for servers running Mohist. |
|
||||||
|
| |
|
||||||
|
| Because of this **TERRA HAS BEEN DISABLED**. |
|
||||||
|
| Do not come ask us why it is not working. |
|
||||||
|
| |
|
||||||
|
|----------------------------------------------------------------------------------|
|
||||||
|
""".strip());
|
||||||
|
};
|
||||||
|
runnable.run();
|
||||||
|
Bukkit.getScheduler().scheduleAsyncDelayedTask(this, runnable, 200L);
|
||||||
|
// Bukkit.shutdown(); // we're not *that* evil
|
||||||
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
logger.warn("""
|
||||||
|
You are using Mohist, so we will not give you any support for issues that may arise.
|
||||||
|
Since you enabled the "IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways" flag, we won't disable Terra. But be warned.
|
||||||
|
|
||||||
|
> I felt a great disturbance in the JVM, as if millions of plugins suddenly cried out in stack traces and were suddenly silenced.
|
||||||
|
> I fear something terrible has happened.
|
||||||
|
> - Astrash
|
||||||
|
""".strip());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
|
public @Nullable
|
||||||
|
ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
|
||||||
return new BukkitChunkGeneratorWrapper(generatorMap.computeIfAbsent(worldName, name -> {
|
return new BukkitChunkGeneratorWrapper(generatorMap.computeIfAbsent(worldName, name -> {
|
||||||
if(!terraPlugin.getConfigRegistry().contains(id)) throw new IllegalArgumentException("No such config pack \"" + id + "\"");
|
if(!terraPlugin.getConfigRegistry().contains(id)) throw new IllegalArgumentException("No such config pack \"" + id + "\"");
|
||||||
ConfigPack pack = terraPlugin.getConfigRegistry().get(id);
|
ConfigPack pack = terraPlugin.getConfigRegistry().get(id);
|
||||||
@@ -129,58 +226,4 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
|||||||
return pack.getGeneratorProvider().newInstance(pack);
|
return pack.getGeneratorProvider().newInstance(pack);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerSpigotEvents(boolean outdated) {
|
|
||||||
if(outdated) {
|
|
||||||
getLogger().severe("You are using an outdated version of Paper.");
|
|
||||||
getLogger().severe("This version does not contain StructureLocateEvent.");
|
|
||||||
getLogger().severe("Terra will now fall back to Spigot events.");
|
|
||||||
getLogger().severe("This will prevent cartographer villagers from spawning,");
|
|
||||||
getLogger().severe("and cause structure location to not function.");
|
|
||||||
getLogger().severe("If you want these functionalities, update to the latest build of Paper.");
|
|
||||||
getLogger().severe("If you use a fork, update to the latest version, then if you still");
|
|
||||||
getLogger().severe("receive this message, ask the fork developer to update upstream.");
|
|
||||||
} else {
|
|
||||||
getLogger().severe("Paper is not in use. Falling back to Spigot events.");
|
|
||||||
getLogger().severe("This will prevent cartographer villagers from spawning,");
|
|
||||||
getLogger().severe("and cause structure location to not function.");
|
|
||||||
getLogger().severe("If you want these functionalities (and all the other");
|
|
||||||
getLogger().severe("benefits that Paper offers), upgrade your server to Paper.");
|
|
||||||
getLogger().severe("Find out more at https://papermc.io/");
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new SpigotListener(terraPlugin), this); // Register Spigot event listener
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum BukkitVersion {
|
|
||||||
V1_13(13),
|
|
||||||
|
|
||||||
V1_14(14),
|
|
||||||
|
|
||||||
V1_15(15),
|
|
||||||
|
|
||||||
V1_16(16),
|
|
||||||
|
|
||||||
V1_17(17),
|
|
||||||
|
|
||||||
UNKNOWN(Integer.MAX_VALUE); // Assume unknown version is latest.
|
|
||||||
|
|
||||||
private final int index;
|
|
||||||
|
|
||||||
BukkitVersion(int index) {
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets if this version is above or equal to another.
|
|
||||||
*
|
|
||||||
* @param other Other version
|
|
||||||
*
|
|
||||||
* @return Whether this version is equal to or later than other.
|
|
||||||
*/
|
|
||||||
public boolean above(BukkitVersion other) {
|
|
||||||
return this.index >= other.index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -23,6 +23,8 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -37,6 +39,8 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
|||||||
|
|
||||||
|
|
||||||
public class BukkitCommandAdapter implements CommandExecutor, TabCompleter {
|
public class BukkitCommandAdapter implements CommandExecutor, TabCompleter {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(BukkitCommandAdapter.class);
|
||||||
|
|
||||||
private final CommandManager manager;
|
private final CommandManager manager;
|
||||||
|
|
||||||
public BukkitCommandAdapter(CommandManager manager) {
|
public BukkitCommandAdapter(CommandManager manager) {
|
||||||
@@ -68,7 +72,7 @@ public class BukkitCommandAdapter implements CommandExecutor, TabCompleter {
|
|||||||
.filter(s -> s.toLowerCase(Locale.ROOT).startsWith(args[args.length - 1].toLowerCase(Locale.ROOT))).sorted(
|
.filter(s -> s.toLowerCase(Locale.ROOT).startsWith(args[args.length - 1].toLowerCase(Locale.ROOT))).sorted(
|
||||||
String::compareTo).collect(Collectors.toList());
|
String::compareTo).collect(Collectors.toList());
|
||||||
} catch(CommandException e) {
|
} catch(CommandException e) {
|
||||||
e.printStackTrace();
|
logger.warn("Exception occurred during tab completion", e);
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-7
@@ -20,6 +20,8 @@ package com.dfsek.terra.bukkit.generator;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -40,6 +42,7 @@ import com.dfsek.terra.bukkit.world.BukkitBiomeGrid;
|
|||||||
|
|
||||||
|
|
||||||
public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGenerator implements GeneratorWrapper {
|
public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGenerator implements GeneratorWrapper {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(BukkitChunkGeneratorWrapper.class);
|
||||||
|
|
||||||
private static final Map<com.dfsek.terra.api.world.World, PopulationManager> popMap = new HashMap<>();
|
private static final Map<com.dfsek.terra.api.world.World, PopulationManager> popMap = new HashMap<>();
|
||||||
|
|
||||||
@@ -61,17 +64,17 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
|||||||
|
|
||||||
|
|
||||||
public static synchronized void saveAll() {
|
public static synchronized void saveAll() {
|
||||||
for(Map.Entry<com.dfsek.terra.api.world.World, PopulationManager> e : popMap.entrySet()) {
|
for(Map.Entry<com.dfsek.terra.api.world.World, PopulationManager> entry : popMap.entrySet()) {
|
||||||
try {
|
try {
|
||||||
e.getValue().saveBlocks(e.getKey());
|
entry.getValue().saveBlocks(entry.getKey());
|
||||||
} catch(IOException ioException) {
|
} catch(IOException e) {
|
||||||
ioException.printStackTrace();
|
logger.error("Error occurred while saving population manager", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void fixChunk(Chunk c) {
|
public static synchronized void fixChunk(Chunk chunk) {
|
||||||
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
|
popMap.get(chunk.getWorld()).checkNeighbors(chunk.getX(), chunk.getZ(), chunk.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load(com.dfsek.terra.api.world.World w) {
|
private void load(com.dfsek.terra.api.world.World w) {
|
||||||
@@ -80,7 +83,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
|||||||
} catch(FileNotFoundException ignore) {
|
} catch(FileNotFoundException ignore) {
|
||||||
|
|
||||||
} catch(IOException | ClassNotFoundException e) {
|
} catch(IOException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error occurred while loading terra world", e);
|
||||||
}
|
}
|
||||||
popMap.put(w, popMan);
|
popMap.put(w, popMan);
|
||||||
needsLoad = false;
|
needsLoad = false;
|
||||||
|
|||||||
+30
-16
@@ -24,6 +24,8 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
||||||
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
|
|
||||||
@@ -36,6 +38,7 @@ import com.dfsek.terra.api.Platform;
|
|||||||
*/
|
*/
|
||||||
public class SpigotListener implements Listener {
|
public class SpigotListener implements Listener {
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SpigotListener.class);
|
||||||
|
|
||||||
public SpigotListener(Platform platform) {
|
public SpigotListener(Platform platform) {
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
@@ -43,46 +46,57 @@ public class SpigotListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onEnderEye(EntitySpawnEvent e) {
|
public void onEnderEye(EntitySpawnEvent e) {
|
||||||
/*
|
/*
|
||||||
Entity entity = e.getEntity();
|
Entity entity = e.getEntity();
|
||||||
if(e.getEntityType().equals(EntityType.ENDER_SIGNAL)) {
|
if(e.getEntityType() == EntityType.ENDER_SIGNAL) {
|
||||||
main.getDebugLogger().info("Detected Ender Signal...");
|
logger.info("Detected Ender Signal...");
|
||||||
World w = BukkitAdapter.adapt(e.getEntity().getWorld());
|
World w = BukkitAdapter.adapt(e.getEntity().getWorld());
|
||||||
EnderSignal signal = (EnderSignal) entity;
|
EnderSignal signal = (EnderSignal) entity;
|
||||||
ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(w.getConfig().getLocatable().get
|
ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(w.getConfig().getLocatable().get
|
||||||
("STRONGHOLD"));
|
("STRONGHOLD"));
|
||||||
if(config != null) {
|
if(config != null) {
|
||||||
main.getDebugLogger().info("Overriding Ender Signal...");
|
logger.info("Overriding Ender Signal...");
|
||||||
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()
|
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()
|
||||||
.toVector()), tw.getWorld(), 0, 500, location -> {
|
.toVector()), tw.getWorld(), 0, 500, location -> {
|
||||||
if(location != null)
|
if(location != null)
|
||||||
signal.setTargetLocation(BukkitAdapter.adapt(location).toLocation(e.getLocation().getWorld()));
|
signal.setTargetLocation(BukkitAdapter.adapt(location).toLocation(e.getLocation().getWorld()));
|
||||||
main.getDebugLogger().info("Location: " + location);
|
logger.info("Location: {}", location);
|
||||||
}, main);
|
}, main);
|
||||||
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.
|
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.
|
||||||
} else
|
} else
|
||||||
main.logger().warning("No overrides are defined for Strongholds. Ender Signals will not work correctly.");
|
logger.warn("No overrides are defined for Strongholds. Ender Signals will not work correctly.");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onCartographerChange(VillagerAcquireTradeEvent e) {
|
public void onCartographerChange(VillagerAcquireTradeEvent e) {
|
||||||
if(!(e.getEntity() instanceof Villager)) return;
|
if(!(e.getEntity() instanceof Villager))
|
||||||
if(((Villager) e.getEntity()).getProfession().equals(Villager.Profession.CARTOGRAPHER)) {
|
return;
|
||||||
platform.logger().severe("Prevented server crash by stopping Cartographer villager from spawning.");
|
if(((Villager) e.getEntity()).getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||||
platform.logger().severe("Please upgrade to Paper, which has a StructureLocateEvent that fixes this issue");
|
logger.error("""
|
||||||
platform.logger().severe("at the source, and doesn't require us to do stupid band-aids.");
|
.------------------------------------------------------------------------.
|
||||||
|
| Prevented server crash by stopping Cartographer villager from |
|
||||||
|
| spawning. Please upgrade to Paper, which has a StructureLocateEvent |
|
||||||
|
| that fixes this issue at the source, and doesn't require us to do |
|
||||||
|
| stupid band-aids. |
|
||||||
|
|------------------------------------------------------------------------|
|
||||||
|
""".strip());
|
||||||
e.setCancelled(true); // Cancel leveling if the villager is a Cartographer, to prevent crashing server.
|
e.setCancelled(true); // Cancel leveling if the villager is a Cartographer, to prevent crashing server.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onCartographerLevel(VillagerCareerChangeEvent e) {
|
public void onCartographerLevel(VillagerCareerChangeEvent e) {
|
||||||
if(e.getProfession().equals(Villager.Profession.CARTOGRAPHER)) {
|
if(e.getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||||
platform.logger().severe("Prevented server crash by stopping Cartographer villager from spawning.");
|
logger.error("""
|
||||||
platform.logger().severe("Please upgrade to Paper, which has a StructureLocateEvent that fixes this issue");
|
.------------------------------------------------------------------------.
|
||||||
platform.logger().severe("at the source, and doesn't require us to do stupid band-aids.");
|
| Prevented server crash by stopping Cartographer villager from leveling |
|
||||||
|
| up. Please upgrade to Paper, which has a StructureLocateEvent that |
|
||||||
|
| fixes this issue at the source, and doesn't require us to do stupid |
|
||||||
|
| band-aids. |
|
||||||
|
|------------------------------------------------------------------------|
|
||||||
|
""".strip());
|
||||||
e.getEntity().setProfession(Villager.Profession.NITWIT); // Give villager new profession to prevent server crash.
|
e.getEntity().setProfession(Villager.Profession.NITWIT); // Give villager new profession to prevent server crash.
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
package com.dfsek.terra.bukkit.util;
|
||||||
|
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
|
public final class VersionUtil {
|
||||||
|
public static final SpigotVersionInfo SPIGOT_VERSION_INFO;
|
||||||
|
public static final MinecraftVersionInfo MINECRAFT_VERSION_INFO;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(VersionUtil.class);
|
||||||
|
|
||||||
|
static {
|
||||||
|
SPIGOT_VERSION_INFO = new SpigotVersionInfo();
|
||||||
|
|
||||||
|
MinecraftVersionInfo mcVersionInfo;
|
||||||
|
try {
|
||||||
|
mcVersionInfo = new MinecraftVersionInfo();
|
||||||
|
} catch(Throwable t) {
|
||||||
|
logger.error("Error while parsing minecraft version info. Continuing launch, but setting all versions to -1.");
|
||||||
|
mcVersionInfo = new MinecraftVersionInfo(-1, -1, -1);
|
||||||
|
}
|
||||||
|
MINECRAFT_VERSION_INFO = mcVersionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MinecraftVersionInfo getMinecraftVersionInfo() {
|
||||||
|
return MINECRAFT_VERSION_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SpigotVersionInfo getSpigotVersionInfo() {
|
||||||
|
return SPIGOT_VERSION_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class SpigotVersionInfo {
|
||||||
|
private final boolean spigot;
|
||||||
|
private final boolean paper;
|
||||||
|
private final boolean mohist;
|
||||||
|
|
||||||
|
|
||||||
|
public SpigotVersionInfo() {
|
||||||
|
logger.debug("Parsing spigot version info...");
|
||||||
|
|
||||||
|
paper = PaperLib.isPaper();
|
||||||
|
spigot = PaperLib.isSpigot();
|
||||||
|
|
||||||
|
|
||||||
|
boolean isMohist = false;
|
||||||
|
try {
|
||||||
|
Class.forName("com.mohistmc.MohistMC");
|
||||||
|
// it's mohist
|
||||||
|
isMohist = true;
|
||||||
|
} catch(ClassNotFoundException ignore) { }
|
||||||
|
this.mohist = isMohist;
|
||||||
|
|
||||||
|
logger.debug("Spigot version info parsed successfully.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPaper() {
|
||||||
|
return paper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMohist() {
|
||||||
|
return mohist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSpigot() {
|
||||||
|
return spigot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static final class MinecraftVersionInfo {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(MinecraftVersionInfo.class);
|
||||||
|
|
||||||
|
private static final Pattern VERSION_PATTERN = Pattern.compile("v?(\\d+)_(\\d+)_R(\\d+)");
|
||||||
|
private final int major;
|
||||||
|
private final int minor;
|
||||||
|
private final int patch;
|
||||||
|
|
||||||
|
private MinecraftVersionInfo() {
|
||||||
|
this(Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MinecraftVersionInfo(int major, int minor, int patch) {
|
||||||
|
this.major = major;
|
||||||
|
this.minor = minor;
|
||||||
|
this.patch = patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MinecraftVersionInfo(String versionString) {
|
||||||
|
Matcher versionMatcher = VERSION_PATTERN.matcher(versionString);
|
||||||
|
if(versionMatcher.find()) {
|
||||||
|
major = Integer.parseInt(versionMatcher.group(1));
|
||||||
|
minor = Integer.parseInt(versionMatcher.group(2));
|
||||||
|
patch = Integer.parseInt(versionMatcher.group(3));
|
||||||
|
} else {
|
||||||
|
logger.warn("Error while parsing minecraft version info. Continuing launch, but setting all versions to -1.");
|
||||||
|
|
||||||
|
major = -1;
|
||||||
|
minor = -1;
|
||||||
|
patch = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if(major == -1 && minor == -1 && patch == -1)
|
||||||
|
return "Unknown";
|
||||||
|
|
||||||
|
return String.format("v%d.%d.%d", major, minor, patch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMajor() {
|
||||||
|
return major;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinor() {
|
||||||
|
return minor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPatch() {
|
||||||
|
return patch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,9 @@ val fabricLoader = "0.12.5"
|
|||||||
dependencies {
|
dependencies {
|
||||||
"shadedApi"(project(":common:implementation"))
|
"shadedApi"(project(":common:implementation"))
|
||||||
|
|
||||||
|
shadedImplementation("org.slf4j:slf4j-log4j12:1.7.32")
|
||||||
|
// shadedImplementation("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
|
||||||
|
|
||||||
"minecraft"("com.mojang:minecraft:$minecraft")
|
"minecraft"("com.mojang:minecraft:$minecraft")
|
||||||
"mappings"("net.fabricmc:yarn:$minecraft+build.$yarn:v2")
|
"mappings"("net.fabricmc:yarn:$minecraft+build.$yarn:v2")
|
||||||
"modImplementation"("net.fabricmc:fabric-loader:$fabricLoader")
|
"modImplementation"("net.fabricmc:fabric-loader:$fabricLoader")
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import net.minecraft.util.registry.BuiltinRegistries;
|
|||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -50,6 +52,8 @@ import com.dfsek.terra.fabric.util.FabricUtil;
|
|||||||
public final class FabricAddon implements BaseAddon {
|
public final class FabricAddon implements BaseAddon {
|
||||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||||
private final PlatformImpl terraFabricPlugin;
|
private final PlatformImpl terraFabricPlugin;
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FabricAddon.class);
|
||||||
|
|
||||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||||
|
|
||||||
public FabricAddon(PlatformImpl terraFabricPlugin) {
|
public FabricAddon(PlatformImpl terraFabricPlugin) {
|
||||||
@@ -66,17 +70,19 @@ public final class FabricAddon implements BaseAddon {
|
|||||||
try {
|
try {
|
||||||
event.loadTemplate(template);
|
event.loadTemplate(template);
|
||||||
} catch(ConfigException e) {
|
} catch(ConfigException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error loading config template", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(template.doRegistryInjection()) {
|
if(template.doRegistryInjection()) {
|
||||||
|
logger.info("Injecting structures into Terra");
|
||||||
|
|
||||||
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
|
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
|
||||||
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
|
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
|
||||||
try {
|
try {
|
||||||
event.getPack().getCheckedRegistry(Tree.class).register(entry.getKey().getValue().toString(),
|
event.getPack()
|
||||||
(Tree) entry.getValue());
|
.getCheckedRegistry(Tree.class)
|
||||||
terraFabricPlugin.getDebugLogger().info(
|
.register(entry.getKey().getValue().toString(), (Tree) entry.getValue());
|
||||||
"Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree.");
|
logger.info("Injected ConfiguredFeature {} as Tree.", entry.getKey().getValue());
|
||||||
} catch(DuplicateEntryException ignored) {
|
} catch(DuplicateEntryException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,7 +101,7 @@ public final class FabricAddon implements BaseAddon {
|
|||||||
try {
|
try {
|
||||||
event.loadTemplate(template);
|
event.loadTemplate(template);
|
||||||
} catch(ConfigException e) {
|
} catch(ConfigException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error loading config template", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
templates.get(event.getPack()).setRight(template);
|
templates.get(event.getPack()).setRight(template);
|
||||||
@@ -107,18 +113,19 @@ public final class FabricAddon implements BaseAddon {
|
|||||||
.getHandler(FunctionalEventHandler.class)
|
.getHandler(FunctionalEventHandler.class)
|
||||||
.register(this, BiomeRegistrationEvent.class)
|
.register(this, BiomeRegistrationEvent.class)
|
||||||
.then(event -> {
|
.then(event -> {
|
||||||
terraFabricPlugin.logger().info("Registering biomes...");
|
logger.info("Registering biomes...");
|
||||||
|
|
||||||
Registry<Biome> biomeRegistry = event.getRegistryManager().get(Registry.BIOME_KEY);
|
Registry<Biome> biomeRegistry = event.getRegistryManager().get(Registry.BIOME_KEY);
|
||||||
terraFabricPlugin.getConfigRegistry().forEach(pack -> pack.getCheckedRegistry(TerraBiome.class)
|
terraFabricPlugin.getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||||
.forEach(
|
pack.getCheckedRegistry(TerraBiome.class)
|
||||||
(id, biome) -> FabricUtil.registerOrOverwrite(
|
.forEach((id, biome) -> {
|
||||||
biomeRegistry, Registry.BIOME_KEY,
|
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
|
||||||
new Identifier("terra",
|
Biome fabricBiome = FabricUtil.createBiome(biome, pack, event.getRegistryManager());
|
||||||
FabricUtil.createBiomeID(
|
|
||||||
pack, id)),
|
FabricUtil.registerOrOverwrite(biomeRegistry, Registry.BIOME_KEY, identifier, fabricBiome);
|
||||||
FabricUtil.createBiome(biome, pack,
|
});
|
||||||
event.getRegistryManager())))); // Register all Terra biomes.
|
});
|
||||||
terraFabricPlugin.logger().info("Biomes registered.");
|
logger.info("Biomes registered.");
|
||||||
})
|
})
|
||||||
.global();
|
.global();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,20 +20,26 @@ package com.dfsek.terra.fabric;
|
|||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||||
|
|
||||||
|
|
||||||
public class FabricEntryPoint implements ModInitializer {
|
public class FabricEntryPoint implements ModInitializer {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FabricEntryPoint.class);
|
||||||
|
|
||||||
private static final PlatformImpl TERRA_PLUGIN = new PlatformImpl();
|
private static final PlatformImpl TERRA_PLUGIN = new PlatformImpl();
|
||||||
|
|
||||||
|
|
||||||
public static PlatformImpl getPlatform() {
|
public static PlatformImpl getPlatform() {
|
||||||
return TERRA_PLUGIN;
|
return TERRA_PLUGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
logger.info("Initializing Terra Fabric mod...");
|
||||||
// register the things
|
// register the things
|
||||||
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
|
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
|
||||||
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
|
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
|
||||||
|
|||||||
@@ -19,14 +19,10 @@ package com.dfsek.terra.fabric;
|
|||||||
|
|
||||||
import com.dfsek.tectonic.exception.LoadException;
|
import com.dfsek.tectonic.exception.LoadException;
|
||||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||||
|
|
||||||
import com.dfsek.terra.api.addon.BaseAddon;
|
|
||||||
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.BuiltinRegistries;
|
import net.minecraft.util.registry.BuiltinRegistries;
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -34,9 +30,9 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.dfsek.terra.AbstractPlatform;
|
import com.dfsek.terra.AbstractPlatform;
|
||||||
|
import com.dfsek.terra.api.addon.BaseAddon;
|
||||||
import com.dfsek.terra.api.handle.ItemHandle;
|
import com.dfsek.terra.api.handle.ItemHandle;
|
||||||
import com.dfsek.terra.api.handle.WorldHandle;
|
import com.dfsek.terra.api.handle.WorldHandle;
|
||||||
import com.dfsek.terra.api.util.Logger;
|
|
||||||
import com.dfsek.terra.api.util.generic.Lazy;
|
import com.dfsek.terra.api.util.generic.Lazy;
|
||||||
import com.dfsek.terra.config.lang.LangUtil;
|
import com.dfsek.terra.config.lang.LangUtil;
|
||||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||||
@@ -103,36 +99,15 @@ public class PlatformImpl extends AbstractPlatform {
|
|||||||
@Override
|
@Override
|
||||||
public void register(TypeRegistry registry) {
|
public void register(TypeRegistry registry) {
|
||||||
super.register(registry);
|
super.register(registry);
|
||||||
registry
|
registry.registerLoader(com.dfsek.terra.api.world.biome.Biome.class, (t, o, l) -> parseBiome((String) o))
|
||||||
.registerLoader(com.dfsek.terra.api.world.biome.Biome.class, (t, o, l) -> parseBiome((String) o))
|
|
||||||
.registerLoader(Identifier.class, (t, o, l) -> {
|
.registerLoader(Identifier.class, (t, o, l) -> {
|
||||||
Identifier identifier = Identifier.tryParse((String) o);
|
Identifier identifier = Identifier.tryParse((String) o);
|
||||||
if(identifier == null) throw new LoadException("Invalid identifier: " + o);
|
if(identifier == null)
|
||||||
|
throw new LoadException("Invalid identifier: " + o);
|
||||||
return identifier;
|
return identifier;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Logger createLogger() {
|
|
||||||
final org.apache.logging.log4j.Logger log4jLogger = LogManager.getLogger();
|
|
||||||
return new Logger() {
|
|
||||||
@Override
|
|
||||||
public void info(String message) {
|
|
||||||
log4jLogger.info(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warning(String message) {
|
|
||||||
log4jLogger.warn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void severe(String message) {
|
|
||||||
log4jLogger.error(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private ProtoBiome parseBiome(String id) throws LoadException {
|
private ProtoBiome parseBiome(String id) throws LoadException {
|
||||||
Identifier identifier = Identifier.tryParse(id);
|
Identifier identifier = Identifier.tryParse(id);
|
||||||
|
|||||||
+34
-27
@@ -17,17 +17,6 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.fabric.generation;
|
package com.dfsek.terra.fabric.generation;
|
||||||
|
|
||||||
import com.dfsek.terra.api.config.ConfigPack;
|
|
||||||
import com.dfsek.terra.api.world.World;
|
|
||||||
import com.dfsek.terra.api.world.generator.ChunkData;
|
|
||||||
import com.dfsek.terra.api.world.generator.ChunkGenerator;
|
|
||||||
import com.dfsek.terra.api.world.generator.Chunkified;
|
|
||||||
import com.dfsek.terra.api.world.generator.GeneratorWrapper;
|
|
||||||
import com.dfsek.terra.fabric.FabricEntryPoint;
|
|
||||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
|
||||||
import com.dfsek.terra.fabric.mixin.StructureAccessorAccessor;
|
|
||||||
import com.dfsek.terra.util.FastRandom;
|
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
@@ -46,22 +35,40 @@ import net.minecraft.world.StructureWorldAccess;
|
|||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
import net.minecraft.world.biome.SpawnSettings;
|
import net.minecraft.world.biome.SpawnSettings;
|
||||||
import net.minecraft.world.biome.source.BiomeAccess;
|
import net.minecraft.world.biome.source.BiomeAccess;
|
||||||
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
|
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
|
||||||
import net.minecraft.world.biome.source.util.MultiNoiseUtil.NoiseValuePoint;
|
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.gen.GenerationStep.Carver;
|
import net.minecraft.world.gen.GenerationStep;
|
||||||
import net.minecraft.world.gen.StructureAccessor;
|
import net.minecraft.world.gen.StructureAccessor;
|
||||||
import net.minecraft.world.gen.chunk.Blender;
|
import net.minecraft.world.gen.chunk.Blender;
|
||||||
import net.minecraft.world.gen.chunk.StructuresConfig;
|
import net.minecraft.world.gen.chunk.StructuresConfig;
|
||||||
import net.minecraft.world.gen.chunk.VerticalBlockSample;
|
import net.minecraft.world.gen.chunk.VerticalBlockSample;
|
||||||
import net.minecraft.world.gen.feature.*;
|
import net.minecraft.world.gen.feature.NetherFortressFeature;
|
||||||
|
import net.minecraft.world.gen.feature.OceanMonumentFeature;
|
||||||
|
import net.minecraft.world.gen.feature.PillagerOutpostFeature;
|
||||||
|
import net.minecraft.world.gen.feature.StructureFeature;
|
||||||
|
import net.minecraft.world.gen.feature.SwampHutFeature;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
|
import com.dfsek.terra.api.world.World;
|
||||||
|
import com.dfsek.terra.api.world.generator.ChunkData;
|
||||||
|
import com.dfsek.terra.api.world.generator.ChunkGenerator;
|
||||||
|
import com.dfsek.terra.api.world.generator.Chunkified;
|
||||||
|
import com.dfsek.terra.api.world.generator.GeneratorWrapper;
|
||||||
|
import com.dfsek.terra.fabric.FabricEntryPoint;
|
||||||
|
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||||
|
import com.dfsek.terra.fabric.mixin.StructureAccessorAccessor;
|
||||||
|
import com.dfsek.terra.util.FastRandom;
|
||||||
|
|
||||||
|
|
||||||
public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.ChunkGenerator implements GeneratorWrapper {
|
public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.ChunkGenerator implements GeneratorWrapper {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FabricChunkGeneratorWrapper.class);
|
||||||
|
|
||||||
public static final Codec<ConfigPack> PACK_CODEC = RecordCodecBuilder.create(
|
public static final Codec<ConfigPack> PACK_CODEC = RecordCodecBuilder.create(
|
||||||
config -> config.group(
|
config -> config.group(
|
||||||
Codec.STRING.fieldOf("pack")
|
Codec.STRING.fieldOf("pack")
|
||||||
@@ -90,7 +97,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
|||||||
this.pack = configPack;
|
this.pack = configPack;
|
||||||
|
|
||||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||||
delegate.getPlatform().logger().info("Loading world with config pack " + pack.getID());
|
logger.info("Loading world with config pack {}", pack.getID());
|
||||||
this.biomeSource = biomeSource;
|
this.biomeSource = biomeSource;
|
||||||
|
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
@@ -106,15 +113,17 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
|||||||
return new FabricChunkGeneratorWrapper((TerraBiomeSource) this.biomeSource.withSeed(seed), seed, pack);
|
return new FabricChunkGeneratorWrapper((TerraBiomeSource) this.biomeSource.withSeed(seed), seed, pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setPack(ConfigPack pack) {
|
||||||
public MultiNoiseSampler getMultiNoiseSampler() {
|
this.pack = pack;
|
||||||
return (x, y, z) -> new NoiseValuePoint(0, 0, 0, 0, 0, 0);
|
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||||
|
biomeSource.setPack(pack);
|
||||||
|
|
||||||
|
logger.debug("Loading world with config pack {}", pack.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void carve(ChunkRegion chunkRegion, long seed, BiomeAccess biomeAccess, StructureAccessor structureAccessor, Chunk chunk,
|
public MultiNoiseUtil.MultiNoiseSampler getMultiNoiseSampler() {
|
||||||
Carver generationStep) {
|
return (x, y, z) -> new MultiNoiseUtil.NoiseValuePoint(0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -281,12 +290,10 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
|||||||
return pack;
|
return pack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPack(ConfigPack pack) {
|
@Override
|
||||||
this.pack = pack;
|
public void carve(ChunkRegion chunkRegion, long seed, BiomeAccess biomeAccess, StructureAccessor structureAccessor, Chunk chunk,
|
||||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
GenerationStep.Carver generationStep) {
|
||||||
biomeSource.setPack(pack);
|
|
||||||
|
|
||||||
delegate.getPlatform().logger().info("Loading world with config pack " + pack.getID());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWorld(ServerWorld world) {
|
public void setWorld(ServerWorld world) {
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import net.minecraft.world.gen.Spawner;
|
|||||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.ServerWorldProperties;
|
import net.minecraft.world.level.ServerWorldProperties;
|
||||||
import net.minecraft.world.level.storage.LevelStorage;
|
import net.minecraft.world.level.storage.LevelStorage;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
@@ -41,6 +43,8 @@ import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
|||||||
|
|
||||||
@Mixin(ServerWorld.class)
|
@Mixin(ServerWorld.class)
|
||||||
public abstract class ServerWorldMixin {
|
public abstract class ServerWorldMixin {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ServerWorldMixin.class);
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("RETURN"))
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session,
|
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session,
|
||||||
ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType,
|
ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType,
|
||||||
@@ -49,7 +53,7 @@ public abstract class ServerWorldMixin {
|
|||||||
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
|
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
|
||||||
((FabricChunkGeneratorWrapper) chunkGenerator).setWorld((ServerWorld) (Object) this);
|
((FabricChunkGeneratorWrapper) chunkGenerator).setWorld((ServerWorld) (Object) this);
|
||||||
FabricEntryPoint.getPlatform().addWorld((ServerWorld) (Object) this);
|
FabricEntryPoint.getPlatform().addWorld((ServerWorld) (Object) this);
|
||||||
FabricEntryPoint.getPlatform().logger().info("Registered world " + this);
|
logger.info("Registered world {}", this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
"shadedApi"(project(":common:implementation"))
|
"shadedApi"(project(":common:implementation"))
|
||||||
|
|
||||||
|
shadedImplementation("org.slf4j:slf4j-log4j12:1.7.32")
|
||||||
|
// "shadedImplementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
|
||||||
|
|
||||||
"annotationProcessor"("org.spongepowered:spongeapi:9.0.0-SNAPSHOT")
|
"annotationProcessor"("org.spongepowered:spongeapi:9.0.0-SNAPSHOT")
|
||||||
"shadedImplementation"("org.spongepowered:spongeapi:9.0.0-SNAPSHOT")
|
"shadedImplementation"("org.spongepowered:spongeapi:9.0.0-SNAPSHOT")
|
||||||
"annotationProcessor"("org.spongepowered:mixin:0.8.2:processor")
|
"annotationProcessor"("org.spongepowered:mixin:0.8.2:processor")
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.spongepowered.api.Sponge;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
|
||||||
import com.dfsek.terra.AbstractPlatform;
|
import com.dfsek.terra.AbstractPlatform;
|
||||||
import com.dfsek.terra.api.handle.ItemHandle;
|
import com.dfsek.terra.api.handle.ItemHandle;
|
||||||
import com.dfsek.terra.api.handle.WorldHandle;
|
import com.dfsek.terra.api.handle.WorldHandle;
|
||||||
@@ -61,24 +62,4 @@ public class PlatformImpl extends AbstractPlatform {
|
|||||||
public ItemHandle getItemHandle() {
|
public ItemHandle getItemHandle() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Logger createLogger() {
|
|
||||||
return new Logger() {
|
|
||||||
@Override
|
|
||||||
public void info(String message) {
|
|
||||||
plugin.getPluginContainer().logger().info(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warning(String message) {
|
|
||||||
plugin.getPluginContainer().logger().warn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void severe(String message) {
|
|
||||||
plugin.getPluginContainer().logger().error(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user