Compare commits

...

216 Commits
1.0.1 ... 5.0.0

Author SHA1 Message Date
Auxilor
fd87683b6a Fixed display 2021-04-04 16:48:33 +01:00
Auxilor
83da1e7b95 Fixed ShapedCraftingRecipe 2021-04-04 16:34:08 +01:00
Auxilor
9f9515675a Removed ULands as softdepend 2021-04-04 16:27:43 +01:00
Auxilor
1aa084cd90 Fixed main class 2021-04-04 16:27:24 +01:00
Auxilor
525ec0260f Renamed CustomItems to Items 2021-04-04 15:17:02 +01:00
Auxilor
ac15ffee6c Moved ConfigUpdater into core 2021-04-04 15:09:53 +01:00
Auxilor
83d68c5046 Fixed RunnableTask 2021-04-04 15:03:26 +01:00
Auxilor
7d1186811f Cleaned up util initialization 2021-04-04 14:53:40 +01:00
Auxilor
88bc01e5df Refactored shaped recipes 2021-04-04 14:45:17 +01:00
Auxilor
78d2459c7a Changed dependencies 2021-04-04 13:58:40 +01:00
Auxilor
21f4bd79eb Changed TeamUtils teams 2021-04-04 13:50:17 +01:00
Auxilor
64147c6261 Refactoring 2021-04-04 13:45:13 +01:00
Auxilor
c67c486f2f Registered custom logger 2021-04-04 13:31:07 +01:00
Auxilor
ae419bacb3 Refactored Config and Lang into ConfigYml and LangYml 2021-04-04 13:30:27 +01:00
Auxilor
17b0214f2f Added <#ffffff> hex pattern 2021-04-04 13:23:18 +01:00
Auxilor
963f706018 Added more gradient and hex patterns 2021-04-04 13:22:05 +01:00
Auxilor
74398cda62 Removed hardcoded author in PAPI integration 2021-04-04 13:15:23 +01:00
Auxilor
8321af5af2 Renamed RecipePart into CustomItem system 2021-04-03 20:13:34 +01:00
Auxilor
2524d86462 Removed unneeded fully qualified name 2021-04-03 19:57:43 +01:00
Auxilor
e050bf83df Removed 1.15 support 2021-04-03 19:57:27 +01:00
Auxilor
91c936a06f ArrowDataListener now sends the whole ItemStack 2021-04-03 19:53:48 +01:00
Auxilor
93dfd44410 Removed broken ULands integration 2021-04-03 16:37:02 +01:00
Auxilor
304d0cdebf Updated spigot api to 1.16.5 2021-04-03 16:34:49 +01:00
Auxilor
108d878939 Refactored internal/util into internal/core/util 2021-04-03 16:34:19 +01:00
Auxilor
e10e327c56 Updated v1_16_R3 to spigot 1.16.5 2021-04-03 15:28:27 +01:00
Auxilor
cabea9fba9 Added fast sin and cos functions 2021-04-03 15:22:00 +01:00
Auxilor
f9159cf245 Added setters to config 2021-04-03 14:26:27 +01:00
Auxilor
2db011ae10 Refactoring and removed serialization system 2021-04-03 14:19:11 +01:00
Auxilor
f96716966d Removed deprecated DisplayModule method 2021-04-03 14:01:47 +01:00
Auxilor
7515efbde9 Added CraftItemStack check to FastItemStackHandler 2021-04-03 13:57:28 +01:00
Auxilor
4ebd0d79d5 Updated to 5.0.0 2021-04-03 13:26:34 +01:00
Auxilor
0c3b5d3c30 Began implementing FastItemStack 2021-04-03 12:32:39 +01:00
Auxilor
e0b06dedff Continued refactor 2021-04-03 11:01:47 +01:00
Auxilor
187ac8163d Merge branch 'master' into develop
# Conflicts:
#	eco-api/src/main/java/com/willfp/eco/internal/config/AbstractConfig.java
#	eco-api/src/main/java/com/willfp/eco/internal/config/ConfigSection.java
#	eco-api/src/main/java/com/willfp/eco/internal/config/ConfigWrapper.java
#	eco-api/src/main/java/com/willfp/eco/util/SerializationUtils.java
#	eco-api/src/main/java/com/willfp/eco/util/config/Config.java
#	eco-api/src/main/java/com/willfp/eco/util/config/StaticOptionalConfig.java
#	eco-api/src/main/java/com/willfp/eco/util/serialization/Deserializer.java
#	eco-api/src/main/java/com/willfp/eco/util/serialization/EcoSerializable.java
#	eco-api/src/main/java/com/willfp/eco/util/serialization/NoRegisteredDeserializerException.java
2021-04-03 10:49:02 +01:00
Auxilor
ac2078957d Began refactor 2021-04-03 10:48:31 +01:00
Auxilor
352d495301 Renamed eco-util to eco-api 2021-04-03 10:22:01 +01:00
Auxilor
864456e61e Updated to 4.3.1 2021-04-02 12:36:45 +01:00
Auxilor
bd7ce1cf3c Fixed error with plugins using deprecated getter 2021-04-02 12:36:32 +01:00
Auxilor
9565ab0641 Fixed StaticOptionalConfig 2021-04-02 12:26:56 +01:00
Auxilor
45c53b96dc Updated to 4.3.0 2021-04-02 12:24:49 +01:00
Auxilor
861325ac3f Added serialization system 2021-04-02 12:24:38 +01:00
Auxilor
70c015c1f0 Updated to 4.2.9 2021-03-29 20:15:58 +01:00
Auxilor
8f3755b130 Fixed NCP integration 2021-03-29 20:15:45 +01:00
Auxilor
697ff0ccbb Updated to 4.2.8 2021-03-29 08:54:46 +01:00
Auxilor
f117847fc3 Fixed towny again 2021-03-29 08:54:36 +01:00
Auxilor
bd88d40309 Updated to 4.2.7 2021-03-28 21:39:44 +01:00
Auxilor
2fd8aab230 Fixed towny integration 2021-03-28 21:39:15 +01:00
Auxilor
5ec10ec617 Fixed ComabatLogX integration 2021-03-27 19:57:43 +00:00
Auxilor
270270d015 Added support for CombatLogX NewbieHelper and UltimateLands 2021-03-27 19:53:51 +00:00
Auxilor
3364b01c9d Added combatlogx integration 2021-03-27 19:37:30 +00:00
Auxilor
4beda35adf Updated to 4.2.6 2021-03-27 19:16:34 +00:00
Auxilor
fd3e79378b Fixed display occuring twice 2021-03-27 19:15:51 +00:00
Auxilor
4d0068e551 Fixed varargs breaking plugins using new display system 2021-03-27 19:15:40 +00:00
Auxilor
6933c0e5ef Added backend for future dependencies 2021-03-27 19:15:07 +00:00
Auxilor
839b3724e7 Updated to 4.2.5 2021-03-24 18:31:57 +00:00
Auxilor
6006865358 Merge remote-tracking branch 'origin/master' into master 2021-03-24 18:30:46 +00:00
Auxilor
4907b4b6e6 Updated to 4.2.4 2021-03-24 18:30:31 +00:00
Auxilor
29735cdf83 Fixed mcMMO Integration when running an old version 2021-03-24 18:30:08 +00:00
Auxilor
ae4b2ce0d0 Updated to 4.2.4 2021-03-21 16:26:06 +00:00
Auxilor
786cbbcd7d Added CMI hex code support 2021-03-21 16:21:50 +00:00
Auxilor
6d3f2fc5dc Improved consistency of config list getters 2021-03-18 18:55:50 +00:00
Auxilor
6697cc412e Updated to 4.2.3 2021-03-12 22:33:19 +00:00
Auxilor
17a877a89a Merge remote-tracking branch 'origin/master' into master 2021-03-12 22:32:36 +00:00
Auxilor
9d4149c58f Switched illusioner with ecobosses 2021-03-12 22:32:26 +00:00
Auxilor
123ac79918 Updated to 4.2.2 2021-03-06 18:03:50 +00:00
Auxilor
1670c8b3fb Merge pull request #5 from PaulBGD/master 2021-03-06 17:15:42 +00:00
Paul Sauve
6125044e4c Do less work with displaying items 2021-03-06 11:07:18 -06:00
Auxilor
492439470c Updated to 4.2.1 2021-02-26 10:12:33 +00:00
Auxilor
e9e39345ed Reworked finalize system 2021-02-26 10:12:22 +00:00
Auxilor
cf29df7bce Updated to 4.2.0 2021-02-25 17:56:03 +00:00
Auxilor
c259cb5a45 Changed display to allow varargs 2021-02-25 17:55:49 +00:00
Auxilor
4148f55bb5 Updated to 4.1.3 2021-02-25 17:20:32 +00:00
Auxilor
b63791c14b Prevented overriding getPluginName() metod 2021-02-25 17:20:20 +00:00
Auxilor
294dfabd54 Removed duplicate display modules 2021-02-25 17:20:01 +00:00
Auxilor
d7f7cad863 Updated to 4.1.2 2021-02-23 18:53:53 +00:00
Auxilor
afd8df5b48 Fixed WorldGuard integration 2021-02-23 18:53:38 +00:00
Auxilor
b9d1f36604 Getters breaking 2021-02-18 15:02:48 +00:00
Auxilor
403a7a7da8 Fixed Configs again 2021-02-18 14:57:36 +00:00
Auxilor
f6fb5bcf66 Updated to 4.1.1 2021-02-18 14:55:22 +00:00
Auxilor
194eb8b5f5 Fixed configs 2021-02-18 14:55:07 +00:00
Auxilor
853aaca071 Updated to 4.1.0 2021-02-18 14:26:48 +00:00
Auxilor
18dabd6bcf Added StaticOptionalConfig 2021-02-18 14:26:37 +00:00
Auxilor
bb42505d66 Hopeful fix 2021-02-17 16:07:08 +00:00
Auxilor
b4d59077e3 Fixed load order again 2021-02-17 15:55:39 +00:00
Auxilor
104d55c11b Changed load order again 2021-02-17 15:49:51 +00:00
Auxilor
b5af17cf08 Changed load order 2021-02-17 15:45:33 +00:00
Auxilor
78ae662ced Fixed RecipeParts 2021-02-17 15:20:39 +00:00
Auxilor
32e48db3ce Removed @Nullable because it's annoying 2021-02-17 15:02:52 +00:00
Auxilor
8a27e75c02 Fixed EcoPlugin 2021-02-17 14:55:34 +00:00
Auxilor
bf55e9b189 Constructor change 2021-02-17 14:54:28 +00:00
Auxilor
bfbaa3d033 Removed redundant check 2021-02-17 14:42:03 +00:00
Auxilor
64f87d5741 Cleaned up recipes 2021-02-17 13:54:02 +00:00
Auxilor
cb3441286c Removed redundant Registerable interface 2021-02-17 13:39:32 +00:00
Auxilor
5e97a0f894 Refactored ArrowDataListener 2021-02-17 13:35:32 +00:00
Auxilor
de2166dfdb Reworked tuples 2021-02-17 13:33:57 +00:00
Auxilor
abd361f4b5 Refactored config internals 2021-02-17 13:30:06 +00:00
Auxilor
422f8ead23 Removed RecipeListener from api 2021-02-17 13:27:28 +00:00
Auxilor
7c05dd7457 Reworked recipes 2021-02-17 13:20:34 +00:00
Auxilor
3ef7622c6f Updated to 4.0.0 2021-02-17 12:50:16 +00:00
Auxilor
8207d62b1f Reworked display system. 2021-02-17 12:50:01 +00:00
Auxilor
75a0b1dd0d Added @Internal annotations 2021-02-17 12:05:14 +00:00
Auxilor
d1307e35db Minor code issues 2021-02-16 19:48:20 +00:00
Auxilor
0a6b197a97 Cleaned various internals 2021-02-16 19:44:34 +00:00
Auxilor
8d6512886c Removed redundant PluginDependentFactory.java 2021-02-16 19:37:55 +00:00
Auxilor
5c0c0f3e2a Refactored Scheduler.java 2021-02-16 19:35:55 +00:00
Auxilor
e2c2fc776a Moved break blocks into block utils 2021-02-16 19:34:26 +00:00
Auxilor
576050b31e Updated to 3.8.0 2021-02-16 19:22:20 +00:00
Auxilor
f9a43bd336 Added trident util initializatoin 2021-02-16 19:17:59 +00:00
Auxilor
203f2f599a Added trident utils 2021-02-16 19:16:48 +00:00
Auxilor
baa5d37744 Added PlayerUtils 2021-02-16 19:11:02 +00:00
Auxilor
17f6af2a70 Added Skull texture setter 2021-02-16 18:07:47 +00:00
Auxilor
eae213f58e More refactoring, splitting api and internal 2021-02-14 16:31:16 +00:00
Auxilor
3a6a133560 Added caching to AbstractConfig 2021-02-14 15:32:10 +00:00
Auxilor
57cf144c57 Refactoring to remove internal components from API 2021-02-14 15:23:42 +00:00
Auxilor
5c29859d49 Updated to 3.7.0 2021-02-10 10:50:46 +00:00
Auxilor
02510127d1 Added getParts to EcoShapedRecipe 2021-02-10 10:50:31 +00:00
Auxilor
f6b5c8f7e0 Updated to eco 3.6.1 2021-02-09 09:30:29 +00:00
Auxilor
dbfef3094b Fixed villager trade being finalized 2021-02-09 09:30:08 +00:00
Auxilor
b5c3af752c Fixed bugs with new config system 2021-02-07 20:18:00 +00:00
Auxilor
d0366b39e2 Updated to 3.6.0 2021-02-07 20:03:46 +00:00
Auxilor
ed5390d2b5 Reworked config system (again) 2021-02-07 20:03:31 +00:00
Auxilor
e31857a15d Merge remote-tracking branch 'origin/master' into master
# Conflicts:
#	gradle.properties
2021-02-07 19:29:52 +00:00
Auxilor
32e119d187 Updated to 3.5.0 2021-02-07 19:29:32 +00:00
Auxilor
5690eccd14 Refactored config system and added update blacklist 2021-02-07 19:29:05 +00:00
Auxilor
2faf3732df Updated to 3.4.4 2021-02-07 15:00:52 +00:00
Auxilor
8670fb36e0 Changed ItemStats to StatTrackers 2021-02-07 15:00:36 +00:00
Auxilor
7c001c4809 Updated to 3.4.3 2021-02-03 09:14:20 +00:00
Auxilor
bce1dd9fee Fixed finalize issues 2021-02-03 09:13:45 +00:00
Auxilor
412c2e1e3c Updated to 3.4.2 2021-02-01 16:04:28 +00:00
Auxilor
dd7ffac974 Cleaned up DurabilityUtils and added edge case 2021-02-01 16:04:17 +00:00
Auxilor
7ad59e0166 Updated to 3.4.1 2021-02-01 08:54:30 +00:00
Auxilor
2f2bdbb9f5 Prevented dropping empty dropqueue or air 2021-02-01 08:54:17 +00:00
Auxilor
d23dc10bc5 Improved finalization (again) 2021-01-30 14:48:14 +00:00
Auxilor
46c2e3f90a Updated to 3.4.0 2021-01-30 14:31:51 +00:00
Auxilor
1776b668a4 Improved Display system 2021-01-30 14:31:31 +00:00
Auxilor
10dccd0f38 Updated to 3.3.3 2021-01-28 13:13:21 +00:00
Auxilor
f1918eb1ec Stopped removing final modifier on villager trades 2021-01-28 13:13:02 +00:00
Auxilor
436b33fde2 Fixed lands 2021-01-27 10:33:08 +00:00
Auxilor
cfa5cab1fa Updated to 3.3.2 2021-01-27 10:28:02 +00:00
Auxilor
a8ba4dd812 Updated KingdomsX integration 2021-01-27 10:27:44 +00:00
Auxilor
94bf383d23 Added setType to DropManager 2021-01-27 09:56:23 +00:00
Auxilor
096207de82 Fixed EcoEventManager javadoc 2021-01-27 09:36:03 +00:00
Auxilor
3cb654f5df Refactored integration packages on the backend 2021-01-27 09:34:04 +00:00
Auxilor
5552cc4fb0 Updated to 3.3.1 2021-01-27 08:34:31 +00:00
Auxilor
94aacf8cca Changed AntigriefKingdoms integration 2021-01-27 08:34:19 +00:00
Auxilor
128d473b33 Added direct mcMMO support 2021-01-24 16:04:40 +00:00
Auxilor
d5679dd58f Downgraded back to 3.2.2 2021-01-23 19:45:44 +00:00
Auxilor
b1e8165ecb Removed ReflectionUtils.java 2021-01-23 19:44:40 +00:00
Auxilor
d0a3d644f3 Updated to 3.3.0 2021-01-23 19:38:23 +00:00
Auxilor
35b060af53 Added ReflectionUtils to use Unsafe to set final fields 2021-01-23 19:38:06 +00:00
Auxilor
337dba23b4 Removed PacketPlayOutRecipeUpdateFix 2021-01-22 19:45:29 +00:00
Auxilor
433f9f53ab Revert "Revert "Changed the fix for PacketPlayOutRecipeUpdateFix""
This reverts commit 1365fdae
2021-01-22 19:29:46 +00:00
Auxilor
ba7a748efd Re-fixed the rework of the fix of the changed fix of the fix 2021-01-22 19:29:11 +00:00
Auxilor
1365fdae88 Revert "Changed the fix for PacketPlayOutRecipeUpdateFix"
This reverts commit 876343fa
2021-01-22 17:53:36 +00:00
Auxilor
6a159bf049 Changed PacketPlayOutRecipeUpdateFix 2021-01-22 10:29:05 +00:00
Auxilor
31e0e93951 Updated to 3.2.1 2021-01-21 08:38:38 +00:00
Auxilor
876343facb Changed the fix for PacketPlayOutRecipeUpdateFix 2021-01-21 08:38:28 +00:00
Auxilor
f0cd9ae16d Updated to 3.2.0 2021-01-20 20:13:09 +00:00
Auxilor
b220428b8c Added StaticBaseConfig, a non-updating config implementation 2021-01-20 20:12:53 +00:00
Auxilor
8386aacfd8 Updated to 3.1.3 2021-01-20 19:06:07 +00:00
Auxilor
3c54e24102 Reworked gradients 2021-01-20 19:05:55 +00:00
Auxilor
3dc0693b8c Reworked gradients 2021-01-20 18:47:56 +00:00
Auxilor
f087113ddf Updated to 3.1.2 2021-01-20 17:38:51 +00:00
Auxilor
d5d1f5d8cc Added fix for PacketPlayOutRecipeUpdate being too large 2021-01-20 17:35:29 +00:00
Auxilor
0d5bf901e2 Updated to 3.1.1 2021-01-20 11:27:57 +00:00
Auxilor
ae0445f47b Fixed recipe listener registration 2021-01-20 11:27:46 +00:00
Auxilor
a6ba24b7a5 Added auto version 2021-01-19 17:39:25 +00:00
Auxilor
1b00831147 Prevented duplicate module registration 2021-01-19 17:38:36 +00:00
Auxilor
479cff60d5 Fixed list emptiness java 2021-01-19 17:30:01 +00:00
Auxilor
d2499b1e27 Fixed artifact id name 2021-01-19 17:10:45 +00:00
Auxilor
4f65f33953 Reworked project structure 2021-01-19 17:02:04 +00:00
Auxilor
6d4a69c781 Removed debug message 2021-01-19 14:30:39 +00:00
Auxilor
e90e58b50a Moved event listeners 2021-01-19 14:29:09 +00:00
Auxilor
826bdb63d0 Removed pointless bukkit services 2021-01-19 14:07:48 +00:00
Auxilor
4ecba69161 Updated to 3.0.3 2021-01-19 13:59:21 +00:00
Auxilor
e64510ebf5 Fixed FastCollatedDropQueueRunnable 2021-01-19 13:58:57 +00:00
Auxilor
50a506af62 Added gradient support 2021-01-19 11:36:47 +00:00
Auxilor
bdbbb7e40a Added redundant config.yml and lang.yml 2021-01-18 09:50:24 +00:00
Auxilor
f2503e989c Made eco an AbstractEcoPlugin and updated to 3.0.1 2021-01-18 09:48:36 +00:00
Auxilor
11c54a0055 Finally fixed proxies 2021-01-17 15:52:40 +00:00
Auxilor
7cc24199fb Kept trying to fix proxy error. 2021-01-17 15:01:01 +00:00
Auxilor
068b2cca0c Removed getInstance method 2021-01-17 14:22:29 +00:00
Auxilor
f67f01278e Moved cached proxies into cached factories 2021-01-17 13:35:53 +00:00
Auxilor
8be8e1dab2 Fixed DropManager updatable 2021-01-17 12:45:08 +00:00
Auxilor
6d3651aca1 Fixed fields 2021-01-17 12:42:37 +00:00
Auxilor
3dd2c58595 Added loadbefore 2021-01-17 12:40:02 +00:00
Auxilor
255aa1dd54 Re-added RecipePartUtils 2021-01-17 11:51:48 +00:00
Auxilor
f2c5b085e8 Removed all getInstance calls 2021-01-17 11:37:58 +00:00
Auxilor
b8a5fe0031 Fixed EcoShapedRecipe 2021-01-17 10:48:55 +00:00
Auxilor
5603890663 Reworked eco to be a spigot plugin 2021-01-17 10:48:34 +00:00
Auxilor
1a86cc4dbd Fixed shading errors. 2021-01-14 20:06:27 +00:00
Auxilor
734add6dbc Cleaned 2021-01-14 19:25:21 +00:00
Auxilor
5641c0def3 Updated to 1.3.1 2021-01-14 19:24:37 +00:00
Auxilor
b74ab5349a Fixed shading issues 2021-01-14 19:24:13 +00:00
Auxilor
b0971e5124 Renamed LookupUtils to RecipePartUtils 2021-01-14 14:06:50 +00:00
Auxilor
02d8c8c6b6 Updated to 1.3.0 2021-01-14 13:06:32 +00:00
Auxilor
d9bd5257e3 Added custom item registry 2021-01-14 13:06:03 +00:00
Auxilor
c1a214f34e Fixed crafting 2021-01-14 11:31:05 +00:00
Auxilor
64d1fbb9b1 Updated to 1.2.0 2021-01-14 10:57:23 +00:00
Auxilor
a5433fbb3f Added recipe system 2021-01-14 10:55:44 +00:00
Auxilor
2a2aed52e0 Optimised VectorUtils getCircle() 2021-01-12 14:52:36 +00:00
Auxilor
b16266e22a Cleaned up numerals 2021-01-10 20:05:50 +00:00
Auxilor
2c886dc33b Updated to 1.1.2 2021-01-10 18:51:37 +00:00
Auxilor
db9c60cf35 Added fromNumeral method 2021-01-10 18:51:21 +00:00
Auxilor
a34b36daec Updated to 1.1.1 2021-01-08 22:18:17 +00:00
Auxilor
41a35e99fd Call update is now invoked twice 2021-01-08 22:18:00 +00:00
Auxilor
8e12dad247 Added players to packet adapters 2021-01-08 08:02:15 +00:00
Auxilor
72afa1e5cc Updated to 1.1.0 2021-01-08 08:01:21 +00:00
Auxilor
9904553325 Updated to 1.0.6 2021-01-05 14:17:41 +00:00
Auxilor
ad069ab32f Cleaned up loader 2021-01-05 14:17:26 +00:00
Auxilor
b83a3dd548 Fixed TelekinesisUtils and updated to 1.0.5 2021-01-05 09:09:05 +00:00
Auxilor
7f41eab5e4 Fixed compileOnly issues with jitpack 2021-01-04 12:46:00 +00:00
Auxilor
0d1c2364da Fixed telekinesistests registration and updated to 1.0.4 2021-01-04 12:45:05 +00:00
Auxilor
5bca33a9f5 Added protected getter for BaseConfig and updated to 1.0.3 2021-01-02 17:55:22 +00:00
Auxilor
1196fe8004 Updated to 1.0.2 2021-01-01 16:54:05 +00:00
Auxilor
98ae416fa7 Reduced loaded integration verbosity 2021-01-01 16:53:32 +00:00
184 changed files with 5276 additions and 1987 deletions

