Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c69bb6904f | ||
|
|
9f193b7206 | ||
|
|
6fce2c13fe | ||
|
|
02342c11a6 | ||
|
|
2fde56df0d | ||
|
|
cb64dedd74 | ||
|
|
a7c489413e | ||
|
|
f9ed174e31 | ||
|
|
496d878a14 | ||
|
|
00853d4a92 | ||
|
|
5eb0d2380a | ||
|
|
d19cff9a42 | ||
|
|
234b5fdd8e | ||
|
|
2dbe6c7fe4 | ||
|
|
9d4d1ace08 | ||
|
|
364550d228 | ||
|
|
d5e8cbaf33 | ||
|
|
c4d532fda9 | ||
|
|
aa097cf7e2 | ||
|
|
6f4ca40a94 | ||
|
|
2ef9b4033c | ||
|
|
9aa22ffc86 | ||
|
|
d81c1e6fcb | ||
|
|
ac72e0770a | ||
|
|
5e3e09c4bc | ||
|
|
ee945d5901 | ||
|
|
7f747f3afc | ||
|
|
2d47593f51 | ||
|
|
df529ba239 |
@@ -4,7 +4,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ plugins {
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
id("maven-publish")
|
||||
id("java")
|
||||
kotlin("jvm") version "1.6.10"
|
||||
kotlin("jvm") version "1.6.21"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -71,9 +71,6 @@ allprojects {
|
||||
// CombatLogX
|
||||
maven("https://nexus.sirblobman.xyz/repository/public/")
|
||||
|
||||
// IridiumSkyblock
|
||||
maven("https://nexus.iridiumdevelopment.net/repository/maven-releases/")
|
||||
|
||||
// MythicMobs
|
||||
maven("https://mvn.lumine.io/repository/maven-public/")
|
||||
|
||||
@@ -85,21 +82,25 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(kotlin("stdlib", version = "1.6.10"))
|
||||
// Included in spigot jar, no need to move to implementation
|
||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||
compileOnly("com.google.guava:guava:31.1-jre")
|
||||
|
||||
// Test
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
|
||||
|
||||
|
||||
// Adventure
|
||||
compileOnly("net.kyori:adventure-api:4.10.0")
|
||||
compileOnly("net.kyori:adventure-text-serializer-gson:4.10.0")
|
||||
compileOnly("net.kyori:adventure-text-serializer-legacy:4.10.0")
|
||||
implementation("net.kyori:adventure-api:4.10.1")
|
||||
implementation("net.kyori:adventure-text-serializer-gson:4.10.1") {
|
||||
exclude("com.google.code.gson", "gson") // Prevent shading into the jar
|
||||
}
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:4.10.1")
|
||||
|
||||
// Other
|
||||
compileOnly("com.google.guava:guava:31.1-jre")
|
||||
compileOnly("com.github.ben-manes.caffeine:caffeine:3.0.5")
|
||||
implementation("com.github.ben-manes.caffeine:caffeine:3.0.6")
|
||||
implementation("org.apache.maven:maven-artifact:3.8.4")
|
||||
implementation(kotlin("stdlib", version = "1.6.21"))
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
@@ -115,10 +116,11 @@ allprojects {
|
||||
exclude(group = "com.darkblade12", module = "particleeffect")
|
||||
exclude(group = "com.github.cryptomorin", module = "XSeries")
|
||||
exclude(group = "net.wesjd", module = "anvilgui")
|
||||
exclude(group = "org.slf4j", module = "slf4j-api")
|
||||
}
|
||||
|
||||
configurations.testImplementation {
|
||||
setExtendsFrom(listOf(configurations.compileOnly.get()))
|
||||
setExtendsFrom(listOf(configurations.compileOnly.get(), configurations.implementation.get()))
|
||||
}
|
||||
|
||||
tasks {
|
||||
@@ -133,6 +135,28 @@ allprojects {
|
||||
shadowJar {
|
||||
relocate("org.bstats", "com.willfp.eco.libs.bstats")
|
||||
relocate("redempt.crunch", "com.willfp.eco.libs.crunch")
|
||||
relocate("org.apache.commons.lang3", "com.willfp.eco.libs.lang3")
|
||||
relocate("org.apache.maven", "com.willfp.eco.libs.maven")
|
||||
relocate("org.checkerframework", "com.willfp.eco.libs.checkerframework")
|
||||
relocate("org.intellij", "com.willfp.eco.libs.intellij")
|
||||
relocate("org.jetbrains.annotations", "com.willfp.eco.libs.jetbrains.annotations")
|
||||
//relocate("org.jetbrains.exposed", "com.willfp.eco.libs.exposed")
|
||||
relocate("org.objenesis", "com.willfp.eco.libs.objenesis")
|
||||
relocate("org.reflections", "com.willfp.eco.libs.reflections")
|
||||
relocate("javassist", "com.willfp.eco.libs.javassist")
|
||||
relocate("javax.annotation", "com.willfp.eco.libs.annotation")
|
||||
relocate("com.google.errorprone", "com.willfp.eco.libs.errorprone")
|
||||
relocate("com.google.j2objc", "com.willfp.eco.libs.j2objc")
|
||||
relocate("com.google.thirdparty", "com.willfp.eco.libs.google.thirdparty")
|
||||
relocate("com.google.protobuf", "com.willfp.eco.libs.google.protobuf") // No I don't know either
|
||||
relocate("google.protobuf", "com.willfp.eco.libs.protobuf") // Still don't know
|
||||
relocate("com.zaxxer.hikari", "com.willfp.eco.libs.hikari")
|
||||
//relocate("com.mysql", "com.willfp.eco.libs.mysql")
|
||||
|
||||
/*
|
||||
Kotlin and caffeine are not shaded so that they can be accessed directly by eco plugins.
|
||||
Also, not relocating adventure, because it's a pain in the ass, and it doesn't *seem* to be causing loader constraint violations.
|
||||
*/
|
||||
}
|
||||
|
||||
compileJava {
|
||||
|
||||
@@ -4,7 +4,6 @@ dependencies {
|
||||
|
||||
// Other
|
||||
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.apache.maven:maven-artifact:3.8.1'
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.1-SNAPSHOT'
|
||||
compileOnly 'com.google.code.gson:gson:2.8.8'
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
|
||||
if (!(currentVersion.compareTo(mostRecentVersion) > 0 || currentVersion.equals(mostRecentVersion))) {
|
||||
this.outdated = true;
|
||||
this.getLogger().warning(this.getName() + " is out of date! (Version " + this.getDescription().getVersion() + ")");
|
||||
this.getLogger().warning("The newest version is &f" + version);
|
||||
this.getLogger().warning("The newest version is " + version);
|
||||
this.getLogger().warning("Download the new version!");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.willfp.eco.core.fast;
|
||||
|
||||
import com.willfp.eco.core.Eco;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -16,7 +19,7 @@ import java.util.Set;
|
||||
/**
|
||||
* FastItemStack contains methods to modify and read items faster than in default bukkit.
|
||||
*/
|
||||
public interface FastItemStack {
|
||||
public interface FastItemStack extends PersistentDataHolder {
|
||||
/**
|
||||
* Get all enchantments on an item.
|
||||
*
|
||||
@@ -45,17 +48,54 @@ public interface FastItemStack {
|
||||
* @param checkStored If stored enchantments should be accounted for.
|
||||
* @return A map of all enchantments.
|
||||
*/
|
||||
@NotNull
|
||||
Map<Enchantment, Integer> getEnchants(boolean checkStored);
|
||||
|
||||
/**
|
||||
* Get the level of an enchantment on an item.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @return The enchantment level, or 0 if not found.
|
||||
* @deprecated Poorly named method. Use getEnchantmentLevel instead.
|
||||
*/
|
||||
@Deprecated(since = "6.34.0", forRemoval = true)
|
||||
default int getLevelOnItem(@NotNull Enchantment enchantment) {
|
||||
return getEnchantmentLevel(enchantment, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level of an enchantment on an item.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @param checkStored If the stored NBT should also be checked.
|
||||
* @return The enchantment level, or 0 if not found.
|
||||
* @deprecated Poorly named method. Use getEnchantmentLevel instead.
|
||||
*/
|
||||
int getLevelOnItem(@NotNull Enchantment enchantment,
|
||||
boolean checkStored);
|
||||
@Deprecated(since = "6.34.0", forRemoval = true)
|
||||
default int getLevelOnItem(@NotNull Enchantment enchantment,
|
||||
boolean checkStored) {
|
||||
return getEnchantmentLevel(enchantment, checkStored);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level of an enchantment.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @return The enchantment level, or 0 if not found.
|
||||
*/
|
||||
default int getEnchantmentLevel(@NotNull Enchantment enchantment) {
|
||||
return getLevelOnItem(enchantment, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level of an enchantment.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @param checkStored If the stored NBT should also be checked.
|
||||
* @return The enchantment level, or 0 if not found.
|
||||
*/
|
||||
int getEnchantmentLevel(@NotNull Enchantment enchantment,
|
||||
boolean checkStored);
|
||||
|
||||
/**
|
||||
* Set the item lore.
|
||||
@@ -64,6 +104,13 @@ public interface FastItemStack {
|
||||
*/
|
||||
void setLore(@Nullable List<String> lore);
|
||||
|
||||
/**
|
||||
* Set the item lore.
|
||||
*
|
||||
* @param lore The lore.
|
||||
*/
|
||||
void setLoreComponents(@Nullable List<Component> lore);
|
||||
|
||||
/**
|
||||
* Get the item lore.
|
||||
*
|
||||
@@ -71,6 +118,40 @@ public interface FastItemStack {
|
||||
*/
|
||||
List<String> getLore();
|
||||
|
||||
/**
|
||||
* Get the item lore.
|
||||
*
|
||||
* @return The lore.
|
||||
*/
|
||||
List<Component> getLoreComponents();
|
||||
|
||||
/**
|
||||
* Set the item name.
|
||||
*
|
||||
* @param name The name.
|
||||
*/
|
||||
void setDisplayName(@Nullable Component name);
|
||||
|
||||
/**
|
||||
* Set the item name.
|
||||
*
|
||||
* @param name The name.
|
||||
*/
|
||||
void setDisplayName(@Nullable String name);
|
||||
|
||||
/**
|
||||
* Get the item display name.
|
||||
*
|
||||
* @return The display name.
|
||||
*/
|
||||
Component getDisplayNameComponent();
|
||||
|
||||
/**
|
||||
* Get the item display name.
|
||||
*
|
||||
* @return The display name.
|
||||
*/
|
||||
String getDisplayName();
|
||||
|
||||
/**
|
||||
* Set the rework penalty.
|
||||
@@ -81,7 +162,6 @@ public interface FastItemStack {
|
||||
|
||||
/**
|
||||
* Get the rework penalty.
|
||||
* .
|
||||
*
|
||||
* @return The rework penalty found on the item.
|
||||
*/
|
||||
@@ -116,11 +196,28 @@ public interface FastItemStack {
|
||||
*/
|
||||
boolean hasItemFlag(@NotNull ItemFlag flag);
|
||||
|
||||
/**
|
||||
* Get the base NBT tag (Not PublicBukkitValues, the base) as a PersistentDataContainer.
|
||||
* <p>
|
||||
* The returned PersistentDataContainer will not modify the item until the tag is set.
|
||||
*
|
||||
* @return The base NBT tag.
|
||||
*/
|
||||
PersistentDataContainer getBaseTag();
|
||||
|
||||
/**
|
||||
* Set the base NBT tag (Not PublicBukkitValues, the base) from a PersistentDataContainer.
|
||||
*
|
||||
* @param container The PersistentDataContainer.
|
||||
*/
|
||||
void setBaseTag(@Nullable PersistentDataContainer container);
|
||||
|
||||
/**
|
||||
* Get the Bukkit ItemStack again.
|
||||
*
|
||||
* @return The ItemStack.
|
||||
*/
|
||||
@NotNull
|
||||
ItemStack unwrap();
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,6 +34,17 @@ public final class CustomItemsManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all the custom items for a specific plugin into eco.
|
||||
*
|
||||
* @see com.willfp.eco.core.items.Items
|
||||
*/
|
||||
public static void registerProviders() {
|
||||
for (CustomItemsWrapper customItemsWrapper : REGISTERED) {
|
||||
customItemsWrapper.registerProvider();
|
||||
}
|
||||
}
|
||||
|
||||
private CustomItemsManager() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
@@ -11,5 +11,14 @@ public interface CustomItemsWrapper extends Integration {
|
||||
*
|
||||
* @see com.willfp.eco.core.items.Items
|
||||
*/
|
||||
void registerAllItems();
|
||||
default void registerAllItems() {
|
||||
// Override when needed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Register {@link com.willfp.eco.core.items.provider.ItemProvider}s.
|
||||
*/
|
||||
default void registerProvider() {
|
||||
// Override when needed.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.core.items;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.willfp.eco.core.fast.FastItemStack;
|
||||
import com.willfp.eco.core.items.args.LookupArgParser;
|
||||
import com.willfp.eco.core.items.provider.ItemProvider;
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
||||
@@ -13,8 +14,10 @@ import com.willfp.eco.util.NamespacedKeyUtils;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -430,6 +433,90 @@ public final class Items {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge ItemStack onto another ItemStack.
|
||||
*
|
||||
* @param from The ItemStack to merge from.
|
||||
* @param to The ItemStack to merge onto.
|
||||
* @return The ItemStack, merged (same instance as to).
|
||||
*/
|
||||
@NotNull
|
||||
public static ItemStack mergeFrom(@NotNull final ItemStack from,
|
||||
@NotNull final ItemStack to) {
|
||||
ItemMeta fromMeta = from.getItemMeta();
|
||||
ItemMeta toMeta = to.getItemMeta();
|
||||
|
||||
if (fromMeta == null || toMeta == null) {
|
||||
return to;
|
||||
}
|
||||
|
||||
ItemMeta newMeta = mergeFrom(fromMeta, toMeta);
|
||||
|
||||
to.setItemMeta(newMeta);
|
||||
to.setType(from.getType());
|
||||
to.setAmount(from.getAmount());
|
||||
return to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge ItemMeta onto other ItemMeta.
|
||||
*
|
||||
* @param from The ItemMeta to merge from.
|
||||
* @param to The ItemMeta to merge onto.
|
||||
* @return The ItemMeta, merged (same instance as to).
|
||||
*/
|
||||
@NotNull
|
||||
public static ItemMeta mergeFrom(@NotNull final ItemMeta from,
|
||||
@NotNull final ItemMeta to) {
|
||||
if (from.hasDisplayName()) {
|
||||
to.setDisplayName(from.getDisplayName());
|
||||
}
|
||||
|
||||
to.setLore(from.getLore());
|
||||
|
||||
for (Enchantment enchant : to.getEnchants().keySet()) {
|
||||
to.removeEnchant(enchant);
|
||||
}
|
||||
|
||||
for (Map.Entry<Enchantment, Integer> entry : from.getEnchants().entrySet()) {
|
||||
to.addEnchant(entry.getKey(), entry.getValue(), true);
|
||||
}
|
||||
|
||||
if (from.hasCustomModelData()) {
|
||||
to.setCustomModelData(from.getCustomModelData());
|
||||
} else {
|
||||
to.setCustomModelData(null);
|
||||
}
|
||||
|
||||
return to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base NBT tag on an item.
|
||||
*
|
||||
* @param itemStack The ItemStack.
|
||||
* @return The base NBT.
|
||||
*/
|
||||
@NotNull
|
||||
public static PersistentDataContainer getBaseNBT(@NotNull final ItemStack itemStack) {
|
||||
return FastItemStack.wrap(itemStack).getBaseTag();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base NBT tag on an item.
|
||||
*
|
||||
* @param itemStack The ItemStack.
|
||||
* @param container The base NBT tag.
|
||||
* @return The ItemStack, modified. Not required to use, as this modifies the instance.¬
|
||||
*/
|
||||
@NotNull
|
||||
public static ItemStack setBaseNBT(@NotNull final ItemStack itemStack,
|
||||
@Nullable final PersistentDataContainer container) {
|
||||
FastItemStack fis = FastItemStack.wrap(itemStack);
|
||||
fis.setBaseTag(container);
|
||||
return fis.unwrap();
|
||||
}
|
||||
|
||||
private Items() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -76,33 +77,37 @@ public final class StringUtils {
|
||||
.build(StringUtils::processFormatting);
|
||||
|
||||
/**
|
||||
* Json -> Legacy Cache.
|
||||
* Json -> Component Cache.
|
||||
*/
|
||||
private static final LoadingCache<String, String> JSON_TO_LEGACY = Caffeine.newBuilder()
|
||||
private static final Cache<String, Component> JSON_TO_COMPONENT = Caffeine.newBuilder()
|
||||
.expireAfterAccess(10, TimeUnit.SECONDS)
|
||||
.build(
|
||||
json -> {
|
||||
try {
|
||||
Component component = GSON_COMPONENT_SERIALIZER.deserialize(json);
|
||||
return LEGACY_COMPONENT_SERIALIZER.serialize(component);
|
||||
} catch (JsonSyntaxException e) {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
);
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Legacy -> Json Cache.
|
||||
* Component -> Json Cache.
|
||||
*/
|
||||
private static final LoadingCache<String, String> LEGACY_TO_JSON = Caffeine.newBuilder()
|
||||
private static final Cache<Component, String> COMPONENT_TO_JSON = Caffeine.newBuilder()
|
||||
.expireAfterAccess(10, TimeUnit.SECONDS)
|
||||
.build(
|
||||
legacy -> GSON_COMPONENT_SERIALIZER.serialize(
|
||||
Component.empty().decoration(TextDecoration.ITALIC, false).append(
|
||||
LEGACY_COMPONENT_SERIALIZER.deserialize(legacy)
|
||||
)
|
||||
)
|
||||
);
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Legacy -> Component Cache.
|
||||
*/
|
||||
private static final Cache<String, Component> LEGACY_TO_COMPONENT = Caffeine.newBuilder()
|
||||
.expireAfterAccess(10, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Component -> Legacy Cache.
|
||||
*/
|
||||
private static final Cache<Component, String> COMPONENT_TO_LEGACY = Caffeine.newBuilder()
|
||||
.expireAfterAccess(10, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Empty JSON.
|
||||
*/
|
||||
private static final String EMPTY_JSON = GSON_COMPONENT_SERIALIZER.serialize(Component.empty());
|
||||
|
||||
/**
|
||||
* Color map.
|
||||
@@ -483,12 +488,7 @@ public final class StringUtils {
|
||||
*/
|
||||
@NotNull
|
||||
public static String legacyToJson(@Nullable final String legacy) {
|
||||
String processed = legacy;
|
||||
if (legacy == null) {
|
||||
processed = "";
|
||||
}
|
||||
|
||||
return LEGACY_TO_JSON.get(processed);
|
||||
return componentToJson(toComponent(legacy));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -499,11 +499,53 @@ public final class StringUtils {
|
||||
*/
|
||||
@NotNull
|
||||
public static String jsonToLegacy(@Nullable final String json) {
|
||||
if (json == null || json.isEmpty()) {
|
||||
return "";
|
||||
return toLegacy(jsonToComponent(json));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Component to JSON String.
|
||||
*
|
||||
* @param component The Component.
|
||||
* @return The JSON string.
|
||||
*/
|
||||
@NotNull
|
||||
public static String componentToJson(@Nullable final Component component) {
|
||||
if (component == null) {
|
||||
return EMPTY_JSON;
|
||||
}
|
||||
|
||||
return JSON_TO_LEGACY.get(json);
|
||||
return COMPONENT_TO_JSON.get(component, it -> {
|
||||
try {
|
||||
return GSON_COMPONENT_SERIALIZER.serialize(
|
||||
Component.empty().decoration(TextDecoration.ITALIC, false).append(
|
||||
it
|
||||
)
|
||||
);
|
||||
} catch (JsonSyntaxException e) {
|
||||
return GSON_COMPONENT_SERIALIZER.serialize(Component.empty());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert JSON String to Component.
|
||||
*
|
||||
* @param json The JSON String.
|
||||
* @return The component.
|
||||
*/
|
||||
@NotNull
|
||||
public static Component jsonToComponent(@Nullable final String json) {
|
||||
if (json == null || json.isEmpty()) {
|
||||
return Component.empty();
|
||||
}
|
||||
|
||||
return JSON_TO_COMPONENT.get(json, it -> {
|
||||
try {
|
||||
return GSON_COMPONENT_SERIALIZER.deserialize(it);
|
||||
} catch (JsonSyntaxException e) {
|
||||
return Component.empty();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,12 +556,7 @@ public final class StringUtils {
|
||||
*/
|
||||
@NotNull
|
||||
public static Component toComponent(@Nullable final String legacy) {
|
||||
String processed = legacy;
|
||||
if (legacy == null) {
|
||||
processed = "";
|
||||
}
|
||||
|
||||
return LEGACY_COMPONENT_SERIALIZER.deserialize(processed);
|
||||
return LEGACY_TO_COMPONENT.get(legacy == null ? "" : legacy, LEGACY_COMPONENT_SERIALIZER::deserialize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -530,7 +567,7 @@ public final class StringUtils {
|
||||
*/
|
||||
@NotNull
|
||||
public static String toLegacy(@NotNull final Component component) {
|
||||
return LEGACY_COMPONENT_SERIALIZER.serialize(component);
|
||||
return COMPONENT_TO_LEGACY.get(component, LEGACY_COMPONENT_SERIALIZER::serialize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,9 +3,39 @@
|
||||
package com.willfp.eco.core.items
|
||||
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
|
||||
/**
|
||||
* @see Items.toLookupString
|
||||
*/
|
||||
fun ItemStack?.toLookupString(): String =
|
||||
Items.toLookupString(this)
|
||||
|
||||
/**
|
||||
* @see Items.mergeFrom
|
||||
*/
|
||||
fun ItemStack.mergeFrom(other: ItemStack): ItemStack =
|
||||
Items.mergeFrom(other, this)
|
||||
|
||||
/**
|
||||
* @see Items.mergeFrom
|
||||
*/
|
||||
fun ItemMeta.mergeFrom(other: ItemMeta): ItemMeta =
|
||||
Items.mergeFrom(other, this)
|
||||
|
||||
/**
|
||||
* @see Items.getBaseNBT
|
||||
* @see Items.setBaseNBT
|
||||
*/
|
||||
var ItemStack.baseNBT: PersistentDataContainer
|
||||
get() = Items.getBaseNBT(this)
|
||||
set(value) {
|
||||
Items.setBaseNBT(this, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Items.setBaseNBT
|
||||
*/
|
||||
fun ItemStack.clearNBT() =
|
||||
Items.setBaseNBT(this, null)
|
||||
|
||||
@@ -11,12 +11,24 @@ import org.bukkit.entity.Player
|
||||
fun String.toComponent(): Component =
|
||||
StringUtils.toComponent(this)
|
||||
|
||||
/**
|
||||
* @see StringUtils.jsonToComponent
|
||||
*/
|
||||
fun String.jsonToComponent(): Component =
|
||||
StringUtils.jsonToComponent(this)
|
||||
|
||||
/**
|
||||
* @see StringUtils.toLegacy
|
||||
*/
|
||||
fun Component.toLegacy(): String =
|
||||
StringUtils.toLegacy(this)
|
||||
|
||||
/**
|
||||
* @see StringUtils.componentToJson
|
||||
*/
|
||||
fun Component.toJSON(): String =
|
||||
StringUtils.componentToJson(this)
|
||||
|
||||
/**
|
||||
* @see StringUtils.format
|
||||
*/
|
||||
|
||||
@@ -2,10 +2,12 @@ group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
// Libraries
|
||||
implementation 'org.reflections:reflections:0.9.12'
|
||||
implementation 'org.objenesis:objenesis:3.2'
|
||||
|
||||
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.10'
|
||||
compileOnly 'org.reflections:reflections:0.9.12'
|
||||
compileOnly 'net.kyori:adventure-text-minimessage:4.10.0'
|
||||
compileOnly 'net.kyori:adventure-platform-bukkit:4.1.0'
|
||||
compileOnly 'org.objenesis:objenesis:3.2'
|
||||
}
|
||||
@@ -4,12 +4,17 @@ import com.willfp.eco.core.entities.ai.EntityGoal
|
||||
import com.willfp.eco.core.entities.ai.TargetGoal
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.EntityGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.TargetGoalFactory
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.item.Item
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.entity.Mob
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
|
||||
private lateinit var impl: CommonsProvider
|
||||
|
||||
@@ -39,9 +44,27 @@ fun <T : EntityGoal<*>> T.getVersionSpecificEntityGoalFactory(): EntityGoalFacto
|
||||
fun <T : TargetGoal<*>> T.getVersionSpecificEntityGoalFactory(): TargetGoalFactory<T>? =
|
||||
impl.getVersionSpecificTargetGoalFactory(this)
|
||||
|
||||
private val MATERIAL_TO_ITEM = mutableMapOf<Material, Item>()
|
||||
|
||||
fun Material.toItem(): Item =
|
||||
MATERIAL_TO_ITEM.getOrPut(this) {
|
||||
Registry.ITEM.getOptional(this.key.toResourceLocation())
|
||||
.orElseThrow { IllegalArgumentException("Material is not item!") }
|
||||
}
|
||||
|
||||
fun CompoundTag.makePdc(base: Boolean = false): PersistentDataContainer =
|
||||
impl.makePdc(this, base)
|
||||
|
||||
fun CompoundTag.setPdc(pdc: PersistentDataContainer?, item: net.minecraft.world.item.ItemStack? = null) =
|
||||
impl.setPdc(this, pdc, item)
|
||||
|
||||
interface CommonsProvider {
|
||||
val nbtTagString: Int
|
||||
|
||||
fun makePdc(tag: CompoundTag, base: Boolean): PersistentDataContainer
|
||||
|
||||
fun setPdc(tag: CompoundTag, pdc: PersistentDataContainer?, item: net.minecraft.world.item.ItemStack? = null)
|
||||
|
||||
fun toPathfinderMob(mob: Mob): PathfinderMob?
|
||||
|
||||
fun toResourceLocation(namespacedKey: NamespacedKey): ResourceLocation
|
||||
|
||||
@@ -10,9 +10,6 @@ import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
import net.minecraft.world.entity.ai.goal.TemptGoal
|
||||
import net.minecraft.world.entity.ai.targeting.TargetingConditions
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity
|
||||
import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory
|
||||
import org.bukkit.event.entity.EntityTargetEvent
|
||||
import java.util.EnumSet
|
||||
import kotlin.math.abs
|
||||
|
||||
@@ -57,19 +54,6 @@ class EnhancedTemptGoal(
|
||||
false
|
||||
} else {
|
||||
player = mob.level.getNearestPlayer(targetingConditions, mob as LivingEntity)
|
||||
// CraftBukkit start
|
||||
if (player != null) {
|
||||
val event = CraftEventFactory.callEntityTargetLivingEvent(
|
||||
mob,
|
||||
player,
|
||||
EntityTargetEvent.TargetReason.TEMPT
|
||||
)
|
||||
if (event.isCancelled) {
|
||||
return false
|
||||
}
|
||||
player = if (event.target == null) null else (event.target as CraftLivingEntity?)!!.handle
|
||||
}
|
||||
// CraftBukkit end
|
||||
player != null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.minecraft.world.entity.EntityType
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
import net.minecraft.world.entity.monster.SpellcasterIllager
|
||||
import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class DelegatedSpellcaster(private val handle: SpellcasterIllager) : SpellcasterIllager(
|
||||
@@ -66,15 +65,6 @@ abstract class OpenUseSpellGoal(
|
||||
override fun tick() {
|
||||
--attackWarmupDelay
|
||||
if (attackWarmupDelay == 0) {
|
||||
// CraftBukkit start
|
||||
if (!CraftEventFactory.handleEntitySpellCastEvent(
|
||||
handle,
|
||||
spell
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
// CraftBukkit end
|
||||
performSpellCasting()
|
||||
handle.playSound(openHandle.openCastingSoundEvent, 1.0f, 1.0f)
|
||||
}
|
||||
|
||||
@@ -3,25 +3,34 @@ package com.willfp.eco.internal.spigot.proxy.common.fast
|
||||
import com.willfp.eco.core.fast.FastItemStack
|
||||
import com.willfp.eco.internal.spigot.proxy.common.NBT_TAG_STRING
|
||||
import com.willfp.eco.internal.spigot.proxy.common.asNMSStack
|
||||
import com.willfp.eco.internal.spigot.proxy.common.makePdc
|
||||
import com.willfp.eco.internal.spigot.proxy.common.mergeIfNeeded
|
||||
import com.willfp.eco.internal.spigot.proxy.common.setPdc
|
||||
import com.willfp.eco.internal.spigot.proxy.common.toItem
|
||||
import com.willfp.eco.util.NamespacedKeyUtils
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import com.willfp.eco.util.toComponent
|
||||
import com.willfp.eco.util.toLegacy
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.nbt.StringTag
|
||||
import net.minecraft.world.item.EnchantedBookItem
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.Items
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.inventory.ItemFlag
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import kotlin.experimental.and
|
||||
|
||||
@Suppress("UsePropertyAccessSyntax")
|
||||
class EcoFastItemStack(
|
||||
private val bukkit: org.bukkit.inventory.ItemStack
|
||||
) : FastItemStack {
|
||||
private var loreCache: List<String>? = null
|
||||
private val handle = bukkit.asNMSStack()
|
||||
private val pdc = (if (handle.hasTag()) handle.getTag()!! else CompoundTag()).makePdc()
|
||||
|
||||
override fun getEnchants(checkStored: Boolean): Map<Enchantment, Int> {
|
||||
val enchantmentNBT =
|
||||
@@ -41,7 +50,7 @@ class EcoFastItemStack(
|
||||
return foundEnchantments
|
||||
}
|
||||
|
||||
override fun getLevelOnItem(
|
||||
override fun getEnchantmentLevel(
|
||||
enchantment: Enchantment,
|
||||
checkStored: Boolean
|
||||
): Int {
|
||||
@@ -60,13 +69,14 @@ class EcoFastItemStack(
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun setLore(lore: List<String>?) {
|
||||
loreCache = null
|
||||
val jsonLore: MutableList<String> = ArrayList()
|
||||
override fun setLore(lore: List<String>?) = setLoreComponents(lore?.map { it.toComponent() })
|
||||
|
||||
override fun setLoreComponents(lore: List<Component>?) {
|
||||
val jsonLore = mutableListOf<String>()
|
||||
|
||||
if (lore != null) {
|
||||
for (s in lore) {
|
||||
jsonLore.add(StringUtils.legacyToJson(s))
|
||||
jsonLore.add(StringUtils.componentToJson(s))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,17 +97,7 @@ class EcoFastItemStack(
|
||||
apply()
|
||||
}
|
||||
|
||||
override fun getLore(): List<String> {
|
||||
if (loreCache != null) {
|
||||
return loreCache!!
|
||||
}
|
||||
|
||||
val lore = this.getLoreJSON().map { StringUtils.jsonToLegacy(it) }
|
||||
loreCache = lore
|
||||
return lore
|
||||
}
|
||||
|
||||
private fun getLoreJSON(): List<String> {
|
||||
override fun getLoreComponents(): List<Component> {
|
||||
val displayTag = handle.getTagElement("display") ?: return emptyList()
|
||||
|
||||
if (!displayTag.contains("Lore")) {
|
||||
@@ -105,15 +105,47 @@ class EcoFastItemStack(
|
||||
}
|
||||
|
||||
val loreTag = displayTag.getList("Lore", NBT_TAG_STRING)
|
||||
val lore = ArrayList<String>(loreTag.size)
|
||||
val jsonLore = mutableListOf<String>()
|
||||
|
||||
for (i in loreTag.indices) {
|
||||
lore.add(loreTag.getString(i))
|
||||
jsonLore.add(loreTag.getString(i))
|
||||
}
|
||||
|
||||
return lore
|
||||
return jsonLore.map { StringUtils.jsonToComponent(it) }
|
||||
}
|
||||
|
||||
override fun getLore(): List<String> =
|
||||
getLoreComponents().map { StringUtils.toLegacy(it) }
|
||||
|
||||
override fun setDisplayName(name: Component?) {
|
||||
val displayTag = handle.getOrCreateTagElement("display")
|
||||
|
||||
displayTag.remove("Name")
|
||||
|
||||
if (name != null) {
|
||||
displayTag.put("Name", StringTag.valueOf(StringUtils.componentToJson(name)))
|
||||
}
|
||||
|
||||
apply()
|
||||
}
|
||||
|
||||
override fun setDisplayName(name: String?) = setDisplayName(name?.toComponent())
|
||||
|
||||
override fun getDisplayNameComponent(): Component {
|
||||
val displayTag =
|
||||
handle.getTagElement("display") ?: return Component.translatable(bukkit.type.toItem().getDescriptionId())
|
||||
|
||||
if (!displayTag.contains("Name")) {
|
||||
return Component.translatable(bukkit.type.toItem().getDescriptionId())
|
||||
}
|
||||
|
||||
val nameTag = displayTag.getString("Name")
|
||||
|
||||
return StringUtils.jsonToComponent(nameTag)
|
||||
}
|
||||
|
||||
override fun getDisplayName(): String = displayNameComponent.toLegacy()
|
||||
|
||||
override fun addItemFlags(vararg hideFlags: ItemFlag) {
|
||||
for (flag in hideFlags) {
|
||||
this.flagBits = this.flagBits or getBitModifier(flag)
|
||||
@@ -151,6 +183,14 @@ class EcoFastItemStack(
|
||||
return this.flagBits and bitModifier == bitModifier
|
||||
}
|
||||
|
||||
override fun getBaseTag(): PersistentDataContainer =
|
||||
(if (handle.hasTag()) handle.getTag()!! else CompoundTag()).makePdc(base = true)
|
||||
|
||||
override fun setBaseTag(container: PersistentDataContainer?) {
|
||||
(if (handle.hasTag()) handle.getTag()!! else CompoundTag()).setPdc(container, item = handle)
|
||||
apply()
|
||||
}
|
||||
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
private var flagBits: Int
|
||||
get() =
|
||||
@@ -170,6 +210,10 @@ class EcoFastItemStack(
|
||||
handle.setRepairCost(cost)
|
||||
}
|
||||
|
||||
override fun getPersistentDataContainer(): PersistentDataContainer {
|
||||
return ContinuallyAppliedPersistentDataContainer(this.pdc, this)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is EcoFastItemStack) {
|
||||
return false
|
||||
@@ -183,7 +227,11 @@ class EcoFastItemStack(
|
||||
return handle.getTag()?.hashCode() ?: (0b00010101 * 31 + Item.getId(handle.getItem()))
|
||||
}
|
||||
|
||||
private fun apply() {
|
||||
internal fun apply() {
|
||||
if (handle.hasTag()) {
|
||||
handle.getTag()?.setPdc(this.pdc)
|
||||
}
|
||||
|
||||
bukkit.mergeIfNeeded(handle)
|
||||
}
|
||||
|
||||
@@ -195,3 +243,18 @@ class EcoFastItemStack(
|
||||
return bukkit
|
||||
}
|
||||
}
|
||||
|
||||
private class ContinuallyAppliedPersistentDataContainer(
|
||||
val handle: PersistentDataContainer,
|
||||
val fis: EcoFastItemStack
|
||||
) : PersistentDataContainer by handle {
|
||||
override fun <T : Any, Z : Any> set(key: NamespacedKey, type: PersistentDataType<T, Z>, value: Z) {
|
||||
handle.set(key, type, value)
|
||||
fis.apply()
|
||||
}
|
||||
|
||||
override fun remove(key: NamespacedKey) {
|
||||
handle.remove(key)
|
||||
fis.apply()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.willfp.eco.internal.spigot.proxy.v1_17_R1
|
||||
|
||||
import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.common.CommonsProvider
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.Tag
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import org.bukkit.Bukkit
|
||||
@@ -10,11 +12,14 @@ import org.bukkit.craftbukkit.v1_17_R1.CraftServer
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftMob
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_17_R1.persistence.CraftPersistentDataContainer
|
||||
import org.bukkit.craftbukkit.v1_17_R1.persistence.CraftPersistentDataTypeRegistry
|
||||
import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers
|
||||
import org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.entity.Mob
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
import java.lang.reflect.Field
|
||||
|
||||
class CommonsInitializer : CommonsInitializerProxy {
|
||||
@@ -27,6 +32,11 @@ class CommonsInitializer : CommonsInitializerProxy {
|
||||
isAccessible = true
|
||||
}
|
||||
|
||||
private val pdcRegsitry = Class.forName("org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaItem")
|
||||
.getDeclaredField("DATA_TYPE_REGISTRY")
|
||||
.apply { isAccessible = true }
|
||||
.get(null) as CraftPersistentDataTypeRegistry
|
||||
|
||||
override val nbtTagString = CraftMagicNumbers.NBT.TAG_STRING
|
||||
|
||||
override fun toPathfinderMob(mob: Mob): PathfinderMob? {
|
||||
@@ -57,5 +67,66 @@ class CommonsInitializer : CommonsInitializerProxy {
|
||||
|
||||
override fun toBukkitEntity(entity: net.minecraft.world.entity.LivingEntity): LivingEntity? =
|
||||
CraftEntity.getEntity(Bukkit.getServer() as CraftServer, entity) as? LivingEntity
|
||||
|
||||
override fun makePdc(tag: CompoundTag, base: Boolean): PersistentDataContainer {
|
||||
fun emptyPdc(): CraftPersistentDataContainer = CraftPersistentDataContainer(pdcRegsitry)
|
||||
|
||||
fun CompoundTag?.toPdc(): PersistentDataContainer {
|
||||
val pdc = emptyPdc()
|
||||
this ?: return pdc
|
||||
val keys = this.allKeys
|
||||
for (key in keys) {
|
||||
pdc.put(key, this[key])
|
||||
}
|
||||
|
||||
return pdc
|
||||
}
|
||||
|
||||
return if (base) {
|
||||
tag.toPdc()
|
||||
} else {
|
||||
if (tag.contains("PublicBukkitValues")) {
|
||||
tag.getCompound("PublicBukkitValues").toPdc()
|
||||
} else {
|
||||
emptyPdc()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setPdc(
|
||||
tag: CompoundTag,
|
||||
pdc: PersistentDataContainer?,
|
||||
item: net.minecraft.world.item.ItemStack?
|
||||
) {
|
||||
fun CraftPersistentDataContainer.toTag(): CompoundTag {
|
||||
val compound = CompoundTag()
|
||||
val rawPublicMap: Map<String, Tag> = this.raw
|
||||
for ((key, value) in rawPublicMap) {
|
||||
compound.put(key, value)
|
||||
}
|
||||
|
||||
return compound
|
||||
}
|
||||
|
||||
pdc as CraftPersistentDataContainer?
|
||||
|
||||
if (item != null) {
|
||||
if (pdc != null && !pdc.isEmpty) {
|
||||
for (key in tag.allKeys.toSet()) {
|
||||
tag.remove(key)
|
||||
}
|
||||
|
||||
tag.merge(pdc.toTag())
|
||||
} else {
|
||||
item.setTag(null)
|
||||
}
|
||||
} else {
|
||||
if (pdc != null && !pdc.isEmpty) {
|
||||
tag.put("PublicBukkitValues", pdc.toTag())
|
||||
} else {
|
||||
tag.remove("PublicBukkitValues")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,6 @@ class Skull : SkullProxy {
|
||||
val profile = profile[meta] as GameProfile? ?: return null
|
||||
val properties = profile.properties ?: return null
|
||||
val prop = properties["textures"] ?: return null
|
||||
return prop.toMutableList().firstOrNull()?.name
|
||||
return prop.toMutableList().firstOrNull()?.value
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.willfp.eco.internal.spigot.proxy.v1_18_R1
|
||||
|
||||
import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.common.CommonsProvider
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.Tag
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import org.bukkit.Bukkit
|
||||
@@ -10,11 +12,14 @@ import org.bukkit.craftbukkit.v1_18_R1.CraftServer
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftMob
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_18_R1.persistence.CraftPersistentDataContainer
|
||||
import org.bukkit.craftbukkit.v1_18_R1.persistence.CraftPersistentDataTypeRegistry
|
||||
import org.bukkit.craftbukkit.v1_18_R1.util.CraftMagicNumbers
|
||||
import org.bukkit.craftbukkit.v1_18_R1.util.CraftNamespacedKey
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.entity.Mob
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
import java.lang.reflect.Field
|
||||
|
||||
class CommonsInitializer : CommonsInitializerProxy {
|
||||
@@ -27,6 +32,11 @@ class CommonsInitializer : CommonsInitializerProxy {
|
||||
isAccessible = true
|
||||
}
|
||||
|
||||
private val pdcRegsitry = Class.forName("org.bukkit.craftbukkit.v1_18_R1.inventory.CraftMetaItem")
|
||||
.getDeclaredField("DATA_TYPE_REGISTRY")
|
||||
.apply { isAccessible = true }
|
||||
.get(null) as CraftPersistentDataTypeRegistry
|
||||
|
||||
override val nbtTagString = CraftMagicNumbers.NBT.TAG_STRING
|
||||
|
||||
override fun toPathfinderMob(mob: Mob): PathfinderMob? {
|
||||
@@ -57,5 +67,66 @@ class CommonsInitializer : CommonsInitializerProxy {
|
||||
|
||||
override fun toBukkitEntity(entity: net.minecraft.world.entity.LivingEntity): LivingEntity? =
|
||||
CraftEntity.getEntity(Bukkit.getServer() as CraftServer, entity) as? LivingEntity
|
||||
|
||||
override fun makePdc(tag: CompoundTag, base: Boolean): PersistentDataContainer {
|
||||
fun emptyPdc(): CraftPersistentDataContainer = CraftPersistentDataContainer(pdcRegsitry)
|
||||
|
||||
fun CompoundTag?.toPdc(): PersistentDataContainer {
|
||||
val pdc = emptyPdc()
|
||||
this ?: return pdc
|
||||
val keys = this.allKeys
|
||||
for (key in keys) {
|
||||
pdc.put(key, this[key])
|
||||
}
|
||||
|
||||
return pdc
|
||||
}
|
||||
|
||||
return if (base) {
|
||||
tag.toPdc()
|
||||
} else {
|
||||
if (tag.contains("PublicBukkitValues")) {
|
||||
tag.getCompound("PublicBukkitValues").toPdc()
|
||||
} else {
|
||||
emptyPdc()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setPdc(
|
||||
tag: CompoundTag,
|
||||
pdc: PersistentDataContainer?,
|
||||
item: net.minecraft.world.item.ItemStack?
|
||||
) {
|
||||
fun CraftPersistentDataContainer.toTag(): CompoundTag {
|
||||
val compound = CompoundTag()
|
||||
val rawPublicMap: Map<String, Tag> = this.raw
|
||||
for ((key, value) in rawPublicMap) {
|
||||
compound.put(key, value)
|
||||
}
|
||||
|
||||
return compound
|
||||
}
|
||||
|
||||
pdc as CraftPersistentDataContainer?
|
||||
|
||||
if (item != null) {
|
||||
if (pdc != null && !pdc.isEmpty) {
|
||||
for (key in tag.allKeys.toSet()) {
|
||||
tag.remove(key)
|
||||
}
|
||||
|
||||
tag.merge(pdc.toTag())
|
||||
} else {
|
||||
item.setTag(null)
|
||||
}
|
||||
} else {
|
||||
if (pdc != null && !pdc.isEmpty) {
|
||||
tag.put("PublicBukkitValues", pdc.toTag())
|
||||
} else {
|
||||
tag.remove("PublicBukkitValues")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,6 @@ class Skull : SkullProxy {
|
||||
val profile = profile[meta] as GameProfile? ?: return null
|
||||
val properties = profile.properties ?: return null
|
||||
val prop = properties["textures"] ?: return null
|
||||
return prop.toMutableList().firstOrNull()?.name
|
||||
return prop.toMutableList().firstOrNull()?.value
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.willfp.eco.internal.spigot.proxy.v1_18_R2
|
||||
|
||||
import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.common.CommonsProvider
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.Tag
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import org.bukkit.Bukkit
|
||||
@@ -10,11 +12,14 @@ import org.bukkit.craftbukkit.v1_18_R2.CraftServer
|
||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftMob
|
||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_18_R2.persistence.CraftPersistentDataContainer
|
||||
import org.bukkit.craftbukkit.v1_18_R2.persistence.CraftPersistentDataTypeRegistry
|
||||
import org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers
|
||||
import org.bukkit.craftbukkit.v1_18_R2.util.CraftNamespacedKey
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.entity.Mob
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
import java.lang.reflect.Field
|
||||
|
||||
class CommonsInitializer : CommonsInitializerProxy {
|
||||
@@ -27,6 +32,11 @@ class CommonsInitializer : CommonsInitializerProxy {
|
||||
isAccessible = true
|
||||
}
|
||||
|
||||
private val pdcRegsitry = Class.forName("org.bukkit.craftbukkit.v1_18_R2.inventory.CraftMetaItem")
|
||||
.getDeclaredField("DATA_TYPE_REGISTRY")
|
||||
.apply { isAccessible = true }
|
||||
.get(null) as CraftPersistentDataTypeRegistry
|
||||
|
||||
override val nbtTagString = CraftMagicNumbers.NBT.TAG_STRING
|
||||
|
||||
override fun toPathfinderMob(mob: Mob): PathfinderMob? {
|
||||
@@ -57,5 +67,66 @@ class CommonsInitializer : CommonsInitializerProxy {
|
||||
|
||||
override fun toBukkitEntity(entity: net.minecraft.world.entity.LivingEntity): LivingEntity? =
|
||||
CraftEntity.getEntity(Bukkit.getServer() as CraftServer, entity) as? LivingEntity
|
||||
|
||||
override fun makePdc(tag: CompoundTag, base: Boolean): PersistentDataContainer {
|
||||
fun emptyPdc(): CraftPersistentDataContainer = CraftPersistentDataContainer(pdcRegsitry)
|
||||
|
||||
fun CompoundTag?.toPdc(): PersistentDataContainer {
|
||||
val pdc = emptyPdc()
|
||||
this ?: return pdc
|
||||
val keys = this.allKeys
|
||||
for (key in keys) {
|
||||
pdc.put(key, this[key])
|
||||
}
|
||||
|
||||
return pdc
|
||||
}
|
||||
|
||||
return if (base) {
|
||||
tag.toPdc()
|
||||
} else {
|
||||
if (tag.contains("PublicBukkitValues")) {
|
||||
tag.getCompound("PublicBukkitValues").toPdc()
|
||||
} else {
|
||||
emptyPdc()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setPdc(
|
||||
tag: CompoundTag,
|
||||
pdc: PersistentDataContainer?,
|
||||
item: net.minecraft.world.item.ItemStack?
|
||||
) {
|
||||
fun CraftPersistentDataContainer.toTag(): CompoundTag {
|
||||
val compound = CompoundTag()
|
||||
val rawPublicMap: Map<String, Tag> = this.raw
|
||||
for ((key, value) in rawPublicMap) {
|
||||
compound.put(key, value)
|
||||
}
|
||||
|
||||
return compound
|
||||
}
|
||||
|
||||
pdc as CraftPersistentDataContainer?
|
||||
|
||||
if (item != null) {
|
||||
if (pdc != null && !pdc.isEmpty) {
|
||||
for (key in tag.allKeys.toSet()) {
|
||||
tag.remove(key)
|
||||
}
|
||||
|
||||
tag.merge(pdc.toTag())
|
||||
} else {
|
||||
item.setTag(null)
|
||||
}
|
||||
} else {
|
||||
if (pdc != null && !pdc.isEmpty) {
|
||||
tag.put("PublicBukkitValues", pdc.toTag())
|
||||
} else {
|
||||
tag.remove("PublicBukkitValues")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,6 @@ class Skull : SkullProxy {
|
||||
val profile = profile[meta] as GameProfile? ?: return null
|
||||
val properties = profile.properties ?: return null
|
||||
val prop = properties["textures"] ?: return null
|
||||
return prop.toMutableList().firstOrNull()?.name
|
||||
return prop.toMutableList().firstOrNull()?.value
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,23 @@ group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.Redempt:Crunch:1.1.2'
|
||||
compileOnly 'net.kyori:adventure-platform-bukkit:4.1.0'
|
||||
compileOnly 'org.apache.maven:maven-artifact:3.8.1'
|
||||
compileOnly 'com.google.code.gson:gson:2.8.8'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
|
||||
compileOnly project(":eco-core:core-proxy")
|
||||
compileOnly project(":eco-core:core-backend")
|
||||
|
||||
// Libraries
|
||||
implementation 'com.github.Redempt:Crunch:1.1.2'
|
||||
implementation 'mysql:mysql-connector-java:8.0.25'
|
||||
implementation 'org.jetbrains.exposed:exposed-core:0.37.3'
|
||||
implementation 'org.jetbrains.exposed:exposed-dao:0.37.3'
|
||||
implementation 'org.jetbrains.exposed:exposed-jdbc:0.37.3'
|
||||
implementation 'com.zaxxer:HikariCP:5.0.0'
|
||||
implementation 'net.kyori:adventure-platform-bukkit:4.1.0'
|
||||
|
||||
// Included in spigot jar
|
||||
compileOnly 'com.google.code.gson:gson:2.8.8'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
|
||||
|
||||
// Plugin dependencies
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.1-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.7-SNAPSHOT'
|
||||
compileOnly 'com.github.TechFortress:GriefPrevention:16.17.1'
|
||||
@@ -26,34 +36,28 @@ dependencies {
|
||||
compileOnly 'com.github.brcdev-minecraft:shopgui-api:2.2.0'
|
||||
compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.4.7'
|
||||
compileOnly 'com.arcaniax:HeadDatabase-API:1.3.0'
|
||||
compileOnly 'org.jetbrains.exposed:exposed-core:0.37.3'
|
||||
compileOnly 'org.jetbrains.exposed:exposed-dao:0.37.3'
|
||||
compileOnly 'org.jetbrains.exposed:exposed-jdbc:0.37.3'
|
||||
compileOnly 'mysql:mysql-connector-java:8.0.25'
|
||||
compileOnly 'com.zaxxer:HikariCP:5.0.0'
|
||||
compileOnly 'com.gmail.filoghost.holographicdisplays:holographicdisplays-api:2.4.0'
|
||||
compileOnly 'com.github.EssentialsX:Essentials:2.18.2'
|
||||
compileOnly 'com.bgsoftware:SuperiorSkyblockAPI:1.8.3'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||
compileOnly 'world.bentobox:bentobox:1.17.3-SNAPSHOT'
|
||||
compileOnly 'com.iridium:IridiumSkyblock:3.1.2'
|
||||
compileOnly 'com.github.WhipDevelopment:CrashClaim:f9cd7d92eb'
|
||||
compileOnly 'com.wolfyscript.wolfyutilities:wolfyutilities:3.16.0.0'
|
||||
compileOnly 'com.github.decentsoftware-eu:decentholograms:2.1.2'
|
||||
|
||||
// MythicMobs
|
||||
compileOnly 'io.lumine:Mythic:5.0.1'
|
||||
compileOnly 'io.lumine:LumineUtils:1.16.1-SNAPSHOT'
|
||||
|
||||
// CombatLogX V10 + NewbieHelper Expansion
|
||||
compileOnly 'com.SirBlobman.combatlogx:CombatLogX-API:10.0.0.0-SNAPSHOT'
|
||||
compileOnly 'com.SirBlobman.combatlogx.expansions:NewbieHelper:10.0.0.0-SNAPSHOT'
|
||||
|
||||
// CombatLogX V11 + NewbieHelper Expansion
|
||||
compileOnly 'com.github.sirblobman.combatlogx:api:11.0.0.0-SNAPSHOT'
|
||||
compileOnly 'com.github.sirblobman.combatlogx.expansion:newbie-helper:11.0.0.0-SNAPSHOT'
|
||||
|
||||
// LibsDisguises
|
||||
compileOnly 'LibsDisguises:LibsDisguises:10.0.26'
|
||||
|
||||
// All other libs
|
||||
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
|
||||
}
|
||||
|
||||
|
||||
@@ -178,6 +178,8 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
|
||||
NumberUtils.initCrunch { expression, player, statics -> evaluateExpression(expression, player, statics) }
|
||||
|
||||
CustomItemsManager.registerProviders()
|
||||
|
||||
postInit()
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ class MySQLDataHandler(
|
||||
private val serverHandler: ImplementedMySQLHandler
|
||||
|
||||
init {
|
||||
|
||||
val config = HikariConfig()
|
||||
config.driverClassName = "com.mysql.cj.jdbc.Driver"
|
||||
config.username = plugin.configYml.getString("mysql.user")
|
||||
|
||||
@@ -13,7 +13,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
|
||||
player: Player,
|
||||
block: Block
|
||||
): Boolean {
|
||||
val api = IridiumSkyblockAPI.getInstance() ?: return true
|
||||
val api = IridiumSkyblockAPI.getInstance()
|
||||
|
||||
return api.getIslandPermission(api.getIslandViaLocation(block.location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_BREAK)
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
|
||||
player: Player,
|
||||
location: Location
|
||||
): Boolean {
|
||||
val api = IridiumSkyblockAPI.getInstance() ?: return true
|
||||
val api = IridiumSkyblockAPI.getInstance()
|
||||
|
||||
return api.getIslandPermission(api.getIslandViaLocation(location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_BREAK)
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
|
||||
player: Player,
|
||||
block: Block
|
||||
): Boolean {
|
||||
val api = IridiumSkyblockAPI.getInstance() ?: return true
|
||||
val api = IridiumSkyblockAPI.getInstance()
|
||||
|
||||
return api.getIslandPermission(api.getIslandViaLocation(block.location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_PLACE)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
|
||||
player: Player,
|
||||
victim: LivingEntity
|
||||
): Boolean {
|
||||
val api = IridiumSkyblockAPI.getInstance() ?: return true
|
||||
val api = IridiumSkyblockAPI.getInstance()
|
||||
|
||||
return when (victim) {
|
||||
is Player -> api.getIslandViaLocation(victim.location).orElse(null) != null
|
||||
@@ -49,7 +49,7 @@ class AntigriefIridiumSkyblock : AntigriefWrapper {
|
||||
}
|
||||
|
||||
override fun canPickupItem(player: Player, location: Location): Boolean {
|
||||
val api = IridiumSkyblockAPI.getInstance() ?: return true
|
||||
val api = IridiumSkyblockAPI.getInstance()
|
||||
return api.getIslandPermission(api.getIslandViaLocation(location).orElse(null) ?: return true, api.getUser(player), PermissionType.PICKUP_ITEMS)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack
|
||||
import java.util.function.Predicate
|
||||
|
||||
class CustomItemsCustomCrafting : CustomItemsWrapper {
|
||||
override fun registerAllItems() {
|
||||
override fun registerProvider() {
|
||||
Items.registerItemProvider(CustomCraftingProvider())
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack
|
||||
import java.util.function.Predicate
|
||||
|
||||
class CustomItemsExecutableItems : CustomItemsWrapper {
|
||||
override fun registerAllItems() {
|
||||
override fun registerProvider() {
|
||||
Items.registerItemProvider(ExecutableItemsProvider())
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class CustomItemsHeadDatabase(
|
||||
plugin.eventManager.registerListener(provider)
|
||||
}
|
||||
|
||||
override fun registerAllItems() {
|
||||
override fun registerProvider() {
|
||||
Items.registerItemProvider(HeadDBProvider())
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack
|
||||
import java.util.function.Predicate
|
||||
|
||||
class CustomItemsItemsAdder : CustomItemsWrapper {
|
||||
override fun registerAllItems() {
|
||||
override fun registerProvider() {
|
||||
Items.registerItemProvider(ItemsAdderProvider())
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,6 @@ class CustomItemsMythicMobs(
|
||||
return "MythicMobs"
|
||||
}
|
||||
|
||||
override fun registerAllItems() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onLoad(event: MythicDropLoadEvent) {
|
||||
val name = event.dropName
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.willfp.eco.util.NamespacedKeyUtils
|
||||
import io.th0rgal.oraxen.items.OraxenItems
|
||||
|
||||
class CustomItemsOraxen : CustomItemsWrapper {
|
||||
override fun registerAllItems() {
|
||||
override fun registerProvider() {
|
||||
Items.registerItemProvider(OraxenProvider())
|
||||
}
|
||||
|
||||
|
||||
@@ -42,20 +42,4 @@ softdepend:
|
||||
- MythicMobs
|
||||
- CustomCrafting
|
||||
- ExecutableItems
|
||||
- RPGHorses
|
||||
libraries:
|
||||
- 'org.reflections:reflections:0.9.12'
|
||||
- 'org.apache.maven:maven-artifact:3.0.3'
|
||||
- 'org.jetbrains.kotlin:kotlin-stdlib:1.6.10'
|
||||
- 'net.kyori:adventure-platform-bukkit:4.1.0'
|
||||
- 'net.kyori:adventure-api:4.10.0'
|
||||
- 'net.kyori:adventure-text-serializer-gson:4.10.0'
|
||||
- 'net.kyori:adventure-text-serializer-legacy:4.10.0'
|
||||
- 'org.jetbrains.exposed:exposed-core:0.37.3'
|
||||
- 'org.jetbrains.exposed:exposed-dao:0.37.3'
|
||||
- 'org.jetbrains.exposed:exposed-jdbc:0.37.3'
|
||||
- 'mysql:mysql-connector-java:8.0.25'
|
||||
- 'com.google.guava:guava:31.1-jre'
|
||||
- 'com.zaxxer:HikariCP:5.0.0'
|
||||
- 'org.objenesis:objenesis:3.2'
|
||||
- 'com.github.ben-manes.caffeine:caffeine:3.0.5'
|
||||
- RPGHorses
|
||||
@@ -1,3 +1,3 @@
|
||||
version = 6.31.3
|
||||
version = 6.34.0
|
||||
plugin-name = eco
|
||||
kotlin.code.style = official
|
||||
BIN
lib/BentoBox-1.20.0.jar
Normal file
BIN
lib/BentoBox-1.20.0.jar
Normal file
Binary file not shown.
BIN
lib/IridiumSkyblock-3.2.8.jar
Normal file
BIN
lib/IridiumSkyblock-3.2.8.jar
Normal file
Binary file not shown.
BIN
lib/NewbieHelper-10.0.0.0-20210830.204745-1.jar
Normal file
BIN
lib/NewbieHelper-10.0.0.0-20210830.204745-1.jar
Normal file
Binary file not shown.
BIN
lib/newbie-helper-11.0.0.0-20220406.181927-90.jar
Normal file
BIN
lib/newbie-helper-11.0.0.0-20220406.181927-90.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user