rename main parameters/fields to platform

This commit is contained in:
dfsek
2021-09-26 13:22:45 -07:00
parent 8f51707505
commit 4945a3bbfa
117 changed files with 535 additions and 516 deletions

View File

@@ -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.yaml.snakeyaml.Yaml;
@@ -17,7 +20,6 @@ import java.util.Map;
import java.util.Optional;
import com.dfsek.terra.api.util.Logger;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.command.CommandManager;
import com.dfsek.terra.api.command.exception.MalformedCommandException;

View File

@@ -12,12 +12,12 @@ import com.dfsek.terra.api.inject.annotations.Inject;
)
public class AddonsCommand implements CommandTemplate {
@Inject
private Platform main;
private Platform platform;
@Override
public void execute(CommandSender sender) {
sender.sendMessage("Installed Addons:");
main.getAddons().forEach(
platform.getAddons().forEach(
addon -> sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor()));
}
}

View File

@@ -19,7 +19,7 @@ import com.dfsek.terra.api.inject.annotations.Inject;
)
public class GetBlockCommand implements CommandTemplate {
@Inject
private Platform main;
private Platform platform;
@Override
public void execute(CommandSender sender) {

View File

@@ -15,11 +15,11 @@ import com.dfsek.terra.config.lang.LangUtil;
)
public class PacksCommand implements CommandTemplate {
@Inject
private Platform main;
private Platform platform;
@Override
public void execute(CommandSender sender) {
CheckedRegistry<ConfigPack> registry = main.getConfigRegistry();
CheckedRegistry<ConfigPack> registry = platform.getConfigRegistry();
if(registry.entries().size() == 0) {
LangUtil.send("command.packs.none", sender);

View File

@@ -13,11 +13,11 @@ import com.dfsek.terra.config.lang.LangUtil;
)
public class ReloadCommand implements CommandTemplate {
@Inject
private Platform main;
private Platform platform;
@Override
public void execute(CommandSender sender) {
if(!main.reload()) {
if(!platform.reload()) {
LangUtil.send("command.reload-error", sender);
} else {
LangUtil.send("command.reload", sender);

View File

@@ -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.Platform;
import com.dfsek.terra.api.command.CommandManager;
import com.dfsek.terra.api.command.CommandTemplate;
import com.dfsek.terra.api.command.annotation.Argument;
@@ -41,11 +42,11 @@ import com.dfsek.terra.inject.InjectorImpl;
public class TerraCommandManager implements CommandManager {
private final Map<String, CommandHolder> commands = new HashMap<>();
private final InjectorImpl<Platform> pluginInjector;
private final Platform main;
private final Platform platform;
public TerraCommandManager(Platform main) {
this.main = main;
this.pluginInjector = new InjectorImpl<>(main);
public TerraCommandManager(Platform platform) {
this.platform = platform;
this.pluginInjector = new InjectorImpl<>(platform);
pluginInjector.addExplicitTarget(Platform.class);
}
@@ -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;
}

View File

@@ -13,11 +13,11 @@ import com.dfsek.terra.config.lang.LangUtil;
)
public class VersionCommand implements CommandTemplate {
@Inject
private Platform 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());
}
}

View File

@@ -12,13 +12,13 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@DebugCommand
public class ProfileQueryCommand implements CommandTemplate {
@Inject
private Platform 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'));
main.logger().info(data.toString());
platform.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n'));
platform.logger().info(data.toString());
sender.sendMessage("Profiler data dumped to console.");
}
}

View File

@@ -12,11 +12,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@DebugCommand
public class ProfileResetCommand implements CommandTemplate {
@Inject
private Platform main;
private Platform platform;
@Override
public void execute(CommandSender sender) {
main.getProfiler().reset();
platform.getProfiler().reset();
sender.sendMessage("Profiler reset.");
}
}

View File

@@ -12,11 +12,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@DebugCommand
public class ProfileStartCommand implements CommandTemplate {
@Inject
private Platform main;
private Platform platform;
@Override
public void execute(CommandSender sender) {
main.getProfiler().start();
platform.getProfiler().start();
sender.sendMessage("Profiling enabled.");
}
}

View File

@@ -12,11 +12,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@DebugCommand
public class ProfileStopCommand implements CommandTemplate {
@Inject
private Platform main;
private Platform platform;
@Override
public void execute(CommandSender sender) {
main.getProfiler().stop();
platform.getProfiler().stop();
sender.sendMessage("Profiling disabled.");
}
}

View File

@@ -19,10 +19,10 @@ import com.dfsek.terra.config.loaders.RangeLoader;
public class GenericLoaders implements LoaderRegistrar {
private final Platform main;
private final Platform platform;
public GenericLoaders(Platform 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));
}
}
}

View File

@@ -76,10 +76,10 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
private int maxRecursion = 1000;
@Override
public void load(Platform main) {
Logger logger = main.logger();
public void load(Platform platform) {
Logger logger = platform.logger();
logger.info("Loading config values");
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) {

View File

@@ -12,9 +12,9 @@ import com.dfsek.terra.api.lang.Language;
public final class LangUtil {
private static Language language;
public static void load(String langID, Platform main) {
Logger logger = main.logger();
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());

View File

@@ -85,7 +85,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 Platform main;
private final Platform platform;
private final Loader loader;
private final Configuration configuration;
@@ -101,18 +101,18 @@ public class ConfigPackImpl implements ConfigPack {
private final TreeMap<Integer, List<ImmutablePair<String, ConfigType<?, ?>>>> configTypes = new TreeMap<>();
public ConfigPackImpl(File folder, Platform 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");
@@ -123,39 +123,39 @@ 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);
main.logger().info("Loading config pack \"" + template.getID() + "\"");
load(l, main);
platform.logger().info("Loading config pack \"" + template.getID() + "\"");
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);
}
} catch(Exception e) {
main.logger().severe("Failed to load config pack from folder \"" + folder.getAbsolutePath() + "\"");
platform.logger().severe("Failed to load config pack from folder \"" + folder.getAbsolutePath() + "\"");
throw e;
}
toWorldConfig(new DummyWorld()); // Build now to catch any errors immediately.
}
public ConfigPackImpl(ZipFile file, Platform 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;
@@ -173,24 +173,24 @@ 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);
main.logger().info("Loading config pack \"" + template.getID() + "\"");
platform.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);
}
} catch(Exception e) {
main.logger().severe("Failed to load config pack from ZIP archive \"" + file.getName() + "\"");
platform.logger().severe("Failed to load config pack from ZIP archive \"" + file.getName() + "\"");
throw e;
}
@@ -221,7 +221,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
@@ -281,7 +281,7 @@ 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));
platform.getDebugLogger().info("Registered loader for registry of class " + ReflectionUtil.typeToString(c));
if(type instanceof ParameterizedType) {
ParameterizedType param = (ParameterizedType) type;
@@ -299,7 +299,7 @@ public class ConfigPackImpl implements ConfigPack {
(Registry<Supplier<ObjectTemplate<Supplier<ObjectTemplate<?>>>>>) registry);
selfLoader.registerLoader(templateType, loader);
abstractConfigLoader.registerLoader(templateType, loader);
main.getDebugLogger().info(
platform.getDebugLogger().info(
"Registered template loader for registry of class " + ReflectionUtil.typeToString(templateType));
}
}
@@ -347,12 +347,12 @@ public class ConfigPackImpl implements ConfigPack {
@SuppressWarnings("unchecked")
private ConfigTypeRegistry createRegistry() {
return new ConfigTypeRegistry(main, (id, configType) -> {
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.
main.getDebugLogger().warning("Copying values from old registry for " + configType.getTypeKey());
platform.getDebugLogger().warning("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);
@@ -361,10 +361,10 @@ public class ConfigPackImpl implements ConfigPack {
});
}
private void checkDeadEntries(Platform main) {
private void checkDeadEntries(Platform platform) {
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft()).getDeadEntries()
.forEach((id, value) -> main.getDebugLogger()
.warning("Dead entry in '" +
.forEach((id, value) -> platform.getDebugLogger()
.warning("Dead entry in '" +
ReflectionUtil.typeToString(
clazz) +
"' registry: '" +
@@ -372,7 +372,7 @@ public class ConfigPackImpl implements ConfigPack {
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void load(long start, Platform main) throws ConfigException {
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()) {
@@ -381,7 +381,7 @@ public class ConfigPackImpl implements ConfigPack {
Map<String, Configuration> configurations = new HashMap<>();
main.getEventManager().callEvent(new ConfigurationDiscoveryEvent(this, loader, configurations::put)); // Create all the configs.
platform.getEventManager().callEvent(new ConfigurationDiscoveryEvent(this, loader, configurations::put)); // Create all the configs.
MetaStringPreprocessor stringPreprocessor = new MetaStringPreprocessor(configurations);
selfLoader.registerPreprocessor(Meta.class, stringPreprocessor);
@@ -415,24 +415,24 @@ public class ConfigPackImpl implements ConfigPack {
for(ConfigType<?, ?> configType : configTypeRegistry.entries()) { // Load the configs
CheckedRegistry registry = getCheckedRegistry(configType.getTypeKey());
main.getEventManager().callEvent(new ConfigTypePreLoadEvent(configType, registry, this));
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, main), config), main);
selfLoader.load(configType.getTemplate(this, platform), config), platform);
registry.register(config.getID(), loaded);
main.getEventManager().callEvent(
platform.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));
platform.getEventManager().callEvent(new ConfigTypePostLoadEvent(configType, registry, this));
}
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
main.logger().info(
platform.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
platform.logger().info(
"Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " +
(System.nanoTime() - start) / 1000000D + "ms.");
}

View File

@@ -25,10 +25,10 @@ public class WorldConfigImpl implements WorldConfig {
private final Map<Type, Registry<?>> registryMap = new HashMap<>();
public WorldConfigImpl(World world, ConfigPackImpl pack, Platform 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())));

View File

@@ -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 Platform main;
private final Platform platform;
public EventManagerImpl(Platform 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

View File

@@ -23,10 +23,10 @@ import com.dfsek.terra.api.util.reflection.TypeKey;
public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
private final Map<Type, List<EventContextImpl<?>>> contextMap = new HashMap<>();
private final Platform main;
private final Platform platform;
public FunctionalEventHandlerImpl(Platform main) {
this.main = main;
public FunctionalEventHandlerImpl(Platform platform) {
this.platform = platform;
}
@SuppressWarnings("unchecked")
@@ -45,9 +45,9 @@ public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
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(
platform.logger().warning("Exception occurred during event handling:");
platform.logger().warning(writer.toString());
platform.logger().warning(
"Report this to the maintainers of " + context.getAddon().getName() + ", " + context.getAddon().getAuthor());
}
});

View File

@@ -12,19 +12,19 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
private final BiConsumer<String, ConfigType<?, ?>> callback;
private final Platform main;
private final Platform platform;
public ConfigTypeRegistry(Platform 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
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()));
platform.getDebugLogger().info("Registered config registry with ID " + identifier + " to type " +
ReflectionUtil.typeToString(value.getValue().getTypeKey().getType()));
return super.register(identifier, value);
}
}

View File

@@ -20,14 +20,14 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
private final Platform main;
private final Platform platform;
public AddonRegistry(Platform main) {
this.main = main;
public AddonRegistry(Platform platform) {
this.platform = platform;
}
public AddonRegistry(TerraAddon addon, Platform main) {
this.main = main;
public AddonRegistry(TerraAddon addon, Platform platform) {
this.platform = platform;
register(addon);
}
@@ -35,7 +35,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());
platform.logger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor());
return super.register(identifier, addon);
}
@@ -53,18 +53,18 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
}
public boolean loadAll(ClassLoader parent) {
InjectorImpl<Platform> pluginInjector = new InjectorImpl<>(main);
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();
try {
for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) {
main.logger().info("Loading Addon(s) from: " + jar.getName());
platform.logger().info("Loading Addon(s) from: " + jar.getName());
for(Class<? extends TerraAddon> addonClass : AddonClassLoader.fetchAddonClasses(jar, parent)) {
pool.add(new PreLoadAddon(addonClass, jar));
}
@@ -103,9 +103,9 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
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());
platform.logger().severe("Duplicate addon ID; addon with ID " + loadedAddon.getName() + " is already loaded.");
platform.logger().severe("Existing addon class: " + get(loadedAddon.getName()).getClass().getCanonicalName());
platform.logger().severe("Duplicate addon class: " + addonClass.getCanonicalName());
}
}
} catch(AddonLoadException | IOException e) {

View File

@@ -16,18 +16,18 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
* Class to hold config packs
*/
public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
public void load(File folder, Platform 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(Platform 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) {
e.printStackTrace();
valid = false;
@@ -35,8 +35,8 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
}
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".terra"))) {
try {
main.getDebugLogger().info("Loading ZIP archive: " + zip.getName());
load(new ZipFile(zip), main);
platform.getDebugLogger().info("Loading ZIP archive: " + zip.getName());
load(new ZipFile(zip), platform);
} catch(IOException | ConfigException e) {
e.printStackTrace();
valid = false;
@@ -45,8 +45,8 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
return valid;
}
public void load(ZipFile file, Platform 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);
}
}

View File

@@ -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.Platform;
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(Platform 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) {