2
.gitignore vendored
View File

@@ -14,7 +14,7 @@ bin/
# Gradle
.gradle
**/build/
!src/**/build/
!eco-api/src/**/build/
.gradletasknamecache
!gradle-wrapper.jar
gradle-app.setting

View File

@@ -6,97 +6,94 @@ plugins {
}
dependencies {
implementation 'org.apache.maven:maven-artifact:3.0.3'
implementation 'org.bstats:bstats-bukkit:1.7'
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
compileOnly 'me.clip:placeholderapi:2.10.9'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
compileOnly 'com.github.TechFortress:GriefPrevention:16.14.0'
compileOnly 'com.massivecraft:Factions:1.6.9.5-U0.5.10'
compileOnly 'com.github.cryptomorin:kingdoms:1.10.3.1'
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
compileOnly 'com.github.angeschossen:LandsAPI:4.7.3'
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
compileOnly 'org.jetbrains:annotations:19.0.0'
compileOnly fileTree(dir: '/lib', include: ['*.jar'])
// Lombok
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testCompileOnly 'org.projectlombok:lombok:1.18.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
implementation project(":eco-api")
implementation project(":eco-core").getSubprojects()
}
allprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
mavenCentral()
jcenter()
mavenLocal()
maven { url 'https://jitpack.io' }
repositories {
mavenCentral()
jcenter()
mavenLocal()
maven { url 'https://jitpack.io' }
// NMS (for jitpack compilation)
maven { url 'https://repo.codemc.org/repository/nms/' }
// NMS (for jitpack compilation)
maven { url 'https://repo.codemc.org/repository/nms/' }
// bStats
maven { url 'https://repo.codemc.org/repository/maven-public' }
// bStats, mcMMO
maven { url 'https://repo.codemc.org/repository/maven-public' }
// Spigot API
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
// Spigot API
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
// PlaceholderAPI
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
// PlaceholderAPI
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
// ProtocolLib
maven { url 'https://repo.dmulloy2.net/nexus/repository/public/' }
// ProtocolLib
maven { url 'https://repo.dmulloy2.net/nexus/repository/public/' }
// WorldGuard
maven { url 'https://maven.enginehub.org/repo/' }
// WorldGuard
maven { url 'https://maven.enginehub.org/repo/' }
// FactionsUUID
maven { url 'https://ci.ender.zone/plugin/repository/everything/' }
// FactionsUUID
maven { url 'https://ci.ender.zone/plugin/repository/everything/' }
// NoCheatPlus
maven { url 'https://repo.md-5.net/content/repositories/snapshots/' }
}
// NoCheatPlus
maven { url 'https://repo.md-5.net/content/repositories/snapshots/' }
tasks.withType(JavaCompile) {
options.deprecation = true
options.encoding = 'UTF-8'
}
configurations.all {
exclude group: "org.codehaus.plexus", module: "plexus-utils"
exclude group: "com.mojang", module: "brigadier"
exclude group: "org.kitteh", module: "paste-gg-api"
exclude group: "org.spongepowered", module: "configurate-hocon"
exclude group: "com.darkblade12", module: "particleeffect"
}
shadowJar {
relocate('org.bstats.bukkit', 'com.willfp.eco.util.shaded.bstats')
relocate('org.apache.maven', 'com.willfp.eco.util.shaded.maven')
}
publishing {
publications {
shadow(MavenPublication) {
from components.java
artifact shadowJar
}
// CombatLogX
maven { url 'https://nexus.sirblobman.xyz/repository/public/' }
}
dependencies {
compileOnly 'org.jetbrains:annotations:19.0.0'
// Lombok
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testCompileOnly 'org.projectlombok:lombok:1.18.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
}
tasks.withType(JavaCompile) {
options.deprecation = true
options.encoding = 'UTF-8'
}
configurations.all {
exclude group: "org.codehaus.plexus", module: "plexus-utils"
exclude group: "com.mojang", module: "brigadier"
exclude group: "org.kitteh", module: "paste-gg-api"
exclude group: "org.spongepowered", module: "configurate-hocon"
exclude group: "com.darkblade12", module: "particleeffect"
exclude group: "com.github.cryptomorin", module: "XSeries"
}
shadowJar {
relocate('org.bstats.bukkit', 'com.willfp.eco.shaded.bstats')
relocate('org.apache.maven', 'com.willfp.eco.shaded.maven')
}
jar {
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
}
compileJava {
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
}
compileJava.options.encoding = 'UTF-8'
compileJava.dependsOn clean
build.dependsOn shadowJar
}
compileJava.options.encoding = 'UTF-8'
compileJava.dependsOn clean
publishToMavenLocal.dependsOn shadowJar
build.dependsOn shadowJar
build.dependsOn publishToMavenLocal
group = 'com.willfp'
archivesBaseName = project.name
version = '1.0.1'
version = findProperty("version")
java.sourceCompatibility = JavaVersion.VERSION_1_8

View File

@@ -115,7 +115,6 @@
<!-- Checks for imports -->
<!-- See https://checkstyle.org/config_imports.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>

View File

@@ -5,6 +5,10 @@
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<!-- Internals don't need javadoc. -->
<suppress files="[\\/]internal[\\/]" checks="MissingJavadocMethod"/>
<suppress files="[\\/]internal[\\/]" checks="JavadocVariable"/>
<!-- Modified version of library -->
<suppress files="ArmorEquipEvent.java" checks="JavadocVariable"/>
<suppress files="ArmorEquipEvent.java" checks="MissingJavadocMethod"/>

25
eco-api/build.gradle Normal file
View File

