mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-20 07:10:24 +00:00
Merge remote-tracking branch 'origin/ver/6.0.0' into architecture/slf4j-logging
# Conflicts: # common/addons/chunk-generator-noise-3d/src/main/java/com/dfsek/terra/addons/chunkgenerator/generation/generators/NoiseChunkGenerator3D.java # common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/command/structure/StructureExportCommand.java # common/addons/config-structure/src/main/java/com/dfsek/terra/addons/structure/structures/loot/functions/EnchantFunction.java # common/addons/language-yaml/src/main/java/com/dfsek/terra/addons/yaml/YamlAddon.java # common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/buffer/items/BufferedBlock.java # common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/buffer/items/BufferedLootApplication.java # common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/buffer/items/BufferedStateManipulator.java # common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/StructureScript.java # common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/LootFunction.java # common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/script/functions/StructureFunction.java # common/api/core/src/main/java/com/dfsek/terra/api/Platform.java # common/implementation/src/main/java/com/dfsek/terra/AbstractPlatform.java # common/implementation/src/main/java/com/dfsek/terra/InternalAddon.java # common/implementation/src/main/java/com/dfsek/terra/commands/AddonsCommand.java # common/implementation/src/main/java/com/dfsek/terra/commands/ReloadCommand.java # common/implementation/src/main/java/com/dfsek/terra/commands/profiler/ProfileQueryCommand.java # common/implementation/src/main/java/com/dfsek/terra/config/PluginConfigImpl.java # common/implementation/src/main/java/com/dfsek/terra/config/lang/LangUtil.java # common/implementation/src/main/java/com/dfsek/terra/config/pack/ConfigPackImpl.java # common/implementation/src/main/java/com/dfsek/terra/event/FunctionalEventHandlerImpl.java # common/implementation/src/main/java/com/dfsek/terra/registry/config/ConfigTypeRegistry.java # common/implementation/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java # common/implementation/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java # platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitAddon.java # platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/PlatformImpl.java # platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java # platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricAddon.java # platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricEntryPoint.java # platforms/fabric/src/main/java/com/dfsek/terra/fabric/PlatformImpl.java # platforms/fabric/src/main/java/com/dfsek/terra/fabric/generation/FabricChunkGeneratorWrapper.java # platforms/sponge/src/main/java/com/dfsek/terra/sponge/PlatformImpl.java
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -18,7 +21,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
||||
@@ -43,12 +45,12 @@ import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton implementation of {@link TerraPlugin}
|
||||
* Skeleton implementation of {@link Platform}
|
||||
* <p>
|
||||
* Implementations must invoke {@link #load()} in their constructors.
|
||||
*/
|
||||
public abstract class AbstractTerraPlugin implements TerraPlugin {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractTerraPlugin.class);
|
||||
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);
|
||||
@@ -15,11 +15,10 @@ import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class InternalAddon extends TerraAddon {
|
||||
private final AbstractPlatform main;
|
||||
private static final Logger logger = LoggerFactory.getLogger(InternalAddon.class);
|
||||
|
||||
private final AbstractTerraPlugin main;
|
||||
|
||||
public InternalAddon(AbstractTerraPlugin main) {
|
||||
public InternalAddon(AbstractPlatform main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.commands;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
@@ -12,12 +12,12 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
)
|
||||
public class AddonsCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
sender.sendMessage("Installed Addons:");
|
||||
main.getAddons().forEach(addon -> {
|
||||
platform.getAddons().forEach(addon -> {
|
||||
sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.commands;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.command.annotation.type.DebugCommand;
|
||||
@@ -19,7 +19,7 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
)
|
||||
public class GetBlockCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.commands;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
@@ -15,11 +15,11 @@ import com.dfsek.terra.config.lang.LangUtil;
|
||||
)
|
||||
public class PacksCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
CheckedRegistry<ConfigPack> registry = main.getConfigRegistry();
|
||||
CheckedRegistry<ConfigPack> registry = platform.getConfigRegistry();
|
||||
|
||||
if(registry.entries().isEmpty()) {
|
||||
LangUtil.send("command.packs.none", sender);
|
||||
@@ -27,8 +27,6 @@ public class PacksCommand implements CommandTemplate {
|
||||
}
|
||||
|
||||
LangUtil.send("command.packs.main", sender);
|
||||
registry.entries().forEach(entry -> {
|
||||
LangUtil.send("command.packs.pack", sender, entry.getID(), entry.getAuthor(), entry.getVersion());
|
||||
});
|
||||
registry.entries().forEach(entry -> LangUtil.send("command.packs.pack", sender, entry.getID(), entry.getAuthor(), entry.getVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.dfsek.terra.commands;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
@@ -18,12 +18,12 @@ public class ReloadCommand implements CommandTemplate {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ReloadCommand.class);
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
logger.info("Reloading Terra...");
|
||||
if(main.reload()) {
|
||||
if(platform.reload()) {
|
||||
logger.info("Terra reloaded successfully.");
|
||||
LangUtil.send("command.reload", sender);
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.commands;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -12,7 +14,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Argument;
|
||||
@@ -40,13 +41,13 @@ import com.dfsek.terra.inject.InjectorImpl;
|
||||
|
||||
public class TerraCommandManager implements CommandManager {
|
||||
private final Map<String, CommandHolder> commands = new HashMap<>();
|
||||
private final InjectorImpl<TerraPlugin> pluginInjector;
|
||||
private final TerraPlugin main;
|
||||
private final InjectorImpl<Platform> pluginInjector;
|
||||
private final Platform platform;
|
||||
|
||||
public TerraCommandManager(TerraPlugin main) {
|
||||
this.main = main;
|
||||
this.pluginInjector = new InjectorImpl<>(main);
|
||||
pluginInjector.addExplicitTarget(TerraPlugin.class);
|
||||
public TerraCommandManager(Platform platform) {
|
||||
this.platform = platform;
|
||||
this.pluginInjector = new InjectorImpl<>(platform);
|
||||
pluginInjector.addExplicitTarget(Platform.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,7 +82,7 @@ public class TerraCommandManager implements CommandManager {
|
||||
private void execute(CommandHolder commandHolder, CommandSender sender, List<String> args) throws CommandException {
|
||||
Class<? extends CommandTemplate> commandClass = commandHolder.clazz;
|
||||
|
||||
if(commandClass.isAnnotationPresent(DebugCommand.class) && !main.getTerraConfig().isDebugCommands()) {
|
||||
if(commandClass.isAnnotationPresent(DebugCommand.class) && !platform.getTerraConfig().isDebugCommands()) {
|
||||
sender.sendMessage("Command must be executed with debug commands enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.commands;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
@@ -13,11 +13,11 @@ import com.dfsek.terra.config.lang.LangUtil;
|
||||
)
|
||||
public class VersionCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
String terraVersion = main.getVersion();
|
||||
LangUtil.send("command.version", sender, terraVersion, main.platformName());
|
||||
String terraVersion = platform.getVersion();
|
||||
LangUtil.send("command.version", sender, terraVersion, platform.platformName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ 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.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.command.annotation.type.DebugCommand;
|
||||
@@ -17,12 +17,12 @@ public class ProfileQueryCommand implements CommandTemplate {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProfileQueryCommand.class);
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
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'));
|
||||
platform.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n'));
|
||||
logger.info(data.toString());
|
||||
sender.sendMessage("Profiler data dumped to console.");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.commands.profiler;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.command.annotation.type.DebugCommand;
|
||||
@@ -12,11 +12,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
@DebugCommand
|
||||
public class ProfileResetCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
main.getProfiler().reset();
|
||||
platform.getProfiler().reset();
|
||||
sender.sendMessage("Profiler reset.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.commands.profiler;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.command.annotation.type.DebugCommand;
|
||||
@@ -12,11 +12,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
@DebugCommand
|
||||
public class ProfileStartCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
main.getProfiler().start();
|
||||
platform.getProfiler().start();
|
||||
sender.sendMessage("Profiling enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.commands.profiler;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.command.annotation.type.DebugCommand;
|
||||
@@ -12,11 +12,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
@DebugCommand
|
||||
public class ProfileStopCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
private Platform platform;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
main.getProfiler().stop();
|
||||
platform.getProfiler().stop();
|
||||
sender.sendMessage("Profiling disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
@@ -19,10 +19,10 @@ import com.dfsek.terra.config.loaders.RangeLoader;
|
||||
|
||||
|
||||
public class GenericLoaders implements LoaderRegistrar {
|
||||
private final TerraPlugin main;
|
||||
private final Platform platform;
|
||||
|
||||
public GenericLoaders(TerraPlugin main) {
|
||||
this.main = main;
|
||||
public GenericLoaders(Platform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,11 +32,11 @@ public class GenericLoaders implements LoaderRegistrar {
|
||||
.registerLoader(MaterialSet.class, new MaterialSetLoader())
|
||||
.registerLoader(LinkedHashMap.class, new LinkedHashMapLoader());
|
||||
|
||||
if(main != null) {
|
||||
registry.registerLoader(TerraAddon.class, main.getAddons())
|
||||
if(platform != null) {
|
||||
registry.registerLoader(TerraAddon.class, platform.getAddons())
|
||||
.registerLoader(BlockType.class,
|
||||
(t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType())
|
||||
.registerLoader(BlockState.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object));
|
||||
(t, object, cf) -> platform.getWorldHandle().createBlockData((String) object).getBlockType())
|
||||
.registerLoader(BlockState.class, (t, object, cf) -> platform.getWorldHandle().createBlockData((String) object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.time.Duration;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@@ -79,9 +79,9 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
|
||||
private int maxRecursion = 1000;
|
||||
|
||||
@Override
|
||||
public void load(TerraPlugin main) {
|
||||
public void load(Platform platform) {
|
||||
logger.info("Loading config values from config.yml");
|
||||
try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "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) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.lang.Language;
|
||||
|
||||
@@ -22,8 +22,9 @@ public final class LangUtil {
|
||||
|
||||
private LangUtil() { }
|
||||
|
||||
public static void load(String langID, TerraPlugin main) {
|
||||
File file = new File(main.getDataFolder(), "lang");
|
||||
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());
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.function.Supplier;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
@@ -89,7 +89,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
private final AbstractConfigLoader abstractConfigLoader = new AbstractConfigLoader();
|
||||
private final ConfigLoader selfLoader = new ConfigLoader();
|
||||
private final Scope varScope = new Scope();
|
||||
private final TerraPlugin main;
|
||||
private final Platform platform;
|
||||
private final Loader loader;
|
||||
|
||||
private final Configuration configuration;
|
||||
@@ -105,18 +105,18 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
private final TreeMap<Integer, List<ImmutablePair<String, ConfigType<?, ?>>>> configTypes = new TreeMap<>();
|
||||
|
||||
public ConfigPackImpl(File folder, TerraPlugin main) throws ConfigException {
|
||||
public ConfigPackImpl(File folder, Platform platform) throws ConfigException {
|
||||
try {
|
||||
this.loader = new FolderLoader(folder.toPath());
|
||||
this.main = main;
|
||||
this.platform = platform;
|
||||
this.configTypeRegistry = createRegistry();
|
||||
long l = System.nanoTime();
|
||||
|
||||
register(abstractConfigLoader);
|
||||
main.register(abstractConfigLoader);
|
||||
platform.register(abstractConfigLoader);
|
||||
|
||||
register(selfLoader);
|
||||
main.register(selfLoader);
|
||||
platform.register(selfLoader);
|
||||
|
||||
File pack = new File(folder, "pack.yml");
|
||||
|
||||
@@ -127,17 +127,17 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
selfLoader.load(addonsTemplate, configuration);
|
||||
this.addons = addonsTemplate.getAddons();
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
platform.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
|
||||
logger.info("Loading config pack \"{}\"", template.getID());
|
||||
load(l, main);
|
||||
load(l, platform);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
selfLoader.load(packPostTemplate, configuration);
|
||||
seededBiomeProvider = packPostTemplate.getProviderBuilder();
|
||||
checkDeadEntries(main);
|
||||
checkDeadEntries(platform);
|
||||
} catch(FileNotFoundException e) {
|
||||
throw new LoadException("No pack.yml file found in " + folder.getAbsolutePath(), e);
|
||||
}
|
||||
@@ -148,18 +148,18 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
toWorldConfig(new DummyWorld()); // Build now to catch any errors immediately.
|
||||
}
|
||||
|
||||
public ConfigPackImpl(ZipFile file, TerraPlugin main) throws ConfigException {
|
||||
public ConfigPackImpl(ZipFile file, Platform platform) throws ConfigException {
|
||||
try {
|
||||
this.loader = new ZIPLoader(file);
|
||||
this.main = main;
|
||||
this.platform = platform;
|
||||
this.configTypeRegistry = createRegistry();
|
||||
long l = System.nanoTime();
|
||||
|
||||
register(selfLoader);
|
||||
main.register(selfLoader);
|
||||
platform.register(selfLoader);
|
||||
|
||||
register(abstractConfigLoader);
|
||||
main.register(abstractConfigLoader);
|
||||
platform.register(abstractConfigLoader);
|
||||
|
||||
try {
|
||||
ZipEntry pack = null;
|
||||
@@ -177,19 +177,19 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
selfLoader.load(addonsTemplate, configuration);
|
||||
this.addons = addonsTemplate.getAddons();
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
platform.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
logger.info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
load(l, main);
|
||||
load(l, platform);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
|
||||
selfLoader.load(packPostTemplate, configuration);
|
||||
seededBiomeProvider = packPostTemplate.getProviderBuilder();
|
||||
checkDeadEntries(main);
|
||||
checkDeadEntries(platform);
|
||||
} catch(IOException e) {
|
||||
throw new LoadException("Unable to load pack.yml from ZIP file", e);
|
||||
}
|
||||
@@ -225,7 +225,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
@Override
|
||||
public WorldConfigImpl toWorldConfig(World world) {
|
||||
return new WorldConfigImpl(world, this, main);
|
||||
return new WorldConfigImpl(world, this, platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -273,93 +273,6 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
return template.vanillaDecorations();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ConfigTypeRegistry createRegistry() {
|
||||
return new ConfigTypeRegistry(main, (id, configType) -> {
|
||||
OpenRegistry<?> openRegistry = configType.registrySupplier(this).get();
|
||||
if(registryMap.containsKey(configType.getTypeKey()
|
||||
.getType())) { // Someone already registered something; we need to copy things to the
|
||||
// new registry.
|
||||
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);
|
||||
abstractConfigLoader.registerLoader(configType.getTypeKey().getType(), openRegistry);
|
||||
registryMap.put(configType.getTypeKey().getType(), ImmutablePair.of(openRegistry, new CheckedRegistryImpl<>(openRegistry)));
|
||||
});
|
||||
}
|
||||
|
||||
private void checkDeadEntries(TerraPlugin main) {
|
||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft())
|
||||
.getDeadEntries()
|
||||
.forEach((id, value) -> logger.warn("Dead entry in '{}' registry: '{}'", ReflectionUtil.typeToString(clazz), id)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private void load(long start, TerraPlugin main) throws ConfigException {
|
||||
configTypes.values().forEach(list -> list.forEach(pair -> configTypeRegistry.register(pair.getLeft(), pair.getRight())));
|
||||
|
||||
for(Map.Entry<String, Double> var : template.getVariables().entrySet()) {
|
||||
varScope.create(var.getKey(), var.getValue());
|
||||
}
|
||||
|
||||
Map<String, Configuration> configurations = new HashMap<>();
|
||||
|
||||
main.getEventManager().callEvent(new ConfigurationDiscoveryEvent(this, loader, configurations::put)); // Create all the configs.
|
||||
|
||||
MetaStringPreprocessor stringPreprocessor = new MetaStringPreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, stringPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, stringPreprocessor);
|
||||
|
||||
MetaListLikePreprocessor listPreprocessor = new MetaListLikePreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, listPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, listPreprocessor);
|
||||
|
||||
MetaMapPreprocessor mapPreprocessor = new MetaMapPreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, mapPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, mapPreprocessor);
|
||||
|
||||
MetaValuePreprocessor valuePreprocessor = new MetaValuePreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, valuePreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, valuePreprocessor);
|
||||
|
||||
MetaNumberPreprocessor numberPreprocessor = new MetaNumberPreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, numberPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, numberPreprocessor);
|
||||
|
||||
Map<ConfigType<? extends ConfigTemplate, ?>, List<Configuration>> configs = new HashMap<>();
|
||||
|
||||
for(Configuration configuration : configurations.values()) { // Sort the configs
|
||||
if(configuration.contains("type")) { // Only sort configs with type key
|
||||
ProtoConfig config = new ProtoConfig();
|
||||
selfLoader.load(config, configuration);
|
||||
configs.computeIfAbsent(config.getType(), configType -> new ArrayList<>()).add(configuration);
|
||||
}
|
||||
}
|
||||
|
||||
for(ConfigType<?, ?> configType : configTypeRegistry.entries()) { // Load the configs
|
||||
CheckedRegistry registry = getCheckedRegistry(configType.getTypeKey());
|
||||
main.getEventManager().callEvent(new ConfigTypePreLoadEvent(configType, registry, this));
|
||||
for(AbstractConfiguration config : abstractConfigLoader.loadConfigs(
|
||||
configs.getOrDefault(configType, Collections.emptyList()))) {
|
||||
try {
|
||||
Object loaded = ((ConfigFactory) configType.getFactory()).build(
|
||||
selfLoader.load(configType.getTemplate(this, main), config), main);
|
||||
registry.register(config.getID(), loaded);
|
||||
main.getEventManager().callEvent(
|
||||
new ConfigurationLoadEvent(this, config, template -> selfLoader.load(template, config), configType, loaded));
|
||||
} catch(DuplicateEntryException e) {
|
||||
throw new LoadException("Duplicate registry entry: ", e);
|
||||
}
|
||||
}
|
||||
main.getEventManager().callEvent(new ConfigTypePostLoadEvent(configType, registry, this));
|
||||
}
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
logger.info("Loaded config pack \"{}\" v{} by {} in {}ms.",
|
||||
template.getID(), template.getVersion(), template.getAuthor(), (System.nanoTime() - start) / 1000000.0D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider getBiomeProviderBuilder() {
|
||||
return seededBiomeProvider;
|
||||
@@ -373,7 +286,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
selfLoader.registerLoader(c, registry);
|
||||
abstractConfigLoader.registerLoader(c, registry);
|
||||
logger.debug("Registered loader for registry of class {}", ReflectionUtil.typeToString(c));
|
||||
|
||||
|
||||
if(type instanceof ParameterizedType param) {
|
||||
Type base = param.getRawType();
|
||||
if(base instanceof Class // should always be true but we'll check anyways
|
||||
@@ -393,7 +306,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ImmutablePair.of(registry, new CheckedRegistryImpl<>(registry));
|
||||
}).getRight();
|
||||
}
|
||||
@@ -433,6 +346,93 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
return template.getGeneratorProvider();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ConfigTypeRegistry createRegistry() {
|
||||
return new ConfigTypeRegistry(platform, (id, configType) -> {
|
||||
OpenRegistry<?> openRegistry = configType.registrySupplier(this).get();
|
||||
if(registryMap.containsKey(configType.getTypeKey()
|
||||
.getType())) { // Someone already registered something; we need to copy things to the
|
||||
// new registry.
|
||||
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);
|
||||
abstractConfigLoader.registerLoader(configType.getTypeKey().getType(), openRegistry);
|
||||
registryMap.put(configType.getTypeKey().getType(), ImmutablePair.of(openRegistry, new CheckedRegistryImpl<>(openRegistry)));
|
||||
});
|
||||
}
|
||||
|
||||
private void checkDeadEntries(TerraPlugin main) {
|
||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft())
|
||||
.getDeadEntries()
|
||||
.forEach((id, value) -> logger.warn("Dead entry in '{}' registry: '{}'", ReflectionUtil.typeToString(clazz), id)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private void load(long start, Platform platform) throws ConfigException {
|
||||
configTypes.values().forEach(list -> list.forEach(pair -> configTypeRegistry.register(pair.getLeft(), pair.getRight())));
|
||||
|
||||
for(Map.Entry<String, Double> var : template.getVariables().entrySet()) {
|
||||
varScope.create(var.getKey(), var.getValue());
|
||||
}
|
||||
|
||||
Map<String, Configuration> configurations = new HashMap<>();
|
||||
|
||||
platform.getEventManager().callEvent(new ConfigurationDiscoveryEvent(this, loader, configurations::put)); // Create all the configs.
|
||||
|
||||
MetaStringPreprocessor stringPreprocessor = new MetaStringPreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, stringPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, stringPreprocessor);
|
||||
|
||||
MetaListLikePreprocessor listPreprocessor = new MetaListLikePreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, listPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, listPreprocessor);
|
||||
|
||||
MetaMapPreprocessor mapPreprocessor = new MetaMapPreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, mapPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, mapPreprocessor);
|
||||
|
||||
MetaValuePreprocessor valuePreprocessor = new MetaValuePreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, valuePreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, valuePreprocessor);
|
||||
|
||||
MetaNumberPreprocessor numberPreprocessor = new MetaNumberPreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, numberPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, numberPreprocessor);
|
||||
|
||||
Map<ConfigType<? extends ConfigTemplate, ?>, List<Configuration>> configs = new HashMap<>();
|
||||
|
||||
for(Configuration configuration : configurations.values()) { // Sort the configs
|
||||
if(configuration.contains("type")) { // Only sort configs with type key
|
||||
ProtoConfig config = new ProtoConfig();
|
||||
selfLoader.load(config, configuration);
|
||||
configs.computeIfAbsent(config.getType(), configType -> new ArrayList<>()).add(configuration);
|
||||
}
|
||||
}
|
||||
|
||||
for(ConfigType<?, ?> configType : configTypeRegistry.entries()) { // Load the configs
|
||||
CheckedRegistry registry = getCheckedRegistry(configType.getTypeKey());
|
||||
platform.getEventManager().callEvent(new ConfigTypePreLoadEvent(configType, registry, this));
|
||||
for(AbstractConfiguration config : abstractConfigLoader.loadConfigs(
|
||||
configs.getOrDefault(configType, Collections.emptyList()))) {
|
||||
try {
|
||||
Object loaded = ((ConfigFactory) configType.getFactory()).build(
|
||||
selfLoader.load(configType.getTemplate(this, platform), config), platform);
|
||||
registry.register(config.getID(), loaded);
|
||||
platform.getEventManager().callEvent(
|
||||
new ConfigurationLoadEvent(this, config, template -> selfLoader.load(template, config), configType, loaded));
|
||||
} catch(DuplicateEntryException e) {
|
||||
throw new LoadException("Duplicate registry entry: ", e);
|
||||
}
|
||||
}
|
||||
platform.getEventManager().callEvent(new ConfigTypePostLoadEvent(configType, registry, this));
|
||||
}
|
||||
|
||||
platform.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
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() {
|
||||
return registryMap;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.WorldConfig;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
@@ -25,10 +25,10 @@ public class WorldConfigImpl implements WorldConfig {
|
||||
|
||||
private final Map<Type, Registry<?>> registryMap = new HashMap<>();
|
||||
|
||||
public WorldConfigImpl(World world, ConfigPackImpl pack, TerraPlugin main) {
|
||||
public WorldConfigImpl(World world, ConfigPackImpl pack, Platform platform) {
|
||||
this.world = world;
|
||||
this.pack = pack;
|
||||
this.samplerCache = new SamplerCacheImpl(main, world);
|
||||
this.samplerCache = new SamplerCacheImpl(platform, world);
|
||||
|
||||
pack.getRegistryMap().forEach((clazz, pair) -> registryMap.put(clazz, new LockedRegistryImpl<>(pair.getLeft())));
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.dfsek.terra.event;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.event.EventHandler;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
@@ -12,11 +12,11 @@ import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
|
||||
public class EventManagerImpl implements EventManager {
|
||||
private final Map<Class<?>, EventHandler> handlers = new HashMap<>();
|
||||
private final TerraPlugin main;
|
||||
private final Platform platform;
|
||||
|
||||
public EventManagerImpl(TerraPlugin main) {
|
||||
this.main = main;
|
||||
registerHandler(FunctionalEventHandler.class, new FunctionalEventHandlerImpl(main)); // default handler
|
||||
public EventManagerImpl(Platform platform) {
|
||||
this.platform = platform;
|
||||
registerHandler(FunctionalEventHandler.class, new FunctionalEventHandlerImpl(platform)); // default handler
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
@@ -26,10 +26,10 @@ public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
||||
|
||||
private final Map<Type, List<EventContextImpl<?>>> contextMap = new HashMap<>();
|
||||
|
||||
private final TerraPlugin main;
|
||||
private final Platform platform;
|
||||
|
||||
public FunctionalEventHandlerImpl(TerraPlugin main) {
|
||||
this.main = main;
|
||||
public FunctionalEventHandlerImpl(Platform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -39,7 +39,7 @@ public class OpenRegistryImpl<T> implements OpenRegistry<T> {
|
||||
T obj = get((String) o);
|
||||
StringBuilder keys = new StringBuilder("[");
|
||||
|
||||
objects.keySet().forEach(key -> keys.append(key + ", "));
|
||||
objects.keySet().forEach(key -> keys.append(key).append(", "));
|
||||
|
||||
if(obj == null)
|
||||
throw new LoadException("No such " + type.getType().getTypeName() + " matching \"" + o +
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
@@ -17,12 +17,12 @@ public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
|
||||
|
||||
private final BiConsumer<String, ConfigType<?, ?>> callback;
|
||||
|
||||
private final TerraPlugin main;
|
||||
private final Platform platform;
|
||||
|
||||
public ConfigTypeRegistry(TerraPlugin main, BiConsumer<String, ConfigType<?, ?>> callback) {
|
||||
public ConfigTypeRegistry(Platform platform, BiConsumer<String, ConfigType<?, ?>> callback) {
|
||||
super(new LinkedHashMap<>()); // Ordered
|
||||
this.callback = callback;
|
||||
this.main = main;
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.dfsek.terra.addon.AddonClassLoader;
|
||||
import com.dfsek.terra.addon.AddonPool;
|
||||
import com.dfsek.terra.addon.PreLoadAddon;
|
||||
import com.dfsek.terra.addon.exception.AddonLoadException;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.inject.Injector;
|
||||
import com.dfsek.terra.api.inject.exception.InjectionException;
|
||||
@@ -25,14 +25,14 @@ 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;
|
||||
private final Platform platform;
|
||||
|
||||
public AddonRegistry(TerraPlugin main) {
|
||||
this.main = main;
|
||||
public AddonRegistry(Platform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
public AddonRegistry(TerraAddon addon, TerraPlugin main) {
|
||||
this.main = main;
|
||||
public AddonRegistry(TerraAddon addon, Platform platform) {
|
||||
this.platform = platform;
|
||||
register(addon);
|
||||
}
|
||||
|
||||
@@ -54,16 +54,16 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
|
||||
}
|
||||
|
||||
public boolean loadAll() {
|
||||
return loadAll(TerraPlugin.class.getClassLoader());
|
||||
return loadAll(Platform.class.getClassLoader());
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "NestedTryStatement", "ThrowCaughtLocally" })
|
||||
public boolean loadAll(ClassLoader parent) {
|
||||
InjectorImpl<TerraPlugin> pluginInjector = new InjectorImpl<>(main);
|
||||
pluginInjector.addExplicitTarget(TerraPlugin.class);
|
||||
InjectorImpl<Platform> pluginInjector = new InjectorImpl<>(platform);
|
||||
pluginInjector.addExplicitTarget(Platform.class);
|
||||
|
||||
boolean valid = true;
|
||||
File addonsFolder = new File(main.getDataFolder(), "addons");
|
||||
File addonsFolder = new File(platform.getDataFolder(), "addons");
|
||||
addonsFolder.mkdirs();
|
||||
|
||||
AddonPool pool = new AddonPool();
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.config.pack.ConfigPackImpl;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
@@ -20,18 +20,18 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
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);
|
||||
public void load(File folder, Platform platform) throws ConfigException {
|
||||
ConfigPack pack = new ConfigPackImpl(folder, platform);
|
||||
register(pack.getID(), pack);
|
||||
}
|
||||
|
||||
public boolean loadAll(TerraPlugin main) {
|
||||
public boolean loadAll(Platform platform) {
|
||||
boolean valid = true;
|
||||
File packsFolder = new File(main.getDataFolder(), "packs");
|
||||
File packsFolder = new File(platform.getDataFolder(), "packs");
|
||||
packsFolder.mkdirs();
|
||||
for(File dir : packsFolder.listFiles(File::isDirectory)) {
|
||||
try {
|
||||
load(dir, main);
|
||||
load(dir, platform);
|
||||
} catch(ConfigException e) {
|
||||
logger.error("Error loading config pack {}", dir.getName(), e);
|
||||
valid = false;
|
||||
@@ -40,7 +40,7 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".terra"))) {
|
||||
try {
|
||||
logger.info("Loading ZIP archive: " + zip.getName());
|
||||
load(new ZipFile(zip), main);
|
||||
load(new ZipFile(zip), platform);
|
||||
} catch(IOException | ConfigException e) {
|
||||
logger.error("Error loading config pack {}", zip.getName(), e);
|
||||
valid = false;
|
||||
@@ -49,8 +49,8 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void load(ZipFile file, TerraPlugin main) throws ConfigException {
|
||||
ConfigPackImpl pack = new ConfigPackImpl(file, main);
|
||||
public void load(ZipFile file, Platform platform) throws ConfigException {
|
||||
ConfigPackImpl pack = new ConfigPackImpl(file, platform);
|
||||
register(pack.getTemplate().getID(), pack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.world;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.util.math.Sampler;
|
||||
@@ -15,8 +16,8 @@ import com.dfsek.terra.api.util.math.Sampler;
|
||||
public class SamplerCacheImpl implements com.dfsek.terra.api.world.generator.SamplerCache {
|
||||
private final LoadingCache<Long, Sampler> cache;
|
||||
|
||||
public SamplerCacheImpl(TerraPlugin main, World world) {
|
||||
cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getSamplerCache())
|
||||
public SamplerCacheImpl(Platform platform, World world) {
|
||||
cache = CacheBuilder.newBuilder().maximumSize(platform.getTerraConfig().getSamplerCache())
|
||||
.build(new CacheLoader<>() {
|
||||
@Override
|
||||
public Sampler load(@NotNull Long key) {
|
||||
|
||||
@@ -30,9 +30,7 @@ public class ProfilerTest {
|
||||
PROFILER.push("thing4");
|
||||
PROFILER.pop("thing4");
|
||||
|
||||
PROFILER.getTimings().forEach((id, timings) -> {
|
||||
System.out.println(id + ": " + timings.toString());
|
||||
});
|
||||
PROFILER.getTimings().forEach((id, timings) -> System.out.println(id + ": " + timings.toString()));
|
||||
}
|
||||
|
||||
private static void doThing() throws InterruptedException {
|
||||
|
||||
Reference in New Issue
Block a user