Skip to content

Commit

Permalink
Merge pull request #416 from Shynixn/development
Browse files Browse the repository at this point in the history
Merge changes to master --release.
  • Loading branch information
Shynixn committed Oct 27, 2021
2 parents c28068e + 75093a6 commit 215d9e7
Show file tree
Hide file tree
Showing 18 changed files with 500 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ RUN ./gradlew build pluginJar --no-daemon
# 4. Launch a minecraft server with jdk16 and plugin
FROM adoptopenjdk/openjdk16
# Change to the current plugin version present in build.gradle
ENV PLUGIN_VERSION=6.26.0
ENV PLUGIN_VERSION=6.27.0
# Change to the server version you want to test.
ENV SERVER_VERSION=1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar
# Port of the Minecraft Server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ interface BallMeta {
*/
var enabledKick: Boolean

/**
* Optional nbt applied to the item of the ball. e.g. Skull.
*/
var itemNbt: String?

/**
* Is the rightclick passing the ball enabled?
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ interface Item {
* Item skin.
*/
var skin: String?
}

/**
* Optional nbt tags.
*/
var nbt: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.shynixn.blockball.api.business.enumeration.MaterialType
import com.github.shynixn.blockball.api.business.enumeration.Version
import com.github.shynixn.blockball.api.business.service.ItemTypeService
import com.github.shynixn.blockball.api.persistence.entity.Item
import com.github.shynixn.blockball.bukkit.logic.business.extension.findClazz
import com.github.shynixn.blockball.core.logic.business.extension.translateChatColors
import com.github.shynixn.blockball.core.logic.persistence.entity.ItemEntity
import com.google.inject.Inject
Expand Down Expand Up @@ -67,7 +68,11 @@ class ItemTypeServiceImpl @Inject constructor(private val version: Version) : It
* Converts the given item to an ItemStack.
*/
override fun <I> toItemStack(item: Item): I {
val itemStack = ItemStack(findItemType(item.type), 1, item.dataValue.toShort())
var itemStack = ItemStack(findItemType(item.type), 1, item.dataValue.toShort())

if (item.nbt != null) {
itemStack = parseNBTTags(itemStack, item.nbt!!)
}

if (itemStack.itemMeta != null) {
var currentMeta = itemStack.itemMeta
Expand Down Expand Up @@ -231,4 +236,95 @@ class ItemTypeServiceImpl @Inject constructor(private val version: Version) : It

throw IllegalArgumentException("Hint $sourceHint does not exist!")
}

private fun parseNBTTags(itemStack: ItemStack, nbtText: String): ItemStack {
if (version.isVersionSameOrGreaterThan(Version.VERSION_1_17_R1)) {
val nmsItemStackClass = findClazz("net.minecraft.world.item.ItemStack")
val craftItemStackClass = findClazz("org.bukkit.craftbukkit.VERSION.inventory.CraftItemStack")
val nmsCopyMethod = craftItemStackClass.getDeclaredMethod("asNMSCopy", ItemStack::class.java)
val nmsToBukkitMethod = craftItemStackClass.getDeclaredMethod("asBukkitCopy", nmsItemStackClass)

val nbtTagClass = findClazz("net.minecraft.nbt.NBTTagCompound")
val getNBTTag = nmsItemStackClass.getDeclaredMethod("getTag")
val setNBTTag = nmsItemStackClass.getDeclaredMethod("setTag", nbtTagClass)

val nmsItemStack = nmsCopyMethod.invoke(null, itemStack)
var targetNbtTag = getNBTTag.invoke(nmsItemStack)

if (targetNbtTag == null) {
targetNbtTag = nbtTagClass.newInstance()
}

val compoundMapField = nbtTagClass.getDeclaredField("x")
compoundMapField.isAccessible = true
val targetNbtMap = compoundMapField.get(targetNbtTag) as MutableMap<Any?, Any?>

try {
val sourceNbtTag = findClazz(
"net.minecraft.nbt.MojangsonParser"
)
.getDeclaredMethod("parse", String::class.java).invoke(null, nbtText)
val sourceNbtMap = compoundMapField.get(sourceNbtTag) as MutableMap<Any?, Any?>

for (key in sourceNbtMap.keys) {
targetNbtMap[key] = sourceNbtMap[key]
}

setNBTTag.invoke(nmsItemStack, targetNbtTag)
} catch (e: Exception) {
e.printStackTrace()
}

return nmsToBukkitMethod.invoke(null, nmsItemStack) as ItemStack
} else {
val nmsItemStackClass =
Class.forName("net.minecraft.server.VERSION.ItemStack".replace("VERSION", version.bukkitId))
val craftItemStackClass =
Class.forName(
"org.bukkit.craftbukkit.VERSION.inventory.CraftItemStack".replace(
"VERSION",
version.bukkitId
)
)
val nmsCopyMethod = craftItemStackClass.getDeclaredMethod("asNMSCopy", ItemStack::class.java)
val nmsToBukkitMethod = craftItemStackClass.getDeclaredMethod("asBukkitCopy", nmsItemStackClass)

val nbtTagClass =
Class.forName("net.minecraft.server.VERSION.NBTTagCompound".replace("VERSION", version.bukkitId))
val getNBTTag = nmsItemStackClass.getDeclaredMethod("getTag")
val setNBTTag = nmsItemStackClass.getDeclaredMethod("setTag", nbtTagClass)

val nmsItemStack = nmsCopyMethod.invoke(null, itemStack)
var targetNbtTag = getNBTTag.invoke(nmsItemStack)

if (targetNbtTag == null) {
targetNbtTag = nbtTagClass.newInstance()
}

val compoundMapField = nbtTagClass.getDeclaredField("map")
compoundMapField.isAccessible = true
val targetNbtMap = compoundMapField.get(targetNbtTag) as MutableMap<Any?, Any?>

try {
val sourceNbtTag = Class.forName(
"net.minecraft.server.VERSION.MojangsonParser".replace(
"VERSION",
version.bukkitId
)
)
.getDeclaredMethod("parse", String::class.java).invoke(null, nbtText)
val sourceNbtMap = compoundMapField.get(sourceNbtTag) as MutableMap<Any?, Any?>

for (key in sourceNbtMap.keys) {
targetNbtMap[key] = sourceNbtMap[key]
}

setNBTTag.invoke(nmsItemStack, targetNbtTag)
} catch (e: Exception) {
e.printStackTrace()
}

return nmsToBukkitMethod.invoke(null, nmsItemStack) as ItemStack
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ class RayTracingService113R2Impl : RayTracingService {
val sourceLocation = position.toLocation()

val directionVector = motion.toVector().normalize()
val distance = motion.length()
var distance = motion.length()
val world = sourceLocation.world!!

sourceLocation.x = fixFiniteDomain(sourceLocation.x)
sourceLocation.y = fixFiniteDomain(sourceLocation.y)
sourceLocation.z = fixFiniteDomain(sourceLocation.z)
sourceLocation.yaw = fixFiniteDomain(sourceLocation.yaw.toDouble()).toFloat()
sourceLocation.pitch = fixFiniteDomain(sourceLocation.pitch.toDouble()).toFloat()
directionVector.x = fixFiniteDomain(directionVector.x)
directionVector.y = fixFiniteDomain(directionVector.y)
directionVector.z = fixFiniteDomain(directionVector.z)
distance = fixFiniteDomain(distance)

val movingObjectPosition =
world.rayTraceBlocks(sourceLocation, directionVector, distance, FluidCollisionMode.NEVER, false)

Expand Down
2 changes: 1 addition & 1 deletion blockball-bukkit-plugin/src/main/resources/plugin-1.17.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: BlockBall
version: 6.26.0
version: 6.27.0
author: Shynixn
website: https://www.spigotmc.org/members/shynixn.63455/
main: com.github.shynixn.blockball.bukkit.BlockBallPlugin
Expand Down
2 changes: 1 addition & 1 deletion blockball-bukkit-plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: BlockBall
version: 6.26.0
version: 6.27.0
author: Shynixn
website: https://www.spigotmc.org/members/shynixn.63455/
main: com.github.shynixn.blockball.bukkit.BlockBallPlugin
Expand Down

0 comments on commit 215d9e7

Please sign in to comment.