@@ -0,0 +1,25 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT'
compileOnly 'org.apache.maven:maven-artifact:3.0.3'
compileOnly 'org.bstats:bstats-bukkit:1.7'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
compileOnly 'me.clip:placeholderapi:2.10.9'
}
compileJava.options.encoding = 'UTF-8'
compileJava.dependsOn clean
build.dependsOn publishToMavenLocal
publishing {
publications {
shadow(MavenPublication) {
from components.java
artifact shadowJar
artifactId 'eco'
}
}
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.protocollib;
package com.willfp.eco.core;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
@@ -6,8 +6,8 @@ import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
@@ -34,7 +34,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
* @param priority The priority at which the adapter should be ran on packet send/receive.
* @param postLoad If the packet adapter should be registered after the server has loaded.
*/
protected AbstractPacketAdapter(@NotNull final AbstractEcoPlugin plugin,
protected AbstractPacketAdapter(@NotNull final EcoPlugin plugin,
@NotNull final PacketType type,
@NotNull final ListenerPriority priority,
final boolean postLoad) {
@@ -50,7 +50,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
* @param type The {@link PacketType} to listen for.
* @param postLoad If the packet adapter should be registered after the server has loaded.
*/
protected AbstractPacketAdapter(@NotNull final AbstractEcoPlugin plugin,
protected AbstractPacketAdapter(@NotNull final EcoPlugin plugin,
@NotNull final PacketType type,
final boolean postLoad) {
this(plugin, type, ListenerPriority.NORMAL, postLoad);
@@ -60,8 +60,10 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
* The code that should be executed once the packet has been received.
*
* @param packet The packet.
* @param player The player.
*/
public void onReceive(@NotNull final PacketContainer packet) {
public void onReceive(@NotNull final PacketContainer packet,
@NotNull final Player player) {
// Empty rather than abstract as implementations don't need both
}
@@ -69,8 +71,10 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
* THe code that should be executed once the packet has been sent.
*
* @param packet The packet.
* @param player The player.
*/
public void onSend(@NotNull final PacketContainer packet) {
public void onSend(@NotNull final PacketContainer packet,
@NotNull final Player player) {
// Empty rather than abstract as implementations don't need both
}
@@ -89,7 +93,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
return;
}
onReceive(event.getPacket());
onReceive(event.getPacket(), event.getPlayer());
}
/**
@@ -107,7 +111,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
return;
}
onSend(event.getPacket());
onSend(event.getPacket(), event.getPlayer());
}
/**

View File

@@ -0,0 +1,416 @@
package com.willfp.eco.core;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.config.base.ConfigYml;
import com.willfp.eco.core.config.base.LangYml;
import com.willfp.eco.internal.config.updating.ConfigHandler;
import com.willfp.eco.core.display.Display;
import com.willfp.eco.core.display.DisplayModule;
import com.willfp.eco.core.events.EventManager;
import com.willfp.eco.core.extensions.ExtensionLoader;
import com.willfp.eco.core.factory.MetadataValueFactory;
import com.willfp.eco.core.factory.NamespacedKeyFactory;
import com.willfp.eco.core.factory.RunnableFactory;
import com.willfp.eco.core.integrations.IntegrationLoader;
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
import com.willfp.eco.core.scheduling.Scheduler;
import com.willfp.eco.internal.UpdateChecker;
import com.willfp.eco.internal.arrows.ArrowDataListener;
import com.willfp.eco.internal.events.EcoEventManager;
import com.willfp.eco.internal.extensions.EcoExtensionLoader;
import com.willfp.eco.internal.factory.EcoMetadataValueFactory;
import com.willfp.eco.internal.factory.EcoNamespacedKeyFactory;
import com.willfp.eco.internal.factory.EcoRunnableFactory;
import com.willfp.eco.internal.integrations.PlaceholderIntegrationPAPI;
import com.willfp.eco.internal.logging.EcoLogger;
import com.willfp.eco.internal.scheduling.EcoScheduler;
import lombok.Getter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public abstract class EcoPlugin extends JavaPlugin {
/**
* Loaded eco plugins.
*/
public static final List<String> LOADED_ECO_PLUGINS = new ArrayList<>();
/**
* The name of the plugin.
*/
@Getter
private final String pluginName;
/**
* The spigot resource ID of the plugin.
*/
@Getter
private final int resourceId;
/**
* The bStats resource ID of the plugin.
*/
@Getter
private final int bStatsId;
/**
* The package where proxy implementations are.
*/
@Getter
private final String proxyPackage;
/**
* The color of the plugin, used in messages.
*/
@Getter
private final String color;
/**
* Loaded integrations.
*/
@Getter
private final Set<String> loadedIntegrations = new HashSet<>();
/**
* Set of classes to be processed on config update.
*/
private final List<Class<?>> updatableClasses = new ArrayList<>();
/**
* The internal plugin scheduler.
*/
@Getter
private final Scheduler scheduler;
/**
* The internal plugin Event Manager.
*/
@Getter
private final EventManager eventManager;
/**
* Config.yml.
*/
@Getter
private final ConfigYml configYml;
/**
* Lang.yml.
*/
@Getter
private final LangYml langYml;
/**
* The internal factory to produce {@link org.bukkit.NamespacedKey}s.
*/
@Getter
private final NamespacedKeyFactory namespacedKeyFactory;
/**
* The internal factory to produce {@link org.bukkit.metadata.FixedMetadataValue}s.
*/
@Getter
private final MetadataValueFactory metadataValueFactory;
/**
* The internal factory to produce {@link com.willfp.eco.core.scheduling.RunnableTask}s.
*/
@Getter
private final RunnableFactory runnableFactory;
/**
* The loader for all plugin extensions.
*
* @see com.willfp.eco.core.extensions.Extension
*/
@Getter
private final ExtensionLoader extensionLoader;
/**
* The handler class for updatable classes.
*/
@Getter
private final ConfigHandler configHandler;
/**
* The display module for the plugin.
*/
@Getter
private DisplayModule displayModule;
/**
* The logger for the plugin.
*/
private final Logger logger;
/**
* If the server is running an outdated version of the plugin.
*/
@Getter
private boolean outdated = false;
/**
* Create a new plugin.
*
* @param pluginName The name of the plugin.
* @param resourceId The spigot resource ID for the plugin.
* @param bStatsId The bStats resource ID for the plugin.
* @param proxyPackage The package where proxy implementations are stored.
* @param color The color of the plugin (used in messages, such as &a, &b)
*/
protected EcoPlugin(@NotNull final String pluginName,
final int resourceId,
final int bStatsId,
@NotNull final String proxyPackage,
@NotNull final String color) {
this.pluginName = pluginName;
this.resourceId = resourceId;
this.bStatsId = bStatsId;
this.proxyPackage = proxyPackage;
this.color = color;
this.scheduler = new EcoScheduler(this);
this.eventManager = new EcoEventManager(this);
this.namespacedKeyFactory = new EcoNamespacedKeyFactory(this);
this.metadataValueFactory = new EcoMetadataValueFactory(this);
this.runnableFactory = new EcoRunnableFactory(this);
this.extensionLoader = new EcoExtensionLoader(this);
this.configHandler = new ConfigHandler(this);
this.logger = new EcoLogger(this);
this.langYml = new LangYml(this);
this.configYml = new ConfigYml(this);
LOADED_ECO_PLUGINS.add(this.getName().toLowerCase());
}
/**
* Default code to be executed on plugin enable.
*/
@Override
public final void onEnable() {
super.onEnable();
this.getLogger().info("");
this.getLogger().info("Loading " + this.color + this.pluginName);
this.getEventManager().registerListener(new ArrowDataListener(this));
new UpdateChecker(this).getVersion(version -> {
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion());
DefaultArtifactVersion mostRecentVersion = new DefaultArtifactVersion(version);
if (!(currentVersion.compareTo(mostRecentVersion) > 0 || currentVersion.equals(mostRecentVersion))) {
this.outdated = true;
this.getScheduler().runTimer(() -> {
this.getLogger().info("&c " + this.pluginName + " is out of date! (Version " + this.getDescription().getVersion() + ")");
this.getLogger().info("&cThe newest version is &f" + version);
this.getLogger().info("&cDownload the new version!");
}, 0, 864000);
}
});
new Metrics(this, this.bStatsId);
Set<String> enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet());
if (enabledPlugins.contains("PlaceholderAPI")) {
this.loadedIntegrations.add("PlaceholderAPI");
PlaceholderManager.addIntegration(new PlaceholderIntegrationPAPI(this));
}
this.getIntegrationLoaders().forEach((integrationLoader -> {
if (enabledPlugins.contains(integrationLoader.getPluginName())) {
this.loadedIntegrations.add(integrationLoader.getPluginName());
integrationLoader.load();
}
}));
this.getLogger().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));
Prerequisite.update();
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
if (!abstractPacketAdapter.isPostLoad()) {
abstractPacketAdapter.register();
}
});
updatableClasses.addAll(this.getUpdatableClasses());
this.getListeners().forEach(listener -> this.getEventManager().registerListener(listener));
this.getCommands().forEach(AbstractCommand::register);
this.getScheduler().runLater(this::afterLoad, 1);
this.updatableClasses.forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz));
this.enable();
this.getLogger().info("");
}
/**
* Default code to be executed on plugin disable.
*/
@Override
public final void onDisable() {
super.onDisable();
this.getEventManager().unregisterAllListeners();
this.getScheduler().cancelAll();
this.disable();
}
/**
* Default code to be executed on plugin load.
*/
@Override
public final void onLoad() {
super.onLoad();
this.load();
}
/**
* Default code to be executed after the server is up.
*/
public final void afterLoad() {
this.displayModule = createDisplayModule();
if (this.getDisplayModule() != null) {
Display.registerDisplayModule(this.getDisplayModule());
}
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
if (abstractPacketAdapter.isPostLoad()) {
abstractPacketAdapter.register();
}
});
if (!Prerequisite.HAS_PAPER.isMet()) {
this.getLogger().severe("");
this.getLogger().severe("----------------------------");
this.getLogger().severe("");
this.getLogger().severe("You don't seem to be running paper!");
this.getLogger().severe("Paper is strongly recommended for all servers,");
this.getLogger().severe("and some things may not function properly without it");
this.getLogger().severe("Download Paper from &fhttps://papermc.io");
this.getLogger().severe("");
this.getLogger().severe("----------------------------");
this.getLogger().severe("");
}
this.postLoad();
this.reload();
this.getLogger().info("Loaded " + this.color + this.pluginName);
}
/**
* Default code to be executed on plugin reload.
*/
public final void reload() {
this.getConfigYml().update();
this.getLangYml().update();
this.getConfigHandler().callUpdate();
this.getConfigHandler().callUpdate(); // Call twice to fix issues
this.getScheduler().cancelAll();
this.onReload();
}
/**
* The plugin-specific code to be executed on enable.
*/
public abstract void enable();
/**
* The plugin-specific code to be executed on disable.
*/
public abstract void disable();
/**
* The plugin-specific code to be executed on load.
*/
public abstract void load();
/**
* The plugin-specific code to be executed on reload.
*/
public abstract void onReload();
/**
* The plugin-specific code to be executed after the server is up.
*/
public abstract void postLoad();
/**
* The plugin-specific integrations to be tested and loaded.
*
* @return A list of integrations.
*/
public abstract List<IntegrationLoader> getIntegrationLoaders();
/**
* The command to be registered.
*
* @return A list of commands.
*/
public abstract List<AbstractCommand> getCommands();
/**
* ProtocolLib packet adapters to be registered.
* <p>
* If the plugin does not require ProtocolLib this can be left empty.
*
* @return A list of packet adapters.
*/
public abstract List<AbstractPacketAdapter> getPacketAdapters();
/**
* All listeners to be registered.
*
* @return A list of all listeners.
*/
public abstract List<Listener> getListeners();
/**
* All updatable classes.
*
* @return A list of all updatable classes.
*/
public abstract List<Class<?>> getUpdatableClasses();
/**
* Create the display module for the plugin.
*
* @return The display module, or null.
*/
@Nullable
protected DisplayModule createDisplayModule() {
return null;
}
@NotNull
@Override
public Logger getLogger() {
return logger;
}
}

View File

@@ -0,0 +1,22 @@
package com.willfp.eco.core;
import lombok.AccessLevel;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public abstract class PluginDependent {
/**
* The {@link EcoPlugin} that is stored.
*/
@Getter(AccessLevel.PROTECTED)
private final EcoPlugin plugin;
/**
* Pass an {@link EcoPlugin} in order to interface with it.
*
* @param plugin The plugin to manage.
*/
protected PluginDependent(@NotNull final EcoPlugin plugin) {
this.plugin = plugin;
}
}

View File

@@ -1,8 +1,7 @@
package com.willfp.eco.util.optional;
package com.willfp.eco.core;
import com.willfp.eco.util.ClassUtils;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -15,15 +14,6 @@ public class Prerequisite {
* All existing prerequisites are registered on creation.
*/
private static final List<Prerequisite> VALUES = new ArrayList<>();
/**
* Requires the server to be running minecraft version 1.16 or higher.
*/
public static final Prerequisite MINIMUM_1_16 = new Prerequisite(
() -> !Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].contains("15"),
"Requires minimum server version of 1.16"
);
/**
* Requires the server to be running an implementation of paper.
*/

View File

