mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Created 1.18 R1 (plugin's native version) nms package.
Created 1.18 R1 handling of sending player abilities packet and tested on spigot. Documented force_protocolib config.
This commit is contained in:
parent
6c5eab6fff
commit
0f2a295039
15 changed files with 201 additions and 67 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,5 +5,6 @@
|
|||
.lastDeploymentsId
|
||||
|
||||
#nms submodule build directory ignored
|
||||
/nms/build
|
||||
/nms/*/build
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ plugins {
|
|||
`maven-publish`
|
||||
signing
|
||||
id("cn.lalaki.central").version("1.2.5")
|
||||
id("io.papermc.paperweight.userdev") version "1.7.1" apply false
|
||||
}
|
||||
|
||||
group = "xyz.alexcrea"
|
||||
|
|
@ -22,6 +23,9 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
// Spigot api
|
||||
compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT")
|
||||
|
||||
// Gui library
|
||||
implementation("com.github.stefvanschie.inventoryframework:IF:0.10.14")
|
||||
|
||||
|
|
@ -34,6 +38,7 @@ dependencies {
|
|||
|
||||
// Include nms
|
||||
implementation(project(":nms:nms-common"))
|
||||
implementation(project(":nms:v1_18R1", configuration = "reobf"))
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -46,33 +51,32 @@ allprojects {
|
|||
|
||||
// Spigot repository
|
||||
maven(url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
|
||||
|
||||
// Paper repository
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(kotlin("stdlib"))
|
||||
|
||||
// We assume nms part will not require version specific api.
|
||||
// If any issue occur because of this assumption. please fell free to edit.
|
||||
compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT")
|
||||
|
||||
// Currently not used. but it would be useful to test.
|
||||
testImplementation(platform("org.junit:junit-bom:5.9.1"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
}
|
||||
|
||||
tasks.getByName<Test>("test") {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
// Configure used version of kotlin and java
|
||||
java {
|
||||
disableAutoTargetJvm()
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(20))
|
||||
}
|
||||
|
||||
tasks.getByName<Test>("test") {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
// Set target version
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
sourceCompatibility = "16" // We aim for java 16 for minecraft 1.16.5. even if it not really suported.
|
||||
sourceCompatibility = "16" // We aim for java 16 for minecraft 1.16.5. even if it not really suported by custom anvil.
|
||||
targetCompatibility = "16"
|
||||
|
||||
options.encoding = "UTF-8"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
// Spigot api
|
||||
compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT")
|
||||
|
||||
// Protocolib
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,14 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.packet
|
||||
|
||||
// ProtocoLib not installed and not in a supported version: We do nothing
|
||||
class NoPacketManager: AbstractPacketManager()
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class NoPacketManager: PacketManager {
|
||||
|
||||
override val canSetInstantBuild: Boolean
|
||||
get() = false
|
||||
|
||||
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
|
||||
// ProtocoLib not installed and not in a supported version: We do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.packet
|
||||
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.Listener
|
||||
|
||||
abstract class PacketManagerBase() : PacketManager, Listener {
|
||||
|
||||
abstract class AbstractPacketManager : PacketManager {
|
||||
override val canSetInstantBuild: Boolean
|
||||
get() = false
|
||||
|
||||
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
|
||||
// Default empty.
|
||||
// Default implementation is empty.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.packet;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PacketManagerSelector {
|
||||
|
||||
private PacketManagerSelector(){}
|
||||
|
||||
public static @NotNull PacketManager selectPacketManager(boolean forceProtocolib){
|
||||
// Try to find version
|
||||
if(forceProtocolib){
|
||||
PacketManager protocolibPacketManager = getProtocolibIfPresent();
|
||||
if(protocolibPacketManager != null) return protocolibPacketManager;
|
||||
}
|
||||
|
||||
PacketManager versionSpecificManager = getVersionSpecificManager();
|
||||
if(versionSpecificManager != null) return versionSpecificManager;
|
||||
|
||||
if(!forceProtocolib){
|
||||
PacketManager protocolibPacketManager = getProtocolibIfPresent();
|
||||
if(protocolibPacketManager != null) return protocolibPacketManager;
|
||||
}
|
||||
return new NoPacketManager();
|
||||
}
|
||||
|
||||
private static @Nullable PacketManager getProtocolibIfPresent(){
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) return new ProtocoLibWrapper();
|
||||
return null;
|
||||
}
|
||||
|
||||
private static @Nullable PacketManager getVersionSpecificManager() {
|
||||
|
||||
|
||||
//TODO depending on version. find the manager !
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
43
nms/v1_18R1/build.gradle.kts
Normal file
43
nms/v1_18R1/build.gradle.kts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
group = rootProject.group
|
||||
version = rootProject.version
|
||||
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":nms:nms-common"))
|
||||
|
||||
// Used for nms
|
||||
paperweight.paperDevBundle("1.18-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
|
||||
}
|
||||
|
||||
// As minecraft 1.18 work with java 1.17 or above. we set language version to 1.17
|
||||
|
||||
// Configure used version of kotlin and java
|
||||
java {
|
||||
disableAutoTargetJvm()
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
|
||||
// Set target version
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
sourceCompatibility = "17"
|
||||
targetCompatibility = "17"
|
||||
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0)
|
||||
jvmTarget.set(JvmTarget.JVM_17)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.packet.versions
|
||||
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket
|
||||
import net.minecraft.world.entity.player.Abilities
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer
|
||||
import org.bukkit.entity.Player
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
|
||||
|
||||
class V1_18R1_Manager : PacketManagerBase(), PacketManager {
|
||||
override val canSetInstantBuild: Boolean
|
||||
get() = true
|
||||
|
||||
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
|
||||
val nmsPlayer = (player as CraftPlayer).handle
|
||||
val playerAbilities = nmsPlayer.abilities
|
||||
val sendedAbilities: Abilities
|
||||
if (playerAbilities.instabuild == instantBuild) {
|
||||
sendedAbilities = playerAbilities
|
||||
} else {
|
||||
sendedAbilities = Abilities()
|
||||
sendedAbilities.invulnerable = playerAbilities.invulnerable
|
||||
sendedAbilities.flying = playerAbilities.flying
|
||||
sendedAbilities.mayfly = playerAbilities.mayfly
|
||||
sendedAbilities.instabuild = instantBuild
|
||||
sendedAbilities.mayBuild = playerAbilities.mayBuild
|
||||
sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed
|
||||
sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed
|
||||
}
|
||||
val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities)
|
||||
nmsPlayer.connection.send(packet)
|
||||
}
|
||||
}
|
||||
|
|
@ -2,3 +2,5 @@ rootProject.name = "CustomAnvil"
|
|||
|
||||
include("nms:nms-common")
|
||||
findProject(":nms:nms-common")?.name = "nms-common"
|
||||
include("nms:v1_18R1")
|
||||
findProject(":nms:v1_18R1")?.name = "v1_18R1"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.update;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -7,9 +8,14 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
public class UpdateUtils {
|
||||
public final static String MINECRAFT_VERSION_PATH = "lowMinecraftVersion";
|
||||
public static final String MINECRAFT_VERSION_PATH = "lowMinecraftVersion";
|
||||
|
||||
static int[] readVersionFromString(String versionString){
|
||||
public static int[] currentMinecraftVersion(){
|
||||
String versionString = Bukkit.getServer().getBukkitVersion().split("-")[0];
|
||||
return UpdateUtils.readVersionFromString(versionString);
|
||||
}
|
||||
|
||||
public static int[] readVersionFromString(String versionString){
|
||||
String[] partialVersion = versionString.split("\\.");
|
||||
int[] versionParts = new int[]{0, 0, 0};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.update;
|
||||
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
|
||||
|
|
@ -23,8 +22,7 @@ public class Update_1_21 {
|
|||
}
|
||||
}
|
||||
|
||||
String versionString = Bukkit.getServer().getBukkitVersion().split("-")[0];
|
||||
int[] versionParts = UpdateUtils.readVersionFromString(versionString);
|
||||
int[] versionParts = UpdateUtils.currentMinecraftVersion();
|
||||
|
||||
// Test 1.21
|
||||
if((versionParts[0] >= 1) && (versionParts[1] >= 21)){
|
||||
|
|
|
|||
|
|
@ -98,6 +98,12 @@ class CustomAnvil : JavaPlugin() {
|
|||
chatListener = ChatEventListener()
|
||||
server.pluginManager.registerEvents(chatListener, this)
|
||||
|
||||
// Load default configuration
|
||||
if (!ConfigHolder.loadDefaultConfig()) {
|
||||
logger.log(Level.SEVERE,"could not load default config.")
|
||||
return
|
||||
}
|
||||
|
||||
// Load dependency
|
||||
DependencyManager.loadDependency()
|
||||
|
||||
|
|
@ -113,12 +119,6 @@ class CustomAnvil : JavaPlugin() {
|
|||
}
|
||||
|
||||
private fun loadEnchantmentSystem(){
|
||||
// Load default configuration
|
||||
if (!ConfigHolder.loadDefaultConfig()) {
|
||||
logger.log(Level.SEVERE,"could not load default config.")
|
||||
return
|
||||
}
|
||||
|
||||
// Register enchantments
|
||||
CAEnchantmentRegistry.getInstance().registerBukkit()
|
||||
DependencyManager.registerEnchantments()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ object DependencyManager {
|
|||
fun loadDependency(){
|
||||
val pluginManager = Bukkit.getPluginManager()
|
||||
|
||||
// ProtocolLib dependency
|
||||
// Packet Manager
|
||||
val forceProtocolib = ConfigHolder.DEFAULT_CONFIG.config.getBoolean("force_protocolib", false)
|
||||
packetManager = PacketManagerSelector.selectPacketManager(forceProtocolib)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.packet
|
||||
|
||||
import org.bukkit.Bukkit
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.versions.V1_18R1_Manager
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils
|
||||
|
||||
object PacketManagerSelector {
|
||||
fun selectPacketManager(forceProtocolib: Boolean): PacketManager {
|
||||
// Try to find version
|
||||
return if (forceProtocolib)
|
||||
protocolibIfPresent
|
||||
else
|
||||
versionSpecificManager ?: protocolibIfPresent
|
||||
}
|
||||
|
||||
private val protocolibIfPresent: PacketManager
|
||||
get() =
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib"))
|
||||
ProtocoLibWrapper()
|
||||
else
|
||||
NoPacketManager()
|
||||
private val versionSpecificManager: PacketManager?
|
||||
get() {
|
||||
val versionParts = UpdateUtils.currentMinecraftVersion()
|
||||
if (versionParts[0] != 1) return null;
|
||||
|
||||
return when (versionParts[1]) {
|
||||
16 -> when (versionParts[2]) {
|
||||
4, 5 -> null // TODO V1_16R3 (if possible)
|
||||
else -> null
|
||||
}
|
||||
|
||||
17 -> when (versionParts[2]) {
|
||||
0, 1 -> null // TODO V1_17R1 (if possible)
|
||||
else -> null
|
||||
}
|
||||
|
||||
18 -> when (versionParts[2]) {
|
||||
0, 1 -> V1_18R1_Manager()
|
||||
2 -> null // TODO V1_18R2
|
||||
else -> null
|
||||
}
|
||||
|
||||
19 -> when (versionParts[2]) {
|
||||
0, 1, 2 -> null // TODO V1_19R1
|
||||
3 -> null // TODO V1_19R2
|
||||
4 -> null // TODO V1_19R3
|
||||
else -> null
|
||||
}
|
||||
|
||||
20 -> when (versionParts[2]) {
|
||||
0, 1 -> null // TODO V1_20R1
|
||||
2 -> null // TODO V1_20R2
|
||||
3, 4 -> null // TODO V1_20R3
|
||||
5, 6 -> null // TODO V1_20R4
|
||||
else -> null
|
||||
}
|
||||
|
||||
21 -> when (versionParts[2]) {
|
||||
0 -> null // TODO V1_21R1
|
||||
else -> null
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -265,4 +265,10 @@ debug_log: false
|
|||
# Whether to show verbose debug logging
|
||||
debug_log_verbose: false
|
||||
|
||||
# In case something when wrong with CustomAnvil packet manager.
|
||||
# If you see "missing class exception" or similar you may test this.
|
||||
# If enabled and Protocolib absent or disabled "Replace to expensive" will not work.
|
||||
# ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled.
|
||||
force_protocolib: false
|
||||
|
||||
configVersion: 1.4.5
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue