Compare commits

..

119 Commits

Author SHA1 Message Date
Auxilor
a6754379e8 Updated to 6.37.3 2022-07-07 22:55:03 +01:00
Auxilor
bbd0182c2a Fixed weird bug 2022-07-07 22:54:54 +01:00
Auxilor
0370e9f454 Fixed startup order 2022-07-03 16:49:26 +01:00
Auxilor
8d585b58cb Fixed initializing text 2022-07-03 16:45:44 +01:00
Auxilor
0bfbd4c036 Updated to 6.37.2 2022-07-03 16:38:32 +01:00
Auxilor
881839955e Added player health fixer 2022-07-03 16:38:21 +01:00
Auxilor
709de3bb5f Updated to 6.37.1 2022-06-14 12:43:11 +01:00
Auxilor
f2aa2ffd9b Removed ExactTestableItem 2022-06-14 12:43:04 +01:00
Auxilor
5ce70399f0 Improved SNBT lookups 2022-06-14 12:42:49 +01:00
Auxilor
3f8759b08a Updated to 6.37.0 2022-06-14 12:14:33 +01:00
Auxilor
abecaa6e9f Added SNBT parsing 2022-06-14 12:13:48 +01:00
Auxilor
4744bfc78b Updated to 6.36.5 2022-06-09 19:24:49 +01:00
Auxilor
487e68221a Added 1.19 support 2022-06-09 19:24:37 +01:00
Auxilor
1c68992a8e Updated to 6.36.4 2022-05-29 17:46:52 +01:00
Auxilor
c5b7d0b644 Fixed conflict finder breaking the polymart autoupdater 2022-05-29 17:46:24 +01:00
Auxilor
0f91aec3b7 Slots can now be not captive for some players 2022-05-29 11:34:32 +01:00
Auxilor
d2bf38c5c9 Updated to 6.36.3 2022-05-29 11:11:33 +01:00
Auxilor
2c96b79aba Improved slots 2022-05-29 11:11:16 +01:00
Auxilor
d539b9e59e Improvements to captive items 2022-05-28 17:33:06 +01:00
Auxilor
b0b06ef402 Updated to 6.36.2 2022-05-28 17:20:35 +01:00
Auxilor
7a84c3de3b Captive from empty, take 2 2022-05-28 17:20:23 +01:00
Auxilor
9431321e1c Revert "Added captive defaults"
This reverts commit 7adcdd572d.
2022-05-28 17:08:36 +01:00
Auxilor
4816284fba Revert "Added captive default kotlin extension"
This reverts commit 2bcbf181a9.
2022-05-28 17:08:01 +01:00
Auxilor
a9874c9386 Revert "Updated to 6.37.0"
This reverts commit fc3c80f633.
2022-05-28 17:08:01 +01:00
Auxilor
fe68760184 Revert "Fixed backwards compatibility"
This reverts commit 1f7cf78491.
2022-05-28 17:08:01 +01:00
Auxilor
5ae8e72a98 Revert "Fixed captive default"
This reverts commit 15fc6053c8.
2022-05-28 17:08:01 +01:00
Auxilor
15fc6053c8 Fixed captive default 2022-05-28 16:54:58 +01:00
Auxilor
1f7cf78491 Fixed backwards compatibility 2022-05-28 16:43:35 +01:00
Auxilor
fc3c80f633 Updated to 6.37.0 2022-05-28 16:41:30 +01:00
Auxilor
2bcbf181a9 Added captive default kotlin extension 2022-05-28 16:41:20 +01:00
Auxilor
7adcdd572d Added captive defaults 2022-05-28 16:40:14 +01:00
Auxilor
f6eba21006 Updated to 6.36.1 2022-05-28 16:10:40 +01:00
Auxilor
cc02f26807 Fixed key registry 2022-05-28 16:10:30 +01:00
Auxilor
60f552ce65 KDoc Formatting 2022-05-28 14:38:59 +01:00
Auxilor
9fe8d4ad15 Added more slot builders 2022-05-28 14:36:48 +01:00
Auxilor
b835988eec Added toSingletonList 2022-05-28 14:32:35 +01:00
Auxilor
22366835de Added additional MaskItems constructor 2022-05-28 14:31:20 +01:00
Auxilor
cdd1baec6c Fixed codemc 2022-05-28 14:28:24 +01:00
Auxilor
1ea0da365a Removed villager-display-fix 2022-05-28 13:59:38 +01:00
Auxilor
852d40372d Added option to toggle displayed recipes 2022-05-28 13:59:03 +01:00
Auxilor
999c831dd7 Removed non-functional packet splitting 2022-05-28 13:47:44 +01:00
Auxilor
80fa5d346a Fixed recipe packet fixer 2022-05-28 12:37:47 +01:00
Auxilor
336cdc3716 Added recipe packet splitting 2022-05-28 12:31:55 +01:00
Auxilor
a49a9e92b4 Updated villager trade 2022-05-28 12:23:47 +01:00
Auxilor
1c6e64832e Minor changes 2022-05-28 12:12:35 +01:00
Auxilor
44a141cddc Improved economy helpers 2022-05-27 19:03:53 +01:00
Auxilor
ea4956870e Added more GUI kotlin utils 2022-05-27 19:02:47 +01:00
Auxilor
9207d1782b Various changes 2022-05-27 17:09:00 +01:00
Auxilor
9debcb7089 Server will no longer restart after data migration 2022-05-27 16:25:11 +01:00
Auxilor
ef53ee2ed3 Fixed constrained types 2022-05-27 16:17:31 +01:00
Auxilor
4c90360038 More MySQL fixes 2022-05-27 16:07:24 +01:00
Auxilor
d4b5102913 Fixed MySQL 2022-05-27 16:01:44 +01:00
Auxilor
f4553c544a Fixed MySQL 2022-05-27 15:57:15 +01:00
Auxilor
5ad1db72fc Fixed minimize 2022-05-27 15:52:36 +01:00
Auxilor
c761df9ee6 Data Handler changes 2022-05-27 15:48:13 +01:00
Auxilor
b6d79da4e1 Improved config.yml header 2022-05-27 15:43:02 +01:00
Auxilor
42f41618ca Added warning for MySQL users 2022-05-27 15:38:28 +01:00
Auxilor
de878fd423 Codestyle 2022-05-27 15:29:39 +01:00
Auxilor
7782657d57 Improved DataHandlers again 2022-05-27 15:29:03 +01:00
Auxilor
7778425936 Improved DataHandler 2022-05-27 15:12:05 +01:00
Auxilor
6446cef255 OOps 2022-05-27 15:06:18 +01:00
Auxilor
8dacecbcba Added big ominous comment to the MySQL Data Handler 2022-05-27 15:06:00 +01:00
Auxilor
5f8ec4f94a Added PersistentDataKeyType#STRING_LIST 2022-05-27 14:56:53 +01:00
Auxilor
d7847e9efc Optimized writes mongo 2022-05-27 14:17:17 +01:00
Auxilor
930ecd4896 Improved conflict finder 2022-05-27 14:03:54 +01:00
Auxilor
af8d6a4167 Added OfflinePlayer#balance kotlin extensions 2022-05-27 14:02:52 +01:00
Auxilor
361f0a0103 Added unused suppression 2022-05-27 13:58:45 +01:00
Auxilor
eb545a7d9e Fixed relocations 2022-05-27 13:53:28 +01:00
Auxilor
d3c64deef4 Fixed minimize / exclude 2022-05-27 13:51:20 +01:00
Auxilor
31db9dcb95 Minimzed plugin module 2022-05-27 13:24:35 +01:00
Auxilor
4938ad84bc Added clarifying comment 2022-05-27 13:02:51 +01:00
Auxilor
06b2301da1 Janky fix for mongo logging 2022-05-27 13:00:59 +01:00
Auxilor
c307878c09 More migration improvements 2022-05-26 20:40:57 +01:00
Auxilor
3b10ff01ec Updated to 6.36.0 2022-05-26 20:17:47 +01:00
Auxilor
e042754f5d Mongo improvements / Added data migration 2022-05-26 20:17:31 +01:00
Auxilor
c2b8a80560 Improved MongoDB 2022-05-25 20:21:50 +01:00
Auxilor
07c0e72564 Added MongoDB data handler 2022-05-25 20:08:24 +01:00
Auxilor
de9b961d83 Revert "Added LONG_STRING column type"
This reverts commit 83958c719c.
2022-05-25 19:20:47 +01:00
Auxilor
83958c719c Added LONG_STRING column type 2022-05-21 19:35:05 +01:00
Auxilor
9c3dfaeb01 Updated to 6.35.12 2022-05-19 17:13:00 +01:00
Auxilor
7e61340285 Fixed static placeholder string formatting 2022-05-19 17:12:51 +01:00
Auxilor
78b76cb453 Updated to 6.35.11 2022-05-18 16:02:56 +01:00
Auxilor
bb1da29704 Added placeholder injections to strings 2022-05-18 16:02:36 +01:00
Auxilor
cf152215d3 Cleaned up internal 2022-05-18 15:00:23 +01:00
Auxilor
e6a59fbc91 Updated to 6.35.10 2022-05-18 10:53:06 +01:00
Will FP
b787f8b76a Merge pull request #133
Bump io.papermc.paperweight.userdev from 1.3.5 to 1.3.6
2022-05-18 10:52:43 +01:00
Will FP
ccc83da5b0 Merge pull request #135
Bump caffeine from 3.0.6 to 3.1.0
2022-05-18 10:52:30 +01:00
Will FP
f11068f2f1 Merge pull request #145
add CMI gradient format
2022-05-18 10:52:18 +01:00
Will FP
a5cc1a5d32 Merge pull request #146
Add an exception for armorstand in interact flag of WG
2022-05-18 10:52:10 +01:00
Kapitowa
7440749ba5 Add an exception for armorstand in interact flag of WG 2022-05-18 01:28:10 +03:00
Kapitowa
75010d25fa add CMI gradient format 2022-05-18 01:01:07 +03:00
Auxilor
bb95376b93 Removed async-display 2022-05-17 19:55:13 +01:00
Auxilor
ab6d4c7aa2 Updated to 6.35.9 2022-05-17 16:53:57 +01:00
Auxilor
9ab8827e55 Fixed non-applied FIS Flags 2022-05-17 16:45:37 +01:00
Auxilor
991290095b Updated to 6.35.8 2022-05-17 10:19:48 +01:00
Auxilor
8735478fc3 More bit manip 2022-05-17 10:19:36 +01:00
Auxilor
6e44f09621 Fixed ItemFlags in FastItemStack 2022-05-17 10:11:04 +01:00
Auxilor
060106881e Updated to 6.35.7 2022-05-13 12:07:26 +01:00
Auxilor
96cc9706b3 Placeholder injection fixes 2022-05-13 12:07:15 +01:00
Auxilor
3d87b1eb73 Revert "Fixed placeholder injection bugs"
This reverts commit 06bcb10958.
2022-05-13 11:46:57 +01:00
Auxilor
4c4247b4ec Revert "Updated to 6.35.7"
This reverts commit b94dc4ac3a.
2022-05-13 11:46:57 +01:00
Auxilor
b94dc4ac3a Updated to 6.35.7 2022-05-13 11:34:58 +01:00
Auxilor
06bcb10958 Fixed placeholder injection bugs 2022-05-13 11:34:42 +01:00
Auxilor
295095e9ce Fixed spelling 2022-05-09 12:34:14 +01:00
Auxilor
ba9c5865e3 Updated to 6.35.6 2022-05-09 12:30:22 +01:00
Auxilor
d24be4121f Added conflict finder 2022-05-09 12:30:14 +01:00
Auxilor
bcc5e4ef08 Skull improvements 2022-05-09 10:23:35 +01:00
Auxilor
bf8609666a Codestyle 2022-05-09 10:20:05 +01:00
Auxilor
1a02335825 Fixed dumbest error of all time 2022-05-09 10:14:18 +01:00
Auxilor
f5ef98ec5c Improved custom item lookup 2022-05-09 10:11:06 +01:00
Auxilor
45135e2b55 Updated to 6.35.5 2022-05-08 17:27:14 +01:00
Auxilor
758b42ff8e Fixed ItemsAdder integration 2022-05-08 17:26:50 +01:00
Auxilor
4a134402da Fixed Prerequisite#HAS_PAPER 2022-05-06 09:09:54 +01:00
Auxilor
e6ad4c9268 Updated to 6.35.4 2022-05-06 09:08:38 +01:00
Auxilor
809dcbae85 Improved NaturalExpGainListeners for paper 2022-05-06 09:07:57 +01:00
Auxilor
d7fce6834c Updated to 6.35.3 2022-05-03 13:05:41 +01:00
Auxilor
ac807a991b Players can no longer tab-complete commands they don't have permission for 2022-05-03 13:05:32 +01:00
dependabot[bot]
bd5555ff01 Bump caffeine from 3.0.6 to 3.1.0
Bumps [caffeine](https://github.com/ben-manes/caffeine) from 3.0.6 to 3.1.0.
- [Release notes](https://github.com/ben-manes/caffeine/releases)
- [Commits](https://github.com/ben-manes/caffeine/compare/v3.0.6...v3.1.0)

---
updated-dependencies:
- dependency-name: com.github.ben-manes.caffeine:caffeine
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-28 21:41:30 +00:00
dependabot[bot]
5f80b6052d Bump io.papermc.paperweight.userdev from 1.3.5 to 1.3.6
Bumps [io.papermc.paperweight.userdev](https://github.com/PaperMC/paperweight) from 1.3.5 to 1.3.6.
- [Release notes](https://github.com/PaperMC/paperweight/releases)
- [Commits](https://github.com/PaperMC/paperweight/compare/v1.3.5...v1.3.6)

---
updated-dependencies:
- dependency-name: io.papermc.paperweight.userdev
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-22 21:29:44 +00:00
99 changed files with 1998 additions and 735 deletions

View File

@@ -18,12 +18,13 @@ plugins {
dependencies { dependencies {
implementation(project(":eco-api")) 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-proxy"))
implementation(project(":eco-core:core-backend")) 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_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_R1", configuration = "reobf"))
implementation(project(path = ":eco-core:core-nms:v1_18_R2", 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 { allprojects {
@@ -44,11 +45,8 @@ allprojects {
// SuperiorSkyblock2 // SuperiorSkyblock2
maven("https://repo.bg-software.com/repository/api/") maven("https://repo.bg-software.com/repository/api/")
// NMS (for jitpack compilation)
maven("https://repo.codemc.org/repository/nms/")
// mcMMO, BentoBox // mcMMO, BentoBox
maven("https://repo.codemc.org/repository/maven-public/") maven("https://repo.codemc.io/repository/maven-public/")
// Spigot API, Bungee API // Spigot API, Bungee API
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
@@ -84,6 +82,7 @@ allprojects {
dependencies { dependencies {
// Kotlin // Kotlin
implementation(kotlin("stdlib", version = "1.6.21")) implementation(kotlin("stdlib", version = "1.6.21"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
// Included in spigot jar, no need to move to implementation // Included in spigot jar, no need to move to implementation
compileOnly("org.jetbrains:annotations:23.0.0") compileOnly("org.jetbrains:annotations:23.0.0")
@@ -101,7 +100,7 @@ allprojects {
implementation("net.kyori:adventure-text-serializer-legacy:4.10.1") implementation("net.kyori:adventure-text-serializer-legacy:4.10.1")
// Other // 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") implementation("org.apache.maven:maven-artifact:3.8.5")
} }
@@ -154,6 +153,13 @@ allprojects {
relocate("google.protobuf", "com.willfp.eco.libs.protobuf") // Still don't know relocate("google.protobuf", "com.willfp.eco.libs.protobuf") // Still don't know
relocate("com.zaxxer.hikari", "com.willfp.eco.libs.hikari") relocate("com.zaxxer.hikari", "com.willfp.eco.libs.hikari")
//relocate("com.mysql", "com.willfp.eco.libs.mysql") //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. Kotlin and caffeine are not shaded so that they can be accessed directly by eco plugins.

View File

@@ -304,6 +304,11 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
this.color = props.getColor(); this.color = props.getColor();
this.supportingExtensions = props.isSupportingExtensions(); 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.scheduler = Eco.getHandler().createScheduler(this);
this.eventManager = Eco.getHandler().createEventManager(this); this.eventManager = Eco.getHandler().createEventManager(this);
this.namespacedKeyFactory = Eco.getHandler().createNamespacedKeyFactory(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.runnableFactory = Eco.getHandler().createRunnableFactory(this);
this.extensionLoader = Eco.getHandler().createExtensionLoader(this); this.extensionLoader = Eco.getHandler().createExtensionLoader(this);
this.configHandler = Eco.getHandler().createConfigHandler(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.langYml = this.createLangYml();
this.configYml = this.createConfigYml(); this.configYml = this.createConfigYml();
Eco.getHandler().addNewPlugin(this); 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 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 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)); PlaceholderManager.addIntegration(Eco.getHandler().createPAPIIntegration(this));
} }
this.loadIntegrationLoaders().forEach((integrationLoader -> { this.loadIntegrationLoaders().forEach(integrationLoader -> {
if (enabledPlugins.contains(integrationLoader.getPluginName().toLowerCase())) { if (enabledPlugins.contains(integrationLoader.getPluginName().toLowerCase())) {
this.loadedIntegrations.add(integrationLoader.getPluginName()); this.loadedIntegrations.add(integrationLoader.getPluginName());
integrationLoader.load(); integrationLoader.load();
} }
})); });
this.getLogger().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations())); this.getLogger().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));

View File

@@ -15,6 +15,7 @@ import com.willfp.eco.core.factory.RunnableFactory;
import com.willfp.eco.core.fast.FastItemStack; import com.willfp.eco.core.fast.FastItemStack;
import com.willfp.eco.core.gui.GUIFactory; import com.willfp.eco.core.gui.GUIFactory;
import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration; 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.Cleaner;
import com.willfp.eco.core.proxy.ProxyFactory; import com.willfp.eco.core.proxy.ProxyFactory;
import com.willfp.eco.core.scheduling.Scheduler; import com.willfp.eco.core.scheduling.Scheduler;
@@ -282,8 +283,7 @@ public interface Handler {
* @param <T> The mob type. * @param <T> The mob type.
* @return The controlled entity. * @return The controlled entity.
*/ */
@NotNull @NotNull <T extends Mob> EntityController<T> createEntityController(@NotNull T mob);
<T extends Mob> EntityController<T> createEntityController(@NotNull T mob);
/** /**
* Adapt base PDC to extended PDC. * Adapt base PDC to extended PDC.
@@ -301,4 +301,12 @@ public interface Handler {
*/ */
@NotNull @NotNull
PersistentDataContainer newPdc(); PersistentDataContainer newPdc();
/**
* Get SNBT handler.
*
* @return The SNBT handler.
*/
@NotNull
SNBTHandler getSNBTHandler();
} }

View File

@@ -26,7 +26,7 @@ public class Prerequisite {
* Requires the server to be running an implementation of paper. * Requires the server to be running an implementation of paper.
*/ */
public static final Prerequisite HAS_PAPER = new Prerequisite( public static final Prerequisite HAS_PAPER = new Prerequisite(
() -> ClassUtils.exists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent"), () -> ClassUtils.exists("com.destroystokyo.paper.event.block.BeaconEffectEvent"),
"Requires server to be running paper (or a fork)" "Requires server to be running paper (or a fork)"
); );
@@ -41,11 +41,19 @@ public class Prerequisite {
"Requires server to have vault" "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. * Requires the server to be running 1.18.
*/ */
public static final Prerequisite HAS_1_18 = new Prerequisite( 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+" "Requires server to be running 1.18+"
); );

View File

@@ -167,7 +167,10 @@ abstract class HandledCommand implements CommandBase {
StringUtil.copyPartialMatches( StringUtil.copyPartialMatches(
args[0], args[0],
this.getSubcommands().stream().map(CommandBase::getName).collect(Collectors.toList()), this.getSubcommands().stream()
.filter(subCommand -> sender.hasPermission(subCommand.getPermission()))
.map(CommandBase::getName)
.collect(Collectors.toList()),
completions completions
); );
@@ -182,6 +185,10 @@ abstract class HandledCommand implements CommandBase {
HandledCommand command = null; HandledCommand command = null;
for (CommandBase subcommand : this.getSubcommands()) { for (CommandBase subcommand : this.getSubcommands()) {
if (!sender.hasPermission(subcommand.getPermission())) {
continue;
}
if (args[0].equalsIgnoreCase(subcommand.getName())) { if (args[0].equalsIgnoreCase(subcommand.getName())) {
command = (HandledCommand) subcommand; command = (HandledCommand) subcommand;
} }

View File

@@ -68,7 +68,7 @@ public interface ProfileHandler {
* @param async If the saving should be done asynchronously. * @param async If the saving should be done asynchronously.
* @deprecated async is now handled automatically depending on implementation. * @deprecated async is now handled automatically depending on implementation.
*/ */
@Deprecated @Deprecated(forRemoval = true)
default void saveAll(boolean async) { default void saveAll(boolean async) {
saveAll(); saveAll();
} }
@@ -77,8 +77,13 @@ public interface ProfileHandler {
* Save all player data. * Save all player data.
* <p> * <p>
* Can run async if using MySQL. * 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. * Commit all changes to the file.

View File

@@ -21,6 +21,15 @@ public interface KeyRegistry {
*/ */
void registerKey(@NotNull PersistentDataKey<?> key); 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. * Get all registered keys.
* *

View File

@@ -38,6 +38,11 @@ public final class PersistentDataKeyType<T> {
*/ */
public static final PersistentDataKeyType<Double> DOUBLE = new PersistentDataKeyType<>(Double.class, "DOUBLE"); 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. * The class of the type.
*/ */
@@ -52,7 +57,10 @@ public final class PersistentDataKeyType<T> {
* Get the class of the type. * Get the class of the type.
* *
* @return The class. * @return The class.
* @deprecated String list type will return null.
*/ */
@Deprecated(since = "6.36.0", forRemoval = true)
@Nullable
public Class<T> getTypeClass() { public Class<T> getTypeClass() {
return typeClass; return typeClass;
} }
@@ -72,7 +80,7 @@ public final class PersistentDataKeyType<T> {
* @param typeClass The type class. * @param typeClass The type class.
* @param name The name. * @param name The name.
*/ */
private PersistentDataKeyType(@NotNull final Class<T> typeClass, private PersistentDataKeyType(@Nullable final Class<T> typeClass,
@NotNull final String name) { @NotNull final String name) {
VALUES.add(this); VALUES.add(this);

View File

@@ -8,6 +8,7 @@ import org.bukkit.Material;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@@ -17,6 +18,15 @@ import java.util.List;
* @param items The items. * @param items The items.
*/ */
public record MaskItems(@NotNull TestableItem... 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. * Create MaskItems from a list of item names.
* *

View File

@@ -28,6 +28,26 @@ public interface Slot {
*/ */
boolean isCaptive(); 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. * Create a builder for an ItemStack.
* *

View File

@@ -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.SlotHandler;
import com.willfp.eco.core.gui.slot.functional.SlotModifier; import com.willfp.eco.core.gui.slot.functional.SlotModifier;
import com.willfp.eco.core.gui.slot.functional.SlotUpdater; import com.willfp.eco.core.gui.slot.functional.SlotUpdater;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Predicate;
/** /**
* Builder to create slots. * Builder to create slots.
@@ -102,6 +104,14 @@ public interface SlotBuilder {
*/ */
SlotBuilder onMiddleClick(@NotNull SlotHandler handler); 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. * Modify the ItemStack.
* *
@@ -130,7 +140,17 @@ public interface SlotBuilder {
* *
* @return The builder. * @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. * Build the slot.

View File

@@ -2,6 +2,7 @@ package com.willfp.eco.core.items;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache; 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.fast.FastItemStack;
import com.willfp.eco.core.items.args.LookupArgParser; import com.willfp.eco.core.items.args.LookupArgParser;
import com.willfp.eco.core.items.provider.ItemProvider; import com.willfp.eco.core.items.provider.ItemProvider;
@@ -185,6 +186,10 @@ public final class Items {
*/ */
@NotNull @NotNull
public static TestableItem lookup(@NotNull final String key) { public static TestableItem lookup(@NotNull final String key) {
if (key.startsWith("{")) {
return Eco.getHandler().getSNBTHandler().createTestable(key);
}
return ITEMS_LOOKUP_HANDLER.parseKey(key); return ITEMS_LOOKUP_HANDLER.parseKey(key);
} }
@@ -222,7 +227,10 @@ public final class Items {
if (part == null && PROVIDERS.containsKey(namespace)) { if (part == null && PROVIDERS.containsKey(namespace)) {
ItemProvider provider = PROVIDERS.get(namespace); ItemProvider provider = PROVIDERS.get(namespace);
item = provider.provideForKey(keyID);
String reformattedKey = keyID.replace("__", ":");
item = provider.provideForKey(reformattedKey);
if (item instanceof EmptyTestableItem || item == null) { if (item instanceof EmptyTestableItem || item == null) {
return new EmptyTestableItem(); return new EmptyTestableItem();
} }
@@ -517,6 +525,28 @@ public final class Items {
return fis.unwrap(); 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() { private Items() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
} }

View File

@@ -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);
}

View File

@@ -20,7 +20,8 @@ public final class ProxyConstants {
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList( public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
"v1_17_R1", "v1_17_R1",
"v1_18_R1", "v1_18_R1",
"v1_18_R2" "v1_18_R2",
"v1_19_R1"
); );
private ProxyConstants() { private ProxyConstants() {

View File

@@ -96,50 +96,53 @@ public final class ShapedCraftingRecipe extends PluginDependent<EcoPlugin> imple
shapedRecipe.setIngredient(character, parts.get(i).getItem().getType()); shapedRecipe.setIngredient(character, parts.get(i).getItem().getType());
} }
ShapedRecipe displayedRecipe = new ShapedRecipe(this.getDisplayedKey(), this.getOutput()); if (Eco.getHandler().getEcoPlugin().getConfigYml().getBool("displayed-recipes")) {
displayedRecipe.shape("012", "345", "678"); ShapedRecipe displayedRecipe = new ShapedRecipe(this.getDisplayedKey(), this.getOutput());
for (int i = 0; i < 9; i++) { displayedRecipe.shape("012", "345", "678");
if (parts.get(i) instanceof EmptyTestableItem) { for (int i = 0; i < 9; i++) {
continue; 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());
} }
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(shapedRecipe);
Bukkit.getServer().addRecipe(displayedRecipe);
} }
/** /**

View File

@@ -101,43 +101,46 @@ public final class ShapelessCraftingRecipe extends PluginDependent<EcoPlugin> im
shapelessRecipe.addIngredient(part.getItem().getType()); shapelessRecipe.addIngredient(part.getItem().getType());
} }
ShapelessRecipe displayedRecipe = new ShapelessRecipe(this.getDisplayedKey(), this.getOutput()); if (Eco.getHandler().getEcoPlugin().getConfigYml().getBool("displayed-recipes")) {
for (TestableItem part : parts) { ShapelessRecipe displayedRecipe = new ShapelessRecipe(this.getDisplayedKey(), this.getOutput());
List<TestableItem> items = new ArrayList<>(); for (TestableItem part : parts) {
if (part instanceof GroupedTestableItems group) { List<TestableItem> items = new ArrayList<>();
items.addAll(group.getChildren()); if (part instanceof GroupedTestableItems group) {
} else { items.addAll(group.getChildren());
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 { } 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(shapelessRecipe);
Bukkit.getServer().addRecipe(displayedRecipe);
} }
/** /**

View File

@@ -20,6 +20,17 @@ public final class MenuUtils {
return new Pair<>(row + 1, column + 1); 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);
}
private MenuUtils() { private MenuUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
} }

View File

@@ -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("<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})}")) .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(); .build();
/** /**

View File

@@ -121,8 +121,8 @@ fun CommandBase.addSubcommand(
} }
/** /**
* Kotlin builder for commands. * Kotlin builder for commands. Inherits plugin, permission, players
* Inherits plugin, permission, players only. * only.
* *
* @param name The command name. * @param name The command name.
* @param init The builder. * @param init The builder.

View File

@@ -4,9 +4,7 @@ package com.willfp.eco.core.config
import com.willfp.eco.core.config.interfaces.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) { class DSLConfig internal constructor(type: ConfigType) : TransientConfig(emptyMap(), type) {
/** /**
* Map a key to a value. * Map a key to a value.

View File

@@ -5,47 +5,33 @@ package com.willfp.eco.core.data
import org.bukkit.persistence.PersistentDataContainer import org.bukkit.persistence.PersistentDataContainer
import org.bukkit.persistence.PersistentDataType 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) = fun <T : Any, Z : Any> PersistentDataContainer.set(key: String, dataType: PersistentDataType<T, Z>, value: Z) =
ExtendedPersistentDataContainer.extend(this).set(key, dataType, value) 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 = fun <T : Any, Z : Any> PersistentDataContainer.has(key: String, dataType: PersistentDataType<T, Z>): Boolean =
ExtendedPersistentDataContainer.extend(this).has(key, dataType) 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? = fun <T : Any, Z : Any> PersistentDataContainer.get(key: String, dataType: PersistentDataType<T, Z>): Z? =
ExtendedPersistentDataContainer.extend(this).get(key, dataType) ExtendedPersistentDataContainer.extend(this).get(key, dataType)
/** /** @see ExtendedPersistentDataContainer.getOrDefault */
* @see ExtendedPersistentDataContainer.getOrDefault
*/
fun <T : Any, Z : Any> PersistentDataContainer.getOrDefault( fun <T : Any, Z : Any> PersistentDataContainer.getOrDefault(
key: String, key: String,
dataType: PersistentDataType<T, Z>, dataType: PersistentDataType<T, Z>,
defaultValue: Z defaultValue: Z
): Z = ExtendedPersistentDataContainer.extend(this).getOrDefault(key, dataType, defaultValue) ): Z = ExtendedPersistentDataContainer.extend(this).getOrDefault(key, dataType, defaultValue)
/** /** @see ExtendedPersistentDataContainer.getAllKeys */
* @see ExtendedPersistentDataContainer.getAllKeys
*/
fun PersistentDataContainer.getAllKeys(): Set<String> = fun PersistentDataContainer.getAllKeys(): Set<String> =
ExtendedPersistentDataContainer.extend(this).allKeys ExtendedPersistentDataContainer.extend(this).allKeys
/** /** @see ExtendedPersistentDataContainer.remove */
* @see ExtendedPersistentDataContainer.remove
*/
fun PersistentDataContainer.remove(key: String) = fun PersistentDataContainer.remove(key: String) =
ExtendedPersistentDataContainer.extend(this).remove(key) 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() = fun newPersistentDataContainer() =
ExtendedPersistentDataContainer.create().base ExtendedPersistentDataContainer.create().base

View File

@@ -5,14 +5,10 @@ package com.willfp.eco.core.data
import org.bukkit.OfflinePlayer import org.bukkit.OfflinePlayer
import org.bukkit.Server import org.bukkit.Server
/** /** @see PlayerProfile.load */
* @see PlayerProfile.load
*/
val OfflinePlayer.profile: PlayerProfile val OfflinePlayer.profile: PlayerProfile
get() = PlayerProfile.load(this) get() = PlayerProfile.load(this)
/** /** @see ServerProfile.load */
* @see ServerProfile.load
*/
val Server.profile: ServerProfile val Server.profile: ServerProfile
get() = ServerProfile.load() get() = ServerProfile.load()

View File

@@ -5,8 +5,6 @@ package com.willfp.eco.core.entities
import com.willfp.eco.core.entities.ai.EntityController import com.willfp.eco.core.entities.ai.EntityController
import org.bukkit.entity.Mob import org.bukkit.entity.Mob
/** /** @see EntityController.getFor */
* @see EntityController.getFor
*/
val <T : Mob> T.controller: EntityController<T> val <T : Mob> T.controller: EntityController<T>
get() = EntityController.getFor(this) get() = EntityController.getFor(this)

View File

@@ -4,8 +4,6 @@ package com.willfp.eco.core.fast
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
/** /** @see FastItemStack.wrap */
* @see FastItemStack.wrap
*/
fun ItemStack.fast(): FastItemStack = fun ItemStack.fast(): FastItemStack =
FastItemStack.wrap(this) FastItemStack.wrap(this)

View File

@@ -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.menu.MenuBuilder
import com.willfp.eco.core.gui.slot.Slot import com.willfp.eco.core.gui.slot.Slot
import com.willfp.eco.core.gui.slot.SlotBuilder import com.willfp.eco.core.gui.slot.SlotBuilder
import com.willfp.eco.core.items.TestableItem
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.InventoryCloseEvent import org.bukkit.event.inventory.InventoryCloseEvent
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
/** /** @see SlotBuilder.onLeftClick */
* @see SlotBuilder.onLeftClick
*/
fun SlotBuilder.onLeftClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = fun SlotBuilder.onLeftClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
this.onLeftClick { a, b, c -> action(a, b, c) } this.onLeftClick { a, b, c -> action(a, b, c) }
/** /** @see SlotBuilder.onRightClick */
* @see SlotBuilder.onRightClick
*/
fun SlotBuilder.onRightClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = fun SlotBuilder.onRightClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
this.onRightClick { a, b, c -> action(a, b, c) } this.onRightClick { a, b, c -> action(a, b, c) }
/** /** @see SlotBuilder.onShiftLeftClick */
* @see SlotBuilder.onShiftLeftClick
*/
fun SlotBuilder.onShiftLeftClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = fun SlotBuilder.onShiftLeftClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
this.onShiftLeftClick { a, b, c -> action(a, b, c) } this.onShiftLeftClick { a, b, c -> action(a, b, c) }
/** /** @see SlotBuilder.onShiftRightClick */
* @see SlotBuilder.onShiftRightClick
*/
fun SlotBuilder.onShiftRightClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = fun SlotBuilder.onShiftRightClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
this.onShiftRightClick { a, b, c -> action(a, b, c) } this.onShiftRightClick { a, b, c -> action(a, b, c) }
/** /** @see SlotBuilder.onShiftRightClick */
* @see SlotBuilder.onShiftRightClick
*/
fun SlotBuilder.onMiddleClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = fun SlotBuilder.onMiddleClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
this.onMiddleClick { a, b, c -> action(a, b, c) } 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 * @see SlotBuilder.setModifier
* @deprecated Use SlotUpdater instead. * @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 = fun SlotBuilder.setModifier(action: (Player, Menu, ItemStack) -> Unit): SlotBuilder =
this.setUpdater { a, b, c -> c.apply { action(a, b, c) } } 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 = fun SlotBuilder.setUpdater(action: (Player, Menu, ItemStack) -> ItemStack): SlotBuilder =
this.setUpdater { a, b, c -> action(a, b, c) } 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( fun slot(
item: ItemStack, item: ItemStack,
init: SlotBuilder.() -> Unit init: SlotBuilder.() -> Unit
@@ -68,9 +80,17 @@ fun slot(
return builder.build() 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( fun slot(
provider: (Player, Menu) -> ItemStack, provider: (Player, Menu) -> ItemStack,
init: SlotBuilder.() -> Unit init: SlotBuilder.() -> Unit
@@ -80,27 +100,24 @@ fun slot(
return builder.build() return builder.build()
} }
/** /** Kotlin builder for slots. */
* @see MenuBuilder.onClose 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 = fun MenuBuilder.onClose(action: (InventoryCloseEvent, Menu) -> Unit): MenuBuilder =
this.onClose { a, b -> action(a, b) } this.onClose { a, b -> action(a, b) }
/** /** @see MenuBuilder.modify */
* @see MenuBuilder.modify
*/
fun MenuBuilder.modify(modifier: (MenuBuilder) -> Unit): MenuBuilder = fun MenuBuilder.modify(modifier: (MenuBuilder) -> Unit): MenuBuilder =
this.modfiy { modifier(it) } this.modfiy { modifier(it) }
/** /** @see MenuBuilder.onRender */
* @see MenuBuilder.onRender
*/
fun MenuBuilder.onRender(action: (Player, Menu) -> Unit): MenuBuilder = fun MenuBuilder.onRender(action: (Player, Menu) -> Unit): MenuBuilder =
this.onRender { a, b -> action(a, b) } this.onRender { a, b -> action(a, b) }
/** /** Kotlin builder for menus. */
* Kotlin builder for menus.
*/
fun menu( fun menu(
rows: Int, rows: Int,
init: MenuBuilder.() -> Unit init: MenuBuilder.() -> Unit

View File

@@ -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)
}
}

View File

@@ -6,21 +6,15 @@ import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.ItemMeta import org.bukkit.inventory.meta.ItemMeta
import org.bukkit.persistence.PersistentDataContainer import org.bukkit.persistence.PersistentDataContainer
/** /** @see Items.toLookupString */
* @see Items.toLookupString
*/
fun ItemStack?.toLookupString(): String = fun ItemStack?.toLookupString(): String =
Items.toLookupString(this) Items.toLookupString(this)
/** /** @see Items.mergeFrom */
* @see Items.mergeFrom
*/
fun ItemStack.mergeFrom(other: ItemStack): ItemStack = fun ItemStack.mergeFrom(other: ItemStack): ItemStack =
Items.mergeFrom(other, this) Items.mergeFrom(other, this)
/** /** @see Items.mergeFrom */
* @see Items.mergeFrom
*/
fun ItemMeta.mergeFrom(other: ItemMeta): ItemMeta = fun ItemMeta.mergeFrom(other: ItemMeta): ItemMeta =
Items.mergeFrom(other, this) Items.mergeFrom(other, this)
@@ -34,8 +28,6 @@ var ItemStack.baseNBT: PersistentDataContainer
Items.setBaseNBT(this, value) Items.setBaseNBT(this, value)
} }
/** /** @see Items.setBaseNBT */
* @see Items.setBaseNBT
*/
fun ItemStack.clearNBT() = fun ItemStack.clearNBT() =
Items.setBaseNBT(this, null) Items.setBaseNBT(this, null)

View File

@@ -5,8 +5,6 @@ package com.willfp.eco.util
import org.bukkit.entity.Arrow import org.bukkit.entity.Arrow
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
/** /** @see ArrowUtils.getBow */
* @see ArrowUtils.getBow
*/
val Arrow.bow: ItemStack? val Arrow.bow: ItemStack?
get() = ArrowUtils.getBow(this) get() = ArrowUtils.getBow(this)

View File

@@ -4,8 +4,6 @@ package com.willfp.eco.util
import org.bukkit.block.Block import org.bukkit.block.Block
/** /** @see ArrowUtils.getBow */
* @see ArrowUtils.getBow
*/
val Block.isPlayerPlaced: Boolean val Block.isPlayerPlaced: Boolean
get() = BlockUtils.isPlayerPlaced(this) get() = BlockUtils.isPlayerPlaced(this)

View File

@@ -5,14 +5,10 @@ package com.willfp.eco.util
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
/** /** @see DurabilityUtils.damageItem */
* @see DurabilityUtils.damageItem
*/
fun ItemStack.damage(damage: Int) = fun ItemStack.damage(damage: Int) =
DurabilityUtils.damageItem(this, damage) DurabilityUtils.damageItem(this, damage)
/** /** @see DurabilityUtils.damageItem */
* @see DurabilityUtils.damageItem
*/
fun ItemStack.damage(damage: Int, player: Player) = fun ItemStack.damage(damage: Int, player: Player) =
DurabilityUtils.damageItem(player, this, damage) DurabilityUtils.damageItem(player, this, damage)

View File

@@ -2,20 +2,18 @@
package com.willfp.eco.util package com.willfp.eco.util
/** /** @see ListUtils.listToFrequencyMap */
* @see ListUtils.listToFrequencyMap
*/
fun <T> List<T>.toFrequencyMap(): Map<T, Int> = fun <T> List<T>.toFrequencyMap(): Map<T, Int> =
ListUtils.listToFrequencyMap(this) ListUtils.listToFrequencyMap(this)
/** /** @see ListUtils.containsIgnoreCase */
* @see ListUtils.containsIgnoreCase
*/
fun Iterable<String>.containsIgnoreCase(element: String): Boolean = fun Iterable<String>.containsIgnoreCase(element: String): Boolean =
ListUtils.containsIgnoreCase(this, element) ListUtils.containsIgnoreCase(this, element)
/** /** @see ListUtils.create2DList */
* @see ListUtils.create2DList
*/
fun <T> create2DList(rows: Int, columns: Int): MutableList<MutableList<T>> = fun <T> create2DList(rows: Int, columns: Int): MutableList<MutableList<T>> =
ListUtils.create2DList(rows, columns) ListUtils.create2DList(rows, columns)
/** @see ListUtils.toSingletonList */
fun <T> T.toSingletonList(): List<T> =
ListUtils.toSingletonList(this)

View File

@@ -4,26 +4,18 @@ package com.willfp.eco.util
import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.EcoPlugin
/** /** @see NamespacedKeyUtils.fromString */
* @see NamespacedKeyUtils.fromString
*/
fun namespacedKeyOf(string: String) = fun namespacedKeyOf(string: String) =
NamespacedKeyUtils.fromString(string) NamespacedKeyUtils.fromString(string)
/** /** @see NamespacedKeyUtils.fromString */
* @see NamespacedKeyUtils.fromString
*/
fun safeNamespacedKeyOf(string: String) = fun safeNamespacedKeyOf(string: String) =
NamespacedKeyUtils.fromStringOrNull(string) NamespacedKeyUtils.fromStringOrNull(string)
/** /** @see NamespacedKeyUtils.create */
* @see NamespacedKeyUtils.create
*/
fun namespacedKeyOf(namespace: String, key: String) = fun namespacedKeyOf(namespace: String, key: String) =
NamespacedKeyUtils.create(namespace, key) NamespacedKeyUtils.create(namespace, key)
/** /** @see EcoPlugin.namespacedKeyFactory */
* @see EcoPlugin.namespacedKeyFactory
*/
fun namespacedKeyOf(plugin: EcoPlugin, key: String) = fun namespacedKeyOf(plugin: EcoPlugin, key: String) =
plugin.namespacedKeyFactory.create(key) plugin.namespacedKeyFactory.create(key)

View File

@@ -2,8 +2,6 @@
package com.willfp.eco.util package com.willfp.eco.util
/** /** @see NumberUtils.toNumeral */
* @see NumberUtils.toNumeral
*/
fun Number.toNumeral(): String = fun Number.toNumeral(): String =
NumberUtils.toNumeral(this.toInt()) NumberUtils.toNumeral(this.toInt())

View File

@@ -8,32 +8,22 @@ import org.bukkit.command.CommandSender
import org.bukkit.entity.Entity import org.bukkit.entity.Entity
import org.bukkit.entity.Player import org.bukkit.entity.Player
/** /** @see PlayerUtils.getSavedDisplayName */
* @see PlayerUtils.getSavedDisplayName
*/
val OfflinePlayer.savedDisplayName: String val OfflinePlayer.savedDisplayName: String
get() = PlayerUtils.getSavedDisplayName(this) get() = PlayerUtils.getSavedDisplayName(this)
/** /** @see PlayerUtils.getAudience */
* @see PlayerUtils.getAudience
*/
fun Player.asAudience(): Audience = fun Player.asAudience(): Audience =
PlayerUtils.getAudience(this) PlayerUtils.getAudience(this)
/** /** @see PlayerUtils.getAudience */
* @see PlayerUtils.getAudience
*/
fun CommandSender.asAudience(): Audience = fun CommandSender.asAudience(): Audience =
PlayerUtils.getAudience(this) PlayerUtils.getAudience(this)
/** /** @see PlayerUtils.runExempted */
* @see PlayerUtils.runExempted
*/
fun Player.runExempted(action: () -> Unit) = fun Player.runExempted(action: () -> Unit) =
PlayerUtils.runExempted(this, action) PlayerUtils.runExempted(this, action)
/** /** @see PlayerUtils.tryAsPlayer */
* @see PlayerUtils.tryAsPlayer
*/
fun Entity?.tryAsPlayer(): Player? = fun Entity?.tryAsPlayer(): Player? =
PlayerUtils.tryAsPlayer(this) PlayerUtils.tryAsPlayer(this)

View File

@@ -4,8 +4,6 @@ package com.willfp.eco.util
import org.bukkit.potion.PotionData import org.bukkit.potion.PotionData
/** /** @see PotionData.duration */
* @see PotionData.duration
*/
val PotionData.duration: Int val PotionData.duration: Int
get() = PotionUtils.getDuration(this) get() = PotionUtils.getDuration(this)

View File

@@ -4,8 +4,6 @@ package com.willfp.eco.util
import org.bukkit.Server import org.bukkit.Server
/** /** @see ServerUtils.getTps */
* @see ServerUtils.getTps
*/
val Server.tps: Double val Server.tps: Double
get() = ServerUtils.getTps() get() = ServerUtils.getTps()

View File

@@ -5,33 +5,23 @@ package com.willfp.eco.util
import net.kyori.adventure.text.Component import net.kyori.adventure.text.Component
import org.bukkit.entity.Player import org.bukkit.entity.Player
/** /** @see StringUtils.toComponent */
* @see StringUtils.toComponent
*/
fun String.toComponent(): Component = fun String.toComponent(): Component =
StringUtils.toComponent(this) StringUtils.toComponent(this)
/** /** @see StringUtils.jsonToComponent */
* @see StringUtils.jsonToComponent
*/
fun String.jsonToComponent(): Component = fun String.jsonToComponent(): Component =
StringUtils.jsonToComponent(this) StringUtils.jsonToComponent(this)
/** /** @see StringUtils.toLegacy */
* @see StringUtils.toLegacy
*/
fun Component.toLegacy(): String = fun Component.toLegacy(): String =
StringUtils.toLegacy(this) StringUtils.toLegacy(this)
/** /** @see StringUtils.componentToJson */
* @see StringUtils.componentToJson
*/
fun Component.toJSON(): String = fun Component.toJSON(): String =
StringUtils.componentToJson(this) StringUtils.componentToJson(this)
/** /** @see StringUtils.format */
* @see StringUtils.format
*/
fun String.formatEco( fun String.formatEco(
player: Player? = null, player: Player? = null,
formatPlaceholders: Boolean = false formatPlaceholders: Boolean = false
@@ -41,9 +31,7 @@ fun String.formatEco(
if (formatPlaceholders) StringUtils.FormatOption.WITH_PLACEHOLDERS else StringUtils.FormatOption.WITHOUT_PLACEHOLDERS if (formatPlaceholders) StringUtils.FormatOption.WITH_PLACEHOLDERS else StringUtils.FormatOption.WITHOUT_PLACEHOLDERS
) )
/** /** @see StringUtils.formatList */
* @see StringUtils.formatList
*/
fun List<String>.formatEco( fun List<String>.formatEco(
player: Player? = null, player: Player? = null,
formatPlaceholders: Boolean = false formatPlaceholders: Boolean = false
@@ -53,14 +41,10 @@ fun List<String>.formatEco(
if (formatPlaceholders) StringUtils.FormatOption.WITH_PLACEHOLDERS else StringUtils.FormatOption.WITHOUT_PLACEHOLDERS if (formatPlaceholders) StringUtils.FormatOption.WITH_PLACEHOLDERS else StringUtils.FormatOption.WITHOUT_PLACEHOLDERS
) )
/** /** @see StringUtils.splitAround */
* @see StringUtils.splitAround
*/
fun String.splitAround(separator: String): Array<String> = fun String.splitAround(separator: String): Array<String> =
StringUtils.splitAround(this, separator) StringUtils.splitAround(this, separator)
/** /** @see StringUtils.toNiceString */
* @see StringUtils.toNiceString
*/
fun Any?.toNiceString(): String = fun Any?.toNiceString(): String =
StringUtils.toNiceString(this) StringUtils.toNiceString(this)

View File

@@ -4,14 +4,10 @@ package com.willfp.eco.util
import org.bukkit.util.Vector import org.bukkit.util.Vector
/** /** @see VectorUtils.isFinite */
* @see VectorUtils.isFinite
*/
val Vector.isFinite: Boolean val Vector.isFinite: Boolean
get() = VectorUtils.isFinite(this) get() = VectorUtils.isFinite(this)
/** /** @see VectorUtils.simplifyVector */
* @see VectorUtils.simplifyVector
*/
fun Vector.simplify(): Vector = fun Vector.simplify(): Vector =
VectorUtils.simplifyVector(this) VectorUtils.simplifyVector(this)

View File

@@ -16,7 +16,7 @@ fun ConfigType.toMap(input: String?): Map<String, Any?> =
fun ConfigType.toString(map: Map<String, Any?>): String = fun ConfigType.toString(map: Map<String, Any?>): String =
this.handler.toString(map) 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 Map<*, *> -> EcoConfigSection(type, this.normalizeToConfig(type))
is Iterable<*> -> { is Iterable<*> -> {
if (this.firstOrNull() == null) { if (this.firstOrNull() == null) {
@@ -31,7 +31,7 @@ fun Any?.constrainConfigTypes(type: ConfigType): Any? = when (this) {
else -> 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?>() val building = mutableMapOf<String, Any?>()
for ((unprocessedKey, value) in this.entries) { for ((unprocessedKey, value) in this.entries) {

View File

@@ -3,6 +3,7 @@ package com.willfp.eco.internal.config
import com.willfp.eco.core.config.ConfigType import com.willfp.eco.core.config.ConfigType
import com.willfp.eco.core.config.interfaces.Config import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.placeholder.InjectablePlaceholder import com.willfp.eco.core.placeholder.InjectablePlaceholder
import com.willfp.eco.core.placeholder.StaticPlaceholder
import com.willfp.eco.util.StringUtils import com.willfp.eco.util.StringUtils
import org.bukkit.configuration.file.YamlConfiguration import org.bukkit.configuration.file.YamlConfiguration
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
@@ -103,11 +104,13 @@ open class EcoConfig(
} }
override fun getSubsectionOrNull(path: String): Config? { 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>? { 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 { override fun getType(): ConfigType {
@@ -135,7 +138,14 @@ open class EcoConfig(
format: Boolean, format: Boolean,
option: StringUtils.FormatOption option: StringUtils.FormatOption
): String? { ): 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 return if (format) StringUtils.format(string, option) else string
} }
@@ -144,7 +154,18 @@ open class EcoConfig(
format: Boolean, format: Boolean,
option: StringUtils.FormatOption option: StringUtils.FormatOption
): List<String>? { ): 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 return if (format) StringUtils.formatList(strings, option) else strings
} }

View File

@@ -49,11 +49,13 @@ class EcoMenu(
player.openInventory(inventory) player.openInventory(inventory)
MenuHandler.registerInventory(inventory, this, player) MenuHandler.registerInventory(inventory, this, player)
inventory.asRenderedInventory()?.generateCaptive()
return inventory return inventory
} }
fun handleClose(event: InventoryCloseEvent) { fun handleClose(event: InventoryCloseEvent) {
onClose.handle(event, this) onClose.handle(event, this)
event.inventory.asRenderedInventory()?.generateCaptive()
MenuHandler.unregisterInventory(event.inventory) MenuHandler.unregisterInventory(event.inventory)
} }

View File

@@ -34,7 +34,7 @@ class MenuRenderedInventory(
menu.runOnRender(player) menu.runOnRender(player)
} }
private fun generateCaptive() { fun generateCaptive() {
captiveItems.clear() captiveItems.clear()
for (i in 0 until inventory.size) { for (i in 0 until inventory.size) {
val (row, column) = MenuUtils.convertSlotToRowColumn(i) val (row, column) = MenuUtils.convertSlotToRowColumn(i)
@@ -43,7 +43,17 @@ class MenuRenderedInventory(
val renderedItem = slot.getItemStack(player) val renderedItem = slot.getItemStack(player)
val itemStack = inventory.getItem(i) ?: continue 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 continue
} }

View File

@@ -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.SlotHandler
import com.willfp.eco.core.gui.slot.functional.SlotProvider import com.willfp.eco.core.gui.slot.functional.SlotProvider
import org.bukkit.entity.Player
class EcoCaptiveSlot( class EcoCaptiveSlot(
provider: SlotProvider provider: SlotProvider,
private val captiveFromEmpty: Boolean,
private val notCaptiveFor: (Player) -> Boolean
) : EcoSlot( ) : EcoSlot(
provider, provider,
allowMovingItem, captiveWithTest(notCaptiveFor),
allowMovingItem, captiveWithTest(notCaptiveFor),
allowMovingItem, captiveWithTest(notCaptiveFor),
allowMovingItem, captiveWithTest(notCaptiveFor),
allowMovingItem, captiveWithTest(notCaptiveFor),
{ _, _, prev -> prev } { _, _, prev -> prev }
) { ) {
override fun isCaptive(): Boolean { override fun isCaptive(): Boolean {
return true return true
} }
override fun isCaptiveFromEmpty(): Boolean {
return captiveFromEmpty
}
override fun isNotCaptiveFor(player: Player): Boolean {
return notCaptiveFor(player)
}
} }
private val allowMovingItem = SlotHandler { event, _, _ -> private fun captiveWithTest(test: (Player) -> Boolean): SlotHandler {
event.isCancelled = false return SlotHandler { event, _, _ ->
} event.isCancelled = test(event.whoClicked as Player)
}
}

View File

@@ -1,25 +1,39 @@
package com.willfp.eco.internal.gui.slot 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.Slot
import com.willfp.eco.core.gui.slot.SlotBuilder 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.SlotHandler
import com.willfp.eco.core.gui.slot.functional.SlotProvider import com.willfp.eco.core.gui.slot.functional.SlotProvider
import com.willfp.eco.core.gui.slot.functional.SlotUpdater 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 { class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
private var captive = false private var captive = false
private var captiveFromEmpty = false
private var updater: SlotUpdater = SlotUpdater { player, menu, _ -> provider.provide(player, menu) } private var updater: SlotUpdater = SlotUpdater { player, menu, _ -> provider.provide(player, menu) }
private var onLeftClick = private var onLeftClick: SlotHandler = NoOpSlot
SlotHandler { _, _, _ -> run { } } private var onRightClick: SlotHandler = NoOpSlot
private var onRightClick = private var onShiftLeftClick: SlotHandler = NoOpSlot
SlotHandler { _, _, _ -> run { } } private var onShiftRightClick: SlotHandler = NoOpSlot
private var onShiftLeftClick = private var onMiddleClick: SlotHandler = NoOpSlot
SlotHandler { _, _, _ -> run { } }
private var onShiftRightClick = private var notCaptiveFor: (Player) -> Boolean = { false }
SlotHandler { _, _, _ -> run { } }
private var onMiddleClick =
SlotHandler { _, _, _ -> run { } }
override fun onLeftClick(action: SlotHandler): SlotBuilder { override fun onLeftClick(action: SlotHandler): SlotBuilder {
onLeftClick = action onLeftClick = action
@@ -46,8 +60,14 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
return this 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 captive = true
captiveFromEmpty = fromEmpty
return this return this
} }
@@ -58,9 +78,21 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
override fun build(): Slot { override fun build(): Slot {
return if (captive) { return if (captive) {
EcoCaptiveSlot(provider) EcoCaptiveSlot(
provider,
captiveFromEmpty,
notCaptiveFor
)
} else { } else {
EcoSlot(provider, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick, updater) EcoSlot(
provider,
onLeftClick,
onRightClick,
onShiftLeftClick,
onShiftRightClick,
onMiddleClick,
updater
)
} }
} }
} }

View File

@@ -1,5 +1,5 @@
plugins { plugins {
id("io.papermc.paperweight.userdev") version "1.3.5" id("io.papermc.paperweight.userdev") version "1.3.6"
} }
group = "com.willfp" group = "com.willfp"

View File

@@ -26,6 +26,8 @@ import org.bukkit.inventory.ItemFlag
import org.bukkit.persistence.PersistentDataContainer import org.bukkit.persistence.PersistentDataContainer
import org.bukkit.persistence.PersistentDataType import org.bukkit.persistence.PersistentDataType
import kotlin.experimental.and import kotlin.experimental.and
import kotlin.experimental.inv
import kotlin.experimental.or
@Suppress("UsePropertyAccessSyntax") @Suppress("UsePropertyAccessSyntax")
class EcoFastItemStack( class EcoFastItemStack(
@@ -149,35 +151,29 @@ class EcoFastItemStack(
override fun getDisplayName(): String = displayNameComponent.toLegacy() override fun getDisplayName(): String = displayNameComponent.toLegacy()
override fun addItemFlags(vararg hideFlags: ItemFlag) { override fun addItemFlags(vararg hideFlags: ItemFlag) {
for (flag in hideFlags) { for (f in hideFlags) {
this.flagBits = this.flagBits or getBitModifier(flag) this.flagBits = this.flagBits or getBitModifier(f)
} }
apply() apply()
} }
override fun removeItemFlags(vararg hideFlags: ItemFlag) { override fun removeItemFlags(vararg hideFlags: ItemFlag) {
for (flag in hideFlags) { for (f in hideFlags) {
this.flagBits = this.flagBits and getBitModifier(flag) this.flagBits = this.flagBits and getBitModifier(f).inv()
} }
apply() apply()
} }
override fun getItemFlags(): MutableSet<ItemFlag> { override fun getItemFlags(): Set<ItemFlag> {
val flags = mutableSetOf<ItemFlag>() val currentFlags = mutableSetOf<ItemFlag>()
for (f in ItemFlag.values()) {
var flagArr: Array<ItemFlag> if (hasItemFlag(f)) {
val size = ItemFlag.values().also { flagArr = it }.size currentFlags.add(f)
for (i in 0 until size) {
val flag = flagArr[i]
if (this.hasItemFlag(flag)) {
flags.add(flag)
} }
} }
return currentFlags
return flags
} }
override fun hasItemFlag(flag: ItemFlag): Boolean { override fun hasItemFlag(flag: ItemFlag): Boolean {
@@ -194,15 +190,15 @@ class EcoFastItemStack(
} }
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION") @Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
private var flagBits: Int private var flagBits: Byte
get() = get() =
if (handle.hasTag() && handle.getTag()!!.contains( if (handle.hasTag() && handle.getTag()!!.contains(
"HideFlags", "HideFlags",
99 99
) )
) handle.getTag()!!.getInt("HideFlags") else 0 ) handle.getTag()!!.getInt("HideFlags").toByte() else 0
set(value) = set(value) =
handle.getOrCreateTag().putInt("HideFlags", value) handle.getOrCreateTag().putInt("HideFlags", value.toInt())
override fun getRepairCost(): Int { override fun getRepairCost(): Int {
return handle.getBaseRepairCost() return handle.getBaseRepairCost()
@@ -268,8 +264,8 @@ class EcoFastItemStack(
bukkit.mergeIfNeeded(handle) bukkit.mergeIfNeeded(handle)
} }
private fun getBitModifier(hideFlag: ItemFlag): Int { private fun getBitModifier(hideFlag: ItemFlag): Byte {
return 1 shl hideFlag.ordinal return (1 shl hideFlag.ordinal).toByte()
} }
override fun unwrap(): org.bukkit.inventory.ItemStack { override fun unwrap(): org.bukkit.inventory.ItemStack {

View File

@@ -1,5 +1,5 @@
plugins { plugins {
id("io.papermc.paperweight.userdev") version "1.3.5" id("io.papermc.paperweight.userdev") version "1.3.6"
} }
group = "com.willfp" group = "com.willfp"

View File

@@ -0,0 +1,54 @@
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(nbt)
}
class SNBTTestableItem(
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 {
return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.of(tag))
}
}
}

View File

@@ -20,6 +20,10 @@ class Skull : SkullProxy {
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java) setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
setProfile.isAccessible = true setProfile.isAccessible = true
} }
if (base64.length < 20) {
return
}
val uuid = UUID( val uuid = UUID(
base64.substring(base64.length - 20).hashCode().toLong(), base64.substring(base64.length - 20).hashCode().toLong(),
base64.substring(base64.length - 10).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 profile = profile[meta] as GameProfile? ?: return null
val properties = profile.properties ?: return null val properties = profile.properties ?: return null
val prop = properties["textures"] ?: return null val prop = properties["textures"] ?: return null
return prop.toMutableList().firstOrNull()?.value return prop.toMutableList().firstOrNull()?.name
} }
} }

View File

@@ -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.core.display.Display
import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy 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 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.craftbukkit.v1_17_R1.inventory.CraftMerchantRecipe
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.inventory.MerchantRecipe import org.bukkit.inventory.MerchantRecipe
@@ -15,20 +18,17 @@ class VillagerTrade : VillagerTradeProxy {
recipe: MerchantRecipe, recipe: MerchantRecipe,
player: Player player: Player
): MerchantRecipe { ): MerchantRecipe {
val oldRecipe = recipe as CraftMerchantRecipe recipe as CraftMerchantRecipe
val newRecipe = CraftMerchantRecipe(
Display.display(recipe.getResult().clone(), player), val nbt = getHandle(recipe).createTag()
recipe.getUses(), for (tag in arrayOf("buy", "buyB", "sell")) {
recipe.getMaxUses(), val nms = ItemStack.of(nbt.getCompound(tag))
recipe.hasExperienceReward(), val displayed = Display.display(CraftItemStack.asBukkitCopy(nms), player)
recipe.getVillagerExperience(), val itemNBT = CraftItemStack.asNMSCopy(displayed).save(CompoundTag())
recipe.getPriceMultiplier() nbt.put(tag, itemNBT)
)
for (ingredient in recipe.getIngredients()) {
newRecipe.addIngredient(Display.display(ingredient.clone(), player))
} }
getHandle(newRecipe).specialPriceDiff = getHandle(oldRecipe).specialPriceDiff
return newRecipe return CraftMerchantRecipe(MerchantOffer(nbt))
} }
private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer { private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer {

View File

@@ -1,5 +1,5 @@
plugins { plugins {
id("io.papermc.paperweight.userdev") version "1.3.5" id("io.papermc.paperweight.userdev") version "1.3.6"
} }
group = "com.willfp" group = "com.willfp"

View File

@@ -0,0 +1,54 @@
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(nbt)
}
class SNBTTestableItem(
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 {
return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.of(tag))
}
}
}

View File

@@ -20,6 +20,10 @@ class Skull : SkullProxy {
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java) setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
setProfile.isAccessible = true setProfile.isAccessible = true
} }
if (base64.length < 20) {
return
}
val uuid = UUID( val uuid = UUID(
base64.substring(base64.length - 20).hashCode().toLong(), base64.substring(base64.length - 20).hashCode().toLong(),
base64.substring(base64.length - 10).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 profile = profile[meta] as GameProfile? ?: return null
val properties = profile.properties ?: return null val properties = profile.properties ?: return null
val prop = properties["textures"] ?: return null val prop = properties["textures"] ?: return null
return prop.toMutableList().firstOrNull()?.value return prop.toMutableList().firstOrNull()?.name
} }
} }

View File

@@ -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.core.display.Display
import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy 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 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.craftbukkit.v1_18_R1.inventory.CraftMerchantRecipe
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.inventory.MerchantRecipe import org.bukkit.inventory.MerchantRecipe
@@ -15,20 +18,17 @@ class VillagerTrade : VillagerTradeProxy {
recipe: MerchantRecipe, recipe: MerchantRecipe,
player: Player player: Player
): MerchantRecipe { ): MerchantRecipe {
val oldRecipe = recipe as CraftMerchantRecipe recipe as CraftMerchantRecipe
val newRecipe = CraftMerchantRecipe(
Display.display(recipe.getResult().clone(), player), val nbt = getHandle(recipe).createTag()
recipe.getUses(), for (tag in arrayOf("buy", "buyB", "sell")) {
recipe.getMaxUses(), val nms = ItemStack.of(nbt.getCompound(tag))
recipe.hasExperienceReward(), val displayed = Display.display(CraftItemStack.asBukkitCopy(nms), player)
recipe.getVillagerExperience(), val itemNBT = CraftItemStack.asNMSCopy(displayed).save(CompoundTag())
recipe.getPriceMultiplier() nbt.put(tag, itemNBT)
)
for (ingredient in recipe.getIngredients()) {
newRecipe.addIngredient(Display.display(ingredient.clone(), player))
} }
getHandle(newRecipe).setSpecialPriceDiff(getHandle(oldRecipe).getSpecialPriceDiff())
return newRecipe return CraftMerchantRecipe(MerchantOffer(nbt))
} }
private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer { private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer {

View File

@@ -1,5 +1,5 @@
plugins { plugins {
id("io.papermc.paperweight.userdev") version "1.3.5" id("io.papermc.paperweight.userdev") version "1.3.6"
} }
group = "com.willfp" group = "com.willfp"

View File

@@ -0,0 +1,54 @@
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(nbt)
}
class SNBTTestableItem(
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 {
return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.of(tag))
}
}
}

View File

@@ -20,6 +20,10 @@ class Skull : SkullProxy {
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java) setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
setProfile.isAccessible = true setProfile.isAccessible = true
} }
if (base64.length < 20) {
return
}
val uuid = UUID( val uuid = UUID(
base64.substring(base64.length - 20).hashCode().toLong(), base64.substring(base64.length - 20).hashCode().toLong(),
base64.substring(base64.length - 10).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 profile = profile[meta] as GameProfile? ?: return null
val properties = profile.properties ?: return null val properties = profile.properties ?: return null
val prop = properties["textures"] ?: return null val prop = properties["textures"] ?: return null
return prop.toMutableList().firstOrNull()?.value return prop.toMutableList().firstOrNull()?.name
} }
} }

View File

@@ -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.core.display.Display
import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy 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 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.craftbukkit.v1_18_R2.inventory.CraftMerchantRecipe
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.inventory.MerchantRecipe import org.bukkit.inventory.MerchantRecipe
@@ -15,20 +18,17 @@ class VillagerTrade : VillagerTradeProxy {
recipe: MerchantRecipe, recipe: MerchantRecipe,
player: Player player: Player
): MerchantRecipe { ): MerchantRecipe {
val oldRecipe = recipe as CraftMerchantRecipe recipe as CraftMerchantRecipe
val newRecipe = CraftMerchantRecipe(
Display.display(recipe.getResult().clone(), player), val nbt = getHandle(recipe).createTag()
recipe.getUses(), for (tag in arrayOf("buy", "buyB", "sell")) {
recipe.getMaxUses(), val nms = ItemStack.of(nbt.getCompound(tag))
recipe.hasExperienceReward(), val displayed = Display.display(CraftItemStack.asBukkitCopy(nms), player)
recipe.getVillagerExperience(), val itemNBT = CraftItemStack.asNMSCopy(displayed).save(CompoundTag())
recipe.getPriceMultiplier() nbt.put(tag, itemNBT)
)
for (ingredient in recipe.getIngredients()) {
newRecipe.addIngredient(Display.display(ingredient.clone(), player))
} }
getHandle(newRecipe).setSpecialPriceDiff(getHandle(oldRecipe).getSpecialPriceDiff())
return newRecipe return CraftMerchantRecipe(MerchantOffer(nbt))
} }
private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer { private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer {

View 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"
)
}
}

View File

@@ -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")
}
}

View File

@@ -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)
}
}

View File

@@ -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")
}
}
}
}
}

View File

@@ -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())
}
}

View File

@@ -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)
}
}

View File

@@ -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
}
}
}

View File

@@ -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)
}
}

View File

@@ -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
}
}

