mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 06:11:24 +00:00
Merge branch 'master' into dev/7.0-2
This commit is contained in:
@@ -20,6 +20,7 @@ package com.dfsek.terra.bukkit;
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -30,10 +31,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
@@ -41,7 +40,6 @@ import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.handles.BukkitItemHandle;
|
||||
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
||||
import com.dfsek.terra.bukkit.nms.Initializer;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
|
||||
|
||||
@@ -96,11 +94,6 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
plugin.getGlobalRegionScheduler().run(plugin, task -> runnable.run());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
return List.of(Initializer.nmsAddon(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull WorldHandle getWorldHandle() {
|
||||
return handle;
|
||||
@@ -130,7 +123,7 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
|
||||
}
|
||||
|
||||
private BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
|
||||
protected BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
|
||||
NamespacedKey key = NamespacedKey.fromString(id);
|
||||
if(key == null || !key.namespace().equals("minecraft")) throw new LoadException("Invalid biome identifier " + id, depthTracker);
|
||||
return new BukkitPlatformBiome(RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME).getOrThrow(key));
|
||||
|
||||
@@ -51,7 +51,7 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
public class TerraBukkitPlugin extends JavaPlugin {
|
||||
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
|
||||
|
||||
private final PlatformImpl platform = new PlatformImpl(this);
|
||||
private PlatformImpl platform;
|
||||
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
|
||||
|
||||
private AsyncScheduler asyncScheduler = this.getServer().getAsyncScheduler();
|
||||
@@ -64,13 +64,14 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
|
||||
if(!Initializer.init(platform)) {
|
||||
platform = Initializer.init(this);
|
||||
if(platform == null) {
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
|
||||
try {
|
||||
LegacyPaperCommandManager<CommandSender> commandManager = getCommandSenderPaperCommandManager();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -12,13 +14,11 @@ public interface Initializer {
|
||||
String NMS = VersionUtil.getMinecraftVersionInfo().toString().replace(".", "_");
|
||||
String TERRA_PACKAGE = Initializer.class.getPackageName();
|
||||
|
||||
static boolean init(PlatformImpl platform) {
|
||||
static PlatformImpl init(TerraBukkitPlugin plugin) {
|
||||
Logger logger = LoggerFactory.getLogger(Initializer.class);
|
||||
|
||||
Initializer initializer = constructInitializer();
|
||||
if(initializer != null) {
|
||||
initializer.initialize(platform);
|
||||
} else {
|
||||
PlatformImpl platform = constructPlatform(plugin);
|
||||
if (platform == null) {
|
||||
logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS);
|
||||
logger.error("This is usually due to running Terra on an unsupported Minecraft version.");
|
||||
String bypassKey = "IKnowThereAreNoNMSBindingsFor" + NMS + "ButIWillProceedAnyway";
|
||||
@@ -26,7 +26,7 @@ public interface Initializer {
|
||||
logger.error("Because of this **TERRA HAS BEEN DISABLED**.");
|
||||
logger.error("Do not come ask us why it is not working.");
|
||||
logger.error("If you wish to proceed anyways, you can add the JVM System Property \"{}\" to enable the plugin.", bypassKey);
|
||||
return false;
|
||||
return null;
|
||||
} else {
|
||||
logger.error("");
|
||||
logger.error("");
|
||||
@@ -42,24 +42,21 @@ public interface Initializer {
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return platform;
|
||||
}
|
||||
|
||||
static BukkitAddon nmsAddon(PlatformImpl platform) {
|
||||
Initializer initializer = constructInitializer();
|
||||
return initializer != null ? initializer.getNMSAddon(platform) : new BukkitAddon(platform);
|
||||
}
|
||||
|
||||
private static Initializer constructInitializer() {
|
||||
private static PlatformImpl constructPlatform(TerraBukkitPlugin plugin) {
|
||||
try {
|
||||
String packageVersion = NMS;
|
||||
if (NMS.equals("v1_21_5") || NMS.equals("v1_21_6")) {
|
||||
packageVersion = "v1_21_7";
|
||||
}
|
||||
|
||||
Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSInitializer");
|
||||
Class<?> platformClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSPlatform");
|
||||
try {
|
||||
return (Initializer) initializerClass.getConstructor().newInstance();
|
||||
return (PlatformImpl) platformClass
|
||||
.getConstructor(TerraBukkitPlugin.class)
|
||||
.newInstance(plugin);
|
||||
} catch(ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e);
|
||||
}
|
||||
@@ -67,8 +64,4 @@ public interface Initializer {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void initialize(PlatformImpl plugin);
|
||||
|
||||
BukkitAddon getNMSAddon(PlatformImpl plugin);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user