@@ -1,9 +1,7 @@
package com.willfp.eco.util.command;
package com.willfp.eco.core.command;
import com.willfp.eco.util.config.Configs;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.interfaces.Registerable;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -16,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
public abstract class AbstractCommand extends PluginDependent implements CommandExecutor, Registerable {
public abstract class AbstractCommand extends PluginDependent implements CommandExecutor {
/**
* The name of the command
* <p>
@@ -45,12 +43,12 @@ public abstract class AbstractCommand extends PluginDependent implements Command
* <p>
* The name cannot be the same as an existing command as this will conflict.
*
* @param plugin The owning {@link AbstractEcoPlugin}.
* @param plugin The owning {@link EcoPlugin}.
* @param name The name used in execution.
* @param permission The permission required to execute the command.
* @param playersOnly If only players should be able to execute this command.
*/
protected AbstractCommand(@NotNull final AbstractEcoPlugin plugin,
protected AbstractCommand(@NotNull final EcoPlugin plugin,
@NotNull final String name,
@NotNull final String permission,
final boolean playersOnly) {
@@ -100,7 +98,7 @@ public abstract class AbstractCommand extends PluginDependent implements Command
* @param command The bukkit command.
* @param label The name of the executed command.
* @param args The arguments of the command (anything after the physical command name)
* @return If the command was processed by the linked {@link AbstractEcoPlugin}
* @return If the command was processed by the linked {@link EcoPlugin}
*/
@Override
public final boolean onCommand(@NotNull final CommandSender sender,
@@ -112,12 +110,12 @@ public abstract class AbstractCommand extends PluginDependent implements Command
}
if (playersOnly && !(sender instanceof Player)) {
sender.sendMessage(Configs.LANG.getMessage("not-player"));
sender.sendMessage(this.getPlugin().getLangYml().getMessage("not-player"));
return true;
}
if (!sender.hasPermission(permission) && sender instanceof Player) {
sender.sendMessage(Configs.LANG.getNoPermission());
sender.sendMessage(this.getPlugin().getLangYml().getNoPermission());
return true;
}
@@ -131,7 +129,6 @@ public abstract class AbstractCommand extends PluginDependent implements Command
* <p>
* Requires the command name to exist, defined in plugin.yml.
*/
@Override
public final void register() {
PluginCommand command = Bukkit.getPluginCommand(name);
assert command != null;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.command;
package com.willfp.eco.core.command;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@@ -0,0 +1,40 @@
package com.willfp.eco.core.config;
import com.willfp.eco.internal.config.UpdatableYamlConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public abstract class BaseConfig extends UpdatableYamlConfig {
/**
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
* <p>
* Automatically updates.
*
* @param configName The name of the config
* @param removeUnused Whether keys not present in the default config should be removed on update.
* @param plugin The plugin.
* @param updateBlacklist Substring of keys to not add/remove keys for.
*/
protected BaseConfig(@NotNull final String configName,
final boolean removeUnused,
@NotNull final EcoPlugin plugin,
@NotNull final String... updateBlacklist) {
super(configName, plugin, "", plugin.getClass(), removeUnused, updateBlacklist);
}
/**
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
* <p>
* Automatically updates.
*
* @param configName The name of the config
* @param removeUnused Whether keys not present in the default config should be removed on update.
* @param plugin The plugin.
*/
protected BaseConfig(@NotNull final String configName,
final boolean removeUnused,
@NotNull final EcoPlugin plugin) {
super(configName, plugin, "", plugin.getClass(), removeUnused, "");
}
}

View File

@@ -0,0 +1,219 @@
package com.willfp.eco.core.config;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public interface Config {
/**
* Clears cache.
*/
void clearCache();
/**
* Get if the config contains a key.
*
* @param path The key to check.
* @return If contained.
*/
boolean has(@NotNull String path);
/**
* Get config keys.
*
* @param deep If keys from subsections should be fetched too.
* @return A list of keys.
*/
@NotNull
List<String> getKeys(boolean deep);
/**
* Get an object from config.
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#get(String)}.
*
* @param path The path.
* @return The object.
*/
@Nullable
Object get(@NotNull String path);
/**
* Set an object in config.
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#set(String, Object)}
*
* @param path The path.
* @param object The object.
*/
void set(@NotNull String path,
@Nullable Object object);
/**
* Get subsection from config.
*
* @param path The key to check.
* @return The subsection. Throws NPE if not found.
*/
@NotNull
Config getSubsection(@NotNull String path);
/**
* Get subsection from config.
*
* @param path The key to check.
* @return The subsection, or null if not found.
*/
@Nullable
Config getSubsectionOrNull(@NotNull String path);
/**
* Get an integer from config.
*
* @param path The key to fetch the value from.
* @return The found value, or 0 if not found.
*/
int getInt(@NotNull String path);
/**
* Get an integer from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
Integer getIntOrNull(@NotNull String path);
/**
* Get an integer from config with a specified default (not found) value.
*
* @param path The key to fetch the value from.
* @param def The value to default to if not found.
* @return The found value, or the default.
*/
int getInt(@NotNull String path,
int def);
/**
* Get a list of integers from config.
*
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@NotNull
List<Integer> getInts(@NotNull String path);
/**
* Get a list of integers from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
List<Integer> getIntsOrNull(@NotNull String path);
/**
* Get a boolean from config.
*
* @param path The key to fetch the value from.
* @return The found value, or false if not found.
*/
boolean getBool(@NotNull String path);
/**
* Get a boolean from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
Boolean getBoolOrNull(@NotNull String path);
/**
* Get a list of booleans from config.
*
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@NotNull
List<Boolean> getBools(@NotNull String path);
/**
* Get a list of booleans from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
List<Boolean> getBoolsOrNull(@NotNull String path);
/**
* Get a string from config.
*
* @param path The key to fetch the value from.
* @return The found value, or an empty string if not found.
*/
@NotNull
String getString(@NotNull String path);
/**
* Get a string from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
String getStringOrNull(@NotNull String path);
/**
* Get a list of strings from config.
*
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@NotNull
List<String> getStrings(@NotNull String path);
/**
* Get a list of strings from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
List<String> getStringsOrNull(@NotNull String path);
/**
* Get a decimal from config.
*
* @param path The key to fetch the value from.
* @return The found value, or 0 if not found.
*/
double getDouble(@NotNull String path);
/**
* Get a decimal from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
Double getDoubleOrNull(@NotNull String path);
/**
* Get a list of decimals from config.
*
* @param path The key to fetch the value from.
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
*/
@NotNull
List<Double> getDoubles(@NotNull String path);
/**
* Get a list of decimals from config.
*
* @param path The key to fetch the value from.
* @return The found value, or null if not found.
*/
@Nullable
List<Double> getDoublesOrNull(@NotNull String path);
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.config.updating.annotations;
package com.willfp.eco.core.config;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -0,0 +1,28 @@
package com.willfp.eco.core.config;
import com.willfp.eco.internal.config.UpdatableYamlConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public abstract class ExtendableConfig extends UpdatableYamlConfig {
/**
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
* <p>
* Automatically updates.
*
* @param configName The name of the config
* @param removeUnused Whether keys not present in the default config should be removed on update.
* @param plugin The plugin.
* @param updateBlacklist Substring of keys to not add/remove keys for.
* @param subDirectoryPath The subdirectory path.
* @param source The class that owns the resource.
*/
protected ExtendableConfig(@NotNull final String configName,
final boolean removeUnused,
@NotNull final EcoPlugin plugin,
@NotNull final Class<?> source,
@NotNull final String subDirectoryPath,
@NotNull final String... updateBlacklist) {
super(configName, plugin, subDirectoryPath, source, removeUnused, updateBlacklist);
}
}

View File

@@ -0,0 +1,20 @@
package com.willfp.eco.core.config;
import com.willfp.eco.internal.config.LoadableYamlConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public abstract class StaticBaseConfig extends LoadableYamlConfig {
/**
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
* <p>
* Does not automatically update.
*
* @param configName The name of the config
* @param plugin The plugin.
*/
protected StaticBaseConfig(@NotNull final String configName,
@NotNull final EcoPlugin plugin) {
super(configName, plugin, "", plugin.getClass());
}
}

View File

@@ -0,0 +1,18 @@
package com.willfp.eco.core.config;
import com.willfp.eco.internal.config.ConfigWrapper;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
public abstract class YamlConfig extends ConfigWrapper<YamlConfiguration> {
/**
* Config implementation for passing YamlConfigurations.
* <p>
* Does not automatically update.
*
* @param config The YamlConfiguration handle.
*/
public YamlConfig(@NotNull final YamlConfiguration config) {
init(config);
}
}

View File

@@ -0,0 +1,17 @@
package com.willfp.eco.core.config.base;
import com.willfp.eco.core.config.BaseConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public class ConfigYml extends BaseConfig {
/**
* Config.yml.
*
* @param plugin The plugin.
*/
public ConfigYml(@NotNull final EcoPlugin plugin) {
super("config", true, plugin);
}
}

View File

@@ -1,15 +1,17 @@
package com.willfp.eco.util.config.configs;
package com.willfp.eco.core.config.base;
import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.config.BaseConfig;
import com.willfp.eco.core.config.BaseConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public class Lang extends BaseConfig {
public class LangYml extends BaseConfig {
/**
* lang.yml.
* Lang.yml.
*
* @param plugin The plugin.
*/
public Lang() {
super("lang", false);
public LangYml(@NotNull final EcoPlugin plugin) {
super("lang", false, plugin);
}
/**
@@ -18,7 +20,7 @@ public class Lang extends BaseConfig {
* @return The prefix.
*/
public String getPrefix() {
return StringUtils.translate(this.getConfig().getString("messages.prefix"));
return this.getString("messages.prefix");
}
/**
@@ -27,7 +29,7 @@ public class Lang extends BaseConfig {
* @return The message.
*/
public String getNoPermission() {
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages.no-permission"));
return getPrefix() + this.getString("messages.no-permission");
}
/**
@@ -37,6 +39,6 @@ public class Lang extends BaseConfig {
* @return The message with a prefix appended.
*/
public String getMessage(@NotNull final String message) {
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages." + message));
return getPrefix() + this.getString("messages." + message);
}
}

View File

@@ -0,0 +1,216 @@
package com.willfp.eco.core.display;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang.Validate;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@UtilityClass
public class Display {
/**
* The prefix for lore lines.
*/
public static final String PREFIX = "§z";
/**
* All registered display modules.
*/
private static final Map<DisplayPriority, List<DisplayModule>> MODULES = new HashMap<>();
/**
* NamespacedKey for finalizing.
*/
private static NamespacedKey finalizeKey = null;
/**
* Register display module.
*
* @param module The module.
*/
public void registerDisplayModule(@NotNull final DisplayModule module) {
List<DisplayModule> modules = MODULES.get(module.getPriority());
modules.removeIf(module1 -> module1.getPluginName().equalsIgnoreCase(module.getPluginName()));
modules.add(module);
MODULES.put(module.getPriority(), modules);
}
/**
* Display on ItemStacks.
*
* @param itemStack The item.
* @return The itemstack.
*/
public ItemStack display(@NotNull final ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return itemStack; // return early if there's no customization of the item
}
Map<String, Object[]> pluginVarArgs = new HashMap<>();
for (DisplayPriority priority : DisplayPriority.values()) {
List<DisplayModule> modules = MODULES.get(priority);
for (DisplayModule module : modules) {
pluginVarArgs.put(module.getPluginName(), module.generateVarArgs(itemStack));
}
}
revert(itemStack);
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return itemStack;
}
for (DisplayPriority priority : DisplayPriority.values()) {
List<DisplayModule> modules = MODULES.get(priority);
for (DisplayModule module : modules) {
Object[] varargs = pluginVarArgs.get(module.getPluginName());
module.display(itemStack, varargs);
}
}
return itemStack;
}
/**
* Display on ItemStacks and then finalize.
*
* @param itemStack The item.
* @return The itemstack.
*/
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack) {
return finalize(display(itemStack));
}
/**
* Revert on ItemStacks.
*
* @param itemStack The item.
* @return The itemstack.
*/
public ItemStack revert(@NotNull final ItemStack itemStack) {
if (Display.isFinalized(itemStack)) {
unfinalize(itemStack);
}
if (!itemStack.hasItemMeta()) {
return itemStack;
}
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return itemStack;
}
List<String> lore = meta.getLore();
if (lore != null && lore.removeIf(line -> line.startsWith(Display.PREFIX))) { // only apply lore modification if needed
meta.setLore(lore);
itemStack.setItemMeta(meta);
}
for (DisplayPriority priority : DisplayPriority.values()) {
List<DisplayModule> modules = MODULES.get(priority);
for (DisplayModule module : modules) {
module.revert(itemStack);
}
}
return itemStack;
}
/**
* Finalize an ItemStacks.
*
* @param itemStack The item.
* @return The itemstack.
*/
public ItemStack finalize(@NotNull final ItemStack itemStack) {
Validate.notNull(finalizeKey, "Key cannot be null!");
if (itemStack.getType().getMaxStackSize() > 1) {
return itemStack;
}
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return itemStack;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
container.set(finalizeKey, PersistentDataType.INTEGER, 1);
itemStack.setItemMeta(meta);
return itemStack;
}
/**
* Unfinalize an ItemStacks.
*
* @param itemStack The item.
* @return The itemstack.
*/
public ItemStack unfinalize(@NotNull final ItemStack itemStack) {
Validate.notNull(finalizeKey, "Key cannot be null!");
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return itemStack;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
container.remove(finalizeKey);
itemStack.setItemMeta(meta);
return itemStack;
}
/**
* If an item is finalized.
*
* @param itemStack The item.
* @return If finalized.
*/
public boolean isFinalized(@NotNull final ItemStack itemStack) {
Validate.notNull(finalizeKey, "Key cannot be null!");
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return false;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
return container.has(finalizeKey, PersistentDataType.INTEGER);
}
/**
* Set key to be used for finalization.
*
* @param finalizeKey The key.
*/
@ApiStatus.Internal
public static void setFinalizeKey(@NotNull final NamespacedKey finalizeKey) {
Display.finalizeKey = finalizeKey;
}
static {
for (DisplayPriority priority : DisplayPriority.values()) {
MODULES.put(priority, new ArrayList<>());
}
}
}

View File

@@ -0,0 +1,66 @@
package com.willfp.eco.core.display;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import lombok.Getter;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public abstract class DisplayModule extends PluginDependent {
/**
* The priority of the module.
*/
@Getter
private final DisplayPriority priority;
/**
* Create a new display module.
*
* @param plugin The plugin that the display is for.
* @param priority The priority of the module.
*/
protected DisplayModule(@NotNull final EcoPlugin plugin,
@NotNull final DisplayPriority priority) {
super(plugin);
this.priority = priority;
}
/**
* Display an item.
*
* @param itemStack The item.
* @param args Optional args for display.
*/
protected void display(@NotNull final ItemStack itemStack,
@NotNull final Object... args) {
// Technically optional.
}
/**
* Revert an item.
*
* @param itemStack The item.
*/
protected void revert(@NotNull final ItemStack itemStack) {
// Technically optional.
}
/**
* Create varargs to pass back to itemstack after reverting, but before display.
*
* @param itemStack The itemStack.
* @return The plugin-specific varargs.
*/
protected Object[] generateVarArgs(@NotNull final ItemStack itemStack) {
return new Object[0];
}
/**
* Get name of plugin.
*
* @return The plugin name.
*/
final String getPluginName() {
return super.getPlugin().getPluginName();
}
}

View File

@@ -0,0 +1,23 @@
package com.willfp.eco.core.display;
public enum DisplayPriority {
/**
* Ran first.
*/
LOWEST,
/**
* Ran second.
*/
LOW,
/**
* Ran third.
*/
HIGH,
/**
* Ran last.
*/
HIGHEST
}

View File

@@ -1,10 +1,10 @@
package com.willfp.eco.util.drops;
package com.willfp.eco.core.drops;
import com.willfp.eco.util.drops.internal.AbstractDropQueue;
import com.willfp.eco.util.drops.internal.DropManager;
import com.willfp.eco.util.drops.internal.DropQueueType;
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
import com.willfp.eco.util.drops.internal.InternalDropQueue;
import com.willfp.eco.internal.drops.AbstractDropQueue;
import com.willfp.eco.internal.drops.DropManager;
import com.willfp.eco.internal.drops.DropQueueType;
import com.willfp.eco.internal.drops.impl.FastCollatedDropQueue;
import com.willfp.eco.internal.drops.impl.InternalDropQueue;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

View File

@@ -0,0 +1,31 @@
package com.willfp.eco.core.events;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
public class ArmorEquipEvent extends PlayerEvent {
private static final HandlerList HANDLERS = new HandlerList();
public ArmorEquipEvent(@NotNull final Player player) {
super(player);
}
/**
* Gets a list of handlers handling this event.
*
* @return A list of handlers handling this event.
*/
@Override
@NotNull
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.events.entitydeathbyentity;
package com.willfp.eco.core.events;
import lombok.Getter;
import org.bukkit.entity.Entity;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.bukkit.events;
package com.willfp.eco.core.events;
import org.bukkit.event.Listener;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.events.naturalexpgainevent;
package com.willfp.eco.core.events;
import lombok.Getter;
import org.bukkit.event.Event;

View File

@@ -1,18 +1,27 @@
package com.willfp.eco.util.extensions;
package com.willfp.eco.core.extensions;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.internal.extensions.ExtensionMetadata;
import com.willfp.eco.core.EcoPlugin;
import lombok.AccessLevel;
import lombok.Getter;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
public abstract class Extension {
/**
* The {@link AbstractEcoPlugin} that this extension is for.
* The {@link EcoPlugin} that this extension is for.
*/
@Getter(AccessLevel.PROTECTED)
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
private final EcoPlugin plugin;
/**
* Create a new extension for a plugin.
*
* @param plugin The plugin.
*/
protected Extension(@NotNull final EcoPlugin plugin) {
this.plugin = plugin;
}
/**
* Metadata containing version and name.
@@ -62,7 +71,7 @@ public abstract class Extension {
*/
public final String getName() {
Validate.notNull(metadata, "Metadata cannot be null!");
return this.metadata.name;
return this.metadata.getName();
}
/**
@@ -72,36 +81,6 @@ public abstract class Extension {
*/
public final String getVersion() {
Validate.notNull(metadata, "Metadata cannot be null!");
return this.metadata.version;
}
/**
* Wrapper for the string and version of the extension.
* Contains versions and name.
* Designed for internal use.
*/
@ApiStatus.Internal
public static final class ExtensionMetadata {
/**
* The version of the extension.
*/
private final @NotNull String version;
/**
* The extension's name.
*/
private final @NotNull String name;
/**
* Create a new extension metadata.
*
* @param version The version for the extension to be.
* @param name The name of the extension.
*/
public ExtensionMetadata(@NotNull final String version,
@NotNull final String name) {
this.version = version;
this.name = name;
}
return this.metadata.getVersion();
}
}

View File

@@ -1,6 +1,4 @@
package com.willfp.eco.util.extensions.loader;
import com.willfp.eco.util.extensions.Extension;
package com.willfp.eco.core.extensions;
import java.util.Set;
@@ -20,11 +18,6 @@ public interface ExtensionLoader {
*/
void unloadExtensions();
/**
* Reload all extensions.
*/
void reloadExtensions();
/**
* Retrieve a set of all loaded extensions.
*

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.extensions;
package com.willfp.eco.core.extensions;
import org.jetbrains.annotations.NotNull;

View File

@@ -0,0 +1,8 @@
package com.willfp.eco.core.factory;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
public interface MetadataValueFactory {
FixedMetadataValue create(@NotNull Object value);
}

View File

@@ -0,0 +1,14 @@
package com.willfp.eco.core.factory;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.NotNull;
public interface NamespacedKeyFactory {
/**
* Create an {@link NamespacedKey} associated with an {@link com.willfp.eco.core.EcoPlugin}.
*
* @param key The key in the {@link NamespacedKey}.
* @return The created {@link NamespacedKey}.
*/
NamespacedKey create(@NotNull String key);
}

View File

@@ -0,0 +1,16 @@
package com.willfp.eco.core.factory;
import com.willfp.eco.core.scheduling.RunnableTask;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
public interface RunnableFactory {
/**
* Create a {@link RunnableTask}.
*
* @param consumer Lambda of the code to run, where the parameter represents the instance of the runnable.
* @return The created {@link RunnableTask}.
*/
RunnableTask create(@NotNull Consumer<RunnableTask> consumer);
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations;
package com.willfp.eco.core.integrations;
public interface Integration {
/**

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations;
package com.willfp.eco.core.integrations;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.integrations.anticheat;
package com.willfp.eco.core.integrations.anticheat;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
@@ -11,11 +11,6 @@ import java.util.Set;
@UtilityClass
public class AnticheatManager {
/**
* The linked {@link AbstractEcoPlugin} to register anticheat listeners to.
*/
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
/**
* A set of all registered anticheats.
*/
@@ -24,9 +19,11 @@ public class AnticheatManager {
/**
* Register a new anticheat.
*
* @param plugin The plugin.
* @param anticheat The anticheat to register.
*/
public void register(@NotNull final AnticheatWrapper anticheat) {
public void register(@NotNull final EcoPlugin plugin,
@NotNull final AnticheatWrapper anticheat) {
if (anticheat instanceof Listener) {
plugin.getEventManager().registerListener((Listener) anticheat);
}
@@ -49,8 +46,6 @@ public class AnticheatManager {
* @param player The player to remove the exemption.
*/
public void unexemptPlayer(@NotNull final Player player) {
plugin.getScheduler().runLater(() -> {
anticheats.forEach(anticheat -> anticheat.unexempt(player));
}, 1);
anticheats.forEach(anticheat -> anticheat.unexempt(player));
}
}

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.integrations.anticheat;
package com.willfp.eco.core.integrations.anticheat;
import com.willfp.eco.util.integrations.Integration;
import com.willfp.eco.core.integrations.Integration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations.antigrief;
package com.willfp.eco.core.integrations.antigrief;
import lombok.experimental.UtilityClass;
import org.bukkit.Location;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.integrations.antigrief;
package com.willfp.eco.core.integrations.antigrief;
import com.willfp.eco.util.integrations.Integration;
import com.willfp.eco.core.integrations.Integration;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;

View File

@@ -0,0 +1,52 @@
package com.willfp.eco.core.integrations.mcmmo;
import lombok.experimental.UtilityClass;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
@UtilityClass
public class McmmoManager {
/**
* A set of all registered integrations.
*/
private final Set<McmmoWrapper> regsistered = new HashSet<>();
/**
* Register a new integration.
*
* @param integration The integration to register.
*/
public void register(@NotNull final McmmoWrapper integration) {
regsistered.add(integration);
}
/**
* Get bonus drop count from block.
*
* @param block The block.
* @return The bonus drop count.
*/
public int getBonusDropCount(@NotNull final Block block) {
for (McmmoWrapper mcmmoWrapper : regsistered) {
return mcmmoWrapper.getBonusDropCount(block);
}
return 0;
}
/**
* Get if event is fake.
*
* @param event The event to check.
* @return If the event is fake.
*/
public boolean isFake(@NotNull final Event event) {
for (McmmoWrapper mcmmoWrapper : regsistered) {
return mcmmoWrapper.isFake(event);
}
return false;
}
}

View File

@@ -0,0 +1,23 @@
package com.willfp.eco.core.integrations.mcmmo;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
public interface McmmoWrapper {
/**
* Get bonus drop count of block.
*
* @param block The block.
* @return The drop multiplier.
*/
int getBonusDropCount(@NotNull Block block);
/**
* Get if event is fake.
*
* @param event The event.
* @return If is fake.
*/
boolean isFake(@NotNull Event event);
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations.placeholder;
package com.willfp.eco.core.integrations.placeholder;
import lombok.Getter;
import org.apache.commons.lang.Validate;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.integrations.placeholder;
package com.willfp.eco.core.integrations.placeholder;
import com.willfp.eco.util.integrations.Integration;
import com.willfp.eco.core.integrations.Integration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations.placeholder;
package com.willfp.eco.core.integrations.placeholder;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;

View File

@@ -0,0 +1,59 @@
package com.willfp.eco.core.items;
import lombok.Getter;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Predicate;
public class CustomItem implements TestableItem {
/**
* The key.
*/
@Getter
private final NamespacedKey key;
/**
* The test for ItemStacks to pass.
*/
private final Predicate<ItemStack> test;
/**
* Example Item: what the user should see.
*/
private final ItemStack item;
/**
* Create a new complex recipe part.
*
* @param key The item key.
* @param test The test.
* @param item The example ItemStacks.
*/
public CustomItem(@NotNull final NamespacedKey key,
@NotNull final Predicate<ItemStack> test,
@NotNull final ItemStack item) {
this.key = key;
this.test = test;
this.item = item;
}
@Override
public boolean matches(@Nullable final ItemStack itemStack) {
return test.test(itemStack);
}
@Override
public ItemStack getItem() {
return item;
}
/**
* Register the item.
*/
public void register() {
Items.registerCustomItem(this.getKey(), this);
}
}

View File

@@ -0,0 +1,69 @@
package com.willfp.eco.core.items;
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
@UtilityClass
@SuppressWarnings("deprecation")
public final class Items {
/**
* All recipe parts.
*/
private static final Map<NamespacedKey, CustomItem> REGISTRY = new HashMap<>();
/**
* Register a new recipe part.
*
* @param key The key of the recipe part.
* @param part The recipe part.
*/
public void registerCustomItem(@NotNull final NamespacedKey key,
@NotNull final CustomItem part) {
REGISTRY.put(key, part);
}
/**
* Lookup item from string.
* <p>
* Used for recipes.
*
* @param key The string to test.
* @return The found testable item, or an empty item if not found.
*/
public TestableItem lookup(@NotNull final String key) {
String[] split = key.toLowerCase().split(":");
if (split.length == 1) {
Material material = Material.getMaterial(key.toUpperCase());
if (material == null || material == Material.AIR) {
return new EmptyTestableItem();
}
return new MaterialTestableItem(material);
}
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
return part == null ? new EmptyTestableItem() : part;
}
/**
* Get if itemStack is a custom item.
*
* @param itemStack The itemStack to check.
* @return If is recipe.
*/
public boolean isCustomItem(@NotNull final ItemStack itemStack) {
for (CustomItem item : REGISTRY.values()) {
if (item.matches(itemStack)) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,21 @@
package com.willfp.eco.core.items;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
public interface TestableItem {
/**
* If an ItemStack matches the recipe part.
*
* @param itemStack The item to test.
* @return If the item matches.
*/
boolean matches(@Nullable ItemStack itemStack);
/**
* Get an example item.
*
* @return The item.
*/
ItemStack getItem();
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.proxy;
package com.willfp.eco.core.proxy;
public interface AbstractProxy {

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.proxy;
package com.willfp.eco.core.proxy;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.proxy;
package com.willfp.eco.core.proxy;
import org.jetbrains.annotations.NotNull;

View File

@@ -0,0 +1,62 @@
package com.willfp.eco.core.recipe;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
import lombok.experimental.UtilityClass;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@UtilityClass
@SuppressWarnings("deprecation")
public class Recipes {
/**
* Registry of all recipes.
*/
private static final BiMap<NamespacedKey, CraftingRecipe> RECIPES = HashBiMap.create();
/**
* Register a recipe.
*
* @param recipe The recipe.
*/
public void register(@NotNull final CraftingRecipe recipe) {
RECIPES.forcePut(recipe.getKey(), recipe);
}
/**
* Get recipe matching matrix.
*
* @param matrix The matrix to test.
* @return The match, or null if not found.
*/
@Nullable
public CraftingRecipe getMatch(@NotNull final ItemStack[] matrix) {
return RECIPES.values().stream().filter(recipe -> recipe.test(matrix)).findFirst().orElse(null);
}
/**
* Get recipe by key.
*
* @param key The key.
* @return The recipe, or null if not found.
*/
@Nullable
public CraftingRecipe getRecipe(@NotNull final NamespacedKey key) {
CraftingRecipe recipe = RECIPES.get(key);
if (recipe != null) {
return recipe;
}
if (key.getKey().contains("_displayed")) {
NamespacedKey otherKey = new NamespacedKey(key.getNamespace(), key.getKey().replace("_displayed", ""));
return RECIPES.get(otherKey);
}
return null;
}
}

View File

@@ -0,0 +1,31 @@
package com.willfp.eco.core.recipe.parts;
import com.willfp.eco.core.items.TestableItem;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
public class EmptyTestableItem implements TestableItem {
/**
* Create a new empty recipe part.
*/
public EmptyTestableItem() {
}
/**
* If the item is empty.
*
* @param itemStack The item to test.
* @return If the item is empty.
*/
@Override
public boolean matches(@Nullable final ItemStack itemStack) {
return itemStack == null || itemStack.getType() == Material.AIR;
}
@Override
public ItemStack getItem() {
return new ItemStack(Material.AIR);
}
}

View File

@@ -0,0 +1,41 @@
package com.willfp.eco.core.recipe.parts;
import com.willfp.eco.core.items.TestableItem;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class MaterialTestableItem implements TestableItem {
/**
* The material.
*/
@Getter
private final Material material;
/**
* Create a new simple recipe part.
*
* @param material The material.
*/
public MaterialTestableItem(@NotNull final Material material) {
this.material = material;
}
/**
* If the item matches the material.
*
* @param itemStack The item to test.
* @return If the item is of the specified material.
*/
@Override
public boolean matches(@Nullable final ItemStack itemStack) {
return itemStack != null && itemStack.getType() == material;
}
@Override
public ItemStack getItem() {
return new ItemStack(material);
}
}

View File

@@ -0,0 +1,51 @@
package com.willfp.eco.core.recipe.recipes;
import com.willfp.eco.core.items.TestableItem;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface CraftingRecipe {
/**
* Test matrix against recipe.
*
* @param matrix The matrix to check.
* @return If the recipe matches.
*/
boolean test(@NotNull ItemStack[] matrix);
/**
* Register the recipe.
*/
void register();
/**
* The recipe parts.
*
* @return The parts.
*/
List<TestableItem> getParts();
/**
* Get the recipe key.
*
* @return The key.
*/
NamespacedKey getKey();
/**
* Get the displayed recipe key.
*
* @return The key.
*/
NamespacedKey getDisplayedKey();
/**
* Get the recipe output.
*
* @return The output.
*/
ItemStack getOutput();
}

View File

@@ -0,0 +1,65 @@
package com.willfp.eco.core.recipe.recipes;
import lombok.Getter;
public enum RecipePosition {
/**
* Top left of matrix.
*/
TOP_LEFT(0),
/**
* Top middle of matrix.
*/
TOP_MIDDLE(1),
/**
* Top right of matrix.
*/
TOP_RIGHT(2),
/**
* Middle left of matrix.
*/
MIDDLE_LEFT(3),
/**
* Middle of matrix.
*/
MIDDLE(4),
/**
* Middle right of matrix.
*/
MIDDLE_RIGHT(5),
/**
* Bottom left of matrix.
*/
BOTTOM_LEFT(6),
/**
* Bottom middle of matrix.
*/
BOTTOM_MIDDLE(7),
/**
* Bottom right of matrix.
*/
BOTTOM_RIGHT(8);
/**
* The index within a crafting table matrix.
*/
@Getter
private final int index;
/**
* Recipe position with crafting table index.
*
* @param index The index.
*/
RecipePosition(final int index) {
this.index = index;
}
}

View File

@@ -0,0 +1,192 @@
package com.willfp.eco.core.recipe.recipes;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.items.TestableItem;
import com.willfp.eco.core.recipe.Recipes;
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("deprecation")
public final class ShapedCraftingRecipe extends PluginDependent implements CraftingRecipe {
/**
* Recipe parts.
*/
@Getter
private final List<TestableItem> parts;
/**
* The key of the recipe.
*/
@Getter
private final NamespacedKey key;
/**
* The key of the displayed recipe.
*/
@Getter
private final NamespacedKey displayedKey;
/**
* The recipe's output.
*/
@Getter
private final ItemStack output;
private ShapedCraftingRecipe(@NotNull final EcoPlugin plugin,
@NotNull final String key,
@NotNull final List<TestableItem> parts,
@NotNull final ItemStack output) {
super(plugin);
this.parts = parts;
this.key = plugin.getNamespacedKeyFactory().create(key);
this.displayedKey = plugin.getNamespacedKeyFactory().create(key + "_displayed");
this.output = output;
}
@Override
public boolean test(@NotNull final ItemStack[] matrix) {
boolean matches = true;
for (int i = 0; i < 9; i++) {
if (!parts.get(i).matches(matrix[i])) {
matches = false;
}
}
return matches;
}
@Override
public void register() {
Recipes.register(this);
Bukkit.getServer().removeRecipe(this.getKey());
Bukkit.getServer().removeRecipe(this.getDisplayedKey());
ShapedRecipe shapedRecipe = new ShapedRecipe(this.getKey(), this.getOutput());
shapedRecipe.shape("012", "345", "678");
for (int i = 0; i < 9; i++) {
char character = String.valueOf(i).toCharArray()[0];
shapedRecipe.setIngredient(character, parts.get(i).getItem().getType());
}
ShapedRecipe displayedRecipe = new ShapedRecipe(this.getDisplayedKey(), this.getOutput());
displayedRecipe.shape("012", "345", "678");
for (int i = 0; i < 9; i++) {
char character = String.valueOf(i).toCharArray()[0];
displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(parts.get(i).getItem()));
}
Bukkit.getServer().addRecipe(shapedRecipe);
Bukkit.getServer().addRecipe(displayedRecipe);
}
/**
* Create a new recipe builder.
*
* @param plugin The plugin that owns the recipe.
* @param key The recipe key.
* @return A new builder.
*/
public static Builder builder(@NotNull final EcoPlugin plugin,
@NotNull final String key) {
return new Builder(plugin, key);
}
public static final class Builder {
/**
* The recipe parts.
*/
private final List<TestableItem> recipeParts = new ArrayList<>(Arrays.asList(null, null, null, null, null, null, null, null, null)); // Jank
/**
* The output of the recipe.
*/
private ItemStack output = null;
/**
* The key of the recipe.
*/
private final String key;
/**
* The plugin that created the recipe.
*/
private final EcoPlugin plugin;
/**
* Create a new recipe builder.
*
* @param plugin The plugin that owns the recipe.
* @param key The recipe key.
*/
private Builder(@NotNull final EcoPlugin plugin,
@NotNull final String key) {
this.key = key;
this.plugin = plugin;
}
/**
* Set a recipe part.
*
* @param position The position of the recipe within a crafting matrix.
* @param part The part of the recipe.
* @return The builder.
*/
public Builder setRecipePart(@NotNull final RecipePosition position,
@NotNull final TestableItem part) {
recipeParts.set(position.getIndex(), part);
return this;
}
/**
* Set a recipe part.
*
* @param position The position of the recipe within a crafting matrix.
* @param part The part of the recipe.
* @return The builder.
*/
public Builder setRecipePart(final int position,
@NotNull final TestableItem part) {
recipeParts.set(position, part);
return this;
}
/**
* Set the output of the recipe.
*
* @param output The output.
* @return The builder.
*/
public Builder setOutput(@NotNull final ItemStack output) {
this.output = output;
return this;
}
/**
* Build the recipe.
*
* @return The built recipe.
*/
public ShapedCraftingRecipe build() {
for (int i = 0; i < 9; i++) {
if (recipeParts.get(i) == null) {
recipeParts.set(i, new EmptyTestableItem());
}
}
return new ShapedCraftingRecipe(plugin, key.toLowerCase(), recipeParts, output);
}
}
}

View File

@@ -0,0 +1,59 @@
package com.willfp.eco.core.scheduling;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
public interface RunnableTask extends Runnable {
/**
* Run the task.
*
* @return The created {@link BukkitTask}.
*/
@NotNull BukkitTask runTask();
/**
* Run the task asynchronously.
*
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskAsynchronously();
/**
* Run the task after a specified number of ticks.
*
* @param delay The number of ticks to wait.
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskLater(long delay);
/**
* Run the task asynchronously after a specified number of ticks.
*
* @param delay The number of ticks to wait.
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskLaterAsynchronously(long delay);
/**
* Run the task repeatedly on a timer.
*
* @param delay The delay before the task is first ran (in ticks).
* @param period The ticks elapsed before the task is ran again.
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskTimer(long delay, long period);
/**
* Run the task repeatedly on a timer asynchronously.
*
* @param delay The delay before the task is first ran (in ticks).
* @param period The ticks elapsed before the task is ran again.
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskTimerAsynchronously(long delay, long period);
/**
* Cancel the task.
*/
void cancel();
}

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.bukkit.scheduling;
package com.willfp.eco.core.scheduling;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
@@ -12,7 +12,8 @@ public interface Scheduler {
* @param ticksLater The amount of ticks to wait before execution.
* @return The created {@link BukkitTask}.
*/
BukkitTask runLater(@NotNull Runnable runnable, long ticksLater);
BukkitTask runLater(@NotNull Runnable runnable,
long ticksLater);
/**
* Run the task repeatedly on a timer.
@@ -22,7 +23,9 @@ public interface Scheduler {
* @param repeat The amount of ticks to wait between executions.
* @return The created {@link BukkitTask}.
*/
BukkitTask runTimer(@NotNull Runnable runnable, long delay, long repeat);
BukkitTask runTimer(@NotNull Runnable runnable,
long delay,
long repeat);
/**
* Run the task repeatedly and asynchronously on a timer.
@@ -32,7 +35,9 @@ public interface Scheduler {
* @param repeat The amount of ticks to wait between executions.
* @return The created {@link BukkitTask}.
*/
BukkitTask runAsyncTimer(@NotNull Runnable runnable, long delay, long repeat);
BukkitTask runAsyncTimer(@NotNull Runnable runnable,
long delay,
long repeat);
/**
* Run the task.
@@ -58,10 +63,12 @@ public interface Scheduler {
* @param repeat The amount of ticks to wait between executions.
* @return The id of the task.
*/
int syncRepeating(@NotNull Runnable runnable, long delay, long repeat);
int syncRepeating(@NotNull Runnable runnable,
long delay,
long repeat);
/**
* Cancel all running tasks from the linked {@link AbstractEcoPlugin}.
* Cancel all running tasks from the linked {@link EcoPlugin}.
*/
void cancelAll();
}

View File

@@ -1,14 +1,12 @@
package com.willfp.eco.util.tuplets;
package com.willfp.eco.core.tuples;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.jetbrains.annotations.Nullable;
@ToString
public class Pair<A, B> {
/**
* The first value in the pair.
* The first item in the tuple.
*/
@Getter
@Setter
@@ -16,7 +14,7 @@ public class Pair<A, B> {
private A first;
/**
* The second value in the pair.
* The second item in the tuple.
*/
@Getter
@Setter

View File

@@ -0,0 +1,30 @@
package com.willfp.eco.core.tuples;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;
public class Triplet<A, B, C> extends Pair<A, B> {
/**
* The third item in the tuple.
*/
@Getter
@Setter
@Nullable
private C third;
/**
* Create a triple of values.
*
* @param first The first item in the pair.
* @param second The second item in the pair.
* @param third The third item in the pair.
*/
public Triplet(@Nullable final A first,
@Nullable final B second,
@Nullable final C third) {
super(first, second);
this.third = third;
}
}

View File

@@ -1,7 +1,7 @@
package com.willfp.eco.util.updater;
package com.willfp.eco.internal;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.util.Consumer;
import org.jetbrains.annotations.NotNull;
@@ -16,7 +16,7 @@ public class UpdateChecker extends PluginDependent {
*
* @param plugin The plugin to check.
*/
public UpdateChecker(@NotNull final AbstractEcoPlugin plugin) {
public UpdateChecker(@NotNull final EcoPlugin plugin) {
super(plugin);
}

View File

@@ -1,9 +1,8 @@
package com.willfp.eco.util.arrows;
package com.willfp.eco.internal.arrows;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
@@ -14,16 +13,14 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public class ArrowDataListener extends PluginDependent implements Listener {
/**
* Listener to add metadata to arrows about the enchantments on the bow that shot them.
*
* @param plugin The {@link AbstractEcoPlugin} that registered the listener.
* @param plugin The {@link EcoPlugin} that registered the listener.
*/
@ApiStatus.Internal
public ArrowDataListener(@NotNull final AbstractEcoPlugin plugin) {
public ArrowDataListener(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@@ -54,7 +51,6 @@ public class ArrowDataListener extends PluginDependent implements Listener {
return;
}
Map<Enchantment, Integer> enchantments = item.getItemMeta().getEnchants();
arrow.setMetadata("enchantments", this.getPlugin().getMetadataValueFactory().create(enchantments));
arrow.setMetadata("shot-from", this.getPlugin().getMetadataValueFactory().create(item));
}
}

View File

@@ -0,0 +1,15 @@
package com.willfp.eco.internal.config;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
public class ConfigSection extends ConfigWrapper<ConfigurationSection> {
/**
* Config section.
*
* @param section The section.
*/
protected ConfigSection(@NotNull final ConfigurationSection section) {
this.init(section);
}
}

View File

@@ -0,0 +1,264 @@
package com.willfp.eco.internal.config;
import com.willfp.eco.util.StringUtils;
import com.willfp.eco.core.config.Config;
import lombok.Getter;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@SuppressWarnings({"unchecked", "unused"})
public abstract class ConfigWrapper<T extends ConfigurationSection> implements Config {
/**
* The linked {@link ConfigurationSection} where values are physically stored.
*/
@Getter
private T handle = null;
/**
* Cached values for faster reading.
*/
private final Map<String, Object> cache = new HashMap<>();
/**
* Abstract config.
*/
protected ConfigWrapper() {
}
protected Config init(@NotNull final T config) {
this.handle = config;
return this;
}
@Override
public final void clearCache() {
cache.clear();
}
@Override
public boolean has(@NotNull final String path) {
return handle.contains(path);
}
@NotNull
@Override
public List<String> getKeys(final boolean deep) {
return new ArrayList<>(handle.getKeys(deep));
}
@Override
@Nullable
public Object get(@NotNull final String path) {
return handle.get(path);
}
@Override
public void set(@NotNull final String path,
@Nullable final Object object) {
handle.set(path, object);
}
@Override
@NotNull
public Config getSubsection(@NotNull final String path) {
Config subsection = getSubsectionOrNull(path);
Validate.notNull(subsection);
return subsection;
}
@Override
@Nullable
public Config getSubsectionOrNull(@NotNull final String path) {
if (cache.containsKey(path)) {
return (Config) cache.get(path);
} else {
cache.put(path, new ConfigSection(Objects.requireNonNull(handle.getConfigurationSection(path))));
return getSubsectionOrNull(path);
}
}
@Override
public int getInt(@NotNull final String path) {
if (cache.containsKey(path)) {
return (int) cache.get(path);
} else {
cache.put(path, handle.getInt(path, 0));
return getInt(path);
}
}
@Override
@Nullable
public Integer getIntOrNull(@NotNull final String path) {
if (has(path)) {
return getInt(path);
} else {
return null;
}
}
@Override
public int getInt(@NotNull final String path,
final int def) {
if (cache.containsKey(path)) {
return (int) cache.get(path);
} else {
cache.put(path, handle.getInt(path, def));
return getInt(path);
}
}
@Override
@NotNull
public List<Integer> getInts(@NotNull final String path) {
if (cache.containsKey(path)) {
return (List<Integer>) cache.get(path);
} else {
cache.put(path, has(path) ? new ArrayList<>(handle.getIntegerList(path)) : new ArrayList<>());
return getInts(path);
}
}
@Override
@Nullable
public List<Integer> getIntsOrNull(@NotNull final String path) {
if (has(path)) {
return getInts(path);
} else {
return null;
}
}
@Override
public boolean getBool(@NotNull final String path) {
if (cache.containsKey(path)) {
return (boolean) cache.get(path);
} else {
cache.put(path, handle.getBoolean(path));
return getBool(path);
}
}
@Override
@Nullable
public Boolean getBoolOrNull(@NotNull final String path) {
if (has(path)) {
return getBool(path);
} else {
return null;
}
}
@Override
@NotNull
public List<Boolean> getBools(@NotNull final String path) {
if (cache.containsKey(path)) {
return (List<Boolean>) cache.get(path);
} else {
cache.put(path, has(path) ? new ArrayList<>(handle.getBooleanList(path)) : new ArrayList<>());
return getBools(path);
}
}
@Override
@Nullable
public List<Boolean> getBoolsOrNull(@NotNull final String path) {
if (has(path)) {
return getBools(path);
} else {
return null;
}
}
@Override
@NotNull
public String getString(@NotNull final String path) {
if (cache.containsKey(path)) {
return (String) cache.get(path);
} else {
cache.put(path, StringUtils.translate(Objects.requireNonNull(handle.getString(path, ""))));
return getString(path);
}
}
@Override
@Nullable
public String getStringOrNull(@NotNull final String path) {
if (has(path)) {
return getString(path);
} else {
return null;
}
}
@Override
@NotNull
public List<String> getStrings(@NotNull final String path) {
if (cache.containsKey(path)) {
return (List<String>) cache.get(path);
} else {
cache.put(path, has(path) ? new ArrayList<>(handle.getStringList(path)) : new ArrayList<>());
return getStrings(path);
}
}
@Override
@Nullable
public List<String> getStringsOrNull(@NotNull final String path) {
if (has(path)) {
return getStrings(path);
} else {
return null;
}
}
@Override
public double getDouble(@NotNull final String path) {
if (cache.containsKey(path)) {
return (double) cache.get(path);
} else {
cache.put(path, handle.getDouble(path));
return getDouble(path);
}
}
@Override
@Nullable
public Double getDoubleOrNull(@NotNull final String path) {
if (has(path)) {
return getDouble(path);
} else {
return null;
}
}
@Override
@NotNull
public List<Double> getDoubles(@NotNull final String path) {
if (cache.containsKey(path)) {
return (List<Double>) cache.get(path);
} else {
cache.put(path, has(path) ? new ArrayList<>(handle.getDoubleList(path)) : new ArrayList<>());
return getDoubles(path);
}
}
@Override
@Nullable
public List<Double> getDoublesOrNull(@NotNull final String path) {
if (has(path)) {
return getDoubles(path);
} else {
return null;
}
}
}

View File

@@ -0,0 +1,156 @@
package com.willfp.eco.internal.config;
import com.willfp.eco.core.EcoPlugin;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration> {
/**
* The physical config file, as stored on disk.
*/
@Getter(AccessLevel.PROTECTED)
private final File configFile;
/**
* Plugin handle.
*/
@Getter(AccessLevel.PROTECTED)
private final EcoPlugin plugin;
/**
* The full name of the config file (eg config.yml).
*/
@Getter
private final String name;
/**
* The subdirectory path.
*/
@Getter(AccessLevel.PROTECTED)
private final String subDirectoryPath;
/**
* The provider of the config.
*/
@Getter(AccessLevel.PROTECTED)
private final Class<?> source;
/**
* Abstract config.
*
* @param configName The name of the config
* @param plugin The plugin.
* @param subDirectoryPath The subdirectory path.
* @param source The class that owns the resource.
*/
protected LoadableYamlConfig(@NotNull final String configName,
@NotNull final EcoPlugin plugin,
@NotNull final String subDirectoryPath,
@NotNull final Class<?> source) {
this.plugin = plugin;
this.name = configName + ".yml";
this.source = source;
this.subDirectoryPath = subDirectoryPath;
File directory = new File(this.getPlugin().getDataFolder(), subDirectoryPath);
if (!directory.exists()) {
directory.mkdirs();
}
if (!new File(directory, this.name).exists()) {
createFile();
}
this.configFile = new File(directory, this.name);
init(YamlConfiguration.loadConfiguration(configFile));
}
private void createFile() {
String resourcePath = getResourcePath();
InputStream in = source.getResourceAsStream(resourcePath);
File outFile = new File(this.getPlugin().getDataFolder(), resourcePath);
int lastIndex = resourcePath.lastIndexOf('/');
File outDir = new File(this.getPlugin().getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0)));
if (!outDir.exists()) {
outDir.mkdirs();
}
try {
if (!outFile.exists()) {
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
}
} catch (IOException ignored) {
}
}
/**
* Get resource path as relative to base directory.
*
* @return The resource path.
*/
protected String getResourcePath() {
String resourcePath;
if (subDirectoryPath.isEmpty()) {
resourcePath = name;
} else {
resourcePath = subDirectoryPath + name;
}
return "/" + resourcePath;
}
/**
* Get YamlConfiguration as found in jar.
*
* @return The YamlConfiguration.
*/
protected YamlConfiguration getConfigInJar() {
InputStream newIn = source.getResourceAsStream(getResourcePath());
if (newIn == null) {
throw new NullPointerException(name + " is null?");
}
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
YamlConfiguration newConfig = new YamlConfiguration();
try {
newConfig.load(reader);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
return newConfig;
}
/**
* Save the config.
*
* @throws IOException If error in saving.
*/
public void save() throws IOException {
this.getHandle().save(this.getConfigFile());
}
}

View File

@@ -0,0 +1,87 @@
package com.willfp.eco.internal.config;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class UpdatableYamlConfig extends LoadableYamlConfig {
/**
* Whether keys not in the base config should be removed on update.
*/
private final boolean removeUnused;
/**
* List of blacklisted update keys.
*/
private final List<String> updateBlacklist;
/**
* Updatable config.
*
* @param configName The name of the config
* @param plugin The plugin.
* @param subDirectoryPath The subdirectory path.
* @param source The class that owns the resource.
* @param removeUnused Whether keys not present in the default config should be removed on update.
* @param updateBlacklist Substring of keys to not add/remove keys for.
*/
protected UpdatableYamlConfig(@NotNull final String configName,
@NotNull final EcoPlugin plugin,
@NotNull final String subDirectoryPath,
@NotNull final Class<?> source,
final boolean removeUnused,
@NotNull final String... updateBlacklist) {
super(configName, plugin, subDirectoryPath, source);
this.removeUnused = removeUnused;
this.updateBlacklist = new ArrayList<>(Arrays.asList(updateBlacklist));
this.updateBlacklist.removeIf(String::isEmpty);
update();
}
/**
* Update the config.
* <p>
* Writes missing values, however removes comments due to how configs are stored internally in bukkit.
*/
public void update() {
super.clearCache();
try {
this.getHandle().load(this.getConfigFile());
YamlConfiguration newConfig = this.getConfigInJar();
if (newConfig.getKeys(true).equals(this.getHandle().getKeys(true))) {
return;
}
newConfig.getKeys(true).forEach((s -> {
if (!this.getHandle().getKeys(true).contains(s)) {
if (updateBlacklist.stream().noneMatch(s::contains)) {
this.getHandle().set(s, newConfig.get(s));
}
}
}));
if (this.removeUnused) {
this.getHandle().getKeys(true).forEach((s -> {
if (!newConfig.getKeys(true).contains(s)) {
if (updateBlacklist.stream().noneMatch(s::contains)) {
this.getHandle().set(s, null);
}
}
}));
}
this.getHandle().save(this.getConfigFile());
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,10 +1,10 @@
package com.willfp.eco.util.config.updating;
package com.willfp.eco.internal.config.updating;
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
import com.willfp.eco.util.config.updating.exceptions.InvalidUpdatableClassException;
import com.willfp.eco.util.config.updating.exceptions.InvalidUpdateMethodException;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.config.ConfigUpdater;
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdatableClassException;
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
@@ -21,11 +21,11 @@ public class ConfigHandler extends PluginDependent {
private final Set<Class<?>> updatableClasses = new HashSet<>();
/**
* Creates a new config handler and links it to an {@link AbstractEcoPlugin}.
* Creates a new config handler and links it to an {@link EcoPlugin}.
*
* @param plugin The plugin to manage.
*/
public ConfigHandler(@NotNull final AbstractEcoPlugin plugin) {
public ConfigHandler(@NotNull final EcoPlugin plugin) {
super(plugin);
}

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.config.updating.exceptions;
package com.willfp.eco.internal.config.updating.exceptions;
import com.willfp.eco.util.config.updating.ConfigHandler;
import com.willfp.eco.internal.config.updating.ConfigHandler;
import org.jetbrains.annotations.NotNull;
public class InvalidUpdatableClassException extends RuntimeException {

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.config.updating.exceptions;
package com.willfp.eco.internal.config.updating.exceptions;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.drops.internal;
package com.willfp.eco.internal.drops;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;

View File

@@ -0,0 +1,25 @@
package com.willfp.eco.internal.drops;
import lombok.Getter;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
@UtilityClass
public final class DropManager {
/**
* The currently used type, or implementation, of {@link AbstractDropQueue}.
* <p>
* Default is {@link DropQueueType#COLLATED}, however this can be changed.
*/
@Getter
private DropQueueType type = DropQueueType.COLLATED;
/**
* Sets the type of Drop Queue to be used.
*
* @param type The type.
*/
public static void setType(@NotNull final DropQueueType type) {
DropManager.type = type;
}
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.drops.internal;
package com.willfp.eco.internal.drops;
public enum DropQueueType {
/**

View File

@@ -1,7 +1,6 @@
package com.willfp.eco.util.drops.internal;
package com.willfp.eco.internal.drops.impl;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.internal.drops.AbstractDropQueue;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@@ -9,14 +8,11 @@ import lombok.experimental.Accessors;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class FastCollatedDropQueue extends InternalDropQueue {
/**
@@ -24,7 +20,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
* <p>
* Cleared and updated every tick.
*/
private static final HashMap<Player, CollatedDrops> COLLATED_MAP = new HashMap<>();
public static final Map<Player, CollatedDrops> COLLATED_MAP = new ConcurrentHashMap<>();
/**
* Backend implementation of {@link AbstractDropQueue}
@@ -39,7 +35,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
}
/**
* Queues the drops to be managed by the {@link CollatedRunnable}.
* Queues the drops to be managed by the runnable.
*/
@Override
public void push() {
@@ -52,7 +48,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
* The items, location, and xp linked to a player's drops.
*/
@ToString
private static final class CollatedDrops {
public static final class CollatedDrops {
/**
* A collection of all ItemStacks to be dropped at the end of the tick.
*/
@@ -103,32 +99,4 @@ public class FastCollatedDropQueue extends InternalDropQueue {
return this;
}
}
public static class CollatedRunnable extends PluginDependent {
/**
* The {@link BukkitTask} that the runnable represents.
*/
@Getter
private final BukkitTask runnableTask;
/**
* Create and run a new runnable to process collated drops.
*
* @param plugin The {@link AbstractEcoPlugin} that manages the processing.
*/
@ApiStatus.Internal
public CollatedRunnable(@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
runnableTask = plugin.getScheduler().runTimer(() -> {
for (Map.Entry<Player, CollatedDrops> entry : COLLATED_MAP.entrySet()) {
new InternalDropQueue(entry.getKey())
.setLocation(entry.getValue().getLocation())
.addItems(entry.getValue().getDrops())
.addXP(entry.getValue().getXp())
.push();
}
COLLATED_MAP.clear();
}, 0, 1);
}
}
}

View File

@@ -1,10 +1,12 @@
package com.willfp.eco.util.drops.internal;
package com.willfp.eco.internal.drops.impl;
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
import com.willfp.eco.internal.drops.AbstractDropQueue;
import com.willfp.eco.util.TelekinesisUtils;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
@@ -133,6 +135,11 @@ public class InternalDropQueue implements AbstractDropQueue {
assert world != null;
loc = loc.add(0.5, 0.5, 0.5);
items.removeIf(itemStack -> itemStack.getType() == Material.AIR);
if (items.isEmpty()) {
return;
}
if (hasTelekinesis) {
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(items.toArray(new ItemStack[0]));
for (ItemStack drop : leftover.values()) {

View File

@@ -1,7 +1,8 @@
package com.willfp.eco.util.bukkit.events;
package com.willfp.eco.internal.events;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.events.EventManager;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
@@ -11,13 +12,11 @@ import org.jetbrains.annotations.NotNull;
public class EcoEventManager extends PluginDependent implements EventManager {
/**
* Manager class for event management.
* <p>
* Prevents calls to {@link AbstractEcoPlugin#getInstance()}.
*
* @param plugin The {@link AbstractEcoPlugin} that this manages the events of.
* @param plugin The {@link EcoPlugin} that this manages the events of.
*/
@ApiStatus.Internal
public EcoEventManager(@NotNull final AbstractEcoPlugin plugin) {
public EcoEventManager(@NotNull final EcoPlugin plugin) {
super(plugin);
}

View File

@@ -1,10 +1,12 @@
package com.willfp.eco.util.extensions.loader;
package com.willfp.eco.internal.extensions;
import com.willfp.eco.util.extensions.Extension;
import com.willfp.eco.util.extensions.MalformedExtensionException;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.extensions.Extension;
import com.willfp.eco.core.extensions.MalformedExtensionException;
import com.willfp.eco.core.extensions.ExtensionLoader;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
@@ -29,11 +31,11 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
private final Set<Extension> extensions = new HashSet<>();
/**
* Create a new extension loader and link it to a specific {@link AbstractEcoPlugin}.
* Create a new extension loader and link it to a specific {@link EcoPlugin}.
*
* @param plugin The plugin to manage
*/
public EcoExtensionLoader(@NotNull final AbstractEcoPlugin plugin) {
public EcoExtensionLoader(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@@ -61,7 +63,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
try {
loadExtension(extensionJar);
} catch (MalformedExtensionException e) {
this.getPlugin().getLog().error(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
this.getPlugin().getLogger().severe(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
}
}
}
@@ -94,13 +96,16 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
String mainClass = extensionYml.getString("main");
String name = extensionYml.getString("name");
String version = extensionYml.getString("version");
Extension.ExtensionMetadata metadata = new Extension.ExtensionMetadata(version, name);
Validate.notNull(name, "Name is missing!");
Validate.notNull(version, "Version is missing!");
ExtensionMetadata metadata = new ExtensionMetadata(version, name);
Class<?> cls;
Object object = null;
try {
cls = cl.loadClass(mainClass);
object = cls.getConstructor().newInstance();
object = cls.getConstructor(EcoPlugin.class).newInstance(this.getPlugin());
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
@@ -124,15 +129,6 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
extensions.clear();
}
/**
* Unloads, then loads all extensions.
*/
@Override
public void reloadExtensions() {
unloadExtensions();
loadExtensions();
}
/**
* Returns all loaded extensions.
*

View File

@@ -0,0 +1,32 @@
package com.willfp.eco.internal.extensions;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public class ExtensionMetadata {
/**
* The version of the extension.
*/
@NotNull
@Getter
private final String version;
/**
* The extension's name.
*/
@NotNull
@Getter
private final String name;
/**
* Create a new extension metadata.
*
* @param version The version for the extension to be.
* @param name The name of the extension.
*/
public ExtensionMetadata(@NotNull final String version,
@NotNull final String name) {
this.version = version;
this.name = name;
}
}

View File

@@ -1,26 +1,28 @@
package com.willfp.eco.util.bukkit.meta;
package com.willfp.eco.internal.factory;
import com.willfp.eco.util.internal.PluginDependentFactory;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.factory.MetadataValueFactory;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
public class MetadataValueFactory extends PluginDependentFactory {
public class EcoMetadataValueFactory extends PluginDependent implements MetadataValueFactory {
/**
* Factory class to produce {@link FixedMetadataValue}s associated with an {@link AbstractEcoPlugin}.
* Factory class to produce {@link FixedMetadataValue}s associated with an {@link EcoPlugin}.
*
* @param plugin The plugin that this factory creates values for.
*/
public MetadataValueFactory(@NotNull final AbstractEcoPlugin plugin) {
public EcoMetadataValueFactory(@NotNull final EcoPlugin plugin) {
super(plugin);
}
/**
* Create an {@link FixedMetadataValue} associated with an {@link AbstractEcoPlugin} with a specified value.
* Create an {@link FixedMetadataValue} associated with an {@link EcoPlugin} with a specified value.
*
* @param value The value of meta key.
* @return The created {@link FixedMetadataValue}.
*/
@Override
public FixedMetadataValue create(@NotNull final Object value) {
return new FixedMetadataValue(this.getPlugin(), value);
}

View File

@@ -0,0 +1,22 @@
package com.willfp.eco.internal.factory;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.factory.NamespacedKeyFactory;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.NotNull;
public class EcoNamespacedKeyFactory extends PluginDependent implements NamespacedKeyFactory {
/**
* Factory class to produce {@link NamespacedKey}s associated with an {@link EcoPlugin}.
*
* @param plugin The plugin that this factory creates keys for.
*/
public EcoNamespacedKeyFactory(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@Override
public NamespacedKey create(@NotNull final String key) {
return new NamespacedKey(this.getPlugin(), key);
}
}

View File

@@ -0,0 +1,31 @@
package com.willfp.eco.internal.factory;
import com.willfp.eco.core.factory.RunnableFactory;
import com.willfp.eco.core.scheduling.RunnableTask;
import com.willfp.eco.internal.scheduling.EcoRunnableTask;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
public class EcoRunnableFactory extends PluginDependent implements RunnableFactory {
/**
* Factory class to produce {@link RunnableTask}s associated with an {@link EcoPlugin}.
*
* @param plugin The plugin that this factory creates runnables for.
*/
public EcoRunnableFactory(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@Override
public RunnableTask create(@NotNull final Consumer<RunnableTask> consumer) {
return new EcoRunnableTask(this.getPlugin()) {
@Override
public void run() {
consumer.accept(this);
}
};
}
}

View File

@@ -1,8 +1,8 @@
package com.willfp.eco.util.integrations.placeholder.plugins;
package com.willfp.eco.internal.integrations;
import com.willfp.eco.util.integrations.placeholder.PlaceholderIntegration;
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration;
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
@@ -13,14 +13,14 @@ public class PlaceholderIntegrationPAPI extends PlaceholderExpansion implements
/**
* The linked plugin.
*/
private final AbstractEcoPlugin plugin;
private final EcoPlugin plugin;
/**
* Create a new PlaceholderAPI integration.
*
* @param plugin The plugin to manage placeholders for.
*/
public PlaceholderIntegrationPAPI(@NotNull final AbstractEcoPlugin plugin) {
public PlaceholderIntegrationPAPI(@NotNull final EcoPlugin plugin) {
this.plugin = plugin;
}
@@ -36,7 +36,7 @@ public class PlaceholderIntegrationPAPI extends PlaceholderExpansion implements
@Override
public @NotNull String getAuthor() {
return "Auxilor";
return String.join(", ", plugin.getDescription().getAuthors());
}
@Override

View File

@@ -0,0 +1,32 @@
package com.willfp.eco.internal.logging;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.util.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.logging.Level;
import java.util.logging.Logger;
public class EcoLogger extends Logger {
public EcoLogger(@NotNull final EcoPlugin plugin) {
super(plugin.getName(), (String) null);
String prefix = plugin.getDescription().getPrefix();
this.setParent(plugin.getServer().getLogger());
this.setLevel(Level.ALL);
}
@Override
public void info(@NotNull final String msg) {
super.info(StringUtils.translate(msg));
}
@Override
public void warning(@NotNull final String msg) {
super.warning(StringUtils.translate(msg));
}
@Override
public void severe(@NotNull final String msg) {
super.severe(StringUtils.translate(msg));
}
}

View File

@@ -0,0 +1,73 @@
package com.willfp.eco.internal.scheduling;
import com.willfp.eco.internal.factory.EcoRunnableFactory;
import com.willfp.eco.core.scheduling.RunnableTask;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
public abstract class EcoRunnableTask extends BukkitRunnable implements RunnableTask {
/**
* The linked {@link EcoPlugin} to associate runnables with.
*/
private final EcoPlugin plugin;
/**
* Creates a new {@link EcoRunnableTask}.
* <p>
* Cannot be instantiated normally, use {@link EcoRunnableFactory}.
*
* @param plugin The {@link EcoPlugin} to associate runnables with.
*/
@ApiStatus.Internal
public EcoRunnableTask(@NotNull final EcoPlugin plugin) {
this.plugin = plugin;
}
/**
* Get the {@link EcoPlugin} that created this runnable.
*
* @return The linked plugin.
*/
protected final EcoPlugin getPlugin() {
return this.plugin;
}
@Override
@NotNull
public final synchronized BukkitTask runTask() {
return super.runTask(plugin);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskAsynchronously() {
return super.runTaskAsynchronously(plugin);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskLater(final long delay) {
return super.runTaskLater(plugin, delay);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskLaterAsynchronously(final long delay) {
return super.runTaskLaterAsynchronously(plugin, delay);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskTimer(final long delay, final long period) {
return super.runTaskTimer(plugin, delay, period);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskTimerAsynchronously(final long delay, final long period) {
return super.runTaskTimerAsynchronously(plugin, delay, period);
}
}

View File

@@ -1,7 +1,8 @@
package com.willfp.eco.util.bukkit.scheduling;
package com.willfp.eco.internal.scheduling;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.scheduling.Scheduler;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.ApiStatus;
@@ -9,12 +10,12 @@ import org.jetbrains.annotations.NotNull;
public class EcoScheduler extends PluginDependent implements Scheduler {
/**
* Create a scheduler to manage the tasks of an {@link AbstractEcoPlugin}.
* Create a scheduler to manage the tasks of an {@link EcoPlugin}.
*
* @param plugin The plugin to manage.
*/
@ApiStatus.Internal
public EcoScheduler(@NotNull final AbstractEcoPlugin plugin) {
public EcoScheduler(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@@ -99,7 +100,7 @@ public class EcoScheduler extends PluginDependent implements Scheduler {
}
/**
* Cancel all running tasks from the linked {@link AbstractEcoPlugin}.
* Cancel all running tasks from the linked {@link EcoPlugin}.
*/
@Override
public void cancelAll() {

View File

@@ -0,0 +1,96 @@
package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
@UtilityClass
public class BlockUtils {
/**
* If the meta set function has been set.
*/
private boolean initialized = false;
/**
* The block break function.
*/
private BiConsumer<Player, Block> blockBreakConsumer = null;
private Set<Block> getNearbyBlocks(@NotNull final Block start,
@NotNull final List<Material> allowedMaterials,
@NotNull final Set<Block> blocks,
final int limit) {
for (BlockFace face : BlockFace.values()) {
Block block = start.getRelative(face);
if (!blocks.contains(block) && allowedMaterials.contains(block.getType())) {
blocks.add(block);
if (blocks.size() > limit || blocks.size() > 2500) {
return blocks;
}
}
}
// Running twice to get more spherical shape.
for (BlockFace face : BlockFace.values()) {
Block block = start.getRelative(face);
if (!blocks.contains(block) && allowedMaterials.contains(block.getType())) {
if (blocks.size() > limit || blocks.size() > 2500) {
return blocks;
}
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
}
}
return blocks;
}
/**
* Get a set of all blocks in contact with each other of a specific type.
*
* @param start The initial block.
* @param allowedMaterials A list of all valid {@link Material}s.
* @param limit The maximum size of vein to return.
* @return A set of all {@link Block}s.
*/
public Set<Block> getVein(@NotNull final Block start,
@NotNull final List<Material> allowedMaterials,
final int limit) {
return getNearbyBlocks(start, allowedMaterials, new HashSet<>(), limit);
}
/**
* Break the block as if the player had done it manually.
*
* @param player The player to break the block as.
* @param block The block to break.
*/
public void breakBlock(@NotNull final Player player,
@NotNull final Block block) {
Validate.isTrue(initialized, "Must be initialized!");
Validate.notNull(blockBreakConsumer, "Must be initialized!");
blockBreakConsumer.accept(player, block);
}
/**
* Initialize the block break function.
*
* @param function The function.
*/
@ApiStatus.Internal
public void initialize(@NotNull final BiConsumer<Player, Block> function) {
Validate.isTrue(!initialized, "Already initialized!");
blockBreakConsumer = function;
initialized = true;
}
}

View File

@@ -2,6 +2,7 @@ package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.entity.Player;
@@ -37,25 +38,32 @@ public class DurabilityUtils {
return;
}
if (!(item.getItemMeta() instanceof Damageable)) {
return;
}
// Special edge case
if (item.getType() == Material.CARVED_PUMPKIN || item.getType() == Material.PLAYER_HEAD) {
return;
}
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
Bukkit.getPluginManager().callEvent(event3);
if (!event3.isCancelled()) {
int damage2 = event3.getDamage();
if (item.getItemMeta() instanceof Damageable) {
Damageable meta = (Damageable) item.getItemMeta();
meta.setDamage(meta.getDamage() + damage2);
Damageable meta = (Damageable) item.getItemMeta();
meta.setDamage(meta.getDamage() + damage2);
if (meta.getDamage() >= item.getType().getMaxDurability()) {
meta.setDamage(item.getType().getMaxDurability());
item.setItemMeta((ItemMeta) meta);
PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item);
Bukkit.getPluginManager().callEvent(event);
player.getInventory().clear(slot);
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1);
} else {
item.setItemMeta((ItemMeta) meta);
}
if (meta.getDamage() >= item.getType().getMaxDurability()) {
meta.setDamage(item.getType().getMaxDurability());
item.setItemMeta((ItemMeta) meta);
PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item);
Bukkit.getPluginManager().callEvent(event);
player.getInventory().clear(slot);
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1);
} else {
item.setItemMeta((ItemMeta) meta);
}
}
}
@@ -78,20 +86,22 @@ public class DurabilityUtils {
return;
}
if (!(item.getItemMeta() instanceof Damageable)) {
return;
}
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
Bukkit.getPluginManager().callEvent(event3);
if (!event3.isCancelled()) {
int damage2 = event3.getDamage();
if (item.getItemMeta() instanceof Damageable) {
Damageable meta = (Damageable) item.getItemMeta();
meta.setDamage(meta.getDamage() + damage2);
Damageable meta = (Damageable) item.getItemMeta();
meta.setDamage(meta.getDamage() + damage2);
if (meta.getDamage() >= item.getType().getMaxDurability()) {
meta.setDamage(item.getType().getMaxDurability() - 1);
}
item.setItemMeta((ItemMeta) meta);
if (meta.getDamage() >= item.getType().getMaxDurability()) {
meta.setDamage(item.getType().getMaxDurability() - 1);
}
item.setItemMeta((ItemMeta) meta);
}
}

View File

@@ -1,13 +1,30 @@
package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
import java.text.DecimalFormat;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ThreadLocalRandom;
@UtilityClass
public class NumberUtils {
/**
* Precision.
*/
private static final int FAST_TRIG_PRECISION = 100;
/**
* Modulus.
*/
private static final int FAST_TRIG_MODULUS = 360 * FAST_TRIG_PRECISION;
/**
* Sin lookup table.
*/
private static final double[] SIN_LOOKUP = new double[FAST_TRIG_MODULUS];
/**
* Set of roman numerals to look up.
*/
@@ -27,6 +44,34 @@ public class NumberUtils {
NUMERALS.put(5, "V");
NUMERALS.put(4, "IV");
NUMERALS.put(1, "I");
for (int i = 0; i < SIN_LOOKUP.length; i++) {
SIN_LOOKUP[i] = Math.sin((i * Math.PI) / (FAST_TRIG_PRECISION * 180));
}
}
private static double sinLookup(final int a) {
return a >= 0 ? SIN_LOOKUP[a % FAST_TRIG_MODULUS] : -SIN_LOOKUP[-a % FAST_TRIG_MODULUS];
}
/**
* Get the sin of a number.
*
* @param a The number.
* @return The sin.
*/
public static double fastSin(final double a) {
return sinLookup((int) (a * FAST_TRIG_PRECISION + 0.5f));
}
/**
* Get the cosine of a number.
*
* @param a The number.
* @return The cosine.
*/
public static double fastCos(final double a) {
return sinLookup((int) ((a + 90f) * FAST_TRIG_PRECISION + 0.5f));
}
/**
@@ -85,6 +130,24 @@ public class NumberUtils {
}
}
/**
* Get number from roman numeral.
*
* @param numeral The numeral to convert.
* @return The number, converted from a roman numeral.
*/
public static int fromNumeral(@NotNull final String numeral) {
if (numeral.isEmpty()) {
return 0;
}
for (Map.Entry<Integer, String> entry : NUMERALS.entrySet()) {
if (numeral.startsWith(entry.getValue())) {
return entry.getKey() + fromNumeral(numeral.substring(entry.getValue().length()));
}
}
return 0;
}
/**
* Generate random integer in range.
*

View File

@@ -0,0 +1,49 @@
package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang.Validate;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.function.BiConsumer;
@UtilityClass
public class SkullUtils {
/**
* If the meta set function has been set.
*/
private boolean initialized = false;
/**
* The meta set function.
*/
private BiConsumer<SkullMeta, String> metaSetConsumer = null;
/**
* Set the texture of a skull from base64.
*
* @param meta The meta to modify.
* @param base64 The base64 texture.
*/
public void setSkullTexture(@NotNull final SkullMeta meta,
@NotNull final String base64) {
Validate.isTrue(initialized, "Must be initialized!");
Validate.notNull(metaSetConsumer, "Must be initialized!");
metaSetConsumer.accept(meta, base64);
}
/**
* Initialize the skull texture function.
*
* @param function The function.
*/
@ApiStatus.Internal
public void initialize(@NotNull final BiConsumer<SkullMeta, String> function) {
Validate.isTrue(!initialized, "Already initialized!");
metaSetConsumer = function;
initialized = true;
}
}

View File

@@ -0,0 +1,223 @@
package com.willfp.eco.util;
import com.google.common.collect.ImmutableList;
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static net.md_5.bungee.api.ChatColor.COLOR_CHAR;
@UtilityClass
public class StringUtils {
/**
* Regexes for gradients.
*/
private static final List<Pattern> GRADIENT_PATTERNS = new ImmutableList.Builder<Pattern>()
.add(Pattern.compile("<GRADIENT:([0-9A-Fa-f]{6})>(.*?)</GRADIENT:([0-9A-Fa-f]{6})>"))
.add(Pattern.compile("<G:([0-9A-Fa-f]{6})>(.*?)</G:([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();
/**
* Regexes for hex codes.
*/
private static final List<Pattern> HEX_PATTERNS = new ImmutableList.Builder<Pattern>()
.add(Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + ""))
.add(Pattern.compile("\\{#" + "([A-Fa-f0-9]{6})" + "}"))
.add(Pattern.compile("<#" + "([A-Fa-f0-9]{6})" + ">"))
.build();
/**
* Translate a string - converts Placeholders and Color codes.
*
* @param message The message to translate.
* @param player The player to translate placeholders with respect to.
* @return The message, translated.
*/
public String translate(@NotNull final String message,
@Nullable final Player player) {
String processedMessage = message;
processedMessage = translateGradients(processedMessage);
processedMessage = PlaceholderManager.translatePlaceholders(processedMessage, player);
processedMessage = translateHexColorCodes(processedMessage);
processedMessage = ChatColor.translateAlternateColorCodes('&', processedMessage);
return processedMessage;
}
/**
* Translate a string without respect to a player.
*
* @param message The message to translate.
* @return The message, translated.
* @see StringUtils#translate(String, Player)
*/
public String translate(@NotNull final String message) {
return translate(message, null);
}
private static String translateHexColorCodes(@NotNull final String message) {
String processedMessage = message;
for (Pattern pattern : HEX_PATTERNS) {
processedMessage = translateHexColorCodes(processedMessage, pattern);
}
return processedMessage;
}
private static String translateHexColorCodes(@NotNull final String message,
@NotNull final Pattern pattern) {
Matcher matcher = pattern.matcher(message);
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
while (matcher.find()) {
String group = matcher.group(1);
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5));
}
return matcher.appendTail(buffer).toString();
}
/**
* Colors a string with a gradient.
*
* @param string The string to color.
* @param start The start color.
* @param end The end color.
* @return The string, colored.
*/
private static String processGradients(@NotNull final String string,
@NotNull final Color start,
@NotNull final Color end) {
String processedString = string;
List<ChatColor> modifiers = new ArrayList<>();
if (processedString.contains("&l")) {
modifiers.add(ChatColor.BOLD);
}
if (processedString.contains("&o")) {
modifiers.add(ChatColor.ITALIC);
}
if (processedString.contains("&n")) {
modifiers.add(ChatColor.UNDERLINE);
}
if (processedString.contains("&k")) {
modifiers.add(ChatColor.MAGIC);
}
processedString = processedString.replace("&l", "");
processedString = processedString.replace("&o", "");
processedString = processedString.replace("&n", "");
processedString = processedString.replace("&k", "");
StringBuilder stringBuilder = new StringBuilder();
ChatColor[] colors = getGradientColors(start, end, processedString.length());
String[] characters = processedString.split("");
for (int i = 0; i < processedString.length(); i++) {
stringBuilder.append(colors[i]);
modifiers.forEach(stringBuilder::append);
stringBuilder.append(characters[i]);
}
return stringBuilder.toString();
}
/**
* Creates chatColors for gradients.
*
* @param start The start color.
* @param end The end color.
* @param step How many colors are returned.
* @return Array of chat colors.
*/
private static ChatColor[] getGradientColors(@NotNull final Color start,
@NotNull final Color end,
final int step) {
ChatColor[] colors = new ChatColor[step];
int stepR = Math.abs(start.getRed() - end.getRed()) / (step - 1);
int stepG = Math.abs(start.getGreen() - end.getGreen()) / (step - 1);
int stepB = Math.abs(start.getBlue() - end.getBlue()) / (step - 1);
int[] direction = new int[]{
start.getRed() < end.getRed() ? +1 : -1,
start.getGreen() < end.getGreen() ? +1 : -1,
start.getBlue() < end.getBlue() ? +1 : -1
};
for (int i = 0; i < step; i++) {
Color color = new Color(start.getRed() + ((stepR * i) * direction[0]), start.getGreen() + ((stepG * i) * direction[1]), start.getBlue() + ((stepB * i) * direction[2]));
colors[i] = ChatColor.of(color);
}
return colors;
}
/**
* Add gradients to a string.
*
* @param string The string.
* @return The string, colorized.
*/
private static String translateGradients(@NotNull final String string) {
String processedString = string;
for (Pattern pattern : GRADIENT_PATTERNS) {
Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
String start = matcher.group(1);
String end = matcher.group(3);
String content = matcher.group(2);
processedString = processedString.replace(matcher.group(), processGradients(content, new Color(Integer.parseInt(start, 16)), new Color(Integer.parseInt(end, 16))));
}
}
return processedString;
}
/**
* Internal implementation of {@link String#valueOf}.
* Formats collections and doubles better.
*
* @param object The object to convert to string.
* @return The object stringified.
*/
public String internalToString(@Nullable final Object object) {
if (object == null) {
return "null";
}
if (object instanceof Integer) {
return ((Integer) object).toString();
} else if (object instanceof String) {
return (String) object;
} else if (object instanceof Double) {
return NumberUtils.format((Double) object);
} else if (object instanceof Collection<?>) {
Collection<?> c = (Collection<?>) object;
return c.stream().map(StringUtils::internalToString).collect(Collectors.joining(", "));
} else {
return String.valueOf(object);
}
}
/**
* Remove a string of characters from the start of a string.
*
* @param string The string to remove the prefix from.
* @param prefix The substring to remove.
* @return The string with the prefix removed.
*/
public String removePrefix(@NotNull final String string,
@NotNull final String prefix) {
if (string.startsWith(prefix)) {
return string.substring(prefix.length());
}
return string;
}
}

View File

@@ -2,7 +2,6 @@ package com.willfp.eco.util;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.willfp.eco.util.optional.Prerequisite;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -45,10 +44,10 @@ public class TeamUtils {
Team team;
if (!SCOREBOARD.getTeams().stream().map(Team::getName).collect(Collectors.toList()).contains("EE-" + color.name())) {
team = SCOREBOARD.registerNewTeam("EE-" + color.name());
if (!SCOREBOARD.getTeams().stream().map(Team::getName).collect(Collectors.toList()).contains("EC-" + color.name())) {
team = SCOREBOARD.registerNewTeam("EC-" + color.name());
} else {
team = SCOREBOARD.getTeam("EE-" + color.name());
team = SCOREBOARD.getTeam("EC-" + color.name());
}
assert team != null;
team.setColor(color);
@@ -80,9 +79,6 @@ public class TeamUtils {
MATERIAL_COLORS.forcePut(Material.LAPIS_ORE, ChatColor.BLUE);
MATERIAL_COLORS.forcePut(Material.REDSTONE_ORE, ChatColor.RED);
MATERIAL_COLORS.forcePut(Material.DIAMOND_ORE, ChatColor.AQUA);
if (Prerequisite.MINIMUM_1_16.isMet()) {
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
}
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
}
}

View File

@@ -1,5 +1,6 @@
package com.willfp.eco.util.drops.telekinesis;
package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -7,20 +8,20 @@ import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
public class EcoTelekinesisTests implements TelekinesisTests {
@UtilityClass
public final class TelekinesisUtils {
/**
* Set of tests that return if the player is telekinetic.
*/
private final Set<Function<Player, Boolean>> tests = new HashSet<>();
private static final Set<Function<Player, Boolean>> TESTS = new HashSet<>();
/**
* Register a new test to check against.
*
* @param test The test to register, where the boolean output is if the player is telekinetic.
*/
@Override
public void registerTest(@NotNull final Function<Player, Boolean> test) {
tests.add(test);
TESTS.add(test);
}
/**
@@ -31,9 +32,8 @@ public class EcoTelekinesisTests implements TelekinesisTests {
* @param player The player to test.
* @return If the player is telekinetic.
*/
@Override
public boolean testPlayer(@NotNull final Player player) {
for (Function<Player, Boolean> test : tests) {
for (Function<Player, Boolean> test : TESTS) {
if (test.apply(player)) {
return true;
}

View File

@@ -0,0 +1,49 @@
package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.Trident;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.function.Function;
@UtilityClass
public class TridentUtils {
/**
* If the meta set function has been set.
*/
private boolean initialized = false;
/**
* The meta set function.
*/
private Function<Trident, ItemStack> tridentFunction = null;
/**
* Get a trident's ItemStack.
*
* @param trident The trident to query.
* @return The trident's ItemStack.
*/
public ItemStack getItemStack(@NotNull final Trident trident) {
Validate.isTrue(initialized, "Must be initialized!");
Validate.notNull(tridentFunction, "Must be initialized!");
return tridentFunction.apply(trident);
}
/**
* Initialize the trident function.
*
* @param function The function.
*/
@ApiStatus.Internal
public void initialize(@NotNull final Function<Trident, ItemStack> function) {
Validate.isTrue(!initialized, "Already initialized!");
tridentFunction = function;
initialized = true;
}
}

View File

@@ -6,9 +6,17 @@ import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@UtilityClass
public class VectorUtils {
/**
* Cached circles to prevent many sqrt calls.
*/
private static final Map<Integer, Vector[]> CIRCLE_CACHE = new HashMap<>();
/**
* If vector has all components as finite.
*
@@ -66,7 +74,12 @@ public class VectorUtils {
* @return An array of {@link Vector}s.
*/
public Vector[] getCircle(final int radius) {
ArrayList<Vector> circleVecs = new ArrayList<>();
Vector[] cached = CIRCLE_CACHE.get(radius);
if (cached != null) {
return cached;
}
List<Vector> vectors = new ArrayList<>();
double xoffset = -radius;
double zoffset = -radius;
@@ -74,7 +87,7 @@ public class VectorUtils {
while (zoffset <= radius) {
while (xoffset <= radius) {
if (Math.round(Math.sqrt((xoffset * xoffset) + (zoffset * zoffset))) <= radius) {
circleVecs.add(new Vector(xoffset, 0, zoffset));
vectors.add(new Vector(xoffset, 0, zoffset));
} else {
xoffset++;
continue;
@@ -85,7 +98,9 @@ public class VectorUtils {
zoffset++;
}
return circleVecs.toArray(new Vector[0]);
Vector[] result = vectors.toArray(new Vector[0]);
CIRCLE_CACHE.put(radius, result);
return result;
}
/**
@@ -95,21 +110,21 @@ public class VectorUtils {
* @return An array of {@link Vector}s.
*/
public Vector[] getSquare(final int radius) {
ArrayList<Vector> circleVecs = new ArrayList<>();
List<Vector> vectors = new ArrayList<>();
int xoffset = -radius;
int zoffset = -radius;
while (zoffset <= radius) {
while (xoffset <= radius) {
circleVecs.add(new Vector(xoffset, 0, zoffset));
vectors.add(new Vector(xoffset, 0, zoffset));
xoffset++;
}
xoffset = -radius;
zoffset++;
}
return circleVecs.toArray(new Vector[0]);
return vectors.toArray(new Vector[0]);
}
/**
@@ -119,16 +134,16 @@ public class VectorUtils {
* @return An array of {@link Vector}s.
*/
public Vector[] getCube(final int radius) {
ArrayList<Vector> cubeVecs = new ArrayList<>();
List<Vector> vectors = new ArrayList<>();
for (int y = -radius; y <= radius; y++) {
for (int z = -radius; z <= radius; z++) {
for (int x = -radius; x <= radius; x++) {
cubeVecs.add(new Vector(x, y, z));
vectors.add(new Vector(x, y, z));
}
}
}
return cubeVecs.toArray(new Vector[0]);
return vectors.toArray(new Vector[0]);
}
}

8
eco-core/build.gradle Normal file
View File

@@ -0,0 +1,8 @@
group 'com.willfp'
version rootProject.version
subprojects {
dependencies {
compileOnly project(":eco-api")
}
}

View File

@@ -0,0 +1,9 @@
group 'com.willfp'
version rootProject.version
subprojects {
dependencies {
compileOnly project(':eco-core:core-proxy')
compileOnly project(':eco-core:core-plugin')
}
}

View File

@@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT'
}

View File

@@ -0,0 +1,19 @@
package com.willfp.eco.proxy.v1_16_R1;
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
import net.minecraft.server.v1_16_R1.MinecraftKey;
import net.minecraft.server.v1_16_R1.PacketPlayOutAutoRecipe;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
public final class AutoCraft implements AutoCraftProxy {
@Override
public void modifyPacket(@NotNull final Object packet) throws NoSuchFieldException, IllegalAccessException {
PacketPlayOutAutoRecipe recipePacket = (PacketPlayOutAutoRecipe) packet;
Field fKey = recipePacket.getClass().getDeclaredField("b");
fKey.setAccessible(true);
MinecraftKey key = (MinecraftKey) fKey.get(recipePacket);
fKey.set(recipePacket, new MinecraftKey(key.getNamespace(), key.getKey() + "_displayed"));
}
}

View File

@@ -0,0 +1,16 @@
package com.willfp.eco.proxy.v1_16_R1;
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
import net.minecraft.server.v1_16_R1.BlockPosition;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public final class BlockBreak implements BlockBreakProxy {
@Override
public void breakBlock(@NotNull final Player player,
@NotNull final Block block) {
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
}
}

Some files were not shown because too many files have changed in this diff Show More