Skip to content

Commit

Permalink
v3.4.1.0
Browse files Browse the repository at this point in the history
-Added NMSChunk.getBukkitChunk
-Added NMSWorld.getBlockUtil
-Fixed chunk saving issue for higher minecraft versions

Took 36 minutes
  • Loading branch information
Jake-Moore committed Aug 28, 2024
1 parent 3306b0f commit 65a3530
Show file tree
Hide file tree
Showing 81 changed files with 598 additions and 318 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import java.util.*

@Suppress("PropertyName")
var VERSION = "3.4.0.14"
var VERSION = "3.4.1.0"

plugins { // needed for the subprojects section to work
id("java")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.kamikazejam.kamicommon.nms.wrappers.chunk;

import com.kamikazejam.kamicommon.nms.wrappers.NMSObject;
import org.bukkit.Chunk;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings("unused")
public interface NMSChunk extends NMSObject {
@NotNull NMSChunkProvider getNMSChunkProvider();
@NotNull Chunk getBukkitChunk();

@NotNull
NMSChunkSection getSection(int y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ default void setForceChunkLoad(boolean value) {
// Do nothing (most versions can't change this)
}

@NotNull
NMSChunk getOrCreateChunk(int x, int z);

void saveChunk(@NotNull NMSChunk chunk);

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.kamikazejam.kamicommon.nms.wrappers.chunk.impl;

import com.cryptomorin.xseries.XMaterial;
import com.kamikazejam.kamicommon.nms.abstraction.block.PlaceType;
import com.kamikazejam.kamicommon.nms.wrappers.chunk.NMSChunk;
import com.kamikazejam.kamicommon.nms.wrappers.world.NMSWorld;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;

@SuppressWarnings("unused")
public interface NMSChunkDef extends NMSChunk {

@Override
Expand All @@ -16,8 +22,24 @@ default void saveAndRefresh(boolean withUpdatePackets) {
// Create a default inside this internal interface, to not expose this method
@SuppressWarnings("deprecation")
default void saveAndRefreshI(boolean withUpdatePackets) {
World world = this.getNMSChunkProvider().getNMSWorld().getBukkitWorld();
// Higher versions are lazy about saving chunks, relying on dirty flags
// We can set one block in the chunk in order to flag it as dirty, ensuring it saves
// We select a block at the minimum y, since it's likely to be BEDROCK
// Technically if there is a block data type here it will get overwritten, but this is unlikely
NMSWorld nmsWorld = this.getNMSChunkProvider().getNMSWorld();
Chunk chunk = this.getBukkitChunk();
int minY = nmsWorld.getMinHeight();

// Update, then revert the block (sufficient to trigger a 'dirty' state for this chunk)
Block block = chunk.getBlock(0, minY, 0);
Material prev = block.getType();
nmsWorld.getBlockUtil().setBlockSuperFast(block, XMaterial.AIR, PlaceType.NMS);
nmsWorld.getBlockUtil().setBlockSuperFast(block, XMaterial.matchXMaterial(prev), PlaceType.NMS);

// Refresh the chunk
World world = chunk.getWorld();
world.refreshChunk(this.getX(), this.getZ());

// Use the unload method with save
world.unloadChunk(this.getX(), this.getZ(), true);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kamikazejam.kamicommon.nms.wrappers.world;

import com.kamikazejam.kamicommon.nms.abstraction.block.AbstractBlockUtil;
import com.kamikazejam.kamicommon.nms.wrappers.NMSObject;
import com.kamikazejam.kamicommon.nms.wrappers.chunk.NMSChunkProvider;
import org.bukkit.Location;
Expand All @@ -21,4 +22,8 @@ public interface NMSWorld extends NMSObject {

@NotNull
<T extends org.bukkit.entity.Entity> T spawnEntity(@NotNull Location loc, @NotNull Class<T> clazz, @NotNull CreatureSpawnEvent.SpawnReason reason);

// Internal API method
@NotNull
AbstractBlockUtil getBlockUtil();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kamikazejam.kamicommon.nms.wrapper;

import com.kamikazejam.kamicommon.nms.NmsAPI;
import com.kamikazejam.kamicommon.nms.wrappers.NMSWrapper;
import com.kamikazejam.kamicommon.nms.wrappers.world.*;
import org.bukkit.World;
Expand All @@ -14,55 +15,55 @@ public class NMSWorldWrapper extends NMSWrapper<NMSWorld, World> {
}

if (ver == f("1.8")) {
return new NMSWorld_1_8_R1(world);
return new NMSWorld_1_8_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.8.3")) {
return new NMSWorld_1_8_R2(world);
return new NMSWorld_1_8_R2(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.8.8")) {
return new NMSWorld_1_8_R3(world);
return new NMSWorld_1_8_R3(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.9.2")) {
return new NMSWorld_1_9_R1(world);
return new NMSWorld_1_9_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.9.4")) {
return new NMSWorld_1_9_R2(world);
return new NMSWorld_1_9_R2(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.10.2")) {
return new NMSWorld_1_10_R1(world);
return new NMSWorld_1_10_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.11.2")) {
return new NMSWorld_1_11_R1(world);
return new NMSWorld_1_11_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.12.2")) {
return new NMSWorld_1_12_R1(world);
return new NMSWorld_1_12_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.13")) {
return new NMSWorld_1_13_R1(world);
return new NMSWorld_1_13_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.13.2")) {
return new NMSWorld_1_13_R2(world);
return new NMSWorld_1_13_R2(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.14.4")) {
return new NMSWorld_1_14_R1(world);
return new NMSWorld_1_14_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.15.2")) {
return new NMSWorld_1_15_R1(world);
return new NMSWorld_1_15_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.16.1")) {
return new NMSWorld_1_16_R1(world);
return new NMSWorld_1_16_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.16.3")) {
return new NMSWorld_1_16_R2(world);
return new NMSWorld_1_16_R2(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.16.5")) {
return new NMSWorld_1_16_R3(world);
return new NMSWorld_1_16_R3(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.17.1")) {
return new NMSWorld_1_17_R1(world);
return new NMSWorld_1_17_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.18.1")) {
return new NMSWorld_1_18_R1(world);
return new NMSWorld_1_18_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.18.2")) {
return new NMSWorld_1_18_R2(world);
return new NMSWorld_1_18_R2(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.19.2")) {
return new NMSWorld_1_19_R1(world);
return new NMSWorld_1_19_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.19.3")) {
return new NMSWorld_1_19_R2(world);
return new NMSWorld_1_19_R2(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.19.4")) {
return new NMSWorld_1_19_R3(world);
return new NMSWorld_1_19_R3(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.20.1")) {
return new NMSWorld_1_20_R1(world);
return new NMSWorld_1_20_R1(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.20.2")) {
return new NMSWorld_1_20_R2(world);
return new NMSWorld_1_20_R2(world, NmsAPI.getBlockUtilProvider());
}else if (ver <= f("1.20.4")) {
return new NMSWorld_1_20_R3(world);
return new NMSWorld_1_20_R3(world, NmsAPI.getBlockUtilProvider());
}
// With the mojang-mapped paper nms now, we might be good to use this version indefinitely
return new NMSWorld_1_21_CB(world); // Confirmed for 1.20.5, 1.20.6, 1.21
return new NMSWorld_1_21_CB(world, NmsAPI.getBlockUtilProvider()); // Confirmed for 1.20.5, 1.20.6, 1.21
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.kamikazejam.kamicommon.nms.wrappers.world.NMSWorld_1_10_R1;
import net.minecraft.server.v1_10_R1.Chunk;
import net.minecraft.server.v1_10_R1.ChunkProviderServer;
import org.bukkit.craftbukkit.v1_10_R1.CraftChunk;
import org.jetbrains.annotations.NotNull;

public class ChunkProvider_1_10_R1 implements NMSChunkProvider {
Expand All @@ -25,18 +24,13 @@ public ChunkProvider_1_10_R1(@NotNull NMSWorld_1_10_R1 world, @NotNull ChunkProv
return this.handle;
}

@Override
public @NotNull NMSChunk getOrCreateChunk(int x, int z) {
return new Chunk_1_10_R1(this, this.handle.getChunkAt(x, z));
}

@Override
public void saveChunk(NMSChunk chunk) {
this.handle.saveChunk((Chunk) chunk.getHandle());
}

@Override
public @NotNull NMSChunk wrap(org.bukkit.@NotNull Chunk chunk) {
return new Chunk_1_10_R1(this, ((CraftChunk) chunk).getHandle());
return new Chunk_1_10_R1(this, chunk);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@
import net.minecraft.server.v1_10_R1.Chunk;
import net.minecraft.server.v1_10_R1.ChunkSection;
import net.minecraft.server.v1_10_R1.PacketPlayOutMapChunk;
import org.bukkit.craftbukkit.v1_10_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class Chunk_1_10_R1 implements NMSChunkDef {
private final @NotNull ChunkProvider_1_10_R1 provider;
private final @NotNull org.bukkit.Chunk bukkitChunk;
private final @NotNull Chunk chunk;
public Chunk_1_10_R1(@NotNull ChunkProvider_1_10_R1 provider, @NotNull Chunk chunk) {
public Chunk_1_10_R1(@NotNull ChunkProvider_1_10_R1 provider, @NotNull org.bukkit.Chunk bukkitChunk) {
this.provider = provider;
this.chunk = chunk;
this.bukkitChunk = bukkitChunk;
this.chunk = ((CraftChunk) bukkitChunk).getHandle();
}

@Override
public @NotNull NMSChunkProvider getNMSChunkProvider() {
return this.provider;
}

@Override
public @NotNull org.bukkit.Chunk getBukkitChunk() {
return bukkitChunk;
}

@Override
public @NotNull Object getHandle() {
return this.chunk;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.kamikazejam.kamicommon.nms.wrappers.world;

import com.kamikazejam.kamicommon.nms.abstraction.block.AbstractBlockUtil;
import com.kamikazejam.kamicommon.nms.provider.Provider;
import com.kamikazejam.kamicommon.nms.wrappers.chunk.ChunkProvider_1_10_R1;
import com.kamikazejam.kamicommon.nms.wrappers.chunk.NMSChunkProvider;
import lombok.Getter;
Expand All @@ -20,17 +22,24 @@ public class NMSWorld_1_10_R1 implements NMSWorld {
private final @NotNull World bukkitWorld;
private final @NotNull WorldServer worldServer;
private final @NotNull CraftWorld craftWorld;
public NMSWorld_1_10_R1(@NotNull World world) {
private final @NotNull Provider<AbstractBlockUtil> provider;
public NMSWorld_1_10_R1(@NotNull World world, @NotNull Provider<AbstractBlockUtil> provider) {
this.bukkitWorld = world;
this.craftWorld = (CraftWorld) world;
this.worldServer = this.craftWorld.getHandle();
this.provider = provider;
}

@Override
public @NotNull Object getHandle() {
return this.worldServer;
}

@Override
public @NotNull AbstractBlockUtil getBlockUtil() {
return this.provider.get();
}

@Override
public int getMinHeight() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.kamikazejam.kamicommon.nms.wrappers.world.NMSWorld_1_11_R1;
import net.minecraft.server.v1_11_R1.Chunk;
import net.minecraft.server.v1_11_R1.ChunkProviderServer;
import org.bukkit.craftbukkit.v1_11_R1.CraftChunk;
import org.jetbrains.annotations.NotNull;

public class ChunkProvider_1_11_R1 implements NMSChunkProvider {
Expand All @@ -25,18 +24,13 @@ public ChunkProvider_1_11_R1(@NotNull NMSWorld_1_11_R1 world, @NotNull ChunkProv
return this.handle;
}

@Override
public @NotNull NMSChunk getOrCreateChunk(int x, int z) {
return new Chunk_1_11_R1(this, this.handle.getChunkAt(x, z));
}

@Override
public void saveChunk(NMSChunk chunk) {
this.handle.saveChunk((Chunk) chunk.getHandle());
}

@Override
public @NotNull NMSChunk wrap(org.bukkit.@NotNull Chunk chunk) {
return new Chunk_1_11_R1(this, ((CraftChunk) chunk).getHandle());
return new Chunk_1_11_R1(this, chunk);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@
import net.minecraft.server.v1_11_R1.Chunk;
import net.minecraft.server.v1_11_R1.ChunkSection;
import net.minecraft.server.v1_11_R1.PacketPlayOutMapChunk;
import org.bukkit.craftbukkit.v1_11_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class Chunk_1_11_R1 implements NMSChunkDef {
private final @NotNull ChunkProvider_1_11_R1 provider;
private final @NotNull org.bukkit.Chunk bukkitChunk;
private final @NotNull Chunk chunk;
public Chunk_1_11_R1(@NotNull ChunkProvider_1_11_R1 provider, @NotNull Chunk chunk) {
public Chunk_1_11_R1(@NotNull ChunkProvider_1_11_R1 provider, @NotNull org.bukkit.Chunk bukkitChunk) {
this.provider = provider;
this.chunk = chunk;
this.bukkitChunk = bukkitChunk;
this.chunk = ((CraftChunk) bukkitChunk).getHandle();
}

@Override
public @NotNull Object getHandle() {
return this.chunk;
}

@Override
public @NotNull org.bukkit.Chunk getBukkitChunk() {
return bukkitChunk;
}

@Override
public @NotNull NMSChunkProvider getNMSChunkProvider() {
return this.provider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.kamikazejam.kamicommon.nms.wrappers.world;

import com.kamikazejam.kamicommon.nms.abstraction.block.AbstractBlockUtil;
import com.kamikazejam.kamicommon.nms.provider.Provider;
import com.kamikazejam.kamicommon.nms.wrappers.chunk.ChunkProvider_1_11_R1;
import com.kamikazejam.kamicommon.nms.wrappers.chunk.NMSChunkProvider;
import lombok.Getter;
Expand All @@ -20,17 +22,24 @@ public class NMSWorld_1_11_R1 implements NMSWorld {
private final @NotNull World bukkitWorld;
private final @NotNull WorldServer worldServer;
private final @NotNull CraftWorld craftWorld;
public NMSWorld_1_11_R1(@NotNull World world) {
private final @NotNull Provider<AbstractBlockUtil> provider;
public NMSWorld_1_11_R1(@NotNull World world, @NotNull Provider<AbstractBlockUtil> provider) {
this.bukkitWorld = world;
this.craftWorld = (CraftWorld) world;
this.worldServer = this.craftWorld.getHandle();
this.provider = provider;
}

@Override
public @NotNull Object getHandle() {
return this.worldServer;
}

@Override
public @NotNull AbstractBlockUtil getBlockUtil() {
return this.provider.get();
}

@Override
public int getMinHeight() {
return 0;
Expand Down
Loading

0 comments on commit 65a3530

Please sign in to comment.