View File

@@ -0,0 +1,54 @@
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(nbt)
}
class SNBTTestableItem(
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 {
return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.of(tag))
}
}
}

View File

@@ -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
}
}

View File

@@ -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]
}
}

View File

@@ -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
}
}

View File

@@ -14,10 +14,12 @@ dependencies {
implementation 'com.zaxxer:HikariCP:5.0.0' implementation 'com.zaxxer:HikariCP:5.0.0'
implementation 'net.kyori:adventure-platform-bukkit:4.1.0' implementation 'net.kyori:adventure-platform-bukkit:4.1.0'
implementation 'org.javassist:javassist:3.28.0-GA' 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 // Included in spigot jar
compileOnly 'com.google.code.gson:gson:2.8.8' compileOnly 'com.google.code.gson:gson:2.8.8'
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT' compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT'
// Plugin dependencies // Plugin dependencies
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.1-SNAPSHOT' compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.1-SNAPSHOT'
@@ -63,6 +65,13 @@ dependencies {
compileOnly fileTree(dir: '../../lib', include: ['*.jar']) compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
} }
shadowJar {
minimize {
exclude(dependency('org.litote.kmongo:kmongo-coroutine:.*'))
exclude(dependency('org.jetbrains.exposed:.*:.*'))
}
}
processResources { processResources {
filesNotMatching(["**/*.png", "**/models/**", "**/textures/**"]) { filesNotMatching(["**/*.png", "**/models/**", "**/textures/**"]) {
expand projectVersion: project.version expand projectVersion: project.version

View File

@@ -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")
}

View File

@@ -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
}

View File

@@ -7,6 +7,7 @@ import com.willfp.eco.core.data.ExtendedPersistentDataContainer
import com.willfp.eco.core.entities.ai.EntityController import com.willfp.eco.core.entities.ai.EntityController
import com.willfp.eco.core.fast.FastItemStack import com.willfp.eco.core.fast.FastItemStack
import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration 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.EcoCleaner
import com.willfp.eco.internal.EcoPropsParser import com.willfp.eco.internal.EcoPropsParser
import com.willfp.eco.internal.Plugins 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.DataYml
import com.willfp.eco.internal.spigot.data.EcoKeyRegistry import com.willfp.eco.internal.spigot.data.EcoKeyRegistry
import com.willfp.eco.internal.spigot.data.EcoProfileHandler 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.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.CommonsInitializerProxy
import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy
import com.willfp.eco.internal.spigot.proxy.EntityControllerFactoryProxy import com.willfp.eco.internal.spigot.proxy.EntityControllerFactoryProxy
@@ -57,7 +60,19 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
private var adventure: BukkitAudiences? = null private var adventure: BukkitAudiences? = null
private val keyRegistry = EcoKeyRegistry() 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") @Suppress("RedundantNullableReturnType")
private val keyFactory: InternalNamespacedKeyFactory? = private val keyFactory: InternalNamespacedKeyFactory? =
@@ -159,4 +174,7 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
override fun newPdc(): PersistentDataContainer = override fun newPdc(): PersistentDataContainer =
getProxy(ExtendedPersistentDataContainerFactoryProxy::class.java).newPdc() getProxy(ExtendedPersistentDataContainerFactoryProxy::class.java).newPdc()
override fun getSNBTHandler(): SNBTHandler =
snbtHandler
} }

