Skip to content

Commit

Permalink
Removed redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Aug 29, 2021
1 parent 3d07e10 commit fdd1581
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.bukkit.craftbukkit.v1_16_R3.util.CraftMagicNumbers
import org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey
import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemFlag
import java.lang.reflect.Field
import kotlin.experimental.and

class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemStack<ItemStack>(
Expand Down Expand Up @@ -145,40 +144,16 @@ class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemS
handle.orCreateTag.setInt("HideFlags", value)

override fun getRepairCost(): Int {
return handle.repairCost;
return handle.repairCost
}

override fun setRepairCost(cost: Int) {
handle.repairCost = cost;
handle.repairCost = cost
}

private fun apply() {
if (bukkit !is CraftItemStack) {
bukkit.itemMeta = CraftItemStack.asCraftMirror(handle).itemMeta
}
}

companion object {
private var field: Field

init {
lateinit var temp: Field
try {
val handleField = CraftItemStack::class.java.getDeclaredField("handle")
handleField.isAccessible = true
temp = handleField
} catch (e: ReflectiveOperationException) {
e.printStackTrace()
}
field = temp
}

fun getNMSStack(itemStack: org.bukkit.inventory.ItemStack): ItemStack? {
return if (itemStack !is CraftItemStack) {
CraftItemStack.asNMSCopy(itemStack)
} else {
field.get(itemStack) as ItemStack
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemS
handle.orCreateTag.putInt("HideFlags", value)

override fun getRepairCost(): Int {
return handle.baseRepairCost;
return handle.baseRepairCost
}

override fun setRepairCost(cost: Int) {
handle.setRepairCost(cost);
handle.setRepairCost(cost)
}

private fun apply() {
Expand Down

0 comments on commit fdd1581

Please sign in to comment.