Skip to content

Commit

Permalink
Add official 1.20 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dlsf committed Nov 5, 2023
1 parent f4aad2e commit 5ef63ef
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion multiversion/default/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
6 changes: 6 additions & 0 deletions multiversion/v1_20_R1/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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<Chunk> getChunkAt(World world, int x, int z) {
return PaperLib.getChunkAtAsync(world, x, z, true);
}

}
123 changes: 123 additions & 0 deletions multiversion/v1_20_R1/src/main/java/iridiumcore/nms/NMS_V1_20_R1.java
Original file line number Diff line number Diff line change
@@ -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<Player> 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;
}

}
6 changes: 6 additions & 0 deletions multiversion/v1_20_R2/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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<Chunk> getChunkAt(World world, int x, int z) {
return PaperLib.getChunkAtAsync(world, x, z, true);
}

}
123 changes: 123 additions & 0 deletions multiversion/v1_20_R2/src/main/java/iridiumcore/nms/NMS_V1_20_R2.java
Original file line number Diff line number Diff line change
@@ -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<Player> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<NMS> nmsSupplier;
private final JavaPluginSupplier<MultiVersion> multiVersionSupplier;
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5ef63ef

Please sign in to comment.