View File

@@ -63,7 +63,8 @@ import com.willfp.eco.internal.spigot.display.PacketWindowItems
import com.willfp.eco.internal.spigot.display.frame.clearFrames import com.willfp.eco.internal.spigot.display.frame.clearFrames
import com.willfp.eco.internal.spigot.drops.CollatedRunnable import com.willfp.eco.internal.spigot.drops.CollatedRunnable
import com.willfp.eco.internal.spigot.eventlisteners.EntityDeathByEntityListeners import com.willfp.eco.internal.spigot.eventlisteners.EntityDeathByEntityListeners
import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListeners import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListenersPaper
import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListenersSpigot
import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersPaper import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersPaper
import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersSpigot import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersSpigot
import com.willfp.eco.internal.spigot.eventlisteners.armor.ArmorChangeEventListeners import com.willfp.eco.internal.spigot.eventlisteners.armor.ArmorChangeEventListeners
@@ -110,6 +111,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.ShopShopGuiPlus
import com.willfp.eco.internal.spigot.integrations.shop.ShopZShop import com.willfp.eco.internal.spigot.integrations.shop.ShopZShop
import com.willfp.eco.internal.spigot.math.evaluateExpression 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.FastItemStackFactoryProxy
import com.willfp.eco.internal.spigot.proxy.SkullProxy import com.willfp.eco.internal.spigot.proxy.SkullProxy
import com.willfp.eco.internal.spigot.proxy.TPSProxy import com.willfp.eco.internal.spigot.proxy.TPSProxy
@@ -191,7 +193,27 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
} }
override fun handleEnable() { 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) CollatedRunnable(this)
CustomItemsManager.registerProviders() // Do it again here
// Register events for ShopSellEvent // Register events for ShopSellEvent
ShopManager.registerEvents(this) ShopManager.registerEvents(this)
@@ -218,7 +240,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
override fun handleReload() { override fun handleReload() {
CollatedRunnable(this) CollatedRunnable(this)
DropManager.update(this) DropManager.update(this)
ProfileSaver(this) ProfileSaver(this, Eco.getHandler().profileHandler)
this.scheduler.runTimer( this.scheduler.runTimer(
{ clearFrames() }, { clearFrames() },
this.configYml.getInt("display-frame-ttl").toLong(), this.configYml.getInt("display-frame-ttl").toLong(),
@@ -329,7 +351,6 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
override fun loadListeners(): List<Listener> { override fun loadListeners(): List<Listener> {
val listeners = mutableListOf( val listeners = mutableListOf(
NaturalExpGainListeners(),
ArmorListener(), ArmorListener(),
EntityDeathByEntityListeners(this), EntityDeathByEntityListeners(this),
CraftingRecipeListener(), CraftingRecipeListener(),
@@ -338,13 +359,16 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
ArrowDataListener(this), ArrowDataListener(this),
ArmorChangeEventListeners(this), ArmorChangeEventListeners(this),
DataListener(this), DataListener(this),
PlayerBlockListener(this) PlayerBlockListener(this),
PlayerHealthFixer(this)
) )
if (Prerequisite.HAS_PAPER.isMet) { if (Prerequisite.HAS_PAPER.isMet) {
listeners.add(PlayerJumpListenersPaper()) listeners.add(PlayerJumpListenersPaper())
listeners.add(NaturalExpGainListenersPaper())
} else { } else {
listeners.add(PlayerJumpListenersSpigot()) listeners.add(PlayerJumpListenersSpigot())
listeners.add(NaturalExpGainListenersSpigot())
} }
return listeners return listeners

View File

@@ -24,20 +24,29 @@ class EcoKeyRegistry : KeyRegistry {
return registry.values.toMutableSet() return registry.values.toMutableSet()
} }
override fun getCategory(key: PersistentDataKey<*>): KeyRegistry.KeyCategory? {
return categories[key.key]
}
private fun <T> validateKey(key: PersistentDataKey<T>) { private fun <T> validateKey(key: PersistentDataKey<T>) {
val default = key.defaultValue
when (key.type) { when (key.type) {
PersistentDataKeyType.INT -> if (key.defaultValue !is Int) { PersistentDataKeyType.INT -> if (default !is Int) {
throw IllegalArgumentException("Invalid Data Type! Should be 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") 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") 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") 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!") else -> throw NullPointerException("Null value found!")
} }

View File

@@ -1,5 +1,6 @@
package com.willfp.eco.internal.spigot.data 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.PlayerProfile
import com.willfp.eco.core.data.Profile import com.willfp.eco.core.data.Profile
import com.willfp.eco.core.data.ProfileHandler 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.core.data.keys.PersistentDataKey
import com.willfp.eco.internal.spigot.EcoSpigotPlugin import com.willfp.eco.internal.spigot.EcoSpigotPlugin
import com.willfp.eco.internal.spigot.data.storage.DataHandler 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.MySQLDataHandler
import com.willfp.eco.internal.spigot.data.storage.YamlDataHandler import com.willfp.eco.internal.spigot.data.storage.YamlDataHandler
import org.bukkit.Bukkit
import java.util.UUID import java.util.UUID
val serverProfileUUID = UUID(0, 0) val serverProfileUUID = UUID(0, 0)
class EcoProfileHandler( class EcoProfileHandler(
useSql: Boolean, private val type: HandlerType,
plugin: EcoSpigotPlugin private val plugin: EcoSpigotPlugin
) : ProfileHandler { ) : ProfileHandler {
private val loaded = mutableMapOf<UUID, Profile>() 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 { fun loadGenericProfile(uuid: UUID): Profile {
val found = loaded[uuid] val found = loaded[uuid]
@@ -45,26 +53,87 @@ class EcoProfileHandler(
} }
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) { override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
val profile = loadGenericProfile(uuid) handler.saveKeysFor(uuid, keys)
for (key in keys) {
handler.write(uuid, key.key, profile.read(key))
}
} }
override fun unloadPlayer(uuid: UUID) { override fun unloadPlayer(uuid: UUID) {
loaded.remove(uuid) loaded.remove(uuid)
} }
override fun saveAll() {
handler.saveAll(loaded.keys.toList())
}
override fun save() { override fun save() {
handler.save() handler.save()
} }
fun initialize() { private fun migrateIfNeeded() {
handler.initialize() 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()
}
}

View File

@@ -6,7 +6,7 @@ import com.willfp.eco.util.NamespacedKeyUtils
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
object KeyHelpers { object KeyHelpers {
fun deserializeFromString(serialized: String): PersistentDataKey<*>? { fun deserializeFromString(serialized: String, server: Boolean = false): PersistentDataKey<*>? {
val split = serialized.split(";").toTypedArray() val split = serialized.split(";").toTypedArray()
if (split.size < 2) { if (split.size < 2) {
@@ -15,7 +15,7 @@ object KeyHelpers {
val key = NamespacedKeyUtils.fromStringOrNull(split[0]) ?: return null val key = NamespacedKeyUtils.fromStringOrNull(split[0]) ?: return null
val type = PersistentDataKeyType.valueOf(split[1]) ?: return null val type = PersistentDataKeyType.valueOf(split[1]) ?: return null
return when (type) { val persistentKey = when (type) {
PersistentDataKeyType.STRING -> PersistentDataKey( PersistentDataKeyType.STRING -> PersistentDataKey(
key, key,
type as PersistentDataKeyType<String>, type as PersistentDataKeyType<String>,
@@ -38,6 +38,16 @@ object KeyHelpers {
) )
else -> null else -> null
} }
if (persistentKey != null) {
if (server) {
persistentKey.server()
} else {
persistentKey.player()
}
}
return persistentKey
} }
fun serializeToString(key: PersistentDataKey<*>): String { fun serializeToString(key: PersistentDataKey<*>): String {

View File

@@ -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.KeyRegistry
import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.core.data.keys.PersistentDataKey
import org.bukkit.NamespacedKey
import java.util.UUID import java.util.UUID
interface DataHandler { abstract class DataHandler(
fun save() val type: HandlerType
fun saveAll(uuids: Iterable<UUID>) ) {
/**
* 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) { open fun initialize() {
saveKeysFor(uuid, PersistentDataKey.values())
}
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?
}

View File

@@ -0,0 +1,7 @@
package com.willfp.eco.internal.spigot.data.storage
enum class HandlerType {
YAML,
MYSQL,
MONGO
}

View File

@@ -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>
)

View File

@@ -13,8 +13,6 @@ import com.willfp.eco.internal.spigot.data.KeyHelpers
import com.willfp.eco.internal.spigot.data.serverProfileUUID import com.willfp.eco.internal.spigot.data.serverProfileUUID
import com.zaxxer.hikari.HikariConfig import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource 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.dao.id.UUIDTable
import org.jetbrains.exposed.sql.BooleanColumnType import org.jetbrains.exposed.sql.BooleanColumnType
import org.jetbrains.exposed.sql.Column 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.ResultRow
import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.VarCharColumnType import org.jetbrains.exposed.sql.VarCharColumnType
import org.jetbrains.exposed.sql.exposedLogger
import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update import org.jetbrains.exposed.sql.update
import java.util.UUID import java.util.UUID
import java.util.concurrent.Callable import java.util.concurrent.Callable
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit 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") @Suppress("UNCHECKED_CAST")
class MySQLDataHandler( class MySQLDataHandler(
private val plugin: EcoSpigotPlugin, private val plugin: EcoSpigotPlugin,
handler: EcoProfileHandler handler: EcoProfileHandler
) : DataHandler { ) : DataHandler(HandlerType.MYSQL) {
private val playerHandler: ImplementedMySQLHandler private val playerHandler: ImplementedMySQLHandler
private val serverHandler: ImplementedMySQLHandler private val serverHandler: ImplementedMySQLHandler
init { 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() val config = HikariConfig()
config.driverClassName = "com.mysql.cj.jdbc.Driver" config.driverClassName = "com.mysql.cj.jdbc.Driver"
@@ -58,40 +72,26 @@ class MySQLDataHandler(
Database.connect(HikariDataSource(config)) 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( playerHandler = ImplementedMySQLHandler(
handler, handler,
UUIDTable("eco_players"), UUIDTable("eco_players"),
plugin, plugin
plugin.dataYml.getStrings("categorized-keys.player")
.mapNotNull { KeyHelpers.deserializeFromString(it) }
) )
serverHandler = ImplementedMySQLHandler( serverHandler = ImplementedMySQLHandler(
handler, handler,
UUIDTable("eco_server"), UUIDTable("eco_server"),
plugin, plugin
plugin.dataYml.getStrings("categorized-keys.server")
.mapNotNull { KeyHelpers.deserializeFromString(it) }
) )
} }
override fun saveAll(uuids: Iterable<UUID>) { override fun <T : Any> read(uuid: UUID, key: PersistentDataKey<T>): T? {
serverHandler.saveAll(uuids.filter { it == serverProfileUUID }) return applyFor(uuid) {
playerHandler.saveAll(uuids.filter { it != serverProfileUUID }) 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) { applyFor(uuid) {
it.write(uuid, key, value) 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 { private inline fun <R> applyFor(uuid: UUID, function: (ImplementedMySQLHandler) -> R): R {
return if (uuid == serverProfileUUID) { return if (uuid == serverProfileUUID) {
function(serverHandler) function(serverHandler)
@@ -119,21 +113,21 @@ class MySQLDataHandler(
override fun categorize(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) { override fun categorize(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) {
if (category == KeyRegistry.KeyCategory.SERVER) { if (category == KeyRegistry.KeyCategory.SERVER) {
serverHandler.ensureKeyRegistration(key.key) serverHandler.ensureKeyRegistration(key)
} else { } else {
playerHandler.ensureKeyRegistration(key.key) playerHandler.ensureKeyRegistration(key)
} }
} }
override fun save() { override fun save() {
plugin.dataYml.set( plugin.dataYml.set(
"categorized-keys.player", "categorized-keys.player",
playerHandler.registeredKeys.values playerHandler.registeredKeys
.map { KeyHelpers.serializeToString(it) } .map { KeyHelpers.serializeToString(it) }
) )
plugin.dataYml.set( plugin.dataYml.set(
"categorized-keys.server", "categorized-keys.server",
serverHandler.registeredKeys.values serverHandler.registeredKeys
.map { KeyHelpers.serializeToString(it) } .map { KeyHelpers.serializeToString(it) }
) )
plugin.dataYml.save() plugin.dataYml.save()
@@ -149,21 +143,15 @@ class MySQLDataHandler(
private class ImplementedMySQLHandler( private class ImplementedMySQLHandler(
private val handler: EcoProfileHandler, private val handler: EcoProfileHandler,
private val table: UUIDTable, private val table: UUIDTable,
plugin: EcoPlugin, plugin: EcoPlugin
private val knownKeys: Collection<PersistentDataKey<*>>
) { ) {
private val columns = Caffeine.newBuilder()
.expireAfterWrite(3, TimeUnit.SECONDS)
.build<String, Column<*>>()
private val rows = Caffeine.newBuilder() private val rows = Caffeine.newBuilder()
.expireAfterWrite(3, TimeUnit.SECONDS) .expireAfterWrite(3, TimeUnit.SECONDS)
.build<UUID, ResultRow>() .build<UUID, ResultRow>()
private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build()
private val executor = Executors.newFixedThreadPool(plugin.configYml.getInt("mysql.threads"), threadFactory) private val executor = Executors.newFixedThreadPool(plugin.configYml.getInt("mysql.threads"), threadFactory)
val registeredKeys = ConcurrentHashMap<NamespacedKey, PersistentDataKey<*>>() val registeredKeys = mutableSetOf<PersistentDataKey<*>>()
private val currentlyProcessingRegistration = ConcurrentHashMap<NamespacedKey, Future<*>>()
init { init {
transaction { transaction {
@@ -173,58 +161,32 @@ private class ImplementedMySQLHandler(
fun initialize() { fun initialize() {
transaction { transaction {
for (key in knownKeys) {
registerColumn(key, table)
}
SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
for (key in knownKeys) {
registeredKeys[key.key] = key
}
} }
} }
fun ensureKeyRegistration(key: NamespacedKey) { fun ensureKeyRegistration(key: PersistentDataKey<*>) {
if (registeredKeys.contains(key)) { if (table.columns.any { it.name == key.key.toString() }) {
registeredKeys.add(key)
return return
} }
val persistentKey = Eco.getHandler().keyRegistry.getKeyFrom(key) ?: return registerColumn(key)
registeredKeys.add(key)
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)
}
} }
fun <T> write(uuid: UUID, key: NamespacedKey, value: T) { fun <T : Any> write(uuid: UUID, key: PersistentDataKey<T>, value: Any) {
getOrCreateRow(uuid) getRow(uuid)
doWrite(uuid, key, value) doWrite(uuid, key, key.type.constrainSQLTypes(value))
} }
private fun <T> doWrite(uuid: UUID, key: NamespacedKey, value: T) { private fun doWrite(uuid: UUID, key: PersistentDataKey<*>, constrainedValue: Any) {
val column: Column<T> = getColumn(key) as Column<T> val column: Column<Any> = getColumn(key) as Column<Any>
executor.submit { executor.submit {
transaction { transaction {
table.update({ table.id eq uuid }) { table.update({ table.id eq uuid }) {
it[column] = value it[column] = constrainedValue
} }
} }
} }
@@ -234,35 +196,28 @@ private class ImplementedMySQLHandler(
saveRow(uuid, keys) saveRow(uuid, keys)
} }
fun saveAll(uuids: Iterable<UUID>) {
for (uuid in uuids) {
saveRow(uuid, PersistentDataKey.values())
}
}
private fun saveRow(uuid: UUID, keys: Set<PersistentDataKey<*>>) { private fun saveRow(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
val profile = handler.loadGenericProfile(uuid) val profile = handler.loadGenericProfile(uuid)
executor.submit { executor.submit {
transaction { transaction {
getOrCreateRow(uuid) getRow(uuid)
for (key in keys) { 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?> { val doRead = Callable<T?> {
var value: T? = null
transaction { transaction {
val row = getOrCreateRow(uuid) val row = getRow(uuid)
value = row[getColumn(key)] as T? 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. 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) { private fun <T> registerColumn(key: PersistentDataKey<T>) {
table.apply { transaction {
if (this.columns.stream().anyMatch { it.name == key.key.toString() }) { table.apply {
return@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) { SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
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!")
}
} }
} }
private fun getColumn(key: NamespacedKey): Column<*> { private fun getColumn(key: PersistentDataKey<*>): Column<*> {
ensureKeyRegistration(key) ensureKeyRegistration(key)
val name = key.toString() val name = key.key.toString()
return columns.get(name) { return table.columns.first { it.name == name }
table.columns.first { it.name == name }
}
} }
private fun getOrCreateRow(uuid: UUID): ResultRow { private fun getRow(uuid: UUID): ResultRow {
fun select(uuid: UUID): ResultRow? { fun select(uuid: UUID): ResultRow? {
return transaction { return transaction {
table.select { table.id eq uuid }.limit(1).singleOrNull() 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
}

View File

@@ -1,16 +1,19 @@
package com.willfp.eco.internal.spigot.data.storage 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.EcoPlugin
import com.willfp.eco.core.data.ProfileHandler
import com.willfp.eco.internal.spigot.data.EcoProfile import com.willfp.eco.internal.spigot.data.EcoProfile
class ProfileSaver(plugin: EcoPlugin) { class ProfileSaver(
plugin: EcoPlugin,
handler: ProfileHandler
) {
init { init {
plugin.scheduler.runTimer({ plugin.scheduler.runTimer(1, 1) {
for ((uuid, set) in EcoProfile.CHANGE_MAP) { for ((uuid, set) in EcoProfile.CHANGE_MAP) {
Eco.getHandler().profileHandler.saveKeysFor(uuid, set) handler.saveKeysFor(uuid, set)
} }
EcoProfile.CHANGE_MAP.clear() EcoProfile.CHANGE_MAP.clear()
}, 1, 1) }
} }
} }

View File

@@ -11,42 +11,40 @@ import java.util.UUID
class YamlDataHandler( class YamlDataHandler(
plugin: EcoSpigotPlugin, plugin: EcoSpigotPlugin,
private val handler: EcoProfileHandler private val handler: EcoProfileHandler
) : DataHandler { ) : DataHandler(HandlerType.YAML) {
private val dataYml = plugin.dataYml private val dataYml = plugin.dataYml
override fun save() { override fun save() {
dataYml.save() dataYml.save()
} }
override fun saveAll(uuids: Iterable<UUID>) { override fun <T : Any> read(uuid: UUID, key: PersistentDataKey<T>): T? {
for (uuid in uuids) { // Separate `as T?` for each branch to prevent compiler warnings.
savePlayer(uuid) 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<*>>) { override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
val profile = handler.loadGenericProfile(uuid) val profile = handler.loadGenericProfile(uuid)
for (key in keys) { 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) 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
}
} }

View File

@@ -15,6 +15,10 @@ class PacketAutoRecipe(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, Packet
player: Player, player: Player,
event: PacketEvent event: PacketEvent
) { ) {
if (!this.getPlugin().configYml.getBool("displayed-recipes")) {
return
}
if (!EcoPlugin.getPluginNames() if (!EcoPlugin.getPluginNames()
.contains(packet.minecraftKeys.values[0].fullKey.split(":".toRegex()).toTypedArray()[0]) .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)) newAutoRecipe.minecraftKeys.write(0, packet.minecraftKeys.read(0))
ProtocolLibrary.getProtocolManager().sendServerPacket(player, newAutoRecipe) ProtocolLibrary.getProtocolManager().sendServerPacket(player, newAutoRecipe)
} }
} }

View File

@@ -7,9 +7,7 @@ import com.comphenix.protocol.events.PacketEvent
import com.willfp.eco.core.AbstractPacketAdapter import com.willfp.eco.core.AbstractPacketAdapter
import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy
import com.willfp.eco.util.NamespacedKeyUtils
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.MerchantRecipe import org.bukkit.inventory.MerchantRecipe
class PacketOpenWindowMerchant(plugin: EcoPlugin) : class PacketOpenWindowMerchant(plugin: EcoPlugin) :
@@ -24,22 +22,6 @@ class PacketOpenWindowMerchant(plugin: EcoPlugin) :
) { ) {
val recipes = mutableListOf<MerchantRecipe>() 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)) { for (recipe in packet.merchantRecipeLists.read(0)) {
val newRecipe = getPlugin().getProxy(VillagerTradeProxy::class.java).displayTrade( val newRecipe = getPlugin().getProxy(VillagerTradeProxy::class.java).displayTrade(
recipe!!, player recipe!!, player

View File

@@ -1,30 +1,20 @@
package com.willfp.eco.internal.spigot.display package com.willfp.eco.internal.spigot.display
import com.comphenix.protocol.PacketType import com.comphenix.protocol.PacketType
import com.comphenix.protocol.ProtocolLibrary
import com.comphenix.protocol.events.PacketContainer import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.events.PacketEvent import com.comphenix.protocol.events.PacketEvent
import com.google.common.util.concurrent.ThreadFactoryBuilder
import com.willfp.eco.core.AbstractPacketAdapter import com.willfp.eco.core.AbstractPacketAdapter
import com.willfp.eco.core.Eco
import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.display.Display import com.willfp.eco.core.display.Display
import com.willfp.eco.core.items.HashedItem import com.willfp.eco.core.items.HashedItem
import com.willfp.eco.internal.spigot.display.frame.DisplayFrame import com.willfp.eco.internal.spigot.display.frame.DisplayFrame
import com.willfp.eco.internal.spigot.display.frame.lastDisplayFrame import com.willfp.eco.internal.spigot.display.frame.lastDisplayFrame
import com.willfp.eco.util.ServerUtils
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
class PacketWindowItems(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketType.Play.Server.WINDOW_ITEMS, false) { class PacketWindowItems(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketType.Play.Server.WINDOW_ITEMS, false) {
private val ignorePacketList = ConcurrentHashMap.newKeySet<String>() private val ignorePacketList = ConcurrentHashMap.newKeySet<String>()
private val playerRates = ConcurrentHashMap<String, Int>()
private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-display-thread-%d").build()
private val executor = Executors.newCachedThreadPool(threadFactory)
private val scheduledExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory)
override fun onSend( override fun onSend(
packet: PacketContainer, packet: PacketContainer,
@@ -44,90 +34,9 @@ class PacketWindowItems(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, Packe
val itemStacks = packet.itemListModifier.read(0) ?: return val itemStacks = packet.itemListModifier.read(0) ?: return
handleRateLimit(player)
if (usingAsync(player)) {
val newPacket = packet.deepClone()
executor.execute {
runCatchingWithLogs { modifyAndSend(newPacket, itemStacks, windowId, player) }
}
} else {
modifyPacket(packet, itemStacks, windowId, player)
}
}
private fun modifyPacket(
packet: PacketContainer,
itemStacks: MutableList<ItemStack>,
windowId: Int,
player: Player
) {
packet.itemListModifier.write(0, modifyWindowItems(itemStacks, windowId, player)) packet.itemListModifier.write(0, modifyWindowItems(itemStacks, windowId, player))
} }
private fun modifyAndSend(
packet: PacketContainer,
itemStacks: MutableList<ItemStack>,
windowId: Int,
player: Player
) {
modifyPacket(packet, itemStacks, windowId, player)
ignorePacketList.add(player.name)
this.getPlugin().scheduler.run {
runCatchingWithLogs { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet) }
}
}
private fun handleRateLimit(player: Player) {
fun modifyRateValueBy(player: Player, amount: Int) {
val name = player.name
val current = playerRates[name] ?: 0
val new = current + amount
if (new <= 0) {
playerRates.remove(name)
} else {
playerRates[name] = new
}
}
modifyRateValueBy(player, 1)
scheduledExecutor.schedule(
{ modifyRateValueBy(player, -1) },
this.getPlugin().configYml.getInt("async-display.ratelimit.timeframe").toLong(),
TimeUnit.SECONDS
)
}
private fun usingAsync(player: Player): Boolean {
if (this.getPlugin().configYml.getStrings("async-display.disable-on-types")
.map { it.lowercase() }.contains(player.openInventory.type.name.lowercase())
) {
return false
}
if (this.getPlugin().configYml.getBool("async-display.always-enabled")) {
return true
}
if (
this.getPlugin().configYml.getBool("async-display.emergency.enabled")
&& ServerUtils.getTps() <= this.getPlugin().configYml.getDouble("async-display.emergency.cutoff")
) {
return true
}
if (
this.getPlugin().configYml.getBool("async-display.ratelimit.enabled")
&& (playerRates[player.name] ?: 0) >= this.getPlugin().configYml.getInt("async-display.ratelimit.cutoff")
) {
return true
}
return false
}
private fun modifyWindowItems( private fun modifyWindowItems(
itemStacks: MutableList<ItemStack>, itemStacks: MutableList<ItemStack>,
windowId: Int, windowId: Int,
@@ -162,14 +71,3 @@ class PacketWindowItems(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, Packe
return itemStacks return itemStacks
} }
} }
private inline fun <T> runCatchingWithLogs(toRun: () -> T): Result<T> {
return runCatching { toRun() }.onFailure {
if (Eco.getHandler().ecoPlugin.configYml.getBool("async-display.log-errors")) {
Eco.getHandler().ecoPlugin.logger.warning(
"Error happened in async processing! Disable async display (/plugins/eco/config.yml)" +
"if this is a frequent issue. (Remember to disable ratelimit and emergency too)"
)
}
}
}

View File

@@ -1,7 +1,6 @@
package com.willfp.eco.internal.spigot.eventlisteners package com.willfp.eco.internal.spigot.eventlisteners
import com.willfp.eco.core.events.EntityDeathByEntityEvent import com.willfp.eco.core.events.EntityDeathByEntityEvent
import org.apache.commons.lang.Validate
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.entity.Entity import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity import org.bukkit.entity.LivingEntity
@@ -10,20 +9,12 @@ import org.bukkit.inventory.ItemStack
internal class EntityDeathByEntityBuilder { internal class EntityDeathByEntityBuilder {
var victim: LivingEntity? = null var victim: LivingEntity? = null
var damager: Entity? = null var damager: Entity? = null
var deathEvent: EntityDeathEvent? = null var deathEvent: EntityDeathEvent? = null
var drops: List<ItemStack>? = null var drops: List<ItemStack>? = null
var xp = 0 var xp = 0
fun push() {
Validate.notNull(victim) fun push() {
Validate.notNull(damager)
Validate.notNull(drops)
Validate.notNull(deathEvent)
val event = EntityDeathByEntityEvent(victim!!, damager!!, drops!!, xp, deathEvent!!) val event = EntityDeathByEntityEvent(victim!!, damager!!, drops!!, xp, deathEvent!!)
Bukkit.getPluginManager().callEvent(event) Bukkit.getPluginManager().callEvent(event)
} }

View File

@@ -7,7 +7,6 @@ import org.bukkit.event.EventPriority
import org.bukkit.event.Listener import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageByEntityEvent import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.entity.EntityDeathEvent import org.bukkit.event.entity.EntityDeathEvent
import java.util.concurrent.atomic.AtomicReference
class EntityDeathByEntityListeners( class EntityDeathByEntityListeners(
private val plugin: EcoPlugin private val plugin: EcoPlugin
@@ -35,25 +34,24 @@ class EntityDeathByEntityListeners(
} }
} }
@EventHandler @EventHandler(priority = EventPriority.HIGH)
fun onEntityDeath(event: EntityDeathEvent) { fun onEntityDeath(event: EntityDeathEvent) {
val victim = event.entity val victim = event.entity
val drops = event.drops val drops = event.drops
val xp = event.droppedExp val xp = event.droppedExp
val atomicBuiltEvent = AtomicReference<EntityDeathByEntityBuilder>(null) var builtEvent: EntityDeathByEntityBuilder? = null
for (builder in events) { for (builder in events) {
if (builder.victim == victim) { if (builder.victim == victim) {
atomicBuiltEvent.set(builder) builtEvent = builder
} }
} }
if (atomicBuiltEvent.get() == null) { if (builtEvent == null) {
return return
} }
val builtEvent = atomicBuiltEvent.get()
events.remove(builtEvent) events.remove(builtEvent)
builtEvent.drops = drops builtEvent.drops = drops
builtEvent.xp = xp builtEvent.xp = xp

View File

@@ -1,11 +1,28 @@
package com.willfp.eco.internal.spigot.eventlisteners package com.willfp.eco.internal.spigot.eventlisteners
import com.willfp.eco.core.events.NaturalExpGainEvent
import org.bukkit.Bukkit
import org.bukkit.entity.ThrownExpBottle
import org.bukkit.event.EventHandler import org.bukkit.event.EventHandler
import org.bukkit.event.Listener import org.bukkit.event.Listener
import org.bukkit.event.entity.ExpBottleEvent import org.bukkit.event.entity.ExpBottleEvent
import org.bukkit.event.player.PlayerExpChangeEvent import org.bukkit.event.player.PlayerExpChangeEvent
class NaturalExpGainListeners : Listener { class NaturalExpGainListenersPaper : Listener {
@EventHandler
fun onEvent(event: PlayerExpChangeEvent) {
val source = event.source
if (source is ThrownExpBottle) {
return
}
val ecoEvent = NaturalExpGainEvent(event)
Bukkit.getPluginManager().callEvent(ecoEvent)
}
}
class NaturalExpGainListenersSpigot : Listener {
private val events: MutableSet<NaturalExpGainBuilder> = HashSet() private val events: MutableSet<NaturalExpGainBuilder> = HashSet()
@EventHandler @EventHandler

View File

@@ -11,10 +11,7 @@ import com.willfp.eco.core.integrations.antigrief.AntigriefIntegration
import org.apache.commons.lang.Validate import org.apache.commons.lang.Validate
import org.bukkit.Location import org.bukkit.Location
import org.bukkit.block.Block import org.bukkit.block.Block
import org.bukkit.entity.Animals import org.bukkit.entity.*
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Monster
import org.bukkit.entity.Player
class AntigriefWorldGuard : AntigriefIntegration { class AntigriefWorldGuard : AntigriefIntegration {
override fun canBreakBlock( override fun canBreakBlock(
@@ -85,6 +82,7 @@ class AntigriefWorldGuard : AntigriefIntegration {
is Player -> Flags.PVP is Player -> Flags.PVP
is Monster -> Flags.MOB_DAMAGE is Monster -> Flags.MOB_DAMAGE
is Animals -> Flags.DAMAGE_ANIMALS is Animals -> Flags.DAMAGE_ANIMALS
is ArmorStand -> Flags.INTERACT
else -> return true else -> return true
} }

View File

@@ -21,7 +21,9 @@ class CustomItemsItemsAdder : CustomItemsIntegration {
private class ItemsAdderProvider : ItemProvider("itemsadder") { private class ItemsAdderProvider : ItemProvider("itemsadder") {
override fun provideForKey(key: String): TestableItem? { override fun provideForKey(key: String): TestableItem? {
val item = CustomStack.getInstance("itemsadder:$key") ?: return null val internalId = if (key.contains(":")) key else "itemsadder:$key"
val item = CustomStack.getInstance(internalId) ?: return null
val id = item.id val id = item.id
val namespacedKey = NamespacedKeyUtils.create("itemsadder", key) val namespacedKey = NamespacedKeyUtils.create("itemsadder", key)
val stack = item.itemStack val stack = item.itemStack
@@ -34,6 +36,5 @@ class CustomItemsItemsAdder : CustomItemsIntegration {
stack stack
) )
} }
} }
} }

View File

@@ -0,0 +1,20 @@
package com.willfp.eco.internal.spigot.items
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.items.SNBTHandler
import com.willfp.eco.core.items.TestableItem
import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy
import org.bukkit.inventory.ItemStack
class EcoSNBTHandler(
private val plugin: EcoPlugin
) : SNBTHandler {
override fun fromSNBT(snbt: String): ItemStack? =
plugin.getProxy(SNBTConverterProxy::class.java).fromSNBT(snbt)
override fun toSNBT(itemStack: ItemStack): String =
plugin.getProxy(SNBTConverterProxy::class.java).toSNBT(itemStack)
override fun createTestable(snbt: String): TestableItem =
plugin.getProxy(SNBTConverterProxy::class.java).makeSNBTTestable(snbt)
}

View File

@@ -0,0 +1,42 @@
package com.willfp.eco.internal.spigot.player
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.core.data.keys.PersistentDataKeyType
import com.willfp.eco.core.data.profile
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerQuitEvent
class PlayerHealthFixer(
private val plugin: EcoPlugin
): Listener {
private val lastHealthKey = PersistentDataKey(
plugin.namespacedKeyFactory.create("last_health"),
PersistentDataKeyType.DOUBLE,
0.0
)
@EventHandler
fun onLeave(event: PlayerQuitEvent) {
if (!plugin.configYml.getBool("health-fixer")) {
return
}
val player = event.player
player.profile.write(lastHealthKey, player.health)
}
@EventHandler
fun onJoin(event: PlayerJoinEvent) {
if (!plugin.configYml.getBool("health-fixer")) {
return
}
val player = event.player
plugin.scheduler.runLater(2) {
player.health = player.profile.read(lastHealthKey)
}
}
}

View File

@@ -1,17 +1,30 @@
# #
# eco # eco
# by Auxilor # by Auxilor
# Default config (With Comments) can be found here: https://github.com/Auxilor/eco/blob/master/eco-core/core-plugin/src/main/resources/config.yml
# #
# How player/server data is saved:
# yaml - Stored in data.yml: Good option for single-node servers (i.e. no BungeeCord/Velocity)
# mongo - (Recommended) If you're running on a network (Bungee/Velocity), you should use MongoDB if you can.
# mysql - (Not Recommended) The basic choice for Bungee/Velocity networks, less flexible and worse performance than MongoDB. Only use it if you can't use MongoDB.
data-handler: yaml
# If data should be migrated automatically when changing data handler.
perform-data-migration: true
mongodb:
# The full MongoDB connection URL.
url: ""
mysql: mysql:
enabled: false # Set to false, data.yml will be used instead.
# How many threads to execute statements on. Higher numbers can be faster however # How many threads to execute statements on. Higher numbers can be faster however
# very high numbers can cause issues with OS configuration. If writes are taking # very high numbers can cause issues with OS configuration. If writes are taking
# too long, increase this value. # too long, increase this value.
threads: 2 threads: 2
# The maximum number of MySQL connections. # The maximum number of MySQL connections.
connections: 10 connections: 10
# If read operations should be ran in the thread pool. Runs on main thread by default. # If read operations should be run in the thread pool. Runs on main thread by default.
async-reads: false async-reads: false
host: localhost host: localhost
port: 3306 port: 3306
@@ -19,8 +32,13 @@ mysql:
user: username user: username
password: passy password: passy
# Options to fix villager bugs left behind from old (buggy) versions. # Ignore this option, it does nothing.
villager-display-fix: false enabled: false # Ignore this - only for backwards compatibility
# Options to manage the conflict finder
conflicts:
whitelist: # Plugins that should never be marked as conflicts
- eco
# DropQueue by default uses a faster collated queue system where all drops # DropQueue by default uses a faster collated queue system where all drops
# that originate from the same player on the same tick are dropped together. # that originate from the same player on the same tick are dropped together.
@@ -52,42 +70,13 @@ use-safer-namespacedkey-creation: false
# default to prevent users from reporting bugs. Enable if you're a developer. # default to prevent users from reporting bugs. Enable if you're a developer.
log-full-extension-errors: false log-full-extension-errors: false
# Window items packets have the option to be run asynchronously. This may cause # To make the custom crafting system work better for players, players are also sent an
# some bugs and is considered experimental, however it has been tested without # additional recipe containing the displayed items as ingredients. However, with a large
# any apparent issues. Enable this if performance is absolutely crucial or if you # number of recipes, this can create PacketTooLargeExceptions. If you have this exception,
# are experiencing severe display lag. # disable this option. Bear in mind that this means the auto-craft preview will fail to
async-display: # render items nicely, which may degrade the user experience on your server. If you use
# If async display should always be used. # a custom crafting table, though, this won't affect anything, and you should disable the option.
always-enabled: false displayed-recipes: true
# Log errors that occur in async processing. # Save health on leave and set it back on join - works around attribute modifiers.
log-errors: true health-fixer: false
# The inventory types that should never be processed asynchronously.
# A list of IDs can be found here:
# https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/inventory/InventoryType.html
disable-on-types:
- 'anvil'
# If the server is running under heavy load (below a certain TPS value), enable
# async display automatically. This can prevent some server crashes under load.
emergency:
# If emergency async should be used.
enabled: true
# Below this TPS value, emergency async display will be used.
cutoff: 17
# If players with a large amount of display packets should have their processing
# done asynchronously. This will help if a player is trying to crash the server
# by overloading the display system.
ratelimit:
# If rate limit async display should be used.
enabled: false
# The amount of window items packets per timeframe needed to enable async display
# for a specified player.
cutoff: 4
# The length of the timeframe in seconds.
# Cutoff 5, Timeframe 1 means that if there are more than 5 window items packets
# being sent per second for a player, then that player should have their packets
# handled asynchronously.
timeframe: 1

View File

@@ -0,0 +1,10 @@
package com.willfp.eco.internal.spigot.proxy
import com.willfp.eco.core.items.TestableItem
import org.bukkit.inventory.ItemStack
interface SNBTConverterProxy {
fun toSNBT(itemStack: ItemStack): String
fun fromSNBT(snbt: String): ItemStack?
fun makeSNBTTestable(snbt: String): TestableItem
}

View File

@@ -1,3 +1,3 @@
version = 6.35.2 version = 6.37.3
plugin-name = eco plugin-name = eco
kotlin.code.style = official kotlin.code.style = official

View File

@@ -1,7 +1,7 @@
pluginManagement { pluginManagement {
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
maven("https://papermc.io/repo/repository/maven-public/") maven("https://repo.papermc.io/repository/maven-public/")
} }
} }
@@ -15,6 +15,7 @@ include(":eco-core:core-nms:nms-common")
include(":eco-core:core-nms:v1_17_R1") include(":eco-core:core-nms:v1_17_R1")
include(":eco-core:core-nms:v1_18_R1") include(":eco-core:core-nms:v1_18_R1")
include(":eco-core:core-nms:v1_18_R2") include(":eco-core:core-nms:v1_18_R2")
include(":eco-core:core-nms:v1_19_R1")
include(":eco-core:core-proxy") include(":eco-core:core-proxy")
include(":eco-core:core-plugin") include(":eco-core:core-plugin")
include(":eco-core:core-backend") include(":eco-core:core-backend")