Compare commits
311 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
726f4a44c4 | ||
|
|
eafae209a6 | ||
|
|
04c450b46a | ||
|
|
d4e1f58f2a | ||
|
|
b0806b934b | ||
|
|
a21ecfbdde | ||
|
|
f3a6861bc6 | ||
|
|
eaa295e6a3 | ||
|
|
399387eca1 | ||
|
|
272f551aae | ||
|
|
d8c5fc0959 | ||
|
|
d1ca106d01 | ||
|
|
99f5174e28 | ||
|
|
d9f4aee384 | ||
|
|
c2aae8c2eb | ||
|
|
52061b7b51 | ||
|
|
762969c172 | ||
|
|
62d5cf885f | ||
|
|
1e70a9fdea | ||
|
|
ec8a65b4f8 | ||
|
|
a163219372 | ||
|
|
4d6e097f8f | ||
|
|
497adbe7b1 | ||
|
|
78907412b2 | ||
|
|
d6bec5d88b | ||
|
|
aab1f31ca0 | ||
|
|
5ea586eaae | ||
|
|
2ffc293211 | ||
|
|
88bedef420 | ||
|
|
dac5ffce9a | ||
|
|
d641adadea | ||
|
|
46269354c6 | ||
|
|
2d93465d1d | ||
|
|
484d4dde75 | ||
|
|
5e9a408704 | ||
|
|
f1b113f435 | ||
|
|
5d553d725c | ||
|
|
a3be846083 | ||
|
|
54e0b3f482 | ||
|
|
93794fe454 | ||
|
|
7f4a0c800e | ||
|
|
853864f6f0 | ||
|
|
0cb6e8f669 | ||
|
|
d30f657eec | ||
|
|
d60ecdd340 | ||
|
|
07310df68a | ||
|
|
5c91aa220a | ||
|
|
756a76057a | ||
|
|
b6f27ee232 | ||
|
|
74ca2e82ef | ||
|
|
4039439fda | ||
|
|
7dac671690 | ||
|
|
411d517a9a | ||
|
|
0d84141116 | ||
|
|
6bfd5bd153 | ||
|
|
b7d421e1a8 | ||
|
|
2e9d811d3f | ||
|
|
672b295917 | ||
|
|
60a83478e8 | ||
|
|
c880a476d4 | ||
|
|
692305d595 | ||
|
|
9d4cc2961c | ||
|
|
358b389875 | ||
|
|
7fa25c2500 | ||
|
|
91c58c4a53 | ||
|
|
4ccee91c64 | ||
|
|
eef87342a1 | ||
|
|
efc70ea7a8 | ||
|
|
de38299264 | ||
|
|
bc94f43299 | ||
|
|
ed705cc577 | ||
|
|
93410490c5 | ||
|
|
33914ac284 | ||
|
|
2acf2ee687 | ||
|
|
0470552168 | ||
|
|
3e724eea18 | ||
|
|
33ba5c9d31 | ||
|
|
94ab094952 | ||
|
|
58f5d3f352 | ||
|
|
912872e791 | ||
|
|
7a65e6e821 | ||
|
|
3f446f6072 | ||
|
|
50f57abd6c | ||
|
|
2c5eae6c6c | ||
|
|
1e3e54b8c5 | ||
|
|
0ce9119a94 | ||
|
|
bf76ba9f5a | ||
|
|
8a065bf7ca | ||
|
|
5f045d02a6 | ||
|
|
f07ef3045b | ||
|
|
007a579f5a | ||
|
|
9b19cd412a | ||
|
|
08b5cc1612 | ||
|
|
47aa61c7b3 | ||
|
|
ef1ee84358 | ||
|
|
49a36a4e81 | ||
|
|
bf76dec28e | ||
|
|
a0f51d79e8 | ||
|
|
9be516e511 | ||
|
|
a130935c62 | ||
|
|
4359bd17ae | ||
|
|
07726959e9 | ||
|
|
13c8187b3b | ||
|
|
be1267ef0c | ||
|
|
e61e9bc0a8 | ||
|
|
ec801cd776 | ||
|
|
a5b5bc6b46 | ||
|
|
f5efb50d71 | ||
|
|
d65c04aaa7 | ||
|
|
aa69d2a1a9 | ||
|
|
685cd5f998 | ||
|
|
bae4b567c8 | ||
|
|
0eb3315d61 | ||
|
|
0a42320b78 | ||
|
|
6ce0de8db7 | ||
|
|
345d4cd1b5 | ||
|
|
950c092025 | ||
|
|
0c6bb8c1b7 | ||
|
|
0f9cb7db7a | ||
|
|
7d4262e0ef | ||
|
|
e543be7a13 | ||
|
|
3d7027bf47 | ||
|
|
632b42ad65 | ||
|
|
bcd79e3886 | ||
|
|
8fbcf485b3 | ||
|
|
6a64be2e25 | ||
|
|
3f9f3991d8 | ||
|
|
54a8d942fa | ||
|
|
6aa14be577 | ||
|
|
d6db7673d8 | ||
|
|
d002073124 | ||
|
|
4bc98cae81 | ||
|
|
2696baf1d6 | ||
|
|
3c3cc36403 | ||
|
|
fd87683b6a | ||
|
|
83da1e7b95 | ||
|
|
9f9515675a | ||
|
|
1aa084cd90 | ||
|
|
525ec0260f | ||
|
|
ac15ffee6c | ||
|
|
83d68c5046 | ||
|
|
7d1186811f | ||
|
|
88bc01e5df | ||
|
|
78d2459c7a | ||
|
|
21f4bd79eb | ||
|
|
64147c6261 | ||
|
|
c67c486f2f | ||
|
|
ae419bacb3 | ||
|
|
17b0214f2f | ||
|
|
963f706018 | ||
|
|
74398cda62 | ||
|
|
8321af5af2 | ||
|
|
2524d86462 | ||
|
|
e050bf83df | ||
|
|
91c936a06f | ||
|
|
93dfd44410 | ||
|
|
304d0cdebf | ||
|
|
108d878939 | ||
|
|
e10e327c56 | ||
|
|
cabea9fba9 | ||
|
|
f9159cf245 | ||
|
|
2db011ae10 | ||
|
|
f96716966d | ||
|
|
7515efbde9 | ||
|
|
4ebd0d79d5 | ||
|
|
0c3b5d3c30 | ||
|
|
e0b06dedff | ||
|
|
187ac8163d | ||
|
|
ac2078957d | ||
|
|
352d495301 | ||
|
|
864456e61e | ||
|
|
bd7ce1cf3c | ||
|
|
9565ab0641 | ||
|
|
45c53b96dc | ||
|
|
861325ac3f | ||
|
|
70c015c1f0 | ||
|
|
8f3755b130 | ||
|
|
697ff0ccbb | ||
|
|
f117847fc3 | ||
|
|
bd88d40309 | ||
|
|
2fd8aab230 | ||
|
|
5ec10ec617 | ||
|
|
270270d015 | ||
|
|
3364b01c9d | ||
|
|
4beda35adf | ||
|
|
fd3e79378b | ||
|
|
4d0068e551 | ||
|
|
6933c0e5ef | ||
|
|
839b3724e7 | ||
|
|
6006865358 | ||
|
|
4907b4b6e6 | ||
|
|
29735cdf83 | ||
|
|
ae4b2ce0d0 | ||
|
|
786cbbcd7d | ||
|
|
6d3f2fc5dc | ||
|
|
6697cc412e | ||
|
|
17a877a89a | ||
|
|
9d4149c58f | ||
|
|
123ac79918 | ||
|
|
1670c8b3fb | ||
|
|
6125044e4c | ||
|
|
492439470c | ||
|
|
e9e39345ed | ||
|
|
cf29df7bce | ||
|
|
c259cb5a45 | ||
|
|
4148f55bb5 | ||
|
|
b63791c14b | ||
|
|
294dfabd54 | ||
|
|
d7f7cad863 | ||
|
|
afd8df5b48 | ||
|
|
b9d1f36604 | ||
|
|
403a7a7da8 | ||
|
|
f6fb5bcf66 | ||
|
|
194eb8b5f5 | ||
|
|
853aaca071 | ||
|
|
18dabd6bcf | ||
|
|
bb42505d66 | ||
|
|
b4d59077e3 | ||
|
|
104d55c11b | ||
|
|
b5af17cf08 | ||
|
|
78ae662ced | ||
|
|
32e48db3ce | ||
|
|
8a27e75c02 | ||
|
|
bf55e9b189 | ||
|
|
bfbaa3d033 | ||
|
|
64f87d5741 | ||
|
|
cb3441286c | ||
|
|
5e97a0f894 | ||
|
|
de2166dfdb | ||
|
|
abd361f4b5 | ||
|
|
422f8ead23 | ||
|
|
7c05dd7457 | ||
|
|
3ef7622c6f | ||
|
|
8207d62b1f | ||
|
|
75a0b1dd0d | ||
|
|
d1307e35db | ||
|
|
0a6b197a97 | ||
|
|
8d6512886c | ||
|
|
5c0c0f3e2a | ||
|
|
e2c2fc776a | ||
|
|
576050b31e | ||
|
|
f9a43bd336 | ||
|
|
203f2f599a | ||
|
|
baa5d37744 | ||
|
|
17f6af2a70 | ||
|
|
eae213f58e | ||
|
|
3a6a133560 | ||
|
|
57cf144c57 | ||
|
|
5c29859d49 | ||
|
|
02510127d1 | ||
|
|
f6b5c8f7e0 | ||
|
|
dbfef3094b | ||
|
|
b5c3af752c | ||
|
|
d0366b39e2 | ||
|
|
ed5390d2b5 | ||
|
|
e31857a15d | ||
|
|
32e119d187 | ||
|
|
5690eccd14 | ||
|
|
2faf3732df | ||
|
|
8670fb36e0 | ||
|
|
7c001c4809 | ||
|
|
bce1dd9fee | ||
|
|
412c2e1e3c | ||
|
|
dd7ffac974 | ||
|
|
7ad59e0166 | ||
|
|
2f2bdbb9f5 | ||
|
|
d23dc10bc5 | ||
|
|
46c2e3f90a | ||
|
|
1776b668a4 | ||
|
|
10dccd0f38 | ||
|
|
f1918eb1ec | ||
|
|
436b33fde2 | ||
|
|
cfa5cab1fa | ||
|
|
a8ba4dd812 | ||
|
|
94bf383d23 | ||
|
|
096207de82 | ||
|
|
3cb654f5df | ||
|
|
5552cc4fb0 | ||
|
|
94aacf8cca | ||
|
|
128d473b33 | ||
|
|
d5679dd58f | ||
|
|
b1e8165ecb | ||
|
|
d0a3d644f3 | ||
|
|
35b060af53 | ||
|
|
337dba23b4 | ||
|
|
433f9f53ab | ||
|
|
ba7a748efd | ||
|
|
1365fdae88 | ||
|
|
6a159bf049 | ||
|
|
31e0e93951 | ||
|
|
876343facb | ||
|
|
f0cd9ae16d | ||
|
|
b220428b8c | ||
|
|
8386aacfd8 | ||
|
|
3c54e24102 | ||
|
|
3dc0693b8c | ||
|
|
f087113ddf | ||
|
|
d5d1f5d8cc | ||
|
|
0d5bf901e2 | ||
|
|
ae0445f47b | ||
|
|
a6ba24b7a5 | ||
|
|
1b00831147 | ||
|
|
479cff60d5 | ||
|
|
d2499b1e27 | ||
|
|
4f65f33953 | ||
|
|
6d4a69c781 | ||
|
|
e90e58b50a | ||
|
|
826bdb63d0 | ||
|
|
4ecba69161 | ||
|
|
e64510ebf5 | ||
|
|
50a506af62 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -14,7 +14,7 @@ bin/
|
||||
# Gradle
|
||||
.gradle
|
||||
**/build/
|
||||
!src/**/build/
|
||||
!eco-api/src/**/build/
|
||||
.gradletasknamecache
|
||||
!gradle-wrapper.jar
|
||||
gradle-app.setting
|
||||
|
||||
156
build.gradle
156
build.gradle
@@ -1,102 +1,102 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'com.github.johnrengelman.shadow' version '5.2.0'
|
||||
id 'com.github.johnrengelman.shadow' version '7.0.0'
|
||||
id 'maven-publish'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
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()
|
||||
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.20'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.20'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||
}
|
||||
|
||||
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() }
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
}
|
||||
|
||||
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 = '3.0.1'
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
version = findProperty("version")
|
||||
@@ -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"/>
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
"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"/>
|
||||
<suppress files="[\\/]eco[\\/]spigot[\\/]" checks="MissingJavadocMethod"/>
|
||||
<suppress files="[\\/]eco[\\/]spigot[\\/]" checks="JavadocVariable"/>
|
||||
|
||||
<!-- Modified version of library -->
|
||||
<suppress files="ArmorEquipEvent.java" checks="JavadocVariable"/>
|
||||
<suppress files="ArmorEquipEvent.java" checks="MissingJavadocMethod"/>
|
||||
|
||||
29
eco-api/build.gradle
Normal file
29
eco-api/build.gradle
Normal file
@@ -0,0 +1,29 @@
|
||||
plugins {
|
||||
id 'com.github.johnrengelman.shadow'
|
||||
}
|
||||
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.17-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'
|
||||
compileOnly 'com.google.code.gson:gson:2.8.7'
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
build.dependsOn publishToMavenLocal
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
shadow(MavenPublication) {
|
||||
from components.java
|
||||
artifactId 'eco'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,7 +6,6 @@ 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;
|
||||
@@ -35,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) {
|
||||
@@ -51,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);
|
||||
@@ -79,6 +78,32 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
// Empty rather than abstract as implementations don't need both
|
||||
}
|
||||
|
||||
/**
|
||||
* The code that should be executed once the packet has been received.
|
||||
*
|
||||
* @param packet The packet.
|
||||
* @param player The player.
|
||||
* @param event The event.
|
||||
*/
|
||||
public void onReceive(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player,
|
||||
@NotNull final PacketEvent event) {
|
||||
// Empty rather than abstract as implementations don't need both
|
||||
}
|
||||
|
||||
/**
|
||||
* THe code that should be executed once the packet has been sent.
|
||||
*
|
||||
* @param packet The packet.
|
||||
* @param player The player.
|
||||
* @param event The event.
|
||||
*/
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player,
|
||||
@NotNull final PacketEvent event) {
|
||||
// Empty rather than abstract as implementations don't need both
|
||||
}
|
||||
|
||||
/**
|
||||
* Boilerplate to assert that the packet is of the specified type.
|
||||
*
|
||||
@@ -95,6 +120,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
}
|
||||
|
||||
onReceive(event.getPacket(), event.getPlayer());
|
||||
onReceive(event.getPacket(), event.getPlayer(), event);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,6 +139,12 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
}
|
||||
|
||||
onSend(event.getPacket(), event.getPlayer());
|
||||
onSend(event.getPacket(), event.getPlayer(), event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final EcoPlugin getPlugin() {
|
||||
return (EcoPlugin) super.getPlugin();
|
||||
}
|
||||
|
||||
/**
|
||||
690
eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java
Normal file
690
eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java
Normal file
@@ -0,0 +1,690 @@
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import com.willfp.eco.core.config.ConfigHandler;
|
||||
import com.willfp.eco.core.config.base.ConfigYml;
|
||||
import com.willfp.eco.core.config.base.LangYml;
|
||||
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.Internals;
|
||||
import com.willfp.eco.internal.UpdateChecker;
|
||||
import com.willfp.eco.internal.arrows.ArrowDataListener;
|
||||
import com.willfp.eco.internal.config.updating.EcoConfigHandler;
|
||||
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.commons.lang.Validate;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
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;
|
||||
|
||||
@SuppressWarnings({"deprecation", "DeprecatedIsStillUsed"})
|
||||
public abstract class EcoPlugin extends JavaPlugin {
|
||||
/**
|
||||
* Loaded eco plugins.
|
||||
*/
|
||||
public static final List<String> LOADED_ECO_PLUGINS = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The name of the plugin.
|
||||
*
|
||||
* @deprecated Pointless, use getName instead.
|
||||
*/
|
||||
@Getter
|
||||
@Deprecated
|
||||
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;
|
||||
|
||||
/**
|
||||
* If the plugin supports extensions.
|
||||
*/
|
||||
@Getter
|
||||
private final boolean supportingExtensions;
|
||||
|
||||
/**
|
||||
* Create a new plugin without a specified color, proxy support, spigot, or bStats.
|
||||
*/
|
||||
protected EcoPlugin() {
|
||||
this("&f");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without proxy support, spigot, or bStats.
|
||||
*
|
||||
* @param color The color.
|
||||
*/
|
||||
protected EcoPlugin(@NotNull final String color) {
|
||||
this("", color);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new plugin unlinked to spigot and bStats.
|
||||
*
|
||||
* @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 proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this(0, 0, proxyPackage, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without proxy or extension support.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
*/
|
||||
protected EcoPlugin(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String color) {
|
||||
this(resourceId, bStatsId, "", color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without proxy support.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
* @param supportingExtensions If the plugin supports extensions.
|
||||
*/
|
||||
protected EcoPlugin(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this(resourceId, bStatsId, "", color, supportingExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without extension support.
|
||||
*
|
||||
* @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(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this(resourceId, bStatsId, proxyPackage, color, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new 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)
|
||||
* @param supportingExtensions If the plugin supports extensions.
|
||||
*/
|
||||
protected EcoPlugin(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this("", resourceId, bStatsId, proxyPackage, color, supportingExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* @deprecated pluginName is redundant.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
protected EcoPlugin(@NotNull final String pluginName,
|
||||
final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this(pluginName, resourceId, bStatsId, proxyPackage, color, 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)
|
||||
* @param supportingExtensions If the plugin supports extensions.
|
||||
* @deprecated pluginName is redundant.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
protected EcoPlugin(@NotNull final String pluginName,
|
||||
final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this.pluginName = this.getName();
|
||||
this.resourceId = resourceId;
|
||||
this.bStatsId = bStatsId;
|
||||
this.proxyPackage = proxyPackage;
|
||||
this.color = color;
|
||||
this.supportingExtensions = supportingExtensions;
|
||||
|
||||
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 EcoConfigHandler(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.getColor() + this.getName());
|
||||
|
||||
this.getEventManager().registerListener(new ArrowDataListener(this));
|
||||
|
||||
if (this.getResourceId() != 0) {
|
||||
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.getName() + " 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
DefaultArtifactVersion runningVersion = new DefaultArtifactVersion(Internals.getInstance().getPlugin().getDescription().getVersion());
|
||||
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(this.getMinimumEcoVersion());
|
||||
if (!(runningVersion.compareTo(requiredVersion) > 0 || runningVersion.equals(requiredVersion))) {
|
||||
this.getLogger().severe("You are running an outdated version of eco!");
|
||||
this.getLogger().severe("You must be on at least" + this.getMinimumEcoVersion());
|
||||
this.getLogger().severe("Download the newest version here:");
|
||||
this.getLogger().severe("https://polymart.org/download/773/recent/JSpprMspkuyecf5y1wQ2Jn8OoLQSQ_IW");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
if (this.getBStatsId() != 0) {
|
||||
new Metrics(this, this.getBStatsId());
|
||||
}
|
||||
|
||||
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.getPluginCommands().forEach(PluginCommand::register);
|
||||
|
||||
this.getScheduler().runLater(this::afterLoad, 1);
|
||||
|
||||
this.updatableClasses.forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz));
|
||||
|
||||
if (this.isSupportingExtensions()) {
|
||||
this.getExtensionLoader().loadExtensions();
|
||||
|
||||
if (this.getExtensionLoader().getLoadedExtensions().isEmpty()) {
|
||||
this.getLogger().info("&cNo extensions found");
|
||||
} else {
|
||||
this.getLogger().info("Extensions Loaded:");
|
||||
this.getExtensionLoader().getLoadedExtensions().forEach(extension -> this.getLogger().info("- " + extension.getName() + " v" + extension.getVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
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.getConfigHandler().saveAllConfigs();
|
||||
|
||||
this.disable();
|
||||
|
||||
if (this.isSupportingExtensions()) {
|
||||
this.getExtensionLoader().unloadExtensions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.getConfigHandler().updateConfigs();
|
||||
|
||||
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.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public void enable() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on disable.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public void disable() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on load.
|
||||
* <p>
|
||||
* This is executed before enabling.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public void load() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on reload.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public void onReload() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed after the server is up.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public void postLoad() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific integrations to be tested and loaded.
|
||||
*
|
||||
* @return A list of integrations.
|
||||
*/
|
||||
public List<IntegrationLoader> getIntegrationLoaders() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* The commands to be registered.
|
||||
*
|
||||
* @return A list of commands.
|
||||
* @deprecated Use {@link this#getPluginCommands()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* The commands to be registered.
|
||||
*
|
||||
* @return A list of commands.
|
||||
*/
|
||||
public List<PluginCommand> getPluginCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 List<AbstractPacketAdapter> getPacketAdapters() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 List<Class<?>> getUpdatableClasses() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the display module for the plugin.
|
||||
*
|
||||
* @return The display module, or null.
|
||||
*/
|
||||
@Nullable
|
||||
protected DisplayModule createDisplayModule() {
|
||||
Validate.isTrue(
|
||||
this.getDisplayModule() == null,
|
||||
"Display module exists!"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum version of eco to use the plugin.
|
||||
*
|
||||
* @return The version.
|
||||
*/
|
||||
protected String getMinimumEcoVersion() {
|
||||
return "5.0.0";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin's logger.
|
||||
*
|
||||
* @return The logger.
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unwrapped config.
|
||||
* Does not use eco config system, don't use.
|
||||
*
|
||||
* @return The bukkit config.
|
||||
* @deprecated Use {@link EcoPlugin#getConfigYml()} instead.
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
@Deprecated
|
||||
public final FileConfiguration getConfig() {
|
||||
this.getLogger().warning("Call to default config method in eco plugin!");
|
||||
|
||||
return this.getConfigYml().getHandle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not use eco config system, don't use.
|
||||
*
|
||||
* @deprecated Use eco config system.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void saveConfig() {
|
||||
this.getLogger().warning("Call to default config method in eco plugin!");
|
||||
|
||||
super.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not use eco config system, don't use.
|
||||
*
|
||||
* @deprecated Use eco config system.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void saveDefaultConfig() {
|
||||
this.getLogger().warning("Call to default config method in eco plugin!");
|
||||
|
||||
super.saveDefaultConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not use eco config system, don't use.
|
||||
*
|
||||
* @deprecated Use eco config system.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void reloadConfig() {
|
||||
this.getLogger().warning("Call to default config method in eco plugin!");
|
||||
|
||||
super.reloadConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class PluginDependent<T extends EcoPlugin> {
|
||||
/**
|
||||
* The {@link EcoPlugin} that is stored.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final T plugin;
|
||||
|
||||
/**
|
||||
* Pass an {@link EcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
protected PluginDependent(@NotNull final T plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.willfp.eco.util.optional;
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.willfp.eco.core.proxy.ProxyConstants;
|
||||
import com.willfp.eco.util.ClassUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -16,14 +16,6 @@ public class Prerequisite {
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@@ -32,6 +24,23 @@ public class Prerequisite {
|
||||
"Requires server to be running paper (or a fork)"
|
||||
);
|
||||
|
||||
/**
|
||||
* Requires the server to be running 1.17.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Prerequisite v1_17 = new Prerequisite(
|
||||
() -> ProxyConstants.NMS_VERSION.contains("17"),
|
||||
"Requires server to be running 1.17+"
|
||||
);
|
||||
|
||||
/**
|
||||
* Requires the server to be running 1.17.
|
||||
*/
|
||||
public static final Prerequisite HAS_1_17 = new Prerequisite(
|
||||
() -> ProxyConstants.NMS_VERSION.contains("17"),
|
||||
"Requires server to be running 1.17+"
|
||||
);
|
||||
|
||||
/**
|
||||
* If the necessary prerequisite condition has been met.
|
||||
*/
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.willfp.eco.util.command;
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
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;
|
||||
@@ -15,7 +14,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand extends PluginDependent implements CommandExecutor, Registerable {
|
||||
@Deprecated
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
public abstract class AbstractCommand extends PluginDependent<EcoPlugin> implements CommandExecutor {
|
||||
/**
|
||||
* The name of the command
|
||||
* <p>
|
||||
@@ -44,12 +45,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) {
|
||||
@@ -99,7 +100,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,
|
||||
@@ -130,7 +131,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;
|
||||
@@ -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;
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
public abstract class AbstractTabCompleter implements TabCompleter {
|
||||
/**
|
||||
* The {@link AbstractCommand} that is tab-completed.
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CommandBase {
|
||||
/**
|
||||
* Get command name.
|
||||
*
|
||||
* @return The name.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get command permission.
|
||||
*
|
||||
* @return The permission.
|
||||
*/
|
||||
String getPermission();
|
||||
|
||||
/**
|
||||
* If only players can execute the command.
|
||||
*
|
||||
* @return If true.
|
||||
*/
|
||||
boolean isPlayersOnly();
|
||||
|
||||
/**
|
||||
* Add a subcommand to the command.
|
||||
*
|
||||
* @param command The subcommand.
|
||||
* @return The parent command.
|
||||
*/
|
||||
CommandBase addSubcommand(@NotNull CommandBase command);
|
||||
|
||||
/**
|
||||
* Get the handler.
|
||||
*
|
||||
* @return The handler.
|
||||
*/
|
||||
CommandHandler getHandler();
|
||||
|
||||
/**
|
||||
* Get the tab completer.
|
||||
*
|
||||
* @return The tab completer.
|
||||
*/
|
||||
TabCompleteHandler getTabCompleter();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CommandHandler {
|
||||
/**
|
||||
* The code to be called on execution.
|
||||
*
|
||||
* @param sender The sender.
|
||||
* @param args The arguments.
|
||||
*/
|
||||
void onExecute(@NotNull CommandSender sender,
|
||||
@NotNull List<String> args);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TabCompleteHandler {
|
||||
/**
|
||||
* Handle Tab Completion.
|
||||
*
|
||||
* @param sender The sender.
|
||||
* @param args The arguments.
|
||||
* @return The tab completion results.
|
||||
*/
|
||||
List<String> tabComplete(@NotNull CommandSender sender,
|
||||
@NotNull List<String> args);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.willfp.eco.core.command.impl;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.internal.commands.HandledCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PluginCommand extends HandledCommand implements CommandExecutor, TabCompleter {
|
||||
/**
|
||||
* Create a new command.
|
||||
* <p>
|
||||
* The command will not be registered until {@link this#register()} is called.
|
||||
* <p>
|
||||
* The name cannot be the same as an existing command as this will conflict.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @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 PluginCommand(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String name,
|
||||
@NotNull final String permission,
|
||||
final boolean playersOnly) {
|
||||
super(plugin, name, permission, playersOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the command with the server,
|
||||
* <p>
|
||||
* Requires the command name to exist, defined in plugin.yml.
|
||||
*/
|
||||
public final void register() {
|
||||
org.bukkit.command.PluginCommand command = Bukkit.getPluginCommand(this.getName());
|
||||
assert command != null;
|
||||
command.setExecutor(this);
|
||||
command.setTabCompleter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation used to clean up boilerplate.
|
||||
* Used for parity with {@link CommandExecutor#onCommand(CommandSender, Command, String, String[])}.
|
||||
*
|
||||
* @param sender The executor of the 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 EcoPlugin}
|
||||
*/
|
||||
@Override
|
||||
public final boolean onCommand(@NotNull final CommandSender sender,
|
||||
@NotNull final Command command,
|
||||
@NotNull final String label,
|
||||
@NotNull final String[] args) {
|
||||
if (!command.getName().equalsIgnoreCase(this.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.handle(sender, args);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation used to clean up boilerplate.
|
||||
* Used for parity with {@link TabCompleter#onTabComplete(CommandSender, Command, String, String[])}.
|
||||
*
|
||||
* @param sender The executor of the 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 The list of tab-completions.
|
||||
*/
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull final CommandSender sender,
|
||||
@NotNull final Command command,
|
||||
@NotNull final String label,
|
||||
@NotNull final String[] args) {
|
||||
if (!command.getName().equalsIgnoreCase(this.getName())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.handleTabCompletion(sender, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.willfp.eco.core.command.impl;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.CommandBase;
|
||||
import com.willfp.eco.internal.commands.HandledCommand;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Subcommand extends HandledCommand {
|
||||
/**
|
||||
* Create subcommand.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param name The subcommand name.
|
||||
* @param permission The subcommand permission.
|
||||
* @param playersOnly If the subcommand only works on players.
|
||||
*/
|
||||
protected Subcommand(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String name,
|
||||
@NotNull final String permission,
|
||||
final boolean playersOnly) {
|
||||
super(plugin, name, permission, playersOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create subcommand.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param name The name of the subcommand.
|
||||
* @param parent The parent command.
|
||||
*/
|
||||
protected Subcommand(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String name,
|
||||
@NotNull final CommandBase parent) {
|
||||
super(plugin, name, parent.getPermission(), parent.isPlayersOnly());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.yaml.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, "");
|
||||
}
|
||||
}
|
||||
226
eco-api/src/main/java/com/willfp/eco/core/config/Config.java
Normal file
226
eco-api/src/main/java/com/willfp/eco/core/config/Config.java
Normal file
@@ -0,0 +1,226 @@
|
||||
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();
|
||||
|
||||
/**
|
||||
* Convert the config into readable text.
|
||||
*
|
||||
* @return The plaintext.
|
||||
*/
|
||||
String toPlaintext();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ConfigHandler {
|
||||
/**
|
||||
* Invoke all update methods.
|
||||
*/
|
||||
void callUpdate();
|
||||
|
||||
/**
|
||||
* Register an updatable class.
|
||||
*
|
||||
* @param updatableClass The class with an update method.
|
||||
*/
|
||||
void registerUpdatableClass(@NotNull Class<?> updatableClass);
|
||||
|
||||
/**
|
||||
* Save all configs.
|
||||
*/
|
||||
void saveAllConfigs();
|
||||
|
||||
/**
|
||||
* Update all updatable configs.
|
||||
*/
|
||||
void updateConfigs();
|
||||
|
||||
/**
|
||||
* Add new config to be saved.
|
||||
*
|
||||
* @param config The config.
|
||||
*/
|
||||
void addConfig(@NotNull LoadableConfig config);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.yaml.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface JSONConfig extends Config {
|
||||
/**
|
||||
* Get a list of subsections 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<JSONConfig> getSubsections(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of subsections from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
List<JSONConfig> getSubsectionsOrNull(@NotNull String path);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.internal.config.json.LoadableJsonConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class JsonStaticBaseConfig extends LoadableJsonConfig {
|
||||
/**
|
||||
* Config implementation for configs present in the plugin's base directory (eg config.json, lang.json).
|
||||
* <p>
|
||||
* Does not automatically update.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected JsonStaticBaseConfig(@NotNull final String configName,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
super(configName, plugin, "", plugin.getClass());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.yaml.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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.yaml.YamlConfigWrapper;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class YamlConfig extends YamlConfigWrapper<YamlConfiguration> {
|
||||
/**
|
||||
* Config implementation for passing YamlConfigurations.
|
||||
* <p>
|
||||
* Does not automatically update.
|
||||
*
|
||||
* @param config The YamlConfiguration handle.
|
||||
*/
|
||||
public YamlConfig(@NotNull final YamlConfiguration config) {
|
||||
init(config);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
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.util.plugin.AbstractEcoPlugin;
|
||||
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.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public Lang(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public LangYml(@NotNull final EcoPlugin plugin) {
|
||||
super("lang", false, plugin);
|
||||
}
|
||||
|
||||
@@ -21,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");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,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");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,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);
|
||||
}
|
||||
}
|
||||
85
eco-api/src/main/java/com/willfp/eco/core/data/Data.java
Normal file
85
eco-api/src/main/java/com/willfp/eco/core/data/Data.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.willfp.eco.core.data;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.config.JSONConfig;
|
||||
import com.willfp.eco.core.config.JsonStaticBaseConfig;
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
import com.willfp.eco.internal.config.json.JsonConfigSection;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
public class Data {
|
||||
/**
|
||||
* Instance of eco data.yml.
|
||||
*/
|
||||
private static JSONConfig datafile = null;
|
||||
|
||||
/**
|
||||
* All cached player data.
|
||||
*/
|
||||
private static final Map<UUID, Map<EcoPlugin, JSONConfig>> PLAYER_DATA = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Initialize the player data with an instance of data.json.
|
||||
*
|
||||
* @param config data.json.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void init(@NotNull final JsonStaticBaseConfig config) {
|
||||
datafile = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save to data.yml.
|
||||
*
|
||||
* @param config Instance of data.yml.
|
||||
* @throws IOException Error during saving.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void save(@NotNull final Config config) throws IOException {
|
||||
for (Map.Entry<UUID, Map<EcoPlugin, JSONConfig>> entry : PLAYER_DATA.entrySet()) {
|
||||
entry.getValue().forEach((plugin, jsonConfig) -> {
|
||||
for (String key : jsonConfig.getKeys(false)) {
|
||||
config.set("player-data." + plugin.getName().toLowerCase() + "." + entry.getKey().toString() + "." + key, jsonConfig);
|
||||
}
|
||||
});
|
||||
}
|
||||
((LoadableConfig) config).save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param plugin The plugin.
|
||||
* @return The data.
|
||||
*/
|
||||
public JSONConfig getData(@NotNull final OfflinePlayer player,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
if (!PLAYER_DATA.containsKey(player.getUniqueId())) {
|
||||
PLAYER_DATA.put(player.getUniqueId(), new HashMap<>());
|
||||
}
|
||||
|
||||
JSONConfig config = PLAYER_DATA.get(player.getUniqueId()).get(plugin);
|
||||
|
||||
if (config == null) {
|
||||
config = (JSONConfig) datafile.getSubsectionOrNull("player-data." + plugin.getName().toLowerCase() + "." + player.getUniqueId());
|
||||
if (config == null) {
|
||||
config = new JsonConfigSection(new HashMap<>());
|
||||
}
|
||||
PLAYER_DATA.get(player.getUniqueId()).put(plugin, config);
|
||||
return getData(player, plugin);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
216
eco-api/src/main/java/com/willfp/eco/core/display/Display.java
Normal file
216
eco-api/src/main/java/com/willfp/eco/core/display/Display.java
Normal 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<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<EcoPlugin> {
|
||||
/**
|
||||
* 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().getName();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.bukkit.events;
|
||||
package com.willfp.eco.core.events;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -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;
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.willfp.eco.core.events;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerJumpEvent extends PlayerMoveEvent {
|
||||
/**
|
||||
* Internal bukkit.
|
||||
*/
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
/**
|
||||
* Create a new PlayerJumpEvent.
|
||||
*
|
||||
* @param event The PlayerMoveEvent.
|
||||
*/
|
||||
public PlayerJumpEvent(@NotNull final PlayerMoveEvent event) {
|
||||
super(event.getPlayer(), event.getFrom(), event.getTo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal bukkit.
|
||||
*
|
||||
* @return The handlers.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal bukkit.
|
||||
*
|
||||
* @return The handlers.
|
||||
*/
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,25 @@
|
||||
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;
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new extension for a plugin.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected Extension(@NotNull final AbstractEcoPlugin plugin) {
|
||||
protected Extension(@NotNull final EcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@@ -71,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.name();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,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.version();
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.extensions;
|
||||
package com.willfp.eco.core.extensions;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.willfp.eco.core.factory;
|
||||
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface MetadataValueFactory {
|
||||
/**
|
||||
* Create a metadata value for a given plugin and object.
|
||||
*
|
||||
* @param value The object to store in metadata.
|
||||
* @return The metadata value.
|
||||
*/
|
||||
FixedMetadataValue create(@NotNull Object value);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.willfp.eco.core.gui.menu;
|
||||
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import com.willfp.eco.core.items.builder.ItemStackBuilder;
|
||||
import com.willfp.eco.internal.gui.FillerSlot;
|
||||
import com.willfp.eco.util.ListUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FillerMask {
|
||||
/**
|
||||
* Mask.
|
||||
*/
|
||||
@Getter
|
||||
private final List<List<Slot>> mask;
|
||||
|
||||
/**
|
||||
* Create a new filler mask.
|
||||
*
|
||||
* @param material The mask material.
|
||||
* @param pattern The pattern.
|
||||
*/
|
||||
public FillerMask(@NotNull final Material material,
|
||||
@NotNull final String... pattern) {
|
||||
if (material == Material.AIR) {
|
||||
throw new IllegalArgumentException("Material cannot be air!");
|
||||
}
|
||||
|
||||
mask = ListUtils.create2DList(6, 9);
|
||||
|
||||
ItemStack itemStack = new ItemStackBuilder(material)
|
||||
.setDisplayName("&r")
|
||||
.build();
|
||||
|
||||
int row = 0;
|
||||
|
||||
for (String patternRow : pattern) {
|
||||
int column = 0;
|
||||
if (patternRow.length() != 9) {
|
||||
throw new IllegalArgumentException("Invalid amount of columns in pattern!");
|
||||
}
|
||||
for (char c : patternRow.toCharArray()) {
|
||||
if (c == '0') {
|
||||
mask.get(row).set(column, null);
|
||||
} else if (c == '1') {
|
||||
mask.get(row).set(column, new FillerSlot(itemStack));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid character in pattern! (Must only be 0 and 1)");
|
||||
}
|
||||
|
||||
column++;
|
||||
}
|
||||
row++;
|
||||
}
|
||||
}
|
||||
}
|
||||
146
eco-api/src/main/java/com/willfp/eco/core/gui/menu/Menu.java
Normal file
146
eco-api/src/main/java/com/willfp/eco/core/gui/menu/Menu.java
Normal file
@@ -0,0 +1,146 @@
|
||||
package com.willfp.eco.core.gui.menu;
|
||||
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import com.willfp.eco.internal.gui.EcoMenu;
|
||||
import com.willfp.eco.internal.gui.FillerSlot;
|
||||
import com.willfp.eco.util.ListUtils;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface Menu {
|
||||
/**
|
||||
* Get the amount of rows.
|
||||
*
|
||||
* @return The amount of rows.
|
||||
*/
|
||||
int getRows();
|
||||
|
||||
/**
|
||||
* Get slot at given row and column.
|
||||
*
|
||||
* @param row The row.
|
||||
* @param column The column.
|
||||
* @return The row.
|
||||
*/
|
||||
Slot getSlot(int row,
|
||||
int column);
|
||||
|
||||
/**
|
||||
* Get the menu title.
|
||||
*
|
||||
* @return The title.
|
||||
*/
|
||||
String getTitle();
|
||||
|
||||
/**
|
||||
* Open the inventory for the player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return The inventory.
|
||||
*/
|
||||
Inventory open(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Create a builder with a given amount of rows.
|
||||
*
|
||||
* @param rows The rows.
|
||||
* @return The builder.
|
||||
*/
|
||||
static Builder builder(final int rows) {
|
||||
return new Builder(rows);
|
||||
}
|
||||
|
||||
class Builder {
|
||||
/**
|
||||
* The amount of rows.
|
||||
*/
|
||||
private final int rows;
|
||||
|
||||
/**
|
||||
* The title.
|
||||
*/
|
||||
private String title = "Menu";
|
||||
|
||||
/**
|
||||
* The mask slots.
|
||||
*/
|
||||
private List<List<Slot>> maskSlots;
|
||||
|
||||
/**
|
||||
* The slots.
|
||||
*/
|
||||
private final List<List<Slot>> slots;
|
||||
|
||||
/**
|
||||
* The close event handler.
|
||||
*/
|
||||
private Consumer<InventoryCloseEvent> onClose = (event) -> {
|
||||
};
|
||||
|
||||
Builder(final int rows) {
|
||||
this.rows = rows;
|
||||
this.slots = ListUtils.create2DList(rows, 9);
|
||||
this.maskSlots = ListUtils.create2DList(rows, 9);
|
||||
}
|
||||
|
||||
public Builder setTitle(@NotNull final String title) {
|
||||
this.title = StringUtils.translate(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSlot(final int row,
|
||||
final int column,
|
||||
@NotNull final Slot slot) {
|
||||
if (row < 1 || row > this.rows) {
|
||||
throw new IllegalArgumentException("Invalid row number!");
|
||||
}
|
||||
|
||||
if (column < 1 || column > 9) {
|
||||
throw new IllegalArgumentException("Invalid column number!");
|
||||
}
|
||||
|
||||
slots.get(row - 1).set(column - 1, slot);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMask(@NotNull final FillerMask mask) {
|
||||
this.maskSlots = mask.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder onClose(@NotNull final Consumer<InventoryCloseEvent> action) {
|
||||
this.onClose = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Menu build() {
|
||||
List<List<Slot>> finalSlots = maskSlots;
|
||||
for (int i = 0; i < slots.size(); i++) {
|
||||
for (int j = 0; j < slots.get(i).size(); j++) {
|
||||
Slot slot = slots.get(i).get(j);
|
||||
if (slot != null) {
|
||||
finalSlots.get(i).set(j, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (List<Slot> finalSlot : finalSlots) {
|
||||
for (int j = 0; j < finalSlot.size(); j++) {
|
||||
if (finalSlot.get(j) == null) {
|
||||
finalSlot.set(j, new FillerSlot(new ItemStack(Material.AIR)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new EcoMenu(rows, finalSlots, title, onClose);
|
||||
}
|
||||
}
|
||||
}
|
||||
105
eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java
Normal file
105
eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package com.willfp.eco.core.gui.slot;
|
||||
|
||||
import com.willfp.eco.internal.gui.EcoSlot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface Slot {
|
||||
/**
|
||||
* Get the ItemStack that would be shown to a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return The ItemStack.
|
||||
*/
|
||||
ItemStack getItemStack(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Create a builder for an ItemStack.
|
||||
*
|
||||
* @param itemStack The ItemStack.
|
||||
* @return The builder.
|
||||
*/
|
||||
static Builder builder(@NotNull final ItemStack itemStack) {
|
||||
return new Builder((player) -> itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder for a player-specific ItemStack.
|
||||
*
|
||||
* @param provider The provider.
|
||||
* @return The builder.
|
||||
*/
|
||||
static Builder builder(@NotNull final Function<Player, ItemStack> provider) {
|
||||
return new Builder(provider);
|
||||
}
|
||||
|
||||
class Builder {
|
||||
/**
|
||||
* Provider.
|
||||
*/
|
||||
private final Function<Player, ItemStack> provider;
|
||||
|
||||
/**
|
||||
* Left click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onLeftClick = null;
|
||||
|
||||
/**
|
||||
* Right click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onRightClick = null;
|
||||
|
||||
/**
|
||||
* Shift-Left-Click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onShiftLeftClick = null;
|
||||
|
||||
/**
|
||||
* Shift-Right-Click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onShiftRightClick = null;
|
||||
|
||||
/**
|
||||
* Middle click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onMiddleClick = null;
|
||||
|
||||
Builder(@NotNull final Function<Player, ItemStack> provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public Builder onLeftClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onLeftClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder onRightClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onRightClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder onShiftLeftClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onShiftLeftClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder onShiftRightClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onShiftRightClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder onMiddleClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
this.onMiddleClick = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Slot build() {
|
||||
return new EcoSlot(provider, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations;
|
||||
package com.willfp.eco.core.integrations;
|
||||
|
||||
public interface Integration {
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations;
|
||||
package com.willfp.eco.core.integrations;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -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;
|
||||
@@ -22,7 +22,7 @@ public class AnticheatManager {
|
||||
* @param plugin The plugin.
|
||||
* @param anticheat The anticheat to register.
|
||||
*/
|
||||
public void register(@NotNull final AbstractEcoPlugin plugin,
|
||||
public void register(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final AnticheatWrapper anticheat) {
|
||||
if (anticheat instanceof Listener) {
|
||||
plugin.getEventManager().registerListener((Listener) anticheat);
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -52,7 +52,7 @@ public class PlaceholderManager {
|
||||
public static String getResult(@Nullable final Player player,
|
||||
@NotNull final String identifier) {
|
||||
Optional<PlaceholderEntry> matching = REGISTERED_PLACEHOLDERS.stream().filter(expansion -> expansion.getIdentifier().equalsIgnoreCase(identifier)).findFirst();
|
||||
if (!matching.isPresent()) {
|
||||
if (matching.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
PlaceholderEntry entry = matching.get();
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
89
eco-api/src/main/java/com/willfp/eco/core/items/Items.java
Normal file
89
eco-api/src/main/java/com/willfp/eco/core/items/Items.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.willfp.eco.core.items;
|
||||
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.TestableStack;
|
||||
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);
|
||||
}
|
||||
|
||||
if (split.length == 2) {
|
||||
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
|
||||
|
||||
if (part == null) {
|
||||
Material material = Material.getMaterial(split[0].toUpperCase());
|
||||
if (material == null || material == Material.AIR) {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
return new TestableStack(new MaterialTestableItem(material), Integer.parseInt(split[1]));
|
||||
} else {
|
||||
return part;
|
||||
}
|
||||
}
|
||||
|
||||
if (split.length == 3) {
|
||||
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
|
||||
return part == null ? new EmptyTestableItem() : new TestableStack(part, Integer.parseInt(split[2]));
|
||||
}
|
||||
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.willfp.eco.util.recipe.parts;
|
||||
package com.willfp.eco.core.items;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface RecipePart {
|
||||
public interface TestableItem {
|
||||
/**
|
||||
* If an ItemStack matches the recipe part.
|
||||
*
|
||||
@@ -13,10 +13,9 @@ public interface RecipePart {
|
||||
boolean matches(@Nullable ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get a displayed itemstack, for autocraft.
|
||||
* Get an example item.
|
||||
*
|
||||
* @return The item, displayed.
|
||||
* @return The item.
|
||||
*/
|
||||
ItemStack getDisplayed();
|
||||
ItemStack getItem();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EnchantedBookBuilder extends AbstractItemStackBuilder<EnchantmentStorageMeta, EnchantedBookBuilder> {
|
||||
/**
|
||||
* Create a new EnchantedBookBuilder.
|
||||
*/
|
||||
public EnchantedBookBuilder() {
|
||||
super(Material.ENCHANTED_BOOK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an enchantment to the item.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @param level The level.
|
||||
* @return The builder.
|
||||
*/
|
||||
public EnchantedBookBuilder addStoredEnchantment(@NotNull final Enchantment enchantment,
|
||||
final int level) {
|
||||
this.getMeta().addStoredEnchant(enchantment, level, true);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface ItemBuilder {
|
||||
/**
|
||||
* Set the ItemStack amount.
|
||||
*
|
||||
* @param amount The amount.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setAmount(int amount);
|
||||
|
||||
/**
|
||||
* Set the ItemStack amount.
|
||||
*
|
||||
* @param amount The amount.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setAmount(@NotNull Supplier<Integer> amount);
|
||||
|
||||
/**
|
||||
* Add an enchantment to the item.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @param level The level.
|
||||
* @return The builder.r
|
||||
*/
|
||||
ItemBuilder addEnchantment(@NotNull Enchantment enchantment,
|
||||
int level);
|
||||
|
||||
/**
|
||||
* Add an enchantment to the item.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @param level The level.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addEnchantment(@NotNull Supplier<Enchantment> enchantment,
|
||||
@NotNull Supplier<Integer> level);
|
||||
|
||||
/**
|
||||
* Set the item display name.
|
||||
*
|
||||
* @param name The name.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setDisplayName(@NotNull String name);
|
||||
|
||||
/**
|
||||
* Set the item display name.
|
||||
*
|
||||
* @param name The name.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setDisplayName(@NotNull Supplier<String> name);
|
||||
|
||||
/**
|
||||
* Add lore line.
|
||||
*
|
||||
* @param line The line.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addLoreLine(@NotNull String line);
|
||||
|
||||
/**
|
||||
* Add lore line.
|
||||
*
|
||||
* @param line The line.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addLoreLine(@NotNull Supplier<String> line);
|
||||
|
||||
/**
|
||||
* Add lore lines.
|
||||
*
|
||||
* @param lines The lines.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addLoreLines(@NotNull List<String> lines);
|
||||
|
||||
/**
|
||||
* Add lore lines.
|
||||
*
|
||||
* @param lines The lines.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addLoreLines(@NotNull Supplier<List<String>> lines);
|
||||
|
||||
/**
|
||||
* Add ItemFlags.
|
||||
*
|
||||
* @param itemFlags The flags.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addItemFlag(@NotNull ItemFlag... itemFlags);
|
||||
|
||||
/**
|
||||
* Add ItemFlags.
|
||||
*
|
||||
* @param itemFlags The flags.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addItemFlag(@NotNull Supplier<ItemFlag[]> itemFlags);
|
||||
|
||||
/**
|
||||
* Write meta key.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param type The type.
|
||||
* @param value The value.
|
||||
* @param <A> The type.
|
||||
* @param <B> The type.
|
||||
* @return The builder.
|
||||
*/
|
||||
<A, B> ItemBuilder writeMetaKey(@NotNull NamespacedKey key,
|
||||
@NotNull PersistentDataType<A, B> type,
|
||||
@NotNull B value);
|
||||
|
||||
/**
|
||||
* Write meta key.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param type The type.
|
||||
* @param value The value.
|
||||
* @param <A> The type.
|
||||
* @param <B> The type.
|
||||
* @return The builder.
|
||||
*/
|
||||
<A, B> ItemBuilder writeMetaKey(@NotNull Supplier<NamespacedKey> key,
|
||||
@NotNull Supplier<PersistentDataType<A, B>> type,
|
||||
@NotNull Supplier<B> value);
|
||||
|
||||
/**
|
||||
* Set unbreakable.
|
||||
*
|
||||
* @param unbreakable If the item should be unbreakable.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setUnbreakable(boolean unbreakable);
|
||||
|
||||
/**
|
||||
* Set unbreakable.
|
||||
*
|
||||
* @param unbreakable If the item should be unbreakable.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setUnbreakable(@NotNull Supplier<Boolean> unbreakable);
|
||||
|
||||
/**
|
||||
* Set custom model data.
|
||||
*
|
||||
* @param data The data.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setCustomModelData(@Nullable Integer data);
|
||||
|
||||
/**
|
||||
* Set custom model data.
|
||||
*
|
||||
* @param data The data.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setCustomModelData(@NotNull Supplier<Integer> data);
|
||||
|
||||
/**
|
||||
* Build the item.
|
||||
*
|
||||
* @return The item.
|
||||
*/
|
||||
ItemStack build();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ItemStackBuilder extends AbstractItemStackBuilder<ItemMeta, ItemStackBuilder> {
|
||||
/**
|
||||
* Create a new ItemStackBuilder.
|
||||
*
|
||||
* @param material The material.
|
||||
*/
|
||||
public ItemStackBuilder(@NotNull final Material material) {
|
||||
super(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemStackBuilder to modify an existing item.
|
||||
*
|
||||
* @param base The ItemStack to start with.
|
||||
*/
|
||||
public ItemStackBuilder(@NotNull final ItemStack base) {
|
||||
super(base);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LeatherArmorBuilder extends AbstractItemStackBuilder<LeatherArmorMeta, LeatherArmorBuilder> {
|
||||
/**
|
||||
* Create a new ItemStackBuilder.
|
||||
*
|
||||
* @param material The material.
|
||||
*/
|
||||
public LeatherArmorBuilder(@NotNull final Material material) {
|
||||
super(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemStackBuilder to modify an existing item.
|
||||
*
|
||||
* @param base The ItemStack to start with.
|
||||
*/
|
||||
public LeatherArmorBuilder(@NotNull final ItemStack base) {
|
||||
super(base);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set leather color.
|
||||
*
|
||||
* @param color The color.
|
||||
* @return The builder.
|
||||
*/
|
||||
public LeatherArmorBuilder setColor(@NotNull final java.awt.Color color) {
|
||||
Color bukkitColor = Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue());
|
||||
this.getMeta().setColor(bukkitColor);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||
import com.willfp.eco.util.SkullUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SkullBuilder extends AbstractItemStackBuilder<SkullMeta, SkullBuilder> {
|
||||
/**
|
||||
* Create a new EnchantedBookBuilder.
|
||||
*/
|
||||
public SkullBuilder() {
|
||||
super(Material.PLAYER_HEAD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set skull texture.
|
||||
*
|
||||
* @param texture The texture.
|
||||
* @return The builder.
|
||||
*/
|
||||
public SkullBuilder setSkullTexture(@NotNull final String texture) {
|
||||
SkullUtils.setSkullTexture(this.getMeta(), texture);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.proxy;
|
||||
package com.willfp.eco.core.proxy;
|
||||
|
||||
public interface AbstractProxy {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.proxy;
|
||||
package com.willfp.eco.core.proxy;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.proxy;
|
||||
package com.willfp.eco.core.proxy;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.willfp.eco.core.recipe;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.items.Items;
|
||||
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
|
||||
import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and register recipe.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param key The key.
|
||||
* @param output The output.
|
||||
* @param recipeStrings The recipe.
|
||||
* @return The recipe.
|
||||
*/
|
||||
public CraftingRecipe createAndRegisterRecipe(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String key,
|
||||
@NotNull final ItemStack output,
|
||||
@NotNull final List<String> recipeStrings) {
|
||||
ShapedCraftingRecipe.Builder builder = ShapedCraftingRecipe.builder(plugin, key).setOutput(output);
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
builder.setRecipePart(i, Items.lookup(recipeStrings.get(i)));
|
||||
}
|
||||
|
||||
ShapedCraftingRecipe recipe = builder.build();
|
||||
recipe.register();
|
||||
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.willfp.eco.util.recipe.parts;
|
||||
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 EmptyRecipePart implements RecipePart {
|
||||
public class EmptyTestableItem implements TestableItem {
|
||||
/**
|
||||
* Create a new empty recipe part.
|
||||
*/
|
||||
public EmptyRecipePart() {
|
||||
public EmptyTestableItem() {
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +25,7 @@ public class EmptyRecipePart implements RecipePart {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDisplayed() {
|
||||
public ItemStack getItem() {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.willfp.eco.util.recipe.parts;
|
||||
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 SimpleRecipePart implements RecipePart {
|
||||
public class MaterialTestableItem implements TestableItem {
|
||||
/**
|
||||
* The material.
|
||||
*/
|
||||
@@ -18,7 +19,7 @@ public class SimpleRecipePart implements RecipePart {
|
||||
*
|
||||
* @param material The material.
|
||||
*/
|
||||
public SimpleRecipePart(@NotNull final Material material) {
|
||||
public MaterialTestableItem(@NotNull final Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ public class SimpleRecipePart implements RecipePart {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDisplayed() {
|
||||
public ItemStack getItem() {
|
||||
return new ItemStack(material);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.willfp.eco.core.recipe.parts;
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import com.willfp.eco.internal.Internals;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestableStack implements TestableItem {
|
||||
/**
|
||||
* The item.
|
||||
*/
|
||||
private final TestableItem handle;
|
||||
|
||||
/**
|
||||
* The amount.
|
||||
*/
|
||||
@Getter
|
||||
private final int amount;
|
||||
|
||||
/**
|
||||
* Create a new testable stack.
|
||||
*
|
||||
* @param item The item.
|
||||
* @param amount The amount.
|
||||
*/
|
||||
public TestableStack(@NotNull final TestableItem item,
|
||||
final int amount) {
|
||||
Validate.isTrue(!(item instanceof TestableStack));
|
||||
|
||||
this.handle = item;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 && handle.matches(itemStack) && itemStack.getAmount() >= amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
ItemStack temp = handle.getItem().clone();
|
||||
ItemMeta meta = temp.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
assert lore != null;
|
||||
lore.add("");
|
||||
String add = Internals.getInstance().getPlugin().getLangYml().getString("multiple-in-craft");
|
||||
add = add.replace("%amount%", String.valueOf(amount));
|
||||
lore.add(add);
|
||||
meta.setLore(lore);
|
||||
temp.setItemMeta(meta);
|
||||
temp.setAmount(amount);
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
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;
|
||||
|
||||
public final class ShapedCraftingRecipe extends PluginDependent<EcoPlugin> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
100
eco-api/src/main/java/com/willfp/eco/core/web/Paste.java
Normal file
100
eco-api/src/main/java/com/willfp/eco/core/web/Paste.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.willfp.eco.core.web;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Paste {
|
||||
/**
|
||||
* The contents.
|
||||
*/
|
||||
@Getter
|
||||
private final String contents;
|
||||
|
||||
/**
|
||||
* Create a new paste.
|
||||
*
|
||||
* @param contents The contents.
|
||||
*/
|
||||
public Paste(@NotNull final String contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload to hastebin and get a token.
|
||||
*
|
||||
* @return The token.
|
||||
*/
|
||||
public String getHastebinToken() {
|
||||
try {
|
||||
String url = "https://hastebin.com/documents";
|
||||
URL obj = new URL(url);
|
||||
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||
|
||||
con.setRequestMethod("POST");
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
|
||||
con.setDoOutput(true);
|
||||
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
|
||||
wr.writeBytes(URLEncoder.encode(contents, StandardCharsets.UTF_8));
|
||||
wr.flush();
|
||||
wr.close();
|
||||
|
||||
BufferedReader iny = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
String output;
|
||||
StringBuilder responseBuilder = new StringBuilder();
|
||||
|
||||
while ((output = iny.readLine()) != null) {
|
||||
responseBuilder.append(output);
|
||||
}
|
||||
iny.close();
|
||||
|
||||
String responseString = responseBuilder.toString();
|
||||
|
||||
responseString = responseString.replace("{\"key\":\"", "");
|
||||
responseString = responseString.replace("\"}", "");
|
||||
|
||||
return responseString;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paste from hastebin.
|
||||
*
|
||||
* @param token The token.
|
||||
* @return The paste.
|
||||
*/
|
||||
public static Paste getFromHastebin(@NotNull final String token) {
|
||||
try {
|
||||
StringBuilder result = new StringBuilder();
|
||||
URL url = new URL("https://hastebin.com/raw/" + token);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
try (var reader = new BufferedReader(
|
||||
new InputStreamReader(conn.getInputStream()))) {
|
||||
for (String line; (line = reader.readLine()) != null;) {
|
||||
result.append(line);
|
||||
}
|
||||
}
|
||||
return new Paste(URLDecoder.decode(result.toString(), StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
18
eco-api/src/main/java/com/willfp/eco/internal/Internals.java
Normal file
18
eco-api/src/main/java/com/willfp/eco/internal/Internals.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.willfp.eco.internal;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Internals {
|
||||
private static Internals internals;
|
||||
|
||||
public static void setInterfacing(@NotNull final Internals internals) {
|
||||
Internals.internals = internals;
|
||||
}
|
||||
|
||||
public abstract EcoPlugin getPlugin();
|
||||
|
||||
public static Internals getInstance() {
|
||||
return internals;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -10,13 +10,13 @@ import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class UpdateChecker extends PluginDependent {
|
||||
public class UpdateChecker extends PluginDependent<EcoPlugin> {
|
||||
/**
|
||||
* Create an update checker for the specified spigot resource id.
|
||||
*
|
||||
* @param plugin The plugin to check.
|
||||
*/
|
||||
public UpdateChecker(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public UpdateChecker(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
public class ArrowDataListener extends PluginDependent<EcoPlugin> 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);
|
||||
}
|
||||
|
||||
@@ -34,15 +31,13 @@ public class ArrowDataListener extends PluginDependent implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onLaunch(final ProjectileLaunchEvent event) {
|
||||
if (!(event.getEntity() instanceof Arrow)) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getEntity().getShooter() instanceof LivingEntity)) {
|
||||
if (!(event.getEntity() instanceof Arrow arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Arrow arrow = (Arrow) event.getEntity();
|
||||
LivingEntity entity = (LivingEntity) arrow.getShooter();
|
||||
if (!(arrow.getShooter() instanceof LivingEntity entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.getEquipment() == null) {
|
||||
return;
|
||||
@@ -54,7 +49,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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package com.willfp.eco.internal.commands;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.command.CommandBase;
|
||||
import com.willfp.eco.core.command.CommandHandler;
|
||||
import com.willfp.eco.core.command.TabCompleteHandler;
|
||||
import com.willfp.eco.internal.commands.util.CommandUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class HandledCommand extends PluginDependent<EcoPlugin> implements CommandBase {
|
||||
/**
|
||||
* The name of the command.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The permission required to execute the command.
|
||||
* <p>
|
||||
* Written out as a string for flexibility with subclasses.
|
||||
*/
|
||||
@Getter
|
||||
private final String permission;
|
||||
|
||||
/**
|
||||
* Should the command only be allowed to be executed by players?
|
||||
* <p>
|
||||
* In other worlds, only allowed to be executed by console.
|
||||
*/
|
||||
@Getter
|
||||
private final boolean playersOnly;
|
||||
|
||||
/**
|
||||
* All subcommands for the command.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final List<CommandBase> subcommands;
|
||||
|
||||
/**
|
||||
* Create a new command.
|
||||
* <p>
|
||||
* The name cannot be the same as an existing command as this will conflict.
|
||||
*
|
||||
* @param plugin Instance of a plugin.
|
||||
* @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 HandledCommand(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String name,
|
||||
@NotNull final String permission,
|
||||
final boolean playersOnly) {
|
||||
super(plugin);
|
||||
this.name = name;
|
||||
this.permission = permission;
|
||||
this.playersOnly = playersOnly;
|
||||
this.subcommands = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a subcommand to the command.
|
||||
*
|
||||
* @param subcommand The subcommand.
|
||||
* @return The parent command.
|
||||
*/
|
||||
@Override
|
||||
public final CommandBase addSubcommand(@NotNull final CommandBase subcommand) {
|
||||
subcommands.add(subcommand);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the command.
|
||||
*
|
||||
* @param sender The sender.
|
||||
* @param args The arguments.
|
||||
*/
|
||||
protected final void handle(@NotNull final CommandSender sender,
|
||||
@NotNull final String[] args) {
|
||||
if (!CommandUtils.canExecute(sender, this, this.getPlugin())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length > 0) {
|
||||
for (CommandBase subcommand : this.getSubcommands()) {
|
||||
if (subcommand.getName().equalsIgnoreCase(args[0])) {
|
||||
if (!CommandUtils.canExecute(sender, subcommand, this.getPlugin())) {
|
||||
return;
|
||||
}
|
||||
|
||||
((HandledCommand) subcommand).handle(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.getHandler().onExecute(sender, Arrays.asList(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tab completion.
|
||||
*
|
||||
* @param sender The sender.
|
||||
* @param args The arguments.
|
||||
*/
|
||||
protected final List<String> handleTabCompletion(@NotNull final CommandSender sender,
|
||||
@NotNull final String[] args) {
|
||||
|
||||
if (!sender.hasPermission(this.getPermission())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
StringUtil.copyPartialMatches(
|
||||
args[0],
|
||||
this.getSubcommands().stream().map(CommandBase::getName).collect(Collectors.toList()),
|
||||
completions
|
||||
);
|
||||
|
||||
Collections.sort(completions);
|
||||
|
||||
if (!completions.isEmpty()) {
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 2) {
|
||||
HandledCommand command = null;
|
||||
|
||||
for (CommandBase subcommand : this.getSubcommands()) {
|
||||
if (args[0].equalsIgnoreCase(subcommand.getName())) {
|
||||
command = (HandledCommand) subcommand;
|
||||
}
|
||||
}
|
||||
|
||||
if (command != null) {
|
||||
return command.handleTabCompletion(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
}
|
||||
|
||||
return this.getTabCompleter().tabComplete(sender, Arrays.asList(args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract CommandHandler getHandler();
|
||||
|
||||
@Override
|
||||
public TabCompleteHandler getTabCompleter() {
|
||||
return (sender, args) -> new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.willfp.eco.internal.commands.util;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.CommandBase;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public class CommandUtils {
|
||||
public boolean canExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final CommandBase command,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
if (command.isPlayersOnly() && !(sender instanceof Player)) {
|
||||
sender.sendMessage(plugin.getLangYml().getMessage("not-player"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(command.getPermission()) && sender instanceof Player) {
|
||||
sender.sendMessage(plugin.getLangYml().getNoPermission());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface LoadableConfig {
|
||||
/**
|
||||
* Create the file.
|
||||
*/
|
||||
void createFile();
|
||||
|
||||
/**
|
||||
* Get resource path as relative to base directory.
|
||||
*
|
||||
* @return The resource path.
|
||||
*/
|
||||
String getResourcePath();
|
||||
|
||||
/**
|
||||
* Save the config.
|
||||
*
|
||||
* @throws IOException If error in saving.
|
||||
*/
|
||||
void save() throws IOException;
|
||||
|
||||
/**
|
||||
* Get the config file.
|
||||
*
|
||||
* @return The file.
|
||||
*/
|
||||
File getConfigFile();
|
||||
|
||||
/**
|
||||
* Get the config name (including extension)
|
||||
*
|
||||
* @return The name.
|
||||
*/
|
||||
String getName();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.internal.config.json;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class JsonConfigSection extends JsonConfigWrapper {
|
||||
/**
|
||||
* Config section.
|
||||
*
|
||||
* @param values The values.
|
||||
*/
|
||||
public JsonConfigSection(@NotNull final Map<String, Object> values) {
|
||||
this.init(values);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
package com.willfp.eco.internal.config.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.config.JSONConfig;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
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.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public abstract class JsonConfigWrapper implements JSONConfig, Cloneable {
|
||||
/**
|
||||
* The linked {@link ConfigurationSection} where values are physically stored.
|
||||
*/
|
||||
@Getter
|
||||
private final Gson handle = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
/**
|
||||
* All stored values.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<String, Object> values = new HashMap<>();
|
||||
|
||||
/**
|
||||
* All cached values.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<String, Object> cache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Abstract config.
|
||||
*/
|
||||
protected JsonConfigWrapper() {
|
||||
|
||||
}
|
||||
|
||||
public void init(@NotNull final Map<String, Object> values) {
|
||||
this.values.clear();
|
||||
this.values.putAll(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void clearCache() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toPlaintext() {
|
||||
return this.getHandle().toJson(this.getValues());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull final String path) {
|
||||
return getOfKnownType(path, Object.class) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected <T> T getOfKnownType(@NotNull final String path,
|
||||
@NotNull final Class<T> clazz) {
|
||||
return getOfKnownType(path, clazz, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected <T> T getOfKnownType(@NotNull final String path,
|
||||
@NotNull final Class<T> clazz,
|
||||
final boolean isBase) {
|
||||
String closestPath = path;
|
||||
|
||||
if (cache.containsKey(path) && isBase) {
|
||||
return (T) cache.get(path);
|
||||
}
|
||||
|
||||
if (path.contains(".")) {
|
||||
String[] split = path.split("\\.");
|
||||
closestPath = split[0];
|
||||
}
|
||||
|
||||
if (values.get(closestPath) instanceof Map && !path.equals(closestPath)) {
|
||||
JsonConfigSection section = new JsonConfigSection((Map<String, Object>) values.get(closestPath));
|
||||
return section.getOfKnownType(path.substring(closestPath.length() + 1), clazz, false);
|
||||
} else {
|
||||
if (values.containsKey(closestPath)) {
|
||||
return (T) values.get(closestPath);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getKeys(final boolean deep) {
|
||||
if (deep) {
|
||||
return new ArrayList<>(getDeepKeys(new HashSet<>(), ""));
|
||||
} else {
|
||||
return new ArrayList<>(values.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
protected Set<String> getDeepKeys(@NotNull final Set<String> list,
|
||||
@NotNull final String root) {
|
||||
for (String key : values.keySet()) {
|
||||
list.add(root + key);
|
||||
|
||||
if (values.get(key) instanceof Map) {
|
||||
JsonConfigSection section = new JsonConfigSection((Map<String, Object>) values.get(key));
|
||||
list.addAll(section.getDeepKeys(list, root + key + "."));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object get(@NotNull final String path) {
|
||||
return getOfKnownType(path, Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull final String path,
|
||||
@Nullable final Object object) {
|
||||
setRecursively(path, object, true);
|
||||
clearCache();
|
||||
}
|
||||
|
||||
protected void setRecursively(@NotNull final String path,
|
||||
@Nullable final Object object,
|
||||
final boolean isBase) {
|
||||
String closestPath = path;
|
||||
|
||||
if (path.contains(".")) {
|
||||
String[] split = path.split("\\.");
|
||||
closestPath = split[0];
|
||||
}
|
||||
|
||||
if (values.get(closestPath) instanceof Map && !path.equals(closestPath)) {
|
||||
JsonConfigSection section = new JsonConfigSection((Map<String, Object>) values.get(closestPath));
|
||||
section.setRecursively(path.substring(closestPath.length() + 1), object, false);
|
||||
values.put(closestPath, section.getValues());
|
||||
} else {
|
||||
Object obj = object;
|
||||
|
||||
if (object instanceof JSONConfig) {
|
||||
obj = ((JsonConfigWrapper) object).getValues();
|
||||
}
|
||||
|
||||
values.put(path, obj);
|
||||
}
|
||||
}
|
||||
|
||||
@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 (values.containsKey(path)) {
|
||||
Map<String, Object> subsection = (Map<String, Object>) values.get(path);
|
||||
return new JsonConfigSection(subsection);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JSONConfig> getSubsections(@NotNull final String path) {
|
||||
List<JSONConfig> subsections = getSubsectionsOrNull(path);
|
||||
Validate.notNull(subsections);
|
||||
return subsections;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<JSONConfig> getSubsectionsOrNull(@NotNull final String path) {
|
||||
List<Map<String, Object>> maps = (List<Map<String, Object>>) getOfKnownType(path, Object.class);
|
||||
|
||||
if (maps == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<JSONConfig> configs = new ArrayList<>();
|
||||
|
||||
for (Map<String, Object> map : maps) {
|
||||
configs.add(new JsonConfigSection(map));
|
||||
}
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(@NotNull final String path) {
|
||||
// ew
|
||||
return Objects.requireNonNullElse(getOfKnownType(path, Double.class), 0D).intValue();
|
||||
}
|
||||
|
||||
@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) {
|
||||
return Objects.requireNonNullElse(getOfKnownType(path, Integer.class), def);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Integer> getInts(@NotNull final String path) {
|
||||
return (List<Integer>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>());
|
||||
}
|
||||
|
||||
@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) {
|
||||
return Objects.requireNonNullElse(getOfKnownType(path, Boolean.class), false);
|
||||
}
|
||||
|
||||
@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) {
|
||||
return (List<Boolean>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>());
|
||||
}
|
||||
|
||||
@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) {
|
||||
return StringUtils.translate(Objects.requireNonNullElse(getOfKnownType(path, String.class), ""));
|
||||
}
|
||||
|
||||
@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) {
|
||||
return StringUtils.translateList((List<String>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>()));
|
||||
}
|
||||
|
||||
@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) {
|
||||
return Objects.requireNonNullElse(getOfKnownType(path, Double.class), 0D);
|
||||
}
|
||||
|
||||
@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) {
|
||||
return (List<Double>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<Double> getDoublesOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getDoubles(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONConfig clone() {
|
||||
return new JsonConfigSection(new HashMap<>(this.getValues()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.willfp.eco.internal.config.json;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.HashMap;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public abstract class LoadableJsonConfig extends JsonConfigWrapper implements LoadableConfig {
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
@Getter
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
* Plugin handle.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* The full name of the config file (eg config.json).
|
||||
*/
|
||||
@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 LoadableJsonConfig(@NotNull final String configName,
|
||||
@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String subDirectoryPath,
|
||||
@NotNull final Class<?> source) {
|
||||
this.plugin = plugin;
|
||||
this.name = configName + ".json";
|
||||
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);
|
||||
|
||||
try {
|
||||
init(this.configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
plugin.getConfigHandler().addConfig(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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.
|
||||
*/
|
||||
@Override
|
||||
public String getResourcePath() {
|
||||
String resourcePath;
|
||||
|
||||
if (subDirectoryPath.isEmpty()) {
|
||||
resourcePath = name;
|
||||
} else {
|
||||
resourcePath = subDirectoryPath + name;
|
||||
}
|
||||
|
||||
return "/" + resourcePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the config.
|
||||
*
|
||||
* @throws IOException If error in saving.
|
||||
*/
|
||||
@Override
|
||||
public void save() throws IOException {
|
||||
configFile.delete();
|
||||
Files.write(configFile.toPath(), this.toPlaintext().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the config.
|
||||
*
|
||||
* @param file The config file.
|
||||
* @throws FileNotFoundException If the file doesn't exist.
|
||||
*/
|
||||
public void init(@NotNull final File file) throws FileNotFoundException {
|
||||
super.init(this.getHandle().fromJson(new FileReader(file), HashMap.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.willfp.eco.internal.config.updating;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.config.ConfigHandler;
|
||||
import com.willfp.eco.core.config.ConfigUpdater;
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdatableClassException;
|
||||
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException;
|
||||
import com.willfp.eco.internal.config.yaml.UpdatableYamlConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class EcoConfigHandler extends PluginDependent<EcoPlugin> implements ConfigHandler {
|
||||
/**
|
||||
* A set of all configs that can be saved.
|
||||
*/
|
||||
private final List<LoadableConfig> configs = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A set of all classes that can be updated.
|
||||
*/
|
||||
private final Set<Class<?>> updatableClasses = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Creates a new config handler and links it to an {@link EcoPlugin}.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public EcoConfigHandler(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callUpdate() {
|
||||
updatableClasses.forEach(clazz -> Arrays.stream(clazz.getDeclaredMethods()).forEach(method -> {
|
||||
if (method.isAnnotationPresent(ConfigUpdater.class)) {
|
||||
if (!Modifier.isStatic(method.getModifiers())) {
|
||||
throw new InvalidUpdateMethodException("Update method must be static.");
|
||||
}
|
||||
|
||||
try {
|
||||
if (method.getParameterCount() == 0) {
|
||||
method.invoke(null);
|
||||
} else if (method.getParameterCount() == 1) {
|
||||
method.invoke(null, this.getPlugin());
|
||||
} else {
|
||||
throw new InvalidUpdateMethodException("Update method must have 0 parameters or a plugin parameter.");
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
throw new InvalidUpdateMethodException("Update method generated an exception.");
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUpdatableClass(@NotNull final Class<?> updatableClass) {
|
||||
boolean isValid = false;
|
||||
for (Method method : updatableClass.getDeclaredMethods()) {
|
||||
if (Modifier.isStatic(method.getModifiers()) && (method.getParameterCount() == 0 || method.getParameterCount() == 1) && method.isAnnotationPresent(ConfigUpdater.class)) {
|
||||
isValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
throw new InvalidUpdatableClassException("Registered updatable class " + updatableClass + " must have an annotated static method with no modifiers.");
|
||||
}
|
||||
|
||||
updatableClasses.add(updatableClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllConfigs() {
|
||||
try {
|
||||
for (LoadableConfig config : configs) {
|
||||
config.save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConfig(@NotNull final LoadableConfig config) {
|
||||
configs.add(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConfigs() {
|
||||
for (LoadableConfig config : configs) {
|
||||
if (config instanceof UpdatableYamlConfig updatableYamlConfig) {
|
||||
updatableYamlConfig.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
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.EcoConfigHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InvalidUpdatableClassException extends RuntimeException {
|
||||
/**
|
||||
* Called when an updatable class is registered into an {@link ConfigHandler}.
|
||||
* Called when an updatable class is registered into an {@link EcoConfigHandler}.
|
||||
*
|
||||
* @param message The error message.
|
||||
*/
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.willfp.eco.internal.config.yaml;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public abstract class LoadableYamlConfig extends YamlConfigWrapper<YamlConfiguration> implements LoadableConfig {
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
@Getter
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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) {
|
||||
}
|
||||
|
||||
plugin.getConfigHandler().addConfig(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResourcePath() {
|
||||
String resourcePath;
|
||||
|
||||
if (subDirectoryPath.isEmpty()) {
|
||||
resourcePath = name;
|
||||
} else {
|
||||
resourcePath = subDirectoryPath + name;
|
||||
}
|
||||
|
||||
return "/" + resourcePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws IOException {
|
||||
this.getHandle().save(this.getConfigFile());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.willfp.eco.internal.config.yaml;
|
||||
|
||||
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.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public YamlConfiguration getConfigInJar() {
|
||||
InputStream newIn = this.getSource().getResourceAsStream(getResourcePath());
|
||||
|
||||
if (newIn == null) {
|
||||
throw new NullPointerException(this.getName() + " 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.willfp.eco.internal.config.yaml;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class YamlConfigSection extends YamlConfigWrapper<ConfigurationSection> {
|
||||
/**
|
||||
* Config section.
|
||||
*
|
||||
* @param section The section.
|
||||
*/
|
||||
public YamlConfigSection(@NotNull final ConfigurationSection section) {
|
||||
this.init(section);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package com.willfp.eco.internal.config.yaml;
|
||||
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
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 YamlConfigWrapper<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 YamlConfigWrapper() {
|
||||
|
||||
}
|
||||
|
||||
protected Config init(@NotNull final T config) {
|
||||
this.handle = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toPlaintext() {
|
||||
YamlConfiguration temp = new YamlConfiguration();
|
||||
for (String key : handle.getKeys(true)) {
|
||||
temp.set(key, handle.get(key));
|
||||
}
|
||||
return temp.saveToString();
|
||||
}
|
||||
|
||||
@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) {
|
||||
cache.remove(path);
|
||||
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 {
|
||||
ConfigurationSection raw = handle.getConfigurationSection(path);
|
||||
if (raw == null) {
|
||||
cache.put(path, null);
|
||||
} else {
|
||||
cache.put(path, new YamlConfigSection(raw));
|
||||
}
|
||||
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 StringUtils.translateList((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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
public enum DropQueueType {
|
||||
/**
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user