diff --git a/.gitignore b/.gitignore index 1864cd390..087f714b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Directories # build/ -/bin/ +bin/ target/ # OS Files # @@ -70,10 +70,12 @@ todolist.txt .idea/* #Gradle -/.gradle/ -.gradle/* +.gradle/ !gradle-wrapper.jar # WorldEdit Builds Support-WorldEdit-7/build/tmp* -Support-WorldEdit-6/build/tmp* \ No newline at end of file +Support-WorldEdit-6/build/tmp* + +# run-paper +/run/ diff --git a/Support-WorldEdit-6/build.gradle b/Support-WorldEdit-6/build.gradle index 596b7e545..25e659bc8 100644 --- a/Support-WorldEdit-6/build.gradle +++ b/Support-WorldEdit-6/build.gradle @@ -1,5 +1,5 @@ dependencies { - shadow 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT' - shadow 'com.sk89q.worldedit:worldedit-bukkit:6.1.5' - shadow 'com.sk89q.worldedit:worldedit-core:6.1.4-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT' + compileOnly 'com.sk89q.worldedit:worldedit-bukkit:6.1.5' + compileOnly 'com.sk89q.worldedit:worldedit-core:6.1.4-SNAPSHOT' } diff --git a/Support-WorldEdit-7/build.gradle b/Support-WorldEdit-7/build.gradle index df637e72f..9f9d5b3ae 100644 --- a/Support-WorldEdit-7/build.gradle +++ b/Support-WorldEdit-7/build.gradle @@ -1,4 +1,4 @@ dependencies { - shadow 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT' - shadow 'com.sk89q.worldedit:worldedit-bukkit:7.1.0-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT' + compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.1.0-SNAPSHOT' } diff --git a/adapters/1_18_R1/build.gradle b/adapters/1_18_R1/build.gradle new file mode 100644 index 000000000..2ac99ae20 --- /dev/null +++ b/adapters/1_18_R1/build.gradle @@ -0,0 +1,16 @@ +plugins { + id "io.papermc.paperweight.userdev" version "1.3.5" +} + +dependencies { + api project(":adapters") + paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.18.1-R0.1-SNAPSHOT" +} + +// Reobfuscate JAR with paperweight on build +tasks.named("assemble") { + dependsOn tasks.named("reobfJar") +} + +// Minecraft 1.18 requires Java 17 +java.toolchain.languageVersion = JavaLanguageVersion.of(17) diff --git a/adapters/1_18_R1/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R1/RegistryUtils.java b/adapters/1_18_R1/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R1/RegistryUtils.java new file mode 100644 index 000000000..f22167fa3 --- /dev/null +++ b/adapters/1_18_R1/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R1/RegistryUtils.java @@ -0,0 +1,39 @@ +package com.gmail.val59000mc.adapters.impl.v1_18_R1; + +import java.util.function.Consumer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_18_R1.CraftServer; + +import net.minecraft.core.MappedRegistry; +import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.WritableRegistry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.dedicated.DedicatedServer; + +/** + * Utility class for dealing with the NMS registry. + */ +public abstract class RegistryUtils { + + private static final RegistryAccess registryAccess = getRegistryAccess(); + + private static RegistryAccess getRegistryAccess() { + final DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer(); + return server.registryAccess(); + } + + /** + * Obtains write access to a given registry and runs an operation on it. + * + * @param the type of registry + * @param registryKey the key for the registry + * @param writeOperation the operation to run with write access + */ + public static void obtainWriteAccess(ResourceKey> registryKey, Consumer> writeOperation) { + final MappedRegistry registry = (MappedRegistry) registryAccess.ownedRegistryOrThrow(registryKey); + writeOperation.accept(registry); + } + +} diff --git a/adapters/1_18_R1/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R1/VersionAdapterImpl.java b/adapters/1_18_R1/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R1/VersionAdapterImpl.java new file mode 100644 index 000000000..7739deaf7 --- /dev/null +++ b/adapters/1_18_R1/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R1/VersionAdapterImpl.java @@ -0,0 +1,25 @@ +package com.gmail.val59000mc.adapters.impl.v1_18_R1; + +import java.util.OptionalInt; + +import com.gmail.val59000mc.adapters.VersionAdapter; +import com.mojang.serialization.Lifecycle; + +import net.minecraft.core.Registry; +import net.minecraft.world.level.levelgen.Noises; +import net.minecraft.world.level.levelgen.synth.NormalNoise.NoiseParameters; + +public class VersionAdapterImpl extends VersionAdapter { + + @Override + public void removeOceans() { + // Setting the continentalness noise to a constant 0 will stop ocean generation. + // It may also reduce the quality of the terrain generation, but without + // noise routers (introduced in 1.18.2), this seems like the best solution. + final NoiseParameters continentalnessWithoutOceans = new NoiseParameters(0, 0); + RegistryUtils.obtainWriteAccess(Registry.NOISE_REGISTRY, noiseRegistry -> { + noiseRegistry.registerOrOverride(OptionalInt.empty(), Noises.CONTINENTALNESS, continentalnessWithoutOceans, Lifecycle.stable()); + }); + } + +} diff --git a/adapters/1_18_R2/build.gradle b/adapters/1_18_R2/build.gradle new file mode 100644 index 000000000..8b0270fe8 --- /dev/null +++ b/adapters/1_18_R2/build.gradle @@ -0,0 +1,16 @@ +plugins { + id "io.papermc.paperweight.userdev" version "1.3.5" +} + +dependencies { + api project(":adapters") + paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.18.2-R0.1-SNAPSHOT" +} + +// Reobfuscate JAR with paperweight on build +tasks.named("assemble") { + dependsOn tasks.named("reobfJar") +} + +// Minecraft 1.18 requires Java 17 +java.toolchain.languageVersion = JavaLanguageVersion.of(17) diff --git a/adapters/1_18_R2/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R2/RegistryUtils.java b/adapters/1_18_R2/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R2/RegistryUtils.java new file mode 100644 index 000000000..00389773b --- /dev/null +++ b/adapters/1_18_R2/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R2/RegistryUtils.java @@ -0,0 +1,51 @@ +package com.gmail.val59000mc.adapters.impl.v1_18_R2; + +import java.lang.reflect.Field; +import java.util.function.Consumer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_18_R2.CraftServer; + +import net.minecraft.core.MappedRegistry; +import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.WritableRegistry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.dedicated.DedicatedServer; + +/** + * Utility class for dealing with the NMS registry. + */ +public abstract class RegistryUtils { + + private static final RegistryAccess registryAccess = getRegistryAccess(); + + private static RegistryAccess getRegistryAccess() { + final DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer(); + return server.registryAccess(); + } + + /** + * Obtains write access to a given registry and runs an operation on it. + * + * @param the type of registry + * @param registryKey the key for the registry + * @param writeOperation the operation to run with write access + */ + public static void obtainWriteAccess(ResourceKey> registryKey, Consumer> writeOperation) { + final MappedRegistry registry = (MappedRegistry) registryAccess.ownedRegistryOrThrow(registryKey); + try { + // Starting from 1.18.2, registries are frozen after initialization, + // which happens before any plugins are loaded. This is a workaround + // to allow writing to the registry by temporarily unfreezing it again. + final Field frozen = MappedRegistry.class.getDeclaredField("bL"); + frozen.setAccessible(true); + frozen.set(registry, false); + writeOperation.accept(registry); + frozen.set(registry, true); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + throw new RuntimeException("Unable to get registry write access", e); + } + } + +} diff --git a/adapters/1_18_R2/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R2/VersionAdapterImpl.java b/adapters/1_18_R2/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R2/VersionAdapterImpl.java new file mode 100644 index 000000000..1f3e286b4 --- /dev/null +++ b/adapters/1_18_R2/src/main/java/com/gmail/val59000mc/adapters/impl/v1_18_R2/VersionAdapterImpl.java @@ -0,0 +1,35 @@ +package com.gmail.val59000mc.adapters.impl.v1_18_R2; + +import java.util.OptionalInt; + +import com.gmail.val59000mc.adapters.VersionAdapter; +import com.mojang.serialization.Lifecycle; + +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.DensityFunction; +import net.minecraft.world.level.levelgen.DensityFunctions; +import net.minecraft.world.level.levelgen.DensityFunctions.MarkerOrMarked; +import net.minecraft.world.level.levelgen.NoiseRouterData; + +public class VersionAdapterImpl extends VersionAdapter { + + /** + * See {@link NoiseRouterData#CONTINENTS}. + */ + private final ResourceKey continentsKey = ResourceKey.create(Registry.DENSITY_FUNCTION_REGISTRY, new ResourceLocation("overworld/continents")); + + @Override + public void removeOceans() { + RegistryUtils.obtainWriteAccess(Registry.DENSITY_FUNCTION_REGISTRY, dfRegistry -> { + // The continents noise function is wrapped in a flatCache, see NoiseRouterData#bootstrap(). + final MarkerOrMarked continents = (MarkerOrMarked) dfRegistry.getOrThrow(continentsKey); + // We keep the flatCache for performance, but take the absolute value of the noise function. + // This stops ocean generation, but keeps the qualities of the original noise. + final DensityFunction continentsWithoutOceans = DensityFunctions.flatCache(continents.wrapped().abs()); + dfRegistry.registerOrOverride(OptionalInt.empty(), continentsKey, continentsWithoutOceans, Lifecycle.stable()); + }); + } + +} diff --git a/adapters/build.gradle b/adapters/build.gradle new file mode 100644 index 000000000..563e1af35 --- /dev/null +++ b/adapters/build.gradle @@ -0,0 +1,5 @@ +dependencies { + implementation "io.papermc:paperlib:1.0.7" + implementation ":BiomeMapping-1.3" + compileOnly "org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT" +} diff --git a/adapters/src/main/java/com/gmail/val59000mc/adapters/VersionAdapter.java b/adapters/src/main/java/com/gmail/val59000mc/adapters/VersionAdapter.java new file mode 100644 index 000000000..869cc7716 --- /dev/null +++ b/adapters/src/main/java/com/gmail/val59000mc/adapters/VersionAdapter.java @@ -0,0 +1,69 @@ +package com.gmail.val59000mc.adapters; + +import com.gmail.val59000mc.adapters.impl.DefaultVersionAdapterImpl; + +import org.bukkit.Bukkit; + +/** + * Utility class exposing an abstraction layer for functionality where a + * custom implementation needs to be used depending on the runtime server version. + */ +public abstract class VersionAdapter { + + /** + * Loads and instantiates a {@link VersionAdapter} for the running server version. + * + * @return the adapter instance + * @throws InstantiationException if the adapter couldn't be instantiated + */ + public static VersionAdapter instantiate() throws InstantiationException { + try { + final Class loadedClass = loadAdapterImplClass(); + return loadedClass.getConstructor().newInstance(); + } catch (ClassNotFoundException ignored) { + return new DefaultVersionAdapterImpl(); + } catch (Exception e) { + throw new InstantiationException(e); + } + } + + public static class InstantiationException extends Exception { + public InstantiationException(Throwable cause) { + super("Unable to instantiate version adapter", cause); + } + } + + /** + * Gets the NMS package name of the running server, such as {@code v1_18_R2}. + * + * @return the NMS package name + */ + private static String getNmsPackageName() { + final String nmsPackageName = Bukkit.getServer().getClass().getPackage().getName(); + return nmsPackageName.substring(nmsPackageName.lastIndexOf('.') + 1); + } + + /** + * Loads and returns the adapter implementation class for the running server version. + * + * @return the adapter implementation class + * @throws ClassNotFoundException if the class cannot be loaded + */ + @SuppressWarnings("unchecked") + private static Class loadAdapterImplClass() throws ClassNotFoundException { + final String implPackageName = DefaultVersionAdapterImpl.class.getPackage().getName(); + final String nmsImplPackageName = implPackageName + '.' + getNmsPackageName(); + final String implClassName = VersionAdapter.class.getSimpleName() + "Impl"; + return (Class) Class.forName(nmsImplPackageName + '.' + implClassName); + } + + /** + * Removes oceans from the world generation. + *

