Port most features to 1.18.1.

Fix redyeTerracotta tweak.
main
kalle 2022-01-30 19:37:35 +01:00
parent f4f043e4d6
commit 471a683ae3
20 changed files with 982 additions and 938 deletions

View File

@ -1,8 +1,9 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
kotlin("jvm") version "1.4.32" kotlin("jvm") version "1.5.31"
id("com.github.johnrengelman.shadow") version "5.2.0" id("com.github.johnrengelman.shadow") version "5.2.0"
id("io.papermc.paperweight.userdev") version "1.3.4"
} }
group = "nl.kallestruik" group = "nl.kallestruik"
@ -19,29 +20,17 @@ repositories {
dependencies { dependencies {
implementation("co.aikar:acf-paper:0.5.0-SNAPSHOT") 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("com.comphenix.protocol:ProtocolLib:4.6.0")
compileOnly(kotlin("stdlib-jdk8")) compileOnly(kotlin("stdlib-jdk8"))
compileOnly("nl.kallestruik:DLib:1.0") compileOnly("nl.kallestruik:DLib:1.3.5")
testImplementation(kotlin("test-junit5")) testImplementation(kotlin("test-junit5"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0") testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine: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 { tasks.shadowJar {
relocate("co.aikar.commands", "nl.kallestruik.dtweaks.acf") relocate("co.aikar.commands", "nl.kallestruik.dtweaks.acf")
relocate("co.aikar.locales", "nl.kallestruik.dtweaks.locales") relocate("co.aikar.locales", "nl.kallestruik.dtweaks.locales")
@ -51,10 +40,26 @@ tasks.build {
dependsOn(tasks.shadowJar) dependsOn(tasks.shadowJar)
} }
tasks.withType<KotlinCompile> { tasks {
kotlinOptions.jvmTarget = "11" assemble {
} dependsOn(reobfJar)
}
tasks.processResources { test {
expand("version" to project.version) useJUnitPlatform()
}
compileJava {
options.compilerArgs.add("-parameters")
}
compileKotlin {
kotlinOptions.javaParameters = true
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
processResources {
expand("version" to project.version)
}
} }

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -1,3 +1,9 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven("https://papermc.io/repo/repository/maven-public/")
}
}
rootProject.name = "DTweaks" rootProject.name = "DTweaks"

View File

@ -5,12 +5,7 @@ import co.aikar.commands.PaperCommandManager
import nl.kallestruik.dlib.DUtil import nl.kallestruik.dlib.DUtil
import nl.kallestruik.dlib.MathHelper import nl.kallestruik.dlib.MathHelper
import nl.kallestruik.dlib.ReflectionUtil 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.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.TrampleManager
import nl.kallestruik.dtweaks.managers.TweakManager import nl.kallestruik.dtweaks.managers.TweakManager
import nl.kallestruik.dtweaks.tweaks.craftingtweaks.* 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.dispsensertweaks.DispensersCanPlantSaplings
import nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks.ArmorStandArmorSwapping import nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks.ArmorStandArmorSwapping
import nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks.CarpetBlockPlacingProtocol 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.NoCreeperGrief
import nl.kallestruik.dtweaks.tweaks.mobtweaks.NoDoorBreaking import nl.kallestruik.dtweaks.tweaks.mobtweaks.NoDoorBreaking
import nl.kallestruik.dtweaks.tweaks.mobtweaks.NoEndermanGrief import nl.kallestruik.dtweaks.tweaks.mobtweaks.NoEndermanGrief
@ -38,8 +31,8 @@ class DTweaks: JavaPlugin() {
lateinit var reflectionUtil: ReflectionUtil lateinit var reflectionUtil: ReflectionUtil
private lateinit var trampleManager: TrampleManager private lateinit var trampleManager: TrampleManager
private lateinit var commandManager: PaperCommandManager private lateinit var commandManager: PaperCommandManager
private lateinit var fakePlayerManager: FakePlayerManager // private lateinit var fakePlayerManager: FakePlayerManager
private lateinit var pocketDimensionManager: PocketDimensionManager // private lateinit var pocketDimensionManager: PocketDimensionManager
} }
override fun onEnable() { override fun onEnable() {
@ -53,8 +46,8 @@ class DTweaks: JavaPlugin() {
reflectionUtil = ReflectionUtil() reflectionUtil = ReflectionUtil()
trampleManager = TrampleManager() trampleManager = TrampleManager()
commandManager = PaperCommandManager(this) commandManager = PaperCommandManager(this)
fakePlayerManager = FakePlayerManager() // fakePlayerManager = FakePlayerManager()
pocketDimensionManager = PocketDimensionManager(mathHelper) // pocketDimensionManager = PocketDimensionManager(mathHelper)
// Enable brigadier support on ACF // Enable brigadier support on ACF
commandManager.enableUnstableAPI("brigadier") commandManager.enableUnstableAPI("brigadier")
@ -64,9 +57,9 @@ class DTweaks: JavaPlugin() {
/* /*
* Commands * Commands
*/ */
commandManager.registerCommand(CommandMobcaps(reflectionUtil)) // commandManager.registerCommand(CommandMobcaps(reflectionUtil))
commandManager.registerCommand(CommandPlayer(fakePlayerManager, tweakManager)) // commandManager.registerCommand(CommandPlayer(fakePlayerManager, tweakManager))
commandManager.registerCommand(CommandPocketdim(pocketDimensionManager)) // commandManager.registerCommand(CommandPocketdim(pocketDimensionManager))
commandManager.registerCommand(CommandToggletrample(trampleManager)) commandManager.registerCommand(CommandToggletrample(trampleManager))
/* /*
@ -74,7 +67,7 @@ class DTweaks: JavaPlugin() {
*/ */
tweakManager.loadFromFile(File(dataFolder, Const.TWEAK_STATE_FILE_NAME)) tweakManager.loadFromFile(File(dataFolder, Const.TWEAK_STATE_FILE_NAME))
trampleManager.loadFromFile(File(dataFolder, Const.TRAMPLE_ENABLED_FILE_NAME)) trampleManager.loadFromFile(File(dataFolder, Const.TRAMPLE_ENABLED_FILE_NAME))
pocketDimensionManager.loadData() // pocketDimensionManager.loadData()
/* /*
* Crafting tweaks * Crafting tweaks
@ -87,6 +80,7 @@ class DTweaks: JavaPlugin() {
tweakManager.registerTweak(CraftableSponge(this)) tweakManager.registerTweak(CraftableSponge(this))
tweakManager.registerTweak(IceDecompression(this)) tweakManager.registerTweak(IceDecompression(this))
tweakManager.registerTweak(LogsToChests(this)) tweakManager.registerTweak(LogsToChests(this))
tweakManager.registerTweak(RedyeTerracotta(this))
tweakManager.registerTweak(WoolToString(this)) tweakManager.registerTweak(WoolToString(this))
/* /*
@ -109,8 +103,8 @@ class DTweaks: JavaPlugin() {
*/ */
tweakManager.registerTweak(ArmorStandArmorSwapping(this)) tweakManager.registerTweak(ArmorStandArmorSwapping(this))
tweakManager.registerTweak(CarpetBlockPlacingProtocol(this, mathHelper)) tweakManager.registerTweak(CarpetBlockPlacingProtocol(this, mathHelper))
tweakManager.registerTweak(FakePlayers(fakePlayerManager)) // tweakManager.registerTweak(FakePlayers(fakePlayerManager))
tweakManager.registerTweak(SpaceTimePockets(this, pocketDimensionManager)) // tweakManager.registerTweak(SpaceTimePockets(this, pocketDimensionManager))
/* /*
* Mob Tweaks * Mob Tweaks
@ -127,7 +121,7 @@ class DTweaks: JavaPlugin() {
*/ */
tweakManager.saveToFile(File(dataFolder, Const.TWEAK_STATE_FILE_NAME)) tweakManager.saveToFile(File(dataFolder, Const.TWEAK_STATE_FILE_NAME))
trampleManager.saveToFile(File(dataFolder, Const.TRAMPLE_ENABLED_FILE_NAME)) trampleManager.saveToFile(File(dataFolder, Const.TRAMPLE_ENABLED_FILE_NAME))
pocketDimensionManager.saveData() // pocketDimensionManager.saveData()
} }
private fun registerCommandConditions() { private fun registerCommandConditions() {

View File

@ -1,75 +1,75 @@
package nl.kallestruik.dtweaks.commands //package nl.kallestruik.dtweaks.commands
//
import co.aikar.commands.BaseCommand //import co.aikar.commands.BaseCommand
import co.aikar.commands.annotation.* //import co.aikar.commands.annotation.*
import co.aikar.commands.annotation.Optional //import co.aikar.commands.annotation.Optional
import com.mojang.datafixers.util.Pair //import com.mojang.datafixers.util.Pair
import it.unimi.dsi.fastutil.objects.Object2IntMap //import it.unimi.dsi.fastutil.objects.Object2IntMap
import net.kyori.adventure.text.Component //import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.TextColor //import net.kyori.adventure.text.format.TextColor
import net.minecraft.server.v1_16_R3.ChunkMapDistance //import net.minecraft.server.v1_16_R3.ChunkMapDistance
import net.minecraft.server.v1_16_R3.EnumCreatureType //import net.minecraft.server.v1_16_R3.EnumCreatureType
import nl.kallestruik.dlib.ReflectionUtil //import nl.kallestruik.dlib.ReflectionUtil
import org.bukkit.Bukkit //import org.bukkit.Bukkit
import org.bukkit.command.CommandSender //import org.bukkit.command.CommandSender
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld //import org.bukkit.craftbukkit.v1_18_R1.CraftWorld
import org.bukkit.entity.Player //import org.bukkit.entity.Player
import java.util.* //import java.util.*
//
@CommandAlias("mobcaps") //@CommandAlias("mobcaps")
class CommandMobcaps( //class CommandMobcaps(
private val reflectionUtil: ReflectionUtil // private val reflectionUtil: ReflectionUtil
): BaseCommand() { //): BaseCommand() {
//
@Default // @Default
@Subcommand("view") // @Subcommand("view")
@CommandCompletion("@worlds") // @CommandCompletion("@worlds")
fun onMobcaps(sender: CommandSender, @Optional worldName: String?) { // fun onMobcaps(sender: CommandSender, @Optional worldName: String?) {
var craftWorld: CraftWorld? = null // var craftWorld: CraftWorld? = null
//
if (sender is Player) // if (sender is Player)
craftWorld = (sender.world as CraftWorld) // craftWorld = (sender.world as CraftWorld)
else if (worldName == null) // else if (worldName == null)
sender.sendMessage(Component.text("ERROR: You need to be a player or supply a world name!").color(TextColor.color(0x660000))) // sender.sendMessage(Component.text("ERROR: You need to be a player or supply a world name!").color(TextColor.color(0x660000)))
var name = worldName // var name = worldName
if (worldName == null) { // if (worldName == null) {
name = craftWorld?.name // name = craftWorld?.name
} else { // } else {
val bukkitWorld = Bukkit.getWorld(worldName) // val bukkitWorld = Bukkit.getWorld(worldName)
if (bukkitWorld == null) // if (bukkitWorld == null)
name = craftWorld?.name // name = craftWorld?.name
else // else
craftWorld = (bukkitWorld as CraftWorld) // craftWorld = (bukkitWorld as CraftWorld)
} // }
//
val world = craftWorld?.handle ?: return // val world = craftWorld?.handle ?: return
//
val chunkMapDistance = ( // val chunkMapDistance = (
reflectionUtil.getValueFromField(world.getChunkProvider(), "chunkMapDistance") // reflectionUtil.getValueFromField(world.getChunkProvider(), "chunkMapDistance")
?: return // ?: return
) as ChunkMapDistance // ) as ChunkMapDistance
//
val chunks = chunkMapDistance.b() // val chunks = chunkMapDistance.b()
//
// world.getChunkManager().getSpawnInfo(); // // world.getChunkManager().getSpawnInfo();
val spawnInfo = world.getChunkProvider()?.k() ?: return // val spawnInfo = world.getChunkProvider()?.k() ?: return
//
val mobs: Object2IntMap<EnumCreatureType> = spawnInfo.b() // val mobs: Object2IntMap<EnumCreatureType> = spawnInfo.b()
val mobcaps = EnumMap<EnumCreatureType, Pair<Int, Int>>( // val mobcaps = EnumMap<EnumCreatureType, Pair<Int, Int>>(
EnumCreatureType::class.java // EnumCreatureType::class.java
) // )
for (category in EnumCreatureType.values()) { // for (category in EnumCreatureType.values()) {
if (category == EnumCreatureType.MISC) continue // if (category == EnumCreatureType.MISC) continue
val cur: Int = mobs[category]?: 0 // val cur: Int = mobs[category]?: 0
val max = chunks * category.c() / (17 * 17) // val max = chunks * category.c() / (17 * 17)
mobcaps[category] = Pair(cur, max) // mobcaps[category] = Pair(cur, max)
} // }
//
sender.sendMessage("=============Mobcaps [${name}]=============") // sender.sendMessage("=============Mobcaps [${name}]=============")
for ((key, value) in mobcaps) { // for ((key, value) in mobcaps) {
val cur = value.first // val cur = value.first
val max = value.second // val max = value.second
sender.sendMessage("${key.getName()}: ${cur}/${max}") // sender.sendMessage("${key.getName()}: ${cur}/${max}")
} // }
} // }
} //}

View File

@ -1,28 +1,28 @@
package nl.kallestruik.dtweaks.commands //package nl.kallestruik.dtweaks.commands
//
import co.aikar.commands.BaseCommand //import co.aikar.commands.BaseCommand
import co.aikar.commands.annotation.* //import co.aikar.commands.annotation.*
import nl.kallestruik.dtweaks.managers.FakePlayerManager //import nl.kallestruik.dtweaks.managers.FakePlayerManager
import nl.kallestruik.dtweaks.managers.TweakManager //import nl.kallestruik.dtweaks.managers.TweakManager
import org.bukkit.command.CommandSender //import org.bukkit.command.CommandSender
import org.bukkit.entity.Player //import org.bukkit.entity.Player
//
@CommandAlias("player") //@CommandAlias("player")
@Conditions("tweakEnabled:tweak=FakePlayers") //@Conditions("tweakEnabled:tweak=FakePlayers")
class CommandPlayer( //class CommandPlayer(
private val fakePlayerManager: FakePlayerManager, // private val fakePlayerManager: FakePlayerManager,
private val tweakManager: TweakManager // private val tweakManager: TweakManager
): BaseCommand() { //): BaseCommand() {
//
@Subcommand("spawn") // @Subcommand("spawn")
@CommandCompletion("@players") // @CommandCompletion("@players")
fun onSpawn(sender: Player, @Single playerName: String) { // fun onSpawn(sender: Player, @Single playerName: String) {
fakePlayerManager.spawnFakePlayer(sender.location, playerName) // fakePlayerManager.spawnFakePlayer(sender.location, playerName)
} // }
//
@Subcommand("kill") // @Subcommand("kill")
@CommandCompletion("@players") // @CommandCompletion("@players")
fun onKill(sender: Player, @Single playerName: String) { // fun onKill(sender: Player, @Single playerName: String) {
fakePlayerManager.killFakePlayer(playerName) // fakePlayerManager.killFakePlayer(playerName)
} // }
} //}

View File

@ -1,25 +1,25 @@
package nl.kallestruik.dtweaks.commands //package nl.kallestruik.dtweaks.commands
//
import co.aikar.commands.BaseCommand //import co.aikar.commands.BaseCommand
import co.aikar.commands.annotation.CommandAlias //import co.aikar.commands.annotation.CommandAlias
import co.aikar.commands.annotation.Conditions //import co.aikar.commands.annotation.Conditions
import co.aikar.commands.annotation.Subcommand //import co.aikar.commands.annotation.Subcommand
import nl.kallestruik.dtweaks.managers.PocketDimensionManager //import nl.kallestruik.dtweaks.managers.PocketDimensionManager
import org.bukkit.entity.Player //import org.bukkit.entity.Player
//
@CommandAlias("pocketdim") //@CommandAlias("pocketdim")
@Conditions("tweakEnabled:tweak=SpaceTimePockets") //@Conditions("tweakEnabled:tweak=SpaceTimePockets")
class CommandPocketdim( //class CommandPocketdim(
private val pocketDimensionManager: PocketDimensionManager // private val pocketDimensionManager: PocketDimensionManager
): BaseCommand() { //): BaseCommand() {
//
@Subcommand("create") // @Subcommand("create")
fun onCreate(sender: Player) { // fun onCreate(sender: Player) {
pocketDimensionManager.createPocketForPlayer(sender) // pocketDimensionManager.createPocketForPlayer(sender)
} // }
//
@Subcommand("tp") // @Subcommand("tp")
fun onTp(sender: Player) { // fun onTp(sender: Player) {
pocketDimensionManager.teleportPlayerIntoPocket(sender, sender.uniqueId) // pocketDimensionManager.teleportPlayerIntoPocket(sender, sender.uniqueId)
} // }
} //}

View File

@ -1,30 +1,27 @@
package nl.kallestruik.dtweaks.fakeplayer //package nl.kallestruik.dtweaks.fakeplayer
//
import io.netty.util.concurrent.Future //import io.netty.util.concurrent.Future
import io.netty.util.concurrent.GenericFutureListener //import io.netty.util.concurrent.GenericFutureListener
import net.minecraft.server.v1_16_R3.EnumProtocolDirection //
import net.minecraft.server.v1_16_R3.NetworkManager //class FakeConnection(
import net.minecraft.server.v1_16_R3.Packet // enumProtocolDirection: EnumProtocolDirection
//): NetworkManager(enumProtocolDirection) {
class FakeConnection( // var open = true
enumProtocolDirection: EnumProtocolDirection //
): NetworkManager(enumProtocolDirection) { // // isOpen()
var open = true // override fun isConnected(): Boolean {
// return open
// isOpen() // }
override fun isConnected(): Boolean { //
return open // // hasChannel()
} // override fun i(): Boolean {
// return false
// hasChannel() // }
override fun i(): Boolean { //
return false // override fun sendPacket(packet: Packet<*>?, genericfuturelistener: GenericFutureListener<out Future<in Void?>?>?) {}
} //
// // disableAutoRead()
override fun sendPacket(packet: Packet<*>?, genericfuturelistener: GenericFutureListener<out Future<in Void?>?>?) {} // override fun stopReading() {}
//
// disableAutoRead() // override fun handleDisconnection() {}
override fun stopReading() {} //}
override fun handleDisconnection() {}
}

View File

@ -1,168 +1,168 @@
package nl.kallestruik.dtweaks.fakeplayer //package nl.kallestruik.dtweaks.fakeplayer
//
import com.mojang.authlib.GameProfile //import com.mojang.authlib.GameProfile
import net.minecraft.server.v1_16_R3.* //import net.minecraft.server.v1_16_R3.*
import nl.kallestruik.dtweaks.DTweaks //import nl.kallestruik.dtweaks.DTweaks
import org.bukkit.Location //import org.bukkit.Location
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld //import org.bukkit.craftbukkit.v1_16_R3.CraftWorld
//
class FakePlayer( //class FakePlayer(
minecraftServer: MinecraftServer?, // minecraftServer: MinecraftServer?,
worldServer: WorldServer?, // worldServer: WorldServer?,
gameProfile: GameProfile?, // gameProfile: GameProfile?,
playerInteractManager: PlayerInteractManager? // playerInteractManager: PlayerInteractManager?
): EntityPlayer(minecraftServer, worldServer, gameProfile, playerInteractManager) { //): EntityPlayer(minecraftServer, worldServer, gameProfile, playerInteractManager) {
val locale = "en_US" // val locale = "en_US"
private var hasStartingPos = false // private var hasStartingPos = false
private var startingX = 0.0 // private var startingX = 0.0
private var startingY = 0.0 // private var startingY = 0.0
private var startingZ = 0.0 // private var startingZ = 0.0
private var startingYaw = 0f // private var startingYaw = 0f
private var startingPitch = 0f // private var startingPitch = 0f
//
private constructor( // private constructor(
server: MinecraftServer, // server: MinecraftServer,
worldIn: WorldServer, // worldIn: WorldServer,
profile: GameProfile?, // profile: GameProfile?,
interactionManagerIn: PlayerInteractManager, // interactionManagerIn: PlayerInteractManager,
x: Double, // x: Double,
y: Double, // y: Double,
z: Double, // z: Double,
yaw: Float, // yaw: Float,
pitch: Float // pitch: Float
) : this(server, worldIn, profile, interactionManagerIn) { // ) : this(server, worldIn, profile, interactionManagerIn) {
this.hasStartingPos = true // this.hasStartingPos = true
this.startingX = x // this.startingX = x
this.startingY = y // this.startingY = y
this.startingZ = z // this.startingZ = z
this.startingYaw = yaw // this.startingYaw = yaw
this.startingPitch = pitch // this.startingPitch = pitch
applyStartingPosition() // applyStartingPosition()
} // }
//
companion object { // companion object {
fun atLocation(location: Location, name: String?): FakePlayer? { // fun atLocation(location: Location, name: String?): FakePlayer? {
// Split the location into its parts for use later. // // Split the location into its parts for use later.
val x = location.x // val x = location.x
val y = location.y // val y = location.y
val z = location.z // val z = location.z
val yaw = location.yaw.toDouble() // val yaw = location.yaw.toDouble()
val pitch = location.pitch.toDouble() // val pitch = location.pitch.toDouble()
try { // try {
// Get the minecraft server instance. // // Get the minecraft server instance.
val minecraftServer = MinecraftServer.getServer() // val minecraftServer = MinecraftServer.getServer()
// Create an empty variable for the world server. // // Create an empty variable for the world server.
val worldServer = (location.world as CraftWorld).handle // val worldServer = (location.world as CraftWorld).handle
// Get the game profile from the cache (or retrieve it if it is not cached) // // Get the game profile from the cache (or retrieve it if it is not cached)
var gameProfile = minecraftServer.userCache.getProfile(name) ?: return null // var gameProfile = minecraftServer.userCache.getProfile(name) ?: return null
if (gameProfile.properties.containsKey("textures")) { // if (gameProfile.properties.containsKey("textures")) {
gameProfile = TileEntitySkull.b(gameProfile, null, true).get() // gameProfile = TileEntitySkull.b(gameProfile, null, true).get()
} // }
//
// Create a player interact manager using the world server. // // Create a player interact manager using the world server.
val playerInteractManager = PlayerInteractManager(worldServer) // val playerInteractManager = PlayerInteractManager(worldServer)
//
// Create an instance of our fake player. // // Create an instance of our fake player.
val instance = FakePlayer( // val instance = FakePlayer(
minecraftServer, worldServer, gameProfile, playerInteractManager, x, y, z, // minecraftServer, worldServer, gameProfile, playerInteractManager, x, y, z,
yaw.toFloat(), // yaw.toFloat(),
pitch.toFloat() // pitch.toFloat()
) // )
// Create a fake connection for our fake player. // // Create a fake connection for our fake player.
val connection = FakeConnection(EnumProtocolDirection.SERVERBOUND) // val connection = FakeConnection(EnumProtocolDirection.SERVERBOUND)
//
// Set access to connected channels so we can add our own connection. // // Set access to connected channels so we can add our own connection.
val serverConnection = minecraftServer.serverConnection // val serverConnection = minecraftServer.serverConnection
//
(DTweaks.reflectionUtil.getValueFromField( // (DTweaks.reflectionUtil.getValueFromField(
serverConnection!!, // serverConnection!!,
"connectedChannels" // "connectedChannels"
) as MutableList<NetworkManager?>).add(connection) // ) as MutableList<NetworkManager?>).add(connection)
//
// Connect the fake player to the server using the fake connection. // // Connect the fake player to the server using the fake connection.
FakePlayerList.a(minecraftServer.playerList, connection, instance) // FakePlayerList.a(minecraftServer.playerList, connection, instance)
//
// Check if the fake player is not yet in the correct world. // // Check if the fake player is not yet in the correct world.
if (instance.world.dimensionKey != worldServer.dimensionKey) { // if (instance.world.dimensionKey != worldServer.dimensionKey) {
// Store the old world of the fake player. // // Store the old world of the fake player.
val old_world = instance.world as WorldServer // val old_world = instance.world as WorldServer
// Remove the fake player from the old world. // // Remove the fake player from the old world.
old_world.removePlayer(instance) // old_world.removePlayer(instance)
// Make the fake player not be dead. // // Make the fake player not be dead.
instance.dead = false // instance.dead = false
// Create the fake player in the new world. // // Create the fake player in the new world.
worldServer.addEntity(instance) // worldServer.addEntity(instance)
// Spawn the fake player in the new world. // // Spawn the fake player in the new world.
instance.spawnIn(worldServer) // instance.spawnIn(worldServer)
// Move the fake player to the new world for the server. // // Move the fake player to the new world for the server.
minecraftServer.playerList.moveToWorld(instance, old_world, true, null, false) // minecraftServer.playerList.moveToWorld(instance, old_world, true, null, false)
// requestTeleport(x, y, z, yaw, pitch) // // requestTeleport(x, y, z, yaw, pitch)
// Request the teleport from the fake player. // // Request the teleport from the fake player.
instance.playerConnection.a(x, y, z, yaw.toFloat(), pitch.toFloat()) // instance.playerConnection.a(x, y, z, yaw.toFloat(), pitch.toFloat())
// Set the fake player's world to the new world. // // Set the fake player's world to the new world.
instance.playerInteractManager.world = worldServer // instance.playerInteractManager.world = worldServer
instance.teleportTo(worldServer, BlockPosition(x, y, z)) // instance.teleportTo(worldServer, BlockPosition(x, y, z))
} // }
//
/// Set the fake players health to max. // /// Set the fake players health to max.
instance.health = 20.0f // instance.health = 20.0f
// Make the fake player not be dead. // // Make the fake player not be dead.
instance.dead = false // instance.dead = false
// a == requestTeleport // // a == requestTeleport
// Request the teleport from the fake player. // // Request the teleport from the fake player.
instance.playerConnection.a(x, y, z, yaw.toFloat(), pitch.toFloat()) // instance.playerConnection.a(x, y, z, yaw.toFloat(), pitch.toFloat())
// G == stepHeight // // G == stepHeight
// Set the fake players step height to 0.6 (The normal value). // // Set the fake players step height to 0.6 (The normal value).
instance.G = 0.6f // instance.G = 0.6f
// Set the fake players gamemode to survival. // // Set the fake players gamemode to survival.
playerInteractManager.gameMode = EnumGamemode.SURVIVAL // playerInteractManager.gameMode = EnumGamemode.SURVIVAL
// Tell everyone in the world about the fake player and where he is. // // Tell everyone in the world about the fake player and where he is.
minecraftServer.playerList.a( // minecraftServer.playerList.a(
PacketPlayOutEntityHeadRotation(instance, (instance.yaw * 256 / 360).toByte()), // PacketPlayOutEntityHeadRotation(instance, (instance.yaw * 256 / 360).toByte()),
instance.world.dimensionKey // instance.world.dimensionKey
) // )
minecraftServer.playerList.a(PacketPlayOutEntityTeleport(instance), instance.world.dimensionKey) // minecraftServer.playerList.a(PacketPlayOutEntityTeleport(instance), instance.world.dimensionKey)
// Move the fake player for the worlds chunk provider. // // Move the fake player for the worlds chunk provider.
instance.worldServer.getChunkProvider().movePlayer(instance) // instance.worldServer.getChunkProvider().movePlayer(instance)
// bp == PLAYER_MODEL_PARTS // // bp == PLAYER_MODEL_PARTS
instance.datawatcher.set<Byte>(bj, 0x7f.toByte()) // show all model layers (incl. capes) // instance.datawatcher.set<Byte>(bj, 0x7f.toByte()) // show all model layers (incl. capes)
return instance // return instance
} catch (e: Exception) { // } catch (e: Exception) {
e.printStackTrace() // e.printStackTrace()
} // }
return null // return null
} // }
} // }
//
//
fun applyStartingPosition() { // fun applyStartingPosition() {
if (hasStartingPos) { // if (hasStartingPos) {
this.setPositionRotation(startingX, startingY, startingZ, startingYaw, startingPitch) // this.setPositionRotation(startingX, startingY, startingZ, startingYaw, startingPitch)
mot = Vec3D(0.0, 0.0, 0.0) // mot = Vec3D(0.0, 0.0, 0.0)
} // }
} // }
//
//
override fun killEntity() { // override fun killEntity() {
server.a(TickTask(server.ai()) { playerConnection.a(ChatComponentText("Killed")) }) // server.a(TickTask(server.ai()) { playerConnection.a(ChatComponentText("Killed")) })
} // }
//
override fun tick() { // override fun tick() {
super.tick() // super.tick()
if (H()) { // if (H()) {
I() // I()
} // }
movementTick() // movementTick()
if (server.ai() % 10 == 0) { // if (server.ai() % 10 == 0) {
playerConnection.syncPosition() // playerConnection.syncPosition()
this.worldServer.getChunkProvider().movePlayer(this) // this.worldServer.getChunkProvider().movePlayer(this)
} // }
} // }
//
override fun die(cause: DamageSource?) { // override fun die(cause: DamageSource?) {
super.die(cause) // super.die(cause)
health = 20f // health = 20f
foodData = FoodMetaData(this) // foodData = FoodMetaData(this)
killEntity() // killEntity()
} // }
} //}

View File

@ -1,36 +1,36 @@
package nl.kallestruik.dtweaks.fakeplayer //package nl.kallestruik.dtweaks.fakeplayer
//
import net.minecraft.server.v1_16_R3.* //import net.minecraft.server.v1_16_R3.*
import nl.kallestruik.dtweaks.DTweaks //import nl.kallestruik.dtweaks.DTweaks
import java.lang.reflect.Field //import java.lang.reflect.Field
//
class FakePlayerConnection( //class FakePlayerConnection(
minecraftServer: MinecraftServer, // minecraftServer: MinecraftServer,
networkManager: NetworkManager, // networkManager: NetworkManager,
entityPlayer: EntityPlayer // entityPlayer: EntityPlayer
): PlayerConnection(minecraftServer, networkManager, entityPlayer) { //): PlayerConnection(minecraftServer, networkManager, entityPlayer) {
override fun sendPacket(packet: Packet<*>?) { // override fun sendPacket(packet: Packet<*>?) {
if (packet is PacketPlayOutKeepAlive) { // if (packet is PacketPlayOutKeepAlive) {
val pong = PacketPlayInKeepAlive() // val pong = PacketPlayInKeepAlive()
try { // try {
val pingId: Field = DTweaks.reflectionUtil.getField(PacketPlayOutKeepAlive::class.java, "a") // val pingId: Field = DTweaks.reflectionUtil.getField(PacketPlayOutKeepAlive::class.java, "a")
val pongId: Field = DTweaks.reflectionUtil.getField(PacketPlayInKeepAlive::class.java, "a") // val pongId: Field = DTweaks.reflectionUtil.getField(PacketPlayInKeepAlive::class.java, "a")
pingId.isAccessible = true // pingId.isAccessible = true
pongId.isAccessible = true // pongId.isAccessible = true
pongId[pong] = pingId[packet] // pongId[pong] = pingId[packet]
} catch (e: Exception) { // } catch (e: Exception) {
e.printStackTrace() // e.printStackTrace()
} // }
this.a(pong) // this.a(pong)
} // }
} // }
//
override fun disconnect(message: String?) { // override fun disconnect(message: String?) {
player.killEntity() // player.killEntity()
} // }
//
override fun a(disconnectReason: IChatBaseComponent?) { // override fun a(disconnectReason: IChatBaseComponent?) {
super.a(disconnectReason) // super.a(disconnectReason)
(this.a() as FakeConnection).open = false // (this.a() as FakeConnection).open = false
} // }
} //}

View File

@ -1,258 +1,258 @@
package nl.kallestruik.dtweaks.fakeplayer //package nl.kallestruik.dtweaks.fakeplayer
//
import com.mojang.serialization.DataResult //import com.mojang.serialization.DataResult
import com.mojang.serialization.Dynamic //import com.mojang.serialization.Dynamic
import io.netty.buffer.Unpooled //import io.netty.buffer.Unpooled
import net.minecraft.server.v1_16_R3.* //import net.minecraft.server.v1_16_R3.*
import nl.kallestruik.dtweaks.DTweaks //import nl.kallestruik.dtweaks.DTweaks
import org.apache.logging.log4j.Logger //import org.apache.logging.log4j.Logger
import org.bukkit.Bukkit //import org.bukkit.Bukkit
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld //import org.bukkit.craftbukkit.v1_16_R3.CraftWorld
import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage //import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage
import org.bukkit.entity.Player //import org.bukkit.entity.Player
import org.spigotmc.event.player.PlayerSpawnLocationEvent //import org.spigotmc.event.player.PlayerSpawnLocationEvent
import java.util.* //import java.util.*
//
object FakePlayerList { //object FakePlayerList {
fun a(playerList: PlayerList, networkManager: NetworkManager, entityPlayer: EntityPlayer) { // fun a(playerList: PlayerList, networkManager: NetworkManager, entityPlayer: EntityPlayer) {
// Setup what are normally class level variables // // Setup what are normally class level variables
val server = DTweaks.reflectionUtil.getValueFromField(playerList, "server") as MinecraftServer // val server = DTweaks.reflectionUtil.getValueFromField(playerList, "server") as MinecraftServer
val LOGGER = DTweaks.reflectionUtil.getValueFromField(playerList, "LOGGER") as Logger // val LOGGER = DTweaks.reflectionUtil.getValueFromField(playerList, "LOGGER") as Logger
//
val gameProfile = entityPlayer.profile // val gameProfile = entityPlayer.profile
val userCache = server.userCache // val userCache = server.userCache
val oldGameProfile = userCache.getProfile(gameProfile.id) // val oldGameProfile = userCache.getProfile(gameProfile.id)
var oldName = if (oldGameProfile == null) gameProfile.name else oldGameProfile.name // var oldName = if (oldGameProfile == null) gameProfile.name else oldGameProfile.name
//
userCache.a(gameProfile) // userCache.a(gameProfile)
val playerData = playerList.a(entityPlayer) // val playerData = playerList.a(entityPlayer)
if (playerData != null && playerData.hasKey("bukkit")) { // if (playerData != null && playerData.hasKey("bukkit")) {
val bukkit = playerData.getCompound("bukkit") // val bukkit = playerData.getCompound("bukkit")
oldName = if (bukkit.hasKeyOfType("lastKnownName", 8)) bukkit.getString("lastKnownName") else oldName // oldName = if (bukkit.hasKeyOfType("lastKnownName", 8)) bukkit.getString("lastKnownName") else oldName
} // }
val worldKey: ResourceKey<World> = if (playerData != null) { // val worldKey: ResourceKey<World> = if (playerData != null) {
val dataResult: DataResult<ResourceKey<World>> = DimensionManager.a( // val dataResult: DataResult<ResourceKey<World>> = DimensionManager.a(
Dynamic( // Dynamic(
DynamicOpsNBT.a, // DynamicOpsNBT.a,
playerData["Dimension"] // playerData["Dimension"]
) // )
) // )
dataResult.resultOrPartial { o -> LOGGER.error(o) } // dataResult.resultOrPartial { o -> LOGGER.error(o) }
.orElse(World.OVERWORLD) as ResourceKey<World> // .orElse(World.OVERWORLD) as ResourceKey<World>
} else { // } else {
World.OVERWORLD // World.OVERWORLD
} // }
var worldServer = server.getWorldServer(worldKey) ?: server.E() // var worldServer = server.getWorldServer(worldKey) ?: server.E()
//
entityPlayer.spawnIn(worldServer) // entityPlayer.spawnIn(worldServer)
entityPlayer.playerInteractManager.a(entityPlayer.world as WorldServer) // entityPlayer.playerInteractManager.a(entityPlayer.world as WorldServer)
var s1 = "local" // var s1 = "local"
if (networkManager.getSocketAddress() != null) { // if (networkManager.getSocketAddress() != null) {
s1 = networkManager.getSocketAddress().toString() // s1 = networkManager.getSocketAddress().toString()
} // }
val bukkitPlayer: Player = entityPlayer.bukkitEntity // val bukkitPlayer: Player = entityPlayer.bukkitEntity
val ev = PlayerSpawnLocationEvent(bukkitPlayer, bukkitPlayer.location) // val ev = PlayerSpawnLocationEvent(bukkitPlayer, bukkitPlayer.location)
Bukkit.getPluginManager().callEvent(ev) // Bukkit.getPluginManager().callEvent(ev)
val loc = ev.spawnLocation // val loc = ev.spawnLocation
worldServer = (loc.world as CraftWorld).handle // worldServer = (loc.world as CraftWorld).handle
entityPlayer.spawnIn(worldServer) // entityPlayer.spawnIn(worldServer)
entityPlayer.playerInteractManager.a(entityPlayer.world as WorldServer) // entityPlayer.playerInteractManager.a(entityPlayer.world as WorldServer)
entityPlayer.setPosition(loc.x, loc.y, loc.z) // entityPlayer.setPosition(loc.x, loc.y, loc.z)
//
//entityplayer.setYawPitch(loc.getYaw(), loc.getPitch()); // //entityplayer.setYawPitch(loc.getYaw(), loc.getPitch());
try { // try {
val setYawPitch = Entity::class.java.getDeclaredMethod( // val setYawPitch = Entity::class.java.getDeclaredMethod(
"setYawPitch", // "setYawPitch",
Float::class.javaPrimitiveType, // Float::class.javaPrimitiveType,
Float::class.javaPrimitiveType // Float::class.javaPrimitiveType
) // )
setYawPitch.isAccessible = true // setYawPitch.isAccessible = true
setYawPitch.invoke(entityPlayer, loc.yaw, loc.pitch) // setYawPitch.invoke(entityPlayer, loc.yaw, loc.pitch)
} catch (e: Exception) { // } catch (e: Exception) {
e.printStackTrace() // e.printStackTrace()
} // }
val worldData = worldServer.getWorldData() // val worldData = worldServer.getWorldData()
//
//playerList.a(entityplayer, (EntityPlayer)null, worldserver1); // //playerList.a(entityplayer, (EntityPlayer)null, worldserver1);
try { // try {
val a = PlayerList::class.java.getDeclaredMethod( // val a = PlayerList::class.java.getDeclaredMethod(
"a", // "a",
EntityPlayer::class.java, // EntityPlayer::class.java,
EntityPlayer::class.java, // EntityPlayer::class.java,
WorldServer::class.java // WorldServer::class.java
) // )
a.isAccessible = true // a.isAccessible = true
a.invoke(playerList, entityPlayer, null, worldServer) // a.invoke(playerList, entityPlayer, null, worldServer)
} catch (e: Exception) { // } catch (e: Exception) {
e.printStackTrace() // e.printStackTrace()
} // }
//
//PlayerConnection playerconnection = new PlayerConnection(server, networkmanager, entityplayer); // //PlayerConnection playerconnection = new PlayerConnection(server, networkmanager, entityplayer);
val playerConnection: PlayerConnection = // val playerConnection: PlayerConnection =
(entityPlayer as? FakePlayer)?.let { FakePlayerConnection(server, networkManager, it) } // (entityPlayer as? FakePlayer)?.let { FakePlayerConnection(server, networkManager, it) }
?: PlayerConnection(server, networkManager, entityPlayer) // ?: PlayerConnection(server, networkManager, entityPlayer)
val gameRules = worldServer.gameRules // val gameRules = worldServer.gameRules
val doImmediateRespawn = gameRules.getBoolean(GameRules.DO_IMMEDIATE_RESPAWN) // val doImmediateRespawn = gameRules.getBoolean(GameRules.DO_IMMEDIATE_RESPAWN)
val reducedDebugInfo = gameRules.getBoolean(GameRules.REDUCED_DEBUG_INFO) // val reducedDebugInfo = gameRules.getBoolean(GameRules.REDUCED_DEBUG_INFO)
try { // try {
playerConnection.sendPacket( // playerConnection.sendPacket(
PacketPlayOutLogin( // PacketPlayOutLogin(
entityPlayer.id, // entityPlayer.id,
entityPlayer.playerInteractManager.gameMode, // entityPlayer.playerInteractManager.gameMode,
entityPlayer.playerInteractManager.c(), // entityPlayer.playerInteractManager.c(),
BiomeManager.a( // BiomeManager.a(
worldServer.seed // worldServer.seed
), // ),
worldData.isHardcore, // worldData.isHardcore,
server.F(), // server.F(),
DTweaks.reflectionUtil.getValueFromField(playerList, "s") as IRegistryCustom.Dimension, // DTweaks.reflectionUtil.getValueFromField(playerList, "s") as IRegistryCustom.Dimension,
worldServer.dimensionManager, // worldServer.dimensionManager,
worldServer.dimensionKey, // worldServer.dimensionKey,
playerList.maxPlayers, // playerList.maxPlayers,
worldServer.spigotConfig.viewDistance, // worldServer.spigotConfig.viewDistance,
reducedDebugInfo, // reducedDebugInfo,
!doImmediateRespawn, // !doImmediateRespawn,
worldServer.isDebugWorld, // worldServer.isDebugWorld,
worldServer.isFlatWorld // worldServer.isFlatWorld
) // )
) // )
} catch (e: Exception) { // } catch (e: Exception) {
e.printStackTrace() // e.printStackTrace()
} // }
entityPlayer.bukkitEntity.sendSupportedChannels() // entityPlayer.bukkitEntity.sendSupportedChannels()
playerConnection.sendPacket( // playerConnection.sendPacket(
PacketPlayOutCustomPayload( // PacketPlayOutCustomPayload(
PacketPlayOutCustomPayload.a, // PacketPlayOutCustomPayload.a,
PacketDataSerializer(Unpooled.buffer()).a(playerList.server.serverModName) // PacketDataSerializer(Unpooled.buffer()).a(playerList.server.serverModName)
) // )
) // )
playerConnection.sendPacket(PacketPlayOutServerDifficulty(worldData.difficulty, worldData.isDifficultyLocked)) // playerConnection.sendPacket(PacketPlayOutServerDifficulty(worldData.difficulty, worldData.isDifficultyLocked))
playerConnection.sendPacket(PacketPlayOutAbilities(entityPlayer.abilities)) // playerConnection.sendPacket(PacketPlayOutAbilities(entityPlayer.abilities))
playerConnection.sendPacket(PacketPlayOutHeldItemSlot(entityPlayer.inventory.itemInHandIndex)) // playerConnection.sendPacket(PacketPlayOutHeldItemSlot(entityPlayer.inventory.itemInHandIndex))
playerConnection.sendPacket(PacketPlayOutRecipeUpdate(server.craftingManager.b())) // playerConnection.sendPacket(PacketPlayOutRecipeUpdate(server.craftingManager.b()))
playerConnection.sendPacket(PacketPlayOutTags(server.tagRegistry)) // playerConnection.sendPacket(PacketPlayOutTags(server.tagRegistry))
playerList.d(entityPlayer) // playerList.d(entityPlayer)
entityPlayer.statisticManager.c() // entityPlayer.statisticManager.c()
entityPlayer.recipeBook.a(entityPlayer) // entityPlayer.recipeBook.a(entityPlayer)
playerList.sendScoreboard(worldServer.scoreboard, entityPlayer) // playerList.sendScoreboard(worldServer.scoreboard, entityPlayer)
server.invalidatePingSample() // server.invalidatePingSample()
val chatMessage = if (entityPlayer.profile.name.equals(oldName, ignoreCase = true)) { // val chatMessage = if (entityPlayer.profile.name.equals(oldName, ignoreCase = true)) {
ChatMessage("multiplayer.player.joined", entityPlayer.scoreboardDisplayName) // ChatMessage("multiplayer.player.joined", entityPlayer.scoreboardDisplayName)
} else { // } else {
ChatMessage("multiplayer.player.joined.renamed", entityPlayer.scoreboardDisplayName, oldName) // ChatMessage("multiplayer.player.joined.renamed", entityPlayer.scoreboardDisplayName, oldName)
} // }
chatMessage.a(EnumChatFormat.YELLOW) // chatMessage.a(EnumChatFormat.YELLOW)
var joinMessage = CraftChatMessage.fromComponent(chatMessage) // var joinMessage = CraftChatMessage.fromComponent(chatMessage)
playerConnection.a( // playerConnection.a(
entityPlayer.locX(), // entityPlayer.locX(),
entityPlayer.locY(), // entityPlayer.locY(),
entityPlayer.locZ(), // entityPlayer.locZ(),
entityPlayer.yaw, // entityPlayer.yaw,
entityPlayer.pitch // entityPlayer.pitch
) // )
playerList.players.add(entityPlayer) // playerList.players.add(entityPlayer)
//
//playerList.playersByName.put(entityplayer.getName().toLowerCase(Locale.ROOT), entityplayer); // //playerList.playersByName.put(entityplayer.getName().toLowerCase(Locale.ROOT), entityplayer);
val playersByName = DTweaks.reflectionUtil.getValueFromField(playerList, "playersByName") as HashMap<String, EntityPlayer> // val playersByName = DTweaks.reflectionUtil.getValueFromField(playerList, "playersByName") as HashMap<String, EntityPlayer>
playersByName[entityPlayer.name.toLowerCase(Locale.ROOT)] = entityPlayer // playersByName[entityPlayer.name.toLowerCase(Locale.ROOT)] = entityPlayer
//
//playerList.j.put(entityplayer.getUniqueID(), entityplayer); // //playerList.j.put(entityplayer.getUniqueID(), entityplayer);
val playersByUUID = DTweaks.reflectionUtil.getValueFromField(playerList, "j") as HashMap<UUID, EntityPlayer> // val playersByUUID = DTweaks.reflectionUtil.getValueFromField(playerList, "j") as HashMap<UUID, EntityPlayer>
playersByUUID[entityPlayer.uniqueID] = entityPlayer // playersByUUID[entityPlayer.uniqueID] = entityPlayer
//
if (entityPlayer.playerConnection.networkManager.isConnected) { // if (entityPlayer.playerConnection.networkManager.isConnected) {
var i: Int // var i: Int
if (joinMessage != null && joinMessage.isNotEmpty()) { // if (joinMessage != null && joinMessage.isNotEmpty()) {
var var27: Array<IChatBaseComponent?> // var var27: Array<IChatBaseComponent?>
val var26 = CraftChatMessage.fromString(joinMessage).also { var27 = it }.size // val var26 = CraftChatMessage.fromString(joinMessage).also { var27 = it }.size
i = 0 // i = 0
while (i < var26) { // while (i < var26) {
val line = var27[i] // val line = var27[i]
server.playerList.sendAll(PacketPlayOutChat(line, ChatMessageType.SYSTEM, SystemUtils.b)) // server.playerList.sendAll(PacketPlayOutChat(line, ChatMessageType.SYSTEM, SystemUtils.b))
++i // ++i
} // }
} // }
val packet = PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer) // val packet = PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer)
for (player in playerList.players) { // for (player in playerList.players) {
if (player.bukkitEntity.canSee(entityPlayer.bukkitEntity)) { // if (player.bukkitEntity.canSee(entityPlayer.bukkitEntity)) {
player.playerConnection.sendPacket(packet) // player.playerConnection.sendPacket(packet)
} // }
if (entityPlayer.bukkitEntity.canSee(player.bukkitEntity)) { // if (entityPlayer.bukkitEntity.canSee(player.bukkitEntity)) {
entityPlayer.playerConnection.sendPacket( // entityPlayer.playerConnection.sendPacket(
PacketPlayOutPlayerInfo( // PacketPlayOutPlayerInfo(
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, // PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER,
player // player
) // )
) // )
} // }
} // }
entityPlayer.sentListPacket = true // entityPlayer.sentListPacket = true
entityPlayer.playerConnection.sendPacket( // entityPlayer.playerConnection.sendPacket(
PacketPlayOutEntityMetadata( // PacketPlayOutEntityMetadata(
entityPlayer.id, // entityPlayer.id,
DTweaks.reflectionUtil.getValueFromField(entityPlayer, "datawatcher") as DataWatcher, true // DTweaks.reflectionUtil.getValueFromField(entityPlayer, "datawatcher") as DataWatcher, true
) // )
) // )
//
if (entityPlayer.world === worldServer && !worldServer.getPlayers().contains(entityPlayer)) { // if (entityPlayer.world === worldServer && !worldServer.getPlayers().contains(entityPlayer)) {
worldServer.addPlayerJoin(entityPlayer) // worldServer.addPlayerJoin(entityPlayer)
server.bossBattleCustomData.a(entityPlayer) // server.bossBattleCustomData.a(entityPlayer)
} // }
//
worldServer = entityPlayer.worldServer // worldServer = entityPlayer.worldServer
playerList.a(entityPlayer, worldServer) // playerList.a(entityPlayer, worldServer)
if (server.resourcePack.isNotEmpty()) { // if (server.resourcePack.isNotEmpty()) {
entityPlayer.setResourcePack(server.resourcePack, server.resourcePackHash) // entityPlayer.setResourcePack(server.resourcePack, server.resourcePackHash)
} // }
//
for (mobEffect in entityPlayer.getEffects()) { // for (mobEffect in entityPlayer.getEffects()) {
playerConnection.sendPacket(PacketPlayOutEntityEffect(entityPlayer.id, mobEffect)) // playerConnection.sendPacket(PacketPlayOutEntityEffect(entityPlayer.id, mobEffect))
} // }
//
if (playerData != null && playerData.hasKeyOfType("RootVehicle", 10)) { // if (playerData != null && playerData.hasKeyOfType("RootVehicle", 10)) {
val rootVehicleData = playerData.getCompound("RootVehicle") // val rootVehicleData = playerData.getCompound("RootVehicle")
val entity = EntityTypes.a( // val entity = EntityTypes.a(
rootVehicleData.getCompound("Entity"), worldServer // rootVehicleData.getCompound("Entity"), worldServer
) { entity1x: Entity? -> // ) { entity1x: Entity? ->
if (!worldServer.addEntitySerialized(entity1x) // if (!worldServer.addEntitySerialized(entity1x)
) null else entity1x // ) null else entity1x
} // }
if (entity != null) { // if (entity != null) {
val uuid: UUID? = if (rootVehicleData.b("Attach")) { // val uuid: UUID? = if (rootVehicleData.b("Attach")) {
rootVehicleData.a("Attach") // rootVehicleData.a("Attach")
} else { // } else {
null // null
} // }
if (entity.uniqueID == uuid) { // if (entity.uniqueID == uuid) {
entityPlayer.a(entity, true) // entityPlayer.a(entity, true)
} else { // } else {
for (passenger in entity.allPassengers) { // for (passenger in entity.allPassengers) {
if (passenger.uniqueID == uuid) { // if (passenger.uniqueID == uuid) {
entityPlayer.a(passenger, true) // entityPlayer.a(passenger, true)
break // break
} // }
} // }
} // }
if (!entityPlayer.isPassenger) { // if (!entityPlayer.isPassenger) {
LOGGER.warn("Couldn't reattach entity to player") // LOGGER.warn("Couldn't reattach entity to player")
worldServer.removeEntity(entity) // worldServer.removeEntity(entity)
for (passenger in entity.allPassengers) { // for (passenger in entity.allPassengers) {
worldServer.removeEntity(passenger) // worldServer.removeEntity(passenger)
} // }
} // }
} // }
} // }
entityPlayer.syncInventory() // entityPlayer.syncInventory()
LOGGER.info( // LOGGER.info(
"{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", // "{}[{}] logged in with entity id {} at ([{}]{}, {}, {})",
entityPlayer.getDisplayName().string, // entityPlayer.getDisplayName().string,
s1, // s1,
entityPlayer.id, // entityPlayer.id,
worldServer?.worldDataServer?.name, // worldServer?.worldDataServer?.name,
entityPlayer.locX(), // entityPlayer.locX(),
entityPlayer.locY(), // entityPlayer.locY(),
entityPlayer.locZ() // entityPlayer.locZ()
) // )
} // }
} // }
} //}

View File

@ -1,30 +1,30 @@
package nl.kallestruik.dtweaks.managers //package nl.kallestruik.dtweaks.managers
//
import nl.kallestruik.dtweaks.fakeplayer.FakePlayer //import nl.kallestruik.dtweaks.fakeplayer.FakePlayer
import org.bukkit.Bukkit //import org.bukkit.Bukkit
import org.bukkit.Location //import org.bukkit.Location
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer //import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer
//
class FakePlayerManager { //class FakePlayerManager {
//
fun spawnFakePlayer(loc: Location, name: String) { // fun spawnFakePlayer(loc: Location, name: String) {
val player = Bukkit.getPlayer(name) // val player = Bukkit.getPlayer(name)
if (player != null && player.isOnline) return // if (player != null && player.isOnline) return
FakePlayer.atLocation(loc, name) // FakePlayer.atLocation(loc, name)
} // }
//
fun killFakePlayer(name: String) { // fun killFakePlayer(name: String) {
val player = Bukkit.getPlayer(name) // val player = Bukkit.getPlayer(name)
if (player == null || !player.isOnline) return // if (player == null || !player.isOnline) return
val entityPlayer = (player as CraftPlayer).handle as? FakePlayer ?: return // val entityPlayer = (player as CraftPlayer).handle as? FakePlayer ?: return
entityPlayer.killEntity() // entityPlayer.killEntity()
} // }
//
fun killAllFakePlayers() { // fun killAllFakePlayers() {
for (player in Bukkit.getOnlinePlayers()) { // for (player in Bukkit.getOnlinePlayers()) {
if (!player.isOnline) continue // if (!player.isOnline) continue
val entityPlayer = (player as CraftPlayer).handle as? FakePlayer ?: continue // val entityPlayer = (player as CraftPlayer).handle as? FakePlayer ?: continue
entityPlayer.killEntity() // entityPlayer.killEntity()
} // }
} // }
} //}

View File

@ -1,110 +1,108 @@
package nl.kallestruik.dtweaks.managers //package nl.kallestruik.dtweaks.managers
//
import net.minecraft.server.v1_16_R3.MathHelper //import nl.kallestruik.dlib.MathHelper
import nl.kallestruik.dlib.MathHelper //import nl.kallestruik.dtweaks.spacetimepockets.SpaceTimePocketChunkGenerator
import nl.kallestruik.dtweaks.spacetimepockets.SpaceTimePocketChunkGenerator //import org.bukkit.*
import org.bukkit.* //import org.bukkit.entity.Player
import org.bukkit.entity.Player //import java.util.*
import java.util.* //
//class PocketDimensionManager(
class PocketDimensionManager( // private val mathHelper: MathHelper
private val mathHelper: MathHelper //) {
) { // val pocketDimension: World = WorldCreator.name("space-time-pockets").generator(SpaceTimePocketChunkGenerator()).createWorld()!!
val pocketDimension: World = WorldCreator.name("space-time-pockets").generator(SpaceTimePocketChunkGenerator()).createWorld()!! // private val data = HashMap<UUID, PocketData>()
private val data = HashMap<UUID, PocketData>() // private var lastCreatedPocket = -1
private var lastCreatedPocket = -1 //
// fun loadData() {
fun loadData() { // //TODO: Load data from data file on disk.
//TODO: Load data from data file on disk. // }
} //
// fun saveData() {
fun saveData() { // //TODO: Save data to file on disk.
//TODO: Save data to file on disk. // }
} //
// fun teleportPlayerIntoPocket(player: Player, pocketOwner: UUID) {
fun teleportPlayerIntoPocket(player: Player, pocketOwner: UUID) { // var pocketData = data[pocketOwner]
var pocketData = data[pocketOwner] // if (pocketData == null) pocketData = if (player.uniqueId == pocketOwner) {
if (pocketData == null) pocketData = if (player.uniqueId == pocketOwner) { // createPocketForPlayer(player)
createPocketForPlayer(player) // } else return
} else return // player.teleport(
player.teleport( // Location(
Location( // pocketDimension, (pocketData.startX + 9).toDouble(), 128.0,
pocketDimension, (pocketData.startX + 9).toDouble(), 128.0, // (pocketData.startZ + 9).toDouble()
(pocketData.startZ + 9).toDouble() // )
) // )
) // }
Bukkit.unloadWorld() //
} // fun createPocketForPlayer(player: Player): PocketData {
// // Find a spot
fun createPocketForPlayer(player: Player): PocketData { // val point = findNextFree()
// Find a spot //
val point = findNextFree() // // Load the chunks
// for (x in 0..2) {
// Load the chunks // for (y in 0..2) {
for (x in 0..2) { // pocketDimension.loadChunk(point.x / 16 + x, point.z / 16 + y)
for (y in 0..2) { // }
pocketDimension.loadChunk(point.x / 16 + x, point.z / 16 + y) // }
} //
} // // Build the box
// for (x in 0..17) {
// Build the box // for (z in 0..17) {
for (x in 0..17) { // for (y in 0..255) {
for (z in 0..17) { // if (x == 0 || y == 0 || z == 0 || x == 17 || y == 255 || z == 17) {
for (y in 0..255) { // pocketDimension.getBlockAt(point.x + x, y, point.z + z).type = Material.BLACK_CONCRETE
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
// Create the spawning platform // pocketDimension.getBlockAt(point.x + 8, 127, point.z + 9).type = Material.STONE
pocketDimension.getBlockAt(point.x + 8, 127, point.z + 8).type = Material.STONE // pocketDimension.getBlockAt(point.x + 9, 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 + 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) {
// Unload the chunks // for (y in 0..2) {
for (x in 0..2) { // pocketDimension.unloadChunk(point.x / 16 + x, point.z / 16 + y)
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
val pocketData = PocketData(player.uniqueId, point.x, point.z, ArrayList()) // return pocketData
data[player.uniqueId] = pocketData // }
return pocketData //
} // private fun findNextFree(): Point {
// while (true) {
private fun findNextFree(): Point { // lastCreatedPocket++
while (true) { // val toCheck = getXYForIndex(lastCreatedPocket)
lastCreatedPocket++ // val chunk = pocketDimension.getChunkAt(
val toCheck = getXYForIndex(lastCreatedPocket) // Location(
val chunk = pocketDimension.getChunkAt( // pocketDimension,
Location( // toCheck.x.toDouble(), 0.0, toCheck.z.toDouble()
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) {
val corner = chunk.getBlock(mathHelper.chunkAbs(toCheck.x % 16), 0, mathHelper.chunkAbs(toCheck.z % 16)) // return toCheck
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)
private fun getXYForIndex(index: Int): Point { // // Also subtract 1 from each point so the interior is chunk aligned.
// Space the pockets 256 blocks (16 chunks) from each other with each pocket being 16 blocks (and two for walls) // val x = (256 + 16) * (index % 1000) - 1
// Also subtract 1 from each point so the interior is chunk aligned. // val z = (256 + 16) * (index / 1000) - 1
val x = (256 + 16) * (index % 1000) - 1 // return Point(x, z)
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<GatewayData?>)
//
class PocketData(var owner: UUID, var startX: Int, var startZ: Int, var queuedGateways: ArrayList<GatewayData?>) // class GatewayData
//
class GatewayData // class Point(var x: Int, var y: Int, var z: Int) {
// constructor(x: Int, z: Int) : this(x, 0, z) {}
class Point(var x: Int, var y: Int, var z: Int) { // }
constructor(x: Int, z: Int) : this(x, 0, z) {} //}
}
}

View File

@ -1,27 +1,27 @@
package nl.kallestruik.dtweaks.spacetimepockets //package nl.kallestruik.dtweaks.spacetimepockets
//
import org.bukkit.World //import org.bukkit.World
import org.bukkit.block.Biome //import org.bukkit.block.Biome
import org.bukkit.craftbukkit.v1_16_R3.generator.CraftChunkData //import org.bukkit.craftbukkit.v1_18_R1.generator.CraftChunkData
import org.bukkit.generator.ChunkGenerator //import org.bukkit.generator.ChunkGenerator
import java.util.* //import java.util.*
//
class SpaceTimePocketChunkGenerator: ChunkGenerator() { //class SpaceTimePocketChunkGenerator: ChunkGenerator() {
//
override fun generateChunkData( // override fun generateChunkData(
world: World, // world: World,
random: Random, // random: Random,
x: Int, // x: Int,
z: Int, // z: Int,
biome: BiomeGrid // biome: BiomeGrid
): ChunkData { // ): ChunkData {
for (cx in 0..15) { // for (cx in 0..15) {
for (cz in 0..15) { // for (cz in 0..15) {
for (cy in 0..264) { // for (cy in 0..264) {
biome.setBiome(cx, cy, cz, Biome.THE_VOID) // biome.setBiome(cx, cy, cz, Biome.THE_VOID)
} // }
} // }
} // }
return CraftChunkData(world) // return CraftChunkData(world)
} // }
} //}

View File

@ -15,8 +15,18 @@ class RedyeTerracotta(
private val blueRecipeKey = NamespacedKey(plugin, "blue_terracotta") private val blueRecipeKey = NamespacedKey(plugin, "blue_terracotta")
private val brownRecipeKey = NamespacedKey(plugin, "brown_terracotta") private val brownRecipeKey = NamespacedKey(plugin, "brown_terracotta")
private val cyanRecipeKey = NamespacedKey(plugin, "cyan_terracotta") private val cyanRecipeKey = NamespacedKey(plugin, "cyan_terracotta")
private val blueRecipeKey = NamespacedKey(plugin, "blue_terracotta") private val grayRecipeKey = NamespacedKey(plugin, "gray_terracotta")
private val blueRecipeKey = NamespacedKey(plugin, "blue_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, private val allTerracotta = RecipeChoice.MaterialChoice(Material.TERRACOTTA, Material.BLACK_TERRACOTTA,
Material.BLUE_TERRACOTTA, Material.BROWN_TERRACOTTA, Material.CYAN_TERRACOTTA, Material.GRAY_TERRACOTTA, Material.BLUE_TERRACOTTA, Material.BROWN_TERRACOTTA, Material.CYAN_TERRACOTTA, Material.GRAY_TERRACOTTA,
@ -30,10 +40,40 @@ class RedyeTerracotta(
override fun onEnable() { override fun onEnable() {
addRecipe(blackRecipeKey, Material.BLACK_TERRACOTTA, Material.BLACK_DYE) 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() { override fun onDisable() {
plugin.server.removeRecipe(blackRecipeKey) 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) { private fun addRecipe(key: NamespacedKey, output: Material, dye: Material) {

View File

@ -60,8 +60,11 @@ class DispensersCanPlantSaplings(
event.isCancelled = true event.isCancelled = true
val dispenserInventory = (event.block.state as org.bukkit.block.Dispenser).inventory val dispenserInventory = (event.block.state as org.bukkit.block.Dispenser).inventory
var slot = 0 var slot = 0
for (`is` in dispenserInventory.contents) { if (dispenserInventory.contents == null)
if (`is` != null && `is`.type == event.item.type) break return
for (item in dispenserInventory.contents!!) {
if (item != null && item.type == event.item.type) break
slot++ slot++
} }
val newItemStack = dispenserInventory.getItem(slot) val newItemStack = dispenserInventory.getItem(slot)

View File

@ -31,20 +31,22 @@ class ArmorStandArmorSwapping(
val standEquipment = armorStand.equipment val standEquipment = armorStand.equipment
val player = event.player val player = event.player
val playerEquipment = player.equipment val playerEquipment = player.equipment
if (standEquipment == null || playerEquipment == null) return
val playerHelmet = playerEquipment.helmet val playerHelmet = playerEquipment.helmet
val playerChestplate = playerEquipment.chestplate val playerChestplate = playerEquipment.chestplate
val playerLeggings = playerEquipment.leggings val playerLeggings = playerEquipment.leggings
val playerBoots = playerEquipment.boots val playerBoots = playerEquipment.boots
player.inventory.helmet = standEquipment.helmet player.inventory.helmet = standEquipment.helmet
player.inventory.chestplate = standEquipment.chestplate player.inventory.chestplate = standEquipment.chestplate
player.inventory.leggings = standEquipment.leggings player.inventory.leggings = standEquipment.leggings
player.inventory.boots = standEquipment.boots player.inventory.boots = standEquipment.boots
armorStand.setItem(EquipmentSlot.HEAD, playerHelmet) armorStand.setItem(EquipmentSlot.HEAD, playerHelmet)
armorStand.setItem(EquipmentSlot.CHEST, playerChestplate) armorStand.setItem(EquipmentSlot.CHEST, playerChestplate)
armorStand.setItem(EquipmentSlot.LEGS, playerLeggings) armorStand.setItem(EquipmentSlot.LEGS, playerLeggings)
armorStand.setItem(EquipmentSlot.FEET, playerBoots) armorStand.setItem(EquipmentSlot.FEET, playerBoots)
event.isCancelled = true event.isCancelled = true
} }
} }

View File

@ -1,15 +1,15 @@
package nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks //package nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks
//
import nl.kallestruik.dtweaks.managers.FakePlayerManager //import nl.kallestruik.dtweaks.managers.FakePlayerManager
import nl.kallestruik.dtweaks.tweaks.ITweak //import nl.kallestruik.dtweaks.tweaks.ITweak
//
class FakePlayers( //class FakePlayers(
private val fakePlayerManager: FakePlayerManager // private val fakePlayerManager: FakePlayerManager
): ITweak { //): ITweak {
override fun getIdentifier(): String = "FakePlayers" // override fun getIdentifier(): String = "FakePlayers"
override fun getCategories(): List<String> = listOf("players") // override fun getCategories(): List<String> = listOf("players")
//
override fun onDisable() { // override fun onDisable() {
fakePlayerManager.killAllFakePlayers() // fakePlayerManager.killAllFakePlayers()
} // }
} //}

View File

@ -1,70 +1,70 @@
package nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks //package nl.kallestruik.dtweaks.tweaks.miscellaneoustweaks
//
import nl.kallestruik.dtweaks.managers.PocketDimensionManager //import nl.kallestruik.dtweaks.managers.PocketDimensionManager
import nl.kallestruik.dtweaks.tweaks.ITweak //import nl.kallestruik.dtweaks.tweaks.ITweak
import org.bukkit.entity.Player //import org.bukkit.entity.Player
import org.bukkit.event.EventHandler //import org.bukkit.event.EventHandler
import org.bukkit.event.HandlerList //import org.bukkit.event.HandlerList
import org.bukkit.event.Listener //import org.bukkit.event.Listener
import org.bukkit.event.block.BlockBreakEvent //import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.entity.CreatureSpawnEvent //import org.bukkit.event.entity.CreatureSpawnEvent
import org.bukkit.event.entity.EntityDamageEvent //import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.player.PlayerMoveEvent //import org.bukkit.event.player.PlayerMoveEvent
import org.bukkit.plugin.java.JavaPlugin //import org.bukkit.plugin.java.JavaPlugin
//
class SpaceTimePockets( //class SpaceTimePockets(
private val plugin: JavaPlugin, // private val plugin: JavaPlugin,
private val pocketDimensionManager: PocketDimensionManager // private val pocketDimensionManager: PocketDimensionManager
): ITweak, Listener { //): ITweak, Listener {
override fun getIdentifier(): String = "SpaceTimePockets" // override fun getIdentifier(): String = "SpaceTimePockets"
override fun getCategories(): List<String> = listOf("miscellaneous", "survival") // override fun getCategories(): List<String> = listOf("miscellaneous", "survival")
//
override fun onRegister() { // override fun onRegister() {
plugin.server.pluginManager.registerEvents(this, plugin) // plugin.server.pluginManager.registerEvents(this, plugin)
} // }
//
override fun onUnRegister() { // override fun onUnRegister() {
HandlerList.unregisterAll(this) // HandlerList.unregisterAll(this)
} // }
//
//
@EventHandler // @EventHandler
fun onBlockBreak(event: BlockBreakEvent) { // fun onBlockBreak(event: BlockBreakEvent) {
if (event.player.world != pocketDimensionManager.pocketDimension) { // if (event.player.world != pocketDimensionManager.pocketDimension) {
return // return
} // }
if (event.block.location.chunk == event.player.location.chunk && event.block.y != 0 && event.block.y != 255) return // if (event.block.location.chunk == event.player.location.chunk && event.block.y != 0 && event.block.y != 255) return
event.isCancelled = true // 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.") // 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 // @EventHandler
fun onMobSpawn(event: CreatureSpawnEvent) { // fun onMobSpawn(event: CreatureSpawnEvent) {
if (pocketDimensionManager.pocketDimension != event.location.world) return // if (pocketDimensionManager.pocketDimension != event.location.world) return
event.isCancelled = true // event.isCancelled = true
} // }
//
@EventHandler // @EventHandler
fun onPlayerDamage(event: EntityDamageEvent) { // fun onPlayerDamage(event: EntityDamageEvent) {
if (event.entity !is Player) return // if (event.entity !is Player) return
if (pocketDimensionManager.pocketDimension != event.entity.world) return // if (pocketDimensionManager.pocketDimension != event.entity.world) return
event.isCancelled = true // event.isCancelled = true
} // }
//
@EventHandler // @EventHandler
fun onPlayerFall(event: PlayerMoveEvent) { // fun onPlayerFall(event: PlayerMoveEvent) {
if (pocketDimensionManager.pocketDimension != event.from.world // if (pocketDimensionManager.pocketDimension != event.from.world
|| pocketDimensionManager.pocketDimension != event.to.world // || pocketDimensionManager.pocketDimension != event.to.world
) return // ) return
if (event.from.chunk != event.to.chunk) { // if (event.from.chunk != event.to.chunk) {
event.player.sendMessage("Something pulls you back from the darkness.") // event.player.sendMessage("Something pulls you back from the darkness.")
event.isCancelled = true // event.isCancelled = true
} // }
if (event.to.blockY < 0 || event.to.blockY > 256) { // if (event.to.blockY < 0 || event.to.blockY > 256) {
event.player.sendMessage("Something pulls you back from the darkness.") // event.player.sendMessage("Something pulls you back from the darkness.")
val safeLocation = event.player.location // val safeLocation = event.player.location
safeLocation.y = 128.0 // safeLocation.y = 128.0
event.player.teleport(safeLocation) // event.player.teleport(safeLocation)
} // }
} // }
} //}

View File

@ -1,11 +1,10 @@
package nl.kallestruik.dtweaks.tweaks.mobtweaks package nl.kallestruik.dtweaks.tweaks.mobtweaks
import net.minecraft.server.v1_16_R3.Activity import net.minecraft.core.GlobalPos
import net.minecraft.server.v1_16_R3.EntityVillager import net.minecraft.world.entity.ai.memory.MemoryModuleType
import net.minecraft.server.v1_16_R3.GlobalPos import net.minecraft.world.entity.schedule.Activity
import net.minecraft.server.v1_16_R3.MemoryModuleType
import nl.kallestruik.dtweaks.tweaks.ITweak 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.entity.Villager
import org.bukkit.event.EventHandler import org.bukkit.event.EventHandler
import org.bukkit.event.HandlerList import org.bukkit.event.HandlerList
@ -32,42 +31,42 @@ class VillagerInfo(
fun onInteractEvent(event: PlayerInteractEntityEvent) { fun onInteractEvent(event: PlayerInteractEntityEvent) {
if (!event.player.isSneaking) return if (!event.player.isSneaking) return
val clicked = event.rightClicked as? Villager ?: 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<GlobalPos?> = AtomicReference(null) val homePos: AtomicReference<GlobalPos?> = AtomicReference(null)
eVillager.behaviorController.getMemory(MemoryModuleType.HOME) eVillager.brain.getMemory(MemoryModuleType.HOME)
.ifPresent { newValue -> homePos.set(newValue) } .ifPresent { newValue -> homePos.set(newValue) }
val workPos: AtomicReference<GlobalPos?> = AtomicReference(null) val workPos: AtomicReference<GlobalPos?> = AtomicReference(null)
eVillager.behaviorController.getMemory(MemoryModuleType.JOB_SITE).ifPresent { newValue -> eVillager.brain.getMemory(MemoryModuleType.JOB_SITE).ifPresent { newValue ->
workPos.set( workPos.set(
newValue newValue
) )
} }
val meetingPos: AtomicReference<GlobalPos?> = AtomicReference(null) val meetingPos: AtomicReference<GlobalPos?> = AtomicReference(null)
eVillager.behaviorController.getMemory(MemoryModuleType.MEETING_POINT).ifPresent { newValue -> eVillager.brain.getMemory(MemoryModuleType.MEETING_POINT).ifPresent { newValue ->
meetingPos.set( meetingPos.set(
newValue newValue
) )
} }
val lastWork: AtomicReference<Long?> = AtomicReference(null) val lastWork: AtomicReference<Long?> = AtomicReference(null)
eVillager.behaviorController.getMemory(MemoryModuleType.LAST_WORKED_AT_POI).ifPresent { newValue -> eVillager.brain.getMemory(MemoryModuleType.LAST_WORKED_AT_POI).ifPresent { newValue ->
lastWork.set( lastWork.set(
newValue newValue
) )
} }
val lastSleep: AtomicReference<Long?> = AtomicReference(null) val lastSleep: AtomicReference<Long?> = AtomicReference(null)
eVillager.behaviorController.getMemory(MemoryModuleType.LAST_SLEPT).ifPresent { newValue -> eVillager.brain.getMemory(MemoryModuleType.LAST_SLEPT).ifPresent { newValue ->
lastSleep.set( lastSleep.set(
newValue newValue
) )
} }
val seenIGRecently: AtomicReference<Boolean?> = AtomicReference(null) val seenIGRecently: AtomicReference<Boolean?> = AtomicReference(null)
eVillager.behaviorController.getMemory(MemoryModuleType.GOLEM_DETECTED_RECENTLY).ifPresent { newValue -> eVillager.brain.getMemory(MemoryModuleType.GOLEM_DETECTED_RECENTLY).ifPresent { newValue ->
seenIGRecently.set( seenIGRecently.set(
newValue newValue
) )
} }
val isPanicking: Boolean = eVillager.behaviorController.c(Activity.PANIC) val isPanicking: Boolean = eVillager.brain.isActive(Activity.PANIC)
val player = event.player val player = event.player
player.sendMessage("=====Villager Info=====") player.sendMessage("=====Villager Info=====")
@ -79,27 +78,27 @@ class VillagerInfo(
if (homePos.get() != null) player.sendMessage( if (homePos.get() != null) player.sendMessage(
java.lang.String.format( java.lang.String.format(
"Home: %s, %s, %s", "Home: %s, %s, %s",
homePos.get()?.blockPosition?.x, homePos.get()?.pos()?.x,
homePos.get()?.blockPosition?.y, homePos.get()?.pos()?.y,
homePos.get()?.blockPosition?.z homePos.get()?.pos()?.z
) )
) )
if (workPos.get() != null) player.sendMessage( if (workPos.get() != null) player.sendMessage(
java.lang.String.format( java.lang.String.format(
"Work: %s, %s, %s", "Work: %s, %s, %s",
workPos.get()?.blockPosition?.x, workPos.get()?.pos()?.x,
workPos.get()?.blockPosition?.y, workPos.get()?.pos()?.y,
workPos.get()?.blockPosition?.z workPos.get()?.pos()?.z
) )
) )
if (homePos.get() != null) player.sendMessage( if (homePos.get() != null) player.sendMessage(
java.lang.String.format( java.lang.String.format(
"Meeting point: %s, %s, %s", "Meeting point: %s, %s, %s",
meetingPos.get()?.blockPosition?.x, meetingPos.get()?.pos()?.x,
meetingPos.get()?.blockPosition?.y, meetingPos.get()?.pos()?.y,
meetingPos.get()?.blockPosition?.z meetingPos.get()?.pos()?.z
) )
) )