From 471a683ae3e004ed92d9923da3eb4060812743d6 Mon Sep 17 00:00:00 2001 From: Kalle Struik Date: Sun, 30 Jan 2022 19:37:35 +0100 Subject: [PATCH] Port most features to 1.18.1. Fix redyeTerracotta tweak. --- build.gradle.kts | 45 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 6 + .../kotlin/nl/kallestruik/dtweaks/DTweaks.kt | 30 +- .../dtweaks/commands/CommandMobcaps.kt | 150 ++--- .../dtweaks/commands/CommandPlayer.kt | 56 +- .../dtweaks/commands/CommandPocketdim.kt | 50 +- .../dtweaks/fakeplayer/FakeConnection.kt | 57 +- .../dtweaks/fakeplayer/FakePlayer.kt | 336 ++++++------ .../fakeplayer/FakePlayerConnection.kt | 72 +-- .../dtweaks/fakeplayer/FakePlayerList.kt | 516 +++++++++--------- .../dtweaks/managers/FakePlayerManager.kt | 60 +- .../managers/PocketDimensionManager.kt | 218 ++++---- .../SpaceTimePocketChunkGenerator.kt | 54 +- .../tweaks/craftingtweaks/RedyeTerracotta.kt | 44 +- .../DispensersCanPlantSaplings.kt | 7 +- .../ArmorStandArmorSwapping.kt | 4 +- .../tweaks/miscellaneoustweaks/FakePlayers.kt | 30 +- .../miscellaneoustweaks/SpaceTimePockets.kt | 140 ++--- .../dtweaks/tweaks/mobtweaks/VillagerInfo.kt | 43 +- 20 files changed, 982 insertions(+), 938 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 304999b..ae74679 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,9 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.4.32" + kotlin("jvm") version "1.5.31" id("com.github.johnrengelman.shadow") version "5.2.0" + id("io.papermc.paperweight.userdev") version "1.3.4" } group = "nl.kallestruik" @@ -19,29 +20,17 @@ repositories { dependencies { implementation("co.aikar:acf-paper:0.5.0-SNAPSHOT") - compileOnly("com.destroystokyo.paper:paper:1.16.5-R0.1-SNAPSHOT") + paperDevBundle("1.18.1-R0.1-SNAPSHOT") compileOnly("com.comphenix.protocol:ProtocolLib:4.6.0") compileOnly(kotlin("stdlib-jdk8")) - compileOnly("nl.kallestruik:DLib:1.0") + compileOnly("nl.kallestruik:DLib:1.3.5") testImplementation(kotlin("test-junit5")) testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0") } -tasks.compileJava { - options.compilerArgs.add("-parameters") -} - -tasks.compileKotlin { - kotlinOptions.javaParameters = true -} - -tasks.test { - useJUnitPlatform() -} - tasks.shadowJar { relocate("co.aikar.commands", "nl.kallestruik.dtweaks.acf") relocate("co.aikar.locales", "nl.kallestruik.dtweaks.locales") @@ -51,10 +40,26 @@ tasks.build { dependsOn(tasks.shadowJar) } -tasks.withType { - kotlinOptions.jvmTarget = "11" -} +tasks { + assemble { + dependsOn(reobfJar) + } -tasks.processResources { - expand("version" to project.version) + test { + useJUnitPlatform() + } + + compileJava { + options.compilerArgs.add("-parameters") + } + compileKotlin { + kotlinOptions.javaParameters = true + } + withType { + kotlinOptions.jvmTarget = "11" + } + + processResources { + expand("version" to project.version) + } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index da9702f..e750102 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index fd693a2..c4a8485 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,9 @@ +pluginManagement { + repositories { + gradlePluginPortal() + maven("https://papermc.io/repo/repository/maven-public/") + } +} rootProject.name = "DTweaks" diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/DTweaks.kt b/src/main/kotlin/nl/kallestruik/dtweaks/DTweaks.kt index 155bb89..136f05e 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/DTweaks.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/DTweaks.kt @@ -5,12 +5,7 @@ import co.aikar.commands.PaperCommandManager import nl.kallestruik.dlib.DUtil import nl.kallestruik.dlib.MathHelper import nl.kallestruik.dlib.ReflectionUtil -import nl.kallestruik.dtweaks.commands.CommandMobcaps -import nl.kallestruik.dtweaks.commands.CommandPlayer -import nl.kallestruik.dtweaks.commands.CommandPocketdim import nl.kallestruik.dtweaks.commands.CommandToggletrample -import nl.kallestruik.dtweaks.managers.FakePlayerManager -import nl.kallestruik.dtweaks.managers.PocketDimensionManager import nl.kallestruik.dtweaks.managers.TrampleManager import nl.kallestruik.dtweaks.managers.TweakManager import nl.kallestruik.dtweaks.tweaks.craftingtweaks.* @@ -18,8 +13,6 @@ import nl.kallestruik.dtweaks.tweaks.croptweaks.* import nl.kallestruik.dtweaks.tweaks.dispsensertweaks.DispensersCanPlantSaplings import nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks.ArmorStandArmorSwapping import nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks.CarpetBlockPlacingProtocol -import nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks.FakePlayers -import nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks.SpaceTimePockets import nl.kallestruik.dtweaks.tweaks.mobtweaks.NoCreeperGrief import nl.kallestruik.dtweaks.tweaks.mobtweaks.NoDoorBreaking import nl.kallestruik.dtweaks.tweaks.mobtweaks.NoEndermanGrief @@ -38,8 +31,8 @@ class DTweaks: JavaPlugin() { lateinit var reflectionUtil: ReflectionUtil private lateinit var trampleManager: TrampleManager private lateinit var commandManager: PaperCommandManager - private lateinit var fakePlayerManager: FakePlayerManager - private lateinit var pocketDimensionManager: PocketDimensionManager +// private lateinit var fakePlayerManager: FakePlayerManager +// private lateinit var pocketDimensionManager: PocketDimensionManager } override fun onEnable() { @@ -53,8 +46,8 @@ class DTweaks: JavaPlugin() { reflectionUtil = ReflectionUtil() trampleManager = TrampleManager() commandManager = PaperCommandManager(this) - fakePlayerManager = FakePlayerManager() - pocketDimensionManager = PocketDimensionManager(mathHelper) +// fakePlayerManager = FakePlayerManager() +// pocketDimensionManager = PocketDimensionManager(mathHelper) // Enable brigadier support on ACF commandManager.enableUnstableAPI("brigadier") @@ -64,9 +57,9 @@ class DTweaks: JavaPlugin() { /* * Commands */ - commandManager.registerCommand(CommandMobcaps(reflectionUtil)) - commandManager.registerCommand(CommandPlayer(fakePlayerManager, tweakManager)) - commandManager.registerCommand(CommandPocketdim(pocketDimensionManager)) +// commandManager.registerCommand(CommandMobcaps(reflectionUtil)) +// commandManager.registerCommand(CommandPlayer(fakePlayerManager, tweakManager)) +// commandManager.registerCommand(CommandPocketdim(pocketDimensionManager)) commandManager.registerCommand(CommandToggletrample(trampleManager)) /* @@ -74,7 +67,7 @@ class DTweaks: JavaPlugin() { */ tweakManager.loadFromFile(File(dataFolder, Const.TWEAK_STATE_FILE_NAME)) trampleManager.loadFromFile(File(dataFolder, Const.TRAMPLE_ENABLED_FILE_NAME)) - pocketDimensionManager.loadData() +// pocketDimensionManager.loadData() /* * Crafting tweaks @@ -87,6 +80,7 @@ class DTweaks: JavaPlugin() { tweakManager.registerTweak(CraftableSponge(this)) tweakManager.registerTweak(IceDecompression(this)) tweakManager.registerTweak(LogsToChests(this)) + tweakManager.registerTweak(RedyeTerracotta(this)) tweakManager.registerTweak(WoolToString(this)) /* @@ -109,8 +103,8 @@ class DTweaks: JavaPlugin() { */ tweakManager.registerTweak(ArmorStandArmorSwapping(this)) tweakManager.registerTweak(CarpetBlockPlacingProtocol(this, mathHelper)) - tweakManager.registerTweak(FakePlayers(fakePlayerManager)) - tweakManager.registerTweak(SpaceTimePockets(this, pocketDimensionManager)) +// tweakManager.registerTweak(FakePlayers(fakePlayerManager)) +// tweakManager.registerTweak(SpaceTimePockets(this, pocketDimensionManager)) /* * Mob Tweaks @@ -127,7 +121,7 @@ class DTweaks: JavaPlugin() { */ tweakManager.saveToFile(File(dataFolder, Const.TWEAK_STATE_FILE_NAME)) trampleManager.saveToFile(File(dataFolder, Const.TRAMPLE_ENABLED_FILE_NAME)) - pocketDimensionManager.saveData() +// pocketDimensionManager.saveData() } private fun registerCommandConditions() { diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandMobcaps.kt b/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandMobcaps.kt index 8d7aee5..0f477d1 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandMobcaps.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandMobcaps.kt @@ -1,75 +1,75 @@ -package nl.kallestruik.dtweaks.commands - -import co.aikar.commands.BaseCommand -import co.aikar.commands.annotation.* -import co.aikar.commands.annotation.Optional -import com.mojang.datafixers.util.Pair -import it.unimi.dsi.fastutil.objects.Object2IntMap -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.format.TextColor -import net.minecraft.server.v1_16_R3.ChunkMapDistance -import net.minecraft.server.v1_16_R3.EnumCreatureType -import nl.kallestruik.dlib.ReflectionUtil -import org.bukkit.Bukkit -import org.bukkit.command.CommandSender -import org.bukkit.craftbukkit.v1_16_R3.CraftWorld -import org.bukkit.entity.Player -import java.util.* - -@CommandAlias("mobcaps") -class CommandMobcaps( - private val reflectionUtil: ReflectionUtil -): BaseCommand() { - - @Default - @Subcommand("view") - @CommandCompletion("@worlds") - fun onMobcaps(sender: CommandSender, @Optional worldName: String?) { - var craftWorld: CraftWorld? = null - - if (sender is Player) - craftWorld = (sender.world as CraftWorld) - else if (worldName == null) - sender.sendMessage(Component.text("ERROR: You need to be a player or supply a world name!").color(TextColor.color(0x660000))) - var name = worldName - if (worldName == null) { - name = craftWorld?.name - } else { - val bukkitWorld = Bukkit.getWorld(worldName) - if (bukkitWorld == null) - name = craftWorld?.name - else - craftWorld = (bukkitWorld as CraftWorld) - } - - val world = craftWorld?.handle ?: return - - val chunkMapDistance = ( - reflectionUtil.getValueFromField(world.getChunkProvider(), "chunkMapDistance") - ?: return - ) as ChunkMapDistance - - val chunks = chunkMapDistance.b() - - // world.getChunkManager().getSpawnInfo(); - val spawnInfo = world.getChunkProvider()?.k() ?: return - - val mobs: Object2IntMap = spawnInfo.b() - val mobcaps = EnumMap>( - EnumCreatureType::class.java - ) - for (category in EnumCreatureType.values()) { - if (category == EnumCreatureType.MISC) continue - val cur: Int = mobs[category]?: 0 - val max = chunks * category.c() / (17 * 17) - mobcaps[category] = Pair(cur, max) - } - - sender.sendMessage("=============Mobcaps [${name}]=============") - for ((key, value) in mobcaps) { - val cur = value.first - val max = value.second - sender.sendMessage("${key.getName()}: ${cur}/${max}") - } - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.commands +// +//import co.aikar.commands.BaseCommand +//import co.aikar.commands.annotation.* +//import co.aikar.commands.annotation.Optional +//import com.mojang.datafixers.util.Pair +//import it.unimi.dsi.fastutil.objects.Object2IntMap +//import net.kyori.adventure.text.Component +//import net.kyori.adventure.text.format.TextColor +//import net.minecraft.server.v1_16_R3.ChunkMapDistance +//import net.minecraft.server.v1_16_R3.EnumCreatureType +//import nl.kallestruik.dlib.ReflectionUtil +//import org.bukkit.Bukkit +//import org.bukkit.command.CommandSender +//import org.bukkit.craftbukkit.v1_18_R1.CraftWorld +//import org.bukkit.entity.Player +//import java.util.* +// +//@CommandAlias("mobcaps") +//class CommandMobcaps( +// private val reflectionUtil: ReflectionUtil +//): BaseCommand() { +// +// @Default +// @Subcommand("view") +// @CommandCompletion("@worlds") +// fun onMobcaps(sender: CommandSender, @Optional worldName: String?) { +// var craftWorld: CraftWorld? = null +// +// if (sender is Player) +// craftWorld = (sender.world as CraftWorld) +// else if (worldName == null) +// sender.sendMessage(Component.text("ERROR: You need to be a player or supply a world name!").color(TextColor.color(0x660000))) +// var name = worldName +// if (worldName == null) { +// name = craftWorld?.name +// } else { +// val bukkitWorld = Bukkit.getWorld(worldName) +// if (bukkitWorld == null) +// name = craftWorld?.name +// else +// craftWorld = (bukkitWorld as CraftWorld) +// } +// +// val world = craftWorld?.handle ?: return +// +// val chunkMapDistance = ( +// reflectionUtil.getValueFromField(world.getChunkProvider(), "chunkMapDistance") +// ?: return +// ) as ChunkMapDistance +// +// val chunks = chunkMapDistance.b() +// +// // world.getChunkManager().getSpawnInfo(); +// val spawnInfo = world.getChunkProvider()?.k() ?: return +// +// val mobs: Object2IntMap = spawnInfo.b() +// val mobcaps = EnumMap>( +// EnumCreatureType::class.java +// ) +// for (category in EnumCreatureType.values()) { +// if (category == EnumCreatureType.MISC) continue +// val cur: Int = mobs[category]?: 0 +// val max = chunks * category.c() / (17 * 17) +// mobcaps[category] = Pair(cur, max) +// } +// +// sender.sendMessage("=============Mobcaps [${name}]=============") +// for ((key, value) in mobcaps) { +// val cur = value.first +// val max = value.second +// sender.sendMessage("${key.getName()}: ${cur}/${max}") +// } +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandPlayer.kt b/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandPlayer.kt index 54f8deb..d8c630a 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandPlayer.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandPlayer.kt @@ -1,28 +1,28 @@ -package nl.kallestruik.dtweaks.commands - -import co.aikar.commands.BaseCommand -import co.aikar.commands.annotation.* -import nl.kallestruik.dtweaks.managers.FakePlayerManager -import nl.kallestruik.dtweaks.managers.TweakManager -import org.bukkit.command.CommandSender -import org.bukkit.entity.Player - -@CommandAlias("player") -@Conditions("tweakEnabled:tweak=FakePlayers") -class CommandPlayer( - private val fakePlayerManager: FakePlayerManager, - private val tweakManager: TweakManager -): BaseCommand() { - - @Subcommand("spawn") - @CommandCompletion("@players") - fun onSpawn(sender: Player, @Single playerName: String) { - fakePlayerManager.spawnFakePlayer(sender.location, playerName) - } - - @Subcommand("kill") - @CommandCompletion("@players") - fun onKill(sender: Player, @Single playerName: String) { - fakePlayerManager.killFakePlayer(playerName) - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.commands +// +//import co.aikar.commands.BaseCommand +//import co.aikar.commands.annotation.* +//import nl.kallestruik.dtweaks.managers.FakePlayerManager +//import nl.kallestruik.dtweaks.managers.TweakManager +//import org.bukkit.command.CommandSender +//import org.bukkit.entity.Player +// +//@CommandAlias("player") +//@Conditions("tweakEnabled:tweak=FakePlayers") +//class CommandPlayer( +// private val fakePlayerManager: FakePlayerManager, +// private val tweakManager: TweakManager +//): BaseCommand() { +// +// @Subcommand("spawn") +// @CommandCompletion("@players") +// fun onSpawn(sender: Player, @Single playerName: String) { +// fakePlayerManager.spawnFakePlayer(sender.location, playerName) +// } +// +// @Subcommand("kill") +// @CommandCompletion("@players") +// fun onKill(sender: Player, @Single playerName: String) { +// fakePlayerManager.killFakePlayer(playerName) +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandPocketdim.kt b/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandPocketdim.kt index f7bd7d4..837c50c 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandPocketdim.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/commands/CommandPocketdim.kt @@ -1,25 +1,25 @@ -package nl.kallestruik.dtweaks.commands - -import co.aikar.commands.BaseCommand -import co.aikar.commands.annotation.CommandAlias -import co.aikar.commands.annotation.Conditions -import co.aikar.commands.annotation.Subcommand -import nl.kallestruik.dtweaks.managers.PocketDimensionManager -import org.bukkit.entity.Player - -@CommandAlias("pocketdim") -@Conditions("tweakEnabled:tweak=SpaceTimePockets") -class CommandPocketdim( - private val pocketDimensionManager: PocketDimensionManager -): BaseCommand() { - - @Subcommand("create") - fun onCreate(sender: Player) { - pocketDimensionManager.createPocketForPlayer(sender) - } - - @Subcommand("tp") - fun onTp(sender: Player) { - pocketDimensionManager.teleportPlayerIntoPocket(sender, sender.uniqueId) - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.commands +// +//import co.aikar.commands.BaseCommand +//import co.aikar.commands.annotation.CommandAlias +//import co.aikar.commands.annotation.Conditions +//import co.aikar.commands.annotation.Subcommand +//import nl.kallestruik.dtweaks.managers.PocketDimensionManager +//import org.bukkit.entity.Player +// +//@CommandAlias("pocketdim") +//@Conditions("tweakEnabled:tweak=SpaceTimePockets") +//class CommandPocketdim( +// private val pocketDimensionManager: PocketDimensionManager +//): BaseCommand() { +// +// @Subcommand("create") +// fun onCreate(sender: Player) { +// pocketDimensionManager.createPocketForPlayer(sender) +// } +// +// @Subcommand("tp") +// fun onTp(sender: Player) { +// pocketDimensionManager.teleportPlayerIntoPocket(sender, sender.uniqueId) +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakeConnection.kt b/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakeConnection.kt index 85bf30c..8711b99 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakeConnection.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakeConnection.kt @@ -1,30 +1,27 @@ -package nl.kallestruik.dtweaks.fakeplayer - -import io.netty.util.concurrent.Future -import io.netty.util.concurrent.GenericFutureListener -import net.minecraft.server.v1_16_R3.EnumProtocolDirection -import net.minecraft.server.v1_16_R3.NetworkManager -import net.minecraft.server.v1_16_R3.Packet - -class FakeConnection( - enumProtocolDirection: EnumProtocolDirection -): NetworkManager(enumProtocolDirection) { - var open = true - - // isOpen() - override fun isConnected(): Boolean { - return open - } - - // hasChannel() - override fun i(): Boolean { - return false - } - - override fun sendPacket(packet: Packet<*>?, genericfuturelistener: GenericFutureListener?>?) {} - - // disableAutoRead() - override fun stopReading() {} - - override fun handleDisconnection() {} -} \ No newline at end of file +//package nl.kallestruik.dtweaks.fakeplayer +// +//import io.netty.util.concurrent.Future +//import io.netty.util.concurrent.GenericFutureListener +// +//class FakeConnection( +// enumProtocolDirection: EnumProtocolDirection +//): NetworkManager(enumProtocolDirection) { +// var open = true +// +// // isOpen() +// override fun isConnected(): Boolean { +// return open +// } +// +// // hasChannel() +// override fun i(): Boolean { +// return false +// } +// +// override fun sendPacket(packet: Packet<*>?, genericfuturelistener: GenericFutureListener?>?) {} +// +// // disableAutoRead() +// override fun stopReading() {} +// +// override fun handleDisconnection() {} +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayer.kt b/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayer.kt index e508dce..a1f3d1d 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayer.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayer.kt @@ -1,168 +1,168 @@ -package nl.kallestruik.dtweaks.fakeplayer - -import com.mojang.authlib.GameProfile -import net.minecraft.server.v1_16_R3.* -import nl.kallestruik.dtweaks.DTweaks -import org.bukkit.Location -import org.bukkit.craftbukkit.v1_16_R3.CraftWorld - -class FakePlayer( - minecraftServer: MinecraftServer?, - worldServer: WorldServer?, - gameProfile: GameProfile?, - playerInteractManager: PlayerInteractManager? -): EntityPlayer(minecraftServer, worldServer, gameProfile, playerInteractManager) { - val locale = "en_US" - private var hasStartingPos = false - private var startingX = 0.0 - private var startingY = 0.0 - private var startingZ = 0.0 - private var startingYaw = 0f - private var startingPitch = 0f - - private constructor( - server: MinecraftServer, - worldIn: WorldServer, - profile: GameProfile?, - interactionManagerIn: PlayerInteractManager, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float - ) : this(server, worldIn, profile, interactionManagerIn) { - this.hasStartingPos = true - this.startingX = x - this.startingY = y - this.startingZ = z - this.startingYaw = yaw - this.startingPitch = pitch - applyStartingPosition() - } - - companion object { - fun atLocation(location: Location, name: String?): FakePlayer? { - // Split the location into its parts for use later. - val x = location.x - val y = location.y - val z = location.z - val yaw = location.yaw.toDouble() - val pitch = location.pitch.toDouble() - try { - // Get the minecraft server instance. - val minecraftServer = MinecraftServer.getServer() - // Create an empty variable for the world server. - val worldServer = (location.world as CraftWorld).handle - // Get the game profile from the cache (or retrieve it if it is not cached) - var gameProfile = minecraftServer.userCache.getProfile(name) ?: return null - if (gameProfile.properties.containsKey("textures")) { - gameProfile = TileEntitySkull.b(gameProfile, null, true).get() - } - - // Create a player interact manager using the world server. - val playerInteractManager = PlayerInteractManager(worldServer) - - // Create an instance of our fake player. - val instance = FakePlayer( - minecraftServer, worldServer, gameProfile, playerInteractManager, x, y, z, - yaw.toFloat(), - pitch.toFloat() - ) - // Create a fake connection for our fake player. - val connection = FakeConnection(EnumProtocolDirection.SERVERBOUND) - - // Set access to connected channels so we can add our own connection. - val serverConnection = minecraftServer.serverConnection - - (DTweaks.reflectionUtil.getValueFromField( - serverConnection!!, - "connectedChannels" - ) as MutableList).add(connection) - - // Connect the fake player to the server using the fake connection. - FakePlayerList.a(minecraftServer.playerList, connection, instance) - - // Check if the fake player is not yet in the correct world. - if (instance.world.dimensionKey != worldServer.dimensionKey) { - // Store the old world of the fake player. - val old_world = instance.world as WorldServer - // Remove the fake player from the old world. - old_world.removePlayer(instance) - // Make the fake player not be dead. - instance.dead = false - // Create the fake player in the new world. - worldServer.addEntity(instance) - // Spawn the fake player in the new world. - instance.spawnIn(worldServer) - // Move the fake player to the new world for the server. - minecraftServer.playerList.moveToWorld(instance, old_world, true, null, false) - // requestTeleport(x, y, z, yaw, pitch) - // Request the teleport from the fake player. - instance.playerConnection.a(x, y, z, yaw.toFloat(), pitch.toFloat()) - // Set the fake player's world to the new world. - instance.playerInteractManager.world = worldServer - instance.teleportTo(worldServer, BlockPosition(x, y, z)) - } - - /// Set the fake players health to max. - instance.health = 20.0f - // Make the fake player not be dead. - instance.dead = false - // a == requestTeleport - // Request the teleport from the fake player. - instance.playerConnection.a(x, y, z, yaw.toFloat(), pitch.toFloat()) - // G == stepHeight - // Set the fake players step height to 0.6 (The normal value). - instance.G = 0.6f - // Set the fake players gamemode to survival. - playerInteractManager.gameMode = EnumGamemode.SURVIVAL - // Tell everyone in the world about the fake player and where he is. - minecraftServer.playerList.a( - PacketPlayOutEntityHeadRotation(instance, (instance.yaw * 256 / 360).toByte()), - instance.world.dimensionKey - ) - minecraftServer.playerList.a(PacketPlayOutEntityTeleport(instance), instance.world.dimensionKey) - // Move the fake player for the worlds chunk provider. - instance.worldServer.getChunkProvider().movePlayer(instance) - // bp == PLAYER_MODEL_PARTS - instance.datawatcher.set(bj, 0x7f.toByte()) // show all model layers (incl. capes) - return instance - } catch (e: Exception) { - e.printStackTrace() - } - return null - } - } - - - fun applyStartingPosition() { - if (hasStartingPos) { - this.setPositionRotation(startingX, startingY, startingZ, startingYaw, startingPitch) - mot = Vec3D(0.0, 0.0, 0.0) - } - } - - - override fun killEntity() { - server.a(TickTask(server.ai()) { playerConnection.a(ChatComponentText("Killed")) }) - } - - override fun tick() { - super.tick() - if (H()) { - I() - } - movementTick() - if (server.ai() % 10 == 0) { - playerConnection.syncPosition() - this.worldServer.getChunkProvider().movePlayer(this) - } - } - - override fun die(cause: DamageSource?) { - super.die(cause) - health = 20f - foodData = FoodMetaData(this) - killEntity() - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.fakeplayer +// +//import com.mojang.authlib.GameProfile +//import net.minecraft.server.v1_16_R3.* +//import nl.kallestruik.dtweaks.DTweaks +//import org.bukkit.Location +//import org.bukkit.craftbukkit.v1_16_R3.CraftWorld +// +//class FakePlayer( +// minecraftServer: MinecraftServer?, +// worldServer: WorldServer?, +// gameProfile: GameProfile?, +// playerInteractManager: PlayerInteractManager? +//): EntityPlayer(minecraftServer, worldServer, gameProfile, playerInteractManager) { +// val locale = "en_US" +// private var hasStartingPos = false +// private var startingX = 0.0 +// private var startingY = 0.0 +// private var startingZ = 0.0 +// private var startingYaw = 0f +// private var startingPitch = 0f +// +// private constructor( +// server: MinecraftServer, +// worldIn: WorldServer, +// profile: GameProfile?, +// interactionManagerIn: PlayerInteractManager, +// x: Double, +// y: Double, +// z: Double, +// yaw: Float, +// pitch: Float +// ) : this(server, worldIn, profile, interactionManagerIn) { +// this.hasStartingPos = true +// this.startingX = x +// this.startingY = y +// this.startingZ = z +// this.startingYaw = yaw +// this.startingPitch = pitch +// applyStartingPosition() +// } +// +// companion object { +// fun atLocation(location: Location, name: String?): FakePlayer? { +// // Split the location into its parts for use later. +// val x = location.x +// val y = location.y +// val z = location.z +// val yaw = location.yaw.toDouble() +// val pitch = location.pitch.toDouble() +// try { +// // Get the minecraft server instance. +// val minecraftServer = MinecraftServer.getServer() +// // Create an empty variable for the world server. +// val worldServer = (location.world as CraftWorld).handle +// // Get the game profile from the cache (or retrieve it if it is not cached) +// var gameProfile = minecraftServer.userCache.getProfile(name) ?: return null +// if (gameProfile.properties.containsKey("textures")) { +// gameProfile = TileEntitySkull.b(gameProfile, null, true).get() +// } +// +// // Create a player interact manager using the world server. +// val playerInteractManager = PlayerInteractManager(worldServer) +// +// // Create an instance of our fake player. +// val instance = FakePlayer( +// minecraftServer, worldServer, gameProfile, playerInteractManager, x, y, z, +// yaw.toFloat(), +// pitch.toFloat() +// ) +// // Create a fake connection for our fake player. +// val connection = FakeConnection(EnumProtocolDirection.SERVERBOUND) +// +// // Set access to connected channels so we can add our own connection. +// val serverConnection = minecraftServer.serverConnection +// +// (DTweaks.reflectionUtil.getValueFromField( +// serverConnection!!, +// "connectedChannels" +// ) as MutableList).add(connection) +// +// // Connect the fake player to the server using the fake connection. +// FakePlayerList.a(minecraftServer.playerList, connection, instance) +// +// // Check if the fake player is not yet in the correct world. +// if (instance.world.dimensionKey != worldServer.dimensionKey) { +// // Store the old world of the fake player. +// val old_world = instance.world as WorldServer +// // Remove the fake player from the old world. +// old_world.removePlayer(instance) +// // Make the fake player not be dead. +// instance.dead = false +// // Create the fake player in the new world. +// worldServer.addEntity(instance) +// // Spawn the fake player in the new world. +// instance.spawnIn(worldServer) +// // Move the fake player to the new world for the server. +// minecraftServer.playerList.moveToWorld(instance, old_world, true, null, false) +// // requestTeleport(x, y, z, yaw, pitch) +// // Request the teleport from the fake player. +// instance.playerConnection.a(x, y, z, yaw.toFloat(), pitch.toFloat()) +// // Set the fake player's world to the new world. +// instance.playerInteractManager.world = worldServer +// instance.teleportTo(worldServer, BlockPosition(x, y, z)) +// } +// +// /// Set the fake players health to max. +// instance.health = 20.0f +// // Make the fake player not be dead. +// instance.dead = false +// // a == requestTeleport +// // Request the teleport from the fake player. +// instance.playerConnection.a(x, y, z, yaw.toFloat(), pitch.toFloat()) +// // G == stepHeight +// // Set the fake players step height to 0.6 (The normal value). +// instance.G = 0.6f +// // Set the fake players gamemode to survival. +// playerInteractManager.gameMode = EnumGamemode.SURVIVAL +// // Tell everyone in the world about the fake player and where he is. +// minecraftServer.playerList.a( +// PacketPlayOutEntityHeadRotation(instance, (instance.yaw * 256 / 360).toByte()), +// instance.world.dimensionKey +// ) +// minecraftServer.playerList.a(PacketPlayOutEntityTeleport(instance), instance.world.dimensionKey) +// // Move the fake player for the worlds chunk provider. +// instance.worldServer.getChunkProvider().movePlayer(instance) +// // bp == PLAYER_MODEL_PARTS +// instance.datawatcher.set(bj, 0x7f.toByte()) // show all model layers (incl. capes) +// return instance +// } catch (e: Exception) { +// e.printStackTrace() +// } +// return null +// } +// } +// +// +// fun applyStartingPosition() { +// if (hasStartingPos) { +// this.setPositionRotation(startingX, startingY, startingZ, startingYaw, startingPitch) +// mot = Vec3D(0.0, 0.0, 0.0) +// } +// } +// +// +// override fun killEntity() { +// server.a(TickTask(server.ai()) { playerConnection.a(ChatComponentText("Killed")) }) +// } +// +// override fun tick() { +// super.tick() +// if (H()) { +// I() +// } +// movementTick() +// if (server.ai() % 10 == 0) { +// playerConnection.syncPosition() +// this.worldServer.getChunkProvider().movePlayer(this) +// } +// } +// +// override fun die(cause: DamageSource?) { +// super.die(cause) +// health = 20f +// foodData = FoodMetaData(this) +// killEntity() +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayerConnection.kt b/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayerConnection.kt index f8be696..0c9a81f 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayerConnection.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayerConnection.kt @@ -1,36 +1,36 @@ -package nl.kallestruik.dtweaks.fakeplayer - -import net.minecraft.server.v1_16_R3.* -import nl.kallestruik.dtweaks.DTweaks -import java.lang.reflect.Field - -class FakePlayerConnection( - minecraftServer: MinecraftServer, - networkManager: NetworkManager, - entityPlayer: EntityPlayer -): PlayerConnection(minecraftServer, networkManager, entityPlayer) { - override fun sendPacket(packet: Packet<*>?) { - if (packet is PacketPlayOutKeepAlive) { - val pong = PacketPlayInKeepAlive() - try { - val pingId: Field = DTweaks.reflectionUtil.getField(PacketPlayOutKeepAlive::class.java, "a") - val pongId: Field = DTweaks.reflectionUtil.getField(PacketPlayInKeepAlive::class.java, "a") - pingId.isAccessible = true - pongId.isAccessible = true - pongId[pong] = pingId[packet] - } catch (e: Exception) { - e.printStackTrace() - } - this.a(pong) - } - } - - override fun disconnect(message: String?) { - player.killEntity() - } - - override fun a(disconnectReason: IChatBaseComponent?) { - super.a(disconnectReason) - (this.a() as FakeConnection).open = false - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.fakeplayer +// +//import net.minecraft.server.v1_16_R3.* +//import nl.kallestruik.dtweaks.DTweaks +//import java.lang.reflect.Field +// +//class FakePlayerConnection( +// minecraftServer: MinecraftServer, +// networkManager: NetworkManager, +// entityPlayer: EntityPlayer +//): PlayerConnection(minecraftServer, networkManager, entityPlayer) { +// override fun sendPacket(packet: Packet<*>?) { +// if (packet is PacketPlayOutKeepAlive) { +// val pong = PacketPlayInKeepAlive() +// try { +// val pingId: Field = DTweaks.reflectionUtil.getField(PacketPlayOutKeepAlive::class.java, "a") +// val pongId: Field = DTweaks.reflectionUtil.getField(PacketPlayInKeepAlive::class.java, "a") +// pingId.isAccessible = true +// pongId.isAccessible = true +// pongId[pong] = pingId[packet] +// } catch (e: Exception) { +// e.printStackTrace() +// } +// this.a(pong) +// } +// } +// +// override fun disconnect(message: String?) { +// player.killEntity() +// } +// +// override fun a(disconnectReason: IChatBaseComponent?) { +// super.a(disconnectReason) +// (this.a() as FakeConnection).open = false +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayerList.kt b/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayerList.kt index afd01bd..edd622b 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayerList.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/fakeplayer/FakePlayerList.kt @@ -1,258 +1,258 @@ -package nl.kallestruik.dtweaks.fakeplayer - -import com.mojang.serialization.DataResult -import com.mojang.serialization.Dynamic -import io.netty.buffer.Unpooled -import net.minecraft.server.v1_16_R3.* -import nl.kallestruik.dtweaks.DTweaks -import org.apache.logging.log4j.Logger -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_16_R3.CraftWorld -import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage -import org.bukkit.entity.Player -import org.spigotmc.event.player.PlayerSpawnLocationEvent -import java.util.* - -object FakePlayerList { - fun a(playerList: PlayerList, networkManager: NetworkManager, entityPlayer: EntityPlayer) { - // Setup what are normally class level variables - val server = DTweaks.reflectionUtil.getValueFromField(playerList, "server") as MinecraftServer - val LOGGER = DTweaks.reflectionUtil.getValueFromField(playerList, "LOGGER") as Logger - - val gameProfile = entityPlayer.profile - val userCache = server.userCache - val oldGameProfile = userCache.getProfile(gameProfile.id) - var oldName = if (oldGameProfile == null) gameProfile.name else oldGameProfile.name - - userCache.a(gameProfile) - val playerData = playerList.a(entityPlayer) - if (playerData != null && playerData.hasKey("bukkit")) { - val bukkit = playerData.getCompound("bukkit") - oldName = if (bukkit.hasKeyOfType("lastKnownName", 8)) bukkit.getString("lastKnownName") else oldName - } - val worldKey: ResourceKey = if (playerData != null) { - val dataResult: DataResult> = DimensionManager.a( - Dynamic( - DynamicOpsNBT.a, - playerData["Dimension"] - ) - ) - dataResult.resultOrPartial { o -> LOGGER.error(o) } - .orElse(World.OVERWORLD) as ResourceKey - } else { - World.OVERWORLD - } - var worldServer = server.getWorldServer(worldKey) ?: server.E() - - entityPlayer.spawnIn(worldServer) - entityPlayer.playerInteractManager.a(entityPlayer.world as WorldServer) - var s1 = "local" - if (networkManager.getSocketAddress() != null) { - s1 = networkManager.getSocketAddress().toString() - } - val bukkitPlayer: Player = entityPlayer.bukkitEntity - val ev = PlayerSpawnLocationEvent(bukkitPlayer, bukkitPlayer.location) - Bukkit.getPluginManager().callEvent(ev) - val loc = ev.spawnLocation - worldServer = (loc.world as CraftWorld).handle - entityPlayer.spawnIn(worldServer) - entityPlayer.playerInteractManager.a(entityPlayer.world as WorldServer) - entityPlayer.setPosition(loc.x, loc.y, loc.z) - - //entityplayer.setYawPitch(loc.getYaw(), loc.getPitch()); - try { - val setYawPitch = Entity::class.java.getDeclaredMethod( - "setYawPitch", - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType - ) - setYawPitch.isAccessible = true - setYawPitch.invoke(entityPlayer, loc.yaw, loc.pitch) - } catch (e: Exception) { - e.printStackTrace() - } - val worldData = worldServer.getWorldData() - - //playerList.a(entityplayer, (EntityPlayer)null, worldserver1); - try { - val a = PlayerList::class.java.getDeclaredMethod( - "a", - EntityPlayer::class.java, - EntityPlayer::class.java, - WorldServer::class.java - ) - a.isAccessible = true - a.invoke(playerList, entityPlayer, null, worldServer) - } catch (e: Exception) { - e.printStackTrace() - } - - //PlayerConnection playerconnection = new PlayerConnection(server, networkmanager, entityplayer); - val playerConnection: PlayerConnection = - (entityPlayer as? FakePlayer)?.let { FakePlayerConnection(server, networkManager, it) } - ?: PlayerConnection(server, networkManager, entityPlayer) - val gameRules = worldServer.gameRules - val doImmediateRespawn = gameRules.getBoolean(GameRules.DO_IMMEDIATE_RESPAWN) - val reducedDebugInfo = gameRules.getBoolean(GameRules.REDUCED_DEBUG_INFO) - try { - playerConnection.sendPacket( - PacketPlayOutLogin( - entityPlayer.id, - entityPlayer.playerInteractManager.gameMode, - entityPlayer.playerInteractManager.c(), - BiomeManager.a( - worldServer.seed - ), - worldData.isHardcore, - server.F(), - DTweaks.reflectionUtil.getValueFromField(playerList, "s") as IRegistryCustom.Dimension, - worldServer.dimensionManager, - worldServer.dimensionKey, - playerList.maxPlayers, - worldServer.spigotConfig.viewDistance, - reducedDebugInfo, - !doImmediateRespawn, - worldServer.isDebugWorld, - worldServer.isFlatWorld - ) - ) - } catch (e: Exception) { - e.printStackTrace() - } - entityPlayer.bukkitEntity.sendSupportedChannels() - playerConnection.sendPacket( - PacketPlayOutCustomPayload( - PacketPlayOutCustomPayload.a, - PacketDataSerializer(Unpooled.buffer()).a(playerList.server.serverModName) - ) - ) - playerConnection.sendPacket(PacketPlayOutServerDifficulty(worldData.difficulty, worldData.isDifficultyLocked)) - playerConnection.sendPacket(PacketPlayOutAbilities(entityPlayer.abilities)) - playerConnection.sendPacket(PacketPlayOutHeldItemSlot(entityPlayer.inventory.itemInHandIndex)) - playerConnection.sendPacket(PacketPlayOutRecipeUpdate(server.craftingManager.b())) - playerConnection.sendPacket(PacketPlayOutTags(server.tagRegistry)) - playerList.d(entityPlayer) - entityPlayer.statisticManager.c() - entityPlayer.recipeBook.a(entityPlayer) - playerList.sendScoreboard(worldServer.scoreboard, entityPlayer) - server.invalidatePingSample() - val chatMessage = if (entityPlayer.profile.name.equals(oldName, ignoreCase = true)) { - ChatMessage("multiplayer.player.joined", entityPlayer.scoreboardDisplayName) - } else { - ChatMessage("multiplayer.player.joined.renamed", entityPlayer.scoreboardDisplayName, oldName) - } - chatMessage.a(EnumChatFormat.YELLOW) - var joinMessage = CraftChatMessage.fromComponent(chatMessage) - playerConnection.a( - entityPlayer.locX(), - entityPlayer.locY(), - entityPlayer.locZ(), - entityPlayer.yaw, - entityPlayer.pitch - ) - playerList.players.add(entityPlayer) - - //playerList.playersByName.put(entityplayer.getName().toLowerCase(Locale.ROOT), entityplayer); - val playersByName = DTweaks.reflectionUtil.getValueFromField(playerList, "playersByName") as HashMap - playersByName[entityPlayer.name.toLowerCase(Locale.ROOT)] = entityPlayer - - //playerList.j.put(entityplayer.getUniqueID(), entityplayer); - val playersByUUID = DTweaks.reflectionUtil.getValueFromField(playerList, "j") as HashMap - playersByUUID[entityPlayer.uniqueID] = entityPlayer - - if (entityPlayer.playerConnection.networkManager.isConnected) { - var i: Int - if (joinMessage != null && joinMessage.isNotEmpty()) { - var var27: Array - val var26 = CraftChatMessage.fromString(joinMessage).also { var27 = it }.size - i = 0 - while (i < var26) { - val line = var27[i] - server.playerList.sendAll(PacketPlayOutChat(line, ChatMessageType.SYSTEM, SystemUtils.b)) - ++i - } - } - val packet = PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer) - for (player in playerList.players) { - if (player.bukkitEntity.canSee(entityPlayer.bukkitEntity)) { - player.playerConnection.sendPacket(packet) - } - if (entityPlayer.bukkitEntity.canSee(player.bukkitEntity)) { - entityPlayer.playerConnection.sendPacket( - PacketPlayOutPlayerInfo( - PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, - player - ) - ) - } - } - entityPlayer.sentListPacket = true - entityPlayer.playerConnection.sendPacket( - PacketPlayOutEntityMetadata( - entityPlayer.id, - DTweaks.reflectionUtil.getValueFromField(entityPlayer, "datawatcher") as DataWatcher, true - ) - ) - - if (entityPlayer.world === worldServer && !worldServer.getPlayers().contains(entityPlayer)) { - worldServer.addPlayerJoin(entityPlayer) - server.bossBattleCustomData.a(entityPlayer) - } - - worldServer = entityPlayer.worldServer - playerList.a(entityPlayer, worldServer) - if (server.resourcePack.isNotEmpty()) { - entityPlayer.setResourcePack(server.resourcePack, server.resourcePackHash) - } - - for (mobEffect in entityPlayer.getEffects()) { - playerConnection.sendPacket(PacketPlayOutEntityEffect(entityPlayer.id, mobEffect)) - } - - if (playerData != null && playerData.hasKeyOfType("RootVehicle", 10)) { - val rootVehicleData = playerData.getCompound("RootVehicle") - val entity = EntityTypes.a( - rootVehicleData.getCompound("Entity"), worldServer - ) { entity1x: Entity? -> - if (!worldServer.addEntitySerialized(entity1x) - ) null else entity1x - } - if (entity != null) { - val uuid: UUID? = if (rootVehicleData.b("Attach")) { - rootVehicleData.a("Attach") - } else { - null - } - if (entity.uniqueID == uuid) { - entityPlayer.a(entity, true) - } else { - for (passenger in entity.allPassengers) { - if (passenger.uniqueID == uuid) { - entityPlayer.a(passenger, true) - break - } - } - } - if (!entityPlayer.isPassenger) { - LOGGER.warn("Couldn't reattach entity to player") - worldServer.removeEntity(entity) - for (passenger in entity.allPassengers) { - worldServer.removeEntity(passenger) - } - } - } - } - entityPlayer.syncInventory() - LOGGER.info( - "{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", - entityPlayer.getDisplayName().string, - s1, - entityPlayer.id, - worldServer?.worldDataServer?.name, - entityPlayer.locX(), - entityPlayer.locY(), - entityPlayer.locZ() - ) - } - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.fakeplayer +// +//import com.mojang.serialization.DataResult +//import com.mojang.serialization.Dynamic +//import io.netty.buffer.Unpooled +//import net.minecraft.server.v1_16_R3.* +//import nl.kallestruik.dtweaks.DTweaks +//import org.apache.logging.log4j.Logger +//import org.bukkit.Bukkit +//import org.bukkit.craftbukkit.v1_16_R3.CraftWorld +//import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage +//import org.bukkit.entity.Player +//import org.spigotmc.event.player.PlayerSpawnLocationEvent +//import java.util.* +// +//object FakePlayerList { +// fun a(playerList: PlayerList, networkManager: NetworkManager, entityPlayer: EntityPlayer) { +// // Setup what are normally class level variables +// val server = DTweaks.reflectionUtil.getValueFromField(playerList, "server") as MinecraftServer +// val LOGGER = DTweaks.reflectionUtil.getValueFromField(playerList, "LOGGER") as Logger +// +// val gameProfile = entityPlayer.profile +// val userCache = server.userCache +// val oldGameProfile = userCache.getProfile(gameProfile.id) +// var oldName = if (oldGameProfile == null) gameProfile.name else oldGameProfile.name +// +// userCache.a(gameProfile) +// val playerData = playerList.a(entityPlayer) +// if (playerData != null && playerData.hasKey("bukkit")) { +// val bukkit = playerData.getCompound("bukkit") +// oldName = if (bukkit.hasKeyOfType("lastKnownName", 8)) bukkit.getString("lastKnownName") else oldName +// } +// val worldKey: ResourceKey = if (playerData != null) { +// val dataResult: DataResult> = DimensionManager.a( +// Dynamic( +// DynamicOpsNBT.a, +// playerData["Dimension"] +// ) +// ) +// dataResult.resultOrPartial { o -> LOGGER.error(o) } +// .orElse(World.OVERWORLD) as ResourceKey +// } else { +// World.OVERWORLD +// } +// var worldServer = server.getWorldServer(worldKey) ?: server.E() +// +// entityPlayer.spawnIn(worldServer) +// entityPlayer.playerInteractManager.a(entityPlayer.world as WorldServer) +// var s1 = "local" +// if (networkManager.getSocketAddress() != null) { +// s1 = networkManager.getSocketAddress().toString() +// } +// val bukkitPlayer: Player = entityPlayer.bukkitEntity +// val ev = PlayerSpawnLocationEvent(bukkitPlayer, bukkitPlayer.location) +// Bukkit.getPluginManager().callEvent(ev) +// val loc = ev.spawnLocation +// worldServer = (loc.world as CraftWorld).handle +// entityPlayer.spawnIn(worldServer) +// entityPlayer.playerInteractManager.a(entityPlayer.world as WorldServer) +// entityPlayer.setPosition(loc.x, loc.y, loc.z) +// +// //entityplayer.setYawPitch(loc.getYaw(), loc.getPitch()); +// try { +// val setYawPitch = Entity::class.java.getDeclaredMethod( +// "setYawPitch", +// Float::class.javaPrimitiveType, +// Float::class.javaPrimitiveType +// ) +// setYawPitch.isAccessible = true +// setYawPitch.invoke(entityPlayer, loc.yaw, loc.pitch) +// } catch (e: Exception) { +// e.printStackTrace() +// } +// val worldData = worldServer.getWorldData() +// +// //playerList.a(entityplayer, (EntityPlayer)null, worldserver1); +// try { +// val a = PlayerList::class.java.getDeclaredMethod( +// "a", +// EntityPlayer::class.java, +// EntityPlayer::class.java, +// WorldServer::class.java +// ) +// a.isAccessible = true +// a.invoke(playerList, entityPlayer, null, worldServer) +// } catch (e: Exception) { +// e.printStackTrace() +// } +// +// //PlayerConnection playerconnection = new PlayerConnection(server, networkmanager, entityplayer); +// val playerConnection: PlayerConnection = +// (entityPlayer as? FakePlayer)?.let { FakePlayerConnection(server, networkManager, it) } +// ?: PlayerConnection(server, networkManager, entityPlayer) +// val gameRules = worldServer.gameRules +// val doImmediateRespawn = gameRules.getBoolean(GameRules.DO_IMMEDIATE_RESPAWN) +// val reducedDebugInfo = gameRules.getBoolean(GameRules.REDUCED_DEBUG_INFO) +// try { +// playerConnection.sendPacket( +// PacketPlayOutLogin( +// entityPlayer.id, +// entityPlayer.playerInteractManager.gameMode, +// entityPlayer.playerInteractManager.c(), +// BiomeManager.a( +// worldServer.seed +// ), +// worldData.isHardcore, +// server.F(), +// DTweaks.reflectionUtil.getValueFromField(playerList, "s") as IRegistryCustom.Dimension, +// worldServer.dimensionManager, +// worldServer.dimensionKey, +// playerList.maxPlayers, +// worldServer.spigotConfig.viewDistance, +// reducedDebugInfo, +// !doImmediateRespawn, +// worldServer.isDebugWorld, +// worldServer.isFlatWorld +// ) +// ) +// } catch (e: Exception) { +// e.printStackTrace() +// } +// entityPlayer.bukkitEntity.sendSupportedChannels() +// playerConnection.sendPacket( +// PacketPlayOutCustomPayload( +// PacketPlayOutCustomPayload.a, +// PacketDataSerializer(Unpooled.buffer()).a(playerList.server.serverModName) +// ) +// ) +// playerConnection.sendPacket(PacketPlayOutServerDifficulty(worldData.difficulty, worldData.isDifficultyLocked)) +// playerConnection.sendPacket(PacketPlayOutAbilities(entityPlayer.abilities)) +// playerConnection.sendPacket(PacketPlayOutHeldItemSlot(entityPlayer.inventory.itemInHandIndex)) +// playerConnection.sendPacket(PacketPlayOutRecipeUpdate(server.craftingManager.b())) +// playerConnection.sendPacket(PacketPlayOutTags(server.tagRegistry)) +// playerList.d(entityPlayer) +// entityPlayer.statisticManager.c() +// entityPlayer.recipeBook.a(entityPlayer) +// playerList.sendScoreboard(worldServer.scoreboard, entityPlayer) +// server.invalidatePingSample() +// val chatMessage = if (entityPlayer.profile.name.equals(oldName, ignoreCase = true)) { +// ChatMessage("multiplayer.player.joined", entityPlayer.scoreboardDisplayName) +// } else { +// ChatMessage("multiplayer.player.joined.renamed", entityPlayer.scoreboardDisplayName, oldName) +// } +// chatMessage.a(EnumChatFormat.YELLOW) +// var joinMessage = CraftChatMessage.fromComponent(chatMessage) +// playerConnection.a( +// entityPlayer.locX(), +// entityPlayer.locY(), +// entityPlayer.locZ(), +// entityPlayer.yaw, +// entityPlayer.pitch +// ) +// playerList.players.add(entityPlayer) +// +// //playerList.playersByName.put(entityplayer.getName().toLowerCase(Locale.ROOT), entityplayer); +// val playersByName = DTweaks.reflectionUtil.getValueFromField(playerList, "playersByName") as HashMap +// playersByName[entityPlayer.name.toLowerCase(Locale.ROOT)] = entityPlayer +// +// //playerList.j.put(entityplayer.getUniqueID(), entityplayer); +// val playersByUUID = DTweaks.reflectionUtil.getValueFromField(playerList, "j") as HashMap +// playersByUUID[entityPlayer.uniqueID] = entityPlayer +// +// if (entityPlayer.playerConnection.networkManager.isConnected) { +// var i: Int +// if (joinMessage != null && joinMessage.isNotEmpty()) { +// var var27: Array +// val var26 = CraftChatMessage.fromString(joinMessage).also { var27 = it }.size +// i = 0 +// while (i < var26) { +// val line = var27[i] +// server.playerList.sendAll(PacketPlayOutChat(line, ChatMessageType.SYSTEM, SystemUtils.b)) +// ++i +// } +// } +// val packet = PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer) +// for (player in playerList.players) { +// if (player.bukkitEntity.canSee(entityPlayer.bukkitEntity)) { +// player.playerConnection.sendPacket(packet) +// } +// if (entityPlayer.bukkitEntity.canSee(player.bukkitEntity)) { +// entityPlayer.playerConnection.sendPacket( +// PacketPlayOutPlayerInfo( +// PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, +// player +// ) +// ) +// } +// } +// entityPlayer.sentListPacket = true +// entityPlayer.playerConnection.sendPacket( +// PacketPlayOutEntityMetadata( +// entityPlayer.id, +// DTweaks.reflectionUtil.getValueFromField(entityPlayer, "datawatcher") as DataWatcher, true +// ) +// ) +// +// if (entityPlayer.world === worldServer && !worldServer.getPlayers().contains(entityPlayer)) { +// worldServer.addPlayerJoin(entityPlayer) +// server.bossBattleCustomData.a(entityPlayer) +// } +// +// worldServer = entityPlayer.worldServer +// playerList.a(entityPlayer, worldServer) +// if (server.resourcePack.isNotEmpty()) { +// entityPlayer.setResourcePack(server.resourcePack, server.resourcePackHash) +// } +// +// for (mobEffect in entityPlayer.getEffects()) { +// playerConnection.sendPacket(PacketPlayOutEntityEffect(entityPlayer.id, mobEffect)) +// } +// +// if (playerData != null && playerData.hasKeyOfType("RootVehicle", 10)) { +// val rootVehicleData = playerData.getCompound("RootVehicle") +// val entity = EntityTypes.a( +// rootVehicleData.getCompound("Entity"), worldServer +// ) { entity1x: Entity? -> +// if (!worldServer.addEntitySerialized(entity1x) +// ) null else entity1x +// } +// if (entity != null) { +// val uuid: UUID? = if (rootVehicleData.b("Attach")) { +// rootVehicleData.a("Attach") +// } else { +// null +// } +// if (entity.uniqueID == uuid) { +// entityPlayer.a(entity, true) +// } else { +// for (passenger in entity.allPassengers) { +// if (passenger.uniqueID == uuid) { +// entityPlayer.a(passenger, true) +// break +// } +// } +// } +// if (!entityPlayer.isPassenger) { +// LOGGER.warn("Couldn't reattach entity to player") +// worldServer.removeEntity(entity) +// for (passenger in entity.allPassengers) { +// worldServer.removeEntity(passenger) +// } +// } +// } +// } +// entityPlayer.syncInventory() +// LOGGER.info( +// "{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", +// entityPlayer.getDisplayName().string, +// s1, +// entityPlayer.id, +// worldServer?.worldDataServer?.name, +// entityPlayer.locX(), +// entityPlayer.locY(), +// entityPlayer.locZ() +// ) +// } +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/managers/FakePlayerManager.kt b/src/main/kotlin/nl/kallestruik/dtweaks/managers/FakePlayerManager.kt index e613918..0c926e3 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/managers/FakePlayerManager.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/managers/FakePlayerManager.kt @@ -1,30 +1,30 @@ -package nl.kallestruik.dtweaks.managers - -import nl.kallestruik.dtweaks.fakeplayer.FakePlayer -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer - -class FakePlayerManager { - - fun spawnFakePlayer(loc: Location, name: String) { - val player = Bukkit.getPlayer(name) - if (player != null && player.isOnline) return - FakePlayer.atLocation(loc, name) - } - - fun killFakePlayer(name: String) { - val player = Bukkit.getPlayer(name) - if (player == null || !player.isOnline) return - val entityPlayer = (player as CraftPlayer).handle as? FakePlayer ?: return - entityPlayer.killEntity() - } - - fun killAllFakePlayers() { - for (player in Bukkit.getOnlinePlayers()) { - if (!player.isOnline) continue - val entityPlayer = (player as CraftPlayer).handle as? FakePlayer ?: continue - entityPlayer.killEntity() - } - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.managers +// +//import nl.kallestruik.dtweaks.fakeplayer.FakePlayer +//import org.bukkit.Bukkit +//import org.bukkit.Location +//import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer +// +//class FakePlayerManager { +// +// fun spawnFakePlayer(loc: Location, name: String) { +// val player = Bukkit.getPlayer(name) +// if (player != null && player.isOnline) return +// FakePlayer.atLocation(loc, name) +// } +// +// fun killFakePlayer(name: String) { +// val player = Bukkit.getPlayer(name) +// if (player == null || !player.isOnline) return +// val entityPlayer = (player as CraftPlayer).handle as? FakePlayer ?: return +// entityPlayer.killEntity() +// } +// +// fun killAllFakePlayers() { +// for (player in Bukkit.getOnlinePlayers()) { +// if (!player.isOnline) continue +// val entityPlayer = (player as CraftPlayer).handle as? FakePlayer ?: continue +// entityPlayer.killEntity() +// } +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/managers/PocketDimensionManager.kt b/src/main/kotlin/nl/kallestruik/dtweaks/managers/PocketDimensionManager.kt index 45138d8..cc6a929 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/managers/PocketDimensionManager.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/managers/PocketDimensionManager.kt @@ -1,110 +1,108 @@ -package nl.kallestruik.dtweaks.managers - -import net.minecraft.server.v1_16_R3.MathHelper -import nl.kallestruik.dlib.MathHelper -import nl.kallestruik.dtweaks.spacetimepockets.SpaceTimePocketChunkGenerator -import org.bukkit.* -import org.bukkit.entity.Player -import java.util.* - -class PocketDimensionManager( - private val mathHelper: MathHelper -) { - val pocketDimension: World = WorldCreator.name("space-time-pockets").generator(SpaceTimePocketChunkGenerator()).createWorld()!! - private val data = HashMap() - private var lastCreatedPocket = -1 - - fun loadData() { - //TODO: Load data from data file on disk. - } - - fun saveData() { - //TODO: Save data to file on disk. - } - - fun teleportPlayerIntoPocket(player: Player, pocketOwner: UUID) { - var pocketData = data[pocketOwner] - if (pocketData == null) pocketData = if (player.uniqueId == pocketOwner) { - createPocketForPlayer(player) - } else return - player.teleport( - Location( - pocketDimension, (pocketData.startX + 9).toDouble(), 128.0, - (pocketData.startZ + 9).toDouble() - ) - ) - Bukkit.unloadWorld() - } - - fun createPocketForPlayer(player: Player): PocketData { - // Find a spot - val point = findNextFree() - - // Load the chunks - for (x in 0..2) { - for (y in 0..2) { - pocketDimension.loadChunk(point.x / 16 + x, point.z / 16 + y) - } - } - - // Build the box - for (x in 0..17) { - for (z in 0..17) { - for (y in 0..255) { - if (x == 0 || y == 0 || z == 0 || x == 17 || y == 255 || z == 17) { - pocketDimension.getBlockAt(point.x + x, y, point.z + z).type = Material.BLACK_CONCRETE - } - } - } - } - - // Create the spawning platform - pocketDimension.getBlockAt(point.x + 8, 127, point.z + 8).type = Material.STONE - pocketDimension.getBlockAt(point.x + 8, 127, point.z + 9).type = Material.STONE - pocketDimension.getBlockAt(point.x + 9, 127, point.z + 8).type = Material.STONE - pocketDimension.getBlockAt(point.x + 9, 127, point.z + 9).type = Material.STONE - - // Unload the chunks - for (x in 0..2) { - for (y in 0..2) { - pocketDimension.unloadChunk(point.x / 16 + x, point.z / 16 + y) - } - } - val pocketData = PocketData(player.uniqueId, point.x, point.z, ArrayList()) - data[player.uniqueId] = pocketData - return pocketData - } - - private fun findNextFree(): Point { - while (true) { - lastCreatedPocket++ - val toCheck = getXYForIndex(lastCreatedPocket) - val chunk = pocketDimension.getChunkAt( - Location( - pocketDimension, - toCheck.x.toDouble(), 0.0, toCheck.z.toDouble() - ) - ) - val corner = chunk.getBlock(mathHelper.chunkAbs(toCheck.x % 16), 0, mathHelper.chunkAbs(toCheck.z % 16)) - if (corner.type == Material.AIR) { - return toCheck - } - } - } - - private fun getXYForIndex(index: Int): Point { - // Space the pockets 256 blocks (16 chunks) from each other with each pocket being 16 blocks (and two for walls) - // Also subtract 1 from each point so the interior is chunk aligned. - val x = (256 + 16) * (index % 1000) - 1 - val z = (256 + 16) * (index / 1000) - 1 - return Point(x, z) - } - - class PocketData(var owner: UUID, var startX: Int, var startZ: Int, var queuedGateways: ArrayList) - - class GatewayData - - class Point(var x: Int, var y: Int, var z: Int) { - constructor(x: Int, z: Int) : this(x, 0, z) {} - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.managers +// +//import nl.kallestruik.dlib.MathHelper +//import nl.kallestruik.dtweaks.spacetimepockets.SpaceTimePocketChunkGenerator +//import org.bukkit.* +//import org.bukkit.entity.Player +//import java.util.* +// +//class PocketDimensionManager( +// private val mathHelper: MathHelper +//) { +// val pocketDimension: World = WorldCreator.name("space-time-pockets").generator(SpaceTimePocketChunkGenerator()).createWorld()!! +// private val data = HashMap() +// private var lastCreatedPocket = -1 +// +// fun loadData() { +// //TODO: Load data from data file on disk. +// } +// +// fun saveData() { +// //TODO: Save data to file on disk. +// } +// +// fun teleportPlayerIntoPocket(player: Player, pocketOwner: UUID) { +// var pocketData = data[pocketOwner] +// if (pocketData == null) pocketData = if (player.uniqueId == pocketOwner) { +// createPocketForPlayer(player) +// } else return +// player.teleport( +// Location( +// pocketDimension, (pocketData.startX + 9).toDouble(), 128.0, +// (pocketData.startZ + 9).toDouble() +// ) +// ) +// } +// +// fun createPocketForPlayer(player: Player): PocketData { +// // Find a spot +// val point = findNextFree() +// +// // Load the chunks +// for (x in 0..2) { +// for (y in 0..2) { +// pocketDimension.loadChunk(point.x / 16 + x, point.z / 16 + y) +// } +// } +// +// // Build the box +// for (x in 0..17) { +// for (z in 0..17) { +// for (y in 0..255) { +// if (x == 0 || y == 0 || z == 0 || x == 17 || y == 255 || z == 17) { +// pocketDimension.getBlockAt(point.x + x, y, point.z + z).type = Material.BLACK_CONCRETE +// } +// } +// } +// } +// +// // Create the spawning platform +// pocketDimension.getBlockAt(point.x + 8, 127, point.z + 8).type = Material.STONE +// pocketDimension.getBlockAt(point.x + 8, 127, point.z + 9).type = Material.STONE +// pocketDimension.getBlockAt(point.x + 9, 127, point.z + 8).type = Material.STONE +// pocketDimension.getBlockAt(point.x + 9, 127, point.z + 9).type = Material.STONE +// +// // Unload the chunks +// for (x in 0..2) { +// for (y in 0..2) { +// pocketDimension.unloadChunk(point.x / 16 + x, point.z / 16 + y) +// } +// } +// val pocketData = PocketData(player.uniqueId, point.x, point.z, ArrayList()) +// data[player.uniqueId] = pocketData +// return pocketData +// } +// +// private fun findNextFree(): Point { +// while (true) { +// lastCreatedPocket++ +// val toCheck = getXYForIndex(lastCreatedPocket) +// val chunk = pocketDimension.getChunkAt( +// Location( +// pocketDimension, +// toCheck.x.toDouble(), 0.0, toCheck.z.toDouble() +// ) +// ) +// val corner = chunk.getBlock(mathHelper.chunkAbs(toCheck.x % 16), 0, mathHelper.chunkAbs(toCheck.z % 16)) +// if (corner.type == Material.AIR) { +// return toCheck +// } +// } +// } +// +// private fun getXYForIndex(index: Int): Point { +// // Space the pockets 256 blocks (16 chunks) from each other with each pocket being 16 blocks (and two for walls) +// // Also subtract 1 from each point so the interior is chunk aligned. +// val x = (256 + 16) * (index % 1000) - 1 +// val z = (256 + 16) * (index / 1000) - 1 +// return Point(x, z) +// } +// +// class PocketData(var owner: UUID, var startX: Int, var startZ: Int, var queuedGateways: ArrayList) +// +// class GatewayData +// +// class Point(var x: Int, var y: Int, var z: Int) { +// constructor(x: Int, z: Int) : this(x, 0, z) {} +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/spacetimepockets/SpaceTimePocketChunkGenerator.kt b/src/main/kotlin/nl/kallestruik/dtweaks/spacetimepockets/SpaceTimePocketChunkGenerator.kt index b8683ac..361a90d 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/spacetimepockets/SpaceTimePocketChunkGenerator.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/spacetimepockets/SpaceTimePocketChunkGenerator.kt @@ -1,27 +1,27 @@ -package nl.kallestruik.dtweaks.spacetimepockets - -import org.bukkit.World -import org.bukkit.block.Biome -import org.bukkit.craftbukkit.v1_16_R3.generator.CraftChunkData -import org.bukkit.generator.ChunkGenerator -import java.util.* - -class SpaceTimePocketChunkGenerator: ChunkGenerator() { - - override fun generateChunkData( - world: World, - random: Random, - x: Int, - z: Int, - biome: BiomeGrid - ): ChunkData { - for (cx in 0..15) { - for (cz in 0..15) { - for (cy in 0..264) { - biome.setBiome(cx, cy, cz, Biome.THE_VOID) - } - } - } - return CraftChunkData(world) - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.spacetimepockets +// +//import org.bukkit.World +//import org.bukkit.block.Biome +//import org.bukkit.craftbukkit.v1_18_R1.generator.CraftChunkData +//import org.bukkit.generator.ChunkGenerator +//import java.util.* +// +//class SpaceTimePocketChunkGenerator: ChunkGenerator() { +// +// override fun generateChunkData( +// world: World, +// random: Random, +// x: Int, +// z: Int, +// biome: BiomeGrid +// ): ChunkData { +// for (cx in 0..15) { +// for (cz in 0..15) { +// for (cy in 0..264) { +// biome.setBiome(cx, cy, cz, Biome.THE_VOID) +// } +// } +// } +// return CraftChunkData(world) +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/craftingtweaks/RedyeTerracotta.kt b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/craftingtweaks/RedyeTerracotta.kt index d495e86..3509455 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/craftingtweaks/RedyeTerracotta.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/craftingtweaks/RedyeTerracotta.kt @@ -15,8 +15,18 @@ class RedyeTerracotta( private val blueRecipeKey = NamespacedKey(plugin, "blue_terracotta") private val brownRecipeKey = NamespacedKey(plugin, "brown_terracotta") private val cyanRecipeKey = NamespacedKey(plugin, "cyan_terracotta") - private val blueRecipeKey = NamespacedKey(plugin, "blue_terracotta") - private val blueRecipeKey = NamespacedKey(plugin, "blue_terracotta") + private val grayRecipeKey = NamespacedKey(plugin, "gray_terracotta") + private val greenRecipeKey = NamespacedKey(plugin, "green_terracotta") + private val lightBlueRecipeKey = NamespacedKey(plugin, "light_blue_terracotta") + private val lightGrayRecipeKey = NamespacedKey(plugin, "light_gray_terracotta") + private val limeRecipeKey = NamespacedKey(plugin, "lime_terracotta") + private val magentaRecipeKey = NamespacedKey(plugin, "magenta_terracotta") + private val orangeRecipeKey = NamespacedKey(plugin, "orange_terracotta") + private val pinkRecipeKey = NamespacedKey(plugin, "pink_terracotta") + private val purpleRecipeKey = NamespacedKey(plugin, "purple_terracotta") + private val redRecipeKey = NamespacedKey(plugin, "red_terracotta") + private val whiteRecipeKey = NamespacedKey(plugin, "white_terracotta") + private val yellowRecipeKey = NamespacedKey(plugin, "yellow_terracotta") private val allTerracotta = RecipeChoice.MaterialChoice(Material.TERRACOTTA, Material.BLACK_TERRACOTTA, Material.BLUE_TERRACOTTA, Material.BROWN_TERRACOTTA, Material.CYAN_TERRACOTTA, Material.GRAY_TERRACOTTA, @@ -30,10 +40,40 @@ class RedyeTerracotta( override fun onEnable() { addRecipe(blackRecipeKey, Material.BLACK_TERRACOTTA, Material.BLACK_DYE) + addRecipe(blueRecipeKey, Material.BLUE_TERRACOTTA, Material.BLUE_DYE) + addRecipe(brownRecipeKey, Material.BROWN_TERRACOTTA, Material.BROWN_DYE) + addRecipe(cyanRecipeKey, Material.CYAN_TERRACOTTA, Material.CYAN_DYE) + addRecipe(grayRecipeKey, Material.GRAY_TERRACOTTA, Material.GRAY_DYE) + addRecipe(greenRecipeKey, Material.GREEN_TERRACOTTA, Material.GREEN_DYE) + addRecipe(lightBlueRecipeKey, Material.LIGHT_BLUE_TERRACOTTA, Material.LIGHT_BLUE_DYE) + addRecipe(lightGrayRecipeKey, Material.LIGHT_GRAY_TERRACOTTA, Material.LIGHT_GRAY_DYE) + addRecipe(limeRecipeKey, Material.LIME_TERRACOTTA, Material.LIME_DYE) + addRecipe(magentaRecipeKey, Material.MAGENTA_TERRACOTTA, Material.MAGENTA_DYE) + addRecipe(orangeRecipeKey, Material.ORANGE_TERRACOTTA, Material.ORANGE_DYE) + addRecipe(pinkRecipeKey, Material.PINK_TERRACOTTA, Material.PINK_DYE) + addRecipe(purpleRecipeKey, Material.PURPLE_TERRACOTTA, Material.PURPLE_DYE) + addRecipe(redRecipeKey, Material.RED_TERRACOTTA, Material.RED_DYE) + addRecipe(whiteRecipeKey, Material.WHITE_TERRACOTTA, Material.WHITE_DYE) + addRecipe(yellowRecipeKey, Material.YELLOW_TERRACOTTA, Material.YELLOW_DYE) } override fun onDisable() { plugin.server.removeRecipe(blackRecipeKey) + plugin.server.removeRecipe(blueRecipeKey) + plugin.server.removeRecipe(brownRecipeKey) + plugin.server.removeRecipe(cyanRecipeKey) + plugin.server.removeRecipe(grayRecipeKey) + plugin.server.removeRecipe(greenRecipeKey) + plugin.server.removeRecipe(lightBlueRecipeKey) + plugin.server.removeRecipe(lightGrayRecipeKey) + plugin.server.removeRecipe(limeRecipeKey) + plugin.server.removeRecipe(magentaRecipeKey) + plugin.server.removeRecipe(orangeRecipeKey) + plugin.server.removeRecipe(pinkRecipeKey) + plugin.server.removeRecipe(purpleRecipeKey) + plugin.server.removeRecipe(redRecipeKey) + plugin.server.removeRecipe(whiteRecipeKey) + plugin.server.removeRecipe(yellowRecipeKey) } private fun addRecipe(key: NamespacedKey, output: Material, dye: Material) { diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/dispsensertweaks/DispensersCanPlantSaplings.kt b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/dispsensertweaks/DispensersCanPlantSaplings.kt index 192a793..d1fa178 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/dispsensertweaks/DispensersCanPlantSaplings.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/dispsensertweaks/DispensersCanPlantSaplings.kt @@ -60,8 +60,11 @@ class DispensersCanPlantSaplings( event.isCancelled = true val dispenserInventory = (event.block.state as org.bukkit.block.Dispenser).inventory var slot = 0 - for (`is` in dispenserInventory.contents) { - if (`is` != null && `is`.type == event.item.type) break + if (dispenserInventory.contents == null) + return + + for (item in dispenserInventory.contents!!) { + if (item != null && item.type == event.item.type) break slot++ } val newItemStack = dispenserInventory.getItem(slot) diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/ArmorStandArmorSwapping.kt b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/ArmorStandArmorSwapping.kt index b23473c..cc6e7af 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/ArmorStandArmorSwapping.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/ArmorStandArmorSwapping.kt @@ -31,20 +31,22 @@ class ArmorStandArmorSwapping( val standEquipment = armorStand.equipment val player = event.player val playerEquipment = player.equipment - if (standEquipment == null || playerEquipment == null) return val playerHelmet = playerEquipment.helmet val playerChestplate = playerEquipment.chestplate val playerLeggings = playerEquipment.leggings val playerBoots = playerEquipment.boots + player.inventory.helmet = standEquipment.helmet player.inventory.chestplate = standEquipment.chestplate player.inventory.leggings = standEquipment.leggings player.inventory.boots = standEquipment.boots + armorStand.setItem(EquipmentSlot.HEAD, playerHelmet) armorStand.setItem(EquipmentSlot.CHEST, playerChestplate) armorStand.setItem(EquipmentSlot.LEGS, playerLeggings) armorStand.setItem(EquipmentSlot.FEET, playerBoots) + event.isCancelled = true } } diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/FakePlayers.kt b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/FakePlayers.kt index 6db4c15..4c168bc 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/FakePlayers.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/FakePlayers.kt @@ -1,15 +1,15 @@ -package nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks - -import nl.kallestruik.dtweaks.managers.FakePlayerManager -import nl.kallestruik.dtweaks.tweaks.ITweak - -class FakePlayers( - private val fakePlayerManager: FakePlayerManager -): ITweak { - override fun getIdentifier(): String = "FakePlayers" - override fun getCategories(): List = listOf("players") - - override fun onDisable() { - fakePlayerManager.killAllFakePlayers() - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks +// +//import nl.kallestruik.dtweaks.managers.FakePlayerManager +//import nl.kallestruik.dtweaks.tweaks.ITweak +// +//class FakePlayers( +// private val fakePlayerManager: FakePlayerManager +//): ITweak { +// override fun getIdentifier(): String = "FakePlayers" +// override fun getCategories(): List = listOf("players") +// +// override fun onDisable() { +// fakePlayerManager.killAllFakePlayers() +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/SpaceTimePockets.kt b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/SpaceTimePockets.kt index ab10f39..a194c73 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/SpaceTimePockets.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/miscellaneoustweaks/SpaceTimePockets.kt @@ -1,70 +1,70 @@ -package nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks - -import nl.kallestruik.dtweaks.managers.PocketDimensionManager -import nl.kallestruik.dtweaks.tweaks.ITweak -import org.bukkit.entity.Player -import org.bukkit.event.EventHandler -import org.bukkit.event.HandlerList -import org.bukkit.event.Listener -import org.bukkit.event.block.BlockBreakEvent -import org.bukkit.event.entity.CreatureSpawnEvent -import org.bukkit.event.entity.EntityDamageEvent -import org.bukkit.event.player.PlayerMoveEvent -import org.bukkit.plugin.java.JavaPlugin - -class SpaceTimePockets( - private val plugin: JavaPlugin, - private val pocketDimensionManager: PocketDimensionManager -): ITweak, Listener { - override fun getIdentifier(): String = "SpaceTimePockets" - override fun getCategories(): List = listOf("miscellaneous", "survival") - - override fun onRegister() { - plugin.server.pluginManager.registerEvents(this, plugin) - } - - override fun onUnRegister() { - HandlerList.unregisterAll(this) - } - - - @EventHandler - fun onBlockBreak(event: BlockBreakEvent) { - if (event.player.world != pocketDimensionManager.pocketDimension) { - return - } - if (event.block.location.chunk == event.player.location.chunk && event.block.y != 0 && event.block.y != 255) return - event.isCancelled = true - event.player.sendMessage("It seems like a bad idea to break the only thing keeping you from getting lost into the endlessness around you.") - } - - @EventHandler - fun onMobSpawn(event: CreatureSpawnEvent) { - if (pocketDimensionManager.pocketDimension != event.location.world) return - event.isCancelled = true - } - - @EventHandler - fun onPlayerDamage(event: EntityDamageEvent) { - if (event.entity !is Player) return - if (pocketDimensionManager.pocketDimension != event.entity.world) return - event.isCancelled = true - } - - @EventHandler - fun onPlayerFall(event: PlayerMoveEvent) { - if (pocketDimensionManager.pocketDimension != event.from.world - || pocketDimensionManager.pocketDimension != event.to.world - ) return - if (event.from.chunk != event.to.chunk) { - event.player.sendMessage("Something pulls you back from the darkness.") - event.isCancelled = true - } - if (event.to.blockY < 0 || event.to.blockY > 256) { - event.player.sendMessage("Something pulls you back from the darkness.") - val safeLocation = event.player.location - safeLocation.y = 128.0 - event.player.teleport(safeLocation) - } - } -} \ No newline at end of file +//package nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks +// +//import nl.kallestruik.dtweaks.managers.PocketDimensionManager +//import nl.kallestruik.dtweaks.tweaks.ITweak +//import org.bukkit.entity.Player +//import org.bukkit.event.EventHandler +//import org.bukkit.event.HandlerList +//import org.bukkit.event.Listener +//import org.bukkit.event.block.BlockBreakEvent +//import org.bukkit.event.entity.CreatureSpawnEvent +//import org.bukkit.event.entity.EntityDamageEvent +//import org.bukkit.event.player.PlayerMoveEvent +//import org.bukkit.plugin.java.JavaPlugin +// +//class SpaceTimePockets( +// private val plugin: JavaPlugin, +// private val pocketDimensionManager: PocketDimensionManager +//): ITweak, Listener { +// override fun getIdentifier(): String = "SpaceTimePockets" +// override fun getCategories(): List = listOf("miscellaneous", "survival") +// +// override fun onRegister() { +// plugin.server.pluginManager.registerEvents(this, plugin) +// } +// +// override fun onUnRegister() { +// HandlerList.unregisterAll(this) +// } +// +// +// @EventHandler +// fun onBlockBreak(event: BlockBreakEvent) { +// if (event.player.world != pocketDimensionManager.pocketDimension) { +// return +// } +// if (event.block.location.chunk == event.player.location.chunk && event.block.y != 0 && event.block.y != 255) return +// event.isCancelled = true +// event.player.sendMessage("It seems like a bad idea to break the only thing keeping you from getting lost into the endlessness around you.") +// } +// +// @EventHandler +// fun onMobSpawn(event: CreatureSpawnEvent) { +// if (pocketDimensionManager.pocketDimension != event.location.world) return +// event.isCancelled = true +// } +// +// @EventHandler +// fun onPlayerDamage(event: EntityDamageEvent) { +// if (event.entity !is Player) return +// if (pocketDimensionManager.pocketDimension != event.entity.world) return +// event.isCancelled = true +// } +// +// @EventHandler +// fun onPlayerFall(event: PlayerMoveEvent) { +// if (pocketDimensionManager.pocketDimension != event.from.world +// || pocketDimensionManager.pocketDimension != event.to.world +// ) return +// if (event.from.chunk != event.to.chunk) { +// event.player.sendMessage("Something pulls you back from the darkness.") +// event.isCancelled = true +// } +// if (event.to.blockY < 0 || event.to.blockY > 256) { +// event.player.sendMessage("Something pulls you back from the darkness.") +// val safeLocation = event.player.location +// safeLocation.y = 128.0 +// event.player.teleport(safeLocation) +// } +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/mobtweaks/VillagerInfo.kt b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/mobtweaks/VillagerInfo.kt index b881316..ea9ac9c 100644 --- a/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/mobtweaks/VillagerInfo.kt +++ b/src/main/kotlin/nl/kallestruik/dtweaks/tweaks/mobtweaks/VillagerInfo.kt @@ -1,11 +1,10 @@ package nl.kallestruik.dtweaks.tweaks.mobtweaks -import net.minecraft.server.v1_16_R3.Activity -import net.minecraft.server.v1_16_R3.EntityVillager -import net.minecraft.server.v1_16_R3.GlobalPos -import net.minecraft.server.v1_16_R3.MemoryModuleType +import net.minecraft.core.GlobalPos +import net.minecraft.world.entity.ai.memory.MemoryModuleType +import net.minecraft.world.entity.schedule.Activity import nl.kallestruik.dtweaks.tweaks.ITweak -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftVillager +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftVillager import org.bukkit.entity.Villager import org.bukkit.event.EventHandler import org.bukkit.event.HandlerList @@ -32,42 +31,42 @@ class VillagerInfo( fun onInteractEvent(event: PlayerInteractEntityEvent) { if (!event.player.isSneaking) return val clicked = event.rightClicked as? Villager ?: return - val eVillager: EntityVillager = (clicked as CraftVillager).handle + val eVillager: net.minecraft.world.entity.npc.Villager = (clicked as CraftVillager).handle val homePos: AtomicReference = AtomicReference(null) - eVillager.behaviorController.getMemory(MemoryModuleType.HOME) + eVillager.brain.getMemory(MemoryModuleType.HOME) .ifPresent { newValue -> homePos.set(newValue) } val workPos: AtomicReference = AtomicReference(null) - eVillager.behaviorController.getMemory(MemoryModuleType.JOB_SITE).ifPresent { newValue -> + eVillager.brain.getMemory(MemoryModuleType.JOB_SITE).ifPresent { newValue -> workPos.set( newValue ) } val meetingPos: AtomicReference = AtomicReference(null) - eVillager.behaviorController.getMemory(MemoryModuleType.MEETING_POINT).ifPresent { newValue -> + eVillager.brain.getMemory(MemoryModuleType.MEETING_POINT).ifPresent { newValue -> meetingPos.set( newValue ) } val lastWork: AtomicReference = AtomicReference(null) - eVillager.behaviorController.getMemory(MemoryModuleType.LAST_WORKED_AT_POI).ifPresent { newValue -> + eVillager.brain.getMemory(MemoryModuleType.LAST_WORKED_AT_POI).ifPresent { newValue -> lastWork.set( newValue ) } val lastSleep: AtomicReference = AtomicReference(null) - eVillager.behaviorController.getMemory(MemoryModuleType.LAST_SLEPT).ifPresent { newValue -> + eVillager.brain.getMemory(MemoryModuleType.LAST_SLEPT).ifPresent { newValue -> lastSleep.set( newValue ) } val seenIGRecently: AtomicReference = AtomicReference(null) - eVillager.behaviorController.getMemory(MemoryModuleType.GOLEM_DETECTED_RECENTLY).ifPresent { newValue -> + eVillager.brain.getMemory(MemoryModuleType.GOLEM_DETECTED_RECENTLY).ifPresent { newValue -> seenIGRecently.set( newValue ) } - val isPanicking: Boolean = eVillager.behaviorController.c(Activity.PANIC) + val isPanicking: Boolean = eVillager.brain.isActive(Activity.PANIC) val player = event.player player.sendMessage("=====Villager Info=====") @@ -79,27 +78,27 @@ class VillagerInfo( if (homePos.get() != null) player.sendMessage( java.lang.String.format( "Home: %s, %s, %s", - homePos.get()?.blockPosition?.x, - homePos.get()?.blockPosition?.y, - homePos.get()?.blockPosition?.z + homePos.get()?.pos()?.x, + homePos.get()?.pos()?.y, + homePos.get()?.pos()?.z ) ) if (workPos.get() != null) player.sendMessage( java.lang.String.format( "Work: %s, %s, %s", - workPos.get()?.blockPosition?.x, - workPos.get()?.blockPosition?.y, - workPos.get()?.blockPosition?.z + workPos.get()?.pos()?.x, + workPos.get()?.pos()?.y, + workPos.get()?.pos()?.z ) ) if (homePos.get() != null) player.sendMessage( java.lang.String.format( "Meeting point: %s, %s, %s", - meetingPos.get()?.blockPosition?.x, - meetingPos.get()?.blockPosition?.y, - meetingPos.get()?.blockPosition?.z + meetingPos.get()?.pos()?.x, + meetingPos.get()?.pos()?.y, + meetingPos.get()?.pos()?.z ) )