mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Migrate logging to SLF4J
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
@@ -14,7 +14,7 @@ import com.dfsek.terra.api.world.generator.Palette;
|
||||
public class BiomePaletteTemplate implements ObjectTemplate<PaletteInfo> {
|
||||
@Value("slant")
|
||||
@Default
|
||||
private final @Meta SlantHolder slant;
|
||||
private @Meta SlantHolder slant;
|
||||
@Value("palette")
|
||||
private @Meta PaletteHolder palette;
|
||||
@Value("ocean.level")
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.dfsek.terra.addons.chunkgenerator.generation.generators;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -30,6 +32,8 @@ import com.dfsek.terra.api.world.generator.Sampler;
|
||||
|
||||
|
||||
public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
private static final Logger logger = LoggerFactory.getLogger(NoiseChunkGenerator3D.class);
|
||||
|
||||
private final ConfigPack configPack;
|
||||
private final TerraPlugin main;
|
||||
private final List<GenerationStage> generationStages = new ArrayList<>();
|
||||
@@ -87,7 +91,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
PaletteInfo paletteInfo = biome.getContext().get(PaletteInfo.class);
|
||||
|
||||
if(paletteInfo == null) {
|
||||
main.logger().info("null palette: " + biome.getID());
|
||||
logger.info("null palette: {}", biome.getID());
|
||||
}
|
||||
|
||||
GenerationSettings generationSettings = biome.getGenerator();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.addons.structure.command.structure;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@@ -28,6 +31,8 @@ import com.dfsek.terra.api.vector.Vector3;
|
||||
@DebugCommand
|
||||
@Command(arguments = @Argument("id"), usage = "/terra structure export <ID>")
|
||||
public class StructureExportCommand implements CommandTemplate {
|
||||
private static final Logger logger = LoggerFactory.getLogger(StructureExportCommand.class);
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@@ -38,10 +43,10 @@ public class StructureExportCommand implements CommandTemplate {
|
||||
public void execute(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
Pair<Vector3, Vector3> l = main.getWorldHandle().getSelectedLocation(player);
|
||||
Pair<Vector3, Vector3> area = main.getWorldHandle().getSelectedLocation(player);
|
||||
|
||||
Vector3 l1 = l.getLeft();
|
||||
Vector3 l2 = l.getRight();
|
||||
Vector3 firstCorner = area.getLeft();
|
||||
Vector3 secondCorner = area.getRight();
|
||||
|
||||
StringBuilder scriptBuilder = new StringBuilder("id \"" + id + "\";\nnum y = 0;\n");
|
||||
|
||||
@@ -49,38 +54,36 @@ public class StructureExportCommand implements CommandTemplate {
|
||||
int centerY = 0;
|
||||
int centerZ = 0;
|
||||
|
||||
for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) {
|
||||
for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) {
|
||||
for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) {
|
||||
for(int x = firstCorner.getBlockX(); x <= secondCorner.getBlockX(); x++) {
|
||||
for(int y = firstCorner.getBlockY(); y <= secondCorner.getBlockY(); y++) {
|
||||
for(int z = firstCorner.getBlockZ(); z <= secondCorner.getBlockZ(); z++) {
|
||||
BlockEntity state = player.world().getBlockState(x, y, z);
|
||||
if(state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
if(sign.getLine(0).equals("[TERRA]") && sign.getLine(1).equals("[CENTER]")) {
|
||||
centerX = x - l1.getBlockX();
|
||||
centerY = y - l1.getBlockY();
|
||||
centerZ = z - l1.getBlockZ();
|
||||
if(state instanceof Sign sign) {
|
||||
if("[TERRA]".equals(sign.getLine(0)) && "[CENTER]".equals(sign.getLine(1))) {
|
||||
centerX = x - firstCorner.getBlockX();
|
||||
centerY = y - firstCorner.getBlockY();
|
||||
centerZ = z - firstCorner.getBlockZ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) {
|
||||
for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) {
|
||||
for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) {
|
||||
for(int x = firstCorner.getBlockX(); x <= secondCorner.getBlockX(); x++) {
|
||||
for(int y = firstCorner.getBlockY(); y <= secondCorner.getBlockY(); y++) {
|
||||
for(int z = firstCorner.getBlockZ(); z <= secondCorner.getBlockZ(); z++) {
|
||||
|
||||
BlockState data = player.world().getBlockData(x, y, z);
|
||||
if(data.isStructureVoid()) continue;
|
||||
BlockEntity state = player.world().getBlockState(x, y, z);
|
||||
if(state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
if(sign.getLine(0).equals("[TERRA]")) {
|
||||
if(state instanceof Sign sign) {
|
||||
if("[TERRA]".equals(sign.getLine(0))) {
|
||||
data = main.getWorldHandle().createBlockData(sign.getLine(2) + sign.getLine(3));
|
||||
}
|
||||
}
|
||||
if(!data.isStructureVoid()) {
|
||||
scriptBuilder.append("block(").append(x - l1.getBlockX() - centerX).append(", y + ").append(
|
||||
y - l1.getBlockY() - centerY).append(", ").append(z - l1.getBlockZ() - centerZ).append(", ")
|
||||
scriptBuilder.append("block(").append(x - firstCorner.getBlockX() - centerX).append(", y + ").append(
|
||||
y - firstCorner.getBlockY() - centerY).append(", ").append(z - firstCorner.getBlockZ() - centerZ).append(", ")
|
||||
.append("\"");
|
||||
scriptBuilder.append(data.getAsString()).append("\");\n");
|
||||
}
|
||||
@@ -93,12 +96,12 @@ public class StructureExportCommand implements CommandTemplate {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error creating file to export", e);
|
||||
}
|
||||
try(BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
|
||||
writer.write(scriptBuilder.toString());
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error writing script file", e);
|
||||
}
|
||||
|
||||
sender.sendMessage("Exported structure to " + file.getAbsolutePath());
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.dfsek.terra.addons.structure.structures.loot.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -15,6 +17,8 @@ import com.dfsek.terra.api.inventory.item.ItemMeta;
|
||||
|
||||
|
||||
public class EnchantFunction implements LootFunction {
|
||||
private static final Logger logger = LoggerFactory.getLogger(EnchantFunction.class);
|
||||
|
||||
private final int min;
|
||||
private final int max;
|
||||
private final JSONArray disabled;
|
||||
@@ -60,9 +64,8 @@ public class EnchantFunction implements LootFunction {
|
||||
try {
|
||||
meta.addEnchantment(chosen, FastMath.max(lvl, 1));
|
||||
} catch(IllegalArgumentException e) {
|
||||
main.logger().warning(
|
||||
"Attempted to enchant " + original.getType() + " with " + chosen + " at level " + FastMath.max(lvl, 1) +
|
||||
", but an unexpected exception occurred! Usually this is caused by a misbehaving enchantment plugin.");
|
||||
logger.warn("Attempted to enchant {} with {} at level {}, but an unexpected exception occurred! Usually this is caused " +
|
||||
"by a misbehaving enchantment plugin.", original.getType(), chosen, FastMath.max(lvl, 1));
|
||||
}
|
||||
}
|
||||
original.setItemMeta(meta);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.dfsek.terra.addons.yaml;
|
||||
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
@@ -16,6 +18,8 @@ import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
@Version("1.0.0")
|
||||
@Author("Terra")
|
||||
public class YamlAddon extends TerraAddon {
|
||||
private static final Logger logger = LoggerFactory.getLogger(YamlAddon.class);
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@@ -25,7 +29,7 @@ public class YamlAddon extends TerraAddon {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationDiscoveryEvent.class)
|
||||
.then(event -> event.getLoader().open("", ".yml").thenEntries(entries -> entries.forEach(entry -> {
|
||||
main.getDebugLogger().info("Discovered config " + entry.getKey());
|
||||
logger.info("Discovered config {}", entry.getKey());
|
||||
event.register(entry.getKey(), new YamlConfiguration(entry.getValue(), entry.getKey()));
|
||||
})))
|
||||
.failThrough();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.addons.terrascript.buffer.items;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.base.Properties;
|
||||
@@ -9,6 +12,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 TerraPlugin main;
|
||||
@@ -32,8 +37,7 @@ public class BufferedBlock implements BufferedItem {
|
||||
world.setBlockData(origin, data);
|
||||
}
|
||||
} catch(RuntimeException e) {
|
||||
main.logger().severe("Failed to place block at location " + origin + ": " + e.getMessage());
|
||||
main.getDebugLogger().stack(e);
|
||||
logger.error("Failed to place block at location {}", origin, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.addons.terrascript.buffer.items;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.script.StructureScript;
|
||||
@@ -14,6 +17,8 @@ import com.dfsek.terra.api.world.World;
|
||||
|
||||
|
||||
public class BufferedLootApplication implements BufferedItem {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BufferedLootApplication.class);
|
||||
|
||||
private final LootTable table;
|
||||
private final TerraPlugin main;
|
||||
private final StructureScript structure;
|
||||
@@ -28,12 +33,11 @@ public class BufferedLootApplication implements BufferedItem {
|
||||
public void paste(Vector3 origin, World world) {
|
||||
try {
|
||||
BlockEntity data = world.getBlockState(origin);
|
||||
if(!(data instanceof Container)) {
|
||||
main.logger().severe("Failed to place loot at " + origin + "; block " + data + " is not container.");
|
||||
if(!(data instanceof Container container)) {
|
||||
logger.error("Failed to place loot at {}; block {} is not container.", origin, data);
|
||||
return;
|
||||
}
|
||||
Container container = (Container) data;
|
||||
|
||||
|
||||
LootPopulateEvent event = new LootPopulateEvent(container, table, world.getConfig().getPack(), structure);
|
||||
main.getEventManager().callEvent(event);
|
||||
if(event.isCancelled()) return;
|
||||
@@ -41,8 +45,7 @@ public class BufferedLootApplication implements BufferedItem {
|
||||
event.getTable().fillInventory(container.getInventory(), new Random(origin.hashCode()));
|
||||
data.update(false);
|
||||
} catch(Exception e) {
|
||||
main.logger().warning("Could not apply loot at " + origin + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
logger.warn("Could not apply loot at {}", origin, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.addons.terrascript.buffer.items;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||
@@ -8,6 +11,8 @@ import com.dfsek.terra.api.world.World;
|
||||
|
||||
|
||||
public class BufferedStateManipulator implements BufferedItem {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BufferedStateManipulator.class);
|
||||
|
||||
private final TerraPlugin main;
|
||||
private final String data;
|
||||
|
||||
@@ -23,8 +28,7 @@ public class BufferedStateManipulator implements BufferedItem {
|
||||
state.applyState(data);
|
||||
state.update(false);
|
||||
} catch(Exception e) {
|
||||
main.logger().warning("Could not apply BlockState at " + origin + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
logger.warn("Could not apply BlockState at {}", origin, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import net.jafama.FastMath;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -49,6 +51,8 @@ import com.dfsek.terra.api.world.World;
|
||||
|
||||
|
||||
public class StructureScript implements Structure {
|
||||
private static final Logger logger = LoggerFactory.getLogger(StructureScript.class);
|
||||
|
||||
private final Block block;
|
||||
private final String id;
|
||||
private final Cache<Vector3, StructureBuffer> cache;
|
||||
@@ -93,7 +97,7 @@ public class StructureScript implements Structure {
|
||||
.registerFunction("rotationDegrees", new ZeroArgFunctionBuilder<>(arguments -> arguments.getRotation().getDegrees(),
|
||||
Returnable.ReturnType.NUMBER))
|
||||
.registerFunction("print",
|
||||
new UnaryStringFunctionBuilder(string -> main.getDebugLogger().info("[" + tempID + "] " + string)))
|
||||
new UnaryStringFunctionBuilder(string -> logger.info("[{}] {}", tempID, string)))
|
||||
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> FastMath.abs(number.doubleValue())))
|
||||
.registerFunction("pow", new BinaryNumberFunctionBuilder(
|
||||
(number, number2) -> FastMath.pow(number.doubleValue(), number2.doubleValue())))
|
||||
@@ -175,8 +179,7 @@ public class StructureScript implements Structure {
|
||||
try {
|
||||
return block.apply(arguments).getLevel() != Block.ReturnLevel.FAIL;
|
||||
} catch(RuntimeException e) {
|
||||
main.logger().severe("Failed to generate structure at " + arguments.getBuffer().getOrigin() + ": " + e.getMessage());
|
||||
main.getDebugLogger().stack(e);
|
||||
logger.error("Failed to generate structure at {}: {}", arguments.getBuffer().getOrigin(), e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -21,6 +23,8 @@ import com.dfsek.terra.api.vector.Vector3;
|
||||
|
||||
|
||||
public class LootFunction implements Function<Void> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LootFunction.class);
|
||||
|
||||
private final Registry<LootTable> registry;
|
||||
private final Returnable<String> data;
|
||||
private final Returnable<Number> x, y, z;
|
||||
@@ -52,7 +56,7 @@ public class LootFunction implements Function<Void> {
|
||||
LootTable table = registry.get(id);
|
||||
|
||||
if(table == null) {
|
||||
main.logger().severe("No such loot table " + id);
|
||||
logger.error("No such loot table {}", id);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.dfsek.terra.addons.terrascript.tokenizer;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
@@ -11,6 +14,8 @@ import java.util.List;
|
||||
* Stream-like data structure that allows viewing future elements without consuming current.
|
||||
*/
|
||||
public class Lookahead {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Lookahead.class);
|
||||
|
||||
private final List<Char> buffer = new ArrayList<>();
|
||||
private final Reader input;
|
||||
private int index = 0;
|
||||
@@ -108,7 +113,7 @@ public class Lookahead {
|
||||
index++;
|
||||
return new Char((char) c, line, index);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error while fetching next token", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,7 @@ dependencies {
|
||||
"shadedApi"("com.dfsek.tectonic:common:2.1.2")
|
||||
|
||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||
|
||||
"shadedApi"("org.slf4j:slf4j-api:1.7.32")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.dfsek.terra.api;
|
||||
|
||||
public interface Logger {
|
||||
void info(String message);
|
||||
|
||||
void warning(String message);
|
||||
|
||||
void severe(String message);
|
||||
|
||||
default void stack(Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,6 @@ import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
* Represents a Terra mod/plugin instance.
|
||||
*/
|
||||
public interface TerraPlugin extends LoaderRegistrar {
|
||||
Logger logger();
|
||||
|
||||
boolean reload();
|
||||
|
||||
String platformName();
|
||||
@@ -50,8 +48,6 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
|
||||
ItemHandle getItemHandle();
|
||||
|
||||
Logger getDebugLogger();
|
||||
|
||||
EventManager getEventManager();
|
||||
|
||||
default String getVersion() {
|
||||
|
||||
@@ -3,6 +3,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;
|
||||
@@ -16,7 +18,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
@@ -28,7 +29,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.generic.Lazy;
|
||||
import com.dfsek.terra.api.util.mutable.MutableBoolean;
|
||||
import com.dfsek.terra.commands.CommandUtil;
|
||||
import com.dfsek.terra.commands.TerraCommandManager;
|
||||
@@ -40,7 +40,6 @@ import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.CheckedRegistryImpl;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.util.logging.DebugLogger;
|
||||
|
||||
|
||||
/**
|
||||
@@ -49,9 +48,10 @@ import com.dfsek.terra.util.logging.DebugLogger;
|
||||
* Implementations must invoke {@link #load()} in their constructors.
|
||||
*/
|
||||
public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractTerraPlugin.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);
|
||||
@@ -66,19 +66,11 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(this);
|
||||
|
||||
private final Lazy<Logger> logger = Lazy.lazy(() -> createLogger());
|
||||
private final Lazy<DebugLogger> debugLogger = Lazy.lazy(() -> new DebugLogger(logger()));
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
loaders.register(registry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger logger() {
|
||||
return logger.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginConfig getTerraConfig() {
|
||||
return config;
|
||||
@@ -99,11 +91,6 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
return addonRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getDebugLogger() {
|
||||
return debugLogger.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventManager getEventManager() {
|
||||
return eventManager;
|
||||
@@ -122,7 +109,7 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
}
|
||||
LOADED.set(true);
|
||||
|
||||
logger().info("Initializing Terra...");
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
getPlatformAddon().ifPresent(addonRegistry::register);
|
||||
|
||||
@@ -132,7 +119,7 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
FileUtils.copyInputStreamToFile(stream, configFile);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config.yml resource from jar", e);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,16 +130,17 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
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();
|
||||
@@ -167,14 +155,12 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
}
|
||||
}));
|
||||
} 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();
|
||||
}
|
||||
@@ -184,20 +170,18 @@ public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
if(!addonRegistry.loadAll(getClass().getClassLoader())) { // load all addons
|
||||
throw new IllegalStateException("Failed to load addons. Please correct addon installations to continue.");
|
||||
}
|
||||
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<TerraAddon> getPlatformAddon() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
import com.dfsek.terra.api.addon.annotations.Author;
|
||||
@@ -12,6 +15,8 @@ import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class InternalAddon extends TerraAddon {
|
||||
private static final Logger logger = LoggerFactory.getLogger(InternalAddon.class);
|
||||
|
||||
private final AbstractTerraPlugin main;
|
||||
|
||||
public InternalAddon(AbstractTerraPlugin main) {
|
||||
@@ -24,9 +29,9 @@ public class InternalAddon extends TerraAddon {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, PlatformInitializationEvent.class)
|
||||
.then(event -> {
|
||||
main.logger().info("Loading config packs...");
|
||||
logger.info("Loading config packs...");
|
||||
main.getRawConfigRegistry().loadAll(main);
|
||||
main.logger().info("Loaded packs.");
|
||||
logger.info("Loaded packs.");
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.commands.profiler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
@@ -11,6 +14,8 @@ import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
@Command
|
||||
@DebugCommand
|
||||
public class ProfileQueryCommand implements CommandTemplate {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProfileQueryCommand.class);
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@@ -18,7 +23,7 @@ public class ProfileQueryCommand implements CommandTemplate {
|
||||
public void execute(CommandSender sender) {
|
||||
StringBuilder data = new StringBuilder("Terra Profiler data dump: \n");
|
||||
main.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n'));
|
||||
main.logger().info(data.toString());
|
||||
logger.info(data.toString());
|
||||
sender.sendMessage("Profiler data dumped to console.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,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;
|
||||
@@ -13,19 +15,20 @@ import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.time.Duration;
|
||||
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
|
||||
|
||||
@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
|
||||
@@ -77,20 +80,20 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
|
||||
|
||||
@Override
|
||||
public void load(TerraPlugin main) {
|
||||
Logger logger = main.logger();
|
||||
logger.info("Loading config values");
|
||||
try(FileInputStream file = new FileInputStream(new File(main.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(isDebugCommands())
|
||||
logger.info("Debug commands enabled.");
|
||||
if(isDebugProfiler())
|
||||
logger.info("Debug profiler enabled.");
|
||||
if(isDebugScript())
|
||||
logger.info("Script debug blocks enabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
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;
|
||||
@@ -14,6 +17,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) {
|
||||
@@ -34,11 +39,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,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;
|
||||
@@ -15,6 +17,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
|
||||
@@ -51,7 +55,7 @@ public abstract class LoaderImpl implements Loader {
|
||||
try {
|
||||
input.close();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.warn("Error occurred while loading", e);
|
||||
}
|
||||
});
|
||||
streams.clear();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
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;
|
||||
@@ -8,6 +11,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) {
|
||||
@@ -33,7 +38,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
package com.dfsek.terra.config.lang;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.lang.Language;
|
||||
|
||||
|
||||
public final class LangUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LangUtil.class);
|
||||
|
||||
private static Language language;
|
||||
|
||||
public static void load(String langID, TerraPlugin main) {
|
||||
Logger logger = main.logger();
|
||||
File file = new File(main.getDataFolder(), "lang");
|
||||
try {
|
||||
File file1 = new File(file, langID + ".yml");
|
||||
logger.info(file1.getAbsolutePath());
|
||||
language = new LanguageImpl(file1);
|
||||
logger.info("Loaded language " + langID);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,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;
|
||||
@@ -78,6 +80,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();
|
||||
@@ -127,7 +131,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
logger.info("Loading config pack \"{}\"", template.getID());
|
||||
load(l, main);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
@@ -138,7 +142,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
throw new LoadException("No pack.yml file found in " + folder.getAbsolutePath(), e);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
main.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.
|
||||
@@ -177,7 +181,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
logger.info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
load(l, main);
|
||||
|
||||
@@ -190,7 +194,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
throw new LoadException("Unable to load pack.yml from ZIP file", e);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
main.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;
|
||||
}
|
||||
|
||||
@@ -281,16 +285,14 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
OpenRegistry<T> registry = new OpenRegistryImpl<>();
|
||||
selfLoader.registerLoader(c, registry);
|
||||
abstractConfigLoader.registerLoader(c, registry);
|
||||
main.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)) {
|
||||
@@ -299,8 +301,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
(Registry<Supplier<ObjectTemplate<Supplier<ObjectTemplate<?>>>>>) registry);
|
||||
selfLoader.registerLoader(templateType, loader);
|
||||
abstractConfigLoader.registerLoader(templateType, loader);
|
||||
main.getDebugLogger().info(
|
||||
"Registered template loader for registry of class " + ReflectionUtil.typeToString(templateType));
|
||||
logger.debug("Registered template loader for registry of class {}", ReflectionUtil.typeToString(templateType));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,13 +362,9 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
}
|
||||
|
||||
private void checkDeadEntries(TerraPlugin main) {
|
||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft()).getDeadEntries()
|
||||
.forEach((id, value) -> main.getDebugLogger()
|
||||
.warning("Dead entry in '" +
|
||||
ReflectionUtil.typeToString(
|
||||
clazz) +
|
||||
"' registry: '" +
|
||||
id + "'")));
|
||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft())
|
||||
.getDeadEntries()
|
||||
.forEach((id, value) -> logger.warn("Dead entry in '{}' registry: '{}'", ReflectionUtil.typeToString(clazz), id)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@@ -431,9 +428,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
}
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
main.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() {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
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;
|
||||
@@ -21,6 +22,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 TerraPlugin main;
|
||||
@@ -42,13 +45,10 @@ 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));
|
||||
main.logger().warning("Exception occurred during event handling:");
|
||||
main.logger().warning(writer.toString());
|
||||
main.logger().warning(
|
||||
"Report this to the maintainers of " + context.getAddon().getName() + ", " + context.getAddon().getAuthor());
|
||||
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().getName(), context.getAddon().getAuthor(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.registry.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@@ -10,6 +13,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 TerraPlugin main;
|
||||
@@ -23,8 +28,8 @@ public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
|
||||
@Override
|
||||
public boolean register(String identifier, Entry<ConfigType<?, ?>> value) {
|
||||
callback.accept(identifier, value.getValue());
|
||||
main.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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.registry.master;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -13,6 +15,7 @@ import com.dfsek.terra.addon.PreLoadAddon;
|
||||
import com.dfsek.terra.addon.exception.AddonLoadException;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.injection.Injector;
|
||||
import com.dfsek.terra.api.injection.exception.InjectionException;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.inject.InjectorImpl;
|
||||
@@ -20,6 +23,8 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
|
||||
|
||||
public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(AddonRegistry.class);
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
public AddonRegistry(TerraPlugin main) {
|
||||
@@ -35,7 +40,7 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
public boolean register(String identifier, TerraAddon addon) {
|
||||
if(contains(identifier)) throw new IllegalArgumentException("Addon " + identifier + " is already registered.");
|
||||
addon.initialize();
|
||||
main.logger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor());
|
||||
logger.info("Loaded addon {} v{}, by {}", addon.getName(), addon.getVersion(), addon.getAuthor());
|
||||
return super.register(identifier, addon);
|
||||
}
|
||||
|
||||
@@ -52,6 +57,7 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
return loadAll(TerraPlugin.class.getClassLoader());
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "NestedTryStatement", "ThrowCaughtLocally" })
|
||||
public boolean loadAll(ClassLoader parent) {
|
||||
InjectorImpl<TerraPlugin> pluginInjector = new InjectorImpl<>(main);
|
||||
pluginInjector.addExplicitTarget(TerraPlugin.class);
|
||||
@@ -64,7 +70,7 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
|
||||
try {
|
||||
for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) {
|
||||
main.logger().info("Loading Addon(s) from: " + jar.getName());
|
||||
logger.info("Loading Addon(s) from: " + jar.getName());
|
||||
for(Class<? extends TerraAddon> addonClass : AddonClassLoader.fetchAddonClasses(jar, parent)) {
|
||||
pool.add(new PreLoadAddon(addonClass, jar));
|
||||
}
|
||||
@@ -82,8 +88,9 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
if(!LogManager.getLogManager().addLogger(addonLogger)) {
|
||||
addonLogger = LogManager.getLogManager().getLogger(logPrefix);
|
||||
}
|
||||
|
||||
InjectorImpl<Logger> loggerInjector = new InjectorImpl<>(addonLogger);
|
||||
|
||||
// TODO: 2021-08-30 Remove logger injector entirely?
|
||||
Injector<Logger> loggerInjector = new InjectorImpl<>(addonLogger);
|
||||
loggerInjector.addExplicitTarget(Logger.class);
|
||||
|
||||
try {
|
||||
@@ -97,19 +104,24 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
pluginInjector.inject(loadedAddon);
|
||||
loggerInjector.inject(loadedAddon);
|
||||
} catch(InstantiationException | IllegalAccessException | InvocationTargetException | InjectionException e) {
|
||||
throw new AddonLoadException("Failed to load com.dfsek.terra.addon \" + " + addon.getId() + "\": ", e);
|
||||
throw new AddonLoadException(String.format("Failed to load addon \"%s\"", addon.getId()), e);
|
||||
}
|
||||
try {
|
||||
registerChecked(loadedAddon.getName(), loadedAddon);
|
||||
} catch(DuplicateEntryException e) {
|
||||
valid = false;
|
||||
main.logger().severe("Duplicate addon ID; addon with ID " + loadedAddon.getName() + " is already loaded.");
|
||||
main.logger().severe("Existing addon class: " + get(loadedAddon.getName()).getClass().getCanonicalName());
|
||||
main.logger().severe("Duplicate addon class: " + addonClass.getCanonicalName());
|
||||
logger.error("""
|
||||
Duplicate addon ID; addon with ID {} is already loaded.
|
||||
Existing addon class: {}
|
||||
Duplicate addon class: {}
|
||||
""",
|
||||
loadedAddon.getName(),
|
||||
get(loadedAddon.getName()).getClass().getCanonicalName(),
|
||||
addonClass.getCanonicalName());
|
||||
}
|
||||
}
|
||||
} catch(AddonLoadException | IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Failed during addon loading", e);
|
||||
valid = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,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;
|
||||
@@ -16,6 +18,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, TerraPlugin main) throws ConfigException {
|
||||
ConfigPack pack = new ConfigPackImpl(folder, main);
|
||||
register(pack.getID(), pack);
|
||||
@@ -29,16 +33,16 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
try {
|
||||
load(dir, main);
|
||||
} 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 {
|
||||
main.getDebugLogger().info("Loading ZIP archive: " + zip.getName());
|
||||
logger.info("Loading ZIP archive: " + zip.getName());
|
||||
load(new ZipFile(zip), main);
|
||||
} catch(IOException | ConfigException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config pack {}", zip.getName(), e);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.dfsek.terra.util.logging;
|
||||
|
||||
import com.dfsek.terra.api.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,27 +0,0 @@
|
||||
package com.dfsek.terra.util.logging;
|
||||
|
||||
import com.dfsek.terra.api.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,8 @@ val purpurURL = "https://ci.pl3x.net/job/Purpur/lastSuccessfulBuild/artifact/fin
|
||||
dependencies {
|
||||
"shadedApi"(project(":common:implementation"))
|
||||
|
||||
"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")
|
||||
|
||||
|
||||
@@ -8,6 +8,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;
|
||||
@@ -31,6 +33,7 @@ import com.dfsek.terra.commands.TerraCommandManager;
|
||||
|
||||
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();
|
||||
@@ -53,9 +56,9 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Running on version " + BUKKIT_VERSION);
|
||||
logger.info("Running on version {}", BUKKIT_VERSION);
|
||||
if(BUKKIT_VERSION == BukkitVersion.UNKNOWN) {
|
||||
getLogger().warning("Terra is running on an unknown Bukkit version. Proceed with caution.");
|
||||
logger.warn("Terra is running on an unknown Bukkit version. Proceed with caution.");
|
||||
}
|
||||
|
||||
terraPlugin.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
@@ -72,9 +75,12 @@ 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.
|
||||
""", e);
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
@@ -115,21 +121,21 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
|
||||
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.");
|
||||
logger.error("You are using an outdated version of Paper.");
|
||||
logger.error("This version does not contain StructureLocateEvent.");
|
||||
logger.error("Terra will now fall back to Spigot events.");
|
||||
logger.error("This will prevent cartographer villagers from spawning,");
|
||||
logger.error("and cause structure location to not function.");
|
||||
logger.error("If you want these functionalities, update to the latest build of Paper.");
|
||||
logger.error("If you use a fork, update to the latest version, then if you still");
|
||||
logger.error("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/");
|
||||
logger.error("Paper is not in use. Falling back to Spigot events.");
|
||||
logger.error("This will prevent cartographer villagers from spawning,");
|
||||
logger.error("and cause structure location to not function.");
|
||||
logger.error("If you want these functionalities (and all the other");
|
||||
logger.error("benefits that Paper offers), upgrade your server to Paper.");
|
||||
logger.error("Find out more at https://papermc.io/");
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new SpigotListener(terraPlugin), this); // Register Spigot event listener
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.AbstractTerraPlugin;
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
@@ -19,7 +18,6 @@ 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 TerraPluginImpl extends AbstractTerraPlugin {
|
||||
@@ -78,11 +76,6 @@ public class TerraPluginImpl extends AbstractTerraPlugin {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Logger createLogger() {
|
||||
return new JavaLogger(plugin.getLogger());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<TerraAddon> getPlatformAddon() {
|
||||
return Optional.of(new BukkitAddon(this));
|
||||
|
||||
@@ -6,6 +6,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;
|
||||
@@ -20,6 +22,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) {
|
||||
@@ -51,7 +55,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,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;
|
||||
@@ -23,6 +25,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<>();
|
||||
|
||||
@@ -44,17 +47,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) {
|
||||
@@ -63,7 +66,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;
|
||||
|
||||
@@ -7,6 +7,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.TerraPlugin;
|
||||
|
||||
@@ -18,6 +20,8 @@ import com.dfsek.terra.api.TerraPlugin;
|
||||
* StructureLocateEvent).
|
||||
*/
|
||||
public class SpigotListener implements Listener {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpigotListener.class);
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
public SpigotListener(TerraPlugin main) {
|
||||
@@ -26,46 +30,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)) {
|
||||
main.logger().severe("Prevented server crash by stopping Cartographer villager from spawning.");
|
||||
main.logger().severe("Please upgrade to Paper, which has a StructureLocateEvent that fixes this issue");
|
||||
main.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. |
|
||||
|------------------------------------------------------------------------|
|
||||
""");
|
||||
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)) {
|
||||
main.logger().severe("Prevented server crash by stopping Cartographer villager from spawning.");
|
||||
main.logger().severe("Please upgrade to Paper, which has a StructureLocateEvent that fixes this issue");
|
||||
main.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. |
|
||||
|------------------------------------------------------------------------|
|
||||
""");
|
||||
e.getEntity().setProfession(Villager.Profession.NITWIT); // Give villager new profession to prevent server crash.
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ tasks.named<ShadowJar>("shadowJar") {
|
||||
dependencies {
|
||||
"shadedApi"(project(":common:implementation"))
|
||||
|
||||
"shadedImplementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
|
||||
|
||||
"minecraft"("com.mojang:minecraft:1.17.1")
|
||||
"mappings"("net.fabricmc:yarn:1.17.1+build.1:v2")
|
||||
"modImplementation"("net.fabricmc:fabric-loader:0.11.3")
|
||||
|
||||
@@ -6,6 +6,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;
|
||||
@@ -33,6 +35,8 @@ import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public final class FabricAddon extends TerraAddon {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FabricAddon.class);
|
||||
|
||||
private final TerraPluginImpl terraFabricPlugin;
|
||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||
|
||||
@@ -50,7 +54,7 @@ public final class FabricAddon extends TerraAddon {
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config template", e);
|
||||
}
|
||||
|
||||
if(template.doRegistryInjection()) {
|
||||
@@ -59,8 +63,7 @@ public final class FabricAddon extends TerraAddon {
|
||||
try {
|
||||
event.getPack().getCheckedRegistry(Tree.class).register(entry.getKey().getValue().toString(),
|
||||
(Tree) entry.getValue());
|
||||
terraFabricPlugin.getDebugLogger().info(
|
||||
"Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree.");
|
||||
logger.info("Injected ConfiguredFeature {} as Tree.", entry.getKey().getValue());
|
||||
} catch(DuplicateEntryException ignored) {
|
||||
}
|
||||
}
|
||||
@@ -79,7 +82,7 @@ public final class FabricAddon extends TerraAddon {
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Error loading config templatE", e);
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
@@ -91,7 +94,7 @@ public final class FabricAddon extends TerraAddon {
|
||||
.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(
|
||||
@@ -102,7 +105,7 @@ public final class FabricAddon extends TerraAddon {
|
||||
pack, id)),
|
||||
FabricUtil.createBiome(biome, pack,
|
||||
event.getRegistryManager())))); // Register all Terra biomes.
|
||||
terraFabricPlugin.logger().info("Biomes registered.");
|
||||
logger.info("Biomes registered.");
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
@@ -5,13 +5,11 @@ import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.AbstractTerraPlugin;
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
@@ -72,27 +70,6 @@ public class TerraPluginImpl extends AbstractTerraPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<TerraAddon> getPlatformAddon() {
|
||||
return Optional.of(new FabricAddon(this));
|
||||
|
||||
@@ -25,6 +25,8 @@ import net.minecraft.world.gen.chunk.StructuresConfig;
|
||||
import net.minecraft.world.gen.chunk.VerticalBlockSample;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -42,6 +44,8 @@ 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")
|
||||
@@ -71,7 +75,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
this.pack = configPack;
|
||||
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
delegate.getMain().logger().info("Loading world with config pack " + pack.getID());
|
||||
logger.info("Loading world with config pack {}", pack.getID());
|
||||
this.biomeSource = biomeSource;
|
||||
|
||||
this.seed = seed;
|
||||
|
||||
@@ -10,6 +10,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;
|
||||
@@ -18,12 +20,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import com.dfsek.terra.fabric.FabricEntryPoint;
|
||||
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,
|
||||
@@ -31,7 +34,7 @@ public abstract class ServerWorldMixin {
|
||||
boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
|
||||
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
|
||||
((FabricChunkGeneratorWrapper) chunkGenerator).setWorld((ServerWorld) (Object) this);
|
||||
FabricEntryPoint.getTerraPlugin().logger().info("Registered world " + this);
|
||||
logger.info("Registered world {}", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ java {
|
||||
|
||||
dependencies {
|
||||
"shadedApi"(project(":common:implementation"))
|
||||
|
||||
"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")
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.spongepowered.api.Sponge;
|
||||
import java.io.File;
|
||||
|
||||
import com.dfsek.terra.AbstractTerraPlugin;
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.sponge.handle.SpongeWorldHandle;
|
||||
@@ -44,24 +43,4 @@ public class TerraPluginImpl extends AbstractTerraPlugin {
|
||||
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