Compare commits
143 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1c0b8c857 | ||
|
|
0442ccf58f | ||
|
|
1c1a796610 | ||
|
|
eacb243493 | ||
|
|
7bbed31d4e | ||
|
|
58bccf3cd7 | ||
|
|
4502e1e311 | ||
|
|
054a8d5a5e | ||
|
|
dbdd4785ba | ||
|
|
35f800b62a | ||
|
|
591800dba8 | ||
|
|
46673e8d24 | ||
|
|
bb7c300074 | ||
|
|
b003ec96f7 | ||
|
|
a526f51780 | ||
|
|
dd14fc666a | ||
|
|
ae0150f012 | ||
|
|
04418fa038 | ||
|
|
bcb9523315 | ||
|
|
43e7972ca3 | ||
|
|
7ea61eb393 | ||
|
|
5245a9b1d8 | ||
|
|
195932463c | ||
|
|
3cf60a7e2c | ||
|
|
0f9f57fca2 | ||
|
|
fe21616dd5 | ||
|
|
396144abaa | ||
|
|
50b4fa59ab | ||
|
|
a6754379e8 | ||
|
|
bbd0182c2a | ||
|
|
0370e9f454 | ||
|
|
8d585b58cb | ||
|
|
0bfbd4c036 | ||
|
|
881839955e | ||
|
|
8ffc5f9c0f | ||
|
|
709de3bb5f | ||
|
|
f2aa2ffd9b | ||
|
|
5ce70399f0 | ||
|
|
3f8759b08a | ||
|
|
abecaa6e9f | ||
|
|
4744bfc78b | ||
|
|
487e68221a | ||
|
|
1c68992a8e | ||
|
|
c5b7d0b644 | ||
|
|
0f91aec3b7 | ||
|
|
d2bf38c5c9 | ||
|
|
2c96b79aba | ||
|
|
d539b9e59e | ||
|
|
b0b06ef402 | ||
|
|
7a84c3de3b | ||
|
|
9431321e1c | ||
|
|
4816284fba | ||
|
|
a9874c9386 | ||
|
|
fe68760184 | ||
|
|
5ae8e72a98 | ||
|
|
15fc6053c8 | ||
|
|
1f7cf78491 | ||
|
|
fc3c80f633 | ||
|
|
2bcbf181a9 | ||
|
|
7adcdd572d | ||
|
|
f6eba21006 | ||
|
|
cc02f26807 | ||
|
|
60f552ce65 | ||
|
|
9fe8d4ad15 | ||
|
|
b835988eec | ||
|
|
22366835de | ||
|
|
cdd1baec6c | ||
|
|
1ea0da365a | ||
|
|
852d40372d | ||
|
|
999c831dd7 | ||
|
|
80fa5d346a | ||
|
|
336cdc3716 | ||
|
|
a49a9e92b4 | ||
|
|
1c6e64832e | ||
|
|
44a141cddc | ||
|
|
ea4956870e | ||
|
|
9207d1782b | ||
|
|
9debcb7089 | ||
|
|
ef53ee2ed3 | ||
|
|
4c90360038 | ||
|
|
d4b5102913 | ||
|
|
f4553c544a | ||
|
|
5ad1db72fc | ||
|
|
c761df9ee6 | ||
|
|
b6d79da4e1 | ||
|
|
42f41618ca | ||
|
|
de878fd423 | ||
|
|
7782657d57 | ||
|
|
7778425936 | ||
|
|
6446cef255 | ||
|
|
8dacecbcba | ||
|
|
5f8ec4f94a | ||
|
|
d7847e9efc | ||
|
|
930ecd4896 | ||
|
|
af8d6a4167 | ||
|
|
361f0a0103 | ||
|
|
eb545a7d9e | ||
|
|
d3c64deef4 | ||
|
|
31db9dcb95 | ||
|
|
4938ad84bc | ||
|
|
06b2301da1 | ||
|
|
c307878c09 | ||
|
|
3b10ff01ec | ||
|
|
e042754f5d | ||
|
|
c2b8a80560 | ||
|
|
07c0e72564 | ||
|
|
de9b961d83 | ||
|
|
83958c719c | ||
|
|
9c3dfaeb01 | ||
|
|
7e61340285 | ||
|
|
78b76cb453 | ||
|
|
bb1da29704 | ||
|
|
cf152215d3 | ||
|
|
e6a59fbc91 | ||
|
|
b787f8b76a | ||
|
|
ccc83da5b0 | ||
|
|
f11068f2f1 | ||
|
|
a5cc1a5d32 | ||
|
|
7440749ba5 | ||
|
|
75010d25fa | ||
|
|
bb95376b93 | ||
|
|
ab6d4c7aa2 | ||
|
|
9ab8827e55 | ||
|
|
991290095b | ||
|
|
8735478fc3 | ||
|
|
6e44f09621 | ||
|
|
060106881e | ||
|
|
96cc9706b3 | ||
|
|
3d87b1eb73 | ||
|
|
4c4247b4ec | ||
|
|
b94dc4ac3a | ||
|
|
06bcb10958 | ||
|
|
295095e9ce | ||
|
|
ba9c5865e3 | ||
|
|
d24be4121f | ||
|
|
bcc5e4ef08 | ||
|
|
bf8609666a | ||
|
|
1a02335825 | ||
|
|
f5ef98ec5c | ||
|
|
45135e2b55 | ||
|
|
758b42ff8e | ||
|
|
bd5555ff01 | ||
|
|
5f80b6052d |
@@ -39,7 +39,7 @@ and many more.
|
||||
# For developers
|
||||
|
||||
## Javadoc
|
||||
The 6.27.2 Javadoc can be found [here](https://javadoc.jitpack.io/com/willfp/eco/6.27.2/javadoc/)
|
||||
The 6.38.2 Javadoc can be found [here](https://javadoc.jitpack.io/com/willfp/eco/6.38.2/javadoc/)
|
||||
|
||||
## Plugin Information
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,18 @@ plugins {
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
id("maven-publish")
|
||||
id("java")
|
||||
kotlin("jvm") version "1.6.21"
|
||||
kotlin("jvm") version "1.7.10"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":eco-api"))
|
||||
implementation(project(":eco-core:core-plugin"))
|
||||
implementation(project(path = ":eco-core:core-plugin", configuration = "shadow"))
|
||||
implementation(project(":eco-core:core-proxy"))
|
||||
implementation(project(":eco-core:core-backend"))
|
||||
implementation(project(path = ":eco-core:core-nms:v1_17_R1", configuration = "reobf"))
|
||||
implementation(project(path = ":eco-core:core-nms:v1_18_R1", configuration = "reobf"))
|
||||
implementation(project(path = ":eco-core:core-nms:v1_18_R2", configuration = "reobf"))
|
||||
implementation(project(path = ":eco-core:core-nms:v1_19_R1", configuration = "reobf"))
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@@ -44,11 +45,8 @@ allprojects {
|
||||
// SuperiorSkyblock2
|
||||
maven("https://repo.bg-software.com/repository/api/")
|
||||
|
||||
// NMS (for jitpack compilation)
|
||||
maven("https://repo.codemc.org/repository/nms/")
|
||||
|
||||
// mcMMO, BentoBox
|
||||
maven("https://repo.codemc.org/repository/maven-public/")
|
||||
maven("https://repo.codemc.io/repository/maven-public/")
|
||||
|
||||
// Spigot API, Bungee API
|
||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
|
||||
@@ -63,7 +61,7 @@ allprojects {
|
||||
maven("https://maven.enginehub.org/repo/")
|
||||
|
||||
// FactionsUUID
|
||||
maven("https://ci.ender.zone/plugin/repository/everything/")
|
||||
//maven("https://ci.ender.zone/plugin/repository/everything/")
|
||||
|
||||
// NoCheatPlus
|
||||
maven("https://repo.md-5.net/content/repositories/snapshots/")
|
||||
@@ -79,11 +77,15 @@ allprojects {
|
||||
|
||||
// LibsDisguises
|
||||
maven("https://repo.md-5.net/content/groups/public/")
|
||||
|
||||
// FabledSkyblock
|
||||
maven("https://repo.songoda.com/repository/public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Kotlin
|
||||
implementation(kotlin("stdlib", version = "1.6.21"))
|
||||
implementation(kotlin("stdlib", version = "1.7.10"))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2")
|
||||
|
||||
// Included in spigot jar, no need to move to implementation
|
||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||
@@ -101,7 +103,7 @@ allprojects {
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:4.10.1")
|
||||
|
||||
// Other
|
||||
implementation("com.github.ben-manes.caffeine:caffeine:3.0.6")
|
||||
implementation("com.github.ben-manes.caffeine:caffeine:3.1.0")
|
||||
implementation("org.apache.maven:maven-artifact:3.8.5")
|
||||
}
|
||||
|
||||
@@ -130,8 +132,6 @@ allprojects {
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
targetCompatibility = "17"
|
||||
sourceCompatibility = "17"
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
@@ -154,6 +154,13 @@ allprojects {
|
||||
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")
|
||||
relocate("de.undercouch.bson4jackson", "com.willfp.eco.libs.bson4jackson")
|
||||
relocate("com.fasterxml.jackson", "com.willfp.eco.libs.jackson")
|
||||
relocate("com.mongodb", "com.willfp.eco.libs.mongodb")
|
||||
relocate("org.bson", "com.willfp.eco.libs.bson")
|
||||
relocate("org.litote", "com.willfp.eco.libs.litote")
|
||||
relocate("org.reactivestreams", "com.willfp.eco.libs.reactivestreams")
|
||||
relocate("reactor.", "com.willfp.eco.libs.reactor.") // Dot in name to be safe
|
||||
|
||||
/*
|
||||
Kotlin and caffeine are not shaded so that they can be accessed directly by eco plugins.
|
||||
|
||||
@@ -304,6 +304,11 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
|
||||
this.color = props.getColor();
|
||||
this.supportingExtensions = props.isSupportingExtensions();
|
||||
|
||||
this.proxyFactory = this.proxyPackage.equalsIgnoreCase("") ? null : Eco.getHandler().createProxyFactory(this);
|
||||
this.logger = Eco.getHandler().createLogger(this);
|
||||
|
||||
this.getLogger().info("Initializing " + this.getColor() + this.getName());
|
||||
|
||||
this.scheduler = Eco.getHandler().createScheduler(this);
|
||||
this.eventManager = Eco.getHandler().createEventManager(this);
|
||||
this.namespacedKeyFactory = Eco.getHandler().createNamespacedKeyFactory(this);
|
||||
@@ -311,16 +316,12 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
|
||||
this.runnableFactory = Eco.getHandler().createRunnableFactory(this);
|
||||
this.extensionLoader = Eco.getHandler().createExtensionLoader(this);
|
||||
this.configHandler = Eco.getHandler().createConfigHandler(this);
|
||||
this.logger = Eco.getHandler().createLogger(this);
|
||||
this.proxyFactory = this.proxyPackage.equalsIgnoreCase("") ? null : Eco.getHandler().createProxyFactory(this);
|
||||
|
||||
this.langYml = this.createLangYml();
|
||||
this.configYml = this.createConfigYml();
|
||||
|
||||
Eco.getHandler().addNewPlugin(this);
|
||||
|
||||
this.getLogger().info("Initializing " + this.getColor() + this.getName());
|
||||
|
||||
/*
|
||||
The minimum eco version check was moved here because it's very common
|
||||
to add a lot of code in the constructor of plugins; meaning that the plugin
|
||||
@@ -376,12 +377,12 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
|
||||
PlaceholderManager.addIntegration(Eco.getHandler().createPAPIIntegration(this));
|
||||
}
|
||||
|
||||
this.loadIntegrationLoaders().forEach((integrationLoader -> {
|
||||
this.loadIntegrationLoaders().forEach(integrationLoader -> {
|
||||
if (enabledPlugins.contains(integrationLoader.getPluginName().toLowerCase())) {
|
||||
this.loadedIntegrations.add(integrationLoader.getPluginName());
|
||||
integrationLoader.load();
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
this.getLogger().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.willfp.eco.core.factory.RunnableFactory;
|
||||
import com.willfp.eco.core.fast.FastItemStack;
|
||||
import com.willfp.eco.core.gui.GUIFactory;
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration;
|
||||
import com.willfp.eco.core.items.SNBTHandler;
|
||||
import com.willfp.eco.core.proxy.Cleaner;
|
||||
import com.willfp.eco.core.proxy.ProxyFactory;
|
||||
import com.willfp.eco.core.scheduling.Scheduler;
|
||||
@@ -282,8 +283,7 @@ public interface Handler {
|
||||
* @param <T> The mob type.
|
||||
* @return The controlled entity.
|
||||
*/
|
||||
@NotNull
|
||||
<T extends Mob> EntityController<T> createEntityController(@NotNull T mob);
|
||||
@NotNull <T extends Mob> EntityController<T> createEntityController(@NotNull T mob);
|
||||
|
||||
/**
|
||||
* Adapt base PDC to extended PDC.
|
||||
@@ -301,4 +301,12 @@ public interface Handler {
|
||||
*/
|
||||
@NotNull
|
||||
PersistentDataContainer newPdc();
|
||||
|
||||
/**
|
||||
* Get SNBT handler.
|
||||
*
|
||||
* @return The SNBT handler.
|
||||
*/
|
||||
@NotNull
|
||||
SNBTHandler getSNBTHandler();
|
||||
}
|
||||
|
||||
@@ -41,11 +41,19 @@ public class Prerequisite {
|
||||
"Requires server to have vault"
|
||||
);
|
||||
|
||||
/**
|
||||
* Requires the server to be running 1.19.
|
||||
*/
|
||||
public static final Prerequisite HAS_1_19 = new Prerequisite(
|
||||
() -> ProxyConstants.NMS_VERSION.contains("19"),
|
||||
"Requires server to be running 1.19+"
|
||||
);
|
||||
|
||||
/**
|
||||
* Requires the server to be running 1.18.
|
||||
*/
|
||||
public static final Prerequisite HAS_1_18 = new Prerequisite(
|
||||
() -> ProxyConstants.NMS_VERSION.contains("18"),
|
||||
() -> ProxyConstants.NMS_VERSION.contains("18") || HAS_1_19.isMet(),
|
||||
"Requires server to be running 1.18+"
|
||||
);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public interface ProfileHandler {
|
||||
* @param async If the saving should be done asynchronously.
|
||||
* @deprecated async is now handled automatically depending on implementation.
|
||||
*/
|
||||
@Deprecated
|
||||
@Deprecated(forRemoval = true)
|
||||
default void saveAll(boolean async) {
|
||||
saveAll();
|
||||
}
|
||||
@@ -77,8 +77,13 @@ public interface ProfileHandler {
|
||||
* Save all player data.
|
||||
* <p>
|
||||
* Can run async if using MySQL.
|
||||
*
|
||||
* @deprecated Never used.
|
||||
*/
|
||||
void saveAll();
|
||||
@Deprecated(since = "6.36.0", forRemoval = true)
|
||||
default void saveAll() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit all changes to the file.
|
||||
|
||||
@@ -21,6 +21,15 @@ public interface KeyRegistry {
|
||||
*/
|
||||
void registerKey(@NotNull PersistentDataKey<?> key);
|
||||
|
||||
/**
|
||||
* Get a key's category.
|
||||
*
|
||||
* @param key The key.
|
||||
* @return The category.
|
||||
*/
|
||||
@Nullable
|
||||
KeyCategory getCategory(@NotNull PersistentDataKey<?> key);
|
||||
|
||||
/**
|
||||
* Get all registered keys.
|
||||
*
|
||||
|
||||
@@ -38,6 +38,11 @@ public final class PersistentDataKeyType<T> {
|
||||
*/
|
||||
public static final PersistentDataKeyType<Double> DOUBLE = new PersistentDataKeyType<>(Double.class, "DOUBLE");
|
||||
|
||||
/**
|
||||
* String List.
|
||||
*/
|
||||
public static final PersistentDataKeyType<List<String>> STRING_LIST = new PersistentDataKeyType<>(null, "STRING_LIST");
|
||||
|
||||
/**
|
||||
* The class of the type.
|
||||
*/
|
||||
@@ -52,7 +57,10 @@ public final class PersistentDataKeyType<T> {
|
||||
* Get the class of the type.
|
||||
*
|
||||
* @return The class.
|
||||
* @deprecated String list type will return null.
|
||||
*/
|
||||
@Deprecated(since = "6.36.0", forRemoval = true)
|
||||
@Nullable
|
||||
public Class<T> getTypeClass() {
|
||||
return typeClass;
|
||||
}
|
||||
@@ -72,7 +80,7 @@ public final class PersistentDataKeyType<T> {
|
||||
* @param typeClass The type class.
|
||||
* @param name The name.
|
||||
*/
|
||||
private PersistentDataKeyType(@NotNull final Class<T> typeClass,
|
||||
private PersistentDataKeyType(@Nullable final Class<T> typeClass,
|
||||
@NotNull final String name) {
|
||||
VALUES.add(this);
|
||||
|
||||
|
||||
@@ -64,6 +64,21 @@ public abstract class DisplayModule extends PluginDependent<EcoPlugin> {
|
||||
// Technically optional.
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an item.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @param player The player.
|
||||
* @param properties The properties.
|
||||
* @param args Optional args for display.
|
||||
*/
|
||||
public void display(@NotNull final ItemStack itemStack,
|
||||
@Nullable final Player player,
|
||||
@NotNull final DisplayProperties properties,
|
||||
@NotNull final Object... args) {
|
||||
// Technically optional.
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert an item.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.willfp.eco.core.display;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Extra properties passed into {@link DisplayModule}.
|
||||
*
|
||||
* @param inInventory If the item was in an inventory.
|
||||
* @param inGui If the item is assumed to be in a gui. (Not perfectly accurate).
|
||||
* @param originalItem The original item, not to be modified.
|
||||
*/
|
||||
public record DisplayProperties(
|
||||
boolean inInventory,
|
||||
boolean inGui,
|
||||
@NotNull ItemStack originalItem
|
||||
) {
|
||||
}
|
||||
@@ -68,6 +68,14 @@ public interface MenuBuilder {
|
||||
*/
|
||||
MenuBuilder onClose(@NotNull CloseHandler action);
|
||||
|
||||
/**
|
||||
* Set the menu open handler.
|
||||
*
|
||||
* @param action The handler.
|
||||
* @return The builder.
|
||||
*/
|
||||
MenuBuilder onOpen(@NotNull OpenHandler action);
|
||||
|
||||
/**
|
||||
* Set the action to run on render.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.eco.core.gui.menu;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Interface to run on menu open.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface OpenHandler {
|
||||
/**
|
||||
* Performs this operation on the given arguments.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param menu The menu.
|
||||
*/
|
||||
void handle(@NotNull Player player,
|
||||
@NotNull Menu menu);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -17,6 +18,15 @@ import java.util.List;
|
||||
* @param items The items.
|
||||
*/
|
||||
public record MaskItems(@NotNull TestableItem... items) {
|
||||
/**
|
||||
* Create mask items from materials.
|
||||
*
|
||||
* @param materials The materials.
|
||||
*/
|
||||
public MaskItems(@NotNull final Material... materials) {
|
||||
this(Arrays.stream(materials).map(MaterialTestableItem::new).toList().toArray(new TestableItem[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create MaskItems from a list of item names.
|
||||
*
|
||||
|
||||
@@ -28,6 +28,26 @@ public interface Slot {
|
||||
*/
|
||||
boolean isCaptive();
|
||||
|
||||
/**
|
||||
* If the slot is not captive for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return If not captive for the player.
|
||||
*/
|
||||
default boolean isNotCaptiveFor(@NotNull Player player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the slot is captive from empty.
|
||||
* If true, a captive item will be returned even if the item is the same as the rendered item.
|
||||
*
|
||||
* @return If captive from empty.
|
||||
*/
|
||||
default boolean isCaptiveFromEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder for an ItemStack.
|
||||
*
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.willfp.eco.core.gui.slot;
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotHandler;
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotModifier;
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotUpdater;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Builder to create slots.
|
||||
@@ -102,6 +104,14 @@ public interface SlotBuilder {
|
||||
*/
|
||||
SlotBuilder onMiddleClick(@NotNull SlotHandler handler);
|
||||
|
||||
/**
|
||||
* Prevent captive for players that match a predicate.
|
||||
*
|
||||
* @param predicate The predicate. Returns true when the slot should not be captive.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder notCaptiveFor(@NotNull Predicate<Player> predicate);
|
||||
|
||||
/**
|
||||
* Modify the ItemStack.
|
||||
*
|
||||
@@ -130,7 +140,17 @@ public interface SlotBuilder {
|
||||
*
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder setCaptive();
|
||||
default SlotBuilder setCaptive() {
|
||||
return setCaptive(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set slot to be a captive slot.
|
||||
*
|
||||
* @param fromEmpty If an item with the same output as the rendered item counts as captive.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder setCaptive(boolean fromEmpty);
|
||||
|
||||
/**
|
||||
* Build the slot.
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.placeholder.AdditionalPlayer;
|
||||
import com.willfp.eco.core.placeholder.InjectablePlaceholder;
|
||||
import com.willfp.eco.core.placeholder.Placeholder;
|
||||
import com.willfp.eco.core.placeholder.PlaceholderInjectable;
|
||||
@@ -11,11 +12,13 @@ import com.willfp.eco.core.placeholder.PlayerPlaceholder;
|
||||
import com.willfp.eco.core.placeholder.PlayerStaticPlaceholder;
|
||||
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder;
|
||||
import com.willfp.eco.core.placeholder.StaticPlaceholder;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -23,6 +26,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Class to handle placeholder integrations.
|
||||
@@ -56,11 +61,17 @@ public final class PlaceholderManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<InjectablePlaceholder> getPlaceholderInjections() {
|
||||
public @NotNull
|
||||
List<InjectablePlaceholder> getPlaceholderInjections() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The default PlaceholderAPI pattern; brought in for compatibility.
|
||||
*/
|
||||
private static final Pattern PATTERN = Pattern.compile("[%]([^%]+)[%]");
|
||||
|
||||
/**
|
||||
* Register a new placeholder integration.
|
||||
*
|
||||
@@ -192,7 +203,45 @@ public final class PlaceholderManager {
|
||||
public static String translatePlaceholders(@NotNull final String text,
|
||||
@Nullable final Player player,
|
||||
@NotNull final PlaceholderInjectable context) {
|
||||
return translatePlaceholders(text, player, context, new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate all placeholders with respect to a player.
|
||||
*
|
||||
* @param text The text that may contain placeholders to translate.
|
||||
* @param player The player to translate the placeholders with respect to.
|
||||
* @param context The injectable context.
|
||||
* @param additionalPlayers Additional players to translate placeholders for.
|
||||
* @return The text, translated.
|
||||
*/
|
||||
public static String translatePlaceholders(@NotNull final String text,
|
||||
@Nullable final Player player,
|
||||
@NotNull final PlaceholderInjectable context,
|
||||
@NotNull final Collection<AdditionalPlayer> additionalPlayers) {
|
||||
String processed = text;
|
||||
|
||||
// Prevent running 2 scans if there are no additional players.
|
||||
if (!additionalPlayers.isEmpty()) {
|
||||
List<String> found = findPlaceholdersIn(text);
|
||||
|
||||
for (AdditionalPlayer additionalPlayer : additionalPlayers) {
|
||||
for (String placeholder : found) {
|
||||
String prefix = "%" + additionalPlayer.getIdentifier() + "_";
|
||||
|
||||
if (placeholder.startsWith(prefix)) {
|
||||
processed = processed.replace(
|
||||
placeholder,
|
||||
translatePlaceholders(
|
||||
"%" + StringUtils.removePrefix(prefix, placeholder),
|
||||
additionalPlayer.getPlayer()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PlaceholderIntegration integration : REGISTERED_INTEGRATIONS) {
|
||||
processed = integration.translate(processed, player);
|
||||
}
|
||||
@@ -214,12 +263,21 @@ public final class PlaceholderManager {
|
||||
* @return The placeholders.
|
||||
*/
|
||||
public static List<String> findPlaceholdersIn(@NotNull final String text) {
|
||||
List<String> found = new ArrayList<>();
|
||||
Set<String> found = new HashSet<>();
|
||||
|
||||
// Mock PAPI for those without it installed
|
||||
if (REGISTERED_INTEGRATIONS.isEmpty()) {
|
||||
Matcher matcher = PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
found.add(matcher.group());
|
||||
}
|
||||
}
|
||||
|
||||
for (PlaceholderIntegration integration : REGISTERED_INTEGRATIONS) {
|
||||
found.addAll(integration.findPlaceholdersIn(text));
|
||||
}
|
||||
|
||||
return found;
|
||||
return new ArrayList<>(found);
|
||||
}
|
||||
|
||||
private record EntryWithPlayer(@NotNull PlayerPlaceholder entry,
|
||||
|
||||
@@ -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.Eco;
|
||||
import com.willfp.eco.core.fast.FastItemStack;
|
||||
import com.willfp.eco.core.items.args.LookupArgParser;
|
||||
import com.willfp.eco.core.items.provider.ItemProvider;
|
||||
@@ -185,6 +186,10 @@ public final class Items {
|
||||
*/
|
||||
@NotNull
|
||||
public static TestableItem lookup(@NotNull final String key) {
|
||||
if (key.startsWith("{")) {
|
||||
return Eco.getHandler().getSNBTHandler().createTestable(key);
|
||||
}
|
||||
|
||||
return ITEMS_LOOKUP_HANDLER.parseKey(key);
|
||||
}
|
||||
|
||||
@@ -222,7 +227,10 @@ public final class Items {
|
||||
|
||||
if (part == null && PROVIDERS.containsKey(namespace)) {
|
||||
ItemProvider provider = PROVIDERS.get(namespace);
|
||||
item = provider.provideForKey(keyID);
|
||||
|
||||
String reformattedKey = keyID.replace("__", ":");
|
||||
|
||||
item = provider.provideForKey(reformattedKey);
|
||||
if (item instanceof EmptyTestableItem || item == null) {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
@@ -517,6 +525,28 @@ public final class Items {
|
||||
return fis.unwrap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert item to SNBT.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The NBT string.
|
||||
*/
|
||||
@NotNull
|
||||
public static String toSNBT(@NotNull final ItemStack itemStack) {
|
||||
return Eco.getHandler().getSNBTHandler().toSNBT(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item from SNBT.
|
||||
*
|
||||
* @param snbt The NBT string.
|
||||
* @return The ItemStack, or null if invalid.
|
||||
*/
|
||||
@Nullable
|
||||
public static ItemStack fromSNBT(@NotNull final String snbt) {
|
||||
return Eco.getHandler().getSNBTHandler().fromSNBT(snbt);
|
||||
}
|
||||
|
||||
private Items() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.core.items;
|
||||
|
||||
import com.willfp.eco.core.Eco;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* API to handle SNBT conversion.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
@Eco.HandlerComponent
|
||||
public interface SNBTHandler {
|
||||
/**
|
||||
* Get item from SNBT.
|
||||
*
|
||||
* @param snbt The NBT string.
|
||||
* @return The ItemStack, or null if invalid.
|
||||
*/
|
||||
@Nullable
|
||||
ItemStack fromSNBT(@NotNull String snbt);
|
||||
|
||||
/**
|
||||
* Convert item to SNBT.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The NBT string.
|
||||
*/
|
||||
@NotNull
|
||||
String toSNBT(@NotNull ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Make TestableItem from SNBT.
|
||||
*
|
||||
* @param snbt The NBT string.
|
||||
* @return The TestableItem.
|
||||
*/
|
||||
@NotNull
|
||||
TestableItem createTestable(@NotNull String snbt);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.willfp.eco.core.placeholder;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An additional player with an identifier to parse placeholders for the player.
|
||||
*/
|
||||
public class AdditionalPlayer {
|
||||
/**
|
||||
* The player.
|
||||
*/
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* The identifier.
|
||||
*/
|
||||
private final String identifier;
|
||||
|
||||
/**
|
||||
* Create a new additional player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param identifier The identifier.
|
||||
*/
|
||||
public AdditionalPlayer(@NotNull final Player player,
|
||||
@NotNull final String identifier) {
|
||||
this.player = player;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player.
|
||||
*
|
||||
* @return The player.
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return The identifier.
|
||||
*/
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,8 @@ public final class ProxyConstants {
|
||||
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
|
||||
"v1_17_R1",
|
||||
"v1_18_R1",
|
||||
"v1_18_R2"
|
||||
"v1_18_R2",
|
||||
"v1_19_R1"
|
||||
);
|
||||
|
||||
private ProxyConstants() {
|
||||
|
||||
@@ -96,50 +96,53 @@ public final class ShapedCraftingRecipe extends PluginDependent<EcoPlugin> imple
|
||||
shapedRecipe.setIngredient(character, parts.get(i).getItem().getType());
|
||||
}
|
||||
|
||||
ShapedRecipe displayedRecipe = new ShapedRecipe(this.getDisplayedKey(), this.getOutput());
|
||||
displayedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (parts.get(i) instanceof EmptyTestableItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
|
||||
List<TestableItem> items = new ArrayList<>();
|
||||
if (parts.get(i) instanceof GroupedTestableItems group) {
|
||||
items.addAll(group.getChildren());
|
||||
} else {
|
||||
items.add(parts.get(i));
|
||||
}
|
||||
|
||||
List<ItemStack> displayedItems = new ArrayList<>();
|
||||
|
||||
for (TestableItem testableItem : items) {
|
||||
if (testableItem instanceof TestableStack) {
|
||||
ItemStack item = testableItem.getItem().clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
assert lore != null;
|
||||
lore.add("");
|
||||
String add = Eco.getHandler().getEcoPlugin().getLangYml().getFormattedString("multiple-in-craft");
|
||||
add = add.replace("%amount%", String.valueOf(item.getAmount()));
|
||||
lore.add(add);
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
displayedItems.add(item);
|
||||
} else {
|
||||
displayedItems.add(testableItem.getItem());
|
||||
if (Eco.getHandler().getEcoPlugin().getConfigYml().getBool("displayed-recipes")) {
|
||||
ShapedRecipe displayedRecipe = new ShapedRecipe(this.getDisplayedKey(), this.getOutput());
|
||||
displayedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (parts.get(i) instanceof EmptyTestableItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
|
||||
List<TestableItem> items = new ArrayList<>();
|
||||
if (parts.get(i) instanceof GroupedTestableItems group) {
|
||||
items.addAll(group.getChildren());
|
||||
} else {
|
||||
items.add(parts.get(i));
|
||||
}
|
||||
|
||||
List<ItemStack> displayedItems = new ArrayList<>();
|
||||
|
||||
for (TestableItem testableItem : items) {
|
||||
if (testableItem instanceof TestableStack) {
|
||||
ItemStack item = testableItem.getItem().clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
assert lore != null;
|
||||
lore.add("");
|
||||
String add = Eco.getHandler().getEcoPlugin().getLangYml().getFormattedString("multiple-in-craft");
|
||||
add = add.replace("%amount%", String.valueOf(item.getAmount()));
|
||||
lore.add(add);
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
displayedItems.add(item);
|
||||
} else {
|
||||
displayedItems.add(testableItem.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(displayedItems));
|
||||
}
|
||||
|
||||
displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(displayedItems));
|
||||
Bukkit.getServer().addRecipe(displayedRecipe);
|
||||
}
|
||||
|
||||
Bukkit.getServer().addRecipe(shapedRecipe);
|
||||
Bukkit.getServer().addRecipe(displayedRecipe);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,43 +101,46 @@ public final class ShapelessCraftingRecipe extends PluginDependent<EcoPlugin> im
|
||||
shapelessRecipe.addIngredient(part.getItem().getType());
|
||||
}
|
||||
|
||||
ShapelessRecipe displayedRecipe = new ShapelessRecipe(this.getDisplayedKey(), this.getOutput());
|
||||
for (TestableItem part : parts) {
|
||||
List<TestableItem> items = new ArrayList<>();
|
||||
if (part instanceof GroupedTestableItems group) {
|
||||
items.addAll(group.getChildren());
|
||||
} else {
|
||||
items.add(part);
|
||||
}
|
||||
|
||||
List<ItemStack> displayedItems = new ArrayList<>();
|
||||
|
||||
for (TestableItem testableItem : items) {
|
||||
if (testableItem instanceof TestableStack) {
|
||||
ItemStack item = testableItem.getItem().clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
assert lore != null;
|
||||
lore.add("");
|
||||
String add = Eco.getHandler().getEcoPlugin().getLangYml().getFormattedString("multiple-in-craft");
|
||||
add = add.replace("%amount%", String.valueOf(item.getAmount()));
|
||||
lore.add(add);
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
displayedItems.add(item);
|
||||
if (Eco.getHandler().getEcoPlugin().getConfigYml().getBool("displayed-recipes")) {
|
||||
ShapelessRecipe displayedRecipe = new ShapelessRecipe(this.getDisplayedKey(), this.getOutput());
|
||||
for (TestableItem part : parts) {
|
||||
List<TestableItem> items = new ArrayList<>();
|
||||
if (part instanceof GroupedTestableItems group) {
|
||||
items.addAll(group.getChildren());
|
||||
} else {
|
||||
displayedItems.add(testableItem.getItem());
|
||||
items.add(part);
|
||||
}
|
||||
|
||||
List<ItemStack> displayedItems = new ArrayList<>();
|
||||
|
||||
for (TestableItem testableItem : items) {
|
||||
if (testableItem instanceof TestableStack) {
|
||||
ItemStack item = testableItem.getItem().clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
assert lore != null;
|
||||
lore.add("");
|
||||
String add = Eco.getHandler().getEcoPlugin().getLangYml().getFormattedString("multiple-in-craft");
|
||||
add = add.replace("%amount%", String.valueOf(item.getAmount()));
|
||||
lore.add(add);
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
displayedItems.add(item);
|
||||
} else {
|
||||
displayedItems.add(testableItem.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
displayedRecipe.addIngredient(new RecipeChoice.ExactChoice(displayedItems));
|
||||
}
|
||||
|
||||
displayedRecipe.addIngredient(new RecipeChoice.ExactChoice(displayedItems));
|
||||
Bukkit.getServer().addRecipe(displayedRecipe);
|
||||
}
|
||||
|
||||
Bukkit.getServer().addRecipe(shapelessRecipe);
|
||||
Bukkit.getServer().addRecipe(displayedRecipe);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu;
|
||||
import com.willfp.eco.core.tuples.Pair;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Utilities / API methods for menus.
|
||||
*/
|
||||
public final class MenuUtils {
|
||||
/**
|
||||
* The menu supplier.
|
||||
*/
|
||||
private static Function<Player, Menu> menuGetter = null;
|
||||
|
||||
/**
|
||||
* Convert 0-53 slot to row and column pair.
|
||||
*
|
||||
@@ -20,6 +32,40 @@ public final class MenuUtils {
|
||||
return new Pair<>(row + 1, column + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert row and column to 0-53 slot.
|
||||
*
|
||||
* @param row The row.
|
||||
* @param column The column.
|
||||
* @return The slot.
|
||||
*/
|
||||
public static int rowColumnToSlot(final int row, final int column) {
|
||||
return (column - 1) + ((row - 1) * 9);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player's open menu.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return The menu, or null if none open.
|
||||
*/
|
||||
@Nullable
|
||||
public static Menu getOpenMenu(@NotNull final Player player) {
|
||||
return menuGetter.apply(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the tps supplier function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static void initialize(@NotNull final Function<Player, Menu> function) {
|
||||
Validate.isTrue(menuGetter == null, "Already initialized!");
|
||||
|
||||
menuGetter = function;
|
||||
}
|
||||
|
||||
private MenuUtils() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.willfp.eco.core.placeholder.AdditionalPlayer;
|
||||
import com.willfp.eco.core.placeholder.InjectablePlaceholder;
|
||||
import com.willfp.eco.core.placeholder.PlaceholderInjectable;
|
||||
import com.willfp.eco.core.placeholder.StaticPlaceholder;
|
||||
@@ -11,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -263,7 +265,8 @@ public final class NumberUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<InjectablePlaceholder> getPlaceholderInjections() {
|
||||
public @NotNull
|
||||
List<InjectablePlaceholder> getPlaceholderInjections() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
});
|
||||
@@ -282,7 +285,7 @@ public final class NumberUtils {
|
||||
public static double evaluateExpression(@NotNull final String expression,
|
||||
@Nullable final Player player,
|
||||
@NotNull final Iterable<StaticPlaceholder> statics) {
|
||||
return crunch.evaluate(expression, player, new PlaceholderInjectable() {
|
||||
return evaluateExpression(expression, player, new PlaceholderInjectable() {
|
||||
@Override
|
||||
public void clearInjectedPlaceholders() {
|
||||
// Do nothing.
|
||||
@@ -304,13 +307,29 @@ public final class NumberUtils {
|
||||
*
|
||||
* @param expression The expression.
|
||||
* @param player The player.
|
||||
* @param context The injectable placeholders.
|
||||
* @param context The injectable placeholders.
|
||||
* @return The value of the expression, or zero if invalid.
|
||||
*/
|
||||
public static double evaluateExpression(@NotNull final String expression,
|
||||
@Nullable final Player player,
|
||||
@NotNull final PlaceholderInjectable context) {
|
||||
return crunch.evaluate(expression, player, context);
|
||||
return evaluateExpression(expression, player, context, new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate an expression with respect to a player (for placeholders).
|
||||
*
|
||||
* @param expression The expression.
|
||||
* @param player The player.
|
||||
* @param context The injectable placeholders.
|
||||
* @param additionalPlayers Additional players to parse placeholders for.
|
||||
* @return The value of the expression, or zero if invalid.
|
||||
*/
|
||||
public static double evaluateExpression(@NotNull final String expression,
|
||||
@Nullable final Player player,
|
||||
@NotNull final PlaceholderInjectable context,
|
||||
@NotNull final Collection<AdditionalPlayer> additionalPlayers) {
|
||||
return crunch.evaluate(expression, player, context, additionalPlayers);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,14 +351,16 @@ public final class NumberUtils {
|
||||
/**
|
||||
* Evaluate an expression.
|
||||
*
|
||||
* @param expression The expression.
|
||||
* @param player The player.
|
||||
* @param injectable The injectable placeholders.
|
||||
* @param expression The expression.
|
||||
* @param player The player.
|
||||
* @param injectable The injectable placeholders.
|
||||
* @param additionalPlayers The additional players.
|
||||
* @return The value of the expression, or zero if invalid.
|
||||
*/
|
||||
double evaluate(@NotNull String expression,
|
||||
@Nullable Player player,
|
||||
@NotNull PlaceholderInjectable injectable);
|
||||
@NotNull PlaceholderInjectable injectable,
|
||||
@NotNull Collection<AdditionalPlayer> additionalPlayers);
|
||||
}
|
||||
|
||||
private NumberUtils() {
|
||||
|
||||
@@ -43,6 +43,7 @@ public final class StringUtils {
|
||||
.add(Pattern.compile("<G#([0-9A-Fa-f]{6})>(.*?)</G#([0-9A-Fa-f]{6})>", Pattern.CASE_INSENSITIVE))
|
||||
.add(Pattern.compile("<#:([0-9A-Fa-f]{6})>(.*?)</#:([0-9A-Fa-f]{6})>"))
|
||||
.add(Pattern.compile("\\{#:([0-9A-Fa-f]{6})}(.*?)\\{/#:([0-9A-Fa-f]{6})}"))
|
||||
.add(Pattern.compile("\\{#([0-9A-Fa-f]{6})>}(.*?)\\{#([0-9A-Fa-f]{6})<}"))
|
||||
.build();
|
||||
|
||||
/**
|
||||
|
||||
@@ -152,6 +152,20 @@ public final class VectorUtils {
|
||||
return vectors.toArray(new Vector[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if a vector is a safe velocity.
|
||||
*
|
||||
* @param vec The vector to check.
|
||||
* @return If safe.
|
||||
*/
|
||||
public static boolean isSafeVelocity(@NotNull final Vector vec) {
|
||||
double x = Math.abs(vec.getX());
|
||||
double y = Math.abs(vec.getY());
|
||||
double z = Math.abs(vec.getZ());
|
||||
|
||||
return x < 4 && y < 4 && z < 4;
|
||||
}
|
||||
|
||||
private VectorUtils() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ fun CommandBase.addSubcommand(
|
||||
}
|
||||
|
||||
/**
|
||||
* Kotlin builder for commands.
|
||||
* Inherits plugin, permission, players only.
|
||||
* Kotlin builder for commands. Inherits plugin, permission, players
|
||||
* only.
|
||||
*
|
||||
* @param name The command name.
|
||||
* @param init The builder.
|
||||
|
||||
@@ -4,9 +4,7 @@ package com.willfp.eco.core.config
|
||||
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
|
||||
/**
|
||||
* Helper class to create configs with a kotlin DSL.
|
||||
*/
|
||||
/** Helper class to create configs with a kotlin DSL. */
|
||||
class DSLConfig internal constructor(type: ConfigType) : TransientConfig(emptyMap(), type) {
|
||||
/**
|
||||
* Map a key to a value.
|
||||
|
||||
@@ -5,47 +5,33 @@ package com.willfp.eco.core.data
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
|
||||
/**
|
||||
* @see ExtendedPersistentDataContainer.set
|
||||
*/
|
||||
/** @see ExtendedPersistentDataContainer.set */
|
||||
fun <T : Any, Z : Any> PersistentDataContainer.set(key: String, dataType: PersistentDataType<T, Z>, value: Z) =
|
||||
ExtendedPersistentDataContainer.extend(this).set(key, dataType, value)
|
||||
|
||||
/**
|
||||
* @see ExtendedPersistentDataContainer.has
|
||||
*/
|
||||
/** @see ExtendedPersistentDataContainer.has */
|
||||
fun <T : Any, Z : Any> PersistentDataContainer.has(key: String, dataType: PersistentDataType<T, Z>): Boolean =
|
||||
ExtendedPersistentDataContainer.extend(this).has(key, dataType)
|
||||
|
||||
/**
|
||||
* @see ExtendedPersistentDataContainer.get
|
||||
*/
|
||||
/** @see ExtendedPersistentDataContainer.get */
|
||||
fun <T : Any, Z : Any> PersistentDataContainer.get(key: String, dataType: PersistentDataType<T, Z>): Z? =
|
||||
ExtendedPersistentDataContainer.extend(this).get(key, dataType)
|
||||
|
||||
/**
|
||||
* @see ExtendedPersistentDataContainer.getOrDefault
|
||||
*/
|
||||
/** @see ExtendedPersistentDataContainer.getOrDefault */
|
||||
fun <T : Any, Z : Any> PersistentDataContainer.getOrDefault(
|
||||
key: String,
|
||||
dataType: PersistentDataType<T, Z>,
|
||||
defaultValue: Z
|
||||
): Z = ExtendedPersistentDataContainer.extend(this).getOrDefault(key, dataType, defaultValue)
|
||||
|
||||
/**
|
||||
* @see ExtendedPersistentDataContainer.getAllKeys
|
||||
*/
|
||||
/** @see ExtendedPersistentDataContainer.getAllKeys */
|
||||
fun PersistentDataContainer.getAllKeys(): Set<String> =
|
||||
ExtendedPersistentDataContainer.extend(this).allKeys
|
||||
|
||||
/**
|
||||
* @see ExtendedPersistentDataContainer.remove
|
||||
*/
|
||||
/** @see ExtendedPersistentDataContainer.remove */
|
||||
fun PersistentDataContainer.remove(key: String) =
|
||||
ExtendedPersistentDataContainer.extend(this).remove(key)
|
||||
|
||||
/**
|
||||
* Create a new PDC without the need for an adapter context.
|
||||
*/
|
||||
/** Create a new PDC without the need for an adapter context. */
|
||||
fun newPersistentDataContainer() =
|
||||
ExtendedPersistentDataContainer.create().base
|
||||
|
||||
@@ -5,14 +5,10 @@ package com.willfp.eco.core.data
|
||||
import org.bukkit.OfflinePlayer
|
||||
import org.bukkit.Server
|
||||
|
||||
/**
|
||||
* @see PlayerProfile.load
|
||||
*/
|
||||
/** @see PlayerProfile.load */
|
||||
val OfflinePlayer.profile: PlayerProfile
|
||||
get() = PlayerProfile.load(this)
|
||||
|
||||
/**
|
||||
* @see ServerProfile.load
|
||||
*/
|
||||
/** @see ServerProfile.load */
|
||||
val Server.profile: ServerProfile
|
||||
get() = ServerProfile.load()
|
||||
|
||||
@@ -5,8 +5,6 @@ package com.willfp.eco.core.entities
|
||||
import com.willfp.eco.core.entities.ai.EntityController
|
||||
import org.bukkit.entity.Mob
|
||||
|
||||
/**
|
||||
* @see EntityController.getFor
|
||||
*/
|
||||
/** @see EntityController.getFor */
|
||||
val <T : Mob> T.controller: EntityController<T>
|
||||
get() = EntityController.getFor(this)
|
||||
|
||||
@@ -4,8 +4,6 @@ package com.willfp.eco.core.fast
|
||||
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
/**
|
||||
* @see FastItemStack.wrap
|
||||
*/
|
||||
/** @see FastItemStack.wrap */
|
||||
fun ItemStack.fast(): FastItemStack =
|
||||
FastItemStack.wrap(this)
|
||||
|
||||
@@ -6,41 +6,36 @@ import com.willfp.eco.core.gui.menu.Menu
|
||||
import com.willfp.eco.core.gui.menu.MenuBuilder
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import com.willfp.eco.core.gui.slot.SlotBuilder
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
/**
|
||||
* @see SlotBuilder.onLeftClick
|
||||
*/
|
||||
/** @see SlotBuilder.onLeftClick */
|
||||
fun SlotBuilder.onLeftClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
|
||||
this.onLeftClick { a, b, c -> action(a, b, c) }
|
||||
|
||||
/**
|
||||
* @see SlotBuilder.onRightClick
|
||||
*/
|
||||
/** @see SlotBuilder.onRightClick */
|
||||
fun SlotBuilder.onRightClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
|
||||
this.onRightClick { a, b, c -> action(a, b, c) }
|
||||
|
||||
/**
|
||||
* @see SlotBuilder.onShiftLeftClick
|
||||
*/
|
||||
/** @see SlotBuilder.onShiftLeftClick */
|
||||
fun SlotBuilder.onShiftLeftClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
|
||||
this.onShiftLeftClick { a, b, c -> action(a, b, c) }
|
||||
|
||||
/**
|
||||
* @see SlotBuilder.onShiftRightClick
|
||||
*/
|
||||
/** @see SlotBuilder.onShiftRightClick */
|
||||
fun SlotBuilder.onShiftRightClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
|
||||
this.onShiftRightClick { a, b, c -> action(a, b, c) }
|
||||
|
||||
/**
|
||||
* @see SlotBuilder.onShiftRightClick
|
||||
*/
|
||||
/** @see SlotBuilder.onShiftRightClick */
|
||||
fun SlotBuilder.onMiddleClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
|
||||
this.onMiddleClick { a, b, c -> action(a, b, c) }
|
||||
|
||||
/** @see SlotBuilder.notCaptiveFor */
|
||||
fun SlotBuilder.notCaptiveFor(test: (Player) -> Boolean): SlotBuilder =
|
||||
this.notCaptiveFor { test(it) }
|
||||
|
||||
/**
|
||||
* @see SlotBuilder.setModifier
|
||||
* @deprecated Use SlotUpdater instead.
|
||||
@@ -50,15 +45,32 @@ fun SlotBuilder.onMiddleClick(action: (InventoryClickEvent, Slot, Menu) -> Unit)
|
||||
fun SlotBuilder.setModifier(action: (Player, Menu, ItemStack) -> Unit): SlotBuilder =
|
||||
this.setUpdater { a, b, c -> c.apply { action(a, b, c) } }
|
||||
|
||||
/**
|
||||
* @see SlotBuilder.setUpdater
|
||||
*/
|
||||
/** @see SlotBuilder.setUpdater */
|
||||
fun SlotBuilder.setUpdater(action: (Player, Menu, ItemStack) -> ItemStack): SlotBuilder =
|
||||
this.setUpdater { a, b, c -> action(a, b, c) }
|
||||
|
||||
/**
|
||||
* Kotlin builder for slots.
|
||||
*/
|
||||
/** Kotlin builder for slots. */
|
||||
fun captiveSlot(): Slot = Slot.builder().setCaptive().build()
|
||||
|
||||
/** Kotlin builder for slots. */
|
||||
fun captiveSlot(
|
||||
init: SlotBuilder.() -> Unit
|
||||
): Slot {
|
||||
val builder = Slot.builder().setCaptive()
|
||||
init(builder)
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
/** Kotlin builder for slots. */
|
||||
fun slot(
|
||||
init: SlotBuilder.() -> Unit
|
||||
): Slot {
|
||||
val builder = Slot.builder()
|
||||
init(builder)
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
/** Kotlin builder for slots. */
|
||||
fun slot(
|
||||
item: ItemStack,
|
||||
init: SlotBuilder.() -> Unit
|
||||
@@ -68,9 +80,17 @@ fun slot(
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* Kotlin builder for slots.
|
||||
*/
|
||||
/** Kotlin builder for slots. */
|
||||
fun slot(
|
||||
item: ItemStack
|
||||
): Slot = Slot.builder(item).build()
|
||||
|
||||
/** Kotlin builder for slots. */
|
||||
fun slot(
|
||||
item: TestableItem
|
||||
): Slot = Slot.builder(item.item).build()
|
||||
|
||||
/** Kotlin builder for slots. */
|
||||
fun slot(
|
||||
provider: (Player, Menu) -> ItemStack,
|
||||
init: SlotBuilder.() -> Unit
|
||||
@@ -80,27 +100,28 @@ fun slot(
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* @see MenuBuilder.onClose
|
||||
*/
|
||||
/** Kotlin builder for slots. */
|
||||
fun slot(
|
||||
provider: (Player, Menu) -> ItemStack
|
||||
): Slot = Slot.builder { a, b -> provider(a, b) }.build()
|
||||
|
||||
/** @see MenuBuilder.onClose */
|
||||
fun MenuBuilder.onClose(action: (InventoryCloseEvent, Menu) -> Unit): MenuBuilder =
|
||||
this.onClose { a, b -> action(a, b) }
|
||||
|
||||
/**
|
||||
* @see MenuBuilder.modify
|
||||
*/
|
||||
/** @see MenuBuilder.onOpen */
|
||||
fun MenuBuilder.onOpen(action: (Player, Menu) -> Unit): MenuBuilder =
|
||||
this.onOpen { a, b -> action(a, b) }
|
||||
|
||||
/** @see MenuBuilder.modify */
|
||||
fun MenuBuilder.modify(modifier: (MenuBuilder) -> Unit): MenuBuilder =
|
||||
this.modfiy { modifier(it) }
|
||||
|
||||
/**
|
||||
* @see MenuBuilder.onRender
|
||||
*/
|
||||
/** @see MenuBuilder.onRender */
|
||||
fun MenuBuilder.onRender(action: (Player, Menu) -> Unit): MenuBuilder =
|
||||
this.onRender { a, b -> action(a, b) }
|
||||
|
||||
/**
|
||||
* Kotlin builder for menus.
|
||||
*/
|
||||
/** Kotlin builder for menus. */
|
||||
fun menu(
|
||||
rows: Int,
|
||||
init: MenuBuilder.() -> Unit
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
@file:JvmName("EconomyExtensions")
|
||||
|
||||
package com.willfp.eco.core.integrations.economy
|
||||
|
||||
import org.bukkit.OfflinePlayer
|
||||
|
||||
/** @see EconomyManager */
|
||||
var OfflinePlayer.balance: Double
|
||||
get() = EconomyManager.getBalance(this)
|
||||
set(value) {
|
||||
if (value <= 0) {
|
||||
EconomyManager.removeMoney(this, this.balance)
|
||||
return
|
||||
}
|
||||
|
||||
val diff = this.balance - value
|
||||
|
||||
if (diff > 0) {
|
||||
EconomyManager.removeMoney(this, diff)
|
||||
} else if (diff < 0) {
|
||||
EconomyManager.giveMoney(this, -diff)
|
||||
}
|
||||
}
|
||||
@@ -6,21 +6,15 @@ import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
|
||||
/**
|
||||
* @see Items.toLookupString
|
||||
*/
|
||||
/** @see Items.toLookupString */
|
||||
fun ItemStack?.toLookupString(): String =
|
||||
Items.toLookupString(this)
|
||||
|
||||
/**
|
||||
* @see Items.mergeFrom
|
||||
*/
|
||||
/** @see Items.mergeFrom */
|
||||
fun ItemStack.mergeFrom(other: ItemStack): ItemStack =
|
||||
Items.mergeFrom(other, this)
|
||||
|
||||
/**
|
||||
* @see Items.mergeFrom
|
||||
*/
|
||||
/** @see Items.mergeFrom */
|
||||
fun ItemMeta.mergeFrom(other: ItemMeta): ItemMeta =
|
||||
Items.mergeFrom(other, this)
|
||||
|
||||
@@ -34,8 +28,6 @@ var ItemStack.baseNBT: PersistentDataContainer
|
||||
Items.setBaseNBT(this, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Items.setBaseNBT
|
||||
*/
|
||||
/** @see Items.setBaseNBT */
|
||||
fun ItemStack.clearNBT() =
|
||||
Items.setBaseNBT(this, null)
|
||||
|
||||
@@ -5,8 +5,6 @@ package com.willfp.eco.util
|
||||
import org.bukkit.entity.Arrow
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
/**
|
||||
* @see ArrowUtils.getBow
|
||||
*/
|
||||
/** @see ArrowUtils.getBow */
|
||||
val Arrow.bow: ItemStack?
|
||||
get() = ArrowUtils.getBow(this)
|
||||
|
||||
@@ -4,8 +4,6 @@ package com.willfp.eco.util
|
||||
|
||||
import org.bukkit.block.Block
|
||||
|
||||
/**
|
||||
* @see ArrowUtils.getBow
|
||||
*/
|
||||
/** @see ArrowUtils.getBow */
|
||||
val Block.isPlayerPlaced: Boolean
|
||||
get() = BlockUtils.isPlayerPlaced(this)
|
||||
|
||||
@@ -5,14 +5,10 @@ package com.willfp.eco.util
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
/**
|
||||
* @see DurabilityUtils.damageItem
|
||||
*/
|
||||
/** @see DurabilityUtils.damageItem */
|
||||
fun ItemStack.damage(damage: Int) =
|
||||
DurabilityUtils.damageItem(this, damage)
|
||||
|
||||
/**
|
||||
* @see DurabilityUtils.damageItem
|
||||
*/
|
||||
/** @see DurabilityUtils.damageItem */
|
||||
fun ItemStack.damage(damage: Int, player: Player) =
|
||||
DurabilityUtils.damageItem(player, this, damage)
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
package com.willfp.eco.util
|
||||
|
||||
/**
|
||||
* @see ListUtils.listToFrequencyMap
|
||||
*/
|
||||
/** @see ListUtils.listToFrequencyMap */
|
||||
fun <T> List<T>.toFrequencyMap(): Map<T, Int> =
|
||||
ListUtils.listToFrequencyMap(this)
|
||||
|
||||
/**
|
||||
* @see ListUtils.containsIgnoreCase
|
||||
*/
|
||||
/** @see ListUtils.containsIgnoreCase */
|
||||
fun Iterable<String>.containsIgnoreCase(element: String): Boolean =
|
||||
ListUtils.containsIgnoreCase(this, element)
|
||||
|
||||
/**
|
||||
* @see ListUtils.create2DList
|
||||
*/
|
||||
/** @see ListUtils.create2DList */
|
||||
fun <T> create2DList(rows: Int, columns: Int): MutableList<MutableList<T>> =
|
||||
ListUtils.create2DList(rows, columns)
|
||||
|
||||
/** @see ListUtils.toSingletonList */
|
||||
fun <T> T.toSingletonList(): List<T> =
|
||||
ListUtils.toSingletonList(this)
|
||||
|
||||
10
eco-api/src/main/kotlin/com/willfp/eco/util/MenuUtils.kt
Normal file
10
eco-api/src/main/kotlin/com/willfp/eco/util/MenuUtils.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
@file:JvmName("MenuUtilsExtensions")
|
||||
|
||||
package com.willfp.eco.util
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
/** @see MenuUtils.getOpenMenu */
|
||||
val Player.openMenu: Menu?
|
||||
get() = MenuUtils.getOpenMenu(this)
|
||||
@@ -4,26 +4,18 @@ package com.willfp.eco.util
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
|
||||
/**
|
||||
* @see NamespacedKeyUtils.fromString
|
||||
*/
|
||||
/** @see NamespacedKeyUtils.fromString */
|
||||
fun namespacedKeyOf(string: String) =
|
||||
NamespacedKeyUtils.fromString(string)
|
||||
|
||||
/**
|
||||
* @see NamespacedKeyUtils.fromString
|
||||
*/
|
||||
/** @see NamespacedKeyUtils.fromString */
|
||||
fun safeNamespacedKeyOf(string: String) =
|
||||
NamespacedKeyUtils.fromStringOrNull(string)
|
||||
|
||||
/**
|
||||
* @see NamespacedKeyUtils.create
|
||||
*/
|
||||
/** @see NamespacedKeyUtils.create */
|
||||
fun namespacedKeyOf(namespace: String, key: String) =
|
||||
NamespacedKeyUtils.create(namespace, key)
|
||||
|
||||
/**
|
||||
* @see EcoPlugin.namespacedKeyFactory
|
||||
*/
|
||||
/** @see EcoPlugin.namespacedKeyFactory */
|
||||
fun namespacedKeyOf(plugin: EcoPlugin, key: String) =
|
||||
plugin.namespacedKeyFactory.create(key)
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
package com.willfp.eco.util
|
||||
|
||||
/**
|
||||
* @see NumberUtils.toNumeral
|
||||
*/
|
||||
/** @see NumberUtils.toNumeral */
|
||||
fun Number.toNumeral(): String =
|
||||
NumberUtils.toNumeral(this.toInt())
|
||||
|
||||
@@ -8,32 +8,22 @@ import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
/**
|
||||
* @see PlayerUtils.getSavedDisplayName
|
||||
*/
|
||||
/** @see PlayerUtils.getSavedDisplayName */
|
||||
val OfflinePlayer.savedDisplayName: String
|
||||
get() = PlayerUtils.getSavedDisplayName(this)
|
||||
|
||||
/**
|
||||
* @see PlayerUtils.getAudience
|
||||
*/
|
||||
/** @see PlayerUtils.getAudience */
|
||||
fun Player.asAudience(): Audience =
|
||||
PlayerUtils.getAudience(this)
|
||||
|
||||
/**
|
||||
* @see PlayerUtils.getAudience
|
||||
*/
|
||||
/** @see PlayerUtils.getAudience */
|
||||
fun CommandSender.asAudience(): Audience =
|
||||
PlayerUtils.getAudience(this)
|
||||
|
||||
/**
|
||||
* @see PlayerUtils.runExempted
|
||||
*/
|
||||
/** @see PlayerUtils.runExempted */
|
||||
fun Player.runExempted(action: () -> Unit) =
|
||||
PlayerUtils.runExempted(this, action)
|
||||
|
||||
/**
|
||||
* @see PlayerUtils.tryAsPlayer
|
||||
*/
|
||||
/** @see PlayerUtils.tryAsPlayer */
|
||||
fun Entity?.tryAsPlayer(): Player? =
|
||||
PlayerUtils.tryAsPlayer(this)
|
||||
|
||||
@@ -4,8 +4,6 @@ package com.willfp.eco.util
|
||||
|
||||
import org.bukkit.potion.PotionData
|
||||
|
||||
/**
|
||||
* @see PotionData.duration
|
||||
*/
|
||||
/** @see PotionData.duration */
|
||||
val PotionData.duration: Int
|
||||
get() = PotionUtils.getDuration(this)
|
||||
|
||||
@@ -4,8 +4,6 @@ package com.willfp.eco.util
|
||||
|
||||
import org.bukkit.Server
|
||||
|
||||
/**
|
||||
* @see ServerUtils.getTps
|
||||
*/
|
||||
/** @see ServerUtils.getTps */
|
||||
val Server.tps: Double
|
||||
get() = ServerUtils.getTps()
|
||||
|
||||
@@ -5,33 +5,23 @@ package com.willfp.eco.util
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
/**
|
||||
* @see StringUtils.toComponent
|
||||
*/
|
||||
/** @see StringUtils.toComponent */
|
||||
fun String.toComponent(): Component =
|
||||
StringUtils.toComponent(this)
|
||||
|
||||
/**
|
||||
* @see StringUtils.jsonToComponent
|
||||
*/
|
||||
/** @see StringUtils.jsonToComponent */
|
||||
fun String.jsonToComponent(): Component =
|
||||
StringUtils.jsonToComponent(this)
|
||||
|
||||
/**
|
||||
* @see StringUtils.toLegacy
|
||||
*/
|
||||
/** @see StringUtils.toLegacy */
|
||||
fun Component.toLegacy(): String =
|
||||
StringUtils.toLegacy(this)
|
||||
|
||||
/**
|
||||
* @see StringUtils.componentToJson
|
||||
*/
|
||||
/** @see StringUtils.componentToJson */
|
||||
fun Component.toJSON(): String =
|
||||
StringUtils.componentToJson(this)
|
||||
|
||||
/**
|
||||
* @see StringUtils.format
|
||||
*/
|
||||
/** @see StringUtils.format */
|
||||
fun String.formatEco(
|
||||
player: Player? = null,
|
||||
formatPlaceholders: Boolean = false
|
||||
@@ -41,9 +31,7 @@ fun String.formatEco(
|
||||
if (formatPlaceholders) StringUtils.FormatOption.WITH_PLACEHOLDERS else StringUtils.FormatOption.WITHOUT_PLACEHOLDERS
|
||||
)
|
||||
|
||||
/**
|
||||
* @see StringUtils.formatList
|
||||
*/
|
||||
/** @see StringUtils.formatList */
|
||||
fun List<String>.formatEco(
|
||||
player: Player? = null,
|
||||
formatPlaceholders: Boolean = false
|
||||
@@ -53,14 +41,10 @@ fun List<String>.formatEco(
|
||||
if (formatPlaceholders) StringUtils.FormatOption.WITH_PLACEHOLDERS else StringUtils.FormatOption.WITHOUT_PLACEHOLDERS
|
||||
)
|
||||
|
||||
/**
|
||||
* @see StringUtils.splitAround
|
||||
*/
|
||||
/** @see StringUtils.splitAround */
|
||||
fun String.splitAround(separator: String): Array<String> =
|
||||
StringUtils.splitAround(this, separator)
|
||||
|
||||
/**
|
||||
* @see StringUtils.toNiceString
|
||||
*/
|
||||
/** @see StringUtils.toNiceString */
|
||||
fun Any?.toNiceString(): String =
|
||||
StringUtils.toNiceString(this)
|
||||
|
||||
@@ -4,14 +4,14 @@ package com.willfp.eco.util
|
||||
|
||||
import org.bukkit.util.Vector
|
||||
|
||||
/**
|
||||
* @see VectorUtils.isFinite
|
||||
*/
|
||||
/** @see VectorUtils.isFinite */
|
||||
val Vector.isFinite: Boolean
|
||||
get() = VectorUtils.isFinite(this)
|
||||
|
||||
/**
|
||||
* @see VectorUtils.simplifyVector
|
||||
*/
|
||||
/** @see VectorUtils.simplifyVector */
|
||||
fun Vector.simplify(): Vector =
|
||||
VectorUtils.simplifyVector(this)
|
||||
|
||||
/** @see VectorUtils.isSafeVelocity */
|
||||
val Vector.isSafeVelocity: Boolean
|
||||
get() = VectorUtils.isSafeVelocity(this)
|
||||
|
||||
@@ -16,7 +16,7 @@ fun ConfigType.toMap(input: String?): Map<String, Any?> =
|
||||
fun ConfigType.toString(map: Map<String, Any?>): String =
|
||||
this.handler.toString(map)
|
||||
|
||||
fun Any?.constrainConfigTypes(type: ConfigType): Any? = when (this) {
|
||||
internal fun Any?.constrainConfigTypes(type: ConfigType): Any? = when (this) {
|
||||
is Map<*, *> -> EcoConfigSection(type, this.normalizeToConfig(type))
|
||||
is Iterable<*> -> {
|
||||
if (this.firstOrNull() == null) {
|
||||
@@ -31,7 +31,7 @@ fun Any?.constrainConfigTypes(type: ConfigType): Any? = when (this) {
|
||||
else -> this
|
||||
}
|
||||
|
||||
fun Map<*, *>.normalizeToConfig(type: ConfigType): Map<String, Any?> {
|
||||
internal fun Map<*, *>.normalizeToConfig(type: ConfigType): Map<String, Any?> {
|
||||
val building = mutableMapOf<String, Any?>()
|
||||
|
||||
for ((unprocessedKey, value) in this.entries) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.willfp.eco.internal.config
|
||||
import com.willfp.eco.core.config.ConfigType
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.core.placeholder.InjectablePlaceholder
|
||||
import com.willfp.eco.core.placeholder.StaticPlaceholder
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@@ -103,11 +104,13 @@ open class EcoConfig(
|
||||
}
|
||||
|
||||
override fun getSubsectionOrNull(path: String): Config? {
|
||||
return get(path) as? Config
|
||||
return (get(path) as? Config)?.apply { this.addInjectablePlaceholder(injections) }
|
||||
}
|
||||
|
||||
override fun getSubsectionsOrNull(path: String): List<Config>? {
|
||||
return (get(path) as? Iterable<Config>)?.toList()
|
||||
return (get(path) as? Iterable<Config>)
|
||||
?.map { it.apply { this.addInjectablePlaceholder(injections) } }
|
||||
?.toList()
|
||||
}
|
||||
|
||||
override fun getType(): ConfigType {
|
||||
@@ -135,7 +138,14 @@ open class EcoConfig(
|
||||
format: Boolean,
|
||||
option: StringUtils.FormatOption
|
||||
): String? {
|
||||
val string = get(path)?.toString() ?: return null
|
||||
var string = get(path)?.toString() ?: return null
|
||||
if (format && option == StringUtils.FormatOption.WITH_PLACEHOLDERS) {
|
||||
for (injection in placeholderInjections) {
|
||||
if (injection is StaticPlaceholder) {
|
||||
string = string.replace("%${injection.identifier}%", injection.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
return if (format) StringUtils.format(string, option) else string
|
||||
}
|
||||
|
||||
@@ -144,7 +154,18 @@ open class EcoConfig(
|
||||
format: Boolean,
|
||||
option: StringUtils.FormatOption
|
||||
): List<String>? {
|
||||
val strings = (get(path) as? Iterable<*>)?.map { it.toString() } ?: return null
|
||||
val strings = (get(path) as? Iterable<*>)?.map { it.toString() }?.toMutableList() ?: return null
|
||||
if (placeholderInjections.isNotEmpty() && format && option == StringUtils.FormatOption.WITH_PLACEHOLDERS) {
|
||||
strings.replaceAll {
|
||||
var string = it
|
||||
for (injection in placeholderInjections) {
|
||||
if (injection is StaticPlaceholder) {
|
||||
string = string.replace("%${injection.identifier}%", injection.value)
|
||||
}
|
||||
}
|
||||
string
|
||||
}
|
||||
}
|
||||
return if (format) StringUtils.formatList(strings, option) else strings
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.display.Display
|
||||
import com.willfp.eco.core.display.DisplayHandler
|
||||
import com.willfp.eco.core.display.DisplayModule
|
||||
import com.willfp.eco.core.display.DisplayProperties
|
||||
import com.willfp.eco.core.fast.fast
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.entity.Player
|
||||
@@ -32,13 +33,21 @@ class EcoDisplayHandler(plugin: EcoPlugin) : DisplayHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Display.revert(itemStack)
|
||||
|
||||
if (!itemStack.hasItemMeta()) {
|
||||
return itemStack
|
||||
}
|
||||
|
||||
val original = itemStack.clone()
|
||||
val inventory = player?.openInventory?.topInventory
|
||||
val inInventory = inventory?.contains(original) ?: false
|
||||
|
||||
val props = DisplayProperties(
|
||||
inInventory,
|
||||
inInventory && inventory?.holder == null,
|
||||
original
|
||||
)
|
||||
|
||||
for ((_, modules) in registeredModules) {
|
||||
for (module in modules) {
|
||||
@@ -48,6 +57,7 @@ class EcoDisplayHandler(plugin: EcoPlugin) : DisplayHandler {
|
||||
|
||||
if (player != null) {
|
||||
module.display(itemStack, player as Player?, *varargs)
|
||||
module.display(itemStack, player as Player?, props, *varargs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.internal.gui.menu
|
||||
|
||||
import com.willfp.eco.core.gui.menu.CloseHandler
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
import com.willfp.eco.core.gui.menu.OpenHandler
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import com.willfp.eco.internal.gui.slot.EcoSlot
|
||||
import com.willfp.eco.util.NamespacedKeyUtils
|
||||
@@ -19,7 +20,8 @@ class EcoMenu(
|
||||
val slots: List<MutableList<EcoSlot>>,
|
||||
private val title: String,
|
||||
private val onClose: CloseHandler,
|
||||
private val onRender: (Player, Menu) -> Unit
|
||||
private val onRender: (Player, Menu) -> Unit,
|
||||
private val onOpen: OpenHandler
|
||||
) : Menu {
|
||||
override fun getSlot(row: Int, column: Int): Slot {
|
||||
if (row < 1 || row > this.rows) {
|
||||
@@ -49,11 +51,14 @@ class EcoMenu(
|
||||
|
||||
player.openInventory(inventory)
|
||||
MenuHandler.registerInventory(inventory, this, player)
|
||||
onOpen.handle(player, this)
|
||||
inventory.asRenderedInventory()?.generateCaptive()
|
||||
return inventory
|
||||
}
|
||||
|
||||
fun handleClose(event: InventoryCloseEvent) {
|
||||
onClose.handle(event, this)
|
||||
event.inventory.asRenderedInventory()?.generateCaptive()
|
||||
MenuHandler.unregisterInventory(event.inventory)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.willfp.eco.internal.gui.menu
|
||||
import com.willfp.eco.core.gui.menu.CloseHandler
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
import com.willfp.eco.core.gui.menu.MenuBuilder
|
||||
import com.willfp.eco.core.gui.menu.OpenHandler
|
||||
import com.willfp.eco.core.gui.slot.FillerMask
|
||||
import com.willfp.eco.core.gui.slot.FillerSlot
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
@@ -21,6 +22,7 @@ class EcoMenuBuilder(private val rows: Int ) : MenuBuilder {
|
||||
private var maskSlots: List<MutableList<Slot?>>
|
||||
private val slots: List<MutableList<Slot?>> = ListUtils.create2DList(rows, 9)
|
||||
private var onClose = CloseHandler { _, _ -> }
|
||||
private var onOpen = OpenHandler { _, _ -> }
|
||||
private var onRender: (Player, Menu) -> Unit = { _, _ -> }
|
||||
|
||||
override fun setTitle(title: String): MenuBuilder {
|
||||
@@ -54,6 +56,11 @@ class EcoMenuBuilder(private val rows: Int ) : MenuBuilder {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun onOpen(action: OpenHandler): MenuBuilder {
|
||||
onOpen = action
|
||||
return this
|
||||
}
|
||||
|
||||
override fun onRender(action: BiConsumer<Player, Menu>): MenuBuilder {
|
||||
onRender = { a, b -> action.accept(a, b) }
|
||||
return this
|
||||
@@ -83,7 +90,7 @@ class EcoMenuBuilder(private val rows: Int ) : MenuBuilder {
|
||||
finalSlots.add(tempRow)
|
||||
}
|
||||
|
||||
return EcoMenu(rows, finalSlots, title, onClose, onRender)
|
||||
return EcoMenu(rows, finalSlots, title, onClose, onRender, onOpen)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -34,7 +34,7 @@ class MenuRenderedInventory(
|
||||
menu.runOnRender(player)
|
||||
}
|
||||
|
||||
private fun generateCaptive() {
|
||||
fun generateCaptive() {
|
||||
captiveItems.clear()
|
||||
for (i in 0 until inventory.size) {
|
||||
val (row, column) = MenuUtils.convertSlotToRowColumn(i)
|
||||
@@ -43,7 +43,17 @@ class MenuRenderedInventory(
|
||||
val renderedItem = slot.getItemStack(player)
|
||||
val itemStack = inventory.getItem(i) ?: continue
|
||||
|
||||
if (itemStack == renderedItem || itemStack.type.isAir || itemStack.amount == 0) {
|
||||
if (slot.isNotCaptiveFor(player)) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (!slot.isCaptiveFromEmpty) {
|
||||
if (itemStack == renderedItem) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (itemStack.type.isAir || itemStack.amount == 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -2,23 +2,36 @@ package com.willfp.eco.internal.gui.slot
|
||||
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotHandler
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotProvider
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class EcoCaptiveSlot(
|
||||
provider: SlotProvider
|
||||
provider: SlotProvider,
|
||||
private val captiveFromEmpty: Boolean,
|
||||
private val notCaptiveFor: (Player) -> Boolean
|
||||
) : EcoSlot(
|
||||
provider,
|
||||
allowMovingItem,
|
||||
allowMovingItem,
|
||||
allowMovingItem,
|
||||
allowMovingItem,
|
||||
allowMovingItem,
|
||||
captiveWithTest(notCaptiveFor),
|
||||
captiveWithTest(notCaptiveFor),
|
||||
captiveWithTest(notCaptiveFor),
|
||||
captiveWithTest(notCaptiveFor),
|
||||
captiveWithTest(notCaptiveFor),
|
||||
{ _, _, prev -> prev }
|
||||
) {
|
||||
override fun isCaptive(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun isCaptiveFromEmpty(): Boolean {
|
||||
return captiveFromEmpty
|
||||
}
|
||||
|
||||
override fun isNotCaptiveFor(player: Player): Boolean {
|
||||
return notCaptiveFor(player)
|
||||
}
|
||||
}
|
||||
|
||||
private val allowMovingItem = SlotHandler { event, _, _ ->
|
||||
event.isCancelled = false
|
||||
}
|
||||
private fun captiveWithTest(test: (Player) -> Boolean): SlotHandler {
|
||||
return SlotHandler { event, _, _ ->
|
||||
event.isCancelled = test(event.whoClicked as Player)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ open class EcoSlot(
|
||||
}
|
||||
|
||||
override fun getItemStack(player: Player): ItemStack {
|
||||
val menu = player.openInventory.topInventory.getMenu()!!
|
||||
val menu = player.openInventory.topInventory.getMenu() ?: return ItemStack(Material.AIR)
|
||||
val prev = provider.provide(player, menu)
|
||||
return updater.update(player, menu, prev) ?: ItemStack(Material.AIR)
|
||||
}
|
||||
|
||||
@@ -1,25 +1,39 @@
|
||||
package com.willfp.eco.internal.gui.slot
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import com.willfp.eco.core.gui.slot.SlotBuilder
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotHandler
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotProvider
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotUpdater
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import java.util.function.Predicate
|
||||
|
||||
internal object NoOpSlot : SlotHandler {
|
||||
override fun handle(event: InventoryClickEvent, slot: Slot, menu: Menu) {
|
||||
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is NoOpSlot
|
||||
}
|
||||
}
|
||||
|
||||
internal class NoOpForPlayer
|
||||
|
||||
class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
|
||||
private var captive = false
|
||||
private var captiveFromEmpty = false
|
||||
private var updater: SlotUpdater = SlotUpdater { player, menu, _ -> provider.provide(player, menu) }
|
||||
|
||||
private var onLeftClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onRightClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onShiftLeftClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onShiftRightClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onMiddleClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onLeftClick: SlotHandler = NoOpSlot
|
||||
private var onRightClick: SlotHandler = NoOpSlot
|
||||
private var onShiftLeftClick: SlotHandler = NoOpSlot
|
||||
private var onShiftRightClick: SlotHandler = NoOpSlot
|
||||
private var onMiddleClick: SlotHandler = NoOpSlot
|
||||
|
||||
private var notCaptiveFor: (Player) -> Boolean = { false }
|
||||
|
||||
override fun onLeftClick(action: SlotHandler): SlotBuilder {
|
||||
onLeftClick = action
|
||||
@@ -46,8 +60,14 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setCaptive(): SlotBuilder {
|
||||
override fun notCaptiveFor(predicate: Predicate<Player>): SlotBuilder {
|
||||
notCaptiveFor = { predicate.test(it) }
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setCaptive(fromEmpty: Boolean): SlotBuilder {
|
||||
captive = true
|
||||
captiveFromEmpty = fromEmpty
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -58,9 +78,21 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
|
||||
|
||||
override fun build(): Slot {
|
||||
return if (captive) {
|
||||
EcoCaptiveSlot(provider)
|
||||
EcoCaptiveSlot(
|
||||
provider,
|
||||
captiveFromEmpty,
|
||||
notCaptiveFor
|
||||
)
|
||||
} else {
|
||||
EcoSlot(provider, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick, updater)
|
||||
EcoSlot(
|
||||
provider,
|
||||
onLeftClick,
|
||||
onRightClick,
|
||||
onShiftLeftClick,
|
||||
onShiftRightClick,
|
||||
onMiddleClick,
|
||||
updater
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.3.5"
|
||||
id("io.papermc.paperweight.userdev") version "1.3.6"
|
||||
}
|
||||
|
||||
group = "com.willfp"
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.bukkit.inventory.ItemFlag
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import kotlin.experimental.and
|
||||
import kotlin.experimental.inv
|
||||
import kotlin.experimental.or
|
||||
|
||||
@Suppress("UsePropertyAccessSyntax")
|
||||
class EcoFastItemStack(
|
||||
@@ -149,35 +151,29 @@ class EcoFastItemStack(
|
||||
override fun getDisplayName(): String = displayNameComponent.toLegacy()
|
||||
|
||||
override fun addItemFlags(vararg hideFlags: ItemFlag) {
|
||||
for (flag in hideFlags) {
|
||||
this.flagBits = this.flagBits or getBitModifier(flag)
|
||||
for (f in hideFlags) {
|
||||
this.flagBits = this.flagBits or getBitModifier(f)
|
||||
}
|
||||
|
||||
apply()
|
||||
}
|
||||
|
||||
override fun removeItemFlags(vararg hideFlags: ItemFlag) {
|
||||
for (flag in hideFlags) {
|
||||
this.flagBits = this.flagBits and getBitModifier(flag)
|
||||
for (f in hideFlags) {
|
||||
this.flagBits = this.flagBits and getBitModifier(f).inv()
|
||||
}
|
||||
|
||||
apply()
|
||||
}
|
||||
|
||||
override fun getItemFlags(): MutableSet<ItemFlag> {
|
||||
val flags = mutableSetOf<ItemFlag>()
|
||||
|
||||
var flagArr: Array<ItemFlag>
|
||||
val size = ItemFlag.values().also { flagArr = it }.size
|
||||
|
||||
for (i in 0 until size) {
|
||||
val flag = flagArr[i]
|
||||
if (this.hasItemFlag(flag)) {
|
||||
flags.add(flag)
|
||||
override fun getItemFlags(): Set<ItemFlag> {
|
||||
val currentFlags = mutableSetOf<ItemFlag>()
|
||||
for (f in ItemFlag.values()) {
|
||||
if (hasItemFlag(f)) {
|
||||
currentFlags.add(f)
|
||||
}
|
||||
}
|
||||
|
||||
return flags
|
||||
return currentFlags
|
||||
}
|
||||
|
||||
override fun hasItemFlag(flag: ItemFlag): Boolean {
|
||||
@@ -194,15 +190,15 @@ class EcoFastItemStack(
|
||||
}
|
||||
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
private var flagBits: Int
|
||||
private var flagBits: Byte
|
||||
get() =
|
||||
if (handle.hasTag() && handle.getTag()!!.contains(
|
||||
"HideFlags",
|
||||
99
|
||||
)
|
||||
) handle.getTag()!!.getInt("HideFlags") else 0
|
||||
) handle.getTag()!!.getInt("HideFlags").toByte() else 0
|
||||
set(value) =
|
||||
handle.getOrCreateTag().putInt("HideFlags", value)
|
||||
handle.getOrCreateTag().putInt("HideFlags", value.toInt())
|
||||
|
||||
override fun getRepairCost(): Int {
|
||||
return handle.getBaseRepairCost()
|
||||
@@ -268,8 +264,8 @@ class EcoFastItemStack(
|
||||
bukkit.mergeIfNeeded(handle)
|
||||
}
|
||||
|
||||
private fun getBitModifier(hideFlag: ItemFlag): Int {
|
||||
return 1 shl hideFlag.ordinal
|
||||
private fun getBitModifier(hideFlag: ItemFlag): Byte {
|
||||
return (1 shl hideFlag.ordinal).toByte()
|
||||
}
|
||||
|
||||
override fun unwrap(): org.bukkit.inventory.ItemStack {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.3.5"
|
||||
id("io.papermc.paperweight.userdev") version "1.3.6"
|
||||
}
|
||||
|
||||
group = "com.willfp"
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_17_R1
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
|
||||
import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.SnbtPrinterTagVisitor
|
||||
import net.minecraft.nbt.TagParser
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class SNBTConverter : SNBTConverterProxy {
|
||||
override fun fromSNBT(snbt: String): ItemStack? {
|
||||
val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return null
|
||||
val nms = net.minecraft.world.item.ItemStack.of(nbt)
|
||||
return CraftItemStack.asBukkitCopy(nms)
|
||||
}
|
||||
|
||||
override fun toSNBT(itemStack: ItemStack): String {
|
||||
val nms = CraftItemStack.asNMSCopy(itemStack)
|
||||
return SnbtPrinterTagVisitor().visit(nms.save(CompoundTag()))
|
||||
}
|
||||
|
||||
override fun makeSNBTTestable(snbt: String): TestableItem {
|
||||
val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return EmptyTestableItem()
|
||||
val nms = net.minecraft.world.item.ItemStack.of(nbt)
|
||||
if (nms == net.minecraft.world.item.ItemStack.EMPTY) {
|
||||
return EmptyTestableItem()
|
||||
}
|
||||
|
||||
nbt.remove("Count")
|
||||
|
||||
return SNBTTestableItem(CraftItemStack.asBukkitCopy(nms), nbt)
|
||||
}
|
||||
|
||||
class SNBTTestableItem(
|
||||
private val item: ItemStack,
|
||||
private val tag: CompoundTag
|
||||
) : TestableItem {
|
||||
override fun matches(itemStack: ItemStack?): Boolean {
|
||||
if (itemStack == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
val nms = CraftItemStack.asNMSCopy(itemStack)
|
||||
val nmsTag = nms.save(CompoundTag())
|
||||
nmsTag.remove("Count")
|
||||
return tag.copy().merge(nmsTag) == nmsTag
|
||||
}
|
||||
|
||||
override fun getItem(): ItemStack = item
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,10 @@ class Skull : SkullProxy {
|
||||
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
|
||||
setProfile.isAccessible = true
|
||||
}
|
||||
if (base64.length < 20) {
|
||||
return
|
||||
}
|
||||
|
||||
val uuid = UUID(
|
||||
base64.substring(base64.length - 20).hashCode().toLong(),
|
||||
base64.substring(base64.length - 10).hashCode().toLong()
|
||||
@@ -39,6 +43,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()?.value
|
||||
return prop.toMutableList().firstOrNull()?.name
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ package com.willfp.eco.internal.spigot.proxy.v1_17_R1
|
||||
|
||||
import com.willfp.eco.core.display.Display
|
||||
import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.trading.MerchantOffer
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMerchantRecipe
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.MerchantRecipe
|
||||
@@ -15,20 +18,17 @@ class VillagerTrade : VillagerTradeProxy {
|
||||
recipe: MerchantRecipe,
|
||||
player: Player
|
||||
): MerchantRecipe {
|
||||
val oldRecipe = recipe as CraftMerchantRecipe
|
||||
val newRecipe = CraftMerchantRecipe(
|
||||
Display.display(recipe.getResult().clone(), player),
|
||||
recipe.getUses(),
|
||||
recipe.getMaxUses(),
|
||||
recipe.hasExperienceReward(),
|
||||
recipe.getVillagerExperience(),
|
||||
recipe.getPriceMultiplier()
|
||||
)
|
||||
for (ingredient in recipe.getIngredients()) {
|
||||
newRecipe.addIngredient(Display.display(ingredient.clone(), player))
|
||||
recipe as CraftMerchantRecipe
|
||||
|
||||
val nbt = getHandle(recipe).createTag()
|
||||
for (tag in arrayOf("buy", "buyB", "sell")) {
|
||||
val nms = ItemStack.of(nbt.getCompound(tag))
|
||||
val displayed = Display.display(CraftItemStack.asBukkitCopy(nms), player)
|
||||
val itemNBT = CraftItemStack.asNMSCopy(displayed).save(CompoundTag())
|
||||
nbt.put(tag, itemNBT)
|
||||
}
|
||||
getHandle(newRecipe).specialPriceDiff = getHandle(oldRecipe).specialPriceDiff
|
||||
return newRecipe
|
||||
|
||||
return CraftMerchantRecipe(MerchantOffer(nbt))
|
||||
}
|
||||
|
||||
private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.3.5"
|
||||
id("io.papermc.paperweight.userdev") version "1.3.6"
|
||||
}
|
||||
|
||||
group = "com.willfp"
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_18_R1
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
|
||||
import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.SnbtPrinterTagVisitor
|
||||
import net.minecraft.nbt.TagParser
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class SNBTConverter : SNBTConverterProxy {
|
||||
override fun fromSNBT(snbt: String): ItemStack? {
|
||||
val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return null
|
||||
val nms = net.minecraft.world.item.ItemStack.of(nbt)
|
||||
return CraftItemStack.asBukkitCopy(nms)
|
||||
}
|
||||
|
||||
override fun toSNBT(itemStack: ItemStack): String {
|
||||
val nms = CraftItemStack.asNMSCopy(itemStack)
|
||||
return SnbtPrinterTagVisitor().visit(nms.save(CompoundTag()))
|
||||
}
|
||||
|
||||
override fun makeSNBTTestable(snbt: String): TestableItem {
|
||||
val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return EmptyTestableItem()
|
||||
val nms = net.minecraft.world.item.ItemStack.of(nbt)
|
||||
if (nms == net.minecraft.world.item.ItemStack.EMPTY) {
|
||||
return EmptyTestableItem()
|
||||
}
|
||||
|
||||
nbt.remove("Count")
|
||||
|
||||
return SNBTTestableItem(CraftItemStack.asBukkitCopy(nms), nbt)
|
||||
}
|
||||
|
||||
class SNBTTestableItem(
|
||||
private val item: ItemStack,
|
||||
private val tag: CompoundTag
|
||||
) : TestableItem {
|
||||
override fun matches(itemStack: ItemStack?): Boolean {
|
||||
if (itemStack == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
val nms = CraftItemStack.asNMSCopy(itemStack)
|
||||
val nmsTag = nms.save(CompoundTag())
|
||||
nmsTag.remove("Count")
|
||||
return tag.copy().merge(nmsTag) == nmsTag
|
||||
}
|
||||
|
||||
override fun getItem(): ItemStack = item
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,10 @@ class Skull : SkullProxy {
|
||||
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
|
||||
setProfile.isAccessible = true
|
||||
}
|
||||
if (base64.length < 20) {
|
||||
return
|
||||
}
|
||||
|
||||
val uuid = UUID(
|
||||
base64.substring(base64.length - 20).hashCode().toLong(),
|
||||
base64.substring(base64.length - 10).hashCode().toLong()
|
||||
@@ -39,6 +43,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()?.value
|
||||
return prop.toMutableList().firstOrNull()?.name
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ package com.willfp.eco.internal.spigot.proxy.v1_18_R1
|
||||
|
||||
import com.willfp.eco.core.display.Display
|
||||
import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.trading.MerchantOffer
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftMerchantRecipe
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.MerchantRecipe
|
||||
@@ -15,20 +18,17 @@ class VillagerTrade : VillagerTradeProxy {
|
||||
recipe: MerchantRecipe,
|
||||
player: Player
|
||||
): MerchantRecipe {
|
||||
val oldRecipe = recipe as CraftMerchantRecipe
|
||||
val newRecipe = CraftMerchantRecipe(
|
||||
Display.display(recipe.getResult().clone(), player),
|
||||
recipe.getUses(),
|
||||
recipe.getMaxUses(),
|
||||
recipe.hasExperienceReward(),
|
||||
recipe.getVillagerExperience(),
|
||||
recipe.getPriceMultiplier()
|
||||
)
|
||||
for (ingredient in recipe.getIngredients()) {
|
||||
newRecipe.addIngredient(Display.display(ingredient.clone(), player))
|
||||
recipe as CraftMerchantRecipe
|
||||
|
||||
val nbt = getHandle(recipe).createTag()
|
||||
for (tag in arrayOf("buy", "buyB", "sell")) {
|
||||
val nms = ItemStack.of(nbt.getCompound(tag))
|
||||
val displayed = Display.display(CraftItemStack.asBukkitCopy(nms), player)
|
||||
val itemNBT = CraftItemStack.asNMSCopy(displayed).save(CompoundTag())
|
||||
nbt.put(tag, itemNBT)
|
||||
}
|
||||
getHandle(newRecipe).setSpecialPriceDiff(getHandle(oldRecipe).getSpecialPriceDiff())
|
||||
return newRecipe
|
||||
|
||||
return CraftMerchantRecipe(MerchantOffer(nbt))
|
||||
}
|
||||
|
||||
private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.3.5"
|
||||
id("io.papermc.paperweight.userdev") version "1.3.6"
|
||||
}
|
||||
|
||||
group = "com.willfp"
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_18_R2
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
|
||||
import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.SnbtPrinterTagVisitor
|
||||
import net.minecraft.nbt.TagParser
|
||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class SNBTConverter : SNBTConverterProxy {
|
||||
override fun fromSNBT(snbt: String): ItemStack? {
|
||||
val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return null
|
||||
val nms = net.minecraft.world.item.ItemStack.of(nbt)
|
||||
return CraftItemStack.asBukkitCopy(nms)
|
||||
}
|
||||
|
||||
override fun toSNBT(itemStack: ItemStack): String {
|
||||
val nms = CraftItemStack.asNMSCopy(itemStack)
|
||||
return SnbtPrinterTagVisitor().visit(nms.save(CompoundTag()))
|
||||
}
|
||||
|
||||
override fun makeSNBTTestable(snbt: String): TestableItem {
|
||||
val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return EmptyTestableItem()
|
||||
val nms = net.minecraft.world.item.ItemStack.of(nbt)
|
||||
if (nms == net.minecraft.world.item.ItemStack.EMPTY) {
|
||||
return EmptyTestableItem()
|
||||
}
|
||||
|
||||
nbt.remove("Count")
|
||||
|
||||
return SNBTTestableItem(CraftItemStack.asBukkitCopy(nms), nbt)
|
||||
}
|
||||
|
||||
class SNBTTestableItem(
|
||||
private val item: ItemStack,
|
||||
private val tag: CompoundTag
|
||||
) : TestableItem {
|
||||
override fun matches(itemStack: ItemStack?): Boolean {
|
||||
if (itemStack == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
val nms = CraftItemStack.asNMSCopy(itemStack)
|
||||
val nmsTag = nms.save(CompoundTag())
|
||||
nmsTag.remove("Count")
|
||||
return tag.copy().merge(nmsTag) == nmsTag
|
||||
}
|
||||
|
||||
override fun getItem(): ItemStack = item
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,10 @@ class Skull : SkullProxy {
|
||||
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
|
||||
setProfile.isAccessible = true
|
||||
}
|
||||
if (base64.length < 20) {
|
||||
return
|
||||
}
|
||||
|
||||
val uuid = UUID(
|
||||
base64.substring(base64.length - 20).hashCode().toLong(),
|
||||
base64.substring(base64.length - 10).hashCode().toLong()
|
||||
@@ -39,6 +43,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()?.value
|
||||
return prop.toMutableList().firstOrNull()?.name
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ package com.willfp.eco.internal.spigot.proxy.v1_18_R2
|
||||
|
||||
import com.willfp.eco.core.display.Display
|
||||
import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.trading.MerchantOffer
|
||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftMerchantRecipe
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.MerchantRecipe
|
||||
@@ -15,20 +18,17 @@ class VillagerTrade : VillagerTradeProxy {
|
||||
recipe: MerchantRecipe,
|
||||
player: Player
|
||||
): MerchantRecipe {
|
||||
val oldRecipe = recipe as CraftMerchantRecipe
|
||||
val newRecipe = CraftMerchantRecipe(
|
||||
Display.display(recipe.getResult().clone(), player),
|
||||
recipe.getUses(),
|
||||
recipe.getMaxUses(),
|
||||
recipe.hasExperienceReward(),
|
||||
recipe.getVillagerExperience(),
|
||||
recipe.getPriceMultiplier()
|
||||
)
|
||||
for (ingredient in recipe.getIngredients()) {
|
||||
newRecipe.addIngredient(Display.display(ingredient.clone(), player))
|
||||
recipe as CraftMerchantRecipe
|
||||
|
||||
val nbt = getHandle(recipe).createTag()
|
||||
for (tag in arrayOf("buy", "buyB", "sell")) {
|
||||
val nms = ItemStack.of(nbt.getCompound(tag))
|
||||
val displayed = Display.display(CraftItemStack.asBukkitCopy(nms), player)
|
||||
val itemNBT = CraftItemStack.asNMSCopy(displayed).save(CompoundTag())
|
||||
nbt.put(tag, itemNBT)
|
||||
}
|
||||
getHandle(newRecipe).setSpecialPriceDiff(getHandle(oldRecipe).getSpecialPriceDiff())
|
||||
return newRecipe
|
||||
|
||||
return CraftMerchantRecipe(MerchantOffer(nbt))
|
||||
}
|
||||
|
||||
private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer {
|
||||
|
||||
39
eco-core/core-nms/v1_19_R1/build.gradle.kts
Normal file
39
eco-core/core-nms/v1_19_R1/build.gradle.kts
Normal file
@@ -0,0 +1,39 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.3.6"
|
||||
}
|
||||
|
||||
group = "com.willfp"
|
||||
version = rootProject.version
|
||||
|
||||
dependencies {
|
||||
implementation(project(":eco-core:core-nms:nms-common"))
|
||||
paperDevBundle("1.19-R0.1-SNAPSHOT")
|
||||
|
||||
implementation("net.kyori:adventure-text-minimessage:4.11.0") {
|
||||
version {
|
||||
strictly("4.11.0")
|
||||
}
|
||||
exclude(group = "net.kyori", module = "adventure-api")
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
build {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
|
||||
reobfJar {
|
||||
mustRunAfter(shadowJar)
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate(
|
||||
"com.willfp.eco.internal.spigot.proxy.common",
|
||||
"com.willfp.eco.internal.spigot.proxy.v1_19_R1.common"
|
||||
)
|
||||
relocate(
|
||||
"net.kyori.adventure.text.minimessage",
|
||||
"com.willfp.eco.internal.spigot.proxy.v1_19_R1.minimessage"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.internal.spigot.proxy.AutoCraftProxy
|
||||
import net.minecraft.network.protocol.game.ClientboundPlaceGhostRecipePacket
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
|
||||
class AutoCraft : AutoCraftProxy {
|
||||
override fun modifyPacket(packet: Any) {
|
||||
val recipePacket = packet as ClientboundPlaceGhostRecipePacket
|
||||
val fKey = recipePacket.javaClass.getDeclaredField("b")
|
||||
fKey.isAccessible = true
|
||||
val key = fKey[recipePacket] as ResourceLocation
|
||||
fKey[recipePacket] = ResourceLocation(key.namespace, key.path + "_displayed")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.core.display.Display
|
||||
import com.willfp.eco.internal.spigot.proxy.ChatComponentProxy
|
||||
import net.kyori.adventure.nbt.api.BinaryTagHolder
|
||||
import net.kyori.adventure.text.BuildableComponent
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.TranslatableComponent
|
||||
import net.kyori.adventure.text.event.HoverEvent
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer
|
||||
import net.minecraft.nbt.TagParser
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class ChatComponent : ChatComponentProxy {
|
||||
private val gsonComponentSerializer = GsonComponentSerializer.gson()
|
||||
|
||||
override fun modifyComponent(obj: Any, player: Player): Any {
|
||||
if (obj !is net.minecraft.network.chat.Component) {
|
||||
return obj
|
||||
}
|
||||
|
||||
val component = gsonComponentSerializer.deserialize(
|
||||
net.minecraft.network.chat.Component.Serializer.toJson(
|
||||
obj
|
||||
)
|
||||
).asComponent() as BuildableComponent<*, *>
|
||||
|
||||
val newComponent = modifyBaseComponent(component, player)
|
||||
|
||||
return net.minecraft.network.chat.Component.Serializer.fromJson(
|
||||
gsonComponentSerializer.serialize(newComponent.asComponent())
|
||||
) ?: obj
|
||||
}
|
||||
|
||||
private fun modifyBaseComponent(baseComponent: Component, player: Player): Component {
|
||||
var component = baseComponent
|
||||
|
||||
if (component is TranslatableComponent) {
|
||||
val args = mutableListOf<Component>()
|
||||
for (arg in component.args()) {
|
||||
args.add(modifyBaseComponent(arg, player))
|
||||
}
|
||||
component = component.args(args)
|
||||
}
|
||||
|
||||
val children = mutableListOf<Component>()
|
||||
for (child in component.children()) {
|
||||
children.add(modifyBaseComponent(child, player))
|
||||
}
|
||||
component = component.children(children)
|
||||
|
||||
val hoverEvent: HoverEvent<Any> = component.style().hoverEvent() as HoverEvent<Any>? ?: return component
|
||||
|
||||
val showItem = hoverEvent.value()
|
||||
|
||||
if (showItem !is HoverEvent.ShowItem) {
|
||||
return component
|
||||
}
|
||||
|
||||
val newShowItem = showItem.nbt(
|
||||
BinaryTagHolder.binaryTagHolder(
|
||||
CraftItemStack.asNMSCopy(
|
||||
Display.display(
|
||||
CraftItemStack.asBukkitCopy(
|
||||
CraftItemStack.asNMSCopy(
|
||||
ItemStack(
|
||||
Material.matchMaterial(
|
||||
showItem.item()
|
||||
.toString()
|
||||
) ?: return component,
|
||||
showItem.count()
|
||||
)
|
||||
).apply {
|
||||
this.tag = TagParser.parseTag(
|
||||
showItem.nbt()?.string() ?: return component
|
||||
) ?: return component
|
||||
}
|
||||
),
|
||||
player
|
||||
)
|
||||
).orCreateTag.toString()
|
||||
)
|
||||
)
|
||||
|
||||
val newHover = hoverEvent.value(newShowItem)
|
||||
val style = component.style().hoverEvent(newHover)
|
||||
return component.style(style)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_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
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftMob
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_19_R1.persistence.CraftPersistentDataContainer
|
||||
import org.bukkit.craftbukkit.v1_19_R1.persistence.CraftPersistentDataTypeRegistry
|
||||
import org.bukkit.craftbukkit.v1_19_R1.util.CraftMagicNumbers
|
||||
import org.bukkit.craftbukkit.v1_19_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 {
|
||||
override fun init() {
|
||||
CommonsProvider.setIfNeeded(CommonsProviderImpl)
|
||||
}
|
||||
|
||||
object CommonsProviderImpl : CommonsProvider {
|
||||
private val cisHandle: Field = CraftItemStack::class.java.getDeclaredField("handle").apply {
|
||||
isAccessible = true
|
||||
}
|
||||
|
||||
private val pdcRegsitry = Class.forName("org.bukkit.craftbukkit.v1_19_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? {
|
||||
val craft = mob as? CraftMob ?: return null
|
||||
return craft.handle as? PathfinderMob
|
||||
}
|
||||
|
||||
override fun toResourceLocation(namespacedKey: NamespacedKey): ResourceLocation =
|
||||
CraftNamespacedKey.toMinecraft(namespacedKey)
|
||||
|
||||
override fun asNMSStack(itemStack: ItemStack): net.minecraft.world.item.ItemStack {
|
||||
return if (itemStack !is CraftItemStack) {
|
||||
CraftItemStack.asNMSCopy(itemStack)
|
||||
} else {
|
||||
cisHandle[itemStack] as net.minecraft.world.item.ItemStack? ?: CraftItemStack.asNMSCopy(itemStack)
|
||||
}
|
||||
}
|
||||
|
||||
override fun asBukkitStack(itemStack: net.minecraft.world.item.ItemStack): ItemStack {
|
||||
return CraftItemStack.asBukkitCopy(itemStack)
|
||||
}
|
||||
|
||||
override fun mergeIfNeeded(itemStack: ItemStack, nmsStack: net.minecraft.world.item.ItemStack) {
|
||||
if (itemStack !is CraftItemStack) {
|
||||
itemStack.itemMeta = CraftItemStack.asCraftMirror(nmsStack).itemMeta
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
val container = when (pdc) {
|
||||
is CraftPersistentDataContainer? -> pdc
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (item != null) {
|
||||
if (container != null && !container.isEmpty) {
|
||||
for (key in tag.allKeys.toSet()) {
|
||||
tag.remove(key)
|
||||
}
|
||||
|
||||
tag.merge(container.toTag())
|
||||
} else {
|
||||
item.setTag(null)
|
||||
}
|
||||
} else {
|
||||
if (container != null && !container.isEmpty) {
|
||||
tag.put("PublicBukkitValues", container.toTag())
|
||||
} else {
|
||||
tag.remove("PublicBukkitValues")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.internal.entities.EcoDummyEntity
|
||||
import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.EntityType
|
||||
|
||||
class DummyEntityFactory : DummyEntityFactoryProxy {
|
||||
override fun createDummyEntity(location: Location): Entity {
|
||||
val world = location.world as CraftWorld
|
||||
@Suppress("UsePropertyAccessSyntax")
|
||||
return EcoDummyEntity(world.createEntity(location, EntityType.ZOMBIE.entityClass).getBukkitEntity())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.core.entities.ai.EntityController
|
||||
import com.willfp.eco.internal.spigot.proxy.EntityControllerFactoryProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.EcoEntityController
|
||||
import org.bukkit.entity.Mob
|
||||
|
||||
class EntityControllerFactory : EntityControllerFactoryProxy {
|
||||
override fun <T : Mob> createEntityController(entity: T): EntityController<T> {
|
||||
return EcoEntityController(entity)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.core.data.ExtendedPersistentDataContainer
|
||||
import com.willfp.eco.internal.spigot.proxy.ExtendedPersistentDataContainerFactoryProxy
|
||||
import net.minecraft.nbt.Tag
|
||||
import org.bukkit.craftbukkit.v1_19_R1.persistence.CraftPersistentDataContainer
|
||||
import org.bukkit.craftbukkit.v1_19_R1.persistence.CraftPersistentDataTypeRegistry
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
|
||||
class ExtendedPersistentDataContainerFactory: ExtendedPersistentDataContainerFactoryProxy {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private val registry: CraftPersistentDataTypeRegistry =
|
||||
CraftPersistentDataContainer::class.java.getDeclaredField("registry")
|
||||
.apply { isAccessible = true }.get(null) as CraftPersistentDataTypeRegistry
|
||||
|
||||
override fun adapt(pdc: PersistentDataContainer): ExtendedPersistentDataContainer {
|
||||
return when (pdc) {
|
||||
is CraftPersistentDataContainer -> EcoPersistentDataContainer(pdc)
|
||||
else -> throw IllegalArgumentException("Custom PDC instance is not supported!")
|
||||
}
|
||||
}
|
||||
|
||||
override fun newPdc(): PersistentDataContainer {
|
||||
return CraftPersistentDataContainer(registry)
|
||||
}
|
||||
|
||||
inner class EcoPersistentDataContainer(
|
||||
val handle: CraftPersistentDataContainer
|
||||
) : ExtendedPersistentDataContainer {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private val customDataTags: MutableMap<String, Tag> =
|
||||
CraftPersistentDataContainer::class.java.getDeclaredField("customDataTags")
|
||||
.apply { isAccessible = true }.get(handle) as MutableMap<String, Tag>
|
||||
|
||||
override fun <T : Any, Z : Any> set(key: String, dataType: PersistentDataType<T, Z>, value: Z) {
|
||||
customDataTags[key] = registry.wrap(dataType.primitiveType, dataType.toPrimitive(value, handle.adapterContext))
|
||||
}
|
||||
|
||||
override fun <T : Any, Z : Any> has(key: String, dataType: PersistentDataType<T, Z>): Boolean {
|
||||
val value = customDataTags[key] ?: return false
|
||||
return registry.isInstanceOf(dataType.primitiveType, value)
|
||||
}
|
||||
|
||||
override fun <T : Any, Z : Any> get(key: String, dataType: PersistentDataType<T, Z>): Z? {
|
||||
val value = customDataTags[key] ?: return null
|
||||
return dataType.fromPrimitive(registry.extract(dataType.primitiveType, value), handle.adapterContext)
|
||||
}
|
||||
|
||||
override fun <T : Any, Z : Any> getOrDefault(
|
||||
key: String,
|
||||
dataType: PersistentDataType<T, Z>,
|
||||
defaultValue: Z
|
||||
): Z {
|
||||
return get(key, dataType) ?: defaultValue
|
||||
}
|
||||
|
||||
override fun remove(key: String) {
|
||||
customDataTags.remove(key)
|
||||
}
|
||||
|
||||
override fun getAllKeys(): MutableSet<String> {
|
||||
return customDataTags.keys
|
||||
}
|
||||
|
||||
override fun getBase(): PersistentDataContainer {
|
||||
return handle
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.core.fast.FastItemStack
|
||||
import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.common.item.EcoFastItemStack
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class FastItemStackFactory : FastItemStackFactoryProxy {
|
||||
override fun create(itemStack: ItemStack): FastItemStack {
|
||||
return EcoFastItemStack(itemStack)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.core.display.Display
|
||||
import com.willfp.eco.internal.spigot.proxy.MiniMessageTranslatorProxy
|
||||
import com.willfp.eco.util.toLegacy
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
||||
|
||||
class MiniMessageTranslator : MiniMessageTranslatorProxy {
|
||||
override fun format(message: String): String {
|
||||
var mut = message
|
||||
|
||||
val startsWithPrefix = mut.startsWith(Display.PREFIX)
|
||||
if (startsWithPrefix) {
|
||||
mut = mut.substring(2)
|
||||
}
|
||||
|
||||
mut = mut.replace('§', '&')
|
||||
|
||||
val miniMessage = runCatching {
|
||||
MiniMessage.miniMessage().deserialize(
|
||||
mut
|
||||
).toLegacy()
|
||||
}.getOrNull() ?: mut
|
||||
|
||||
mut = if (startsWithPrefix) {
|
||||
Display.PREFIX + miniMessage
|
||||
} else {
|
||||
miniMessage
|
||||
}
|
||||
|
||||
return mut
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
|
||||
import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.SnbtPrinterTagVisitor
|
||||
import net.minecraft.nbt.TagParser
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class SNBTConverter : SNBTConverterProxy {
|
||||
override fun fromSNBT(snbt: String): ItemStack? {
|
||||
val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return null
|
||||
val nms = net.minecraft.world.item.ItemStack.of(nbt)
|
||||
return CraftItemStack.asBukkitCopy(nms)
|
||||
}
|
||||
|
||||
override fun toSNBT(itemStack: ItemStack): String {
|
||||
val nms = CraftItemStack.asNMSCopy(itemStack)
|
||||
return SnbtPrinterTagVisitor().visit(nms.save(CompoundTag()))
|
||||
}
|
||||
|
||||
override fun makeSNBTTestable(snbt: String): TestableItem {
|
||||
val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return EmptyTestableItem()
|
||||
val nms = net.minecraft.world.item.ItemStack.of(nbt)
|
||||
if (nms == net.minecraft.world.item.ItemStack.EMPTY) {
|
||||
return EmptyTestableItem()
|
||||
}
|
||||
|
||||
nbt.remove("Count")
|
||||
return SNBTTestableItem(CraftItemStack.asBukkitCopy(nms), nbt)
|
||||
}
|
||||
|
||||
class SNBTTestableItem(
|
||||
private val item: ItemStack,
|
||||
private val tag: CompoundTag
|
||||
) : TestableItem {
|
||||
override fun matches(itemStack: ItemStack?): Boolean {
|
||||
if (itemStack == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
val nms = CraftItemStack.asNMSCopy(itemStack)
|
||||
val nmsTag = nms.save(CompoundTag())
|
||||
nmsTag.remove("Count")
|
||||
return tag.copy().merge(nmsTag) == nmsTag
|
||||
}
|
||||
|
||||
override fun getItem(): ItemStack = item
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.mojang.authlib.GameProfile
|
||||
import com.mojang.authlib.properties.Property
|
||||
import com.willfp.eco.internal.spigot.proxy.SkullProxy
|
||||
import org.bukkit.inventory.meta.SkullMeta
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
import java.util.UUID
|
||||
|
||||
class Skull : SkullProxy {
|
||||
private lateinit var setProfile: Method
|
||||
private lateinit var profile: Field
|
||||
|
||||
override fun setSkullTexture(
|
||||
meta: SkullMeta,
|
||||
base64: String
|
||||
) {
|
||||
if (!this::setProfile.isInitialized) {
|
||||
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
|
||||
setProfile.isAccessible = true
|
||||
}
|
||||
if (base64.length < 20) {
|
||||
return
|
||||
}
|
||||
|
||||
val uuid = UUID(
|
||||
base64.substring(base64.length - 20).hashCode().toLong(),
|
||||
base64.substring(base64.length - 10).hashCode().toLong()
|
||||
)
|
||||
val profile = GameProfile(uuid, "eco")
|
||||
profile.properties.put("textures", Property("textures", base64))
|
||||
setProfile.invoke(meta, profile)
|
||||
}
|
||||
|
||||
override fun getSkullTexture(
|
||||
meta: SkullMeta
|
||||
): String? {
|
||||
if (!this::profile.isInitialized) {
|
||||
profile = meta.javaClass.getDeclaredField("profile")
|
||||
profile.isAccessible = true
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.internal.spigot.proxy.TPSProxy
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer
|
||||
|
||||
class TPS : TPSProxy {
|
||||
override fun getTPS(): Double {
|
||||
return (Bukkit.getServer() as CraftServer).handle.server.recentTps[0]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.core.display.Display
|
||||
import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.trading.MerchantOffer
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftMerchantRecipe
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.MerchantRecipe
|
||||
import java.lang.reflect.Field
|
||||
|
||||
class VillagerTrade : VillagerTradeProxy {
|
||||
private val handle: Field = CraftMerchantRecipe::class.java.getDeclaredField("handle")
|
||||
|
||||
override fun displayTrade(
|
||||
recipe: MerchantRecipe,
|
||||
player: Player
|
||||
): MerchantRecipe {
|
||||
recipe as CraftMerchantRecipe
|
||||
|
||||
val nbt = getHandle(recipe).createTag()
|
||||
for (tag in arrayOf("buy", "buyB", "sell")) {
|
||||
val nms = ItemStack.of(nbt.getCompound(tag))
|
||||
val displayed = Display.display(CraftItemStack.asBukkitCopy(nms), player)
|
||||
val itemNBT = CraftItemStack.asNMSCopy(displayed).save(CompoundTag())
|
||||
nbt.put(tag, itemNBT)
|
||||
}
|
||||
|
||||
return CraftMerchantRecipe(MerchantOffer(nbt))
|
||||
}
|
||||
|
||||
private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer {
|
||||
return handle[recipe] as MerchantOffer
|
||||
}
|
||||
|
||||
init {
|
||||
handle.isAccessible = true
|
||||
}
|
||||
}
|
||||
@@ -14,16 +14,17 @@ dependencies {
|
||||
implementation 'com.zaxxer:HikariCP:5.0.0'
|
||||
implementation 'net.kyori:adventure-platform-bukkit:4.1.0'
|
||||
implementation 'org.javassist:javassist:3.28.0-GA'
|
||||
implementation 'org.mongodb:mongodb-driver-sync:4.6.0'
|
||||
implementation 'org.litote.kmongo:kmongo-coroutine:4.6.0'
|
||||
|
||||
// Included in spigot jar
|
||||
compileOnly 'com.google.code.gson:gson:2.8.8'
|
||||
compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT'
|
||||
|
||||
// Plugin dependencies
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.1-SNAPSHOT'
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.7-SNAPSHOT'
|
||||
compileOnly 'com.github.TechFortress:GriefPrevention:16.17.1'
|
||||
compileOnly 'com.massivecraft:Factions:1.6.9.5-U0.5.10'
|
||||
compileOnly 'com.github.cryptomorin:kingdoms:1.12.3'
|
||||
compileOnly('com.github.TownyAdvanced:Towny:0.97.2.6') {
|
||||
exclude group: 'com.zaxxer', module: 'HikariCP'
|
||||
@@ -34,12 +35,13 @@ dependencies {
|
||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.202'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.10'
|
||||
compileOnly 'com.github.oraxen:oraxen:bd81ace154'
|
||||
compileOnly 'com.github.brcdev-minecraft:shopgui-api:2.2.0'
|
||||
compileOnly 'com.github.brcdev-minecraft:shopgui-api:3.0.0'
|
||||
compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.4.7'
|
||||
compileOnly 'com.arcaniax:HeadDatabase-API:1.3.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.songoda:skyblock:2.3.30'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||
compileOnly 'com.github.WhipDevelopment:CrashClaim:f9cd7d92eb'
|
||||
compileOnly 'com.wolfyscript.wolfyutilities:wolfyutilities:3.16.0.0'
|
||||
@@ -63,6 +65,13 @@ dependencies {
|
||||
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
minimize {
|
||||
exclude(dependency('org.litote.kmongo:kmongo-coroutine:.*'))
|
||||
exclude(dependency('org.jetbrains.exposed:.*:.*'))
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
filesNotMatching(["**/*.png", "**/models/**", "**/textures/**"]) {
|
||||
expand projectVersion: project.version
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mongodb.diagnostics.logging
|
||||
|
||||
/*
|
||||
This is a terrible fix for mongo logging.
|
||||
|
||||
I've tried every 'solution' on the internet - setting the level with java native logging,
|
||||
with Log4j / Slf4j, reflectively changing the logger delegate in the Log4J impl, every
|
||||
single method under the sun - but I just couldn't get any of them to work.
|
||||
|
||||
So, I've 'fixed' the problem at the source - the class in the jar now always returns a useless
|
||||
logger that can't do anything. At least there's no console spam anymore.
|
||||
*/
|
||||
|
||||
@Suppress("UNUSED")
|
||||
object Loggers {
|
||||
private const val PREFIX = "org.mongodb.driver"
|
||||
|
||||
@JvmStatic
|
||||
fun getLogger(suffix: String): Logger = NoOpLogger("$PREFIX.$suffix")
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.willfp.eco.internal.spigot
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.util.containsIgnoreCase
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.plugin.Plugin
|
||||
import java.io.File
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
object ConflictFinder {
|
||||
fun searchForConflicts(eco: EcoPlugin): List<Conflict> {
|
||||
val conflicts = mutableListOf<Conflict>()
|
||||
|
||||
for (plugin in Bukkit.getPluginManager().plugins) {
|
||||
if (eco.configYml.getStrings("conflicts.whitelist").containsIgnoreCase(plugin.name)) {
|
||||
continue
|
||||
}
|
||||
|
||||
val conflict = try {
|
||||
plugin.getConflict()
|
||||
} catch (e: Exception) {
|
||||
continue
|
||||
} // Really can't be fucked to do this properly.
|
||||
|
||||
if (conflict != null) {
|
||||
conflicts.add(conflict)
|
||||
}
|
||||
}
|
||||
|
||||
return conflicts
|
||||
}
|
||||
}
|
||||
|
||||
data class Conflict(
|
||||
val plugin: Plugin,
|
||||
val conflictType: ConflictType
|
||||
) {
|
||||
val conflictMessage: String
|
||||
get() = "${plugin.name} will likely conflict with eco! Reason: ${conflictType.friendlyMessage}"
|
||||
}
|
||||
|
||||
enum class ConflictType(
|
||||
val friendlyMessage: String
|
||||
) {
|
||||
LIB_LOADER("Kotlin found in libraries (lib-loader)"),
|
||||
KOTLIN_SHADE("Kotlin shaded into jar");
|
||||
}
|
||||
|
||||
private fun Plugin.getConflict(): Conflict? {
|
||||
if (this.description.libraries.any { it.contains("kotlin-stdlib") }) {
|
||||
return Conflict(this, ConflictType.LIB_LOADER)
|
||||
}
|
||||
|
||||
val file = File(this::class.java.protectionDomain.codeSource.location.toURI())
|
||||
|
||||
if (!file.exists() || file.name.contains("PolymartHelper")) {
|
||||
return null
|
||||
}
|
||||
|
||||
val zip = ZipFile(file)
|
||||
|
||||
for (entry in zip.entries()) {
|
||||
if (entry.name.startsWith("kotlin/") || entry.name.startsWith("kotlinx/")) {
|
||||
return Conflict(this, ConflictType.KOTLIN_SHADE)
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.willfp.eco.core.data.ExtendedPersistentDataContainer
|
||||
import com.willfp.eco.core.entities.ai.EntityController
|
||||
import com.willfp.eco.core.fast.FastItemStack
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration
|
||||
import com.willfp.eco.core.items.SNBTHandler
|
||||
import com.willfp.eco.internal.EcoCleaner
|
||||
import com.willfp.eco.internal.EcoPropsParser
|
||||
import com.willfp.eco.internal.Plugins
|
||||
@@ -29,7 +30,9 @@ import com.willfp.eco.internal.scheduling.EcoScheduler
|
||||
import com.willfp.eco.internal.spigot.data.DataYml
|
||||
import com.willfp.eco.internal.spigot.data.EcoKeyRegistry
|
||||
import com.willfp.eco.internal.spigot.data.EcoProfileHandler
|
||||
import com.willfp.eco.internal.spigot.data.storage.HandlerType
|
||||
import com.willfp.eco.internal.spigot.integrations.bstats.MetricHandler
|
||||
import com.willfp.eco.internal.spigot.items.EcoSNBTHandler
|
||||
import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.EntityControllerFactoryProxy
|
||||
@@ -57,7 +60,19 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
|
||||
|
||||
private var adventure: BukkitAudiences? = null
|
||||
private val keyRegistry = EcoKeyRegistry()
|
||||
private val playerProfileHandler = EcoProfileHandler(this.configYml.getBool("mysql.enabled"), this)
|
||||
private val playerProfileHandler = EcoProfileHandler(
|
||||
if (this.configYml.getBool("mysql.enabled")) {
|
||||
this.configYml.set("mysql.enabled", false)
|
||||
this.configYml.set("data-handler", "mysql")
|
||||
HandlerType.MYSQL
|
||||
} else {
|
||||
HandlerType.valueOf(
|
||||
this.configYml.getString("data-handler").uppercase()
|
||||
)
|
||||
}, this
|
||||
)
|
||||
|
||||
private val snbtHandler = EcoSNBTHandler(this)
|
||||
|
||||
@Suppress("RedundantNullableReturnType")
|
||||
private val keyFactory: InternalNamespacedKeyFactory? =
|
||||
@@ -159,4 +174,7 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
|
||||
|
||||
override fun newPdc(): PersistentDataContainer =
|
||||
getProxy(ExtendedPersistentDataContainerFactoryProxy::class.java).newPdc()
|
||||
|
||||
override fun getSNBTHandler(): SNBTHandler =
|
||||
snbtHandler
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.willfp.eco.internal.entities.EntityArgParserSilent
|
||||
import com.willfp.eco.internal.entities.EntityArgParserSize
|
||||
import com.willfp.eco.internal.entities.EntityArgParserSpawnReinforcements
|
||||
import com.willfp.eco.internal.entities.EntityArgParserSpeed
|
||||
import com.willfp.eco.internal.gui.menu.getMenu
|
||||
import com.willfp.eco.internal.items.ArgParserColor
|
||||
import com.willfp.eco.internal.items.ArgParserCustomModelData
|
||||
import com.willfp.eco.internal.items.ArgParserEnchantment
|
||||
@@ -83,6 +84,7 @@ import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCombatLogX
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCombatLogXV11
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCrashClaim
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefDeluxeCombat
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefFabledSkyBlock
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefFactionsUUID
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefGriefPrevention
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefIridiumSkyblock
|
||||
@@ -111,6 +113,7 @@ import com.willfp.eco.internal.spigot.integrations.shop.ShopEconomyShopGUI
|
||||
import com.willfp.eco.internal.spigot.integrations.shop.ShopShopGuiPlus
|
||||
import com.willfp.eco.internal.spigot.integrations.shop.ShopZShop
|
||||
import com.willfp.eco.internal.spigot.math.evaluateExpression
|
||||
import com.willfp.eco.internal.spigot.player.PlayerHealthFixer
|
||||
import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.SkullProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.TPSProxy
|
||||
@@ -120,6 +123,7 @@ import com.willfp.eco.internal.spigot.recipes.listeners.ComplexInComplex
|
||||
import com.willfp.eco.internal.spigot.recipes.listeners.ComplexInVanilla
|
||||
import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapedCraftingRecipeStackHandler
|
||||
import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapelessCraftingRecipeStackHandler
|
||||
import com.willfp.eco.util.MenuUtils
|
||||
import com.willfp.eco.util.NumberUtils
|
||||
import com.willfp.eco.util.ServerUtils
|
||||
import com.willfp.eco.util.SkullUtils
|
||||
@@ -180,7 +184,9 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
val tpsProxy = getProxy(TPSProxy::class.java)
|
||||
ServerUtils.initialize { tpsProxy.getTPS() }
|
||||
|
||||
NumberUtils.initCrunch { expression, player, context -> evaluateExpression(expression, player, context) }
|
||||
NumberUtils.initCrunch(::evaluateExpression)
|
||||
|
||||
MenuUtils.initialize { it.openInventory.topInventory.getMenu() }
|
||||
|
||||
CustomItemsManager.registerProviders()
|
||||
|
||||
@@ -192,7 +198,27 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
}
|
||||
|
||||
override fun handleEnable() {
|
||||
this.logger.info("Scanning for conflicts...")
|
||||
val conflicts = ConflictFinder.searchForConflicts(this)
|
||||
for (conflict in conflicts) {
|
||||
this.logger.warning(conflict.conflictMessage)
|
||||
}
|
||||
if (conflicts.isNotEmpty()) {
|
||||
this.logger.warning(
|
||||
"You can fix the conflicts by either removing the conflicting plugins, " +
|
||||
"or by asking on the support discord to have them patched!"
|
||||
)
|
||||
this.logger.warning(
|
||||
"Only remove potentially conflicting plugins if you see " +
|
||||
"Loader Constraint Violation / LinkageError anywhere"
|
||||
)
|
||||
} else {
|
||||
this.logger.info("No conflicts found!")
|
||||
}
|
||||
|
||||
|
||||
CollatedRunnable(this)
|
||||
CustomItemsManager.registerProviders() // Do it again here
|
||||
|
||||
// Register events for ShopSellEvent
|
||||
ShopManager.registerEvents(this)
|
||||
@@ -219,7 +245,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
override fun handleReload() {
|
||||
CollatedRunnable(this)
|
||||
DropManager.update(this)
|
||||
ProfileSaver(this)
|
||||
ProfileSaver(this, Eco.getHandler().profileHandler)
|
||||
this.scheduler.runTimer(
|
||||
{ clearFrames() },
|
||||
this.configYml.getInt("display-frame-ttl").toLong(),
|
||||
@@ -239,6 +265,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
IntegrationLoader("IridiumSkyblock") { AntigriefManager.register(AntigriefIridiumSkyblock()) },
|
||||
IntegrationLoader("DeluxeCombat") { AntigriefManager.register(AntigriefDeluxeCombat()) },
|
||||
IntegrationLoader("SuperiorSkyblock2") { AntigriefManager.register(AntigriefSuperiorSkyblock2()) },
|
||||
IntegrationLoader("FabledSkyBlock") { AntigriefManager.register(AntigriefFabledSkyBlock()) },
|
||||
IntegrationLoader("BentoBox") { AntigriefManager.register(AntigriefBentoBox()) },
|
||||
IntegrationLoader("WorldGuard") { AntigriefManager.register(AntigriefWorldGuard()) },
|
||||
IntegrationLoader("GriefPrevention") { AntigriefManager.register(AntigriefGriefPrevention()) },
|
||||
@@ -338,7 +365,8 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
ArrowDataListener(this),
|
||||
ArmorChangeEventListeners(this),
|
||||
DataListener(this),
|
||||
PlayerBlockListener(this)
|
||||
PlayerBlockListener(this),
|
||||
PlayerHealthFixer(this)
|
||||
)
|
||||
|
||||
if (Prerequisite.HAS_PAPER.isMet) {
|
||||
|
||||
@@ -24,20 +24,29 @@ class EcoKeyRegistry : KeyRegistry {
|
||||
return registry.values.toMutableSet()
|
||||
}
|
||||
|
||||
override fun getCategory(key: PersistentDataKey<*>): KeyRegistry.KeyCategory? {
|
||||
return categories[key.key]
|
||||
}
|
||||
|
||||
private fun <T> validateKey(key: PersistentDataKey<T>) {
|
||||
val default = key.defaultValue
|
||||
|
||||
when (key.type) {
|
||||
PersistentDataKeyType.INT -> if (key.defaultValue !is Int) {
|
||||
PersistentDataKeyType.INT -> if (default !is Int) {
|
||||
throw IllegalArgumentException("Invalid Data Type! Should be Int")
|
||||
}
|
||||
PersistentDataKeyType.DOUBLE -> if (key.defaultValue !is Double) {
|
||||
PersistentDataKeyType.DOUBLE -> if (default !is Double) {
|
||||
throw IllegalArgumentException("Invalid Data Type! Should be Double")
|
||||
}
|
||||
PersistentDataKeyType.BOOLEAN -> if (key.defaultValue !is Boolean) {
|
||||
PersistentDataKeyType.BOOLEAN -> if (default !is Boolean) {
|
||||
throw IllegalArgumentException("Invalid Data Type! Should be Boolean")
|
||||
}
|
||||
PersistentDataKeyType.STRING -> if (key.defaultValue !is String) {
|
||||
PersistentDataKeyType.STRING -> if (default !is String) {
|
||||
throw IllegalArgumentException("Invalid Data Type! Should be String")
|
||||
}
|
||||
PersistentDataKeyType.STRING_LIST -> if (default !is List<*> || default.firstOrNull() !is String?) {
|
||||
throw IllegalArgumentException("Invalid Data Type! Should be String List")
|
||||
}
|
||||
|
||||
else -> throw NullPointerException("Null value found!")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.internal.spigot.data
|
||||
|
||||
import com.willfp.eco.core.Eco
|
||||
import com.willfp.eco.core.data.PlayerProfile
|
||||
import com.willfp.eco.core.data.Profile
|
||||
import com.willfp.eco.core.data.ProfileHandler
|
||||
@@ -7,19 +8,26 @@ import com.willfp.eco.core.data.ServerProfile
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||
import com.willfp.eco.internal.spigot.EcoSpigotPlugin
|
||||
import com.willfp.eco.internal.spigot.data.storage.DataHandler
|
||||
import com.willfp.eco.internal.spigot.data.storage.HandlerType
|
||||
import com.willfp.eco.internal.spigot.data.storage.MongoDataHandler
|
||||
import com.willfp.eco.internal.spigot.data.storage.MySQLDataHandler
|
||||
import com.willfp.eco.internal.spigot.data.storage.YamlDataHandler
|
||||
import org.bukkit.Bukkit
|
||||
import java.util.UUID
|
||||
|
||||
val serverProfileUUID = UUID(0, 0)
|
||||
|
||||
class EcoProfileHandler(
|
||||
useSql: Boolean,
|
||||
plugin: EcoSpigotPlugin
|
||||
private val type: HandlerType,
|
||||
private val plugin: EcoSpigotPlugin
|
||||
) : ProfileHandler {
|
||||
private val loaded = mutableMapOf<UUID, Profile>()
|
||||
val handler: DataHandler = if (useSql) MySQLDataHandler(plugin, this) else
|
||||
YamlDataHandler(plugin, this)
|
||||
|
||||
val handler: DataHandler = when (type) {
|
||||
HandlerType.YAML -> YamlDataHandler(plugin, this)
|
||||
HandlerType.MYSQL -> MySQLDataHandler(plugin, this)
|
||||
HandlerType.MONGO -> MongoDataHandler(plugin, this)
|
||||
}
|
||||
|
||||
fun loadGenericProfile(uuid: UUID): Profile {
|
||||
val found = loaded[uuid]
|
||||
@@ -45,26 +53,87 @@ class EcoProfileHandler(
|
||||
}
|
||||
|
||||
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
|
||||
val profile = loadGenericProfile(uuid)
|
||||
|
||||
for (key in keys) {
|
||||
handler.write(uuid, key.key, profile.read(key))
|
||||
}
|
||||
handler.saveKeysFor(uuid, keys)
|
||||
}
|
||||
|
||||
override fun unloadPlayer(uuid: UUID) {
|
||||
loaded.remove(uuid)
|
||||
}
|
||||
|
||||
override fun saveAll() {
|
||||
handler.saveAll(loaded.keys.toList())
|
||||
}
|
||||
|
||||
override fun save() {
|
||||
handler.save()
|
||||
}
|
||||
|
||||
fun initialize() {
|
||||
handler.initialize()
|
||||
private fun migrateIfNeeded() {
|
||||
if (!plugin.configYml.getBool("perform-data-migration")) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!plugin.dataYml.has("previous-handler")) {
|
||||
plugin.dataYml.set("previous-handler", type.name)
|
||||
plugin.dataYml.save()
|
||||
}
|
||||
|
||||
val previousHandlerType = HandlerType.valueOf(plugin.dataYml.getString("previous-handler"))
|
||||
|
||||
if (previousHandlerType == type) {
|
||||
return
|
||||
}
|
||||
|
||||
val previousHandler = when (previousHandlerType) {
|
||||
HandlerType.YAML -> YamlDataHandler(plugin, this)
|
||||
HandlerType.MYSQL -> MySQLDataHandler(plugin, this)
|
||||
HandlerType.MONGO -> MongoDataHandler(plugin, this)
|
||||
}
|
||||
|
||||
plugin.logger.info("eco has detected a change in data handler!")
|
||||
plugin.logger.info("Migrating server data from ${previousHandlerType.name} to ${type.name}")
|
||||
plugin.logger.info("This will take a while!")
|
||||
|
||||
val players = Bukkit.getOfflinePlayers().map { it.uniqueId }
|
||||
|
||||
plugin.logger.info("Found data for ${players.size} players!")
|
||||
|
||||
/*
|
||||
Declared here as its own function to be able to use T.
|
||||
*/
|
||||
fun <T : Any> migrateKey(uuid: UUID, key: PersistentDataKey<T>, from: DataHandler, to: DataHandler) {
|
||||
val category = Eco.getHandler().keyRegistry.getCategory(key)
|
||||
if (category != null) {
|
||||
from.categorize(key, category)
|
||||
}
|
||||
val previous: T? = from.read(uuid, key)
|
||||
if (previous != null) {
|
||||
to.write(uuid, key, previous)
|
||||
}
|
||||
}
|
||||
|
||||
var i = 1
|
||||
for (uuid in players) {
|
||||
plugin.logger.info("Migrating data for $uuid... ($i / ${players.size})")
|
||||
|
||||
for (key in PersistentDataKey.values()) {
|
||||
migrateKey(uuid, key, previousHandler, handler)
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
plugin.logger.info("Updating previous handler...")
|
||||
plugin.dataYml.set("previous-handler", type.name)
|
||||
plugin.dataYml.save()
|
||||
plugin.logger.info("Done!")
|
||||
}
|
||||
}
|
||||
|
||||
fun initialize() {
|
||||
plugin.dataYml.getStrings("categorized-keys.player")
|
||||
.mapNotNull { KeyHelpers.deserializeFromString(it) }
|
||||
|
||||
plugin.dataYml.getStrings("categorized-keys.server")
|
||||
.mapNotNull { KeyHelpers.deserializeFromString(it, server = true) }
|
||||
|
||||
handler.initialize()
|
||||
|
||||
migrateIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.willfp.eco.util.NamespacedKeyUtils
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
object KeyHelpers {
|
||||
fun deserializeFromString(serialized: String): PersistentDataKey<*>? {
|
||||
fun deserializeFromString(serialized: String, server: Boolean = false): PersistentDataKey<*>? {
|
||||
val split = serialized.split(";").toTypedArray()
|
||||
|
||||
if (split.size < 2) {
|
||||
@@ -15,7 +15,7 @@ object KeyHelpers {
|
||||
|
||||
val key = NamespacedKeyUtils.fromStringOrNull(split[0]) ?: return null
|
||||
val type = PersistentDataKeyType.valueOf(split[1]) ?: return null
|
||||
return when (type) {
|
||||
val persistentKey = when (type) {
|
||||
PersistentDataKeyType.STRING -> PersistentDataKey(
|
||||
key,
|
||||
type as PersistentDataKeyType<String>,
|
||||
@@ -38,6 +38,16 @@ object KeyHelpers {
|
||||
)
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (persistentKey != null) {
|
||||
if (server) {
|
||||
persistentKey.server()
|
||||
} else {
|
||||
persistentKey.player()
|
||||
}
|
||||
}
|
||||
|
||||
return persistentKey
|
||||
}
|
||||
|
||||
fun serializeToString(key: PersistentDataKey<*>): String {
|
||||
|
||||
@@ -2,26 +2,37 @@ package com.willfp.eco.internal.spigot.data.storage
|
||||
|
||||
import com.willfp.eco.core.data.keys.KeyRegistry
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||
import org.bukkit.NamespacedKey
|
||||
import java.util.UUID
|
||||
|
||||
interface DataHandler {
|
||||
fun save()
|
||||
fun saveAll(uuids: Iterable<UUID>)
|
||||
abstract class DataHandler(
|
||||
val type: HandlerType
|
||||
) {
|
||||
/**
|
||||
* Read value from a key.
|
||||
*/
|
||||
abstract fun <T : Any> read(uuid: UUID, key: PersistentDataKey<T>): T?
|
||||
|
||||
fun categorize(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) {
|
||||
/**
|
||||
* Write value to a key.
|
||||
*/
|
||||
abstract fun <T : Any> write(uuid: UUID, key: PersistentDataKey<T>, value: T)
|
||||
|
||||
/**
|
||||
* Save a set of keys for a given UUID.
|
||||
*/
|
||||
abstract fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>)
|
||||
|
||||
// Everything below this are methods that are only needed for certain implementations.
|
||||
|
||||
open fun save() {
|
||||
|
||||
}
|
||||
|
||||
fun initialize() {
|
||||
open fun categorize(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) {
|
||||
|
||||
}
|
||||
|
||||
fun savePlayer(uuid: UUID) {
|
||||
saveKeysFor(uuid, PersistentDataKey.values())
|
||||
}
|
||||
open fun initialize() {
|
||||
|
||||
fun <T> write(uuid: UUID, key: NamespacedKey, value: T)
|
||||
fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>)
|
||||
fun <T> read(uuid: UUID, key: PersistentDataKey<T>): T?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.willfp.eco.internal.spigot.data.storage
|
||||
|
||||
enum class HandlerType {
|
||||
YAML,
|
||||
MYSQL,
|
||||
MONGO
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.willfp.eco.internal.spigot.data.storage
|
||||
|
||||
import com.willfp.eco.core.data.Profile
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||
import com.willfp.eco.internal.spigot.EcoSpigotPlugin
|
||||
import com.willfp.eco.internal.spigot.data.EcoProfileHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.bson.codecs.pojo.annotations.BsonId
|
||||
import org.litote.kmongo.coroutine.CoroutineClient
|
||||
import org.litote.kmongo.coroutine.CoroutineCollection
|
||||
import org.litote.kmongo.coroutine.coroutine
|
||||
import org.litote.kmongo.eq
|
||||
import org.litote.kmongo.reactivestreams.KMongo
|
||||
import org.litote.kmongo.setValue
|
||||
import java.util.UUID
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class MongoDataHandler(
|
||||
plugin: EcoSpigotPlugin,
|
||||
private val handler: EcoProfileHandler
|
||||
) : DataHandler(HandlerType.MONGO) {
|
||||
private val client: CoroutineClient
|
||||
private val collection: CoroutineCollection<UUIDProfile>
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
|
||||
init {
|
||||
System.setProperty(
|
||||
"org.litote.mongo.mapping.service",
|
||||
"org.litote.kmongo.jackson.JacksonClassMappingTypeService"
|
||||
)
|
||||
|
||||
val url = plugin.configYml.getString("mongodb.url")
|
||||
|
||||
client = KMongo.createClient(url).coroutine
|
||||
collection = client.getDatabase("eco").getCollection()
|
||||
}
|
||||
|
||||
override fun <T : Any> read(uuid: UUID, key: PersistentDataKey<T>): T? {
|
||||
return runBlocking {
|
||||
doRead(uuid, key)
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T : Any> write(uuid: UUID, key: PersistentDataKey<T>, value: T) {
|
||||
scope.launch {
|
||||
doWrite(uuid, key, value)
|
||||
}
|
||||
}
|
||||
|
||||
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
|
||||
val profile = handler.loadGenericProfile(uuid)
|
||||
|
||||
scope.launch {
|
||||
for (key in keys) {
|
||||
saveKey(profile, uuid, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun <T : Any> saveKey(profile: Profile, uuid: UUID, key: PersistentDataKey<T>) {
|
||||
val data = profile.read(key)
|
||||
doWrite(uuid, key, data)
|
||||
}
|
||||
|
||||
private suspend fun <T> doWrite(uuid: UUID, key: PersistentDataKey<T>, value: T) {
|
||||
val profile = getOrCreateDocument(uuid)
|
||||
|
||||
val newData = profile.data.apply {
|
||||
if (value == null) {
|
||||
this.remove(key.key.toString())
|
||||
} else {
|
||||
this[key.key.toString()] = value
|
||||
}
|
||||
}
|
||||
|
||||
collection.updateOne(UUIDProfile::uuid eq uuid.toString(), setValue(UUIDProfile::data, newData))
|
||||
}
|
||||
|
||||
private suspend fun <T> doRead(uuid: UUID, key: PersistentDataKey<T>): T? {
|
||||
val profile = collection.findOne(UUIDProfile::uuid eq uuid.toString()) ?: return key.defaultValue
|
||||
return profile.data[key.key.toString()] as? T?
|
||||
}
|
||||
|
||||
private suspend fun getOrCreateDocument(uuid: UUID): UUIDProfile {
|
||||
val profile = collection.findOne(UUIDProfile::uuid eq uuid.toString())
|
||||
return if (profile == null) {
|
||||
collection.insertOne(
|
||||
UUIDProfile(
|
||||
uuid.toString(),
|
||||
mutableMapOf()
|
||||
)
|
||||
)
|
||||
|
||||
getOrCreateDocument(uuid)
|
||||
} else {
|
||||
profile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class UUIDProfile(
|
||||
// Storing UUID as strings for serialization
|
||||
@BsonId
|
||||
val uuid: String,
|
||||
// Storing NamespacedKeys as strings for serialization
|
||||
val data: MutableMap<String, Any>
|
||||
)
|
||||
@@ -13,8 +13,6 @@ import com.willfp.eco.internal.spigot.data.KeyHelpers
|
||||
import com.willfp.eco.internal.spigot.data.serverProfileUUID
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import org.apache.logging.log4j.Level
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.jetbrains.exposed.dao.id.UUIDTable
|
||||
import org.jetbrains.exposed.sql.BooleanColumnType
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
@@ -24,27 +22,43 @@ import org.jetbrains.exposed.sql.IntegerColumnType
|
||||
import org.jetbrains.exposed.sql.ResultRow
|
||||
import org.jetbrains.exposed.sql.SchemaUtils
|
||||
import org.jetbrains.exposed.sql.VarCharColumnType
|
||||
import org.jetbrains.exposed.sql.exposedLogger
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.Future
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/*
|
||||
|
||||
The MySQL data handler is hot garbage for several reasons:
|
||||
- Using MySQL on unstructured data: it's being horrifically misused, but that's just how it has to be.
|
||||
- Can't remove un-needed keys, there's wasted space in the columns everywhere.
|
||||
- No native support for the STRING_LIST type, instead it 'serializes' the lists with semicolons as separators.
|
||||
- General lack of flexibility, it's too rigid.
|
||||
|
||||
That's why I added the MongoDB handler, it's far, far better suited for what eco does - use it over
|
||||
MySQL if you can.
|
||||
|
||||
Oh, also - I don't really know how this class works. I've rewritten it and hacked it together several ways
|
||||
in several sessions, and it's basically complete gibberish to me. Adding the STRING_LIST type is probably
|
||||
the worst bodge I've shipped in production.
|
||||
|
||||
*/
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class MySQLDataHandler(
|
||||
private val plugin: EcoSpigotPlugin,
|
||||
handler: EcoProfileHandler
|
||||
) : DataHandler {
|
||||
) : DataHandler(HandlerType.MYSQL) {
|
||||
private val playerHandler: ImplementedMySQLHandler
|
||||
private val serverHandler: ImplementedMySQLHandler
|
||||
|
||||
init {
|
||||
plugin.logger.warning("You're using the MySQL Data Handler")
|
||||
plugin.logger.warning("It's recommended to switch to MongoDB (mongo)!")
|
||||
|
||||
val config = HikariConfig()
|
||||
config.driverClassName = "com.mysql.cj.jdbc.Driver"
|
||||
@@ -58,40 +72,26 @@ class MySQLDataHandler(
|
||||
|
||||
Database.connect(HikariDataSource(config))
|
||||
|
||||
// Get Exposed to shut the hell up
|
||||
runCatching {
|
||||
exposedLogger::class.java.getDeclaredField("logger").apply { isAccessible = true }
|
||||
.apply {
|
||||
get(exposedLogger).apply {
|
||||
this.javaClass.getDeclaredMethod("setLevel", Level::class.java)
|
||||
.invoke(this, Level.OFF)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
playerHandler = ImplementedMySQLHandler(
|
||||
handler,
|
||||
UUIDTable("eco_players"),
|
||||
plugin,
|
||||
plugin.dataYml.getStrings("categorized-keys.player")
|
||||
.mapNotNull { KeyHelpers.deserializeFromString(it) }
|
||||
plugin
|
||||
)
|
||||
|
||||
serverHandler = ImplementedMySQLHandler(
|
||||
handler,
|
||||
UUIDTable("eco_server"),
|
||||
plugin,
|
||||
plugin.dataYml.getStrings("categorized-keys.server")
|
||||
.mapNotNull { KeyHelpers.deserializeFromString(it) }
|
||||
plugin
|
||||
)
|
||||
}
|
||||
|
||||
override fun saveAll(uuids: Iterable<UUID>) {
|
||||
serverHandler.saveAll(uuids.filter { it == serverProfileUUID })
|
||||
playerHandler.saveAll(uuids.filter { it != serverProfileUUID })
|
||||
override fun <T : Any> read(uuid: UUID, key: PersistentDataKey<T>): T? {
|
||||
return applyFor(uuid) {
|
||||
it.read(uuid, key)
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T> write(uuid: UUID, key: NamespacedKey, value: T) {
|
||||
override fun <T : Any> write(uuid: UUID, key: PersistentDataKey<T>, value: T) {
|
||||
applyFor(uuid) {
|
||||
it.write(uuid, key, value)
|
||||
}
|
||||
@@ -103,12 +103,6 @@ class MySQLDataHandler(
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T> read(uuid: UUID, key: PersistentDataKey<T>): T? {
|
||||
return applyFor(uuid) {
|
||||
it.read(uuid, key.key)
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <R> applyFor(uuid: UUID, function: (ImplementedMySQLHandler) -> R): R {
|
||||
return if (uuid == serverProfileUUID) {
|
||||
function(serverHandler)
|
||||
@@ -119,21 +113,21 @@ class MySQLDataHandler(
|
||||
|
||||
override fun categorize(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) {
|
||||
if (category == KeyRegistry.KeyCategory.SERVER) {
|
||||
serverHandler.ensureKeyRegistration(key.key)
|
||||
serverHandler.ensureKeyRegistration(key)
|
||||
} else {
|
||||
playerHandler.ensureKeyRegistration(key.key)
|
||||
playerHandler.ensureKeyRegistration(key)
|
||||
}
|
||||
}
|
||||
|
||||
override fun save() {
|
||||
plugin.dataYml.set(
|
||||
"categorized-keys.player",
|
||||
playerHandler.registeredKeys.values
|
||||
playerHandler.registeredKeys
|
||||
.map { KeyHelpers.serializeToString(it) }
|
||||
)
|
||||
plugin.dataYml.set(
|
||||
"categorized-keys.server",
|
||||
serverHandler.registeredKeys.values
|
||||
serverHandler.registeredKeys
|
||||
.map { KeyHelpers.serializeToString(it) }
|
||||
)
|
||||
plugin.dataYml.save()
|
||||
@@ -149,21 +143,15 @@ class MySQLDataHandler(
|
||||
private class ImplementedMySQLHandler(
|
||||
private val handler: EcoProfileHandler,
|
||||
private val table: UUIDTable,
|
||||
plugin: EcoPlugin,
|
||||
private val knownKeys: Collection<PersistentDataKey<*>>
|
||||
plugin: EcoPlugin
|
||||
) {
|
||||
private val columns = Caffeine.newBuilder()
|
||||
.expireAfterWrite(3, TimeUnit.SECONDS)
|
||||
.build<String, Column<*>>()
|
||||
|
||||
private val rows = Caffeine.newBuilder()
|
||||
.expireAfterWrite(3, TimeUnit.SECONDS)
|
||||
.build<UUID, ResultRow>()
|
||||
|
||||
private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build()
|
||||
private val executor = Executors.newFixedThreadPool(plugin.configYml.getInt("mysql.threads"), threadFactory)
|
||||
val registeredKeys = ConcurrentHashMap<NamespacedKey, PersistentDataKey<*>>()
|
||||
private val currentlyProcessingRegistration = ConcurrentHashMap<NamespacedKey, Future<*>>()
|
||||
val registeredKeys = mutableSetOf<PersistentDataKey<*>>()
|
||||
|
||||
init {
|
||||
transaction {
|
||||
@@ -173,58 +161,32 @@ private class ImplementedMySQLHandler(
|
||||
|
||||
fun initialize() {
|
||||
transaction {
|
||||
for (key in knownKeys) {
|
||||
registerColumn(key, table)
|
||||
}
|
||||
|
||||
SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
|
||||
for (key in knownKeys) {
|
||||
registeredKeys[key.key] = key
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun ensureKeyRegistration(key: NamespacedKey) {
|
||||
if (registeredKeys.contains(key)) {
|
||||
fun ensureKeyRegistration(key: PersistentDataKey<*>) {
|
||||
if (table.columns.any { it.name == key.key.toString() }) {
|
||||
registeredKeys.add(key)
|
||||
return
|
||||
}
|
||||
|
||||
val persistentKey = Eco.getHandler().keyRegistry.getKeyFrom(key) ?: return
|
||||
|
||||
if (table.columns.any { it.name == key.toString() }) {
|
||||
registeredKeys[key] = persistentKey
|
||||
return
|
||||
}
|
||||
|
||||
val future = currentlyProcessingRegistration[key]
|
||||
|
||||
if (future != null) {
|
||||
future.get()
|
||||
return
|
||||
}
|
||||
|
||||
currentlyProcessingRegistration[key] = executor.submit {
|
||||
transaction {
|
||||
registerColumn(persistentKey, table)
|
||||
SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
|
||||
}
|
||||
registeredKeys[key] = persistentKey
|
||||
currentlyProcessingRegistration.remove(key)
|
||||
}
|
||||
registerColumn(key)
|
||||
registeredKeys.add(key)
|
||||
}
|
||||
|
||||
fun <T> write(uuid: UUID, key: NamespacedKey, value: T) {
|
||||
getOrCreateRow(uuid)
|
||||
doWrite(uuid, key, value)
|
||||
fun <T : Any> write(uuid: UUID, key: PersistentDataKey<T>, value: Any) {
|
||||
getRow(uuid)
|
||||
doWrite(uuid, key, key.type.constrainSQLTypes(value))
|
||||
}
|
||||
|
||||
private fun <T> doWrite(uuid: UUID, key: NamespacedKey, value: T) {
|
||||
val column: Column<T> = getColumn(key) as Column<T>
|
||||
private fun doWrite(uuid: UUID, key: PersistentDataKey<*>, constrainedValue: Any) {
|
||||
val column: Column<Any> = getColumn(key) as Column<Any>
|
||||
|
||||
executor.submit {
|
||||
transaction {
|
||||
table.update({ table.id eq uuid }) {
|
||||
it[column] = value
|
||||
it[column] = constrainedValue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,35 +196,28 @@ private class ImplementedMySQLHandler(
|
||||
saveRow(uuid, keys)
|
||||
}
|
||||
|
||||
fun saveAll(uuids: Iterable<UUID>) {
|
||||
for (uuid in uuids) {
|
||||
saveRow(uuid, PersistentDataKey.values())
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveRow(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
|
||||
val profile = handler.loadGenericProfile(uuid)
|
||||
|
||||
executor.submit {
|
||||
transaction {
|
||||
getOrCreateRow(uuid)
|
||||
getRow(uuid)
|
||||
|
||||
for (key in keys) {
|
||||
doWrite(uuid, key.key, profile.read(key))
|
||||
doWrite(uuid, key, key.type.constrainSQLTypes(profile.read(key)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> read(uuid: UUID, key: NamespacedKey): T? {
|
||||
fun <T> read(uuid: UUID, key: PersistentDataKey<T>): T? {
|
||||
val doRead = Callable<T?> {
|
||||
var value: T? = null
|
||||
transaction {
|
||||
val row = getOrCreateRow(uuid)
|
||||
value = row[getColumn(key)] as T?
|
||||
val row = getRow(uuid)
|
||||
val column = getColumn(key)
|
||||
val raw = row[column]
|
||||
key.type.fromConstrained(raw)
|
||||
}
|
||||
|
||||
return@Callable value
|
||||
}
|
||||
|
||||
ensureKeyRegistration(key) // DON'T DELETE THIS LINE! I know it's covered in getColumn, but I need to do it here as well.
|
||||
@@ -274,38 +229,40 @@ private class ImplementedMySQLHandler(
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> registerColumn(key: PersistentDataKey<T>, table: UUIDTable) {
|
||||
table.apply {
|
||||
if (this.columns.stream().anyMatch { it.name == key.key.toString() }) {
|
||||
return@apply
|
||||
private fun <T> registerColumn(key: PersistentDataKey<T>) {
|
||||
transaction {
|
||||
table.apply {
|
||||
when (key.type) {
|
||||
PersistentDataKeyType.INT -> registerColumn<Int>(key.key.toString(), IntegerColumnType())
|
||||
.default(key.defaultValue as Int)
|
||||
PersistentDataKeyType.DOUBLE -> registerColumn<Double>(key.key.toString(), DoubleColumnType())
|
||||
.default(key.defaultValue as Double)
|
||||
PersistentDataKeyType.BOOLEAN -> registerColumn<Boolean>(key.key.toString(), BooleanColumnType())
|
||||
.default(key.defaultValue as Boolean)
|
||||
PersistentDataKeyType.STRING -> registerColumn<String>(key.key.toString(), VarCharColumnType(512))
|
||||
.default(key.defaultValue as String)
|
||||
PersistentDataKeyType.STRING_LIST -> registerColumn<String>(
|
||||
key.key.toString(),
|
||||
VarCharColumnType(8192)
|
||||
).default(PersistentDataKeyType.STRING_LIST.constrainSQLTypes(key.defaultValue as List<String>) as String)
|
||||
|
||||
else -> throw NullPointerException("Null value found!")
|
||||
}
|
||||
}
|
||||
|
||||
when (key.type) {
|
||||
PersistentDataKeyType.INT -> registerColumn<Int>(key.key.toString(), IntegerColumnType())
|
||||
.default(key.defaultValue as Int)
|
||||
PersistentDataKeyType.DOUBLE -> registerColumn<Double>(key.key.toString(), DoubleColumnType())
|
||||
.default(key.defaultValue as Double)
|
||||
PersistentDataKeyType.BOOLEAN -> registerColumn<Boolean>(key.key.toString(), BooleanColumnType())
|
||||
.default(key.defaultValue as Boolean)
|
||||
PersistentDataKeyType.STRING -> registerColumn<String>(key.key.toString(), VarCharColumnType(512))
|
||||
.default(key.defaultValue as String)
|
||||
|
||||
else -> throw NullPointerException("Null value found!")
|
||||
}
|
||||
SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getColumn(key: NamespacedKey): Column<*> {
|
||||
private fun getColumn(key: PersistentDataKey<*>): Column<*> {
|
||||
ensureKeyRegistration(key)
|
||||
|
||||
val name = key.toString()
|
||||
val name = key.key.toString()
|
||||
|
||||
return columns.get(name) {
|
||||
table.columns.first { it.name == name }
|
||||
}
|
||||
return table.columns.first { it.name == name }
|
||||
}
|
||||
|
||||
private fun getOrCreateRow(uuid: UUID): ResultRow {
|
||||
private fun getRow(uuid: UUID): ResultRow {
|
||||
fun select(uuid: UUID): ResultRow? {
|
||||
return transaction {
|
||||
table.select { table.id eq uuid }.limit(1).singleOrNull()
|
||||
@@ -326,3 +283,27 @@ private class ImplementedMySQLHandler(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> PersistentDataKeyType<T>.constrainSQLTypes(value: Any): Any {
|
||||
return if (this == PersistentDataKeyType.STRING_LIST) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
value as List<String>
|
||||
value.joinToString(separator = ";")
|
||||
} else {
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> PersistentDataKeyType<T>.fromConstrained(constrained: Any?): T? {
|
||||
if (constrained == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return if (this == PersistentDataKeyType.STRING_LIST) {
|
||||
constrained as String
|
||||
constrained.split(";").toList()
|
||||
} else {
|
||||
constrained
|
||||
} as T
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.willfp.eco.internal.spigot.data.storage
|
||||
|
||||
import com.willfp.eco.core.Eco
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.data.ProfileHandler
|
||||
import com.willfp.eco.internal.spigot.data.EcoProfile
|
||||
|
||||
class ProfileSaver(plugin: EcoPlugin) {
|
||||
class ProfileSaver(
|
||||
plugin: EcoPlugin,
|
||||
handler: ProfileHandler
|
||||
) {
|
||||
init {
|
||||
plugin.scheduler.runTimer({
|
||||
plugin.scheduler.runTimer(1, 1) {
|
||||
for ((uuid, set) in EcoProfile.CHANGE_MAP) {
|
||||
Eco.getHandler().profileHandler.saveKeysFor(uuid, set)
|
||||
handler.saveKeysFor(uuid, set)
|
||||
}
|
||||
EcoProfile.CHANGE_MAP.clear()
|
||||
}, 1, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,42 +11,40 @@ import java.util.UUID
|
||||
class YamlDataHandler(
|
||||
plugin: EcoSpigotPlugin,
|
||||
private val handler: EcoProfileHandler
|
||||
) : DataHandler {
|
||||
) : DataHandler(HandlerType.YAML) {
|
||||
private val dataYml = plugin.dataYml
|
||||
|
||||
override fun save() {
|
||||
dataYml.save()
|
||||
}
|
||||
|
||||
override fun saveAll(uuids: Iterable<UUID>) {
|
||||
for (uuid in uuids) {
|
||||
savePlayer(uuid)
|
||||
override fun <T : Any> read(uuid: UUID, key: PersistentDataKey<T>): T? {
|
||||
// Separate `as T?` for each branch to prevent compiler warnings.
|
||||
val value = when (key.type) {
|
||||
PersistentDataKeyType.INT -> dataYml.getIntOrNull("player.$uuid.${key.key}") as T?
|
||||
PersistentDataKeyType.DOUBLE -> dataYml.getDoubleOrNull("player.$uuid.${key.key}") as T?
|
||||
PersistentDataKeyType.STRING -> dataYml.getStringOrNull("player.$uuid.${key.key}") as T?
|
||||
PersistentDataKeyType.BOOLEAN -> dataYml.getBoolOrNull("player.$uuid.${key.key}") as T?
|
||||
PersistentDataKeyType.STRING_LIST -> dataYml.getStringsOrNull("player.$uuid.${key.key}") as T?
|
||||
else -> null
|
||||
}
|
||||
|
||||
save()
|
||||
return value
|
||||
}
|
||||
|
||||
override fun <T : Any> write(uuid: UUID, key: PersistentDataKey<T>, value: T) {
|
||||
doWrite(uuid, key.key, value)
|
||||
}
|
||||
|
||||
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
|
||||
val profile = handler.loadGenericProfile(uuid)
|
||||
|
||||
for (key in keys) {
|
||||
write(uuid, key.key, profile.read(key))
|
||||
doWrite(uuid, key.key, profile.read(key))
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T> write(uuid: UUID, key: NamespacedKey, value: T) {
|
||||
private fun doWrite(uuid: UUID, key: NamespacedKey, value: Any) {
|
||||
dataYml.set("player.$uuid.$key", value)
|
||||
}
|
||||
|
||||
override fun <T> read(uuid: UUID, key: PersistentDataKey<T>): T? {
|
||||
val value = when (key.type) {
|
||||
PersistentDataKeyType.INT -> dataYml.getIntOrNull("player.$uuid.${key.key}")
|
||||
PersistentDataKeyType.DOUBLE -> dataYml.getDoubleOrNull("player.$uuid.${key.key}")
|
||||
PersistentDataKeyType.STRING -> dataYml.getStringOrNull("player.$uuid.${key.key}")
|
||||
PersistentDataKeyType.BOOLEAN -> dataYml.getBoolOrNull("player.$uuid.${key.key}")
|
||||
else -> null
|
||||
} as? T?
|
||||
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ class PacketAutoRecipe(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, Packet
|
||||
player: Player,
|
||||
event: PacketEvent
|
||||
) {
|
||||
if (!this.getPlugin().configYml.getBool("displayed-recipes")) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!EcoPlugin.getPluginNames()
|
||||
.contains(packet.minecraftKeys.values[0].fullKey.split(":".toRegex()).toTypedArray()[0])
|
||||
) {
|
||||
@@ -28,4 +32,4 @@ class PacketAutoRecipe(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, Packet
|
||||
newAutoRecipe.minecraftKeys.write(0, packet.minecraftKeys.read(0))
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, newAutoRecipe)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ import com.comphenix.protocol.events.PacketEvent
|
||||
import com.willfp.eco.core.AbstractPacketAdapter
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy
|
||||
import com.willfp.eco.util.NamespacedKeyUtils
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemFlag
|
||||
import org.bukkit.inventory.MerchantRecipe
|
||||
|
||||
class PacketOpenWindowMerchant(plugin: EcoPlugin) :
|
||||
@@ -24,22 +22,6 @@ class PacketOpenWindowMerchant(plugin: EcoPlugin) :
|
||||
) {
|
||||
val recipes = mutableListOf<MerchantRecipe>()
|
||||
|
||||
|
||||
/*
|
||||
This awful, awful bit of code exists to fix a bug that existed in EcoEnchants
|
||||
for too many versions.
|
||||
*/
|
||||
if (getPlugin().configYml.getBool("villager-display-fix")) {
|
||||
for (recipe in packet.merchantRecipeLists.read(0)) {
|
||||
val result = recipe.result
|
||||
val meta = result.itemMeta
|
||||
if (meta != null) {
|
||||
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS)
|
||||
meta.persistentDataContainer.remove(NamespacedKeyUtils.create("ecoenchants", "ecoenchantlore-skip"))
|
||||
result.itemMeta = meta
|
||||
}
|
||||
}
|
||||
}
|
||||
for (recipe in packet.merchantRecipeLists.read(0)) {
|
||||
val newRecipe = getPlugin().getProxy(VillagerTradeProxy::class.java).displayTrade(
|
||||
recipe!!, player
|
||||
|
||||
@@ -17,11 +17,13 @@ class PacketSetSlot(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketTyp
|
||||
player: Player,
|
||||
event: PacketEvent
|
||||
) {
|
||||
packet.itemModifier.modify(0) { item: ItemStack? ->
|
||||
Display.display(
|
||||
item!!, player
|
||||
)
|
||||
}
|
||||
packet.itemModifier.modify(0, object : VersionCompatiblePLibFunction<ItemStack> {
|
||||
override fun apply(item: ItemStack) =
|
||||
Display.display(
|
||||
item,
|
||||
player
|
||||
)
|
||||
})
|
||||
|
||||
player.lastDisplayFrame = DisplayFrame.EMPTY
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user