Skip to content

Commit

Permalink
Fix 1.20.4-1.20.6 support (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlsf authored Oct 7, 2024
1 parent 13c67ad commit 142b5d5
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v3
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
java-version: 21
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
java
`maven-publish`
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.github.goooler.shadow") version "8.1.8"
}

group = "com.iridium"
version = "2.0.6"
version = "2.0.7"
description = "IridiumCore"

allprojects {
Expand Down
6 changes: 6 additions & 0 deletions multiversion/v1_20_R3/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.4-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot:1.20.4")
compileOnly(project(":multiversion:common"))
compileOnly("io.papermc:paperlib:1.0.8")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.iridium.iridiumcore.multiversion;

import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;

public class IridiumInventory_V1_20_R3 extends IridiumInventory {
@Override
public Inventory getTopInventory(Player player) {
return player.getOpenInventory().getTopInventory();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.iridium.iridiumcore.multiversion;

import com.cryptomorin.xseries.XMaterial;
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_R3 extends MultiVersion {

public MultiVersion_V1_20_R3(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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.iridium.iridiumcore.nms;

import com.iridium.iridiumcore.Color;
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_R3 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_R4/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.6-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot:1.20.6")
compileOnly(project(":multiversion:common"))
compileOnly("io.papermc:paperlib:1.0.8")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.iridium.iridiumcore.multiversion;

import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;

public class IridiumInventory_V1_20_R4 extends IridiumInventory {
@Override
public Inventory getTopInventory(Player player) {
return player.getOpenInventory().getTopInventory();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.iridium.iridiumcore.multiversion;

import com.cryptomorin.xseries.XMaterial;
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_R4 extends MultiVersion {

public MultiVersion_V1_20_R4(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);
}

}
Loading

0 comments on commit 142b5d5

Please sign in to comment.