Merge remote-tracking branch 'upstream/ver/6.0.0' into architecture/slf4j-logging

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
solonovamax
2021-11-20 20:09:40 -05:00
738 changed files with 5185 additions and 17062 deletions

View File

@@ -1,9 +1,23 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra;
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;
@@ -17,16 +31,25 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.addon.BootstrapAddonLoader;
import com.dfsek.terra.addon.DependencySorter;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.command.CommandManager;
import com.dfsek.terra.api.command.exception.MalformedCommandException;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.PluginConfig;
import com.dfsek.terra.api.event.EventManager;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.inject.Injector;
import com.dfsek.terra.api.inject.impl.InjectorImpl;
import com.dfsek.terra.api.lang.Language;
import com.dfsek.terra.api.profiler.Profiler;
import com.dfsek.terra.api.registry.CheckedRegistry;
@@ -40,7 +63,8 @@ import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.event.EventManagerImpl;
import com.dfsek.terra.profiler.ProfilerImpl;
import com.dfsek.terra.registry.CheckedRegistryImpl;
import com.dfsek.terra.registry.master.AddonRegistry;
import com.dfsek.terra.registry.LockedRegistryImpl;
import com.dfsek.terra.registry.OpenRegistryImpl;
import com.dfsek.terra.registry.master.ConfigRegistry;
@@ -66,7 +90,9 @@ public abstract class AbstractPlatform implements Platform {
private final CommandManager manager = new TerraCommandManager(this);
private final AddonRegistry addonRegistry = new AddonRegistry(this);
private final CheckedRegistry<BaseAddon> addonRegistry = new CheckedRegistryImpl<>(new OpenRegistryImpl<>());
private final Registry<BaseAddon> lockedAddonRegistry = new LockedRegistryImpl<>(addonRegistry);
@Override
public void register(TypeRegistry registry) {
@@ -89,8 +115,8 @@ public abstract class AbstractPlatform implements Platform {
}
@Override
public Registry<TerraAddon> getAddons() {
return addonRegistry;
public Registry<BaseAddon> getAddons() {
return lockedAddonRegistry;
}
@Override
@@ -98,6 +124,10 @@ public abstract class AbstractPlatform implements Platform {
return eventManager;
}
protected Optional<BaseAddon> platformAddon() {
return Optional.empty();
}
@Override
public Profiler getProfiler() {
return profiler;
@@ -113,8 +143,6 @@ public abstract class AbstractPlatform implements Platform {
logger.info("Initializing Terra...");
getPlatformAddon().ifPresent(addonRegistry::register);
try(InputStream stream = getClass().getResourceAsStream("/config.yml")) {
File configFile = new File(getDataFolder(), "config.yml");
if(!configFile.exists()) {
@@ -167,11 +195,52 @@ public abstract class AbstractPlatform implements Platform {
profiler.start();
}
addonRegistry.register(new InternalAddon(this));
List<BaseAddon> addonList = new ArrayList<>();
InternalAddon internalAddon = new InternalAddon();
addonList.add(internalAddon);
getPlatformAddon().ifPresent(addonList::add);
platformAddon().ifPresent(baseAddon -> {
baseAddon.initialize();
addonList.add(baseAddon);
});
BootstrapAddonLoader bootstrapAddonLoader = new BootstrapAddonLoader(this);
Path addonsFolder = getDataFolder().toPath().resolve("addons");
Injector<Platform> platformInjector = new InjectorImpl<>(this);
platformInjector.addExplicitTarget(Platform.class);
bootstrapAddonLoader.loadAddons(addonsFolder, getClass().getClassLoader())
.forEach(bootstrap -> {
platformInjector.inject(bootstrap);
bootstrap.loadAddons(addonsFolder, getClass().getClassLoader())
.forEach(addonList::add);
});
DependencySorter sorter = new DependencySorter();
addonList.forEach(sorter::add);
sorter.sort().forEach(addon -> {
platformInjector.inject(addon);
addon.initialize();
addonRegistry.register(addon.getID(), addon);
});
eventManager
.getHandler(FunctionalEventHandler.class)
.register(internalAddon, PlatformInitializationEvent.class)
.then(event -> {
logger.info("Loading config packs...");
getRawConfigRegistry().loadAll(this);
logger.info("Loaded packs.");
})
.global();
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.");
try {
@@ -184,7 +253,7 @@ public abstract class AbstractPlatform implements Platform {
logger.info("Finished initialization.");
}
protected Optional<TerraAddon> getPlatformAddon() {
protected Optional<BaseAddon> getPlatformAddon() {
return Optional.empty();
}

View File

@@ -1,37 +1,37 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ca.solostudios.strata.Versions;
import ca.solostudios.strata.version.Version;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.annotations.Addon;
import com.dfsek.terra.api.addon.annotations.Author;
import com.dfsek.terra.api.addon.annotations.Version;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.addon.BaseAddon;
@Addon("terra")
@Author("Terra")
@Version("1.0.0")
public class InternalAddon extends TerraAddon {
private final AbstractPlatform main;
private static final Logger logger = LoggerFactory.getLogger(InternalAddon.class);
public InternalAddon(AbstractPlatform main) {
this.main = main;
public class InternalAddon implements BaseAddon {
private static final Version VERSION = Versions.getVersion(1, 0, 0);
@Override
public String getID() {
return "terra";
}
@Override
public void initialize() {
main.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(this, PlatformInitializationEvent.class)
.then(event -> {
logger.info("Loading config packs...");
main.getRawConfigRegistry().loadAll(main);
logger.info("Loaded packs.");
})
.global();
public Version getVersion() {
return VERSION;
}
}

View File

@@ -0,0 +1,99 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.addon;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.dfsek.terra.addon.dependency.CircularDependencyException;
import com.dfsek.terra.addon.dependency.DependencyException;
import com.dfsek.terra.addon.dependency.DependencyVersionException;
import com.dfsek.terra.api.addon.BaseAddon;
public class DependencySorter {
private final Map<String, BaseAddon> addons = new HashMap<>();
private final Map<String, Boolean> visited = new HashMap<>();
private final List<BaseAddon> addonList = new ArrayList<>();
public void add(BaseAddon addon) {
addons.put(addon.getID(), addon);
visited.put(addon.getID(), false);
addonList.add(addon);
}
private void sortDependencies(BaseAddon addon, List<BaseAddon> sort) {
addon.getDependencies().forEach((id, range) -> {
if(!addons.containsKey(id)) {
throw new DependencyException("Addon " + addon.getID() + " specifies dependency on " + id + ", versions " + range +
", but no such addon is installed.");
}
BaseAddon dependency = addons.get(id);
if(!range.isSatisfiedBy(dependency.getVersion())) {
throw new DependencyVersionException("Addon " + addon.getID() + " specifies dependency on " + id + ", versions " + range +
", but non-matching version " + dependency.getVersion() + " is installed..");
}
if(!visited.get(dependency.getID())) { // if we've not visited it yet
visited.put(dependency.getID(), true); // we've visited it now
sortDependencies(dependency, sort);
sort.add(dependency); // add it to the list.
}
});
}
private void checkDependencies(BaseAddon base, BaseAddon current) {
current.getDependencies().forEach((id, range) -> {
BaseAddon dependency = addons.get(id);
if(dependency.getID().equals(base.getID())) {
throw new CircularDependencyException(
"Addon " + base.getID() + " has circular dependency beginning with " + dependency.getID());
}
checkDependencies(base, dependency);
});
}
public List<BaseAddon> sort() {
List<BaseAddon> sorted = new ArrayList<>();
for(int i = addonList.size() - 1; i >= 0; i--) {
BaseAddon addon = addonList.get(i);
checkDependencies(addon, addon);
addonList.remove(i);
if(!visited.get(addon.getID())) {
sortDependencies(addon, sorted);
}
if(!visited.get(addon.getID())) {
sorted.add(addon);
visited.put(addon.getID(), true);
}
}
return sorted;
}
}

View File

@@ -0,0 +1,34 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.addon.dependency;
import java.io.Serial;
public class CircularDependencyException extends DependencyException{
@Serial
private static final long serialVersionUID = -6098780459461482651L;
public CircularDependencyException(String message) {
super(message);
}
public CircularDependencyException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,35 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.addon.dependency;
import java.io.Serial;
public class DependencyException extends RuntimeException {
@Serial
private static final long serialVersionUID = 4864727433635612759L;
public DependencyException(String message) {
super(message);
}
public DependencyException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,34 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.addon.dependency;
import java.io.Serial;
public class DependencyVersionException extends DependencyException{
@Serial
private static final long serialVersionUID = 3564288935278878135L;
public DependencyVersionException(String message) {
super(message);
}
public DependencyVersionException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands;
import com.dfsek.terra.api.Platform;
@@ -18,7 +35,7 @@ public class AddonsCommand implements CommandTemplate {
public void execute(CommandSender sender) {
sender.sendMessage("Installed Addons:");
platform.getAddons().forEach(addon -> {
sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor());
sender.sendMessage(" - " + addon.getID());
});
}
}

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands;
import org.slf4j.Logger;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands;
import java.util.HashMap;
@@ -13,15 +30,15 @@ public final class ExecutionState {
private final Map<String, String> args = new HashMap<>();
private final CommandSender sender;
protected ExecutionState(CommandSender sender) {
public ExecutionState(CommandSender sender) {
this.sender = sender;
}
protected void addSwitch(String flag) {
public void addSwitch(String flag) {
switches.add(flag);
}
protected void addArgument(String arg, String value) {
public void addArgument(String arg, String value) {
args.put(arg, value);
}

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands;
import com.dfsek.terra.api.Platform;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands;
import com.dfsek.terra.api.Platform;
@@ -27,6 +44,7 @@ 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()));
}
}

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands;
import org.slf4j.Logger;

View File

@@ -1,6 +1,21 @@
package com.dfsek.terra.commands;
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
import com.dfsek.terra.api.Platform;
package com.dfsek.terra.commands;
import net.jafama.FastMath;
@@ -14,6 +29,7 @@ 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;
@@ -35,8 +51,8 @@ import com.dfsek.terra.api.command.tab.TabCompleter;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.inject.exception.InjectionException;
import com.dfsek.terra.api.inject.impl.InjectorImpl;
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
import com.dfsek.terra.inject.InjectorImpl;
public class TerraCommandManager implements CommandManager {

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands;
import com.dfsek.terra.api.Platform;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands.profiler;
import com.dfsek.terra.api.command.CommandTemplate;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands.profiler;
import org.slf4j.Logger;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands.profiler;
import com.dfsek.terra.api.Platform;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands.profiler;
import com.dfsek.terra.api.Platform;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.commands.profiler;
import com.dfsek.terra.api.Platform;

View File

@@ -1,11 +1,29 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config;
import ca.solostudios.strata.version.VersionRange;
import com.dfsek.tectonic.loading.TypeRegistry;
import java.util.LinkedHashMap;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
@@ -16,6 +34,7 @@ import com.dfsek.terra.config.loaders.LinkedHashMapLoader;
import com.dfsek.terra.config.loaders.MaterialSetLoader;
import com.dfsek.terra.config.loaders.ProbabilityCollectionLoader;
import com.dfsek.terra.config.loaders.RangeLoader;
import com.dfsek.terra.config.loaders.VersionRangeLoader;
public class GenericLoaders implements LoaderRegistrar {
@@ -30,10 +49,11 @@ public class GenericLoaders implements LoaderRegistrar {
registry.registerLoader(ProbabilityCollection.class, new ProbabilityCollectionLoader())
.registerLoader(Range.class, new RangeLoader())
.registerLoader(MaterialSet.class, new MaterialSetLoader())
.registerLoader(VersionRange.class, new VersionRangeLoader())
.registerLoader(LinkedHashMap.class, new LinkedHashMapLoader());
if(platform != null) {
registry.registerLoader(TerraAddon.class, platform.getAddons())
registry.registerLoader(BaseAddon.class, platform.getAddons())
.registerLoader(BlockType.class,
(t, object, cf) -> platform.getWorldHandle().createBlockData((String) object).getBlockType())
.registerLoader(BlockState.class, (t, object, cf) -> platform.getWorldHandle().createBlockData((String) object));

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config;
import com.dfsek.tectonic.annotations.Default;
@@ -16,6 +33,7 @@ import java.io.UncheckedIOException;
import java.time.Duration;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.util.Logger;
@SuppressWarnings("FieldMayBeFinal")

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.dummy;
import com.dfsek.terra.api.block.entity.BlockEntity;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.fileloaders;
import org.slf4j.Logger;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.fileloaders;
import com.dfsek.tectonic.exception.ConfigException;
@@ -37,7 +54,7 @@ public abstract class LoaderImpl implements Loader {
* Open a subdirectory.
*
* @param directory Directory to open
* @param extension
* @param extension File extension
*/
@Override
public LoaderImpl open(String directory, String extension) {

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.fileloaders;
import org.slf4j.Logger;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.lang;
import org.jetbrains.annotations.NotNull;
@@ -12,6 +29,7 @@ import java.util.Objects;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.lang.Language;
import com.dfsek.terra.api.util.Logger;
public final class LangUtil {

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.lang;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.lang;
import java.util.Arrays;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.lang;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.loaders;
import com.dfsek.tectonic.config.MapConfiguration;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.loaders;
import com.dfsek.tectonic.exception.LoadException;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.loaders;
import com.dfsek.tectonic.exception.LoadException;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.loaders;
import com.dfsek.tectonic.exception.LoadException;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.loaders;
import com.dfsek.tectonic.exception.LoadException;

View File

@@ -0,0 +1,39 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.loaders;
import ca.solostudios.strata.Versions;
import ca.solostudios.strata.parser.tokenizer.ParseException;
import ca.solostudios.strata.version.VersionRange;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeLoader;
import java.lang.reflect.AnnotatedType;
public class VersionRangeLoader implements TypeLoader<VersionRange> {
@Override
public VersionRange load(AnnotatedType t, Object c, ConfigLoader loader) throws LoadException {
try {
return Versions.parseVersionRange((String) c);
} catch(ParseException e) {
throw new LoadException("Failed to parse version range: ", e);
}
}
}

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.loaders.config;
import com.dfsek.tectonic.exception.LoadException;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.loaders.config;
import com.dfsek.tectonic.loading.ConfigLoader;

View File

@@ -1,22 +1,42 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.pack;
import ca.solostudios.strata.version.VersionRange;
import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.config.ConfigTemplate;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Map;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.BaseAddon;
@SuppressWarnings("FieldMayBeFinal")
public class ConfigPackAddonsTemplate implements ConfigTemplate {
@Value("addons")
@Default
private Set<TerraAddon> addons = new HashSet<>();
private Map<BaseAddon, VersionRange> addons = new HashMap<>();
public Set<TerraAddon> getAddons() {
public Map<BaseAddon, VersionRange> getAddons() {
return addons;
}
}

View File

@@ -1,5 +1,23 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.pack;
import ca.solostudios.strata.version.VersionRange;
import com.dfsek.paralithic.eval.parser.Scope;
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
import com.dfsek.tectonic.abstraction.AbstractConfiguration;
@@ -36,7 +54,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.config.ConfigFactory;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.ConfigType;
@@ -94,7 +112,7 @@ public class ConfigPackImpl implements ConfigPack {
private final Configuration configuration;
private final Set<TerraAddon> addons;
private final Map<BaseAddon, VersionRange> addons;
private final BiomeProvider seededBiomeProvider;
@@ -127,7 +145,8 @@ public class ConfigPackImpl implements ConfigPack {
selfLoader.load(addonsTemplate, configuration);
this.addons = addonsTemplate.getAddons();
platform.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);
@@ -177,7 +196,8 @@ public class ConfigPackImpl implements ConfigPack {
selfLoader.load(addonsTemplate, configuration);
this.addons = addonsTemplate.getAddons();
platform.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);
@@ -239,7 +259,7 @@ public class ConfigPackImpl implements ConfigPack {
}
@Override
public Set<TerraAddon> addons() {
public Map<BaseAddon, VersionRange> addons() {
return addons;
}
@@ -286,7 +306,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
@@ -306,7 +326,7 @@ public class ConfigPackImpl implements ConfigPack {
}
}
}
return ImmutablePair.of(registry, new CheckedRegistryImpl<>(registry));
}).getRight();
}
@@ -431,7 +451,7 @@ public class ConfigPackImpl implements ConfigPack {
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;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.pack;
import com.dfsek.tectonic.annotations.Value;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.pack;
import com.dfsek.tectonic.annotations.Default;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.pack;
import java.lang.reflect.Type;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.preprocessor;
import com.dfsek.tectonic.config.Configuration;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.preprocessor;
import com.dfsek.tectonic.config.Configuration;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.preprocessor;
import com.dfsek.paralithic.eval.parser.Parser;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.preprocessor;
import com.dfsek.tectonic.config.Configuration;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.preprocessor;
import com.dfsek.tectonic.config.Configuration;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.preprocessor;
import com.dfsek.tectonic.config.Configuration;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.prototype;
import com.dfsek.tectonic.annotations.Value;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.event;
import org.jetbrains.annotations.NotNull;
@@ -7,7 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.event.events.Event;
import com.dfsek.terra.api.event.events.FailThroughEvent;
import com.dfsek.terra.api.event.functional.EventContext;
@@ -16,14 +33,14 @@ import com.dfsek.terra.api.util.reflection.ReflectionUtil;
public class EventContextImpl<T extends Event> implements EventContext<T>, Comparable<EventContextImpl<?>> {
private final List<Consumer<T>> actions = new ArrayList<>();
private final TerraAddon addon;
private final BaseAddon addon;
private final Type eventType;
private final FunctionalEventHandlerImpl parent;
private int priority;
private boolean failThrough = false;
private boolean global = false;
public EventContextImpl(TerraAddon addon, Type eventType, FunctionalEventHandlerImpl parent) {
public EventContextImpl(BaseAddon addon, Type eventType, FunctionalEventHandlerImpl parent) {
this.addon = addon;
this.eventType = eventType;
this.parent = parent;
@@ -75,7 +92,7 @@ public class EventContextImpl<T extends Event> implements EventContext<T>, Compa
return priority;
}
public TerraAddon getAddon() {
public BaseAddon getAddon() {
return addon;
}

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.event;
import java.util.HashMap;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.event;
import org.slf4j.Logger;
@@ -12,7 +29,7 @@ import java.util.List;
import java.util.Map;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.event.events.Event;
import com.dfsek.terra.api.event.events.FailThroughEvent;
import com.dfsek.terra.api.event.events.PackEvent;
@@ -38,7 +55,7 @@ public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
contextMap.getOrDefault(event.getClass(), Collections.emptyList()).forEach(context -> {
try {
if(event instanceof PackEvent) {
if((context.isGlobal() || ((PackEvent) event).getPack().addons().contains(context.getAddon()))) {
if((context.isGlobal() || ((PackEvent) event).getPack().addons().containsKey(context.getAddon()))) {
((EventContextImpl<Event>) context).handle(event);
}
} else {
@@ -48,20 +65,21 @@ public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
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);
logger.warn("Exception occurred during event handling. Report this to the maintainers of {}, {}",
context.getAddon().getID(), context.getAddon().getAuthor(), e);
}
});
}
@Override
public <T extends Event> EventContext<T> register(TerraAddon addon, Class<T> clazz) {
public <T extends Event> EventContext<T> register(BaseAddon addon, Class<T> clazz) {
EventContextImpl<T> eventContext = new EventContextImpl<>(addon, clazz, this);
contextMap.computeIfAbsent(clazz, c -> new ArrayList<>()).add(eventContext);
return eventContext;
}
@Override
public <T extends Event> EventContext<T> register(TerraAddon addon, TypeKey<T> clazz) {
public <T extends Event> EventContext<T> register(BaseAddon addon, TypeKey<T> clazz) {
EventContextImpl<T> eventContext = new EventContextImpl<>(addon, clazz.getType(), this);
contextMap.computeIfAbsent(clazz.getType(), c -> new ArrayList<>()).add(eventContext);
return eventContext;

View File

@@ -1,56 +0,0 @@
package com.dfsek.terra.inject;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;
import com.dfsek.terra.api.inject.Injector;
import com.dfsek.terra.api.inject.annotations.Inject;
import com.dfsek.terra.api.inject.exception.InjectionException;
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
public class InjectorImpl<T> implements Injector<T> {
private final T value;
private final Set<Class<? extends T>> targets = new HashSet<>();
/**
* Instantiate an Injector with a value to inject
*
* @param value Value to inject
*/
public InjectorImpl(T value) {
this.value = value;
}
@Override
public void addExplicitTarget(Class<? extends T> target) {
targets.add(target);
}
@Override
public void inject(Object object) throws InjectionException {
for(Field field : ReflectionUtil.getFields(object.getClass())) {
Inject inject = field.getAnnotation(Inject.class);
if(inject == null) continue;
if(value.getClass().equals(field.getType()) || targets.contains(field.getType())) {
int mod = field.getModifiers();
if(Modifier.isFinal(mod)) {
throw new InjectionException("Attempted to inject final field: " + field);
}
if(Modifier.isStatic(mod)) {
throw new InjectionException("Attempted to inject static field: " + field);
}
field.setAccessible(true);
try {
field.set(object, value);
} catch(IllegalAccessException e) {
throw new InjectionException("Failed to inject field: " + field, e);
}
}
}
}
}

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.math;
import java.util.ArrayList;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.profiler;
public class Frame {

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.profiler;
import org.slf4j.Logger;

View File

@@ -1,6 +1,27 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.profiler.exception;
import java.io.Serial;
public class MalformedStackException extends ProfilerException {
@Serial
private static final long serialVersionUID = -3009539681021691054L;
public MalformedStackException(String message) {

View File

@@ -1,6 +1,27 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.profiler.exception;
import java.io.Serial;
public class ProfilerException extends RuntimeException {
@Serial
private static final long serialVersionUID = 8206737998791649002L;
public ProfilerException(String message) {

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.registry;
import com.dfsek.tectonic.exception.LoadException;
@@ -31,12 +48,6 @@ public class CheckedRegistryImpl<T> implements CheckedRegistry<T> {
registry.registerChecked(identifier, value);
}
@Override
@Deprecated
public void registerUnchecked(String identifier, T value) {
registry.register(identifier, value);
}
@Override
public T get(String identifier) {
return registry.get(identifier);

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.registry;
import com.dfsek.tectonic.exception.LoadException;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.registry;
import com.dfsek.tectonic.exception.LoadException;
@@ -11,6 +28,7 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.dfsek.terra.api.registry.OpenRegistry;
@@ -24,6 +42,7 @@ import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
*/
public class OpenRegistryImpl<T> implements OpenRegistry<T> {
private static final Entry<?> NULL = new Entry<>(null);
private static final Pattern ID_PATTERN = Pattern.compile("^[a-zA-Z0-9_-]*$");
private final Map<String, Entry<T>> objects;
public OpenRegistryImpl() {
@@ -37,14 +56,13 @@ public class OpenRegistryImpl<T> implements OpenRegistry<T> {
@Override
public T load(AnnotatedType type, Object o, ConfigLoader configLoader) throws LoadException {
T obj = get((String) o);
StringBuilder keys = new StringBuilder("[");
String list = objects.keySet().stream().sorted().reduce("", (a, b) -> a + "\n - " + b);
objects.keySet().forEach(key -> keys.append(key).append(", "));
if(objects.isEmpty()) list = "[ ]";
if(obj == null)
throw new LoadException("No such " + type.getType().getTypeName() + " matching \"" + o +
"\" was found in this registry. Registry contains items: " + keys.substring(0, keys.length() - 2) +
"]");
"\" was found in this registry. Registry contains items: " + list);
return obj;
}
@@ -66,6 +84,10 @@ public class OpenRegistryImpl<T> implements OpenRegistry<T> {
}
public boolean register(String identifier, Entry<T> value) {
if(!ID_PATTERN.matcher(identifier).matches())
throw new IllegalArgumentException(
"Registry ID must only contain alphanumeric characters, hyphens, and underscores. \"" + identifier +
"\" is not a valid ID.");
boolean exists = objects.containsKey(identifier);
objects.put(identifier, value);
return exists;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.registry;
import com.dfsek.tectonic.exception.LoadException;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.registry.config;
import org.slf4j.Logger;

View File

@@ -1,130 +0,0 @@
package com.dfsek.terra.registry.master;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.LogManager;
import java.util.logging.Logger;
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.Platform;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.inject.Injector;
import com.dfsek.terra.api.inject.exception.InjectionException;
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
import com.dfsek.terra.inject.InjectorImpl;
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 Platform platform;
public AddonRegistry(Platform platform) {
this.platform = platform;
}
public AddonRegistry(TerraAddon addon, Platform platform) {
this.platform = platform;
register(addon);
}
@Override
public boolean register(String identifier, TerraAddon addon) {
if(contains(identifier)) throw new IllegalArgumentException("Addon " + identifier + " is already registered.");
addon.initialize();
logger.info("Loaded addon {} v{}, by {}", addon.getName(), addon.getVersion(), addon.getAuthor());
return super.register(identifier, addon);
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
public boolean register(TerraAddon addon) {
return register(addon.getName(), addon);
}
public boolean loadAll() {
return loadAll(Platform.class.getClassLoader());
}
@SuppressWarnings({ "NestedTryStatement", "ThrowCaughtLocally" })
public boolean loadAll(ClassLoader parent) {
InjectorImpl<Platform> pluginInjector = new InjectorImpl<>(platform);
pluginInjector.addExplicitTarget(Platform.class);
boolean valid = true;
File addonsFolder = new File(platform.getDataFolder(), "addons");
addonsFolder.mkdirs();
AddonPool pool = new AddonPool();
try {
for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) {
logger.info("Loading Addon(s) from: {}", jar.getName());
for(Class<? extends TerraAddon> addonClass : AddonClassLoader.fetchAddonClasses(jar, parent)) {
pool.add(new PreLoadAddon(addonClass, jar));
}
}
pool.buildAll();
for(PreLoadAddon addon : pool.getAddons()) {
Class<? extends TerraAddon> addonClass = addon.getAddonClass();
Constructor<? extends TerraAddon> constructor;
String logPrefix = "Terra:" + addon.getId();
Logger addonLogger = Logger.getLogger(logPrefix);
if(!LogManager.getLogManager().addLogger(addonLogger)) {
addonLogger = LogManager.getLogManager().getLogger(logPrefix);
}
// TODO: 2021-08-30 Remove logger injector entirely?
Injector<Logger> loggerInjector = new InjectorImpl<>(addonLogger);
loggerInjector.addExplicitTarget(Logger.class);
try {
constructor = addonClass.getConstructor();
} catch(NoSuchMethodException e) {
throw new AddonLoadException("Addon class has no valid constructor: " + addonClass.getCanonicalName(), e);
}
TerraAddon loadedAddon;
try {
loadedAddon = constructor.newInstance();
pluginInjector.inject(loadedAddon);
loggerInjector.inject(loadedAddon);
} catch(InstantiationException | IllegalAccessException | InvocationTargetException | InjectionException e) {
throw new AddonLoadException(String.format("Failed to load addon \"%s\"", addon.getId()), e);
}
try {
registerChecked(loadedAddon.getName(), loadedAddon);
} catch(DuplicateEntryException e) {
valid = false;
logger.error("""
Duplicate addon ID; addon with ID {} is already loaded.
Existing addon class: {}
Duplicate addon class: {}
""".strip(),
loadedAddon.getName(),
get(loadedAddon.getName()).getClass().getCanonicalName(),
addonClass.getCanonicalName());
}
}
} catch(AddonLoadException | IOException e) {
logger.error("Failed during addon loading", e);
valid = false;
}
return valid;
}
}

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.registry.master;
import com.dfsek.tectonic.exception.ConfigException;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.transform;
import java.util.HashMap;

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.transform;
import java.util.ArrayList;

View File

@@ -1,14 +1,33 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.util;
import org.apache.commons.rng.core.source64.XoRoShiRo128PlusPlus;
import java.io.Serial;
import java.util.Random;
import java.util.SplittableRandom;
public class FastRandom extends Random {
@Serial
private static final long serialVersionUID = 4571946470190183260L;
private XoRoShiRo128PlusPlus random;

View File

@@ -1,6 +1,21 @@
package com.dfsek.terra.world;
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
import com.dfsek.terra.api.Platform;
package com.dfsek.terra.world;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
@@ -8,9 +23,10 @@ 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;
import com.dfsek.terra.api.world.World;
public class SamplerCacheImpl implements com.dfsek.terra.api.world.generator.SamplerCache {

View File

@@ -1,3 +1,20 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package command;
import org.junit.jupiter.api.Test;

View File

@@ -1,25 +0,0 @@
package noise;
import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
public class ColorConfigTemplate implements ConfigTemplate {
@Value("enable")
@Default
private @Meta boolean enable = false;
@Value("colors")
private @Meta ProbabilityCollection<@Meta Integer> colors;
public boolean enable() {
return enable;
}
public ProbabilityCollection<Integer> getColors() {
return colors;
}
}

View File

@@ -1,17 +0,0 @@
package noise;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.terra.api.noise.NoiseSampler;
@SuppressWarnings("unused")
public class NoiseConfigTemplate implements ConfigTemplate {
@Value(".")
private NoiseSampler builder;
public NoiseSampler getBuilder() {
return builder;
}
}

View File

@@ -1,5 +1,24 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package profiler;
import org.junit.jupiter.api.Test;
import com.dfsek.terra.api.profiler.Profiler;
import com.dfsek.terra.profiler.ProfilerImpl;
@@ -7,32 +26,6 @@ import com.dfsek.terra.profiler.ProfilerImpl;
public class ProfilerTest {
private static final Profiler PROFILER = new ProfilerImpl();
//@Test
public static void main(String... a) throws InterruptedException {
//PROFILER.start();
for(int i = 0; i < 1000; i++) {
doThing();
}
for(int i = 0; i < 100; i++) {
doThirdOtherThing();
}
for(int i = 0; i < 100; i++) {
doOtherThing();
}
PROFILER.stop();
PROFILER.push("thing");
PROFILER.push("thing2");
PROFILER.start();
PROFILER.pop("thing2");
PROFILER.pop("thing");
PROFILER.push("thing4");
PROFILER.pop("thing4");
PROFILER.getTimings().forEach((id, timings) -> System.out.println(id + ": " + timings.toString()));
}
private static void doThing() throws InterruptedException {
PROFILER.push("thing");
Thread.sleep(1);
@@ -60,4 +53,30 @@ public class ProfilerTest {
Thread.sleep(2);
PROFILER.pop("thing4");
}
@Test
public void testProfiler() throws InterruptedException {
//PROFILER.start();
for(int i = 0; i < 100; i++) {
doThing();
}
for(int i = 0; i < 100; i++) {
doThirdOtherThing();
}
for(int i = 0; i < 100; i++) {
doOtherThing();
}
PROFILER.stop();
PROFILER.push("thing");
PROFILER.push("thing2");
PROFILER.start();
PROFILER.pop("thing2");
PROFILER.pop("thing");
PROFILER.push("thing4");
PROFILER.pop("thing4");
PROFILER.getTimings().forEach((id, timings) -> System.out.println(id + ": " + timings.toString()));
}
}

View File

@@ -0,0 +1,70 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package registry;
import org.junit.jupiter.api.Test;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.OpenRegistry;
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
import com.dfsek.terra.registry.CheckedRegistryImpl;
import com.dfsek.terra.registry.OpenRegistryImpl;
import static org.junit.jupiter.api.Assertions.*;
public class RegistryTest {
@Test
public void openRegistry() {
OpenRegistry<String> test = new OpenRegistryImpl<>();
test.register("test", "bazinga");
assertEquals(test.get("test"), "bazinga");
}
@Test
public void openRegistryChecked() {
OpenRegistry<String> test = new OpenRegistryImpl<>();
test.registerChecked("test", "bazinga");
try {
test.registerChecked("test", "bazinga2");
fail("Shouldn't be able to re-register with #registerChecked!");
} catch(DuplicateEntryException ignore) {
}
}
@Test
public void checkedRegistry() {
CheckedRegistry<String> test = new CheckedRegistryImpl<>(new OpenRegistryImpl<>());
test.register("test", "bazinga");
assertEquals(test.get("test"), "bazinga");
try {
test.register("test", "bazinga2");
fail("Shouldn't be able to re-register in CheckedRegistry!");
} catch(DuplicateEntryException ignore) {
}
}
}