+ * This method should be called before the world is generated. + * + * @throws UnsupportedOperationException if not supported by this adapter + */ + public abstract void removeOceans(); + +} diff --git a/adapters/src/main/java/com/gmail/val59000mc/adapters/impl/DefaultVersionAdapterImpl.java b/adapters/src/main/java/com/gmail/val59000mc/adapters/impl/DefaultVersionAdapterImpl.java new file mode 100644 index 000000000..fddfaf47a --- /dev/null +++ b/adapters/src/main/java/com/gmail/val59000mc/adapters/impl/DefaultVersionAdapterImpl.java @@ -0,0 +1,41 @@ +package com.gmail.val59000mc.adapters.impl; + +import com.gmail.val59000mc.adapters.VersionAdapter; +import com.pieterdebot.biomemapping.Biome; +import com.pieterdebot.biomemapping.BiomeMappingAPI; + +import io.papermc.lib.PaperLib; + +/** + * A default {@link VersionAdapter} implementation, used as a fallback. + */ +public class DefaultVersionAdapterImpl extends VersionAdapter { + + @Override + public void removeOceans() { + final int version = PaperLib.getMinecraftVersion(); + if (8 <= version && version <= 17) { + removeOceansUsingBiomeMapping(); + } else { + throw new UnsupportedOperationException(); + } + } + + private void removeOceansUsingBiomeMapping() { + final BiomeMappingAPI biomeMapping = new BiomeMappingAPI(); + Biome replacementBiome = Biome.PLAINS; + + for (Biome biome : Biome.values()) { + if (biome.isOcean() && biomeMapping.biomeSupported(biome)) { + try { + biomeMapping.replaceBiomes(biome, replacementBiome); + } catch (Exception ex) { + ex.printStackTrace(); + } + + replacementBiome = replacementBiome == Biome.PLAINS ? Biome.FOREST : Biome.PLAINS; + } + } + } + +} diff --git a/build.gradle b/build.gradle index 1fc95b088..2dde3ef13 100644 --- a/build.gradle +++ b/build.gradle @@ -1,24 +1,18 @@ import org.apache.tools.ant.filters.ReplaceTokens -buildscript { - repositories { - jcenter() - } - - dependencies { - classpath 'com.github.jengelman.gradle.plugins:shadow:5.1.0' - } +plugins { + id "com.github.johnrengelman.shadow" version "7.1.2" + id "xyz.jpenilla.run-paper" version "1.0.6" } allprojects { - apply plugin: 'java' - apply plugin: 'com.github.johnrengelman.shadow' + apply plugin: 'java-library' group = pluginGroup version = pluginVersion - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + // Target Java 8 by default for legacy support + java.toolchain.languageVersion = JavaLanguageVersion.of(8) repositories { mavenCentral() @@ -32,11 +26,11 @@ allprojects { } maven { // WorldEdit - url = 'http://maven.sk89q.com/repo/' + url = 'https://maven.enginehub.org/repo/' } maven { // ProtocolLib - url "http://repo.dmulloy2.net/nexus/repository/public/" + url "https://repo.dmulloy2.net/repository/public/" } // PaperLib maven { @@ -47,19 +41,19 @@ allprojects { url 'https://repo.codemc.io/repository/maven-snapshots/' } flatDir { - dirs 'libs' + dirs "$rootDir/libs" } } processResources { - from(sourceSets.main.resources.srcDirs) { + filesMatching("plugin.yml") { filter ReplaceTokens, tokens: [version: version] } } } dependencies { - shadow 'com.google.code.findbugs:jsr305:3.0.2' + compileOnly 'com.google.code.findbugs:jsr305:3.0.2' //shadow 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT' //shadow 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT' //shadow 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT' @@ -67,20 +61,30 @@ dependencies { //shadow 'org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT' //shadow 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' //shadow 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT' - shadow 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT' - shadow 'com.github.MilkBowl:VaultAPI:1.7' - shadow 'net.wesjd:anvilgui:1.5.3-SNAPSHOT' - compile name: 'BiomeMapping-1.3' - compile "io.papermc:paperlib:1.0.5" - shadow 'com.comphenix.protocol:ProtocolLib:4.4.0' - compile project('Support-WorldEdit-6') - compile project('Support-WorldEdit-7') + compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT' + compileOnly 'com.github.MilkBowl:VaultAPI:1.7' + implementation 'net.wesjd:anvilgui:1.5.3-SNAPSHOT' + implementation "io.papermc:paperlib:1.0.5" + compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0' + implementation project('Support-WorldEdit-6') + implementation project('Support-WorldEdit-7') + implementation project(":adapters") + runtimeOnly project(path: ":adapters:1_18_R1", configuration: "reobf") + runtimeOnly project(path: ":adapters:1_18_R2", configuration: "reobf") } shadowJar { classifier = '' - configurations = [project.configurations.compile] relocate 'io.papermc.lib', 'com.gmail.val59000mc.paperlib' + relocate 'net.wesjd.anvilgui', 'com.gmail.val59000mc.anvilgui' + relocate 'com.pieterdebot.biomemapping', 'com.gmail.val59000mc.biomemapping' } -build.dependsOn(shadowJar) \ No newline at end of file +build.dependsOn(shadowJar) + +runServer { + minecraftVersion "1.18.2" + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(17) + } +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 558870dad..2e6e5897b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index ed7a5fc36..35bebac3b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,17 @@ +pluginManagement { + repositories { + gradlePluginPortal() + maven { + name "PaperMC" + url "https://papermc.io/repo/repository/maven-public/" + } + } +} + rootProject.name = 'UhcCore' include 'Support-WorldEdit-6' include 'Support-WorldEdit-7' +include ":adapters" +include ":adapters:1_18_R1" +include ":adapters:1_18_R2" diff --git a/src/main/java/com/gmail/val59000mc/UhcCore.java b/src/main/java/com/gmail/val59000mc/UhcCore.java index e7287dd53..a6d401978 100644 --- a/src/main/java/com/gmail/val59000mc/UhcCore.java +++ b/src/main/java/com/gmail/val59000mc/UhcCore.java @@ -1,7 +1,11 @@ package com.gmail.val59000mc; +import java.util.logging.Level; + +import com.gmail.val59000mc.adapters.VersionAdapter; import com.gmail.val59000mc.game.GameManager; import com.gmail.val59000mc.utils.FileUtils; + import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -11,6 +15,7 @@ public class UhcCore extends JavaPlugin{ private static final int MAX_VERSION = 19; private static UhcCore pl; + private static VersionAdapter versionAdapter; private static int version; private GameManager gameManager; private Updater updater; @@ -21,6 +26,14 @@ public void onEnable(){ loadServerVersion(); + try { + versionAdapter = VersionAdapter.instantiate(); + getLogger().info("Successfully loaded version adapter: " + versionAdapter.getClass().getName()); + } catch (VersionAdapter.InstantiationException e) { + getLogger().log(Level.SEVERE, "Unable to start plugin", e); + return; + } + gameManager = new GameManager(); Bukkit.getScheduler().runTaskLater(this, () -> gameManager.loadNewGame(), 1); @@ -57,6 +70,10 @@ public static UhcCore getPlugin(){ return pl; } + public static VersionAdapter getVersionAdapter() { + return versionAdapter; + } + @Override public void onDisable(){ gameManager.getScenarioManager().disableAllScenarios(); diff --git a/src/main/java/com/gmail/val59000mc/game/GameManager.java b/src/main/java/com/gmail/val59000mc/game/GameManager.java index 9a0afd7da..8c2daec44 100644 --- a/src/main/java/com/gmail/val59000mc/game/GameManager.java +++ b/src/main/java/com/gmail/val59000mc/game/GameManager.java @@ -31,7 +31,6 @@ import java.io.File; import java.io.IOException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @@ -175,53 +174,6 @@ public void setGameState(GameState gameState){ // Call UhcGameStateChangedEvent Bukkit.getPluginManager().callEvent(new UhcGameStateChangedEvent(oldGameState, gameState)); - - // Update MOTD - switch(gameState){ - case ENDED: - setMotd(Lang.DISPLAY_MOTD_ENDED); - break; - case LOADING: - setMotd(Lang.DISPLAY_MOTD_LOADING); - break; - case DEATHMATCH: - setMotd(Lang.DISPLAY_MOTD_PLAYING); - break; - case PLAYING: - setMotd(Lang.DISPLAY_MOTD_PLAYING); - break; - case STARTING: - setMotd(Lang.DISPLAY_MOTD_STARTING); - break; - case WAITING: - setMotd(Lang.DISPLAY_MOTD_WAITING); - break; - default: - setMotd(Lang.DISPLAY_MOTD_ENDED); - break; - } - } - - private void setMotd(String motd){ - if (config.get(MainConfig.DISABLE_MOTD)){ - return; // No motd support - } - - if (motd == null){ - return; // Failed to load lang.yml so motd is null. - } - - try { - Class craftServerClass = NMSUtils.getNMSClass("CraftServer"); - Object craftServer = craftServerClass.cast(Bukkit.getServer()); - Object dedicatedPlayerList = NMSUtils.getHandle(craftServer); - Object dedicatedServer = NMSUtils.getServer(dedicatedPlayerList); - - Method setMotd = NMSUtils.getMethod(dedicatedServer.getClass(), "setMotd"); - setMotd.invoke(dedicatedServer, motd); - }catch (ReflectiveOperationException | NullPointerException ex){ - ex.printStackTrace(); - } } public void loadNewGame() { diff --git a/src/main/java/com/gmail/val59000mc/maploader/MapLoader.java b/src/main/java/com/gmail/val59000mc/maploader/MapLoader.java index 86bb06d2a..2ee2f9196 100644 --- a/src/main/java/com/gmail/val59000mc/maploader/MapLoader.java +++ b/src/main/java/com/gmail/val59000mc/maploader/MapLoader.java @@ -11,8 +11,6 @@ import com.gmail.val59000mc.utils.FileUtils; import com.gmail.val59000mc.configuration.YamlFile; import com.gmail.val59000mc.utils.VersionUtils; -import com.pieterdebot.biomemapping.Biome; -import com.pieterdebot.biomemapping.BiomeMappingAPI; import io.papermc.lib.PaperLib; import org.apache.commons.lang.Validate; import org.bukkit.*; @@ -67,7 +65,12 @@ public double getBorderSize(){ public void loadWorlds(boolean debug) { if (config.get(MainConfig.REPLACE_OCEAN_BIOMES)){ - replaceOceanBiomes(); + try { + UhcCore.getVersionAdapter().removeOceans(); + } catch (UnsupportedOperationException ignored) { + UhcCore.getPlugin().getLogger().warning( + "The 'replace-ocean-biomes' setting is not supported on this Minecraft version"); + } } deleteOldPlayersFiles(); @@ -352,24 +355,6 @@ private void deleteOldPlayersFiles() { } } } - - private void replaceOceanBiomes(){ - BiomeMappingAPI biomeMapping = new BiomeMappingAPI(); - - Biome replacementBiome = Biome.PLAINS; - - for (Biome biome : Biome.values()){ - if (biome.isOcean() && biomeMapping.biomeSupported(biome)){ - try { - biomeMapping.replaceBiomes(biome, replacementBiome); - }catch (Exception ex){ - ex.printStackTrace(); - } - - replacementBiome = replacementBiome == Biome.PLAINS ? Biome.FOREST : Biome.PLAINS; - } - } - } private void recursiveCopy(File fSource, File fDest) { try { diff --git a/src/main/java/com/gmail/val59000mc/utils/NMSUtils.java b/src/main/java/com/gmail/val59000mc/utils/NMSUtils.java index 4224d7f7f..b65f9fcc8 100644 --- a/src/main/java/com/gmail/val59000mc/utils/NMSUtils.java +++ b/src/main/java/com/gmail/val59000mc/utils/NMSUtils.java @@ -34,15 +34,6 @@ public static Object getHandle(Object craftObject){ } } - @Nullable - public static Object getServer(Object o){ - try{ - return getMethod(o.getClass(), "getServer").invoke(o); - }catch (ReflectiveOperationException | IllegalArgumentException ex){ - return null; - } - } - public static Method getMethod(Class c, String name) throws ReflectiveOperationException{ return getMethod(c, name, -1); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ab4ebd920..c30b2ee58 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: UhcCore main: com.gmail.val59000mc.UhcCore -version: @version@ +version: "@version@" description: Automates UHC games on a dedicated server author: val59000mc, Mezy softdepend: [WorldEdit,Vault,ProtocolLib]