mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-08 00:36:15 +00:00
Merge pull request #269 from solonovamax/architecture/slf4j-logging
Improve logging and migrate to SLF4J for logging instead of internal logging classes.
This commit is contained in:
@@ -10,6 +10,8 @@ dependencies {
|
||||
|
||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||
|
||||
"shadedApi"("org.slf4j:slf4j-api:1.7.32")
|
||||
|
||||
"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.Registry;
|
||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a Terra mod/plugin instance.
|
||||
*/
|
||||
public interface Platform extends LoaderRegistrar {
|
||||
Logger logger();
|
||||
|
||||
boolean reload();
|
||||
|
||||
String platformName();
|
||||
@@ -58,8 +55,6 @@ public interface Platform extends LoaderRegistrar {
|
||||
|
||||
ItemHandle getItemHandle();
|
||||
|
||||
Logger getDebugLogger();
|
||||
|
||||
EventManager getEventManager();
|
||||
|
||||
default String getVersion() {
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
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.block.state.BlockState;
|
||||
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 {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BufferedBlock.class);
|
||||
|
||||
private final BlockState data;
|
||||
private final boolean overwrite;
|
||||
private final Platform platform;
|
||||
@@ -39,8 +44,7 @@ public class BufferedBlock implements BufferedItem {
|
||||
world.setBlockData(origin, data);
|
||||
}
|
||||
} catch(RuntimeException e) {
|
||||
platform.logger().severe("Failed to place block at location " + origin + ": " + e.getMessage());
|
||||
platform.getDebugLogger().stack(e);
|
||||
logger.error("Failed to place block at location {}", origin, 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 org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
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.registry.CheckedRegistry;
|
||||
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.commands.CommandUtil;
|
||||
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.OpenRegistryImpl;
|
||||
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.
|
||||
*/
|
||||
public abstract class AbstractPlatform implements Platform {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractPlatform.class);
|
||||
|
||||
private static final MutableBoolean LOADED = new MutableBoolean(false);
|
||||
private final EventManager eventManager = new EventManagerImpl(this);
|
||||
|
||||
private final ConfigRegistry configRegistry = new 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 Lazy<Logger> logger = Lazy.lazy(this::createLogger);
|
||||
private final Lazy<DebugLogger> debugLogger = Lazy.lazy(() -> new DebugLogger(logger()));
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
loaders.register(registry);
|
||||
public ConfigRegistry getRawConfigRegistry() {
|
||||
return configRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger logger() {
|
||||
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;
|
||||
public CommandManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
protected Optional<BaseAddon> platformAddon() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
protected void load() {
|
||||
if(LOADED.get()) {
|
||||
throw new IllegalStateException(
|
||||
@@ -154,7 +114,7 @@ public abstract class AbstractPlatform implements Platform {
|
||||
}
|
||||
LOADED.set(true);
|
||||
|
||||
logger().info("Initializing Terra...");
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
try(InputStream stream = getClass().getResourceAsStream("/config.yml")) {
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
@@ -162,7 +122,7 @@ public abstract class AbstractPlatform implements Platform {
|
||||
FileUtils.copyInputStreamToFile(stream, configFile);
|
||||
}
|
||||
} 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()) {
|
||||
try(InputStream resourcesConfig = getClass().getResourceAsStream("/resources.yml")) {
|
||||
if(resourcesConfig == null) {
|
||||
logger().info("No resources config found. Skipping resource dumping.");
|
||||
logger.info("No resources config found. Skipping resource dumping.");
|
||||
return;
|
||||
}
|
||||
String resourceYaml = IOUtils.toString(resourcesConfig, StandardCharsets.UTF_8);
|
||||
Map<String, List<String>> resources = new Yaml().load(resourceYaml);
|
||||
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);
|
||||
if(resource.exists()) return; // dont overwrite
|
||||
logger().info("Dumping resource " + resource.getAbsolutePath());
|
||||
if(resource.exists())
|
||||
return; // dont overwrite
|
||||
logger.info("Dumping resource {}...", resource.getAbsolutePath());
|
||||
try {
|
||||
resource.getParentFile().mkdirs();
|
||||
resource.createNewFile();
|
||||
@@ -197,14 +158,12 @@ public abstract class AbstractPlatform implements Platform {
|
||||
}
|
||||
}));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error while dumping resources...", e);
|
||||
}
|
||||
} 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
|
||||
profiler.start();
|
||||
}
|
||||
@@ -248,36 +207,61 @@ public abstract class AbstractPlatform implements Platform {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(internalAddon, PlatformInitializationEvent.class)
|
||||
.then(event -> {
|
||||
logger().info("Loading config packs...");
|
||||
logger.info("Loading config packs...");
|
||||
getRawConfigRegistry().loadAll(this);
|
||||
logger().info("Loaded packs.");
|
||||
logger.info("Loaded packs.");
|
||||
})
|
||||
.global();
|
||||
|
||||
|
||||
logger().info("Loaded addons.");
|
||||
logger.info("Loaded addons.");
|
||||
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
} 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() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ConfigRegistry getRawConfigRegistry() {
|
||||
return configRegistry;
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
loaders.register(registry);
|
||||
}
|
||||
|
||||
public CommandManager getManager() {
|
||||
return manager;
|
||||
@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 EventManager getEventManager() {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ public class AddonsCommand implements CommandTemplate {
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
sender.sendMessage("Installed Addons:");
|
||||
platform.getAddons().forEach(
|
||||
addon -> sender.sendMessage(" - " + addon.getID()));
|
||||
platform.getAddons().forEach(addon -> {
|
||||
sender.sendMessage(" - " + addon.getID());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,19 +17,23 @@
|
||||
|
||||
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.exception.MalformedCommandException;
|
||||
import com.dfsek.terra.commands.profiler.ProfileCommand;
|
||||
|
||||
|
||||
public final class CommandUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CommandUtil.class);
|
||||
public static void registerAll(CommandManager manager) throws MalformedCommandException {
|
||||
logger.info("Registering Terra commands...");
|
||||
manager.register("profile", ProfileCommand.class);
|
||||
manager.register("reload", ReloadCommand.class);
|
||||
manager.register("addons", AddonsCommand.class);
|
||||
manager.register("version", VersionCommand.class);
|
||||
manager.register("getblock", GetBlockCommand.class);
|
||||
manager.register("packs", PacksCommand.class);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class PacksCommand implements CommandTemplate {
|
||||
public void execute(CommandSender sender) {
|
||||
CheckedRegistry<ConfigPack> registry = platform.getConfigRegistry();
|
||||
|
||||
if(registry.entries().size() == 0) {
|
||||
if(registry.entries().isEmpty()) {
|
||||
LangUtil.send("command.packs.none", sender);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.dfsek.terra.commands;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
@@ -29,15 +32,20 @@ import com.dfsek.terra.config.lang.LangUtil;
|
||||
usage = "/terra reload"
|
||||
)
|
||||
public class ReloadCommand implements CommandTemplate {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ReloadCommand.class);
|
||||
|
||||
@Inject
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
if(!platform.reload()) {
|
||||
LangUtil.send("command.reload-error", sender);
|
||||
} else {
|
||||
logger.info("Reloading Terra...");
|
||||
if(platform.reload()) {
|
||||
logger.info("Terra reloaded successfully.");
|
||||
LangUtil.send("command.reload", sender);
|
||||
} else {
|
||||
logger.warn("Terra failed to reload.");
|
||||
LangUtil.send("command.reload-error", sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
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.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
@@ -28,6 +31,8 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
@Command
|
||||
@DebugCommand
|
||||
public class ProfileQueryCommand implements CommandTemplate {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProfileQueryCommand.class);
|
||||
|
||||
@Inject
|
||||
private Platform platform;
|
||||
|
||||
@@ -35,7 +40,7 @@ public class ProfileQueryCommand implements CommandTemplate {
|
||||
public void execute(CommandSender sender) {
|
||||
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.logger().info(data.toString());
|
||||
logger.info(data.toString());
|
||||
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.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -31,18 +33,19 @@ import java.io.UncheckedIOException;
|
||||
import java.time.Duration;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.config.PluginConfig {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PluginConfigImpl.class);
|
||||
|
||||
@Value("debug.commands")
|
||||
@Default
|
||||
private boolean debugCommands = false;
|
||||
|
||||
@Value("debug.log")
|
||||
@Default
|
||||
private boolean debugLog = false;
|
||||
private boolean debugLog = false; // TODO: 2021-08-30 remove me
|
||||
|
||||
@Value("debug.profiler")
|
||||
@Default
|
||||
@@ -94,20 +97,20 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
|
||||
|
||||
@Override
|
||||
public void load(Platform platform) {
|
||||
Logger logger = platform.logger();
|
||||
logger.info("Loading config values");
|
||||
logger.info("Loading config values from config.yml");
|
||||
try(FileInputStream file = new FileInputStream(new File(platform.getDataFolder(), "config.yml"))) {
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.load(this, new YamlConfiguration(file, "config.yml"));
|
||||
} catch(ConfigException | IOException | UncheckedIOException e) {
|
||||
logger.severe("Failed to load config");
|
||||
e.printStackTrace();
|
||||
logger.error("Failed to load config", e);
|
||||
}
|
||||
|
||||
if(isDebugCommands()) logger.info("Debug commands enabled.");
|
||||
if(isDebugLogging()) logger.info("Debug logging enabled.");
|
||||
if(isDebugProfiler()) logger.info("Debug profiler enabled.");
|
||||
if(isDebugScript()) logger.info("Script debug blocks enabled.");
|
||||
if(debugCommands)
|
||||
logger.info("Debug commands enabled.");
|
||||
if(debugProfiler)
|
||||
logger.info("Debug profiler enabled.");
|
||||
if(debugScript)
|
||||
logger.info("Script debug blocks enabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
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}.
|
||||
*/
|
||||
public class FolderLoader extends LoaderImpl {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FolderLoader.class);
|
||||
|
||||
private final Path path;
|
||||
|
||||
public FolderLoader(Path path) {
|
||||
@@ -51,11 +56,11 @@ public class FolderLoader extends LoaderImpl {
|
||||
String rel = newPath.toPath().relativize(file).toString();
|
||||
streams.put(rel, new FileInputStream(file.toFile()));
|
||||
} catch(FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Could not find file to load", e);
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error while loading files", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -32,6 +34,8 @@ import com.dfsek.terra.api.config.Loader;
|
||||
|
||||
|
||||
public abstract class LoaderImpl implements Loader {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LoaderImpl.class);
|
||||
|
||||
protected final Map<String, InputStream> streams = new HashMap<>();
|
||||
|
||||
@Override
|
||||
@@ -54,7 +58,7 @@ public abstract class LoaderImpl implements Loader {
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
return this;
|
||||
}
|
||||
@@ -68,7 +72,7 @@ public abstract class LoaderImpl implements Loader {
|
||||
try {
|
||||
input.close();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error occurred while loading", e);
|
||||
}
|
||||
});
|
||||
streams.clear();
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
@@ -25,6 +28,8 @@ import java.util.zip.ZipFile;
|
||||
|
||||
|
||||
public class ZIPLoader extends LoaderImpl {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZIPLoader.class);
|
||||
|
||||
private final ZipFile file;
|
||||
|
||||
public ZIPLoader(ZipFile file) {
|
||||
@@ -50,7 +55,7 @@ public class ZIPLoader extends LoaderImpl {
|
||||
String rel = entry.getName().substring(directory.length());
|
||||
streams.put(rel, file.getInputStream(entry));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error while loading file from zip", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,38 +17,46 @@
|
||||
|
||||
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.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.lang.Language;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
|
||||
|
||||
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) {
|
||||
Logger logger = platform.logger();
|
||||
File file = new File(platform.getDataFolder(), "lang");
|
||||
try {
|
||||
File file1 = new File(file, langID + ".yml");
|
||||
logger.info(file1.getAbsolutePath());
|
||||
language = new LanguageImpl(file1);
|
||||
logger.info("Loaded language " + langID);
|
||||
LANGUAGE = new LanguageImpl(file1);
|
||||
logger.info("Loaded language {}", langID);
|
||||
} catch(IOException e) {
|
||||
logger.severe("Unable to load language: " + langID);
|
||||
e.printStackTrace();
|
||||
logger.severe("Double-check your configuration before reporting this to Terra!");
|
||||
logger.error("Unable to load language: {}.\nDouble-check your configuration before reporting this to Terra!", langID, e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Language getLanguage() {
|
||||
return language;
|
||||
return Objects.requireNonNull(LANGUAGE);
|
||||
}
|
||||
|
||||
public static void send(String messageID, CommandSender sender, String... args) {
|
||||
language.getMessage(messageID).send(sender, args);
|
||||
Objects.requireNonNull(LANGUAGE).getMessage(messageID).send(sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
@@ -96,6 +98,8 @@ import com.dfsek.terra.registry.config.ConfigTypeRegistry;
|
||||
* Represents a Terra configuration pack.
|
||||
*/
|
||||
public class ConfigPackImpl implements ConfigPack {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfigPackImpl.class);
|
||||
|
||||
private final ConfigPackTemplate template = new ConfigPackTemplate();
|
||||
|
||||
private final RegistryFactory registryFactory = new RegistryFactoryImpl();
|
||||
@@ -146,18 +150,18 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
|
||||
platform.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
logger.info("Loading config pack \"{}\"", template.getID());
|
||||
load(l, platform);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
selfLoader.load(packPostTemplate, configuration);
|
||||
seededBiomeProvider = packPostTemplate.getProviderBuilder();
|
||||
checkDeadEntries(platform);
|
||||
checkDeadEntries();
|
||||
} catch(FileNotFoundException e) {
|
||||
throw new LoadException("No pack.yml file found in " + folder.getAbsolutePath(), 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;
|
||||
}
|
||||
toWorldConfig(new DummyWorld()); // Build now to catch any errors immediately.
|
||||
@@ -197,7 +201,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
platform.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
logger.info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
load(l, platform);
|
||||
|
||||
@@ -205,12 +209,12 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
selfLoader.load(packPostTemplate, configuration);
|
||||
seededBiomeProvider = packPostTemplate.getProviderBuilder();
|
||||
checkDeadEntries(platform);
|
||||
checkDeadEntries();
|
||||
} catch(IOException e) {
|
||||
throw new LoadException("Unable to load pack.yml from ZIP file", 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;
|
||||
}
|
||||
|
||||
@@ -301,16 +305,14 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
OpenRegistry<T> registry = new OpenRegistryImpl<>();
|
||||
selfLoader.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) {
|
||||
ParameterizedType param = (ParameterizedType) type;
|
||||
if(type instanceof ParameterizedType param) {
|
||||
Type base = param.getRawType();
|
||||
if(base instanceof Class // should always be true but we'll check anyways
|
||||
&& Supplier.class.isAssignableFrom((Class<?>) base)) { // If it's a supplier
|
||||
Type supplied = param.getActualTypeArguments()[0]; // Grab the supplied type
|
||||
if(supplied instanceof ParameterizedType) {
|
||||
ParameterizedType suppliedParam = (ParameterizedType) supplied;
|
||||
if(supplied instanceof ParameterizedType suppliedParam) {
|
||||
Type suppliedBase = suppliedParam.getRawType();
|
||||
if(suppliedBase instanceof Class // should always be true but we'll check anyways
|
||||
&& ObjectTemplate.class.isAssignableFrom((Class<?>) suppliedBase)) {
|
||||
@@ -319,8 +321,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
(Registry<Supplier<ObjectTemplate<Supplier<ObjectTemplate<?>>>>>) registry);
|
||||
selfLoader.registerLoader(templateType, loader);
|
||||
abstractConfigLoader.registerLoader(templateType, loader);
|
||||
platform.getDebugLogger().info(
|
||||
"Registered template loader for registry of class " + ReflectionUtil.typeToString(templateType));
|
||||
logger.debug("Registered template loader for registry of class {}", ReflectionUtil.typeToString(templateType));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,7 +373,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
if(registryMap.containsKey(configType.getTypeKey()
|
||||
.getType())) { // Someone already registered something; we need to copy things to the
|
||||
// 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);
|
||||
}
|
||||
selfLoader.registerLoader(configType.getTypeKey().getType(), openRegistry);
|
||||
@@ -381,16 +382,10 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
});
|
||||
}
|
||||
|
||||
private void checkDeadEntries(Platform platform) {
|
||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft()).getDeadEntries()
|
||||
.forEach((id, value) -> platform.getDebugLogger()
|
||||
.warning(
|
||||
"Dead entry in" +
|
||||
" '" +
|
||||
ReflectionUtil.typeToString(
|
||||
clazz) +
|
||||
"' registry: '" +
|
||||
id + "'")));
|
||||
private void checkDeadEntries() {
|
||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft())
|
||||
.getDeadEntries()
|
||||
.forEach((id, value) -> logger.warn("Dead entry in '{}' registry: '{}'", ReflectionUtil.typeToString(clazz), id)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@@ -454,9 +449,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
}
|
||||
|
||||
platform.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
platform.logger().info(
|
||||
"Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " +
|
||||
(System.nanoTime() - start) / 1000000D + "ms.");
|
||||
logger.info("Loaded config pack \"{}\" v{} by {} in {}ms.",
|
||||
template.getID(), template.getVersion(), template.getAuthor(), (System.nanoTime() - start) / 1000000.0D);
|
||||
}
|
||||
|
||||
protected Map<Type, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> getRegistryMap() {
|
||||
|
||||
@@ -38,8 +38,7 @@ public class MetaStringPreprocessor extends MetaPreprocessor<Meta> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
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
|
||||
String candidate = (String) c;
|
||||
if(String.class.equals(t.getType()) && c instanceof String candidate) { // String is final so we use #equals
|
||||
StringSubstitutor substitutor = new StringSubstitutor(key -> {
|
||||
Object meta = getMetaValue(key);
|
||||
if(!(meta instanceof String) && !(meta instanceof Number) && !(meta instanceof Character) && !(meta instanceof Boolean)) {
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
|
||||
package com.dfsek.terra.event;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -38,6 +39,8 @@ import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
|
||||
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 Platform platform;
|
||||
@@ -59,13 +62,11 @@ public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
||||
((EventContextImpl<Event>) context).handle(event);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
if(context.isFailThrough() && event instanceof FailThroughEvent) throw e; // Rethrow if it's fail-through.
|
||||
StringWriter writer = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(writer));
|
||||
platform.logger().warning("Exception occurred during event handling:");
|
||||
platform.logger().warning(writer.toString());
|
||||
platform.logger().warning(
|
||||
"Report this to the maintainers of " + context.getAddon().getID());
|
||||
if(context.isFailThrough() && event instanceof FailThroughEvent)
|
||||
throw e; // Rethrow if it's fail-through.
|
||||
// else warn
|
||||
logger.warn("Exception occurred during event handling. Report this to the maintainers of {}@{}",
|
||||
context.getAddon().getID(), context.getAddon().getVersion().getFormatted(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -30,6 +33,8 @@ import com.dfsek.terra.profiler.exception.MalformedStackException;
|
||||
|
||||
|
||||
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<Map<String, List<Long>>> TIMINGS = ThreadLocal.withInitial(HashMap::new);
|
||||
private static final ThreadLocal<Boolean> SAFE = ThreadLocal.withInitial(() -> false);
|
||||
@@ -39,7 +44,8 @@ public class ProfilerImpl implements Profiler {
|
||||
private volatile boolean running = false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -62,14 +68,14 @@ public class ProfilerImpl implements Profiler {
|
||||
|
||||
Map<String, List<Long>> timingsMap = TIMINGS.get();
|
||||
|
||||
if(timingsMap.size() == 0) {
|
||||
if(timingsMap.isEmpty()) {
|
||||
synchronized(accessibleThreadMaps) {
|
||||
accessibleThreadMaps.add(timingsMap);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
List<Long> timings = timingsMap.computeIfAbsent(top.getId(), id -> new ArrayList<>());
|
||||
@@ -81,16 +87,19 @@ public class ProfilerImpl implements Profiler {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
logger.info("Starting Terra profiler");
|
||||
running = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
logger.info("Stopping Terra profiler");
|
||||
running = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
logger.info("Resetting Terra profiler");
|
||||
accessibleThreadMaps.forEach(Map::clear);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.dfsek.terra.registry.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@@ -27,6 +30,8 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
|
||||
|
||||
public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfigTypeRegistry.class);
|
||||
|
||||
private final BiConsumer<String, ConfigType<?, ?>> callback;
|
||||
|
||||
private final Platform platform;
|
||||
@@ -40,8 +45,8 @@ public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
|
||||
@Override
|
||||
public boolean register(String identifier, Entry<ConfigType<?, ?>> value) {
|
||||
callback.accept(identifier, value.getValue());
|
||||
platform.getDebugLogger().info("Registered config registry with ID " + identifier + " to type " +
|
||||
ReflectionUtil.typeToString(value.getValue().getTypeKey().getType()));
|
||||
logger.debug("Registered config registry with ID {} to type {}", identifier,
|
||||
ReflectionUtil.typeToString(value.getValue().getTypeKey().getType()));
|
||||
return super.register(identifier, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
package com.dfsek.terra.registry.master;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -33,6 +35,8 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
* Class to hold config packs
|
||||
*/
|
||||
public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfigRegistry.class);
|
||||
|
||||
public void load(File folder, Platform platform) throws ConfigException {
|
||||
ConfigPack pack = new ConfigPackImpl(folder, platform);
|
||||
register(pack.getID(), pack);
|
||||
@@ -46,16 +50,16 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
try {
|
||||
load(dir, platform);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config pack {}", dir.getName(), e);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".terra"))) {
|
||||
try {
|
||||
platform.getDebugLogger().info("Loading ZIP archive: " + zip.getName());
|
||||
logger.info("Loading ZIP archive: " + zip.getName());
|
||||
load(new ZipFile(zip), platform);
|
||||
} catch(IOException | ConfigException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config pack {}", zip.getName(), e);
|
||||
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;
|
||||
|
||||
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.UncheckedIOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -26,31 +31,29 @@ import java.nio.file.Path;
|
||||
import java.util.jar.JarFile;
|
||||
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.api.Platform;
|
||||
import com.dfsek.terra.api.addon.bootstrap.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 final Platform platform;
|
||||
|
||||
public BootstrapAddonLoader(Platform platform) { this.platform = platform; }
|
||||
|
||||
@Override
|
||||
public Iterable<BootstrapBaseAddon<?>> loadAddons(Path addonsFolder, ClassLoader parent) {
|
||||
Path bootstrapAddons = addonsFolder.resolve("bootstrap");
|
||||
platform.logger().info("Loading bootstrap addons from " + bootstrapAddons);
|
||||
logger.info("Loading bootstrap addons from {}", bootstrapAddons);
|
||||
try {
|
||||
return Files.walk(bootstrapAddons, 1)
|
||||
.filter(path -> path.toFile().isFile() && path.toString().endsWith(".jar"))
|
||||
.map(path -> {
|
||||
try {
|
||||
platform.logger().info("Loading bootstrap addon from JAR " + path);
|
||||
logger.info("Loading bootstrap addon from JAR {}", path);
|
||||
JarFile jar = new JarFile(path.toFile());
|
||||
String entry = jar.getManifest().getMainAttributes().getValue("Bootstrap-Addon-Entry-Point");
|
||||
|
||||
@@ -65,7 +68,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
if(!(in instanceof BootstrapBaseAddon)) {
|
||||
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;
|
||||
} catch(InvocationTargetException 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 {
|
||||
"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")
|
||||
"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("io.papermc.lib", "com.dfsek.terra.lib.paperlib")
|
||||
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 com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
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.bukkit.handles.BukkitItemHandle;
|
||||
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
||||
import com.dfsek.terra.bukkit.world.BukkitBiome;
|
||||
import com.dfsek.terra.util.logging.JavaLogger;
|
||||
|
||||
|
||||
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 {
|
||||
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)));
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
@@ -25,6 +24,8 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
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.SpigotListener;
|
||||
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.TerraCommandManager;
|
||||
|
||||
|
||||
public class TerraBukkitPlugin extends JavaPlugin {
|
||||
public static final BukkitVersion BUKKIT_VERSION;
|
||||
|
||||
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 static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
|
||||
|
||||
private final PlatformImpl terraPlugin = new PlatformImpl(this);
|
||||
private final Map<String, com.dfsek.terra.api.world.generator.ChunkGenerator> generatorMap = new HashMap<>();
|
||||
@@ -70,16 +62,15 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Running on version " + BUKKIT_VERSION);
|
||||
if(BUKKIT_VERSION == BukkitVersion.UNKNOWN) {
|
||||
getLogger().warning("Terra is running on an unknown Bukkit version. Proceed with caution.");
|
||||
if(!doVersionCheck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
terraPlugin.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
|
||||
new Metrics(this, 9017); // Set up bStats.
|
||||
|
||||
PluginCommand c = Objects.requireNonNull(getCommand("terra"));
|
||||
PluginCommand cmd = Objects.requireNonNull(getCommand("terra"));
|
||||
|
||||
CommandManager manager = new TerraCommandManager(terraPlugin);
|
||||
|
||||
@@ -89,17 +80,20 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
manager.register("save-data", SaveDataCommand.class);
|
||||
manager.register("fix-chunk", FixChunkCommand.class);
|
||||
} catch(MalformedCommandException e) { // This should never happen.
|
||||
terraPlugin.logger().severe("Errors occurred while registering commands.");
|
||||
e.printStackTrace();
|
||||
terraPlugin.logger().severe("Please report this to Terra.");
|
||||
logger.error("""
|
||||
TERRA HAS BEEN DISABLED
|
||||
|
||||
Errors occurred while registering commands.
|
||||
Please report this to Terra.
|
||||
""".strip(), e);
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
BukkitCommandAdapter command = new BukkitCommandAdapter(manager);
|
||||
|
||||
c.setExecutor(command);
|
||||
c.setTabCompleter(command);
|
||||
cmd.setExecutor(command);
|
||||
cmd.setTabCompleter(command);
|
||||
|
||||
|
||||
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
|
||||
PaperUtil.checkPaper(this);
|
||||
|
||||
if(PaperLib.isPaper()) {
|
||||
try {
|
||||
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.
|
||||
} catch(ClassNotFoundException e) {
|
||||
registerSpigotEvents(true); // Outdated Paper version.
|
||||
try {
|
||||
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.
|
||||
} catch(ClassNotFoundException e) {
|
||||
/*
|
||||
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 {
|
||||
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
|
||||
}
|
||||
} else {
|
||||
registerSpigotEvents(false);
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
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 -> {
|
||||
if(!terraPlugin.getConfigRegistry().contains(id)) throw new IllegalArgumentException("No such config pack \"" + id + "\"");
|
||||
ConfigPack pack = terraPlugin.getConfigRegistry().get(id);
|
||||
@@ -129,58 +226,4 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -37,6 +39,8 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class BukkitCommandAdapter implements CommandExecutor, TabCompleter {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BukkitCommandAdapter.class);
|
||||
|
||||
private final 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(
|
||||
String::compareTo).collect(Collectors.toList());
|
||||
} catch(CommandException e) {
|
||||
e.printStackTrace();
|
||||
logger.warn("Exception occurred during tab completion", e);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ package com.dfsek.terra.bukkit.generator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
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 {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BukkitChunkGeneratorWrapper.class);
|
||||
|
||||
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() {
|
||||
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 {
|
||||
e.getValue().saveBlocks(e.getKey());
|
||||
} catch(IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
entry.getValue().saveBlocks(entry.getKey());
|
||||
} catch(IOException e) {
|
||||
logger.error("Error occurred while saving population manager", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void fixChunk(Chunk c) {
|
||||
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
|
||||
public static synchronized void fixChunk(Chunk chunk) {
|
||||
popMap.get(chunk.getWorld()).checkNeighbors(chunk.getX(), chunk.getZ(), chunk.getWorld());
|
||||
}
|
||||
|
||||
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(IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error occurred while loading terra world", e);
|
||||
}
|
||||
popMap.put(w, popMan);
|
||||
needsLoad = false;
|
||||
|
||||
@@ -24,6 +24,8 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
||||
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
@@ -36,6 +38,7 @@ import com.dfsek.terra.api.Platform;
|
||||
*/
|
||||
public class SpigotListener implements Listener {
|
||||
private final Platform platform;
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpigotListener.class);
|
||||
|
||||
public SpigotListener(Platform platform) {
|
||||
this.platform = platform;
|
||||
@@ -43,46 +46,57 @@ public class SpigotListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEnderEye(EntitySpawnEvent e) {
|
||||
/*
|
||||
/*
|
||||
Entity entity = e.getEntity();
|
||||
if(e.getEntityType().equals(EntityType.ENDER_SIGNAL)) {
|
||||
main.getDebugLogger().info("Detected Ender Signal...");
|
||||
if(e.getEntityType() == EntityType.ENDER_SIGNAL) {
|
||||
logger.info("Detected Ender Signal...");
|
||||
World w = BukkitAdapter.adapt(e.getEntity().getWorld());
|
||||
EnderSignal signal = (EnderSignal) entity;
|
||||
ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(w.getConfig().getLocatable().get
|
||||
("STRONGHOLD"));
|
||||
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()
|
||||
.toVector()), tw.getWorld(), 0, 500, location -> {
|
||||
if(location != null)
|
||||
signal.setTargetLocation(BukkitAdapter.adapt(location).toLocation(e.getLocation().getWorld()));
|
||||
main.getDebugLogger().info("Location: " + location);
|
||||
logger.info("Location: {}", location);
|
||||
}, main);
|
||||
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.
|
||||
} 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
|
||||
public void onCartographerChange(VillagerAcquireTradeEvent e) {
|
||||
if(!(e.getEntity() instanceof Villager)) return;
|
||||
if(((Villager) e.getEntity()).getProfession().equals(Villager.Profession.CARTOGRAPHER)) {
|
||||
platform.logger().severe("Prevented server crash by stopping Cartographer villager from spawning.");
|
||||
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.");
|
||||
if(!(e.getEntity() instanceof Villager))
|
||||
return;
|
||||
if(((Villager) e.getEntity()).getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||
logger.error("""
|
||||
.------------------------------------------------------------------------.
|
||||
| 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.
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCartographerLevel(VillagerCareerChangeEvent e) {
|
||||
if(e.getProfession().equals(Villager.Profession.CARTOGRAPHER)) {
|
||||
platform.logger().severe("Prevented server crash by stopping Cartographer villager from spawning.");
|
||||
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.");
|
||||
if(e.getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||
logger.error("""
|
||||
.------------------------------------------------------------------------.
|
||||
| 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.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 {
|
||||
"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")
|
||||
"mappings"("net.fabricmc:yarn:$minecraft+build.$yarn:v2")
|
||||
"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.world.biome.Biome;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -50,6 +52,8 @@ import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
public final class FabricAddon implements BaseAddon {
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
private final PlatformImpl terraFabricPlugin;
|
||||
private static final Logger logger = LoggerFactory.getLogger(FabricAddon.class);
|
||||
|
||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||
|
||||
public FabricAddon(PlatformImpl terraFabricPlugin) {
|
||||
@@ -66,17 +70,19 @@ public final class FabricAddon implements BaseAddon {
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config template", e);
|
||||
}
|
||||
|
||||
if(template.doRegistryInjection()) {
|
||||
logger.info("Injecting structures into Terra");
|
||||
|
||||
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
|
||||
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
|
||||
try {
|
||||
event.getPack().getCheckedRegistry(Tree.class).register(entry.getKey().getValue().toString(),
|
||||
(Tree) entry.getValue());
|
||||
terraFabricPlugin.getDebugLogger().info(
|
||||
"Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree.");
|
||||
event.getPack()
|
||||
.getCheckedRegistry(Tree.class)
|
||||
.register(entry.getKey().getValue().toString(), (Tree) entry.getValue());
|
||||
logger.info("Injected ConfiguredFeature {} as Tree.", entry.getKey().getValue());
|
||||
} catch(DuplicateEntryException ignored) {
|
||||
}
|
||||
}
|
||||
@@ -95,7 +101,7 @@ public final class FabricAddon implements BaseAddon {
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config template", e);
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
@@ -107,18 +113,19 @@ public final class FabricAddon implements BaseAddon {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, BiomeRegistrationEvent.class)
|
||||
.then(event -> {
|
||||
terraFabricPlugin.logger().info("Registering biomes...");
|
||||
logger.info("Registering biomes...");
|
||||
|
||||
Registry<Biome> biomeRegistry = event.getRegistryManager().get(Registry.BIOME_KEY);
|
||||
terraFabricPlugin.getConfigRegistry().forEach(pack -> pack.getCheckedRegistry(TerraBiome.class)
|
||||
.forEach(
|
||||
(id, biome) -> FabricUtil.registerOrOverwrite(
|
||||
biomeRegistry, Registry.BIOME_KEY,
|
||||
new Identifier("terra",
|
||||
FabricUtil.createBiomeID(
|
||||
pack, id)),
|
||||
FabricUtil.createBiome(biome, pack,
|
||||
event.getRegistryManager())))); // Register all Terra biomes.
|
||||
terraFabricPlugin.logger().info("Biomes registered.");
|
||||
terraFabricPlugin.getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||
pack.getCheckedRegistry(TerraBiome.class)
|
||||
.forEach((id, biome) -> {
|
||||
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
|
||||
Biome fabricBiome = FabricUtil.createBiome(biome, pack, event.getRegistryManager());
|
||||
|
||||
FabricUtil.registerOrOverwrite(biomeRegistry, Registry.BIOME_KEY, identifier, fabricBiome);
|
||||
});
|
||||
});
|
||||
logger.info("Biomes registered.");
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
@@ -20,20 +20,26 @@ package com.dfsek.terra.fabric;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.util.Identifier;
|
||||
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.TerraBiomeSource;
|
||||
|
||||
|
||||
public class FabricEntryPoint implements ModInitializer {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FabricEntryPoint.class);
|
||||
|
||||
private static final PlatformImpl TERRA_PLUGIN = new PlatformImpl();
|
||||
|
||||
|
||||
public static PlatformImpl getPlatform() {
|
||||
return TERRA_PLUGIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
logger.info("Initializing Terra Fabric mod...");
|
||||
// register the things
|
||||
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.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.loading.TypeRegistry;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
@@ -34,9 +30,9 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
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.WorldHandle;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
@@ -103,36 +99,15 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
registry
|
||||
.registerLoader(com.dfsek.terra.api.world.biome.Biome.class, (t, o, l) -> parseBiome((String) o))
|
||||
registry.registerLoader(com.dfsek.terra.api.world.biome.Biome.class, (t, o, l) -> parseBiome((String) o))
|
||||
.registerLoader(Identifier.class, (t, o, l) -> {
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@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 {
|
||||
Identifier identifier = Identifier.tryParse(id);
|
||||
|
||||
@@ -17,17 +17,6 @@
|
||||
|
||||
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.codecs.RecordCodecBuilder;
|
||||
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.SpawnSettings;
|
||||
import net.minecraft.world.biome.source.BiomeAccess;
|
||||
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
|
||||
import net.minecraft.world.biome.source.util.MultiNoiseUtil.NoiseValuePoint;
|
||||
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
|
||||
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.chunk.Blender;
|
||||
import net.minecraft.world.gen.chunk.StructuresConfig;
|
||||
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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
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 {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FabricChunkGeneratorWrapper.class);
|
||||
|
||||
public static final Codec<ConfigPack> PACK_CODEC = RecordCodecBuilder.create(
|
||||
config -> config.group(
|
||||
Codec.STRING.fieldOf("pack")
|
||||
@@ -90,7 +97,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
this.pack = configPack;
|
||||
|
||||
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.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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiNoiseSampler getMultiNoiseSampler() {
|
||||
return (x, y, z) -> new NoiseValuePoint(0, 0, 0, 0, 0, 0);
|
||||
public void setPack(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
biomeSource.setPack(pack);
|
||||
|
||||
logger.debug("Loading world with config pack {}", pack.getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void carve(ChunkRegion chunkRegion, long seed, BiomeAccess biomeAccess, StructureAccessor structureAccessor, Chunk chunk,
|
||||
Carver generationStep) {
|
||||
|
||||
public MultiNoiseUtil.MultiNoiseSampler getMultiNoiseSampler() {
|
||||
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;
|
||||
}
|
||||
|
||||
public void setPack(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
biomeSource.setPack(pack);
|
||||
@Override
|
||||
public void carve(ChunkRegion chunkRegion, long seed, BiomeAccess biomeAccess, StructureAccessor structureAccessor, Chunk chunk,
|
||||
GenerationStep.Carver generationStep) {
|
||||
|
||||
delegate.getPlatform().logger().info("Loading world with config pack " + pack.getID());
|
||||
}
|
||||
|
||||
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.level.ServerWorldProperties;
|
||||
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.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -41,6 +43,8 @@ import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class ServerWorldMixin {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServerWorldMixin.class);
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session,
|
||||
ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType,
|
||||
@@ -49,7 +53,7 @@ public abstract class ServerWorldMixin {
|
||||
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
|
||||
((FabricChunkGeneratorWrapper) chunkGenerator).setWorld((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 {
|
||||
"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")
|
||||
"shadedImplementation"("org.spongepowered:spongeapi:9.0.0-SNAPSHOT")
|
||||
"annotationProcessor"("org.spongepowered:mixin:0.8.2:processor")
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.spongepowered.api.Sponge;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
@@ -61,24 +62,4 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
public ItemHandle getItemHandle() {
|
||||
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