Compare commits

..

9 Commits
6.3.1 ... 6.3.3

Author SHA1 Message Date
Auxilor
60c3b58a33 Updated to 6.3.3 2021-08-10 18:19:46 +01:00
Auxilor
7216d0b09f Fixed component serialization 2021-08-10 18:18:09 +01:00
Auxilor
97eeea8d48 Updated to 6.3.2 2021-08-10 16:18:49 +01:00
Auxilor
82061ee6a3 Added get/set repair cost methods to FastItemStack 2021-08-09 17:30:09 +01:00
Auxilor
f274b9045e Being absolutely sure 2021-08-07 23:17:39 +01:00
Auxilor
2241a5c90f I'm actually going to die 2021-08-07 23:16:59 +01:00
Auxilor
bbc38ae801 Frantic-est fixing 2021-08-07 23:08:12 +01:00
Auxilor
e77346ed62 Even frantic-er fixing 2021-08-07 23:07:06 +01:00
Auxilor
6117abca56 Frantic fixing 2021-08-07 23:00:23 +01:00
8 changed files with 137 additions and 31 deletions

View File

@@ -47,6 +47,21 @@ public interface FastItemStack {
*/
List<String> getLore();
/**
* Set the rework penalty.
*
* @param cost The rework penalty to set.
*/
void setRepairCost(int cost);
/**
* Get the rework penalty.
*.
* @return The rework penalty found on the item.
*/
int getRepairCost();
/**
* Get the Bukkit ItemStack again.
*

View File

@@ -47,6 +47,15 @@ public class StringUtils {
.add(Pattern.compile("<#" + "([A-Fa-f0-9]{6})" + ">"))
.build();
/**
* Legacy serializer.
*/
private static final LegacyComponentSerializer LEGACY_COMPONENT_SERIALIZER = LegacyComponentSerializer.builder()
.character('\u00a7')
.useUnusualXRepeatedCharacterHexFormat()
.hexColors()
.build();
/**
* Format a list of strings - converts Placeholders and Color codes.
*
@@ -246,7 +255,7 @@ public class StringUtils {
public String legacyToJson(@NotNull final String legacy) {
return GsonComponentSerializer.gson().serialize(
Component.empty().decoration(TextDecoration.ITALIC, false).append(
LegacyComponentSerializer.legacySection().deserialize(legacy)
LEGACY_COMPONENT_SERIALIZER.deserialize(legacy)
)
);
}
@@ -258,7 +267,7 @@ public class StringUtils {
* @return The legacy string.
*/
public String jsonToLegacy(@NotNull final String json) {
return LegacyComponentSerializer.legacySection().serialize(
return LEGACY_COMPONENT_SERIALIZER.serialize(
GsonComponentSerializer.gson().deserialize(json)
);
}

View File

@@ -207,7 +207,8 @@ open class EcoYamlConfigWrapper<T : ConfigurationSection> : Config {
return if (cache.containsKey("$path\$FMT")) {
cache["$path\$FMT"] as List<String>
} else {
cache["$path\$FMT"] = StringUtils.formatList(if (has(path)) ArrayList(handle.getStringList(path)) else ArrayList<String>())
val list = if (has(path)) handle.getStringList(path) else ArrayList()
cache["$path\$FMT"] = StringUtils.formatList(list);
getStrings(path, true)
}
} else {

View File

@@ -0,0 +1,43 @@
package com.willfp.eco.proxy.v1_16_R3;
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.Validate;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
public class FastItemStackUtils {
private static final Field FIELD;
public static net.minecraft.server.v1_16_R3.ItemStack getNMSStack(@NotNull final ItemStack itemStack) {
if (!(itemStack instanceof CraftItemStack)) {
return CraftItemStack.asNMSCopy(itemStack);
} else {
try {
net.minecraft.server.v1_16_R3.ItemStack nms = (net.minecraft.server.v1_16_R3.ItemStack) FIELD.get(itemStack);
return nms == null ? CraftItemStack.asNMSCopy(itemStack) : nms;
} catch (ReflectiveOperationException e) {
e.printStackTrace();
return net.minecraft.server.v1_16_R3.ItemStack.b;
}
}
}
static {
Field temp = null;
try {
Field handleField = CraftItemStack.class.getDeclaredField("handle");
handleField.setAccessible(true);
temp = handleField;
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
assert temp != null;
Validate.notNull(temp, "Error occurred in initialization!");
FIELD = temp;
}
}

View File

@@ -1,6 +1,7 @@
package com.willfp.eco.proxy.v1_16_R3.fast
import com.willfp.eco.internal.fast.EcoFastItemStack
import com.willfp.eco.proxy.v1_16_R3.FastItemStackUtils
import com.willfp.eco.util.StringUtils
import net.minecraft.server.v1_16_R3.*
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack
@@ -11,7 +12,7 @@ import java.lang.reflect.Field
import kotlin.experimental.and
class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemStack<ItemStack>(
getNMSStack(itemStack)!!, itemStack
FastItemStackUtils.getNMSStack(itemStack), itemStack
) {
private var loreCache: List<String>? = null
override fun getEnchantmentsOnItem(checkStored: Boolean): Map<Enchantment, Int> {
@@ -95,6 +96,14 @@ class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemS
}
}
override fun getRepairCost(): Int {
return handle.repairCost;
}
override fun setRepairCost(cost: Int) {
handle.repairCost = cost;
}
private fun apply() {
if (bukkit !is CraftItemStack) {
bukkit.itemMeta = CraftItemStack.asCraftMirror(handle).itemMeta

View File

@@ -0,0 +1,45 @@
package com.willfp.eco.proxy.v1_17_R1;
import lombok.experimental.UtilityClass;
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.Validate;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
@UtilityClass
public class FastItemStackUtils {
private static final Field FIELD;
public static net.minecraft.world.item.ItemStack getNMSStack(@NotNull final ItemStack itemStack) {
if (!(itemStack instanceof CraftItemStack)) {
return CraftItemStack.asNMSCopy(itemStack);
} else {
try {
net.minecraft.world.item.ItemStack nms = (net.minecraft.world.item.ItemStack) FIELD.get(itemStack);
return nms == null ? CraftItemStack.asNMSCopy(itemStack) : nms;
} catch (ReflectiveOperationException e) {
e.printStackTrace();
return net.minecraft.world.item.ItemStack.EMPTY;
}
}
}
static {
Field temp = null;
try {
Field handleField = CraftItemStack.class.getDeclaredField("handle");
handleField.setAccessible(true);
temp = handleField;
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
assert temp != null;
Validate.notNull(temp, "Error occurred in initialization!");
FIELD = temp;
}
}

View File

@@ -1,6 +1,7 @@
package com.willfp.eco.proxy.v1_17_R1.fast
import com.willfp.eco.internal.fast.EcoFastItemStack
import com.willfp.eco.proxy.v1_17_R1.FastItemStackUtils
import com.willfp.eco.util.StringUtils
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.ListTag
@@ -12,11 +13,10 @@ import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack
import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers
import org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey
import org.bukkit.enchantments.Enchantment
import java.lang.reflect.Field
import kotlin.experimental.and
class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemStack<ItemStack>(
getNMSStack(itemStack)!!, itemStack
FastItemStackUtils.getNMSStack(itemStack), itemStack
) {
private var loreCache: List<String>? = null
@@ -115,33 +115,17 @@ class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemS
}
}
override fun getRepairCost(): Int {
return handle.baseRepairCost;
}
override fun setRepairCost(cost: Int) {
handle.setRepairCost(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
}
}
}
}

View File

@@ -1,2 +1,2 @@
version = 6.3.1
version = 6.3.3
plugin-name = eco