diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bdc9a83b..744c64d1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/multiversion/default/build.gradle.kts b/multiversion/default/build.gradle.kts index 7f091e20..7b7df352 100644 --- a/multiversion/default/build.gradle.kts +++ b/multiversion/default/build.gradle.kts @@ -1,5 +1,5 @@ dependencies { - compileOnly("org.spigotmc:spigot-api:1.19.3-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT") compileOnly(project(":multiversion:common")) compileOnly("io.papermc:paperlib:1.0.8") } diff --git a/multiversion/v1_20_R1/build.gradle.kts b/multiversion/v1_20_R1/build.gradle.kts new file mode 100644 index 00000000..5298db30 --- /dev/null +++ b/multiversion/v1_20_R1/build.gradle.kts @@ -0,0 +1,6 @@ +dependencies { + compileOnly ("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT") + compileOnly ("org.spigotmc:spigot:1.20") + compileOnly(project(":multiversion:common")) + compileOnly("io.papermc:paperlib:1.0.8") +} diff --git a/multiversion/v1_20_R1/src/main/java/iridiumcore/multiversion/MultiVersion_V1_20_R1.java b/multiversion/v1_20_R1/src/main/java/iridiumcore/multiversion/MultiVersion_V1_20_R1.java new file mode 100644 index 00000000..b40abea8 --- /dev/null +++ b/multiversion/v1_20_R1/src/main/java/iridiumcore/multiversion/MultiVersion_V1_20_R1.java @@ -0,0 +1,47 @@ +package iridiumcore.multiversion; + +import com.cryptomorin.xseries.XMaterial; +import com.iridium.iridiumcore.multiversion.MultiVersion; +import io.papermc.lib.PaperLib; +import org.bukkit.Chunk; +import org.bukkit.ChunkSnapshot; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.concurrent.CompletableFuture; + +/** + * Interface for working with methods that were changed during an update by Spigot. + */ +public class MultiVersion_V1_20_R1 extends MultiVersion { + + public MultiVersion_V1_20_R1(JavaPlugin javaPlugin) { + super(javaPlugin); + } + + /** + * Returns the material at a position in a chunk. + * + * @param chunk The snapshot of the chunk where the position is in + * @param x The relative x position of the block in the chunk + * @param y The relative y position of the block in the chunk + * @param z The relative z position of the block in the chunk + * @return The material at the provided position in the chunk + */ + @Override + public XMaterial getMaterialAtPosition(ChunkSnapshot chunk, int x, int y, int z) { + return XMaterial.matchXMaterial(chunk.getBlockType(x, y, z)); + } + + @Override + public boolean isPassable(Block block) { + return block.isPassable(); + } + + @Override + public CompletableFuture getChunkAt(World world, int x, int z) { + return PaperLib.getChunkAtAsync(world, x, z, true); + } + +} diff --git a/multiversion/v1_20_R1/src/main/java/iridiumcore/nms/NMS_V1_20_R1.java b/multiversion/v1_20_R1/src/main/java/iridiumcore/nms/NMS_V1_20_R1.java new file mode 100644 index 00000000..7c5a50af --- /dev/null +++ b/multiversion/v1_20_R1/src/main/java/iridiumcore/nms/NMS_V1_20_R1.java @@ -0,0 +1,123 @@ +package iridiumcore.nms; + +import com.iridium.iridiumcore.Color; +import com.iridium.iridiumcore.nms.NMS; +import net.minecraft.server.MinecraftServer; +import org.bukkit.*; +import org.bukkit.World.Environment; +import org.bukkit.entity.Player; + +import java.util.List; + +/** + * Interface for working with the net.minecraft.server package. + * Version-specific, so it has to be implemented for every version we support. + * This is the implementation for v1_20_R1. + */ +public class NMS_V1_20_R1 implements NMS { + + /** + * Deletes a block faster than with Spigots implementation. + * See + * https://www.spigotmc.org/threads/methods-for-changing-massive-amount-of-blocks-up-to-14m-blocks-s.395868/ + * for more information. + * + * @param location The location of the block which should be deleted + */ + @Override + public void deleteBlockFast(Location location) { + location.getBlock().setType(Material.AIR, false); + } + + /** + * Sends the provided chunk to all the specified players. + * Used for updating chunks. + * + * @param players The player which should see the updated chunk + * @param chunk The chunk which should be updated + */ + @Override + public void sendChunk(List players, org.bukkit.Chunk chunk) { + chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); + + /* + * net.minecraft.world.level.chunk.Chunk chunkLevel = ((CraftChunk) + * chunk).getHandle(); + * ClientboundLevelChunkWithLightPacket refresh = new + * ClientboundLevelChunkWithLightPacket(chunkLevel, chunkLevel.q.l_(), null, + * null, true); + * for (Player player : players) { + * ((CraftPlayer) player).getHandle().b.a(refresh); + * } + */ + } + + /** + * Sends a colored world border to the specified Player with the provided size + * and center location. + * The size is half of the length of one side of the border. + * + * @param player The Player which should see the border + * @param color The color of the border + * @param size The size of this border, see the description above for + * more information + * @param centerLocation The center of the border + */ + @Override + public void sendWorldBorder(Player player, Color color, double size, Location centerLocation) { + + WorldBorder worldBorder = Bukkit.getServer().createWorldBorder(); + + // WorldBorder worldBorder = new WorldBorder(); + // worldBorder.world = ((CraftWorld) centerLocation.getWorld()).getHandle(); + if(centerLocation.getWorld().getEnvironment() == Environment.NETHER) + worldBorder.setCenter(centerLocation.getBlockX()*8 + 0.5, centerLocation.getBlockZ()*8 + 0.5); + else + worldBorder.setCenter(centerLocation.getBlockX() + 0.5, centerLocation.getBlockZ() + 0.5); + + + if (color == Color.OFF) { + worldBorder.setSize(Integer.MAX_VALUE); + } else { + worldBorder.setSize(size); + } + + worldBorder.setDamageAmount(0); + worldBorder.setDamageBuffer(0); + + if (color == Color.RED) { + worldBorder.setSize(size - 0.1D, 20000000L); + } else if (color == Color.GREEN) { + worldBorder.setSize( size+0.1D, 20000000L); + } + + player.setWorldBorder(worldBorder); + } + + /** + * Sends a title with the provided properties to the Player. + * + * @param player The Player which should see the title + * @param title The upper message of the title + * @param subtitle The lower message of the title + * @param fadeIn The amount of time this title should fade in in ticks + * @param displayTime The amount of time this title should stay fully visible in + * ticks + * @param fadeOut The amount of time this title should fade out in ticks + */ + @Override + public void sendTitle(Player player, String title, String subtitle, int fadeIn, int displayTime, int fadeOut) { + player.sendTitle( + ChatColor.translateAlternateColorCodes('&', title), + ChatColor.translateAlternateColorCodes('&', subtitle), + fadeIn, + displayTime, + fadeOut); + } + + @Override + public double[] getTPS() { + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/multiversion/v1_20_R2/build.gradle.kts b/multiversion/v1_20_R2/build.gradle.kts new file mode 100644 index 00000000..08efc2b6 --- /dev/null +++ b/multiversion/v1_20_R2/build.gradle.kts @@ -0,0 +1,6 @@ +dependencies { + compileOnly ("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT") + compileOnly ("org.spigotmc:spigot:1.20.2") + compileOnly(project(":multiversion:common")) + compileOnly("io.papermc:paperlib:1.0.8") +} diff --git a/multiversion/v1_20_R2/src/main/java/iridiumcore/multiversion/MultiVersion_V1_20_R2.java b/multiversion/v1_20_R2/src/main/java/iridiumcore/multiversion/MultiVersion_V1_20_R2.java new file mode 100644 index 00000000..163ed726 --- /dev/null +++ b/multiversion/v1_20_R2/src/main/java/iridiumcore/multiversion/MultiVersion_V1_20_R2.java @@ -0,0 +1,47 @@ +package iridiumcore.multiversion; + +import com.cryptomorin.xseries.XMaterial; +import com.iridium.iridiumcore.multiversion.MultiVersion; +import io.papermc.lib.PaperLib; +import org.bukkit.Chunk; +import org.bukkit.ChunkSnapshot; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.concurrent.CompletableFuture; + +/** + * Interface for working with methods that were changed during an update by Spigot. + */ +public class MultiVersion_V1_20_R2 extends MultiVersion { + + public MultiVersion_V1_20_R2(JavaPlugin javaPlugin) { + super(javaPlugin); + } + + /** + * Returns the material at a position in a chunk. + * + * @param chunk The snapshot of the chunk where the position is in + * @param x The relative x position of the block in the chunk + * @param y The relative y position of the block in the chunk + * @param z The relative z position of the block in the chunk + * @return The material at the provided position in the chunk + */ + @Override + public XMaterial getMaterialAtPosition(ChunkSnapshot chunk, int x, int y, int z) { + return XMaterial.matchXMaterial(chunk.getBlockType(x, y, z)); + } + + @Override + public boolean isPassable(Block block) { + return block.isPassable(); + } + + @Override + public CompletableFuture getChunkAt(World world, int x, int z) { + return PaperLib.getChunkAtAsync(world, x, z, true); + } + +} diff --git a/multiversion/v1_20_R2/src/main/java/iridiumcore/nms/NMS_V1_20_R2.java b/multiversion/v1_20_R2/src/main/java/iridiumcore/nms/NMS_V1_20_R2.java new file mode 100644 index 00000000..a9d7d2c5 --- /dev/null +++ b/multiversion/v1_20_R2/src/main/java/iridiumcore/nms/NMS_V1_20_R2.java @@ -0,0 +1,123 @@ +package iridiumcore.nms; + +import com.iridium.iridiumcore.Color; +import com.iridium.iridiumcore.nms.NMS; +import net.minecraft.server.MinecraftServer; +import org.bukkit.*; +import org.bukkit.World.Environment; +import org.bukkit.entity.Player; + +import java.util.List; + +/** + * Interface for working with the net.minecraft.server package. + * Version-specific, so it has to be implemented for every version we support. + * This is the implementation for v1_20_R2. + */ +public class NMS_V1_20_R2 implements NMS { + + /** + * Deletes a block faster than with Spigots implementation. + * See + * https://www.spigotmc.org/threads/methods-for-changing-massive-amount-of-blocks-up-to-14m-blocks-s.395868/ + * for more information. + * + * @param location The location of the block which should be deleted + */ + @Override + public void deleteBlockFast(Location location) { + location.getBlock().setType(Material.AIR, false); + } + + /** + * Sends the provided chunk to all the specified players. + * Used for updating chunks. + * + * @param players The player which should see the updated chunk + * @param chunk The chunk which should be updated + */ + @Override + public void sendChunk(List players, org.bukkit.Chunk chunk) { + chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); + + /* + * net.minecraft.world.level.chunk.Chunk chunkLevel = ((CraftChunk) + * chunk).getHandle(); + * ClientboundLevelChunkWithLightPacket refresh = new + * ClientboundLevelChunkWithLightPacket(chunkLevel, chunkLevel.q.l_(), null, + * null, true); + * for (Player player : players) { + * ((CraftPlayer) player).getHandle().b.a(refresh); + * } + */ + } + + /** + * Sends a colored world border to the specified Player with the provided size + * and center location. + * The size is half of the length of one side of the border. + * + * @param player The Player which should see the border + * @param color The color of the border + * @param size The size of this border, see the description above for + * more information + * @param centerLocation The center of the border + */ + @Override + public void sendWorldBorder(Player player, Color color, double size, Location centerLocation) { + + WorldBorder worldBorder = Bukkit.getServer().createWorldBorder(); + + // WorldBorder worldBorder = new WorldBorder(); + // worldBorder.world = ((CraftWorld) centerLocation.getWorld()).getHandle(); + if(centerLocation.getWorld().getEnvironment() == Environment.NETHER) + worldBorder.setCenter(centerLocation.getBlockX()*8 + 0.5, centerLocation.getBlockZ()*8 + 0.5); + else + worldBorder.setCenter(centerLocation.getBlockX() + 0.5, centerLocation.getBlockZ() + 0.5); + + + if (color == Color.OFF) { + worldBorder.setSize(Integer.MAX_VALUE); + } else { + worldBorder.setSize(size); + } + + worldBorder.setDamageAmount(0); + worldBorder.setDamageBuffer(0); + + if (color == Color.RED) { + worldBorder.setSize(size - 0.1D, 20000000L); + } else if (color == Color.GREEN) { + worldBorder.setSize( size+0.1D, 20000000L); + } + + player.setWorldBorder(worldBorder); + } + + /** + * Sends a title with the provided properties to the Player. + * + * @param player The Player which should see the title + * @param title The upper message of the title + * @param subtitle The lower message of the title + * @param fadeIn The amount of time this title should fade in in ticks + * @param displayTime The amount of time this title should stay fully visible in + * ticks + * @param fadeOut The amount of time this title should fade out in ticks + */ + @Override + public void sendTitle(Player player, String title, String subtitle, int fadeIn, int displayTime, int fadeOut) { + player.sendTitle( + ChatColor.translateAlternateColorCodes('&', title), + ChatColor.translateAlternateColorCodes('&', subtitle), + fadeIn, + displayTime, + fadeOut); + } + + @Override + public double[] getTPS() { + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/plugin/src/main/java/com/iridium/iridiumcore/MinecraftVersion.java b/plugin/src/main/java/com/iridium/iridiumcore/MinecraftVersion.java index 8975275b..2176d3ea 100644 --- a/plugin/src/main/java/com/iridium/iridiumcore/MinecraftVersion.java +++ b/plugin/src/main/java/com/iridium/iridiumcore/MinecraftVersion.java @@ -37,7 +37,9 @@ public enum MinecraftVersion { V1_18_R2(() -> new NMS_V1_18_R2(), MultiVersion_V1_18_R2::new), V1_19_R1(() -> new NMS_V1_19_R1(), MultiVersion_V1_19_R1::new), V1_19_R2(() -> new NMS_V1_19_R2(), MultiVersion_V1_19_R2::new), - V1_19_R3(() -> new NMS_V1_19_R3(), MultiVersion_V1_19_R3::new); + V1_19_R3(() -> new NMS_V1_19_R3(), MultiVersion_V1_19_R3::new), + V1_20_R1(() -> new NMS_V1_20_R1(), MultiVersion_V1_20_R1::new), + V1_20_R2(() -> new NMS_V1_20_R2(), MultiVersion_V1_20_R2::new); private final Supplier nmsSupplier; private final JavaPluginSupplier multiVersionSupplier; diff --git a/settings.gradle.kts b/settings.gradle.kts index 8bb00725..ab8e01dc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,6 +3,8 @@ include("plugin") include("multiversion") include("multiversion:common") include("multiversion:default") +include("multiversion:v1_20_R2") +include("multiversion:v1_20_R1") include("multiversion:v1_19_R3") include("multiversion:v1_19_R2") include("multiversion:v1_19_R1")