add deprecated
This commit is contained in:
parent
2e9d684622
commit
660dd4f029
|
|
@ -0,0 +1,16 @@
|
|||
package cc.maxmc.servux
|
||||
|
||||
import cc.maxmc.servux.network.packet.StructureDataPacketHandler
|
||||
import org.bukkit.Bukkit
|
||||
import taboolib.common.platform.Plugin
|
||||
import taboolib.platform.BukkitPlugin
|
||||
|
||||
object ServuxServer: Plugin() {
|
||||
override fun onEnable() {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(BukkitPlugin.getInstance(), StructureDataPacketHandler.CHANNEL)
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(BukkitPlugin.getInstance(), StructureDataPacketHandler.CHANNEL) { string, player, byte ->
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
package cc.maxmc.servux.dataproviders
|
||||
|
||||
import net.minecraft.resources.MinecraftKey
|
||||
import kotlin.math.max
|
||||
|
||||
abstract class DataProviderBase protected constructor(
|
||||
override val name: String,
|
||||
override val networkChannel: MinecraftKey,
|
||||
override val networkChannel: String,
|
||||
override val protocolVersion: Int,
|
||||
override val description: String
|
||||
override val description: String,
|
||||
) : IDataProvider {
|
||||
override var isEnabled = false
|
||||
override var tickRate = 40
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
package cc.maxmc.servux.dataproviders
|
||||
|
||||
import net.minecraft.resources.MinecraftKey
|
||||
|
||||
interface IDataProvider {
|
||||
/**
|
||||
* Returns the simple name for this data provider.
|
||||
|
|
@ -29,7 +27,7 @@ interface IDataProvider {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
val networkChannel: MinecraftKey
|
||||
val networkChannel: String
|
||||
|
||||
/**
|
||||
* Returns the current protocol version this provider supports
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
package cc.maxmc.servux.dataproviders
|
||||
|
||||
// native NBT
|
||||
// World Structure
|
||||
import cc.maxmc.servux.network.packet.StructureDataPacketHandler
|
||||
import cc.maxmc.servux.util.ChunkPos
|
||||
import cc.maxmc.servux.util.PlayerDimensionPosition
|
||||
import cc.maxmc.servux.util.Timeout
|
||||
import cc.maxmc.servux.util.*
|
||||
import io.netty.buffer.Unpooled
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet
|
||||
import it.unimi.dsi.fastutil.longs.LongSet
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.nbt.NBTTagList
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.world.level.ChunkCoordIntPair
|
||||
import net.minecraft.world.level.levelgen.feature.StructureGenerator
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart
|
||||
|
|
@ -16,23 +16,32 @@ import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSeriali
|
|||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Chunk
|
||||
import org.bukkit.World
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftChunk
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld
|
||||
import org.bukkit.entity.Player
|
||||
import taboolib.platform.BukkitPlugin
|
||||
import java.util.*
|
||||
import kotlin.math.abs
|
||||
|
||||
object StructureDataProvider : DataProviderBase("structure_bounding_boxes",
|
||||
class StructureDataProvider : DataProviderBase("structure_bounding_boxes",
|
||||
StructureDataPacketHandler.CHANNEL,
|
||||
StructureDataPacketHandler.PROTOCOL_VERSION,
|
||||
"Structure Bounding Boxes data for structures such as Witch Huts, Ocean Monuments, Nether Fortresses etc.") {
|
||||
|
||||
val registeredPlayers = HashMap<UUID, PlayerDimensionPosition>()
|
||||
val timeouts = HashMap<UUID, MutableMap<ChunkPos, Timeout>>()
|
||||
companion object {
|
||||
private const val timeout = 30 * 20
|
||||
private const val updateInterval = 40
|
||||
}
|
||||
|
||||
private val registeredPlayers = HashMap<UUID, PlayerDimensionPosition>()
|
||||
private val timeouts = HashMap<UUID, MutableMap<ChunkPos, Timeout>>()
|
||||
val metadata: NBTTagCompound = NBTTagCompound()
|
||||
const val timeout = 30 * 20
|
||||
const val updateInterval = 40
|
||||
var retainDistance = 0
|
||||
|
||||
init {
|
||||
metadata.putString("id", StructureDataPacketHandler.CHANNEL)
|
||||
metadata.putInt("timeout", timeout)
|
||||
metadata.putInt("version", StructureDataPacketHandler.PROTOCOL_VERSION)
|
||||
}
|
||||
|
||||
private var retainDistance = 0
|
||||
|
||||
override fun shouldTick(): Boolean = true
|
||||
|
||||
|
|
@ -83,7 +92,7 @@ object StructureDataProvider : DataProviderBase("structure_bounding_boxes",
|
|||
) {
|
||||
val positionsToUpdate: MutableSet<ChunkPos> = HashSet()
|
||||
map.forEach { (key, timeout) ->
|
||||
if (timeout.needsUpdate(tickCounter, this.timeout)) {
|
||||
if (timeout.needsUpdate(tickCounter, Companion.timeout)) {
|
||||
positionsToUpdate.add(key)
|
||||
}
|
||||
}
|
||||
|
|
@ -123,8 +132,8 @@ object StructureDataProvider : DataProviderBase("structure_bounding_boxes",
|
|||
if (!world.isChunkLoaded(chunkX, chunkZ)) {
|
||||
return
|
||||
}
|
||||
|
||||
val chunk = ((world.getChunkAt(chunkX, chunkZ) as CraftChunk).handle) as net.minecraft.world.level.chunk.Chunk
|
||||
val nmsWorld = NMS.INSTANCE.getMinecraftServer().allLevels.findLast { it.serverLevelData.levelName == world.name }!!
|
||||
val chunk = nmsWorld.getChunk(chunkX, chunkZ)
|
||||
chunk.allReferences.forEach { (feature, startChunks) ->
|
||||
if (!startChunks.isEmpty() && feature != StructureGenerator.MINESHAFT) {
|
||||
references.merge(feature, startChunks) { oldSet, entrySet ->
|
||||
|
|
@ -149,7 +158,7 @@ object StructureDataProvider : DataProviderBase("structure_bounding_boxes",
|
|||
// System.out.printf("sendStructures: starts: %d -> structureList: %d. refs: %s\n", starts.size(), structureList.size(), references.keySet());
|
||||
val tag = NBTTagCompound()
|
||||
tag.put("Structures", structureList)
|
||||
PacketSplitter.sendPacketTypeAndCompound(StructureDataPacketHandler.CHANNEL,
|
||||
sendPacketTypeAndCompound(StructureDataPacketHandler.CHANNEL,
|
||||
StructureDataPacketHandler.PACKET_S2C_STRUCTURE_DATA,
|
||||
tag,
|
||||
player)
|
||||
|
|
@ -168,8 +177,8 @@ object StructureDataProvider : DataProviderBase("structure_bounding_boxes",
|
|||
if (!world.isChunkLoaded(pos.x, pos.z)) {
|
||||
continue
|
||||
}
|
||||
val chunk = (world.getChunkAt(pos.x,
|
||||
pos.z) as CraftChunk).handle as net.minecraft.world.level.chunk.Chunk
|
||||
val nmsWorld = NMS.INSTANCE.getMinecraftServer().allLevels.findLast { it.serverLevelData.levelName == world.name }!!
|
||||
val chunk = nmsWorld.getChunk(pos.x, pos.z)
|
||||
val start: StructureStart<*> = chunk.getStartForFeature(feature) ?: return@forEach
|
||||
starts[pos] = start
|
||||
}
|
||||
|
|
@ -196,8 +205,76 @@ object StructureDataProvider : DataProviderBase("structure_bounding_boxes",
|
|||
private fun getStructureList(structures: Map<ChunkPos, StructureStart<*>>, world: World): NBTTagList {
|
||||
val list = NBTTagList()
|
||||
structures.forEach { (pos, value) ->
|
||||
list.add(value.createTag(StructurePieceSerializationContext.fromLevel((world as CraftWorld).handle), ChunkCoordIntPair(pos.x, pos.z)))
|
||||
list.add(value.createTag(StructurePieceSerializationContext.fromLevel(NMS.INSTANCE.getMinecraftServer().allLevels.findLast { it.serverLevelData.levelName == world.name }!!),
|
||||
ChunkCoordIntPair(pos.x, pos.z)))
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun register(player: Player): Boolean {
|
||||
// System.out.printf("register\n");
|
||||
var registered = false
|
||||
val uuid: UUID = player.uniqueId
|
||||
if (!registeredPlayers.containsKey(uuid)) {
|
||||
val bytebuf = Unpooled.buffer()
|
||||
sendPacketTypeAndCompound(StructureDataPacketHandler.CHANNEL,
|
||||
StructureDataPacketHandler.PACKET_S2C_METADATA,
|
||||
metadata,
|
||||
player)
|
||||
registeredPlayers[uuid] = PlayerDimensionPosition(player)
|
||||
val tickCounter: Int = Bukkit.getServer().ticksPerAmbientSpawns
|
||||
this.initialSyncStructuresToPlayerWithinRange(player,
|
||||
Bukkit.getViewDistance(),
|
||||
tickCounter)
|
||||
registered = true
|
||||
}
|
||||
return registered
|
||||
}
|
||||
|
||||
private fun initialSyncStructuresToPlayerWithinRange(
|
||||
player: Player,
|
||||
chunkRadius: Int,
|
||||
tickCounter: Int,
|
||||
) {
|
||||
val uuid: UUID = player.uniqueId
|
||||
val center = ChunkPos(player.location.chunk)
|
||||
val references: Map<StructureGenerator<*>, LongSet> =
|
||||
this.getStructureReferencesWithinRange(player.world, center, chunkRadius)
|
||||
timeouts.remove(uuid)
|
||||
registeredPlayers.computeIfAbsent(uuid) { u: UUID? ->
|
||||
PlayerDimensionPosition(player)
|
||||
}.setPosition(player)
|
||||
|
||||
// System.out.printf("initialSyncStructuresToPlayerWithinRange: references: %d\n", references.size());
|
||||
sendStructures(player, references, tickCounter)
|
||||
}
|
||||
|
||||
private fun getStructureReferencesWithinRange(
|
||||
world: World,
|
||||
center: ChunkPos,
|
||||
chunkRadius: Int,
|
||||
): Map<StructureGenerator<*>, LongSet> {
|
||||
val references = HashMap<StructureGenerator<*>, LongSet>()
|
||||
for (cx in center.x - chunkRadius..center.x + chunkRadius) {
|
||||
for (cz in center.z - chunkRadius..center.z + chunkRadius) {
|
||||
getStructureReferencesFromChunk(cx, cz, world, references)
|
||||
}
|
||||
}
|
||||
|
||||
// System.out.printf("getStructureReferencesWithinRange: references: %d\n", references.size());
|
||||
return references
|
||||
}
|
||||
|
||||
private fun sendPacketTypeAndCompound(
|
||||
channel: String,
|
||||
packetType: Int,
|
||||
data: NBTTagCompound,
|
||||
player: Player,
|
||||
) {
|
||||
val buf = Unpooled.buffer()
|
||||
buf.writeVarInt(packetType)
|
||||
buf.writeNBT(data)
|
||||
buf.readBytes(ByteArray(buf.capacity()))
|
||||
player.sendPluginMessage(BukkitPlugin.getInstance(), channel, buf.array())
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,17 @@
|
|||
package cc.maxmc.servux.network.packet;
|
||||
|
||||
import cc.maxmc.servux.dataproviders.StructureDataProvider;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class StructureDataPacketHandler {
|
||||
public static final MinecraftKey CHANNEL = new MinecraftKey("servux:structures");
|
||||
public static final String CHANNEL = "servux:structures";
|
||||
public static final StructureDataPacketHandler INSTANCE = new StructureDataPacketHandler();
|
||||
|
||||
public static final int PROTOCOL_VERSION = 1;
|
||||
public static final int PACKET_S2C_METADATA = 1;
|
||||
public static final int PACKET_S2C_STRUCTURE_DATA = 2;
|
||||
|
||||
public MinecraftKey getChannel() {
|
||||
public String getChannel() {
|
||||
return CHANNEL;
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +20,7 @@ public class StructureDataPacketHandler {
|
|||
}
|
||||
|
||||
public boolean subscribe(Player player) {
|
||||
return StructureDataProvider.register(netHandler.player);
|
||||
return StructureDataProvider.register(player);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(Player player) {
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package cc.maxmc.servux.util
|
||||
|
||||
import org.bukkit.Chunk
|
||||
|
||||
data class ChunkPos(var x: Int, var z: Int) {
|
||||
constructor(pos: Long) : this(pos.toInt(), (pos shr 32).toInt())
|
||||
constructor(chunk: Chunk) : this(chunk.x, chunk.z)
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package cc.maxmc.servux.util
|
||||
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import taboolib.module.nms.nmsProxy
|
||||
|
||||
abstract class NMS {
|
||||
abstract fun getMinecraftServer(): MinecraftServer
|
||||
|
||||
companion object {
|
||||
val INSTANCE = nmsProxy<NMS>()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package cc.maxmc.servux.util
|
||||
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftServer
|
||||
|
||||
class NMSImpl: NMS() {
|
||||
override fun getMinecraftServer(): MinecraftServer {
|
||||
val cServer = Bukkit.getServer() as CraftServer
|
||||
return cServer.server
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package cc.maxmc.servux.util
|
||||
|
||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket
|
||||
import taboolib.common.platform.event.SubscribeEvent
|
||||
import taboolib.module.nms.PacketSendEvent
|
||||
|
||||
class PacketListener {
|
||||
@SubscribeEvent
|
||||
fun onPacket(e: PacketSendEvent) {
|
||||
if(e.packet.source is ClientboundLevelChunkWithLightPacket)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package cc.maxmc.servux.util
|
||||
|
||||
import io.netty.buffer.ByteBuf
|
||||
import io.netty.buffer.ByteBufOutputStream
|
||||
import io.netty.handler.codec.EncoderException
|
||||
import net.minecraft.nbt.NBTCompressedStreamTools
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import java.io.IOException
|
||||
|
||||
fun ByteBuf.writeVarInt(value: Int): ByteBuf {
|
||||
var value = value
|
||||
while (value and -128 != 0) {
|
||||
this.writeByte(value and 127 or 128)
|
||||
value = value ushr 7
|
||||
}
|
||||
this.writeByte(value)
|
||||
return this
|
||||
}
|
||||
|
||||
fun ByteBuf.writeNBT(compound: NBTTagCompound?): ByteBuf {
|
||||
if (compound == null) {
|
||||
this.writeByte(0)
|
||||
} else {
|
||||
try {
|
||||
NBTCompressedStreamTools.write(compound, ByteBufOutputStream(this))
|
||||
} catch (var3: IOException) {
|
||||
throw EncoderException(var3)
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
|
@ -2,11 +2,13 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.6.10"
|
||||
id("io.papermc.paperweight.userdev") version "1.3.3"
|
||||
id("io.izzel.taboolib") version "1.34"
|
||||
}
|
||||
|
||||
group = "cc.maxmc.servux"
|
||||
version = "1.0.0"
|
||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
|
||||
taboolib {
|
||||
description {
|
||||
|
|
@ -16,22 +18,32 @@ taboolib {
|
|||
}
|
||||
install("common")
|
||||
install("platform-bukkit")
|
||||
install("module-nms")
|
||||
version = "6.0.7-26"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.google.code.gson:gson:2.8.9")
|
||||
paperDevBundle("1.18.1-R0.1-SNAPSHOT")
|
||||
// implementation("com.google.code.gson:gson:2.8.9")
|
||||
compileOnly(kotlin("stdlib"))
|
||||
compileOnly("it.unimi.dsi:fastutil:8.5.6")
|
||||
compileOnly("ink.ptms.core:v11800:11800:api")
|
||||
compileOnly("ink.ptms.core:v11800:11800:mapped")
|
||||
compileOnly("ink.ptms.core:v11800:11800:universal")
|
||||
// compileOnly("it.unimi.dsi:fastutil:8.5.6")
|
||||
// compileOnly("ink.ptms.core:v11800:11800:api")
|
||||
// compileOnly("ink.ptms.core:v11800:11800:mapped")
|
||||
// compileOnly("ink.ptms.core:v11800:11800:universal")
|
||||
// compileOnly("io.netty:netty-all:4.1.25.Final")
|
||||
}
|
||||
|
||||
tasks {
|
||||
assemble {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "16"
|
||||
kotlinOptions.jvmTarget = "17"
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
|
||||
rootProject.name = "ServuxSpigot"
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
package cc.maxmc.servux
|
||||
|
||||
import taboolib.platform.BukkitPlugin
|
||||
|
||||
object ServuxServer: BukkitPlugin()
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package cc.maxmc.servux
|
||||
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftServer
|
||||
|
||||
//object ServuxTLib: Plugin() {
|
||||
// override fun onEnable() {
|
||||
// init()
|
||||
// }
|
||||
//}
|
||||
|
||||
fun init() {
|
||||
println(MinecraftServer.getServer().isReady)
|
||||
val server = Bukkit.getServer() as CraftServer
|
||||
server.server.console.sendMessage("Native Console log with CraftBukkit!!!!!")
|
||||
}
|
||||
Loading…
Reference in New Issue