mirror of
https://github.com/md5sha256/AreaShop.git
synced 2026-11-06 17:32:43 -05:00
Compare commits
376
Commits
v2.7.4
...
dev/bleeding
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7907498c9 | ||
|
|
afbdc6c009 | ||
|
|
cc3a0b32a4 | ||
|
|
aca6103b1c | ||
|
|
02c02dad8d | ||
|
|
822f300e65 | ||
|
|
1671dc8c26 | ||
|
|
72c4a76c6c | ||
|
|
c9e7e3cdbb | ||
|
|
4ceff1b80e | ||
|
|
8e88dc7b6b | ||
|
|
2762ebae1d | ||
|
|
5742dd623e | ||
|
|
e5d190d81e | ||
|
|
b631cfc89d | ||
|
|
399b166339 | ||
|
|
b556cb1bce | ||
|
|
105274b633 | ||
|
|
9b036dad93 | ||
|
|
628aa83089 | ||
|
|
11da15454d | ||
|
|
ff2e4e235d | ||
|
|
88c7b7a4bd | ||
|
|
cd3a7e97a7 | ||
|
|
d33739491a | ||
|
|
5488deb0d7 | ||
|
|
ff59fa7f70 | ||
|
|
219ba0335e | ||
|
|
724439da7d | ||
|
|
7bebca5dca | ||
|
|
5989ecbcbc | ||
|
|
a6a38be0a5 | ||
|
|
5034aa358a | ||
|
|
4f7982f5b2 | ||
|
|
92c8eea23a | ||
|
|
4ff5852a9d | ||
|
|
b30a292398 | ||
|
|
5640a55d73 | ||
|
|
cd79e071a4 | ||
|
|
49a4b1420d | ||
|
|
7ef50fbcba | ||
|
|
f9b1920678 | ||
|
|
a9d388a12c | ||
|
|
d66b79ba67 | ||
|
|
a33e25d83c | ||
|
|
1b1e0c7225 | ||
|
|
a977433a22 | ||
|
|
81ef7b08ba | ||
|
|
1528668f01 | ||
|
|
51487b476b | ||
|
|
a1a64d8eb4 | ||
|
|
e0a451511c | ||
|
|
1bc2523b95 | ||
|
|
dba63b7cdd | ||
|
|
fbef0006d1 | ||
|
|
c1572eb754 | ||
|
|
82ab8dbbbc | ||
|
|
0a1d27488b | ||
|
|
a92b38e664 | ||
|
|
4e1f8f685e | ||
|
|
e02f14b041 | ||
|
|
7687a9be77 | ||
|
|
745895cdae | ||
|
|
0305ec3f1f | ||
|
|
ec36996385 | ||
|
|
2800bf469b | ||
|
|
d25fc9fd45 | ||
|
|
1172b1b775 | ||
|
|
0ba567cf90 | ||
|
|
74f0a8ed3b | ||
|
|
4c6b7233eb | ||
|
|
e00cc2c191 | ||
|
|
73346d241c | ||
|
|
e8a9c6b3c7 | ||
|
|
6c6f9fc8ed | ||
|
|
284d915ca5 | ||
|
|
1494d3a3fd | ||
|
|
abaf960613 | ||
|
|
0ca301970b | ||
|
|
c7c1d9e4f6 | ||
|
|
5a61cee351 | ||
|
|
a4195eb556 | ||
|
|
ddc5145539 | ||
|
|
5daa99c938 | ||
|
|
3c2bd89c8d | ||
|
|
3c3e8965a3 | ||
|
|
6898efb7d7 | ||
|
|
030826d343 | ||
|
|
b8625237a7 | ||
|
|
b0df7ba98d | ||
|
|
a8938dc492 | ||
|
|
9f0a6ee196 | ||
|
|
cb7016264f | ||
|
|
feff1c6e24 | ||
|
|
02d1881f6d | ||
|
|
aa61bc58ca | ||
|
|
4d467e0d05 | ||
|
|
32a84dd4c8 | ||
|
|
f141f78529 | ||
|
|
96d490836e | ||
|
|
7f7f50a650 | ||
|
|
91efe92ccc | ||
|
|
d308420f30 | ||
|
|
22e3785a07 | ||
|
|
ed55641c8b | ||
|
|
b9653b7382 | ||
|
|
7021b50cbc | ||
|
|
894cc9b99c | ||
|
|
2b5d0c6bd0 | ||
|
|
867b50c1f5 | ||
|
|
d6fdcb05ef | ||
|
|
c347e8de59 | ||
|
|
81457b0d0b | ||
|
|
d7006267ca | ||
|
|
31b345ffe0 | ||
|
|
1336cb78b2 | ||
|
|
7c6b80e392 | ||
|
|
46baea2c0d | ||
|
|
d2e61545ea | ||
|
|
a12fb49832 | ||
|
|
08be336499 | ||
|
|
3051e8b402 | ||
|
|
52c3742a2a | ||
|
|
5b16f40335 | ||
|
|
6c6a67928f | ||
|
|
06dd185205 | ||
|
|
02389b7d1b | ||
|
|
bee7f18bd0 | ||
|
|
63dc36c3bd | ||
|
|
4723043e9a | ||
|
|
703bbc6668 | ||
|
|
b524b1c88f | ||
|
|
f1546f8482 | ||
|
|
29ec5a2e3b | ||
|
|
3a15e3d025 | ||
|
|
90e010494a | ||
|
|
7541af37f3 | ||
|
|
36c74a32f0 | ||
|
|
129b144cb1 | ||
|
|
a79b0067f2 | ||
|
|
5c2e4f8f0c | ||
|
|
d639f61e8f | ||
|
|
65b9ffed18 | ||
|
|
ee94a3d549 | ||
|
|
44d8999b3c | ||
|
|
a09d6f9370 | ||
|
|
105cc1033c | ||
|
|
c3daff0842 | ||
|
|
3456bc6a37 | ||
|
|
58269daa45 | ||
|
|
bac50ed5d5 | ||
|
|
8d50a0d1a7 | ||
|
|
bf5436284a | ||
|
|
592a1b24f4 | ||
|
|
aacf75c170 | ||
|
|
4bf598ac5d | ||
|
|
4b4521b002 | ||
|
|
cd262fdf5e | ||
|
|
5b283d503b | ||
|
|
b9d5a29629 | ||
|
|
0b0f4b0289 | ||
|
|
75915f2ebf | ||
|
|
1395220edb | ||
|
|
a318293bbe | ||
|
|
0cbf14183d | ||
|
|
4c636856aa | ||
|
|
7bb3ed1859 | ||
|
|
909f6c4b45 | ||
|
|
adfc4334cc | ||
|
|
f8ae27c3f3 | ||
|
|
d2b2ca2b83 | ||
|
|
6f8afea58e | ||
|
|
113a1a4f63 | ||
|
|
6e7a659c80 | ||
|
|
1336858316 | ||
|
|
7b7b5abf2c | ||
|
|
9fd8a740db | ||
|
|
88a23650a0 | ||
|
|
4e1f9e6875 | ||
|
|
4fdf9d787f | ||
|
|
413f16a2d4 | ||
|
|
3c21ac1eba | ||
|
|
7670d1b479 | ||
|
|
73e04ccc68 | ||
|
|
52256c83b8 | ||
|
|
794854e9c2 | ||
|
|
2c7fc16f8b | ||
|
|
b7fc4175a1 | ||
|
|
6e686f5a3f | ||
|
|
324dae03eb | ||
|
|
8a3122ba93 | ||
|
|
aada9a4624 | ||
|
|
b74736f23b | ||
|
|
c54c8b32ac | ||
|
|
63c1b7474a | ||
|
|
192f34099a | ||
|
|
b933dfea72 | ||
|
|
3d08c9f7be | ||
|
|
52d5b4632b | ||
|
|
7e03db8b10 | ||
|
|
913d1c9b59 | ||
|
|
f24a922fec | ||
|
|
5871b3ba24 | ||
|
|
9d3818906c | ||
|
|
ac69d18dc0 | ||
|
|
2c3a78517d | ||
|
|
04d42c5444 | ||
|
|
172762356d | ||
|
|
aeb201c221 | ||
|
|
788ba7e2b6 | ||
|
|
89114ee126 | ||
|
|
d316f2e914 | ||
|
|
74219ff75b | ||
|
|
e13a5f2bb0 | ||
|
|
c3bc9457ef | ||
|
|
6dc97b019e | ||
|
|
41944102b6 | ||
|
|
90fecd1085 | ||
|
|
e1b4df8f25 | ||
|
|
f0e4bd12ca | ||
|
|
27d832f05a | ||
|
|
1ca846f1ec | ||
|
|
2472a14cae | ||
|
|
c2bfe2158e | ||
|
|
745d1dd7d7 | ||
|
|
f6977061f4 | ||
|
|
c922b83de4 | ||
|
|
444a769f37 | ||
|
|
6b81be9cbb | ||
|
|
cd07b899c8 | ||
|
|
6bd916facd | ||
|
|
d16ea37269 | ||
|
|
56ab7ef52b | ||
|
|
6ef2d89cfc | ||
|
|
94a807d7c2 | ||
|
|
0d01cb956e | ||
|
|
55c4f7f369 | ||
|
|
3348e5b697 | ||
|
|
381c8b2ebe | ||
|
|
6bf344e6be | ||
|
|
e2bcc57128 | ||
|
|
6df08bc713 | ||
|
|
0e0b085000 | ||
|
|
4f9fc950f0 | ||
|
|
fe16d732a2 | ||
|
|
8cc44cf79f | ||
|
|
4fd478dbc3 | ||
|
|
fe77bf0318 | ||
|
|
e4b53982b2 | ||
|
|
3c953ad9a3 | ||
|
|
88f55bb6a9 | ||
|
|
4ba8326314 | ||
|
|
de81d92da0 | ||
|
|
f636a98314 | ||
|
|
e4df5a8cc9 | ||
|
|
56818bebdb | ||
|
|
7e1d7168f1 | ||
|
|
ff1ea3ae51 | ||
|
|
c9dc8dd840 | ||
|
|
c0794daeeb | ||
|
|
d40b9c660b | ||
|
|
f7b010b3f3 | ||
|
|
a06d9271c4 | ||
|
|
dd343aa587 | ||
|
|
e09d4ebd83 | ||
|
|
5f435941e4 | ||
|
|
86316cdd5b | ||
|
|
61828d3cfd | ||
|
|
54241d5ce3 | ||
|
|
d048665530 | ||
|
|
23de68431c | ||
|
|
95b4543f19 | ||
|
|
d058bb7271 | ||
|
|
63d26be369 | ||
|
|
1020388aae | ||
|
|
e56107ffd6 | ||
|
|
06fceb4643 | ||
|
|
e2077c3b32 | ||
|
|
fcb64c2ddb | ||
|
|
cc51109720 | ||
|
|
0b48f4dd2e | ||
|
|
4d7f00b0ce | ||
|
|
b27ea83982 | ||
|
|
66da717a77 | ||
|
|
7f779d2df8 | ||
|
|
ed3bd01f2a | ||
|
|
ef03501d1c | ||
|
|
feb35cfd37 | ||
|
|
b6a8dcc24c | ||
|
|
5619612a6e | ||
|
|
26ac52cc0a | ||
|
|
5f6bd55afe | ||
|
|
aba2e12c5d | ||
|
|
2906de11de | ||
|
|
436672f85b | ||
|
|
5ba8ed7ad8 | ||
|
|
00d97f1beb | ||
|
|
f530fa40af | ||
|
|
a804df2257 | ||
|
|
c96e0b464e | ||
|
|
13e52aa4f1 | ||
|
|
9aeb531d16 | ||
|
|
44f83473d1 | ||
|
|
d7260998f5 | ||
|
|
638382eacf | ||
|
|
e18fe99161 | ||
|
|
bdc9e32c13 | ||
|
|
9a46d5ae3b | ||
|
|
6795fc43d9 | ||
|
|
dd9bd2c434 | ||
|
|
9438166180 | ||
|
|
9e06b9f268 | ||
|
|
4562bf23f6 | ||
|
|
24edb01754 | ||
|
|
2739bf6ad4 | ||
|
|
2ce84186ab | ||
|
|
279fa001ea | ||
|
|
b56d5320a6 | ||
|
|
30665908b9 | ||
|
|
0fd384833a | ||
|
|
09634de4bf | ||
|
|
7fafee82a7 | ||
|
|
2899b2978c | ||
|
|
7afcba79c9 | ||
|
|
72084b38f8 | ||
|
|
6a291feedd | ||
|
|
b85566882c | ||
|
|
c14407e14b | ||
|
|
ae9bd60d1b | ||
|
|
c689c2fae0 | ||
|
|
728cfb6dfa | ||
|
|
3abb6c06e4 | ||
|
|
51c11738af | ||
|
|
172b5a99f1 | ||
|
|
4c5d025e54 | ||
|
|
e93a2d04de | ||
|
|
af5980d555 | ||
|
|
3f7249f4a1 | ||
|
|
73c6fc858e | ||
|
|
360c3e7e21 | ||
|
|
73d0115b78 | ||
|
|
baf7eaabf1 | ||
|
|
ca8c0487a8 | ||
|
|
24156a03c4 | ||
|
|
ec677766d2 | ||
|
|
ef6c8fbf9d | ||
|
|
4f52fe9e6e | ||
|
|
3ebe5a6fa9 | ||
|
|
3cebe5d2c7 | ||
|
|
c76415c4f3 | ||
|
|
b7bc02aef3 | ||
|
|
d75094e191 | ||
|
|
4045914b48 | ||
|
|
1fac002ee0 | ||
|
|
64301e74e0 | ||
|
|
5a5a7fc5ef | ||
|
|
b928caf0c2 | ||
|
|
111f629787 | ||
|
|
718474ca95 | ||
|
|
93b9df3e54 | ||
|
|
bad983a0b8 | ||
|
|
e2c8b06b68 | ||
|
|
7249e39c02 | ||
|
|
9d9a58a170 | ||
|
|
e64e884c2a | ||
|
|
6ad4ff9deb | ||
|
|
eec9806492 | ||
|
|
43b2ae8278 | ||
|
|
6d5a92e389 | ||
|
|
7d7a62ffa0 | ||
|
|
44456d87b6 | ||
|
|
d92c710b27 | ||
|
|
3dceaf98cd | ||
|
|
33c29a3756 | ||
|
|
771734360f | ||
|
|
539e908d32 |
No files matched your search
@@ -0,0 +1,23 @@
|
||||
name: Java CI with Gradle
|
||||
|
||||
on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Only run on PRs if the source branch is on someone else's repo
|
||||
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: ["ubuntu-latest", "windows-latest"]
|
||||
runs-on: "${{ matrix.os }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: gradle/actions/wrapper-validation@v3
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'zulu'
|
||||
cache: 'gradle'
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew clean build
|
||||
+3
-1
@@ -191,4 +191,6 @@ gradle-app.setting
|
||||
### Gradle Patch ###
|
||||
**/build/
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,maven
|
||||
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,maven
|
||||
|
||||
**/run
|
||||
+91
-37
@@ -1,5 +1,12 @@
|
||||
plugins {
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
id("io.github.goooler.shadow") version "8.1.7"
|
||||
id("xyz.jpenilla.run-paper") version "2.3.0"
|
||||
}
|
||||
|
||||
idea {
|
||||
module {
|
||||
isDownloadSources = true
|
||||
}
|
||||
}
|
||||
|
||||
description = "AreaShop"
|
||||
@@ -7,45 +14,55 @@ description = "AreaShop"
|
||||
dependencies {
|
||||
// Platform
|
||||
compileOnlyApi(libs.spigot)
|
||||
compileOnlyApi(libs.worldeditCore) {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
compileOnlyApi(libs.worldeditBukkit) {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
compileOnlyApi(libs.worldguardCore) {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
compileOnlyApi(libs.worldguardBukkit) {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
compileOnlyApi("com.github.MilkBowl:VaultAPI:1.7") {
|
||||
exclude("com.google.guava", "guava")
|
||||
}
|
||||
compileOnlyApi(libs.worldeditCore)
|
||||
compileOnlyApi(libs.worldeditBukkit)
|
||||
compileOnlyApi(libs.worldguardCore)
|
||||
compileOnlyApi(libs.worldguardBukkit)
|
||||
compileOnlyApi("com.github.MilkBowl:VaultAPI:1.7")
|
||||
|
||||
// 3rd party libraries
|
||||
implementation(libs.findbugs)
|
||||
implementation("io.papermc:paperlib:1.0.7")
|
||||
implementation("com.github.NLthijs48:InteractiveMessenger:e7749258ca")
|
||||
implementation("com.github.NLthijs48:BukkitDo:819d51ec2b")
|
||||
implementation("io.github.baked-libs:dough-data:1.0.3")
|
||||
implementation("com.google.inject:guice:5.0.1") {
|
||||
exclude("com.google.guava", "guava")
|
||||
api("io.papermc:paperlib:1.0.8")
|
||||
api("com.github.NLthijs48:InteractiveMessenger:e7749258ca")
|
||||
api("com.github.NLthijs48:BukkitDo:819d51ec2b")
|
||||
api("io.github.baked-libs:dough-data:1.2.0")
|
||||
api("com.google.inject:guice:7.0.0") {
|
||||
exclude("com.google.guava")
|
||||
}
|
||||
implementation("com.google.inject.extensions:guice-assistedinject:5.0.1") {
|
||||
exclude("com.google.guava", "guava")
|
||||
api("com.google.inject.extensions:guice-assistedinject:7.0.0") {
|
||||
exclude("com.google.guava")
|
||||
}
|
||||
implementation("org.incendo:cloud-paper:2.0.0-beta.10") {
|
||||
exclude("com.google.guava")
|
||||
}
|
||||
implementation("org.incendo:cloud-processors-confirmation:1.0.0-beta.3") {
|
||||
exclude("com.google.guava")
|
||||
}
|
||||
implementation("net.kyori:adventure-text-minimessage:4.16.0")
|
||||
implementation("net.kyori:adventure-platform-bukkit:4.3.2")
|
||||
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||
|
||||
// Project submodules
|
||||
implementation(projects.areashopInterface)
|
||||
implementation(projects.areashopBukkit113)
|
||||
implementation(projects.areashopNms)
|
||||
// Adapters
|
||||
runtimeOnly(projects.adapters.plugins.worldedit)
|
||||
runtimeOnly(projects.adapters.plugins.worldguard)
|
||||
runtimeOnly(projects.adapters.plugins.fastasyncworldedit)
|
||||
runtimeOnly(project(":adapters:platform:bukkit-1-17", "reobf"))
|
||||
runtimeOnly(project(":adapters:platform:bukkit-1-18", "reobf"))
|
||||
api(projects.areashopInterface)
|
||||
api(projects.adapters.platform.platformInterface)
|
||||
api(projects.adapters.platform.paper)
|
||||
|
||||
if (!providers.environmentVariable("JITPACK").isPresent) {
|
||||
// We don't need these adapters if we are only publishing an api jar
|
||||
runtimeOnly(projects.adapters.plugins.worldedit)
|
||||
runtimeOnly(projects.adapters.plugins.worldguard)
|
||||
runtimeOnly(projects.adapters.plugins.fastasyncworldedit)
|
||||
runtimeOnly(projects.adapters.plugins.essentials)
|
||||
}
|
||||
testImplementation("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
|
||||
testImplementation("com.github.seeseemelk:MockBukkit-v1.21:3.131.0")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1")
|
||||
}
|
||||
|
||||
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
tasks {
|
||||
@@ -56,11 +73,24 @@ tasks {
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(shadowJar)
|
||||
if (!providers.environmentVariable("JITPACK").isPresent) {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier.set("original")
|
||||
archiveBaseName.set("AreaShop")
|
||||
if (!providers.environmentVariable("JITPACK").isPresent) {
|
||||
archiveClassifier.set("original")
|
||||
} else {
|
||||
archiveClassifier.set("")
|
||||
}
|
||||
}
|
||||
|
||||
if (providers.environmentVariable("JITPACK").isPresent) {
|
||||
artifacts {
|
||||
archives(jar)
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
@@ -78,13 +108,37 @@ tasks {
|
||||
archiveBaseName.set("AreaShop")
|
||||
}
|
||||
val base = "me.wiefferink.areashop.libraries"
|
||||
relocate("org.incendo.cloud", "${base}.cloud")
|
||||
relocate("me.wiefferink.interactivemessenger", "${base}.interactivemessenger")
|
||||
relocate("me.wiefferink.bukkitdo", "${base}.bukkitdo")
|
||||
relocate("io.papermc.lib", "${base}.paperlib")
|
||||
relocate("io.github.bakedlibs.dough", "${base}.dough")
|
||||
relocate("com.google.inject", "${base}.inject")
|
||||
relocate("com.google.errorprone", "${base}.errorprone")
|
||||
relocate("org.aopalliance", "${base}.aopalliance")
|
||||
relocate("javax.annotation", "${base}.javax.annotation")
|
||||
relocate("javax.inject", "${base}.javax.inject")
|
||||
relocate("jakarta.inject", "${base}.jakarta.inject")
|
||||
relocate("org.jetbrains.annotations", "${base}.jetbrains.annotations")
|
||||
relocate("io.leangen.geantyref", "${base}.geantyref")
|
||||
relocate("net.kyori", "${base}.kyori")
|
||||
relocate("org.checkerframework", "${base}.checkerframework")
|
||||
relocate("org.intellij", "${base}.intellij")
|
||||
relocate("org.spongepowered", "${base}.spongepowered")
|
||||
relocate("org.yaml.snakeyaml", "${base}.snakeyaml")
|
||||
}
|
||||
runServer {
|
||||
// Configure the Minecraft version for our task.
|
||||
// This is the only required configuration besides applying the plugin.
|
||||
// Your plugin's jar (or shadowJar if present) will be used automatically.
|
||||
minecraftVersion("1.21.1")
|
||||
|
||||
downloadPlugins {
|
||||
github("EssentialsX", "essentials", "2.20.1", "EssentialsX-2.20.1.jar")
|
||||
github("MilkBowl", "Vault", "1.7.3", "Vault.jar")
|
||||
// WorldEdit 7.3.9
|
||||
url("https://mediafilez.forgecdn.net/files/5935/693/worldedit-bukkit-7.3.9.jar")
|
||||
// WorldGuard 7.0.12
|
||||
url("https://mediafilez.forgecdn.net/files/5719/698/worldguard-bukkit-7.0.12-dist.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package me.wiefferink.areashop;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import me.wiefferink.interactivemessenger.Log;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import me.wiefferink.interactivemessenger.source.LanguageManager;
|
||||
import me.wiefferink.interactivemessenger.translation.Transifex;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Collections;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
|
||||
public class ASLanguageManager extends LanguageManager {
|
||||
private JavaPlugin plugin;
|
||||
private String jarLanguagePath;
|
||||
private File languageFolder;
|
||||
private String wgPrefix;
|
||||
private List<String> chatPrefix;
|
||||
private Map<String, List<String>> currentLanguage, defaultLanguage;
|
||||
|
||||
public ASLanguageManager(JavaPlugin plugin,
|
||||
String jarLanguagePath,
|
||||
String currentLanguageName,
|
||||
String defaultLanguageName,
|
||||
List<String> chatPrefix,
|
||||
String wgPrefix) {
|
||||
super(plugin, jarLanguagePath, currentLanguageName, defaultLanguageName, chatPrefix);
|
||||
this.plugin = plugin;
|
||||
this.jarLanguagePath = jarLanguagePath;
|
||||
this.chatPrefix = chatPrefix;
|
||||
this.languageFolder = new File(plugin.getDataFolder() + File.separator + jarLanguagePath);
|
||||
|
||||
Message.init(this, plugin.getLogger());
|
||||
saveDefaults();
|
||||
currentLanguage = loadLanguage(currentLanguageName);
|
||||
if (defaultLanguageName.equals(currentLanguageName)) {
|
||||
defaultLanguage = currentLanguage;
|
||||
} else {
|
||||
defaultLanguage = loadLanguage(defaultLanguageName);
|
||||
}
|
||||
this.wgPrefix = wgPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMessage(String key) {
|
||||
List<String> message;
|
||||
if (key.equalsIgnoreCase(Message.CHATLANGUAGEVARIABLE)) {
|
||||
message = chatPrefix;
|
||||
} else if (key.equalsIgnoreCase("wgPrefix")) {
|
||||
message = new ArrayList<>();
|
||||
message.add(wgPrefix);
|
||||
} else if (currentLanguage.containsKey(key)) {
|
||||
message = currentLanguage.get(key);
|
||||
} else {
|
||||
message = defaultLanguage.get(key);
|
||||
}
|
||||
if (message == null) {
|
||||
Log.warn("Did not find message '" + key + "' in the current or default language");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return new ArrayList<>(message);
|
||||
}
|
||||
|
||||
private void saveDefaults() {
|
||||
// Create the language folder if it not exists
|
||||
if (!languageFolder.exists()) {
|
||||
if (!languageFolder.mkdirs()) {
|
||||
Log.warn("Could not create language directory: " + languageFolder.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
}
|
||||
File jarPath;
|
||||
try {
|
||||
// Read jar as ZIP file
|
||||
jarPath = new File(plugin.getClass()
|
||||
.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
Log.error("Failed to find location of jar file:", ExceptionUtils.getStackTrace(e));
|
||||
return;
|
||||
}
|
||||
try (ZipFile jar = new ZipFile(jarPath)) {
|
||||
Enumeration<? extends ZipEntry> entries = jar.entries();
|
||||
|
||||
// Each entry is a file or directory
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
|
||||
// Filter to YAML files in the language directory
|
||||
if (!entry.isDirectory() && entry.getName()
|
||||
.startsWith(jarLanguagePath + "/") && entry.getName()
|
||||
.endsWith(".yml")) {
|
||||
// Save the file to disk
|
||||
File targetFile = new File(languageFolder.getAbsolutePath() + File.separator + entry.getName()
|
||||
.substring(entry.getName().lastIndexOf("/")));
|
||||
try (
|
||||
InputStream input = jar.getInputStream(entry);
|
||||
OutputStream output = new FileOutputStream(targetFile)
|
||||
) {
|
||||
byte[] bytes = input.readAllBytes();
|
||||
output.write(bytes);
|
||||
} catch (IOException e) {
|
||||
Log.warn("Something went wrong saving a default language file: " + targetFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (
|
||||
IOException e) {
|
||||
Log.error("Failed to read zip file:", ExceptionUtils.getStackTrace(e));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, List<String>> loadLanguage(String key) {
|
||||
return loadLanguage(key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the specified language
|
||||
*
|
||||
* @param key The language to load
|
||||
* @param convert try conversion or not (infinite recursion prevention)
|
||||
* @return Map with the messages loaded from the file
|
||||
*/
|
||||
private Map<String, List<String>> loadLanguage(String key, boolean convert) {
|
||||
Map<String, List<String>> result = new HashMap<>();
|
||||
|
||||
// Load the language file
|
||||
boolean convertFromTransifex = false;
|
||||
File file = new File(languageFolder.getAbsolutePath() + File.separator + key + ".yml");
|
||||
try (
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)
|
||||
) {
|
||||
// Detect empty language files, happens when the YAML parsers prints an exception (it does return an empty YamlConfiguration though)
|
||||
YamlConfiguration ymlFile = YamlConfiguration.loadConfiguration(reader);
|
||||
if (ymlFile.getKeys(false).isEmpty()) {
|
||||
Log.warn("Language file " + key + ".yml has zero messages.");
|
||||
return result;
|
||||
}
|
||||
|
||||
// Retrieve the messages from the YAML file and create the result
|
||||
if (convert && Transifex.needsConversion(ymlFile)) {
|
||||
convertFromTransifex = true;
|
||||
} else {
|
||||
for (String messageKey : ymlFile.getKeys(false)) {
|
||||
List<String> toPut;
|
||||
if (ymlFile.isList(messageKey)) {
|
||||
toPut = ymlFile.getStringList(messageKey);
|
||||
} else {
|
||||
toPut = Collections.singletonList(ymlFile.getString(messageKey));
|
||||
}
|
||||
result.put(messageKey, new ArrayList<>(toPut));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.warn("Could not load language file: " + file.getAbsolutePath());
|
||||
}
|
||||
|
||||
// Do conversion (after block above closed the reader)
|
||||
if (convertFromTransifex) {
|
||||
if (!Transifex.convertFrom(file)) {
|
||||
Log.warn("Failed to convert " + file.getName() + " from the Transifex layout to the AreaShop layout, check the errors above");
|
||||
}
|
||||
return loadLanguage(key, false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -6,26 +6,35 @@ import com.google.inject.Stage;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.wiefferink.areashop.adapters.platform.MinecraftPlatform;
|
||||
import me.wiefferink.areashop.adapters.platform.paper.PaperPlatform;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommands;
|
||||
import me.wiefferink.areashop.extensions.AreashopExtension;
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.interfaces.AreaShopInterface;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.listeners.PlayerLoginLogoutListener;
|
||||
import me.wiefferink.areashop.managers.CommandManager;
|
||||
import me.wiefferink.areashop.managers.CacheManager;
|
||||
import me.wiefferink.areashop.managers.FeatureManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.Manager;
|
||||
import me.wiefferink.areashop.managers.SignErrorLogger;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
import me.wiefferink.areashop.modules.AreaShopModule;
|
||||
import me.wiefferink.areashop.modules.BukkitModule;
|
||||
import me.wiefferink.areashop.modules.DependencyModule;
|
||||
import me.wiefferink.areashop.nms.NMS;
|
||||
import me.wiefferink.areashop.modules.PlatformModule;
|
||||
import me.wiefferink.areashop.services.ServiceManager;
|
||||
import me.wiefferink.areashop.tools.GithubUpdateCheck;
|
||||
import me.wiefferink.areashop.tools.LanguageConverter;
|
||||
import me.wiefferink.areashop.tools.SimpleMessageBridge;
|
||||
import me.wiefferink.areashop.tools.SpigotPlatform;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.areashop.tools.version.Version;
|
||||
import me.wiefferink.areashop.tools.version.VersionUtil;
|
||||
import me.wiefferink.bukkitdo.Do;
|
||||
import me.wiefferink.interactivemessenger.source.LanguageManager;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
@@ -43,15 +52,19 @@ import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Main class for the AreaShop plugin.
|
||||
@@ -67,12 +80,10 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
private WorldGuardInterface worldGuardInterface = null;
|
||||
private WorldEditPlugin worldEdit = null;
|
||||
private WorldEditInterface worldEditInterface = null;
|
||||
private NMS nms;
|
||||
private BukkitInterface bukkitInterface = null;
|
||||
private MessageBridge messageBridge;
|
||||
private IFileManager fileManager = null;
|
||||
private LanguageManager languageManager = null;
|
||||
private CommandManager commandManager = null;
|
||||
private CacheManager cacheManager = null;
|
||||
private SignLinkerManager signLinkerManager = null;
|
||||
private FeatureManager featureManager = null;
|
||||
private SignManager signManager;
|
||||
@@ -83,6 +94,8 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
private boolean ready = false;
|
||||
private GithubUpdateCheck githubUpdateCheck = null;
|
||||
|
||||
private final ServiceManager serviceManager = new ServiceManager();
|
||||
|
||||
// Folders and file names
|
||||
public static final String languageFolder = "lang";
|
||||
public static final String schematicFolder = "schem";
|
||||
@@ -91,7 +104,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
public static final String defaultFile = "default.yml";
|
||||
public static final String configFile = "config.yml";
|
||||
public static final String configFileHidden = "hiddenConfig.yml";
|
||||
public static final String signLogFile = "sign-errors.yml";
|
||||
public static final String signLogFile = "sign-errors.log";
|
||||
public static final String versionFile = "versions";
|
||||
|
||||
// Euro tag for in the config
|
||||
@@ -166,20 +179,30 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
AreaShop.instance = this;
|
||||
Do.init(this);
|
||||
managers = new HashSet<>();
|
||||
boolean error = false;
|
||||
messageBridge = new SimpleMessageBridge();
|
||||
messageBridge = new SimpleMessageBridge(this.serviceManager);
|
||||
signErrorLogger = new SignErrorLogger(new File(getDataFolder(), signLogFile));
|
||||
|
||||
// Setup NMS Impl
|
||||
String rawServerVersion = Bukkit.getServer().getClass().getPackageName();
|
||||
String[] split = rawServerVersion.split("\\.");
|
||||
String serverVersion = split[3];
|
||||
try {
|
||||
Class<?> nmsImpl = Class.forName("me.wiefferink.areashop.adapters.platform." + serverVersion + ".NMSImpl");
|
||||
this.nms = nmsImpl.asSubclass(NMS.class).getConstructor().newInstance();
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace();
|
||||
error("Failed to initialize NMS implementation!");
|
||||
Version currentServerVersion = VersionUtil.parseMinecraftVersion(Bukkit.getBukkitVersion());
|
||||
if (currentServerVersion.versionData().isOlderThan(VersionUtil.MC_1_21)) {
|
||||
error("Unsupported minecraft version: " + currentServerVersion + "! Minimum is 1.21");
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
|
||||
final MinecraftPlatform platform;
|
||||
if (PaperLib.isPaper()) {
|
||||
platform = new PaperPlatform(this);
|
||||
info("Detected Paper; using the PaperPlatform impl");
|
||||
} else {
|
||||
platform = new SpigotPlatform(this);
|
||||
info("Detected Spigot; using the SpigotPlatform impl");
|
||||
}
|
||||
final PlatformModule platformModule = new PlatformModule(platform);
|
||||
|
||||
// Check if Vault is present
|
||||
if(getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
error("Vault plugin is not present or has not loaded correctly");
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
@@ -237,47 +260,51 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> clazz = Class.forName("me.wiefferink.areashop.handlers.BukkitHandler1_13");
|
||||
bukkitInterface = (BukkitInterface)clazz.getConstructor(AreaShopInterface.class).newInstance(this);
|
||||
} catch (Exception e) {
|
||||
error("Could not load the Bukkit handler (used for sign updates), report this problem to the author:", ExceptionUtils.getStackTrace(e));
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if Vault is present
|
||||
if(getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
error("Vault plugin is not present or has not loaded correctly");
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
|
||||
AreaShopModule asModule = new AreaShopModule(this, messageBridge, nms, bukkitInterface, worldEditInterface, worldGuardInterface, signErrorLogger, dependencyModule);
|
||||
AreaShopModule asModule = new AreaShopModule(this,
|
||||
this.messageBridge,
|
||||
this.worldEditInterface,
|
||||
this.worldGuardInterface,
|
||||
this.signErrorLogger,
|
||||
this.serviceManager,
|
||||
platformModule,
|
||||
dependencyModule
|
||||
);
|
||||
injector = Guice.createInjector(Stage.PRODUCTION, new BukkitModule(getServer()), asModule);
|
||||
|
||||
// Load all data from files and check versions
|
||||
fileManager = injector.getInstance(IFileManager.class);
|
||||
managers.add((FileManager) fileManager);
|
||||
boolean loadFilesResult = fileManager.loadFiles(false);
|
||||
error = error || !loadFilesResult;
|
||||
if (!loadFilesResult) {
|
||||
shutdownOnError();
|
||||
return;
|
||||
}
|
||||
|
||||
performLanguageMigrations();
|
||||
setupLanguageManager();
|
||||
|
||||
featureManager = injector.getInstance(FeatureManager.class);
|
||||
featureManager.initializeFeatures(injector);
|
||||
managers.add(featureManager);
|
||||
signManager = new SignManager();
|
||||
signManager = injector.getInstance(SignManager.class);
|
||||
managers.add(signManager);
|
||||
cacheManager = injector.getInstance(CacheManager.class);
|
||||
String rawExpiryDuration = fileManager.getConfig().getString("cacheExpiryDuration", "7d");
|
||||
long millis = Utils.durationStringToLong(rawExpiryDuration);
|
||||
cacheManager.initialize(new File(getDataFolder(), "uuid-cache.bin"), Duration.ofMillis(millis));
|
||||
cacheManager.loadCache();
|
||||
managers.add(cacheManager);
|
||||
|
||||
loadExtensions();
|
||||
|
||||
// Register the event listeners
|
||||
getServer().getPluginManager().registerEvents(new PlayerLoginLogoutListener(this, messageBridge), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerLoginLogoutListener(this, messageBridge, this.cacheManager), this);
|
||||
|
||||
setupTasks();
|
||||
|
||||
// Startup the CommandManager (registers itself for the command)
|
||||
commandManager = injector.getInstance(CommandManager.class);
|
||||
managers.add(commandManager);
|
||||
// Register commands
|
||||
AreashopCommands commands = injector.getInstance(AreashopCommands.class);
|
||||
commands.registerCommands();
|
||||
|
||||
// Create a signLinkerManager
|
||||
signLinkerManager = injector.getInstance(SignLinkerManager.class);
|
||||
@@ -292,15 +319,18 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
this,
|
||||
"md5sha256",
|
||||
"AreaShop"
|
||||
).withVersionComparator((latestVersion, currentVersion) ->
|
||||
!cleanVersion(latestVersion).equals(cleanVersion(currentVersion))
|
||||
).withVersionComparator((latestVersion, currentVersion) -> {
|
||||
Version latest = Version.parse(cleanVersion(latestVersion));
|
||||
Version current = Version.parse(cleanVersion(currentVersion));
|
||||
return latest.versionData().isNewerThan(current.versionData());
|
||||
}
|
||||
).checkUpdate(result -> {
|
||||
AreaShop.debug("Update check result:", result);
|
||||
if(!result.hasUpdate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AreaShop.info("Update from AreaShop V" + cleanVersion(result.getCurrentVersion()) + " to AreaShop V" + cleanVersion(result.getLatestVersion()) + " available, get the latest version at https://www.spigotmc.org/resources/areashop.2991/");
|
||||
AreaShop.info("Update from AreaShop V" + cleanVersion(result.getCurrentVersion()) + " to AreaShop V" + cleanVersion(result.getLatestVersion()) + " available, get the latest version at https://github.com/md5sha256/AreaShop/releases");
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
notifyUpdate(player);
|
||||
}
|
||||
@@ -323,6 +353,25 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
private void loadExtensions() {
|
||||
if (this.getServer().getPluginManager().isPluginEnabled("Essentials")) {
|
||||
loadEssentialsExt().ifPresent(ext -> ext.init(this, this.injector));
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<AreashopExtension> loadEssentialsExt() {
|
||||
try {
|
||||
Class<?> clazz = Class.forName("me.wiefferink.areashop.adapters.plugins.essentials.EssentialsExtension");
|
||||
Class<? extends AreashopExtension> extClass = clazz.asSubclass(AreashopExtension.class);
|
||||
AreashopExtension extension = extClass.getConstructor().newInstance();
|
||||
return Optional.of(extension);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
error("Failed to initialize the essentials extension!");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup a version number.
|
||||
* @param version Version to clean
|
||||
@@ -344,6 +393,10 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
return version;
|
||||
}
|
||||
|
||||
public CacheManager getCacheManager() {
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on shutdown or reload of the server.
|
||||
*/
|
||||
@@ -360,6 +413,14 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the plugin will be using MiniMessage or not
|
||||
* @return true if MiniMessage should be used, false otherwise
|
||||
*/
|
||||
public static boolean useMiniMessage() {
|
||||
return getInstance().getConfig().getBoolean("useMiniMessage");
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the plugin is ready to be used.
|
||||
* @return true if the plugin is ready, false otherwise
|
||||
@@ -384,16 +445,53 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
private void performLanguageMigrations() {
|
||||
boolean migrateExisting = this.getConfig().getBoolean("migrateLanguages", false);
|
||||
if (!migrateExisting) {
|
||||
return;
|
||||
}
|
||||
getLogger().info("Performing language migration");
|
||||
List<String> chatPrefix = getConfig().getStringList("chatPrefix");
|
||||
List<String> convertedChatPrefix = LanguageConverter.convertRawList(chatPrefix);
|
||||
if (convertedChatPrefix.size() == 1) {
|
||||
getConfig().set("mmChatPrefix", convertedChatPrefix.getFirst());
|
||||
} else {
|
||||
getConfig().set("mmChatPrefix", convertedChatPrefix);
|
||||
}
|
||||
saveConfig();
|
||||
File existingLanguages = getDataFolder().toPath().resolve(languageFolder).toFile();
|
||||
File[] langFiles = existingLanguages.listFiles(file -> file.getName().endsWith(".yml"));
|
||||
if (langFiles == null) {
|
||||
return;
|
||||
}
|
||||
for (File file : langFiles) {
|
||||
String name = file.getName();
|
||||
String langName = name.substring(0, name.length() - 4);
|
||||
if (langName.endsWith("-MM")) {
|
||||
debug("Skipping migration for " + langName + " as it already exists.");
|
||||
continue;
|
||||
}
|
||||
File toMigrate = new File(existingLanguages, langName + "-MM.yml");
|
||||
try {
|
||||
LanguageConverter.performConversion(file, toMigrate);
|
||||
} catch (IOException ex) {
|
||||
getLogger().log(Level.SEVERE, "Failed to perform migration for lang: " + file.getName(), ex);
|
||||
}
|
||||
}
|
||||
getLogger().info("Language migration complete!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a new LanguageManager.
|
||||
*/
|
||||
private void setupLanguageManager() {
|
||||
languageManager = new LanguageManager(
|
||||
languageManager = new ASLanguageManager(
|
||||
this,
|
||||
languageFolder,
|
||||
getConfig().getString("language"),
|
||||
useMiniMessage() ? getConfig().getString("mmLanguage") : getConfig().getString("language"),
|
||||
"EN",
|
||||
chatprefix
|
||||
useMiniMessage() ? getConfig().getStringList("mmChatPrefix") : chatprefix,
|
||||
getConfig().getString("wgPrefix")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -405,10 +503,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
this.chatprefix = chatprefix;
|
||||
}
|
||||
|
||||
public NMS getNms() {
|
||||
return nms;
|
||||
}
|
||||
|
||||
public SignErrorLogger getSignErrorLogger() {
|
||||
return signErrorLogger;
|
||||
}
|
||||
@@ -454,6 +548,11 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
return worldEdit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin pluginInstance() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get WorldGuardInterface for version dependent things.
|
||||
* @return WorldGuardInterface
|
||||
@@ -470,24 +569,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
return languageManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the BukkitHandler, for sign interactions.
|
||||
* @return BukkitHandler
|
||||
*/
|
||||
public BukkitInterface getBukkitHandler() {
|
||||
return this.bukkitInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the CommandManager.
|
||||
* @return the CommandManager
|
||||
*/
|
||||
@Nonnull
|
||||
@Override
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SignLinkerManager.
|
||||
* Handles sign linking mode.
|
||||
@@ -510,11 +591,16 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
return featureManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ServiceManager getServiceManager() {
|
||||
return this.serviceManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the Vault plugin.
|
||||
* @return Economy
|
||||
*/
|
||||
@Deprecated
|
||||
private Economy getEconomy() {
|
||||
RegisteredServiceProvider<Economy> economy = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if(economy == null) {
|
||||
@@ -528,7 +614,6 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
* Get the Vault permissions provider.
|
||||
* @return Vault permissions provider
|
||||
*/
|
||||
@Deprecated
|
||||
private net.milkbowl.vault.permission.Permission getPermissionProvider() {
|
||||
RegisteredServiceProvider<net.milkbowl.vault.permission.Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||
if (permissionProvider == null) {
|
||||
@@ -704,12 +789,19 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
AreaShop.debug(StringUtils.join(message, " "));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debugI(Supplier<String> message) {
|
||||
if (debug) {
|
||||
info("Debug: " + message.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print an information message to the console.
|
||||
* @param message The message to print
|
||||
*/
|
||||
public static void info(Object... message) {
|
||||
AreaShop.getInstance().getLogger().info(StringUtils.join(message, " "));
|
||||
AreaShop.getInstance().getLogger().info(() -> StringUtils.join(message, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -717,7 +809,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
* @param message The message to print
|
||||
*/
|
||||
public static void warn(Object... message) {
|
||||
AreaShop.getInstance().getLogger().warning(StringUtils.join(message, " "));
|
||||
AreaShop.getInstance().getLogger().warning(() -> StringUtils.join(message, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -725,7 +817,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
* @param message The message to print
|
||||
*/
|
||||
public static void error(Object... message) {
|
||||
AreaShop.getInstance().getLogger().severe(StringUtils.join(message, " "));
|
||||
AreaShop.getInstance().getLogger().severe(() -> StringUtils.join(message, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,21 +2,14 @@ package me.wiefferink.areashop;
|
||||
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.interfaces.AreaShopInterface;
|
||||
import me.wiefferink.areashop.managers.CommandManager;
|
||||
import me.wiefferink.areashop.managers.FeatureManager;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
import me.wiefferink.areashop.services.ServiceManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface AreaShopApi extends AreaShopInterface {
|
||||
|
||||
/**
|
||||
* Function to get the CommandManager.
|
||||
*
|
||||
* @return the CommandManager
|
||||
*/
|
||||
@Nonnull CommandManager getCommandManager();
|
||||
|
||||
/**
|
||||
* Get the SignLinkerManager.
|
||||
* Handles sign linking mode.
|
||||
@@ -36,4 +29,7 @@ public interface AreaShopApi extends AreaShopInterface {
|
||||
|
||||
@Nonnull SignManager getSignManager();
|
||||
|
||||
@Nonnull
|
||||
ServiceManager getServiceManager();
|
||||
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package me.wiefferink.areashop;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface MessageBridge {
|
||||
/**
|
||||
* Send a message to a target without a prefix.
|
||||
@@ -18,4 +22,8 @@ public interface MessageBridge {
|
||||
* @param replacements The replacements to insert in the message
|
||||
*/
|
||||
void message(Object target, String key, Object... replacements);
|
||||
|
||||
void messagePersistent(@Nonnull OfflinePlayer target,
|
||||
@Nonnull String key,
|
||||
@Nonnull Object... replacements);
|
||||
}
|
||||
@@ -1,15 +1,23 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.WorldFlagUtil;
|
||||
import me.wiefferink.areashop.commands.util.WorldGuardRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.WorldSelection;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||
import me.wiefferink.areashop.events.ask.BuyingRegionEvent;
|
||||
import me.wiefferink.areashop.events.ask.RentingRegionEvent;
|
||||
import me.wiefferink.areashop.events.notify.BoughtRegionEvent;
|
||||
import me.wiefferink.areashop.events.notify.RentedRegionEvent;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
@@ -23,316 +31,415 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.standard.EnumParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class AddCommand extends CommandAreaShop {
|
||||
public class AddCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private AreaShop plugin;
|
||||
@Inject
|
||||
private WorldEditInterface worldEditInterface;
|
||||
@Inject
|
||||
private WorldGuardInterface worldGuardInterface;
|
||||
@Inject
|
||||
private RegionFactory regionFactory;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop add";
|
||||
}
|
||||
private static final CloudKey<GeneralRegion.RegionType> KEY_REGION_TYPE = CloudKey.of("regionType",
|
||||
GeneralRegion.RegionType.class);
|
||||
private static final CloudKey<ProtectedRegion> KEY_REGION = CloudKey.of("region", ProtectedRegion.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final AreaShop plugin;
|
||||
private final WorldEditInterface worldEditInterface;
|
||||
private final WorldGuardInterface worldGuardInterface;
|
||||
private final RegionFactory regionFactory;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.createrent")
|
||||
|| target.hasPermission("areashop.createrent.member")
|
||||
|| target.hasPermission("areashop.createrent.owner")
|
||||
@Inject
|
||||
public AddCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull AreaShop plugin,
|
||||
@Nonnull WorldEditInterface worldEditInterface,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface,
|
||||
@Nonnull RegionFactory regionFactory) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.plugin = plugin;
|
||||
this.worldEditInterface = worldEditInterface;
|
||||
this.worldGuardInterface = worldGuardInterface;
|
||||
this.regionFactory = regionFactory;
|
||||
}
|
||||
|
||||
|| target.hasPermission("areashop.createbuy")
|
||||
|| target.hasPermission("areashop.createbuy.member")
|
||||
|| target.hasPermission("areashop.createbuy.owner")) {
|
||||
return "help-add";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if(target.hasPermission("areashop.createrent")
|
||||
|| target.hasPermission("areashop.createrent.member")
|
||||
|| target.hasPermission("areashop.createrent.owner")
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
if(!sender.hasPermission("areashop.createrent")
|
||||
&& !sender.hasPermission("areashop.createrent.member")
|
||||
&& !sender.hasPermission("areashop.createrent.owner")
|
||||
|| target.hasPermission("areashop.createbuy")
|
||||
|| target.hasPermission("areashop.createbuy.member")
|
||||
|| target.hasPermission("areashop.createbuy.owner")) {
|
||||
return "help-add";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
&& !sender.hasPermission("areashop.createbuy")
|
||||
&& !sender.hasPermission("areashop.createbuy.member")
|
||||
&& !sender.hasPermission("areashop.createbuy.owner")) {
|
||||
messageBridge.message(sender, "add-noPermission");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
// /as add <rent|buy> [region] [world]
|
||||
var wgRegionParser = WorldGuardRegionParser.worldGuardRegionParser(WorldFlagUtil.DEFAULT_WORLD_FLAG, this.worldGuardInterface);
|
||||
return builder
|
||||
.literal("add")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.required(KEY_REGION_TYPE, EnumParser.enumParser(GeneralRegion.RegionType.class))
|
||||
.optional(KEY_REGION, wgRegionParser)
|
||||
.flag(WorldFlagUtil.DEFAULT_WORLD_FLAG)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
if(args.length < 2 || args[1] == null || (!"rent".equalsIgnoreCase(args[1]) && !"buy".equalsIgnoreCase(args[1]))) {
|
||||
messageBridge.message(sender, "add-help");
|
||||
return;
|
||||
}
|
||||
Map<String, ProtectedRegion> regions = new HashMap<>();
|
||||
World world;
|
||||
Player player = null;
|
||||
if(sender instanceof Player) {
|
||||
player = (Player)sender;
|
||||
}
|
||||
if(args.length == 2) {
|
||||
if(player == null) {
|
||||
messageBridge.message(sender, "cmd-weOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if(selection == null) {
|
||||
messageBridge.message(player, "cmd-noSelection");
|
||||
return;
|
||||
}
|
||||
world = selection.getWorld();
|
||||
regions = Utils.getWorldEditRegionsInSelection(selection).stream().collect(Collectors.toMap(ProtectedRegion::getId, region -> region));
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(player, "cmd-noWERegionsFound");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(player != null) {
|
||||
if(args.length == 4) {
|
||||
world = Bukkit.getWorld(args[3]);
|
||||
if(world == null) {
|
||||
messageBridge.message(sender, "add-incorrectWorld", args[3]);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
world = ((Player)sender).getWorld();
|
||||
}
|
||||
} else {
|
||||
if(args.length < 4) {
|
||||
messageBridge.message(sender, "add-specifyWorld");
|
||||
return;
|
||||
} else {
|
||||
world = Bukkit.getWorld(args[3]);
|
||||
if(world == null) {
|
||||
messageBridge.message(sender, "add-incorrectWorld", args[3]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
ProtectedRegion region = plugin.getRegionManager(world).getRegion(args[2]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-noRegion", args[2]);
|
||||
return;
|
||||
}
|
||||
regions.put(args[2], region);
|
||||
}
|
||||
final boolean isRent = "rent".equalsIgnoreCase(args[1]);
|
||||
final Player finalPlayer = player;
|
||||
AreaShop.debug("Starting add task with " + regions.size() + " regions");
|
||||
private void handleCommand(CommandContext<PlayerCommandSource> context) {
|
||||
Player player = context.sender().sender();
|
||||
final GeneralRegion.RegionType regionType = context.get(KEY_REGION_TYPE);
|
||||
World world = WorldFlagUtil.parseOrDetectWorld(context, player);
|
||||
Map<String, ProtectedRegion> regions;
|
||||
Optional<ProtectedRegion> inputRegion = context.optional(KEY_REGION);
|
||||
if (inputRegion.isPresent()) {
|
||||
regions = new HashMap<>();
|
||||
regions.put(inputRegion.get().getId(), inputRegion.get());
|
||||
} else {
|
||||
WorldSelection selection = WorldSelection.fromPlayer(player, this.worldEditInterface);
|
||||
regions = Utils.getWorldEditRegionsInSelection(selection.selection()).stream()
|
||||
.collect(Collectors.toMap(ProtectedRegion::getId, region -> region));
|
||||
}
|
||||
if (regions.isEmpty()) {
|
||||
throw new AreaShopCommandException("cmd-noWERegionsFound");
|
||||
}
|
||||
AreaShop.debug("Starting add task with " + regions.size() + " regions");
|
||||
AddTaskState state = createState(player, regionType, world);
|
||||
int batchSize = plugin.getConfig().getInt("adding.regionsPerTick");
|
||||
Do.forAll(
|
||||
batchSize,
|
||||
regions.entrySet(),
|
||||
regionEntry -> processEntry(regionEntry, state),
|
||||
() -> onCompletion(state)
|
||||
);
|
||||
}
|
||||
|
||||
TreeSet<GeneralRegion> regionsSuccess = new TreeSet<>();
|
||||
TreeSet<GeneralRegion> regionsAlready = new TreeSet<>();
|
||||
TreeSet<GeneralRegion> regionsAlreadyOtherWorld = new TreeSet<>();
|
||||
TreeSet<GeneralRegion> regionsRentCancelled = new TreeSet<>(); // Denied by an event listener
|
||||
TreeSet<GeneralRegion> regionsBuyCancelled = new TreeSet<>(); // Denied by an event listener
|
||||
TreeSet<String> namesBlacklisted = new TreeSet<>();
|
||||
TreeSet<String> namesNoPermission = new TreeSet<>();
|
||||
TreeSet<String> namesAddCancelled = new TreeSet<>(); // Denied by an event listener
|
||||
Do.forAll(
|
||||
plugin.getConfig().getInt("adding.regionsPerTick"),
|
||||
regions.entrySet(),
|
||||
regionEntry -> {
|
||||
String regionName = regionEntry.getKey();
|
||||
ProtectedRegion region = regionEntry.getValue();
|
||||
// Determine if the player is an owner or member of the region
|
||||
boolean isMember = finalPlayer != null && worldGuardInterface.containsMember(region, finalPlayer.getUniqueId());
|
||||
boolean isOwner = finalPlayer != null && worldGuardInterface.containsOwner(region, finalPlayer.getUniqueId());
|
||||
String type;
|
||||
if(isRent) {
|
||||
type = "rent";
|
||||
} else {
|
||||
type = "buy";
|
||||
}
|
||||
IFileManager.AddResult result = plugin.getFileManager().checkRegionAdd(sender, region, world, isRent ? GeneralRegion.RegionType.RENT : GeneralRegion.RegionType.BUY);
|
||||
if(result == IFileManager.AddResult.ALREADYADDED) {
|
||||
regionsAlready.add(plugin.getFileManager().getRegion(regionName));
|
||||
} else if(result == IFileManager.AddResult.ALREADYADDEDOTHERWORLD) {
|
||||
regionsAlreadyOtherWorld.add(plugin.getFileManager().getRegion(regionName));
|
||||
} else if(result == IFileManager.AddResult.BLACKLISTED) {
|
||||
namesBlacklisted.add(regionName);
|
||||
} else if(result == IFileManager.AddResult.NOPERMISSION) {
|
||||
namesNoPermission.add(regionName);
|
||||
} else {
|
||||
// Check if the player should be landlord
|
||||
boolean landlord = (!sender.hasPermission("areashop.create" + type)
|
||||
&& ((sender.hasPermission("areashop.create" + type + ".owner") && isOwner)
|
||||
|| (sender.hasPermission("areashop.create" + type + ".member") && isMember)));
|
||||
List<UUID> existing = new ArrayList<>();
|
||||
existing.addAll(worldGuardInterface.getOwners(region).asUniqueIdList());
|
||||
existing.addAll(worldGuardInterface.getMembers(region).asUniqueIdList());
|
||||
private AddTaskState createState(
|
||||
@Nonnull Player player,
|
||||
@Nonnull GeneralRegion.RegionType regionType,
|
||||
@Nonnull World world
|
||||
) {
|
||||
Set<GeneralRegion> regionsSuccess = new TreeSet<>();
|
||||
Set<GeneralRegion> regionsAlready = new TreeSet<>();
|
||||
Set<GeneralRegion> regionsAlreadyOtherWorld = new TreeSet<>();
|
||||
Set<GeneralRegion> regionsRentCancelled = new TreeSet<>(); // Denied by an event listener
|
||||
Set<GeneralRegion> regionsBuyCancelled = new TreeSet<>(); // Denied by an event listener
|
||||
Set<String> namesBlacklisted = new TreeSet<>();
|
||||
Set<String> namesNoPermission = new TreeSet<>();
|
||||
Set<String> namesAddCancelled = new TreeSet<>(); // Denied by an event listener
|
||||
return new AddTaskState(
|
||||
player,
|
||||
regionType,
|
||||
regionsSuccess,
|
||||
regionsAlready,
|
||||
regionsAlreadyOtherWorld,
|
||||
regionsRentCancelled,
|
||||
regionsBuyCancelled,
|
||||
namesBlacklisted,
|
||||
namesNoPermission,
|
||||
namesAddCancelled,
|
||||
world
|
||||
);
|
||||
}
|
||||
|
||||
AreaShop.debug("regionAddLandlordStatus:", regionName,
|
||||
"landlord:", landlord,
|
||||
"existing:", existing,
|
||||
"isMember:", isMember,
|
||||
"isOwner:", isOwner,
|
||||
"createPermission:", sender.hasPermission("areashop.create" + type),
|
||||
"ownerPermission:", sender.hasPermission("areashop.create" + type + ".owner"),
|
||||
"memberPermission:", sender.hasPermission("areashop.create" + type + ".member"));
|
||||
private void processEntry(@Nonnull Map.Entry<String, ProtectedRegion> regionEntry,
|
||||
@Nonnull AddTaskState taskState) {
|
||||
Player player = taskState.sender();
|
||||
Set<GeneralRegion> regionsAlready = taskState.regionsAlready();
|
||||
Set<GeneralRegion> regionsAlreadyOtherWorld = taskState.regionsAlreadyOtherWorld();
|
||||
Set<String> namesBlacklisted = taskState.namesBlacklisted();
|
||||
Set<String> namesNoPermission = taskState.namesNoPermission();
|
||||
GeneralRegion.RegionType regionType = taskState.regionType();
|
||||
World world = taskState.world();
|
||||
String regionName = regionEntry.getKey();
|
||||
ProtectedRegion region = regionEntry.getValue();
|
||||
// Determine if the player is an owner or member of the region
|
||||
boolean isMember = this.worldGuardInterface.containsMember(region, player.getUniqueId());
|
||||
boolean isOwner = this.worldGuardInterface.containsOwner(region, player.getUniqueId());
|
||||
String type = regionType.toString().toLowerCase(Locale.ENGLISH);
|
||||
IFileManager.AddResult result = this.plugin.getFileManager()
|
||||
.checkRegionAdd(
|
||||
player,
|
||||
region,
|
||||
world,
|
||||
regionType
|
||||
);
|
||||
switch (result) {
|
||||
case ALREADYADDED -> regionsAlready.add(plugin.getFileManager().getRegion(regionName));
|
||||
case ALREADYADDEDOTHERWORLD -> regionsAlreadyOtherWorld.add(plugin.getFileManager().getRegion(regionName));
|
||||
case BLACKLISTED -> namesBlacklisted.add(regionName);
|
||||
case NOPERMISSION -> namesNoPermission.add(regionName);
|
||||
default -> {
|
||||
// Check if the player should be landlord
|
||||
boolean landlord = (!player.hasPermission("areashop.create" + type)
|
||||
&& ((player.hasPermission("areashop.create" + type + ".owner") && isOwner)
|
||||
|| (player.hasPermission("areashop.create" + type + ".member") && isMember)));
|
||||
List<UUID> existing = new ArrayList<>();
|
||||
existing.addAll(worldGuardInterface.getOwners(region).asUniqueIdList());
|
||||
existing.addAll(worldGuardInterface.getMembers(region).asUniqueIdList());
|
||||
debugResult(player, regionName, landlord, existing, isMember, isOwner, regionType);
|
||||
if (regionType == GeneralRegion.RegionType.BUY) {
|
||||
proccessBuy(region, landlord, existing, taskState);
|
||||
} else if (regionType == GeneralRegion.RegionType.RENT) {
|
||||
processRent(region, landlord, existing, taskState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isRent) {
|
||||
RentRegion rent = regionFactory.createRentRegion(regionName, world);
|
||||
// Set landlord
|
||||
if(landlord) {
|
||||
rent.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
|
||||
}
|
||||
private void debugResult(
|
||||
@Nonnull Player player,
|
||||
@Nonnull String regionName,
|
||||
boolean landlord,
|
||||
List<UUID> existing,
|
||||
boolean isMember,
|
||||
boolean isOwner,
|
||||
@Nonnull GeneralRegion.RegionType regionType
|
||||
) {
|
||||
String type = regionType.name().toLowerCase(Locale.ENGLISH);
|
||||
AreaShop.debug("regionAddLandlordStatus:",
|
||||
regionName,
|
||||
"landlord:",
|
||||
landlord,
|
||||
"existing:",
|
||||
existing,
|
||||
"isMember:",
|
||||
isMember,
|
||||
"isOwner:",
|
||||
isOwner,
|
||||
"createPermission:",
|
||||
player.hasPermission("areashop.create" + type),
|
||||
"ownerPermission:",
|
||||
player.hasPermission("areashop.create" + type + ".owner"),
|
||||
"memberPermission:",
|
||||
player.hasPermission("areashop.create" + type + ".member"));
|
||||
}
|
||||
|
||||
AddingRegionEvent event = plugin.getFileManager().addRegion(rent);
|
||||
if (event.isCancelled()) {
|
||||
namesAddCancelled.add(rent.getName());
|
||||
return;
|
||||
}
|
||||
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||
rent.update();
|
||||
private void onCompletion(@Nonnull AddTaskState taskState) {
|
||||
CommandSender player = taskState.sender();
|
||||
GeneralRegion.RegionType regionType = taskState.regionType;
|
||||
Set<GeneralRegion> regionsSuccess = taskState.regionsSuccess();
|
||||
Set<GeneralRegion> regionsAlready = taskState.regionsAlready();
|
||||
Set<GeneralRegion> regionsAlreadyOtherWorld = taskState.regionsAlreadyOtherWorld();
|
||||
Set<GeneralRegion> regionsRentCancelled = taskState.regionsRentCancelled(); // Denied by an event listener
|
||||
Set<GeneralRegion> regionsBuyCancelled = taskState.regionsBuyCancelled(); // Denied by an event listener
|
||||
Set<String> namesBlacklisted = taskState.namesBlacklisted();
|
||||
Set<String> namesNoPermission = taskState.namesNoPermission();
|
||||
Set<String> namesAddCancelled = taskState.namesAddCancelled(); // Denied by an event listener
|
||||
if (!regionsSuccess.isEmpty()) {
|
||||
this.messageBridge.message(player,
|
||||
"add-success",
|
||||
regionType.name().toLowerCase(Locale.ENGLISH),
|
||||
Utils.combinedMessage(regionsSuccess, "region"));
|
||||
}
|
||||
if (!regionsAlready.isEmpty()) {
|
||||
this.messageBridge.message(player,
|
||||
"add-failed",
|
||||
Utils.combinedMessage(regionsAlready, "region"));
|
||||
}
|
||||
if (!regionsAlreadyOtherWorld.isEmpty()) {
|
||||
this.messageBridge.message(player,
|
||||
"add-failedOtherWorld",
|
||||
Utils.combinedMessage(regionsAlreadyOtherWorld, "region"));
|
||||
}
|
||||
if (!regionsRentCancelled.isEmpty()) {
|
||||
this.messageBridge.message(player,
|
||||
"add-rentCancelled",
|
||||
Utils.combinedMessage(regionsRentCancelled, "region"));
|
||||
}
|
||||
if (!regionsBuyCancelled.isEmpty()) {
|
||||
this.messageBridge.message(player,
|
||||
"add-buyCancelled",
|
||||
Utils.combinedMessage(regionsBuyCancelled, "region"));
|
||||
}
|
||||
if (!namesBlacklisted.isEmpty()) {
|
||||
this.messageBridge.message(player,
|
||||
"add-blacklisted",
|
||||
Utils.createCommaSeparatedList(namesBlacklisted));
|
||||
}
|
||||
if (!namesNoPermission.isEmpty()) {
|
||||
this.messageBridge.message(player,
|
||||
"add-noPermissionRegions",
|
||||
Utils.createCommaSeparatedList(namesNoPermission));
|
||||
this.messageBridge.message(player, "add-noPermissionOwnerMember");
|
||||
}
|
||||
if (!namesAddCancelled.isEmpty()) {
|
||||
this.messageBridge.message(player,
|
||||
"add-rentCancelled",
|
||||
Utils.createCommaSeparatedList(namesAddCancelled));
|
||||
}
|
||||
}
|
||||
|
||||
// Add existing owners/members if any
|
||||
if(!landlord && !existing.isEmpty()) {
|
||||
UUID rentBy = existing.remove(0);
|
||||
OfflinePlayer rentByPlayer = Bukkit.getOfflinePlayer(rentBy);
|
||||
private void processRent(
|
||||
@Nonnull ProtectedRegion region,
|
||||
boolean landlord,
|
||||
List<UUID> existing,
|
||||
@Nonnull AddTaskState taskState
|
||||
) {
|
||||
Player player = taskState.sender();
|
||||
Set<GeneralRegion> regionsSuccess = taskState.regionsSuccess();
|
||||
Set<GeneralRegion> regionsRentCancelled = taskState.regionsRentCancelled(); // Denied by an event listener
|
||||
Set<String> namesAddCancelled = taskState.namesAddCancelled(); // Denied by an event listener
|
||||
World world = taskState.world();
|
||||
String regionName = region.getId();
|
||||
RentRegion rent = regionFactory.createRentRegion(regionName, world);
|
||||
// Set landlord
|
||||
if (landlord) {
|
||||
rent.setLandlord(player.getUniqueId(), player.getName());
|
||||
}
|
||||
|
||||
RentingRegionEvent rentingRegionEvent = new RentingRegionEvent(rent, rentByPlayer, false);
|
||||
Bukkit.getPluginManager().callEvent(rentingRegionEvent);
|
||||
if(rentingRegionEvent.isCancelled()) {
|
||||
regionsRentCancelled.add(rent);
|
||||
} else {
|
||||
// Add values to the rent and send it to FileManager
|
||||
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
|
||||
rent.setRenter(rentBy);
|
||||
rent.updateLastActiveTime();
|
||||
AddingRegionEvent event = plugin.getFileManager().addRegion(rent);
|
||||
if (event.isCancelled()) {
|
||||
namesAddCancelled.add(rent.getName());
|
||||
return;
|
||||
}
|
||||
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||
rent.update();
|
||||
|
||||
// Fire schematic event and updated times extended
|
||||
rent.handleSchematicEvent(GeneralRegion.RegionEvent.RENTED);
|
||||
// Add existing owners/members if any
|
||||
if (!landlord && !existing.isEmpty()) {
|
||||
UUID rentBy = existing.removeFirst();
|
||||
OfflinePlayer rentByPlayer = Bukkit.getOfflinePlayer(rentBy);
|
||||
|
||||
// Add others as friends
|
||||
for(UUID friend : existing) {
|
||||
rent.getFriendsFeature().addFriend(friend, null);
|
||||
}
|
||||
RentingRegionEvent rentingRegionEvent = new RentingRegionEvent(rent,
|
||||
rentByPlayer,
|
||||
false);
|
||||
Bukkit.getPluginManager().callEvent(rentingRegionEvent);
|
||||
if (rentingRegionEvent.isCancelled()) {
|
||||
regionsRentCancelled.add(rent);
|
||||
} else {
|
||||
// Add values to the rent and send it to FileManager
|
||||
rent.setRentedUntil(Calendar.getInstance()
|
||||
.getTimeInMillis() + rent.getDuration());
|
||||
rent.setRenter(rentBy);
|
||||
rent.updateLastActiveTime();
|
||||
|
||||
rent.notifyAndUpdate(new RentedRegionEvent(rent, false));
|
||||
}
|
||||
}
|
||||
// Fire schematic event and updated times extended
|
||||
rent.handleSchematicEvent(GeneralRegion.RegionEvent.RENTED);
|
||||
|
||||
regionsSuccess.add(rent);
|
||||
} else {
|
||||
BuyRegion buy = regionFactory.createBuyRegion(regionName, world);
|
||||
// Set landlord
|
||||
if(landlord) {
|
||||
buy.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
|
||||
}
|
||||
// Add others as friends
|
||||
for (UUID friend : existing) {
|
||||
rent.getFriendsFeature().addFriend(friend, null);
|
||||
}
|
||||
|
||||
AddingRegionEvent event = plugin.getFileManager().addRegion(buy);
|
||||
if (event.isCancelled()) {
|
||||
namesAddCancelled.add(buy.getName());
|
||||
return;
|
||||
}
|
||||
rent.notifyAndUpdate(new RentedRegionEvent(rent, false));
|
||||
}
|
||||
}
|
||||
|
||||
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||
buy.update();
|
||||
regionsSuccess.add(rent);
|
||||
}
|
||||
|
||||
// Add existing owners/members if any
|
||||
if(!landlord && !existing.isEmpty()) {
|
||||
UUID buyBy = existing.remove(0);
|
||||
OfflinePlayer buyByPlayer = Bukkit.getOfflinePlayer(buyBy);
|
||||
private void proccessBuy(
|
||||
@Nonnull ProtectedRegion region,
|
||||
boolean landlord,
|
||||
List<UUID> existing,
|
||||
@Nonnull AddTaskState taskState
|
||||
) {
|
||||
Player player = taskState.sender();
|
||||
Set<GeneralRegion> regionsSuccess = taskState.regionsSuccess();
|
||||
Set<GeneralRegion> regionsBuyCancelled = taskState.regionsBuyCancelled(); // Denied by an event listener
|
||||
Set<String> namesAddCancelled = taskState.namesAddCancelled(); // Denied by an event listener
|
||||
World world = taskState.world();
|
||||
String regionName = region.getId();
|
||||
BuyRegion buy = regionFactory.createBuyRegion(regionName, world);
|
||||
// Set landlord
|
||||
if (landlord) {
|
||||
buy.setLandlord(player.getUniqueId(), player.getName());
|
||||
}
|
||||
|
||||
BuyingRegionEvent buyingRegionEvent = new BuyingRegionEvent(buy, buyByPlayer);
|
||||
Bukkit.getPluginManager().callEvent(buyingRegionEvent);
|
||||
if(buyingRegionEvent.isCancelled()) {
|
||||
regionsBuyCancelled.add(buy);
|
||||
} else {
|
||||
// Set the owner
|
||||
buy.setBuyer(buyBy);
|
||||
buy.updateLastActiveTime();
|
||||
AddingRegionEvent event = plugin.getFileManager().addRegion(buy);
|
||||
if (event.isCancelled()) {
|
||||
namesAddCancelled.add(buy.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
// Update everything
|
||||
buy.handleSchematicEvent(GeneralRegion.RegionEvent.BOUGHT);
|
||||
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||
buy.update();
|
||||
|
||||
// Add others as friends
|
||||
for (UUID friend : existing) {
|
||||
buy.getFriendsFeature().addFriend(friend, null);
|
||||
}
|
||||
// Add existing owners/members if any
|
||||
if (!landlord && !existing.isEmpty()) {
|
||||
UUID buyBy = existing.removeFirst();
|
||||
OfflinePlayer buyByPlayer = Bukkit.getOfflinePlayer(buyBy);
|
||||
|
||||
buy.notifyAndUpdate(new BoughtRegionEvent(buy));
|
||||
}
|
||||
}
|
||||
BuyingRegionEvent buyingRegionEvent = new BuyingRegionEvent(buy,
|
||||
buyByPlayer);
|
||||
Bukkit.getPluginManager().callEvent(buyingRegionEvent);
|
||||
if (buyingRegionEvent.isCancelled()) {
|
||||
regionsBuyCancelled.add(buy);
|
||||
} else {
|
||||
// Set the owner
|
||||
buy.setBuyer(buyBy);
|
||||
buy.updateLastActiveTime();
|
||||
|
||||
regionsSuccess.add(buy);
|
||||
}
|
||||
}
|
||||
},
|
||||
() -> {
|
||||
if(!regionsSuccess.isEmpty()) {
|
||||
messageBridge.message(sender, "add-success", args[1], Utils.combinedMessage(regionsSuccess, "region"));
|
||||
}
|
||||
if(!regionsAlready.isEmpty()) {
|
||||
messageBridge.message(sender, "add-failed", Utils.combinedMessage(regionsAlready, "region"));
|
||||
}
|
||||
if(!regionsAlreadyOtherWorld.isEmpty()) {
|
||||
messageBridge.message(sender, "add-failedOtherWorld", Utils.combinedMessage(regionsAlreadyOtherWorld, "region"));
|
||||
}
|
||||
if(!regionsRentCancelled.isEmpty()) {
|
||||
messageBridge.message(sender, "add-rentCancelled", Utils.combinedMessage(regionsRentCancelled, "region"));
|
||||
}
|
||||
if(!regionsBuyCancelled.isEmpty()) {
|
||||
messageBridge.message(sender, "add-buyCancelled", Utils.combinedMessage(regionsBuyCancelled, "region"));
|
||||
}
|
||||
if(!namesBlacklisted.isEmpty()) {
|
||||
messageBridge.message(sender, "add-blacklisted", Utils.createCommaSeparatedList(namesBlacklisted));
|
||||
}
|
||||
if(!namesNoPermission.isEmpty()) {
|
||||
messageBridge.message(sender, "add-noPermissionRegions", Utils.createCommaSeparatedList(namesNoPermission));
|
||||
messageBridge.message(sender, "add-noPermissionOwnerMember");
|
||||
}
|
||||
if(!namesAddCancelled.isEmpty()) {
|
||||
messageBridge.message(sender, "add-rentCancelled", Utils.createCommaSeparatedList(namesAddCancelled));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
// Update everything
|
||||
buy.handleSchematicEvent(GeneralRegion.RegionEvent.BOUGHT);
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
if(sender.hasPermission("areashop.createrent")) {
|
||||
result.add("rent");
|
||||
}
|
||||
if(sender.hasPermission("areashop.createbuy")) {
|
||||
result.add("buy");
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
if(sender instanceof Player) {
|
||||
Player player = (Player)sender;
|
||||
if(sender.hasPermission("areashop.createrent") || sender.hasPermission("areashop.createbuy")) {
|
||||
for(ProtectedRegion region : plugin.getRegionManager(player.getWorld()).getRegions().values()) {
|
||||
result.add(region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Add others as friends
|
||||
for (UUID friend : existing) {
|
||||
buy.getFriendsFeature().addFriend(friend, null);
|
||||
}
|
||||
|
||||
buy.notifyAndUpdate(new BoughtRegionEvent(buy));
|
||||
}
|
||||
}
|
||||
|
||||
regionsSuccess.add(buy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return "Add a region";
|
||||
}
|
||||
|
||||
public String getHelp(CommandSender target) {
|
||||
if (target.hasPermission("areashop.createrent")
|
||||
|| target.hasPermission("areashop.createrent.member")
|
||||
|| target.hasPermission("areashop.createrent.owner")
|
||||
|
||||
|| target.hasPermission("areashop.createbuy")
|
||||
|| target.hasPermission("areashop.createbuy.member")
|
||||
|| target.hasPermission("areashop.createbuy.owner")) {
|
||||
return "help-add";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("add");
|
||||
}
|
||||
|
||||
private record AddTaskState(
|
||||
@Nonnull Player sender,
|
||||
@Nonnull GeneralRegion.RegionType regionType,
|
||||
@Nonnull Set<GeneralRegion> regionsSuccess,
|
||||
@Nonnull Set<GeneralRegion> regionsAlready,
|
||||
@Nonnull Set<GeneralRegion> regionsAlreadyOtherWorld,
|
||||
@Nonnull Set<GeneralRegion> regionsRentCancelled,
|
||||
@Nonnull Set<GeneralRegion> regionsBuyCancelled,
|
||||
@Nonnull Set<String> namesBlacklisted,
|
||||
@Nonnull Set<String> namesNoPermission,
|
||||
@Nonnull Set<String> namesAddCancelled,
|
||||
@Nonnull World world) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.OfflinePlayerParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class AddFriendCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_FRIEND = CloudKey.of("friend", String.class);
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
private final MessageBridge messageBridge;
|
||||
private final Plugin plugin;
|
||||
private final BukkitSchedulerExecutor executor;
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
@Inject
|
||||
public AddFriendCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull Plugin plugin,
|
||||
@Nonnull BukkitSchedulerExecutor executor,
|
||||
@Nonnull OfflinePlayerHelper offlinePlayerHelper
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.plugin = plugin;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
this.executor = executor;
|
||||
this.offlinePlayerHelper = offlinePlayerHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return "Allows you to add friends to your regions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.addfriendall") || target.hasPermission("areashop.addfriend")) {
|
||||
return "help-addFriend";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("addfriend")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.required(KEY_FRIEND, OfflinePlayerParser.parser())
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
private void handleCommand(CommandContext<PlayerCommandSource> context) {
|
||||
Player sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) {
|
||||
this.messageBridge.message(sender, "addfriend-noPermission");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_FRIEND))
|
||||
.whenCompleteAsync((offlinePlayer, exception) -> {
|
||||
if (exception != null) {
|
||||
sender.sendMessage("failed to lookup offline player!");
|
||||
exception.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
|
||||
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
|
||||
return;
|
||||
}
|
||||
processWithFriend(sender, region, offlinePlayer);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
private void processWithFriend(@Nonnull Player sender,
|
||||
@Nonnull GeneralRegion region,
|
||||
@Nonnull OfflinePlayer friend
|
||||
) {
|
||||
if (sender.hasPermission("areashop.addfriendall") && ((region instanceof RentRegion rentRegion && !rentRegion.isRented())
|
||||
|| (region instanceof BuyRegion buyRegion && !buyRegion.isSold()))) {
|
||||
this.messageBridge.message(sender, "addfriend-noOwner", region);
|
||||
return;
|
||||
|
||||
}
|
||||
if (!sender.hasPermission("areashop.addfriend")) {
|
||||
this.messageBridge.message(sender, "addfriend-noPermission", region);
|
||||
return;
|
||||
}
|
||||
if (!region.isOwner(sender)) {
|
||||
this.messageBridge.message(sender, "addfriend-noPermissionOther", region);
|
||||
return;
|
||||
}
|
||||
if (!friend.hasPlayedBefore() && !friend.isOnline() && !plugin.getConfig()
|
||||
.getBoolean("addFriendNotExistingPlayers")) {
|
||||
this.messageBridge.message(sender, "addfriend-notVisited", friend.getName(), region);
|
||||
} else if (region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
this.messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
|
||||
} else if (region.isOwner(friend.getUniqueId())) {
|
||||
this.messageBridge.message(sender, "addfriend-self", friend.getName(), region);
|
||||
} else if (region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
this.messageBridge.message(sender, "addfriend-success", friend.getName(), region);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("addfriend");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.SignProfileUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Materials;
|
||||
import me.wiefferink.areashop.tools.SignUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Optional;
|
||||
|
||||
@Singleton
|
||||
public class AddSignCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<GeneralRegion> KEY_REGION = CloudKey.of("region", GeneralRegion.class);
|
||||
|
||||
private final SignManager signManager;
|
||||
private final Plugin plugin;
|
||||
private final IFileManager fileManager;
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Inject
|
||||
public AddSignCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull SignManager signManager,
|
||||
@Nonnull Plugin plugin
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.signManager = signManager;
|
||||
this.plugin = plugin;
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return "Allows you to add signs to existing regions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if(target.hasPermission("areashop.addsign")) {
|
||||
return "help-addsign";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("addsign")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.optional(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
|
||||
.flag(SignProfileUtil.DEFAULT_FLAG)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.addsign")) {
|
||||
throw new AreaShopCommandException("addsign-noPermission");
|
||||
}
|
||||
// Get the sign
|
||||
Block block = null;
|
||||
BlockIterator blockIterator = new BlockIterator(sender, 100);
|
||||
while(blockIterator.hasNext() && block == null) {
|
||||
Block next = blockIterator.next();
|
||||
if(next.getType() != Material.AIR) {
|
||||
block = next;
|
||||
}
|
||||
}
|
||||
if(block == null || !Materials.isSign(block.getType())) {
|
||||
messageBridge.message(sender, "addsign-noSign");
|
||||
return;
|
||||
}
|
||||
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, KEY_REGION);
|
||||
String profile = SignProfileUtil.getOrParseProfile(context, this.plugin);
|
||||
Optional<RegionSign> optionalRegionSign = this.signManager.signFromLocation(block.getLocation());
|
||||
if(optionalRegionSign.isPresent()) {
|
||||
RegionSign regionSign = optionalRegionSign.get();
|
||||
messageBridge.message(sender, "addsign-alreadyRegistered", regionSign.getRegion());
|
||||
return;
|
||||
}
|
||||
|
||||
region.getSignsFeature().addSign(block.getLocation(), block.getType(), SignUtils.getSignFacing(block), profile);
|
||||
if(profile == null) {
|
||||
messageBridge.message(sender, "addsign-success", region);
|
||||
} else {
|
||||
messageBridge.message(sender, "addsign-successProfile", profile, region);
|
||||
}
|
||||
region.update();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("addsign");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class AddfriendCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop addfriend";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.addfriendall") || target.hasPermission("areashop.addfriend")) {
|
||||
return "help-addFriend";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) {
|
||||
messageBridge.message(sender, "addfriend-noPermission");
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length < 2) {
|
||||
messageBridge.message(sender, "addfriend-help");
|
||||
return;
|
||||
}
|
||||
|
||||
GeneralRegion region;
|
||||
if(args.length <= 2) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(sender.hasPermission("areashop.addfriendall")) {
|
||||
if((region instanceof RentRegion && !((RentRegion)region).isRented())
|
||||
|| (region instanceof BuyRegion && !((BuyRegion)region).isSold())) {
|
||||
messageBridge.message(sender, "addfriend-noOwner", region);
|
||||
return;
|
||||
}
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
|
||||
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.isOwner(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "addfriend-successOther", friend.getName(), region);
|
||||
}
|
||||
} else {
|
||||
if(sender.hasPermission("areashop.addfriend") && sender instanceof Player) {
|
||||
if(region.isOwner((Player)sender)) {
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
|
||||
messageBridge.message(sender, "addfriend-notVisited", args[1], region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.isOwner(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "addfriend-self", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
|
||||
if(region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "addfriend-success", friend.getName(), region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "addfriend-noPermissionOther", region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "addfriend-noPermission", region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.interfaces.BukkitInterface;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Materials;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@Singleton
|
||||
public class AddsignCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private SignManager signManager;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
@Inject
|
||||
private BukkitInterface bukkitInterface;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop addsign";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.addsign")) {
|
||||
return "help-addsign";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.addsign")) {
|
||||
messageBridge.message(sender, "addsign-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
|
||||
// Get the sign
|
||||
Block block = null;
|
||||
BlockIterator blockIterator = new BlockIterator(player, 100);
|
||||
while(blockIterator.hasNext() && block == null) {
|
||||
Block next = blockIterator.next();
|
||||
if(next.getType() != Material.AIR) {
|
||||
block = next;
|
||||
}
|
||||
}
|
||||
if(block == null || !Materials.isSign(block.getType())) {
|
||||
messageBridge.message(sender, "addsign-noSign");
|
||||
return;
|
||||
}
|
||||
|
||||
GeneralRegion region;
|
||||
if(args.length > 1) {
|
||||
// Get region by argument
|
||||
region = fileManager.getRegion(args[1]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[1]);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Get region by sign position
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(block.getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "addsign-noRegions");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "addsign-couldNotDetect", regions.get(0).getName(), regions.get(1).getName());
|
||||
return;
|
||||
}
|
||||
region = regions.get(0);
|
||||
}
|
||||
String profile = null;
|
||||
if(args.length > 2) {
|
||||
profile = args[2];
|
||||
Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false);
|
||||
if(!profiles.contains(profile)) {
|
||||
messageBridge.message(sender, "addsign-wrongProfile", Utils.createCommaSeparatedList(profiles), region);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Optional<RegionSign> optionalRegionSign = signManager.signFromLocation(block.getLocation());
|
||||
if(optionalRegionSign.isPresent()) {
|
||||
RegionSign regionSign = optionalRegionSign.get();
|
||||
messageBridge.message(sender, "addsign-alreadyRegistered", regionSign.getRegion());
|
||||
return;
|
||||
}
|
||||
|
||||
region.getSignsFeature().addSign(block.getLocation(), block.getType(), bukkitInterface.getSignFacing(block), profile);
|
||||
if(profile == null) {
|
||||
messageBridge.message(sender, "addsign-success", region);
|
||||
} else {
|
||||
messageBridge.message(sender, "addsign-successProfile", profile, region);
|
||||
}
|
||||
region.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(plugin.getConfig().getStringList("signProfiles"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,82 +1,69 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class BuyCommand extends CommandAreaShop {
|
||||
public class BuyCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
private final CommandFlag<BuyRegion> buyRegionFlag;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop buy";
|
||||
}
|
||||
@Inject
|
||||
public BuyCommand(@Nonnull IFileManager fileManager) {
|
||||
this.buyRegionFlag = RegionParseUtil.createDefaultBuy(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.buy")) {
|
||||
return "help-buy";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if(target.hasPermission("areashop.buy")) {
|
||||
return "help-buy";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.buy")) {
|
||||
messageBridge.message(sender, "buy-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
if(args.length > 1 && args[1] != null) {
|
||||
BuyRegion region = fileManager.getBuy(args[1]);
|
||||
if(region == null) {
|
||||
messageBridge.message(player, "buy-notBuyable", args[1]);
|
||||
} else {
|
||||
region.buy(player);
|
||||
}
|
||||
} else {
|
||||
// get the region by location
|
||||
List<BuyRegion> regions = Utils.getImportantBuyRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
} else {
|
||||
regions.get(0).buy(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return "Allows you to buy a region";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("buy");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder
|
||||
.literal("buy")
|
||||
.flag(this.buyRegionFlag)
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
if (!context.hasPermission("areashop.buy")) {
|
||||
throw new AreaShopCommandException("buy-noPermission");
|
||||
}
|
||||
Player sender = context.sender().sender();
|
||||
BuyRegion region = RegionParseUtil.getOrParseBuyRegion(context, sender, this.buyRegionFlag);
|
||||
region.buy(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(BuyRegion region : fileManager.getBuysRef()) {
|
||||
if(!region.isSold()) {
|
||||
result.add(region.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Abstract class for generalising command classes.
|
||||
*/
|
||||
public abstract class CommandAreaShop {
|
||||
|
||||
private final Map<String, CommandTime> lastUsed;
|
||||
|
||||
protected CommandAreaShop() {
|
||||
lastUsed = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this Command instance can execute the given command and arguments.
|
||||
* @param command The command to check for execution
|
||||
* @param args The arguments to check
|
||||
* @return true if it can execute the command, false otherwise
|
||||
*/
|
||||
public boolean canExecute(Command command, String[] args) {
|
||||
String commandString = command.getName() + " " + StringUtils.join(args, " ");
|
||||
if(commandString.length() > getCommandStart().length()) {
|
||||
return commandString.toLowerCase().startsWith(getCommandStart().toLowerCase() + " ");
|
||||
}
|
||||
return commandString.toLowerCase().startsWith(getCommandStart().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of string to complete a command with (raw list, not matching ones not filtered out).
|
||||
* @param toComplete The number of the argument that has to be completed
|
||||
* @param start The already given start of the command
|
||||
* @param sender The CommandSender that wants to tab complete
|
||||
* @return A collection with all the possibilities for argument to complete
|
||||
*/
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the argument that comes after the base command that this command reacts to.
|
||||
* @return The string that should be in front of the command for this class to act
|
||||
*/
|
||||
public abstract String getCommandStart();
|
||||
|
||||
/**
|
||||
* Returns the correct help string key to be used on the help page.
|
||||
* @param target The CommandSender that the help message is for
|
||||
* @return The help message key according to the permissions of the reciever
|
||||
*/
|
||||
public abstract String getHelp(CommandSender target);
|
||||
|
||||
/**
|
||||
* Execute a (sub)command if the conditions are met.
|
||||
* @param sender The commandSender that executed the command
|
||||
* @param args The arguments that are given
|
||||
*/
|
||||
public abstract void execute(CommandSender sender, String[] args);
|
||||
|
||||
/**
|
||||
* Confirm a command.
|
||||
* @param sender To confirm it for, or send a message to confirm
|
||||
* @param args Command args
|
||||
* @param message Message to send when confirmation is required
|
||||
* @return true if confirmed, false if confirmation is required
|
||||
*/
|
||||
public boolean confirm(CommandSender sender, String[] args, Message message) {
|
||||
String command = "/" + getCommandStart() + " " + StringUtils.join(args, " ", 1, args.length);
|
||||
long now = System.currentTimeMillis();
|
||||
CommandTime last = lastUsed.get(sender.getName());
|
||||
if(last != null && last.command.equalsIgnoreCase(command) && last.time > (now - 1000 * 60)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
message.prefix().append(Message.fromKey("confirm-yes").replacements(command)).send(sender);
|
||||
lastUsed.put(sender.getName(), new CommandTime(command, now));
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class CommandTime {
|
||||
public final String command;
|
||||
public final long time;
|
||||
|
||||
CommandTime(String command, long time) {
|
||||
this.command = command;
|
||||
this.time = time;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.WorldSelection;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
@@ -11,142 +18,168 @@ import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@Singleton
|
||||
public class DelCommand extends CommandAreaShop {
|
||||
public class DelCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private WorldEditInterface worldEditInterface;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop del";
|
||||
}
|
||||
private static final CloudKey<GeneralRegion> KEY_REGION = CloudKey.of("region", GeneralRegion.class);
|
||||
private final WorldEditInterface worldEditInterface;
|
||||
private final IFileManager fileManager;
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.destroyrent") || target.hasPermission("areashop.destroybuy") || target.hasPermission("areashop.destroyrent.landlord") || target.hasPermission("areashop.destroybuy.landlord")) {
|
||||
return "help-del";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Inject
|
||||
public DelCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull WorldEditInterface worldEditInterface,
|
||||
@Nonnull IFileManager fileManager
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.worldEditInterface = worldEditInterface;
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.destroybuy")
|
||||
&& !sender.hasPermission("areashop.destroybuy.landlord")
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return "Allows you to delete regions";
|
||||
}
|
||||
|
||||
&& !sender.hasPermission("areashop.destroyrent")
|
||||
&& !sender.hasPermission("areashop.destroyrent.landlord")) {
|
||||
messageBridge.message(sender, "del-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2) {
|
||||
// Only players can have a selection
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-weOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if(selection == null) {
|
||||
messageBridge.message(player, "cmd-noSelection");
|
||||
return;
|
||||
}
|
||||
List<GeneralRegion> regions = Utils.getRegionsInSelection(selection);
|
||||
if(regions == null || regions.isEmpty()) {
|
||||
messageBridge.message(player, "cmd-noRegionsFound");
|
||||
return;
|
||||
}
|
||||
// Start removing the regions that he has permission for
|
||||
ArrayList<String> namesSuccess = new ArrayList<>();
|
||||
TreeSet<GeneralRegion> regionsFailed = new TreeSet<>();
|
||||
TreeSet<GeneralRegion> regionsCancelled = new TreeSet<>();
|
||||
for(GeneralRegion region : regions) {
|
||||
boolean isLandlord = region.isLandlord(((Player)sender).getUniqueId());
|
||||
if(region instanceof RentRegion) {
|
||||
if(!sender.hasPermission("areashop.destroyrent") && !(isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
|
||||
regionsFailed.add(region);
|
||||
continue;
|
||||
}
|
||||
} else if(region instanceof BuyRegion) {
|
||||
if(!sender.hasPermission("areashop.destroybuy") && !(isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
|
||||
regionsFailed.add(region);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.destroyrent") || target.hasPermission("areashop.destroybuy") || target.hasPermission(
|
||||
"areashop.destroyrent.landlord") || target.hasPermission("areashop.destroybuy.landlord")) {
|
||||
return "help-del";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
DeletingRegionEvent event = fileManager.deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
regionsCancelled.add(region);
|
||||
} else {
|
||||
namesSuccess.add(region.getName());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("delete", "del");
|
||||
}
|
||||
|
||||
// Send messages
|
||||
if(!namesSuccess.isEmpty()) {
|
||||
messageBridge.message(sender, "del-success", Utils.createCommaSeparatedList(namesSuccess));
|
||||
}
|
||||
if(!regionsFailed.isEmpty()) {
|
||||
messageBridge.message(sender, "del-failed", Utils.combinedMessage(regionsFailed, "region"));
|
||||
}
|
||||
if(!regionsCancelled.isEmpty()) {
|
||||
messageBridge.message(sender, "del-cancelled", Utils.combinedMessage(regionsCancelled, "region"));
|
||||
}
|
||||
} else {
|
||||
GeneralRegion region = fileManager.getRegion(args[1]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[1]);
|
||||
return;
|
||||
}
|
||||
boolean isLandlord = sender instanceof Player && region.isLandlord(((Player)sender).getUniqueId());
|
||||
if(region instanceof RentRegion) {
|
||||
// Remove the rent if the player has permission
|
||||
if(sender.hasPermission("areashop.destroyrent") || (isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
|
||||
DeletingRegionEvent event = fileManager.deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
messageBridge.message(sender, "general-cancelled", event.getReason());
|
||||
} else {
|
||||
messageBridge.message(sender, "destroy-successRent", region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "destroy-noPermissionRent", region);
|
||||
}
|
||||
} else if(region instanceof BuyRegion) {
|
||||
// Remove the buy if the player has permission
|
||||
if(sender.hasPermission("areashop.destroybuy") || (isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
|
||||
DeletingRegionEvent event = fileManager.deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
messageBridge.message(sender, "general-cancelled", event.getReason());
|
||||
} else {
|
||||
messageBridge.message(sender, "destroy-successBuy", region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "destroy-noPermissionBuy", region);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("del", "delete")
|
||||
.optional(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result = fileManager.getRegionNames();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.destroybuy")
|
||||
&& !sender.hasPermission("areashop.destroybuy.landlord")
|
||||
&& !sender.hasPermission("areashop.destroyrent")
|
||||
&& !sender.hasPermission("areashop.destroyrent.landlord")) {
|
||||
throw new AreaShopCommandException("del-noPermission");
|
||||
}
|
||||
Optional<GeneralRegion> inputRegion = context.optional(KEY_REGION);
|
||||
if (inputRegion.isPresent()) {
|
||||
handleSingleDeletion(sender, inputRegion.get());
|
||||
return;
|
||||
}
|
||||
List<GeneralRegion> regions;
|
||||
if (sender instanceof Player player) {
|
||||
WorldSelection selection = WorldSelection.fromPlayer(player, this.worldEditInterface);
|
||||
regions = Utils.getWorldEditRegionsInSelection(selection.selection()).stream()
|
||||
.map(ProtectedRegion::getId)
|
||||
.map(this.fileManager::getRegion)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
} else {
|
||||
throw new AreaShopCommandException("cmd-weOnlyByPlayer");
|
||||
}
|
||||
if (regions.isEmpty()) {
|
||||
throw new AreaShopCommandException("cmd-noWERegionsFound");
|
||||
}
|
||||
handleMassDeletion(player, regions);
|
||||
}
|
||||
|
||||
private void handleSingleDeletion(@Nonnull CommandSender sender, GeneralRegion region) {
|
||||
boolean isLandlord = sender instanceof Player player && region.isLandlord(player.getUniqueId());
|
||||
if (region instanceof RentRegion) {
|
||||
// Remove the rent if the player has permission
|
||||
if (sender.hasPermission("areashop.destroyrent") || (isLandlord && sender.hasPermission(
|
||||
"areashop.destroyrent.landlord"))) {
|
||||
DeletingRegionEvent event = fileManager.deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
this.messageBridge.message(sender, "general-cancelled", event.getReason());
|
||||
} else {
|
||||
this.messageBridge.message(sender, "destroy-successRent", region);
|
||||
}
|
||||
} else {
|
||||
this.messageBridge.message(sender, "destroy-noPermissionRent", region);
|
||||
}
|
||||
} else if (region instanceof BuyRegion) {
|
||||
// Remove the buy if the player has permission
|
||||
if (sender.hasPermission("areashop.destroybuy") || (isLandlord && sender.hasPermission(
|
||||
"areashop.destroybuy.landlord"))) {
|
||||
DeletingRegionEvent event = fileManager.deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
messageBridge.message(sender, "general-cancelled", event.getReason());
|
||||
} else {
|
||||
messageBridge.message(sender, "destroy-successBuy", region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "destroy-noPermissionBuy", region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMassDeletion(@Nonnull Player sender, @Nonnull List<GeneralRegion> regions) {
|
||||
List<String> namesSuccess = new ArrayList<>();
|
||||
Set<GeneralRegion> regionsFailed = new TreeSet<>();
|
||||
Set<GeneralRegion> regionsCancelled = new TreeSet<>();
|
||||
for (GeneralRegion region : regions) {
|
||||
if (cannotDelete(sender, region)) {
|
||||
regionsFailed.add(region);
|
||||
continue;
|
||||
}
|
||||
|
||||
DeletingRegionEvent event = this.fileManager.deleteRegion(region, true);
|
||||
if (event.isCancelled()) {
|
||||
regionsCancelled.add(region);
|
||||
} else {
|
||||
namesSuccess.add(region.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// Send messages
|
||||
if (!namesSuccess.isEmpty()) {
|
||||
this.messageBridge.message(sender, "del-success", Utils.createCommaSeparatedList(namesSuccess));
|
||||
}
|
||||
if (!regionsFailed.isEmpty()) {
|
||||
this.messageBridge.message(sender, "del-failed", Utils.combinedMessage(regionsFailed, "region"));
|
||||
}
|
||||
if (!regionsCancelled.isEmpty()) {
|
||||
this.messageBridge.message(sender, "del-cancelled", Utils.combinedMessage(regionsCancelled, "region"));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean cannotDelete(@Nonnull Player sender, @Nonnull GeneralRegion region) {
|
||||
boolean isLandlord = region.isLandlord(sender.getUniqueId());
|
||||
if (region instanceof RentRegion
|
||||
&& (!sender.hasPermission("areashop.destroyrent") && !(isLandlord && sender.hasPermission(
|
||||
"areashop.destroyrent.landlord")))) {
|
||||
return true;
|
||||
|
||||
}
|
||||
return region instanceof BuyRegion
|
||||
&& (!sender.hasPermission("areashop.destroybuy") && !(isLandlord && sender.hasPermission(
|
||||
"areashop.destroybuy.landlord")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.OfflinePlayerParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.features.FriendsFeature;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class DelFriendCommand extends AreashopCommandBean {
|
||||
|
||||
|
||||
private static final CloudKey<String> KEY_PLAYER = CloudKey.of("player", String.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
private final BukkitSchedulerExecutor executor;
|
||||
|
||||
@Inject
|
||||
public DelFriendCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
|
||||
@Nonnull BukkitSchedulerExecutor executor
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
this.offlinePlayerHelper = offlinePlayerHelper;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a person can remove friends.
|
||||
*
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can remove friends, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if (person.hasPermission("areashop.delfriendall")) {
|
||||
return true;
|
||||
}
|
||||
if (person instanceof Player player) {
|
||||
return region.isOwner(player) && player.hasPermission("areashop.delfriend");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.delfriendall") || target.hasPermission("areashop.delfriend")) {
|
||||
return "help-delFriend";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("deletefriend", "delfriend");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("delfriend", "deletefriend")
|
||||
.required(KEY_PLAYER, OfflinePlayerParser.parser(), this::suggestFriends)
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) {
|
||||
throw new AreaShopCommandException("delfriend-noPermission");
|
||||
}
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
|
||||
.whenCompleteAsync((offlinePlayer, exception) -> {
|
||||
if (exception != null) {
|
||||
sender.sendMessage("failed to lookup offline player!");
|
||||
exception.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
|
||||
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
|
||||
return;
|
||||
}
|
||||
processWithSender(sender, region, offlinePlayer);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
private void processWithSender(@Nonnull CommandSender sender,
|
||||
@Nonnull GeneralRegion region,
|
||||
@Nonnull OfflinePlayer friend) {
|
||||
FriendsFeature friendsFeature = region.getFriendsFeature();
|
||||
if (sender.hasPermission("areashop.delfriendall")) {
|
||||
if ((region instanceof RentRegion rentRegion && !rentRegion.isRented())
|
||||
|| (region instanceof BuyRegion buyRegion && !buyRegion.isSold())) {
|
||||
throw new AreaShopCommandException("delfriend-noOwner", region);
|
||||
|
||||
}
|
||||
if (!friendsFeature.getFriends().contains(friend.getUniqueId())) {
|
||||
throw new AreaShopCommandException("delfriend-notAdded", friend.getName(), region);
|
||||
|
||||
}
|
||||
if (friendsFeature.deleteFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
this.messageBridge.message(sender, "delfriend-successOther", friend.getName(), region);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!sender.hasPermission("areashop.delfriend") || !(sender instanceof Player player)) {
|
||||
throw new AreaShopCommandException("delfriend-noPermission", region);
|
||||
}
|
||||
if (!region.isOwner(player)) {
|
||||
throw new AreaShopCommandException("delfriend-noPermissionOther", region);
|
||||
}
|
||||
if (!friendsFeature.getFriends().contains(friend.getUniqueId())) {
|
||||
throw new AreaShopCommandException("delfriend-notAdded", friend.getName(), region);
|
||||
} else if (friendsFeature.deleteFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
this.messageBridge.message(sender, "delfriend-success", friend.getName(), region);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestFriends(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.delfriend")) {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
GeneralRegion region;
|
||||
try {
|
||||
region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
} catch (AreaShopCommandException ignored) {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
if (!sender.hasPermission("areashop.delfriendall")
|
||||
&& sender instanceof Player player
|
||||
&& !region.isOwner(player)
|
||||
) {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
String text = input.peekString();
|
||||
FriendsFeature friendsFeature = region.getFriendsFeature();
|
||||
Collection<Suggestion> suggestion = friendsFeature.getFriendNames().stream()
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestion);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.tools.Materials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Optional;
|
||||
|
||||
@Singleton
|
||||
public class DelSignCommand extends AreashopCommandBean {
|
||||
|
||||
private final SignManager signManager;
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Inject
|
||||
public DelSignCommand(@Nonnull MessageBridge messageBridge, @Nonnull SignManager signManager) {
|
||||
this.signManager = signManager;
|
||||
this.messageBridge = messageBridge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("deletesign", "delsign");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("delsign", "deletesign")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.delsign")) {
|
||||
return "help-delsign";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.delsign")) {
|
||||
throw new AreaShopCommandException("delsign-noPermission");
|
||||
}
|
||||
// Get the sign
|
||||
Block block = null;
|
||||
BlockIterator blockIterator = new BlockIterator(sender, 100);
|
||||
while (blockIterator.hasNext() && block == null) {
|
||||
Block next = blockIterator.next();
|
||||
if (!next.getType().isAir()) {
|
||||
block = next;
|
||||
}
|
||||
}
|
||||
if (block == null || !Materials.isSign(block.getType())) {
|
||||
throw new AreaShopCommandException("delsign-noSign");
|
||||
}
|
||||
Optional<RegionSign> optionalSign = signManager.removeSign(block.getLocation());
|
||||
if (optionalSign.isEmpty()) {
|
||||
throw new AreaShopCommandException("delsign-noRegion");
|
||||
}
|
||||
RegionSign regionSign = optionalSign.get();
|
||||
messageBridge.message(sender, "delsign-success", regionSign.getRegion());
|
||||
regionSign.remove();
|
||||
// Sometimes the RegionSign data is corrupted. Forcefully set the block to air
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class DelfriendCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop delfriend";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.delfriendall") || target.hasPermission("areashop.delfriend")) {
|
||||
return "help-delFriend";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a person can remove friends.
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can remove friends, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if(person.hasPermission("areashop.delfriendall")) {
|
||||
return true;
|
||||
}
|
||||
if(person instanceof Player) {
|
||||
Player player = (Player)person;
|
||||
return region.isOwner(player) && player.hasPermission("areashop.delfriend");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) {
|
||||
messageBridge.message(sender, "delfriend-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2) {
|
||||
messageBridge.message(sender, "delfriend-help");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region;
|
||||
if(args.length <= 2) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(sender.hasPermission("areashop.delfriendall")) {
|
||||
if((region instanceof RentRegion && !((RentRegion)region).isRented())
|
||||
|| (region instanceof BuyRegion && !((BuyRegion)region).isSold())) {
|
||||
messageBridge.message(sender, "delfriend-noOwner", region);
|
||||
return;
|
||||
}
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "delfriend-successOther", friend.getName(), region);
|
||||
}
|
||||
} else {
|
||||
if(sender.hasPermission("areashop.delfriend") && sender instanceof Player) {
|
||||
if(region.isOwner((Player)sender)) {
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(!region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
|
||||
messageBridge.message(sender, "delfriend-notAdded", friend.getName(), region);
|
||||
return;
|
||||
}
|
||||
if(region.getFriendsFeature().deleteFriend(friend.getUniqueId(), sender)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "delfriend-success", friend.getName(), region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "delfriend-noPermissionOther", region);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "delfriend-noPermission", region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.features.signs.RegionSign;
|
||||
import me.wiefferink.areashop.features.signs.SignManager;
|
||||
import me.wiefferink.areashop.features.signs.SignsFeature;
|
||||
import me.wiefferink.areashop.tools.Materials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Singleton
|
||||
public class DelsignCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private SignManager signManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop delsign";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.delsign")) {
|
||||
return "help-delsign";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.delsign")) {
|
||||
messageBridge.message(sender, "delsign-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
|
||||
// Get the sign
|
||||
Block block = null;
|
||||
BlockIterator blockIterator = new BlockIterator(player, 100);
|
||||
while(blockIterator.hasNext() && block == null) {
|
||||
Block next = blockIterator.next();
|
||||
if(next.getType() != Material.AIR) {
|
||||
block = next;
|
||||
}
|
||||
}
|
||||
if(block == null || !Materials.isSign(block.getType())) {
|
||||
messageBridge.message(sender, "delsign-noSign");
|
||||
return;
|
||||
}
|
||||
Optional<RegionSign> optionalSign = signManager.removeSign(block.getLocation());
|
||||
if(optionalSign.isEmpty()) {
|
||||
messageBridge.message(sender, "delsign-noRegion");
|
||||
return;
|
||||
}
|
||||
RegionSign regionSign = optionalSign.get();
|
||||
messageBridge.message(sender, "delsign-success", regionSign.getRegion());
|
||||
signManager.removeSign(regionSign);
|
||||
regionSign.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionGroupParser;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
@@ -10,170 +18,183 @@ import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.DoubleParser;
|
||||
import org.incendo.cloud.parser.standard.EnumParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@Singleton
|
||||
public class FindCommand extends CommandAreaShop {
|
||||
public class FindCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private Economy economy;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
private static final CloudKey<GeneralRegion.RegionType> KEY_REGION_TYPE = CloudKey.of("regionType",
|
||||
GeneralRegion.RegionType.class);
|
||||
private static final CloudKey<Double> KEY_PRICE = CloudKey.of("maxPrice", Double.class);
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop find";
|
||||
}
|
||||
private final Economy economy;
|
||||
private final IFileManager fileManager;
|
||||
private final CommandFlag<RegionGroup> regionGroupFlag;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.find")) {
|
||||
return "help-find";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.find")) {
|
||||
messageBridge.message(sender, "find-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
if(args.length <= 1 || args[1] == null || (!args[1].equalsIgnoreCase("buy") && !args[1].equalsIgnoreCase("rent"))) {
|
||||
messageBridge.message(sender, "find-help");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
double balance = 0.0;
|
||||
if(economy != null) {
|
||||
balance = economy.getBalance(player);
|
||||
}
|
||||
double maxPrice = 0;
|
||||
boolean maxPriceSet = false;
|
||||
RegionGroup group = null;
|
||||
// Parse optional price argument
|
||||
if(args.length >= 3) {
|
||||
try {
|
||||
maxPrice = Double.parseDouble(args[2]);
|
||||
maxPriceSet = true;
|
||||
} catch(NumberFormatException e) {
|
||||
messageBridge.message(sender, "find-wrongMaxPrice", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Parse optional group argument
|
||||
if(args.length >= 4) {
|
||||
group = fileManager.getGroup(args[3]);
|
||||
if(group == null) {
|
||||
messageBridge.message(sender, "find-wrongGroup", args[3]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@Inject
|
||||
public FindCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull Economy economy,
|
||||
@Nonnull IFileManager fileManager
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.economy = economy;
|
||||
this.fileManager = fileManager;
|
||||
this.regionGroupFlag = CommandFlag.builder("region")
|
||||
.withComponent(ParserDescriptor.of(new RegionGroupParser<>(fileManager, "find-wrongGroup"),
|
||||
RegionGroup.class))
|
||||
.build();
|
||||
}
|
||||
|
||||
// Find buy regions
|
||||
if(args[1].equalsIgnoreCase("buy")) {
|
||||
Collection<BuyRegion> regions = fileManager.getBuysRef();
|
||||
List<BuyRegion> results = new LinkedList<>();
|
||||
for(BuyRegion region : regions) {
|
||||
if(!region.isSold()
|
||||
&& ((region.getPrice() <= balance && !maxPriceSet) || (region.getPrice() <= maxPrice && maxPriceSet))
|
||||
&& (group == null || group.isMember(region))
|
||||
&& (region.getBooleanSetting("general.findCrossWorld") || player.getWorld().equals(region.getWorld()))) {
|
||||
results.add(region);
|
||||
}
|
||||
}
|
||||
if(!results.isEmpty()) {
|
||||
// Draw a random one
|
||||
BuyRegion region = results.get(new Random().nextInt(results.size()));
|
||||
Message onlyInGroup = Message.empty();
|
||||
if(group != null) {
|
||||
onlyInGroup = Message.fromKey("find-onlyInGroup").replacements(args[3]);
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Teleport
|
||||
if(maxPriceSet) {
|
||||
messageBridge.message(player, "find-successMax", "buy", Utils.formatCurrency(maxPrice), onlyInGroup, region);
|
||||
} else {
|
||||
messageBridge.message(player, "find-success", "buy", Utils.formatCurrency(balance), onlyInGroup, region);
|
||||
}
|
||||
region.getTeleportFeature().teleportPlayer(player, region.getBooleanSetting("general.findTeleportToSign"), false);
|
||||
} else {
|
||||
Message onlyInGroup = Message.empty();
|
||||
if(group != null) {
|
||||
onlyInGroup = Message.fromKey("find-onlyInGroup").replacements(args[3]);
|
||||
}
|
||||
if(maxPriceSet) {
|
||||
messageBridge.message(player, "find-noneFoundMax", "buy", Utils.formatCurrency(maxPrice), onlyInGroup);
|
||||
} else {
|
||||
messageBridge.message(player, "find-noneFound", "buy", Utils.formatCurrency(balance), onlyInGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if(target.hasPermission("areashop.find")) {
|
||||
return "help-find";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Find rental regions
|
||||
else {
|
||||
Collection<RentRegion> regions = fileManager.getRentsRef();
|
||||
List<RentRegion> results = new LinkedList<>();
|
||||
for(RentRegion region : regions) {
|
||||
if(!region.isRented()
|
||||
&& ((region.getPrice() <= balance && !maxPriceSet) || (region.getPrice() <= maxPrice && maxPriceSet))
|
||||
&& (group == null || group.isMember(region))
|
||||
&& (region.getBooleanSetting("general.findCrossWorld") || player.getWorld().equals(region.getWorld()))) {
|
||||
results.add(region);
|
||||
}
|
||||
}
|
||||
if(!results.isEmpty()) {
|
||||
// Draw a random one
|
||||
RentRegion region = results.get(new Random().nextInt(results.size()));
|
||||
Message onlyInGroup = Message.empty();
|
||||
if(group != null) {
|
||||
onlyInGroup = Message.fromKey("find-onlyInGroup").replacements(args[3]);
|
||||
}
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("find")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.required(KEY_REGION_TYPE, EnumParser.enumParser(GeneralRegion.RegionType.class))
|
||||
.optional(KEY_PRICE, DoubleParser.doubleParser(0))
|
||||
.flag(this.regionGroupFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
// Teleport
|
||||
if(maxPriceSet) {
|
||||
messageBridge.message(player, "find-successMax", "rent", Utils.formatCurrency(maxPrice), onlyInGroup, region);
|
||||
} else {
|
||||
messageBridge.message(player, "find-success", "rent", Utils.formatCurrency(balance), onlyInGroup, region);
|
||||
}
|
||||
region.getTeleportFeature().teleportPlayer(player, region.getBooleanSetting("general.findTeleportToSign"), false);
|
||||
} else {
|
||||
Message onlyInGroup = Message.empty();
|
||||
if(group != null) {
|
||||
onlyInGroup = Message.fromKey("find-onlyInGroup").replacements(args[3]);
|
||||
}
|
||||
if(maxPriceSet) {
|
||||
messageBridge.message(player, "find-noneFoundMax", "rent", Utils.formatCurrency(maxPrice), onlyInGroup);
|
||||
} else {
|
||||
messageBridge.message(player, "find-noneFound", "rent", Utils.formatCurrency(balance), onlyInGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("find");
|
||||
}
|
||||
|
||||
}
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.find")) {
|
||||
throw new AreaShopCommandException("find-noPermission");
|
||||
}
|
||||
double balance;
|
||||
if (economy != null) {
|
||||
balance = economy.getBalance(sender);
|
||||
} else {
|
||||
balance = 0;
|
||||
}
|
||||
boolean maxPriceSet = context.contains(KEY_PRICE);
|
||||
double maxPrice = context.getOrDefault(KEY_PRICE, Double.MAX_VALUE);
|
||||
RegionGroup group = context.flags().get(this.regionGroupFlag);
|
||||
GeneralRegion.RegionType regionType = context.get(KEY_REGION_TYPE);
|
||||
Message onlyInGroup;
|
||||
if (group != null) {
|
||||
onlyInGroup = Message.fromKey("find-onlyInGroup").replacements(group.getName());
|
||||
} else {
|
||||
onlyInGroup = Message.empty();
|
||||
}
|
||||
switch (regionType) {
|
||||
case BUY -> handleBuy(sender, balance, maxPrice, maxPriceSet, onlyInGroup, group);
|
||||
case RENT -> handleRent(sender, balance, maxPrice, maxPriceSet, onlyInGroup, group);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result.add("buy");
|
||||
result.add("rent");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private void handleBuy(@Nonnull Player sender,
|
||||
double balance,
|
||||
double maxPrice,
|
||||
boolean maxPriceSet,
|
||||
@Nonnull Message onlyInGroup,
|
||||
RegionGroup group
|
||||
) {
|
||||
Collection<BuyRegion> regions = fileManager.getBuysRef();
|
||||
List<BuyRegion> results = new LinkedList<>();
|
||||
for (BuyRegion region : regions) {
|
||||
if (!region.isSold()
|
||||
&& ((region.getPrice() <= balance && !maxPriceSet) || (region.getPrice() <= maxPrice && maxPriceSet))
|
||||
&& (group == null || group.isMember(region))
|
||||
&& (region.getBooleanSetting("general.findCrossWorld") || sender.getWorld()
|
||||
.equals(region.getWorld()))
|
||||
) {
|
||||
results.add(region);
|
||||
}
|
||||
}
|
||||
if (results.isEmpty()) {
|
||||
double currency = maxPriceSet ? maxPrice : balance;
|
||||
String key = maxPriceSet ? "find-noneFoundMax" : "find-noneFound";
|
||||
throw new AreaShopCommandException(key, "buy", Utils.formatCurrency(currency), onlyInGroup);
|
||||
}
|
||||
// Draw a random one
|
||||
BuyRegion region = results.get(ThreadLocalRandom.current().nextInt(results.size()));
|
||||
// Teleport
|
||||
double currency = maxPriceSet ? maxPrice : balance;
|
||||
String key = maxPriceSet ? "find-successMax" : "find-success";
|
||||
this.messageBridge.message(sender,
|
||||
key,
|
||||
"buy",
|
||||
Utils.formatCurrency(currency),
|
||||
onlyInGroup,
|
||||
region);
|
||||
boolean tpToSign = region.getBooleanSetting("general.findTeleportToSign");
|
||||
region.getTeleportFeature().teleportPlayer(sender, tpToSign, false);
|
||||
}
|
||||
|
||||
private void handleRent(
|
||||
@Nonnull Player sender,
|
||||
double balance,
|
||||
double maxPrice,
|
||||
boolean maxPriceSet,
|
||||
@Nonnull Message onlyInGroup,
|
||||
RegionGroup group
|
||||
) {
|
||||
Collection<RentRegion> regions = fileManager.getRentsRef();
|
||||
List<RentRegion> results = new LinkedList<>();
|
||||
for (RentRegion region : regions) {
|
||||
if (!region.isRented()
|
||||
&& ((region.getPrice() <= balance && !maxPriceSet) || (region.getPrice() <= maxPrice && maxPriceSet))
|
||||
&& (group == null || group.isMember(region))
|
||||
&& (region.getBooleanSetting("general.findCrossWorld") || sender.getWorld()
|
||||
.equals(region.getWorld()))
|
||||
) {
|
||||
results.add(region);
|
||||
}
|
||||
}
|
||||
if (results.isEmpty()) {
|
||||
double currency = maxPriceSet ? maxPrice : balance;
|
||||
String key = maxPriceSet ? "find-noneFoundMax" : "find-noneFound";
|
||||
throw new AreaShopCommandException(key, "rent", Utils.formatCurrency(currency), onlyInGroup);
|
||||
}
|
||||
// Draw a random one
|
||||
RentRegion region = results.get(ThreadLocalRandom.current().nextInt(results.size()));
|
||||
// Teleport
|
||||
double currency = maxPriceSet ? maxPrice : balance;
|
||||
String key = maxPriceSet ? "find-successMax" : "find-success";
|
||||
this.messageBridge.message(sender,
|
||||
key,
|
||||
"rent",
|
||||
Utils.formatCurrency(currency),
|
||||
onlyInGroup,
|
||||
region);
|
||||
boolean tpToSign = region.getBooleanSetting("general.findTeleportToSign");
|
||||
region.getTeleportFeature().teleportPlayer(sender, tpToSign, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class GroupAddCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_GROUP = CloudKey.of("group", String.class);
|
||||
|
||||
private final IFileManager fileManager;
|
||||
private final RegionFactory regionFactory;
|
||||
private final MessageBridge messageBridge;
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
|
||||
@Inject
|
||||
public GroupAddCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull RegionFactory regionFactory
|
||||
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
this.regionFactory = regionFactory;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if(target.hasPermission("areashop.groupadd")) {
|
||||
return "help-groupadd";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("groupadd")
|
||||
.required(KEY_GROUP, StringParser.stringParser(), this::suggestGroupNames)
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("groupadd");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.groupadd")) {
|
||||
throw new AreaShopCommandException("groupadd-noPermission");
|
||||
}
|
||||
String rawGroup = context.get(KEY_GROUP);
|
||||
RegionGroup group = fileManager.getGroup(rawGroup);
|
||||
if (group == null) {
|
||||
group = regionFactory.createRegionGroup(rawGroup);
|
||||
fileManager.addGroup(group);
|
||||
}
|
||||
GeneralRegion declaredRegion = context.flags().get(this.regionFlag);
|
||||
if (declaredRegion != null) {
|
||||
if (!group.addMember(declaredRegion)) {
|
||||
throw new AreaShopCommandException("groupadd-failed", group.getName(), declaredRegion);
|
||||
}
|
||||
declaredRegion.update();
|
||||
this.messageBridge.message(sender,
|
||||
"groupadd-success",
|
||||
group.getName(),
|
||||
group.getMembers().size(),
|
||||
declaredRegion);
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<GeneralRegion> regions = RegionParseUtil.getOrParseRegionsInSel(context, sender, this.regionFlag);
|
||||
Set<GeneralRegion> regionsSuccess = new TreeSet<>();
|
||||
Set<GeneralRegion> regionsFailed = new TreeSet<>();
|
||||
for (GeneralRegion region : regions) {
|
||||
if (group.addMember(region)) {
|
||||
regionsSuccess.add(region);
|
||||
} else {
|
||||
regionsFailed.add(region);
|
||||
}
|
||||
}
|
||||
if (!regionsSuccess.isEmpty()) {
|
||||
messageBridge.message(sender,
|
||||
"groupadd-weSuccess",
|
||||
group.getName(),
|
||||
Utils.combinedMessage(regionsSuccess, "region"));
|
||||
}
|
||||
if (!regionsFailed.isEmpty()) {
|
||||
messageBridge.message(sender,
|
||||
"groupadd-weFailed",
|
||||
group.getName(),
|
||||
Utils.combinedMessage(regionsFailed, "region"));
|
||||
}
|
||||
// Update all regions, this does it in a task, updating them without lag
|
||||
fileManager.updateRegions(List.copyOf(regionsSuccess), sender);
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestGroupNames(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
List<Suggestion> suggestions = this.fileManager.getGroupNames().stream()
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class GroupDelCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_GROUP = CloudKey.of("group", String.class);
|
||||
|
||||
private final IFileManager fileManager;
|
||||
private final RegionFactory regionFactory;
|
||||
private final MessageBridge messageBridge;
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
|
||||
@Inject
|
||||
public GroupDelCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull RegionFactory regionFactory
|
||||
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
this.regionFactory = regionFactory;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if(target.hasPermission("areashop.groupdel")) {
|
||||
return "help-groupdel";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("groupdel")
|
||||
.required(KEY_GROUP, StringParser.stringParser(), this::suggestGroupNames)
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("groupdel");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("groupdel")) {
|
||||
throw new AreaShopCommandException("groupdel-noPermission");
|
||||
}
|
||||
String rawGroup = context.get(KEY_GROUP);
|
||||
RegionGroup group = fileManager.getGroup(rawGroup);
|
||||
if (group == null) {
|
||||
group = regionFactory.createRegionGroup(rawGroup);
|
||||
fileManager.addGroup(group);
|
||||
}
|
||||
GeneralRegion declaredRegion = context.flags().get(this.regionFlag);
|
||||
if (declaredRegion != null) {
|
||||
if (!group.removeMember(declaredRegion)) {
|
||||
throw new AreaShopCommandException("groupdel-failed", group.getName(), declaredRegion);
|
||||
}
|
||||
this.messageBridge.message(sender,
|
||||
"groupdel-success",
|
||||
group.getName(),
|
||||
group.getMembers().size(),
|
||||
declaredRegion);
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<GeneralRegion> regions = RegionParseUtil.getOrParseRegionsInSel(context, sender, this.regionFlag);
|
||||
Set<GeneralRegion> regionsSuccess = new TreeSet<>();
|
||||
Set<GeneralRegion> regionsFailed = new TreeSet<>();
|
||||
for (GeneralRegion region : regions) {
|
||||
if (group.removeMember(region)) {
|
||||
regionsSuccess.add(region);
|
||||
} else {
|
||||
regionsFailed.add(region);
|
||||
}
|
||||
}
|
||||
if (!regionsSuccess.isEmpty()) {
|
||||
messageBridge.message(sender,
|
||||
"groupdel-weSuccess",
|
||||
group.getName(),
|
||||
Utils.combinedMessage(regionsSuccess, "region"));
|
||||
}
|
||||
if (!regionsFailed.isEmpty()) {
|
||||
messageBridge.message(sender,
|
||||
"groupdel-weFailed",
|
||||
group.getName(),
|
||||
Utils.combinedMessage(regionsFailed, "region"));
|
||||
}
|
||||
// Update all regions, this does it in a task, updating them without lag
|
||||
fileManager.updateRegions(List.copyOf(regionsSuccess), sender);
|
||||
group.saveRequired();
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestGroupNames(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
List<Suggestion> suggestions = this.fileManager.getGroupNames().stream()
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionGroupParser;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
|
||||
@Singleton
|
||||
public class GroupInfoCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<RegionGroup> KEY_GROUP = CloudKey.of("group", RegionGroup.class);
|
||||
|
||||
private final IFileManager fileManager;
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Inject
|
||||
public GroupInfoCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if(target.hasPermission("areashop.groupinfo")) {
|
||||
return "help-groupinfo";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
ParserDescriptor<CommandSource<?>, RegionGroup> regionGroupParser = ParserDescriptor.of(
|
||||
new RegionGroupParser<>(this.fileManager, "groupinfo-noGroup"),
|
||||
RegionGroup.class);
|
||||
return builder
|
||||
.literal("groupinfo")
|
||||
.required(KEY_GROUP, regionGroupParser)
|
||||
.handler(this::handleCommand);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("groupinfo");
|
||||
}
|
||||
|
||||
public void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
if (!context.hasPermission("groupinfo")) {
|
||||
throw new AreaShopCommandException("groupinfo-noPermission");
|
||||
}
|
||||
RegionGroup group = context.get(KEY_GROUP);
|
||||
Set<String> members = group.getMembers();
|
||||
if (members.isEmpty()) {
|
||||
throw new AreaShopCommandException("groupinfo-noMembers", group.getName());
|
||||
}
|
||||
String seperatedMembers = Utils.createCommaSeparatedList(members);
|
||||
this.messageBridge.message(context.sender().sender(), "groupinfo-members", group.getName(), seperatedMembers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class GroupListCommand extends AreashopCommandBean {
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
|
||||
@Inject
|
||||
public GroupListCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(CommandSender target) {
|
||||
if(target.hasPermission("areashop.grouplist")) {
|
||||
return "help-grouplist";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("grouplist", "groups")
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("grouplist", "groups");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
if (!context.hasPermission("areashop.grouplist")) {
|
||||
throw new AreaShopCommandException("grouplist-noPermission");
|
||||
}
|
||||
List<String> groups = this.fileManager.getGroupNames();
|
||||
CommandSender sender = context.sender().sender();
|
||||
if(groups.isEmpty()) {
|
||||
messageBridge.message(sender, "grouplist-noGroups");
|
||||
} else {
|
||||
messageBridge.message(sender, "grouplist-success", Utils.createCommaSeparatedList(groups));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@Singleton
|
||||
public class GroupaddCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private RegionFactory regionFactory;
|
||||
@Inject
|
||||
private WorldEditInterface worldEditInterface;
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop groupadd";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.groupadd")) {
|
||||
return "help-groupadd";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.groupadd")) {
|
||||
messageBridge.message(sender, "groupadd-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2 || args[1] == null) {
|
||||
messageBridge.message(sender, "groupadd-help");
|
||||
return;
|
||||
}
|
||||
RegionGroup group = fileManager.getGroup(args[1]);
|
||||
if(group == null) {
|
||||
group = regionFactory.createRegionGroup(args[1]);
|
||||
fileManager.addGroup(group);
|
||||
}
|
||||
if(args.length == 2) {
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-weOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if(selection == null) {
|
||||
messageBridge.message(player, "cmd-noSelection");
|
||||
return;
|
||||
}
|
||||
List<GeneralRegion> regions = Utils.getRegionsInSelection(selection);
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(player, "cmd-noRegionsFound");
|
||||
return;
|
||||
}
|
||||
TreeSet<GeneralRegion> regionsSuccess = new TreeSet<>();
|
||||
TreeSet<GeneralRegion> regionsFailed = new TreeSet<>();
|
||||
for(GeneralRegion region : regions) {
|
||||
if(group.addMember(region)) {
|
||||
regionsSuccess.add(region);
|
||||
} else {
|
||||
regionsFailed.add(region);
|
||||
}
|
||||
}
|
||||
if(!regionsSuccess.isEmpty()) {
|
||||
messageBridge.message(player, "groupadd-weSuccess", group.getName(), Utils.combinedMessage(regionsSuccess, "region"));
|
||||
}
|
||||
if(!regionsFailed.isEmpty()) {
|
||||
messageBridge.message(player, "groupadd-weFailed", group.getName(), Utils.combinedMessage(regionsFailed, "region"));
|
||||
}
|
||||
// Update all regions, this does it in a task, updating them without lag
|
||||
fileManager.updateRegions(new ArrayList<>(regionsSuccess), player);
|
||||
} else {
|
||||
GeneralRegion region = fileManager.getRegion(args[2]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
if(group.addMember(region)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "groupadd-success", group.getName(), group.getMembers().size(), region);
|
||||
} else {
|
||||
messageBridge.message(sender, "groupadd-failed", group.getName(), region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result = fileManager.getGroupNames();
|
||||
} else if(toComplete == 3) {
|
||||
result = fileManager.getRegionNames();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@Singleton
|
||||
public class GroupdelCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private RegionFactory regionFactory;
|
||||
@Inject
|
||||
private WorldEditInterface worldEditInterface;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop groupdel";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.groupdel")) {
|
||||
return "help-groupdel";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.groupdel")) {
|
||||
messageBridge.message(sender, "groupdel-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2 || args[1] == null) {
|
||||
messageBridge.message(sender, "groupdel-help");
|
||||
return;
|
||||
}
|
||||
RegionGroup group = fileManager.getGroup(args[1]);
|
||||
if(group == null) {
|
||||
messageBridge.message(sender, "groupdel-wrongGroup", args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length == 2) {
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-weOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if(selection == null) {
|
||||
messageBridge.message(player, "cmd-noSelection");
|
||||
return;
|
||||
}
|
||||
List<GeneralRegion> regions = Utils.getRegionsInSelection(selection);
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(player, "cmd-noRegionsFound");
|
||||
return;
|
||||
}
|
||||
TreeSet<GeneralRegion> regionsSuccess = new TreeSet<>();
|
||||
TreeSet<GeneralRegion> regionsFailed = new TreeSet<>();
|
||||
for(GeneralRegion region : regions) {
|
||||
if(group.removeMember(region)) {
|
||||
regionsSuccess.add(region);
|
||||
} else {
|
||||
regionsFailed.add(region);
|
||||
}
|
||||
}
|
||||
if(!regionsSuccess.isEmpty()) {
|
||||
messageBridge.message(player, "groupdel-weSuccess", group.getName(), Utils.combinedMessage(regionsSuccess, "region"));
|
||||
}
|
||||
if(!regionsFailed.isEmpty()) {
|
||||
messageBridge.message(player, "groupdel-weFailed", group.getName(), Utils.combinedMessage(regionsFailed, "region"));
|
||||
}
|
||||
// Update all regions, this does it in a task, updating them without lag
|
||||
fileManager.updateRegions(regionsSuccess, player);
|
||||
group.saveRequired();
|
||||
} else {
|
||||
GeneralRegion region = fileManager.getRegion(args[2]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
if(group.removeMember(region)) {
|
||||
region.update();
|
||||
messageBridge.message(sender, "groupdel-success", group.getName(), group.getMembers().size(), region);
|
||||
} else {
|
||||
messageBridge.message(sender, "groupdel-failed", group.getName(), region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result = fileManager.getGroupNames();
|
||||
} else if(toComplete == 3) {
|
||||
result = fileManager.getRegionNames();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Singleton
|
||||
public class GroupinfoCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop groupinfo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.groupinfo")) {
|
||||
return "help-groupinfo";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.groupinfo")) {
|
||||
messageBridge.message(sender, "groupinfo-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2 || args[1] == null) {
|
||||
messageBridge.message(sender, "groupinfo-help");
|
||||
return;
|
||||
}
|
||||
RegionGroup group = fileManager.getGroup(args[1]);
|
||||
if(group == null) {
|
||||
messageBridge.message(sender, "groupinfo-noGroup", args[1]);
|
||||
return;
|
||||
}
|
||||
Set<String> members = group.getMembers();
|
||||
if(members.isEmpty()) {
|
||||
messageBridge.message(sender, "groupinfo-noMembers", group.getName());
|
||||
} else {
|
||||
messageBridge.message(sender, "groupinfo-members", group.getName(), Utils.createCommaSeparatedList(members));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result = fileManager.getGroupNames();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class GrouplistCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop grouplist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.grouplist")) {
|
||||
return "help-grouplist";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.grouplist")) {
|
||||
messageBridge.message(sender, "grouplist-noPermission");
|
||||
return;
|
||||
}
|
||||
List<String> groups = fileManager.getGroupNames();
|
||||
if(groups.isEmpty()) {
|
||||
messageBridge.message(sender, "grouplist-noGroups");
|
||||
} else {
|
||||
messageBridge.message(sender, "grouplist-success", Utils.createCommaSeparatedList(groups));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,34 +2,57 @@ package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import me.wiefferink.areashop.managers.CommandManager;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommands;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class HelpCommand extends CommandAreaShop {
|
||||
@Singleton
|
||||
public class HelpCommand extends AreashopCommandBean {
|
||||
private final AreashopCommands commands;
|
||||
|
||||
private final CommandManager commandManager;
|
||||
@Inject
|
||||
public HelpCommand(@Nonnull AreashopCommands commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public HelpCommand(@Nonnull CommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.help")) {
|
||||
return "help-help";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop help";
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.help")) {
|
||||
return "help-help";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("help")
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
commandManager.showHelp(sender);
|
||||
}
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("help");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.help")) {
|
||||
throw new AreaShopCommandException("help-noPermission");
|
||||
}
|
||||
this.commands.showHelp(sender);
|
||||
}
|
||||
}
|
||||
@@ -1,80 +1,88 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.regions.ImportJob;
|
||||
import me.wiefferink.areashop.commands.util.AcceptedValuesParser;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.regions.ImportJobFactory;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class ImportCommand extends CommandAreaShop {
|
||||
public class ImportCommand extends AreashopCommandBean {
|
||||
|
||||
/* RegionGroup priority usage:
|
||||
0: Settings from /config.yml
|
||||
1: Settings from /worlds/<world>/config.yml
|
||||
2: Settings from /worlds/<world>/parent-regions.yml (if their priority is set it is added to this value)
|
||||
*/
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private ImportJobFactory importJobFactory;
|
||||
private static final CloudKey<String> KEY_SOURCE = CloudKey.of("source", String.class);
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop import";
|
||||
}
|
||||
/* RegionGroup priority usage:
|
||||
0: Settings from /config.yml
|
||||
1: Settings from /worlds/<world>/config.yml
|
||||
2: Settings from /worlds/<world>/parent-regions.yml (if their priority is set it is added to this value)
|
||||
*/
|
||||
private final ImportJobFactory importJobFactory;
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.import")) {
|
||||
return "help-import";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Inject
|
||||
public ImportCommand(@Nonnull MessageBridge messageBridge, @Nonnull ImportJobFactory importJobFactory) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.importJobFactory = importJobFactory;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// - Landlord?
|
||||
// - Friends
|
||||
// - Region flags?
|
||||
// - Settings from the 'permissions' section in RegionForSale/config.yml?
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.import")) {
|
||||
messageBridge.message(sender, "import-noPermission");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if(target.hasPermission("areashop.import")) {
|
||||
return "help-import";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if(args.length < 2) {
|
||||
messageBridge.message(sender, "import-help");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
withConfirmation();
|
||||
var sourceParser = AcceptedValuesParser.ofConstant(List.of("RegionForSale"), "import-wrongSource", true);
|
||||
return builder.literal("import")
|
||||
.required(KEY_SOURCE, ParserDescriptor.of(sourceParser, String.class))
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
if(!"RegionForSale".equalsIgnoreCase(args[1])) {
|
||||
messageBridge.message(sender, "import-wrongSource");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("import");
|
||||
}
|
||||
|
||||
if(!confirm(sender, args, Message.fromKey("import-confirm"))) {
|
||||
return;
|
||||
}
|
||||
// TODO:
|
||||
// - Landlord?
|
||||
// - Friends
|
||||
// - Region flags?
|
||||
// - Settings from the 'permissions' section in RegionForSale/config.yml?
|
||||
|
||||
importJobFactory.createImportJob(sender).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result.add("RegionForSale");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.import")) {
|
||||
this.messageBridge.message(sender, "import-noPermission");
|
||||
return;
|
||||
}
|
||||
String importSource = context.get(KEY_SOURCE);
|
||||
if (!"RegionForSale".equalsIgnoreCase(importSource)) {
|
||||
throw new AreaShopCommandException("import-wrongSource");
|
||||
}
|
||||
importJobFactory.createImportJob(sender).execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class InfoBaseCommand extends AreashopCommandBean {
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Inject
|
||||
public InfoBaseCommand(
|
||||
@Nonnull MessageBridge messageBridge
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.info")) {
|
||||
return "help-info";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("info").handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("info");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.info")) {
|
||||
messageBridge.message(sender, "info-noPermission");
|
||||
return;
|
||||
}
|
||||
this.messageBridge.message(sender, "info-help");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,470 +1,272 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import io.github.bakedlibs.dough.blocks.BlockPosition;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionGroupParser;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.areashop.tools.SimpleMessageBridge;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.EnumParser;
|
||||
import org.incendo.cloud.parser.standard.IntegerParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
// TODO fix '/as info' help message hitting replacement limit (improve depth tracking?)
|
||||
// TODO add info about autoExtend
|
||||
@Singleton
|
||||
public class InfoCommand extends CommandAreaShop {
|
||||
public class InfoCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop info";
|
||||
}
|
||||
private static final CommandFlag<Integer> FLAG_PAGE = CommandFlag.builder("page")
|
||||
.withComponent(IntegerParser.integerParser(1))
|
||||
.build();
|
||||
private static final CloudKey<RegionStateFilterType> KEY_TYPE = CloudKey.of("type", RegionStateFilterType.class);
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.info")) {
|
||||
return "help-info";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
|
||||
/**
|
||||
* Display a page of a list of regions.
|
||||
* @param sender The CommandSender to send the messages to
|
||||
* @param regions The regions to display
|
||||
* @param filterGroup The group to filter the regions by
|
||||
* @param keyHeader The header to print above the page
|
||||
* @param pageInput The page number, if any
|
||||
* @param baseCommand The command to execute for next/previous page (/areashop will be added)
|
||||
*/
|
||||
private void showSortedPagedList(CommandSender sender, List<? extends GeneralRegion> regions, RegionGroup filterGroup, String keyHeader, String pageInput, String baseCommand) {
|
||||
int maximumItems = 20;
|
||||
int itemsPerPage = maximumItems - 2;
|
||||
int page = 1;
|
||||
if(pageInput != null && Utils.isNumeric(pageInput)) {
|
||||
try {
|
||||
page = Integer.parseInt(pageInput);
|
||||
} catch(NumberFormatException e) {
|
||||
messageBridge.message(sender, "info-wrongPage", pageInput);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(filterGroup != null) {
|
||||
regions.removeIf(generalRegion -> !filterGroup.isMember(generalRegion));
|
||||
}
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "info-noRegions");
|
||||
} else {
|
||||
// First sort by type, then by name
|
||||
regions.sort((one, two) -> {
|
||||
int typeCompare = getTypeOrder(two).compareTo(getTypeOrder(one));
|
||||
if(typeCompare != 0) {
|
||||
return typeCompare;
|
||||
} else {
|
||||
return one.getName().compareTo(two.getName());
|
||||
}
|
||||
});
|
||||
// Header
|
||||
Message limitedToGroup = Message.empty();
|
||||
if(filterGroup != null) {
|
||||
limitedToGroup = Message.fromKey("info-limitedToGroup").replacements(filterGroup.getName());
|
||||
}
|
||||
messageBridge.message(sender, keyHeader, limitedToGroup);
|
||||
// Page entries
|
||||
int totalPages = (int)Math.ceil(regions.size() / (double)itemsPerPage); // Clip page to correct boundaries, not much need to tell the user
|
||||
if(regions.size() == itemsPerPage + 1) { // 19 total items is mapped to 1 page of 19
|
||||
itemsPerPage++;
|
||||
totalPages = 1;
|
||||
}
|
||||
page = Math.max(1, Math.min(totalPages, page));
|
||||
int linesPrinted = 1; // header
|
||||
for(int i = (page - 1) * itemsPerPage; i < page * itemsPerPage && i < regions.size(); i++) {
|
||||
String state;
|
||||
GeneralRegion region = regions.get(i);
|
||||
if(region.getType() == GeneralRegion.RegionType.RENT) {
|
||||
if(region.getOwner() == null) {
|
||||
state = "Forrent";
|
||||
} else {
|
||||
state = "Rented";
|
||||
}
|
||||
} else {
|
||||
if(region.getOwner() == null) {
|
||||
state = "Forsale";
|
||||
} else if(!((BuyRegion)region).isInResellingMode()) {
|
||||
state = "Sold";
|
||||
} else {
|
||||
state = "Reselling";
|
||||
}
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "info-entry" + state, region);
|
||||
linesPrinted++;
|
||||
}
|
||||
Message footer = Message.empty();
|
||||
// Previous button
|
||||
if(page > 1) {
|
||||
footer.append(Message.fromKey("info-pagePrevious").replacements(baseCommand + " " + (page - 1)));
|
||||
} else {
|
||||
footer.append(Message.fromKey("info-pageNoPrevious"));
|
||||
}
|
||||
// Page status
|
||||
if(totalPages > 1) {
|
||||
StringBuilder pageString = new StringBuilder("" + page);
|
||||
for(int i = pageString.length(); i < (totalPages + "").length(); i++) {
|
||||
pageString.insert(0, "0");
|
||||
}
|
||||
footer.append(Message.fromKey("info-pageStatus").replacements(page, totalPages));
|
||||
if(page < totalPages) {
|
||||
footer.append(Message.fromKey("info-pageNext").replacements(baseCommand + " " + (page + 1)));
|
||||
} else {
|
||||
footer.append(Message.fromKey("info-pageNoNext"));
|
||||
}
|
||||
// Fill up space if the page is not full (aligns header nicely)
|
||||
for(int i = linesPrinted; i < maximumItems - 1; i++) {
|
||||
sender.sendMessage(" ");
|
||||
}
|
||||
footer.send(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
private final CommandFlag<RegionGroup> filterGroupFlag;
|
||||
|
||||
/**
|
||||
* Get an integer to order by type, usable for Comparators.
|
||||
* @param region The region to get the order for
|
||||
* @return An integer for sorting by type
|
||||
*/
|
||||
private Integer getTypeOrder(GeneralRegion region) {
|
||||
if(region.getType() == GeneralRegion.RegionType.RENT) {
|
||||
if(region.getOwner() == null) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
if(region.getOwner() == null) {
|
||||
return 3;
|
||||
} else if(!((BuyRegion)region).isInResellingMode()) {
|
||||
return 4;
|
||||
} else {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Inject
|
||||
public InfoCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
this.filterGroupFlag = CommandFlag.builder("group")
|
||||
.withComponent(ParserDescriptor.of(new RegionGroupParser<>(fileManager, "info-noFiltergroup"),
|
||||
RegionGroup.class))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.info")) {
|
||||
messageBridge.message(sender, "info-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length > 1 && args[1] != null) {
|
||||
// Get filter group (only used by some commands)
|
||||
RegionGroup filterGroup = null;
|
||||
Set<String> groupFilters = new HashSet<>(Arrays.asList("all", "rented", "forrent", "sold", "forsale", "reselling"));
|
||||
if(groupFilters.contains(args[1].toLowerCase()) && args.length > 2) {
|
||||
if(!Utils.isNumeric(args[2])) {
|
||||
filterGroup = fileManager.getGroup(args[2]);
|
||||
if(filterGroup == null) {
|
||||
messageBridge.message(sender, "info-noFiltergroup", args[2]);
|
||||
return;
|
||||
}
|
||||
// Pass page number to args[2] if available
|
||||
if(args.length > 3) {
|
||||
args[2] = args[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// All regions
|
||||
if(args[1].equalsIgnoreCase("all")) {
|
||||
showSortedPagedList(sender, new ArrayList<>(fileManager.getRegionsRef()), filterGroup, "info-allHeader", (args.length > 2 ? args[2] : null), "info all");
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Rented regions
|
||||
else if(args[1].equalsIgnoreCase("rented")) {
|
||||
List<RentRegion> regions = new ArrayList<>(fileManager.getRentsRef());
|
||||
regions.removeIf(RentRegion::isAvailable);
|
||||
showSortedPagedList(sender, regions, filterGroup, "info-rentedHeader", (args.length > 2 ? args[2] : null), "info rented");
|
||||
}
|
||||
// Forrent regions
|
||||
else if(args[1].equalsIgnoreCase("forrent")) {
|
||||
List<RentRegion> regions = new ArrayList<>(fileManager.getRentsRef());
|
||||
regions.removeIf(RentRegion::isRented);
|
||||
showSortedPagedList(sender, regions, filterGroup, "info-forrentHeader", (args.length > 2 ? args[2] : null), "info forrent");
|
||||
}
|
||||
// Sold regions
|
||||
else if(args[1].equalsIgnoreCase("sold")) {
|
||||
List<BuyRegion> regions = new ArrayList<>(fileManager.getBuysRef());
|
||||
regions.removeIf(BuyRegion::isAvailable);
|
||||
showSortedPagedList(sender, regions, filterGroup, "info-soldHeader", (args.length > 2 ? args[2] : null), "info sold");
|
||||
}
|
||||
// Forsale regions
|
||||
else if(args[1].equalsIgnoreCase("forsale")) {
|
||||
List<BuyRegion> regions = new ArrayList<>(fileManager.getBuysRef());
|
||||
regions.removeIf(BuyRegion::isSold);
|
||||
showSortedPagedList(sender, regions, filterGroup, "info-forsaleHeader", (args.length > 2 ? args[2] : null), "info forsale");
|
||||
}
|
||||
// Reselling regions
|
||||
else if(args[1].equalsIgnoreCase("reselling")) {
|
||||
List<BuyRegion> regions = new ArrayList<>(fileManager.getBuysRef());
|
||||
regions.removeIf(region -> !region.isInResellingMode());
|
||||
showSortedPagedList(sender, regions, filterGroup, "info-resellingHeader", (args.length > 2 ? args[2] : null), "info reselling");
|
||||
}
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("info")
|
||||
.required(KEY_TYPE, EnumParser.enumParser(RegionStateFilterType.class))
|
||||
.flag(FLAG_PAGE)
|
||||
.flag(this.filterGroupFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
// List of regions without a group
|
||||
else if(args[1].equalsIgnoreCase("nogroup")) {
|
||||
List<GeneralRegion> regions = new ArrayList<>(fileManager.getRegionsRef());
|
||||
for(RegionGroup group : fileManager.getGroups()) {
|
||||
regions.removeAll(group.getMemberRegions());
|
||||
}
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "info-nogroupNone");
|
||||
} else {
|
||||
showSortedPagedList(sender, regions, filterGroup, "info-nogroupHeader", (args.length > 2 ? args[2] : null), "info nogroup");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("info");
|
||||
}
|
||||
|
||||
// Region info
|
||||
else if(args[1].equalsIgnoreCase("region")) {
|
||||
if(args.length > 1) {
|
||||
RentRegion rent = null;
|
||||
BuyRegion buy = null;
|
||||
if(args.length > 2) {
|
||||
rent = fileManager.getRent(args[2]);
|
||||
buy = fileManager.getBuy(args[2]);
|
||||
} else {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
if(regions.get(0) instanceof RentRegion) {
|
||||
rent = (RentRegion)regions.get(0);
|
||||
} else if(regions.get(0) instanceof BuyRegion) {
|
||||
buy = (BuyRegion)regions.get(0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
}
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.info")) {
|
||||
messageBridge.message(sender, "info-noPermission");
|
||||
return;
|
||||
}
|
||||
RegionStateFilterType filterType = context.get(KEY_TYPE);
|
||||
processOtherFilters(context, filterType);
|
||||
}
|
||||
|
||||
if(rent == null && buy == null) {
|
||||
messageBridge.message(sender, "info-regionNotExisting", args[2]);
|
||||
return;
|
||||
}
|
||||
private void processOtherFilters(@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull RegionStateFilterType filterType) {
|
||||
RegionGroup filterGroup = context.flags().get(this.filterGroupFlag);
|
||||
int page = context.flags().getValue(FLAG_PAGE).orElse(1);
|
||||
Stream<? extends GeneralRegion> toShow = switch (filterType) {
|
||||
case ALL -> fileManager.getRegionsRef().stream();
|
||||
case SOLD -> fileManager.getBuysRef().stream().filter(BuyRegion::isSold);
|
||||
case RENTED -> fileManager.getRentsRef().stream().filter(RentRegion::isRented);
|
||||
case FORRENT -> fileManager.getRentsRef().stream().filter(RentRegion::isAvailable);
|
||||
case FORSALE -> fileManager.getBuysRef().stream().filter(BuyRegion::isAvailable);
|
||||
case RESELLING -> fileManager.getBuysRef().stream().filter(BuyRegion::isInResellingMode);
|
||||
case NOGROUP -> {
|
||||
List<GeneralRegion> regions = new LinkedList<>(fileManager.getRegions());
|
||||
for (RegionGroup group : fileManager.getGroups()) {
|
||||
regions.removeAll(group.getMemberRegions());
|
||||
}
|
||||
yield regions.stream();
|
||||
}
|
||||
};
|
||||
String header = switch (filterType) {
|
||||
case ALL -> "info-allHeader";
|
||||
case SOLD -> "info-soldHeader";
|
||||
case RENTED -> "info-rentedHeader";
|
||||
case FORRENT -> "info-forrentHeader";
|
||||
case FORSALE -> "info-forsaleHeader";
|
||||
case RESELLING -> "info-resellingHeader";
|
||||
case NOGROUP -> "info-nogroupHeader";
|
||||
};
|
||||
String baseCommand = switch (filterType) {
|
||||
case ALL -> "info all";
|
||||
case SOLD -> "info sold";
|
||||
case RENTED -> "info rented";
|
||||
case FORRENT -> "info forrent";
|
||||
case FORSALE -> "info forsale";
|
||||
case RESELLING -> "info reselling";
|
||||
case NOGROUP -> "info nogroup";
|
||||
};
|
||||
showSortedPagedList(context.sender().sender(), toShow, filterGroup, header, page, baseCommand);
|
||||
}
|
||||
|
||||
if(rent != null) {
|
||||
messageBridge.message(sender, "info-regionHeaderRent", rent);
|
||||
if(rent.isRented()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRented", rent);
|
||||
messageBridge.messageNoPrefix(sender, "info-regionExtending", rent);
|
||||
// Money back
|
||||
if(UnrentCommand.canUse(sender, rent)) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMoneyBackRentClick", rent);
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMoneyBackRent", rent);
|
||||
}
|
||||
// Friends
|
||||
if(!rent.getFriendsFeature().getFriendNames().isEmpty()) {
|
||||
String messagePart = "info-friend";
|
||||
if(DelfriendCommand.canUse(sender, rent)) {
|
||||
messagePart = "info-friendRemove";
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "info-regionFriends", rent, Utils.combinedMessage(rent.getFriendsFeature().getFriendNames(), messagePart));
|
||||
}
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionCanBeRented", rent);
|
||||
}
|
||||
if(rent.getLandlordName() != null) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionLandlord", rent);
|
||||
}
|
||||
// Maximum extends
|
||||
if(rent.getMaxExtends() != -1) {
|
||||
if(rent.getMaxExtends() == 0) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionNoExtending", rent);
|
||||
} else if(rent.isRented()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionExtendsLeft", rent);
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMaxExtends", rent);
|
||||
}
|
||||
}
|
||||
// If maxExtends is zero it does not make sense to show this message
|
||||
if(rent.getMaxRentTime() != -1 && rent.getMaxExtends() != 0) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMaxRentTime", rent);
|
||||
}
|
||||
if(rent.getInactiveTimeUntilUnrent() != -1) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionInactiveUnrent", rent);
|
||||
}
|
||||
// Teleport
|
||||
Message tp = Message.fromKey("info-prefix");
|
||||
boolean foundSomething = false;
|
||||
if(TeleportCommand.canUse(sender, rent)) {
|
||||
foundSomething = true;
|
||||
tp.append(Message.fromKey("info-regionTeleport").replacements(rent));
|
||||
}
|
||||
if(SetteleportCommand.canUse(sender, rent)) {
|
||||
if(foundSomething) {
|
||||
tp.append(", ");
|
||||
}
|
||||
foundSomething = true;
|
||||
tp.append(Message.fromKey("info-setRegionTeleport").replacements(rent));
|
||||
}
|
||||
if(foundSomething) {
|
||||
tp.append(".");
|
||||
tp.send(sender);
|
||||
}
|
||||
// Signs
|
||||
List<String> signLocations = new ArrayList<>();
|
||||
for(BlockPosition location : rent.getSignsFeature().signManager().allSignLocations()) {
|
||||
signLocations.add(Message.fromKey("info-regionSignLocation").replacements(location.getWorld().getName(), location.getX(), location.getY(), location.getZ()).getPlain());
|
||||
}
|
||||
if(!signLocations.isEmpty()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionSigns", Utils.createCommaSeparatedList(signLocations));
|
||||
}
|
||||
// Groups
|
||||
if(sender.hasPermission("areashop.groupinfo") && !rent.getGroupNames().isEmpty()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionGroups", Utils.createCommaSeparatedList(rent.getGroupNames()));
|
||||
}
|
||||
// Restoring
|
||||
if(rent.isRestoreEnabled()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestoringRent", rent);
|
||||
}
|
||||
// Restrictions
|
||||
if(!rent.isRented()) {
|
||||
if(rent.restrictedToRegion()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestrictedRegionRent", rent);
|
||||
} else if(rent.restrictedToWorld()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestrictedWorldRent", rent);
|
||||
}
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "info-regionFooterRent", rent);
|
||||
} else if(buy != null) {
|
||||
messageBridge.message(sender, "info-regionHeaderBuy", buy);
|
||||
if(buy.isSold()) {
|
||||
if(buy.isInResellingMode()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionReselling", buy);
|
||||
messageBridge.messageNoPrefix(sender, "info-regionReselPrice", buy);
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionBought", buy);
|
||||
}
|
||||
// Money back
|
||||
if(!buy.getBooleanSetting("buy.sellDisabled")) {
|
||||
if (SellCommand.canUse(sender, buy)) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMoneyBackBuyClick", buy);
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMoneyBackBuy", buy);
|
||||
}
|
||||
}
|
||||
// Friends
|
||||
if(!buy.getFriendsFeature().getFriendNames().isEmpty()) {
|
||||
String messagePart = "info-friend";
|
||||
if(DelfriendCommand.canUse(sender, buy)) {
|
||||
messagePart = "info-friendRemove";
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "info-regionFriends", buy, Utils.combinedMessage(buy.getFriendsFeature().getFriendNames(), messagePart));
|
||||
}
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionCanBeBought", buy);
|
||||
}
|
||||
if(buy.getLandlord() != null) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionLandlord", buy);
|
||||
}
|
||||
if(buy.getInactiveTimeUntilSell() != -1) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionInactiveSell", buy);
|
||||
}
|
||||
// Teleport
|
||||
Message tp = Message.fromKey("info-prefix");
|
||||
boolean foundSomething = false;
|
||||
if(TeleportCommand.canUse(sender, buy)) {
|
||||
foundSomething = true;
|
||||
tp.append(Message.fromKey("info-regionTeleport").replacements(buy));
|
||||
}
|
||||
if(SetteleportCommand.canUse(sender, buy)) {
|
||||
if(foundSomething) {
|
||||
tp.append(", ");
|
||||
}
|
||||
foundSomething = true;
|
||||
tp.append(Message.fromKey("info-setRegionTeleport").replacements(buy));
|
||||
}
|
||||
if(foundSomething) {
|
||||
tp.append(".");
|
||||
tp.send(sender);
|
||||
}
|
||||
// Signs
|
||||
List<String> signLocations = new ArrayList<>();
|
||||
for(BlockPosition location : buy.getSignsFeature().signManager().allSignLocations()) {
|
||||
signLocations.add(Message.fromKey("info-regionSignLocation").replacements(location.getWorld().getName(), location.getX(), location.getY(), location.getZ()).getPlain());
|
||||
}
|
||||
if(!signLocations.isEmpty()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionSigns", Utils.createCommaSeparatedList(signLocations));
|
||||
}
|
||||
// Groups
|
||||
if(sender.hasPermission("areashop.groupinfo") && !buy.getGroupNames().isEmpty()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionGroups", Utils.createCommaSeparatedList(buy.getGroupNames()));
|
||||
}
|
||||
// Restoring
|
||||
if(buy.isRestoreEnabled()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestoringBuy", buy);
|
||||
}
|
||||
// Restrictions
|
||||
if(!buy.isSold()) {
|
||||
if(buy.restrictedToRegion()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestrictedRegionBuy", buy);
|
||||
} else if(buy.restrictedToWorld()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestrictedWorldBuy", buy);
|
||||
}
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "info-regionFooterBuy", buy);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "info-regionHelp");
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "info-help");
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "info-help");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result.addAll(Arrays.asList("all", "rented", "forrent", "sold", "forsale", "player", "region", "nogroup", "reselling"));
|
||||
} else if(toComplete == 3) {
|
||||
if(start[2].equalsIgnoreCase("player")) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if(start[2].equalsIgnoreCase("region")) {
|
||||
result.addAll(fileManager.getBuyNames());
|
||||
result.addAll(fileManager.getRentNames());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Display a page of a list of regions.
|
||||
*
|
||||
* @param sender The CommandSender to send the messages to
|
||||
* @param regionStream The regions to display
|
||||
* @param filterGroup The group to filter the regions by
|
||||
* @param keyHeader The header to print above the page
|
||||
* @param pageInput The page number, if any
|
||||
* @param baseCommand The command to execute for next/previous page (/areashop will be added)
|
||||
*/
|
||||
private void showSortedPagedList(
|
||||
CommandSender sender,
|
||||
Stream<? extends GeneralRegion> regionStream,
|
||||
RegionGroup filterGroup,
|
||||
String keyHeader,
|
||||
int pageInput,
|
||||
String baseCommand
|
||||
) {
|
||||
int page = pageInput;
|
||||
int maximumItems = 20;
|
||||
int itemsPerPage = maximumItems - 2;
|
||||
List<? extends GeneralRegion> regions;
|
||||
if (filterGroup != null) {
|
||||
regions = regionStream.filter(generalRegion -> !filterGroup.isMember(generalRegion)).toList();
|
||||
} else {
|
||||
regions = regionStream.toList();
|
||||
}
|
||||
if (regions.isEmpty()) {
|
||||
messageBridge.message(sender, "info-noRegions");
|
||||
return;
|
||||
}
|
||||
// First sort by type, then by name
|
||||
regions = regions.stream().sorted((one, two) -> {
|
||||
int typeCompare = getTypeOrder(two).compareTo(getTypeOrder(one));
|
||||
if (typeCompare != 0) {
|
||||
return typeCompare;
|
||||
} else {
|
||||
return one.getName().compareTo(two.getName());
|
||||
}
|
||||
}).toList();
|
||||
// Header
|
||||
Message limitedToGroup = Message.empty();
|
||||
if (filterGroup != null) {
|
||||
limitedToGroup = Message.fromKey("info-limitedToGroup").replacements(filterGroup.getName());
|
||||
}
|
||||
messageBridge.message(sender, keyHeader, limitedToGroup);
|
||||
// Page entries
|
||||
int totalPages = (int) Math.ceil(regions.size() / (double) itemsPerPage); // Clip page to correct boundaries, not much need to tell the user
|
||||
if (regions.size() == itemsPerPage + 1) { // 19 total items is mapped to 1 page of 19
|
||||
itemsPerPage++;
|
||||
totalPages = 1;
|
||||
}
|
||||
page = Math.max(1, Math.min(totalPages, page));
|
||||
int linesPrinted = 1; // header
|
||||
for (int i = (page - 1) * itemsPerPage; i < page * itemsPerPage && i < regions.size(); i++) {
|
||||
String state;
|
||||
GeneralRegion region = regions.get(i);
|
||||
if (region.getType() == GeneralRegion.RegionType.RENT) {
|
||||
if (region.getOwner() == null) {
|
||||
state = "Forrent";
|
||||
} else {
|
||||
state = "Rented";
|
||||
}
|
||||
} else {
|
||||
if (region.getOwner() == null) {
|
||||
state = "Forsale";
|
||||
} else if (!((BuyRegion) region).isInResellingMode()) {
|
||||
state = "Sold";
|
||||
} else {
|
||||
state = "Reselling";
|
||||
}
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "info-entry" + state, region);
|
||||
linesPrinted++;
|
||||
}
|
||||
Message footer = Message.empty();
|
||||
// Previous button
|
||||
if (page > 1) {
|
||||
footer.append(Message.fromKey("info-pagePrevious").replacements(baseCommand + " --page " + (page - 1)));
|
||||
} else {
|
||||
footer.append(Message.fromKey("info-pageNoPrevious"));
|
||||
}
|
||||
// Page status
|
||||
if (totalPages > 1) {
|
||||
StringBuilder pageString = new StringBuilder("" + page);
|
||||
for (int i = pageString.length(); i < (totalPages + "").length(); i++) {
|
||||
pageString.insert(0, "0");
|
||||
}
|
||||
footer.append(Message.fromKey("info-pageStatus").replacements(page, totalPages));
|
||||
if (page < totalPages) {
|
||||
footer.append(Message.fromKey("info-pageNext").replacements(baseCommand + " --page " + (page + 1)));
|
||||
} else {
|
||||
footer.append(Message.fromKey("info-pageNoNext"));
|
||||
}
|
||||
// Fill up space if the page is not full (aligns header nicely)
|
||||
for (int i = linesPrinted; i < maximumItems - 1; i++) {
|
||||
sender.sendMessage(" ");
|
||||
}
|
||||
SimpleMessageBridge.send(footer, sender);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer to order by type, usable for Comparators.
|
||||
*
|
||||
* @param region The region to get the order for
|
||||
* @return An integer for sorting by type
|
||||
*/
|
||||
private Integer getTypeOrder(GeneralRegion region) {
|
||||
if (region.getType() == GeneralRegion.RegionType.RENT) {
|
||||
if (region.getOwner() == null) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
if (region.getOwner() == null) {
|
||||
return 3;
|
||||
} else if (!((BuyRegion) region).isInResellingMode()) {
|
||||
return 4;
|
||||
} else {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private enum RegionStateFilterType {
|
||||
ALL,
|
||||
RENTED,
|
||||
FORRENT,
|
||||
SOLD,
|
||||
FORSALE,
|
||||
RESELLING,
|
||||
NOGROUP
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.OfflinePlayerParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionInfoUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class InfoPlayerCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_PLAYER = CloudKey.of("player", String.class);
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
private final BukkitSchedulerExecutor executor;
|
||||
|
||||
@Inject
|
||||
public InfoPlayerCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
|
||||
@Nonnull BukkitSchedulerExecutor executor
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
this.offlinePlayerHelper = offlinePlayerHelper;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(CommandSender target) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("info").literal("player")
|
||||
.required(KEY_PLAYER, OfflinePlayerParser.parser())
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("info region");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.info")) {
|
||||
messageBridge.message(sender, "info-noPermission");
|
||||
return;
|
||||
}
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
|
||||
.whenCompleteAsync((offlinePlayer, exception) -> {
|
||||
if (exception != null) {
|
||||
sender.sendMessage("failed to lookup offline player!");
|
||||
exception.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
|
||||
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
|
||||
return;
|
||||
}
|
||||
RegionInfoUtil.showRegionInfo(this.messageBridge, this.fileManager, sender, offlinePlayer);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import io.github.bakedlibs.dough.blocks.BlockPosition;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.SimpleMessageBridge;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class InfoRegionCommand extends AreashopCommandBean {
|
||||
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Inject
|
||||
public InfoRegionCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("info").literal("region")
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("info region");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.info")) {
|
||||
messageBridge.message(sender, "info-noPermission");
|
||||
return;
|
||||
}
|
||||
// Region info
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
if (region instanceof RentRegion rent) {
|
||||
handleRent(sender, rent);
|
||||
} else if (region instanceof BuyRegion buy) {
|
||||
handleBuy(sender, buy);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBuy(@Nonnull CommandSender sender, @Nonnull BuyRegion buy) {
|
||||
messageBridge.message(sender, "info-regionHeaderBuy", buy);
|
||||
if (buy.isSold()) {
|
||||
if (buy.isInResellingMode()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionReselling", buy);
|
||||
messageBridge.messageNoPrefix(sender, "info-regionReselPrice", buy);
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionBought", buy);
|
||||
}
|
||||
// Money back
|
||||
if (!buy.getBooleanSetting("buy.sellDisabled")) {
|
||||
if (SellCommand.canUse(sender, buy)) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMoneyBackBuyClick", buy);
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMoneyBackBuy", buy);
|
||||
}
|
||||
}
|
||||
// Friends
|
||||
if (!buy.getFriendsFeature().getFriendNames().isEmpty()) {
|
||||
String messagePart = "info-friend";
|
||||
if (DelFriendCommand.canUse(sender, buy)) {
|
||||
messagePart = "info-friendRemove";
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender,
|
||||
"info-regionFriends",
|
||||
buy,
|
||||
Utils.combinedMessage(buy.getFriendsFeature().getFriendNames(), messagePart));
|
||||
}
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionCanBeBought", buy);
|
||||
}
|
||||
if (buy.getLandlord() != null) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionLandlord", buy);
|
||||
}
|
||||
if (buy.getInactiveTimeUntilSell() != -1) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionInactiveSell", buy);
|
||||
}
|
||||
// Restoring
|
||||
if (buy.isRestoreEnabled()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestoringBuy", buy);
|
||||
}
|
||||
// Restrictions
|
||||
if (!buy.isSold()) {
|
||||
if (buy.restrictedToRegion()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestrictedRegionBuy", buy);
|
||||
} else if (buy.restrictedToWorld()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestrictedWorldBuy", buy);
|
||||
}
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "info-regionFooterBuy", buy);
|
||||
}
|
||||
|
||||
private void handleRent(@Nonnull CommandSender sender, @Nonnull RentRegion rent) {
|
||||
messageBridge.message(sender, "info-regionHeaderRent", rent);
|
||||
if (rent.isRented()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRented", rent);
|
||||
messageBridge.messageNoPrefix(sender, "info-regionExtending", rent);
|
||||
// Money back
|
||||
if (UnrentCommand.canUse(sender, rent)) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMoneyBackRentClick", rent);
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMoneyBackRent", rent);
|
||||
}
|
||||
// Friends
|
||||
if (!rent.getFriendsFeature().getFriendNames().isEmpty()) {
|
||||
String messagePart = "info-friend";
|
||||
if (DelFriendCommand.canUse(sender, rent)) {
|
||||
messagePart = "info-friendRemove";
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender,
|
||||
"info-regionFriends",
|
||||
rent,
|
||||
Utils.combinedMessage(rent.getFriendsFeature().getFriendNames(), messagePart));
|
||||
}
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionCanBeRented", rent);
|
||||
}
|
||||
if (rent.getLandlordName() != null) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionLandlord", rent);
|
||||
}
|
||||
// Maximum extends
|
||||
if (rent.getMaxExtends() != -1) {
|
||||
if (rent.getMaxExtends() == 0) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionNoExtending", rent);
|
||||
} else if (rent.isRented()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionExtendsLeft", rent);
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMaxExtends", rent);
|
||||
}
|
||||
}
|
||||
// If maxExtends is zero it does not make sense to show this message
|
||||
if (rent.getMaxRentTime() != -1 && rent.getMaxExtends() != 0) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionMaxRentTime", rent);
|
||||
}
|
||||
if (rent.getInactiveTimeUntilUnrent() != -1) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionInactiveUnrent", rent);
|
||||
}
|
||||
displayMiscInfo(sender, rent);
|
||||
// Restoring
|
||||
if (rent.isRestoreEnabled()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestoringRent", rent);
|
||||
}
|
||||
// Restrictions
|
||||
if (!rent.isRented()) {
|
||||
if (rent.restrictedToRegion()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestrictedRegionRent", rent);
|
||||
} else if (rent.restrictedToWorld()) {
|
||||
messageBridge.messageNoPrefix(sender, "info-regionRestrictedWorldRent", rent);
|
||||
}
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "info-regionFooterRent", rent);
|
||||
}
|
||||
|
||||
private void displayMiscInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) {
|
||||
displayTeleportInfo(sender, region);
|
||||
displaySignInfo(sender, region);
|
||||
displayGroupInfo(sender, region);
|
||||
}
|
||||
|
||||
private void displayGroupInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) {// Groups
|
||||
if (sender.hasPermission("areashop.groupinfo") && !region.getGroupNames().isEmpty()) {
|
||||
messageBridge.messageNoPrefix(sender,
|
||||
"info-regionGroups",
|
||||
Utils.createCommaSeparatedList(region.getGroupNames()));
|
||||
}
|
||||
}
|
||||
|
||||
private void displaySignInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) {
|
||||
// Signs
|
||||
List<String> signLocations = new ArrayList<>();
|
||||
for (BlockPosition location : region.getSignsFeature().signManager().allSignLocations()) {
|
||||
signLocations.add(Message.fromKey("info-regionSignLocation")
|
||||
.replacements(location.getWorld().getName(),
|
||||
location.getX(),
|
||||
location.getY(),
|
||||
location.getZ())
|
||||
.getPlain());
|
||||
}
|
||||
if (!signLocations.isEmpty()) {
|
||||
messageBridge.messageNoPrefix(sender,
|
||||
"info-regionSigns",
|
||||
Utils.createCommaSeparatedList(signLocations));
|
||||
}
|
||||
}
|
||||
|
||||
private void displayTeleportInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) {
|
||||
// Teleport
|
||||
Message tp = Message.fromKey("info-prefix");
|
||||
boolean foundSomething = false;
|
||||
if (TeleportCommand.canUse(sender, region)) {
|
||||
foundSomething = true;
|
||||
tp.append(Message.fromKey("info-regionTeleport").replacements(region));
|
||||
}
|
||||
if (SetTeleportCommand.canUse(sender, region)) {
|
||||
if (foundSomething) {
|
||||
tp.append(", ");
|
||||
}
|
||||
foundSomething = true;
|
||||
tp.append(Message.fromKey("info-setRegionTeleport").replacements(region));
|
||||
}
|
||||
if (foundSomething) {
|
||||
tp.append(".");
|
||||
SimpleMessageBridge.send(tp, sender);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.SignProfileUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class LinkSignsCommand extends AreashopCommandBean {
|
||||
|
||||
private final SignLinkerManager signLinkerManager;
|
||||
private final AreaShop plugin;
|
||||
|
||||
private final CommandFlag<String> profileFlag;
|
||||
|
||||
@Inject
|
||||
public LinkSignsCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull SignLinkerManager signLinkerManager,
|
||||
@Nonnull AreaShop plugin
|
||||
) {
|
||||
this.signLinkerManager = signLinkerManager;
|
||||
this.plugin = plugin;
|
||||
this.profileFlag = SignProfileUtil.createDefault(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("linksign")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.flag(this.profileFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("linksign");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(CommandSender target) {
|
||||
if (target.hasPermission("areashop.linksigns")) {
|
||||
return "help-linksigns";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player player = context.sender().sender();
|
||||
if (!player.hasPermission("linksigns")) {
|
||||
throw new AreaShopCommandException("linksigns-noPermission");
|
||||
}
|
||||
if (signLinkerManager.isInSignLinkMode(player)) {
|
||||
signLinkerManager.exitSignLinkMode(player);
|
||||
return;
|
||||
}
|
||||
// Get the profile
|
||||
String profile = SignProfileUtil.getOrParseProfile(context, this.plugin);
|
||||
this.signLinkerManager.enterSignLinkMode(player, profile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Singleton
|
||||
public class LinksignsCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private SignLinkerManager signLinkerManager;
|
||||
@Inject
|
||||
private AreaShop plugin;
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop linksigns";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.linksigns")) {
|
||||
return "help-linksigns";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.linksigns")) {
|
||||
messageBridge.message(sender, "linksigns-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player)sender;
|
||||
if(signLinkerManager.isInSignLinkMode(player)) {
|
||||
signLinkerManager.exitSignLinkMode(player);
|
||||
} else {
|
||||
// Get the profile
|
||||
String profile = null;
|
||||
if(args.length > 1) {
|
||||
profile = args[1];
|
||||
ConfigurationSection signProfilesSection = plugin.getConfig().getConfigurationSection("signProfiles");
|
||||
if(signProfilesSection != null) {
|
||||
Set<String> profiles = signProfilesSection.getKeys(false);
|
||||
if(!profiles.contains(profile)) {
|
||||
ArrayList<String> message = new ArrayList<>();
|
||||
for(String p : profiles) {
|
||||
if(!message.isEmpty()) {
|
||||
message.add(", ");
|
||||
}
|
||||
message.addAll(Message.fromKey("addsign-profile").replacements(p).get());
|
||||
}
|
||||
messageBridge.message(sender, "addsign-wrongProfile", Message.fromList(message));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
signLinkerManager.enterSignLinkMode(player, profile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result.addAll(plugin.getFileManager().getRegionNames());
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(plugin.getConfig().getStringList("signProfiles"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,129 +1,100 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.OfflinePlayerParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionInfoUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class MeCommand extends CommandAreaShop {
|
||||
public class MeCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
private static final CloudKey<String> KEY_PLAYER = CloudKey.of("player", String.class);
|
||||
private final IFileManager fileManager;
|
||||
private final MessageBridge messageBridge;
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
private final BukkitSchedulerExecutor executor;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop me";
|
||||
}
|
||||
@Inject
|
||||
public MeCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
|
||||
@Nonnull BukkitSchedulerExecutor executor
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
this.offlinePlayerHelper = offlinePlayerHelper;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.me")) {
|
||||
return "help-me";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.me")) {
|
||||
messageBridge.message(sender, "me-noPermission");
|
||||
return;
|
||||
}
|
||||
OfflinePlayer player = null;
|
||||
if(!(sender instanceof Player)) {
|
||||
if(args.length <= 1) {
|
||||
messageBridge.message(sender, "me-notAPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
player = (OfflinePlayer)sender;
|
||||
}
|
||||
if(args.length > 1) {
|
||||
player = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(!player.hasPlayedBefore()) {
|
||||
messageBridge.message(sender, "me-noPlayer", args[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!player.hasPlayedBefore()) {
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("me")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.optional(KEY_PLAYER, OfflinePlayerParser.parser())
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
// Get the regions owned by the player
|
||||
Set<RentRegion> rentRegions = new HashSet<>();
|
||||
for(RentRegion region : fileManager.getRentsRef()) {
|
||||
if(region.isOwner(player)) {
|
||||
rentRegions.add(region);
|
||||
}
|
||||
}
|
||||
Set<BuyRegion> buyRegions = new HashSet<>();
|
||||
for(BuyRegion region : fileManager.getBuysRef()) {
|
||||
if(region.isOwner(player)) {
|
||||
buyRegions.add(region);
|
||||
}
|
||||
}
|
||||
// Get the regions the player is added as friend
|
||||
Set<GeneralRegion> friendRegions = new HashSet<>();
|
||||
for(GeneralRegion region : fileManager.getRegionsRef()) {
|
||||
if(region.getFriendsFeature().getFriends().contains(player.getUniqueId())) {
|
||||
friendRegions.add(region);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("me");
|
||||
}
|
||||
|
||||
// Send messages
|
||||
boolean foundSome = !rentRegions.isEmpty() || !buyRegions.isEmpty() || !friendRegions.isEmpty();
|
||||
if(foundSome) {
|
||||
messageBridge.message(sender, "me-header", player.getName());
|
||||
}
|
||||
if(!rentRegions.isEmpty()) {
|
||||
for(RentRegion region : rentRegions) {
|
||||
messageBridge.messageNoPrefix(sender, "me-rentLine", region);
|
||||
}
|
||||
}
|
||||
if(!buyRegions.isEmpty()) {
|
||||
for(BuyRegion region : buyRegions) {
|
||||
messageBridge.messageNoPrefix(sender, "me-buyLine", region);
|
||||
}
|
||||
}
|
||||
if(!friendRegions.isEmpty()) {
|
||||
for(GeneralRegion region : friendRegions) {
|
||||
messageBridge.messageNoPrefix(sender, "me-friendLine", region);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.me")) {
|
||||
return "help-me";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!foundSome) {
|
||||
messageBridge.message(sender, "me-nothing", player.getName());
|
||||
} else {
|
||||
messageBridge.messageNoPrefix(sender, "me-clickHint");
|
||||
}
|
||||
}
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.me")) {
|
||||
throw new AreaShopCommandException("me-noPermission");
|
||||
}
|
||||
if (!context.contains(KEY_PLAYER)) {
|
||||
RegionInfoUtil.showRegionInfo(this.messageBridge, this.fileManager, sender, sender);
|
||||
return;
|
||||
}
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
|
||||
.whenCompleteAsync((offlinePlayer, exception) -> {
|
||||
if (exception != null) {
|
||||
sender.sendMessage("failed to lookup offline player!");
|
||||
exception.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
|
||||
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
|
||||
return;
|
||||
}
|
||||
RegionInfoUtil.showRegionInfo(this.messageBridge, this.fileManager, sender, offlinePlayer);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,69 +1,62 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.tools.SimpleMessageBridge;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.bukkit.parser.PlayerParser;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class MessageCommand extends CommandAreaShop {
|
||||
public class MessageCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop message";
|
||||
}
|
||||
private static final CloudKey<Player> KEY_PLAYER = CloudKey.of("player", Player.class);
|
||||
private static final CloudKey<String> KEY_MESSAGE = CloudKey.of("message", String.class);
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
// Internal command, no need to show in the help list
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
if(!sender.hasPermission("areashop.message")) {
|
||||
messageBridge.message(sender, "message-noPermission");
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length < 3) {
|
||||
messageBridge.message(sender, "message-help");
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
if(player == null) {
|
||||
messageBridge.message(sender, "message-notOnline", args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
String[] messageArgs = new String[args.length - 2];
|
||||
System.arraycopy(args, 2, messageArgs, 0, args.length - 2);
|
||||
String message = StringUtils.join(messageArgs, " ");
|
||||
|
||||
Message.fromString(message).send(player);
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("message")
|
||||
.required(KEY_PLAYER, PlayerParser.playerParser())
|
||||
.required(KEY_MESSAGE, StringParser.greedyStringParser())
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("message");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if(!sender.hasPermission("areashop.message")) {
|
||||
throw new AreaShopCommandException("message-noPermission");
|
||||
}
|
||||
return result;
|
||||
Player player = context.get(KEY_PLAYER);
|
||||
String message = context.get(KEY_MESSAGE);
|
||||
Message m = Message.fromString(message);
|
||||
SimpleMessageBridge.send(m, player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.ArgumentParseExceptionHandler;
|
||||
import me.wiefferink.areashop.commands.util.OfflinePlayerParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionCreationUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.exception.CommandExecutionException;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.standard.DoubleParser;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Singleton
|
||||
public class QuickBuyCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_REGION = CloudKey.of("region", String.class);
|
||||
private static final CloudKey<Double> KEY_PRICE = CloudKey.of("price", Double.class);
|
||||
private static final CloudKey<String> KEY_LANDLORD = CloudKey.of("landlord", String.class);
|
||||
private final RegionFactory regionFactory;
|
||||
private final IFileManager fileManager;
|
||||
private final MessageBridge messageBridge;
|
||||
private final RegionCreationUtil regionCreationUtil;
|
||||
private final BukkitSchedulerExecutor executor;
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
@Inject
|
||||
public QuickBuyCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull RegionFactory regionFactory,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull RegionCreationUtil regionCreationUtil,
|
||||
@Nonnull BukkitSchedulerExecutor executor,
|
||||
@Nonnull OfflinePlayerHelper offlinePlayerHelper
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFactory = regionFactory;
|
||||
this.fileManager = fileManager;
|
||||
this.regionCreationUtil = regionCreationUtil;
|
||||
this.executor = executor;
|
||||
this.offlinePlayerHelper = offlinePlayerHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("quickbuy")
|
||||
.permission("permission")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.required(KEY_REGION, StringParser.stringParser())
|
||||
.required(KEY_PRICE, DoubleParser.doubleParser(0))
|
||||
.required(KEY_LANDLORD, OfflinePlayerParser.parser())
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
// /as quickbuy <name> <price> <duration> <landlord>
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player player = context.sender().sender();
|
||||
if (!player.hasPermission("areashop.quickbuy")) {
|
||||
player.sendMessage("Insufficient permission");
|
||||
return;
|
||||
}
|
||||
this.regionCreationUtil.createRegion(context, player, KEY_REGION)
|
||||
.exceptionally(throwable -> {
|
||||
if (throwable instanceof AreaShopCommandException exception) {
|
||||
ArgumentParseExceptionHandler.handleException(this.messageBridge, context.sender(), exception);
|
||||
} else {
|
||||
throw new CommandExecutionException(throwable, context);
|
||||
}
|
||||
return null;
|
||||
}).thenAcceptAsync(region -> {
|
||||
// Error handled previously
|
||||
if (region == null) {
|
||||
this.messageBridge.message(player, "quickadd-failedCreateWGRegion");
|
||||
return;
|
||||
}
|
||||
double price = context.get(KEY_PRICE);
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_LANDLORD))
|
||||
.whenCompleteAsync((landlord, exception) -> {
|
||||
if (exception != null) {
|
||||
player.sendMessage("failed to lookup offline player!");
|
||||
exception.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (!landlord.isOnline() && !landlord.hasPlayedBefore()) {
|
||||
this.messageBridge.message(player, "me-noPlayer", landlord.getName());
|
||||
return;
|
||||
}
|
||||
String regionName = region.getId();
|
||||
World world = player.getWorld();
|
||||
|
||||
BuyRegion buyRegion = this.regionFactory.createBuyRegion(regionName, world);
|
||||
buyRegion.setPrice(price);
|
||||
buyRegion.setLandlord(landlord.getUniqueId(), landlord.getName());
|
||||
this.fileManager.addRegion(buyRegion);
|
||||
this.messageBridge.message(player, "add-success", "buy", regionName);
|
||||
}, this.executor);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpKey(@Nonnull CommandSender target) {
|
||||
if (target.hasPermission("areashop.quickbuy")) {
|
||||
return "help-quickbuy";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("quickbuy");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.description.Description;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Singleton
|
||||
public class QuickDeleteCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<GeneralRegion> KEY_REGION = CloudKey.of("region", GeneralRegion.class);
|
||||
|
||||
private static final CommandFlag<Void> FLAG_RETURN_MONEY = CommandFlag.builder("return-money")
|
||||
.withDescription(Description.of(
|
||||
"If this flag is present, money is returned to the player if someone is currently holding this region"))
|
||||
.build();
|
||||
|
||||
private final IFileManager fileManager;
|
||||
private final WorldGuardInterface worldGuardInterface;
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Inject
|
||||
public QuickDeleteCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface
|
||||
) {
|
||||
this.fileManager = fileManager;
|
||||
this.worldGuardInterface = worldGuardInterface;
|
||||
this.messageBridge = messageBridge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("quickdelete", "quickdel")
|
||||
.permission("areashop.quickdelete")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player player = context.sender().sender();
|
||||
GeneralRegion region = context.get(KEY_REGION);
|
||||
boolean giveMoneyBack = context.flags().isPresent(FLAG_RETURN_MONEY);
|
||||
DeletingRegionEvent event = this.fileManager.deleteRegion(region, giveMoneyBack);
|
||||
if (event.isCancelled()) {
|
||||
throw new AreaShopCommandException("general-cancelled", event.getReason());
|
||||
}
|
||||
this.messageBridge.message(player, "destroy-successRent", region);
|
||||
RegionManager regionManager = this.worldGuardInterface.getRegionManager(region.getWorld());
|
||||
regionManager.removeRegion(region.getRegion().getId());
|
||||
this.messageBridge.message(player, "quickdelete-WGRegionDeleted", region.getName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpKey(@Nonnull CommandSender target) {
|
||||
return "help-quickdelete";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("quickdelete", "quickdel");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.ArgumentParseExceptionHandler;
|
||||
import me.wiefferink.areashop.commands.util.DurationInputParser;
|
||||
import me.wiefferink.areashop.commands.util.OfflinePlayerParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionCreationUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RegionFactory;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import me.wiefferink.areashop.tools.DurationInput;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.exception.CommandExecutionException;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.standard.DoubleParser;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Singleton
|
||||
public class QuickRentCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_REGION = CloudKey.of("region", String.class);
|
||||
private static final CloudKey<Double> KEY_PRICE = CloudKey.of("price", Double.class);
|
||||
|
||||
private static final CloudKey<DurationInput> KEY_DURATION = CloudKey.of("duration", DurationInput.class);
|
||||
private static final CloudKey<String> KEY_LANDLORD = CloudKey.of("landlord", String.class);
|
||||
private final RegionFactory regionFactory;
|
||||
private final IFileManager fileManager;
|
||||
private final MessageBridge messageBridge;
|
||||
private final RegionCreationUtil regionCreationUtil;
|
||||
private final BukkitSchedulerExecutor executor;
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
@Inject
|
||||
public QuickRentCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull RegionFactory regionFactory,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull RegionCreationUtil regionCreationUtil,
|
||||
@Nonnull BukkitSchedulerExecutor executor,
|
||||
@Nonnull OfflinePlayerHelper offlinePlayerHelper
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFactory = regionFactory;
|
||||
this.fileManager = fileManager;
|
||||
this.regionCreationUtil = regionCreationUtil;
|
||||
this.executor = executor;
|
||||
this.offlinePlayerHelper = offlinePlayerHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("quickrent")
|
||||
.permission("permission")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.required(KEY_REGION, StringParser.stringParser())
|
||||
.required(KEY_PRICE, DoubleParser.doubleParser(0))
|
||||
.required(KEY_DURATION, DurationInputParser.durationInputParser())
|
||||
.required(KEY_LANDLORD, OfflinePlayerParser.parser())
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
// /as quickrent <name> <price> <duration> <landlord>
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player player = context.sender().sender();
|
||||
if (!player.hasPermission("areashop.quickrent")) {
|
||||
player.sendMessage("Insufficient permission");
|
||||
return;
|
||||
}
|
||||
this.regionCreationUtil.createRegion(context, player, KEY_REGION)
|
||||
.exceptionally(throwable -> {
|
||||
if (throwable instanceof AreaShopCommandException exception) {
|
||||
ArgumentParseExceptionHandler.handleException(this.messageBridge, context.sender(), exception);
|
||||
} else {
|
||||
throw new CommandExecutionException(throwable, context);
|
||||
}
|
||||
return null;
|
||||
}).thenAcceptAsync(region -> {
|
||||
// Error handled previously
|
||||
if (region == null) {
|
||||
this.messageBridge.message(player, "quickadd-failedCreateWGRegion");
|
||||
return;
|
||||
}
|
||||
double price = context.get(KEY_PRICE);
|
||||
DurationInput duration = context.get(KEY_DURATION);
|
||||
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_LANDLORD))
|
||||
.whenCompleteAsync((landlord, exception) -> {
|
||||
if (exception != null) {
|
||||
player.sendMessage("failed to lookup offline player!");
|
||||
exception.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (!landlord.hasPlayedBefore() && !landlord.isOnline()) {
|
||||
this.messageBridge.message(player, "cmd-invalidPlayer", landlord.getName());
|
||||
return;
|
||||
}
|
||||
String regionName = region.getId();
|
||||
World world = player.getWorld();
|
||||
|
||||
RentRegion rentRegion = this.regionFactory.createRentRegion(regionName, world);
|
||||
rentRegion.setPrice(price);
|
||||
rentRegion.setLandlord(landlord.getUniqueId(), landlord.getName());
|
||||
rentRegion.setDuration(duration.toTinySpacedString());
|
||||
this.fileManager.addRegion(rentRegion);
|
||||
this.messageBridge.message(player, "add-success", "rent", regionName);
|
||||
}, this.executor);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpKey(@Nonnull CommandSender target) {
|
||||
if (target.hasPermission("areashop.quickrent")) {
|
||||
return "help-quickrent";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("quickrent");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
# Commands
|
||||
|
||||
This module contains all AreaShop commands.
|
||||
AreaShop uses https://cloud.incendo.org/
|
||||
|
||||
* `CommandAreaShop` is extended by all other classes, and implements some general functionality and defines which methods should be implemented.
|
||||
* `util/AreashopCommandBean` is extended by all other classes, and implements some general functionality and defines which methods should be implemented.
|
||||
* Other classes implement specific sub-commands, supply their help messages and tab completion.
|
||||
* `CommandManager` class in the `managers` package handles incoming commands and dispatches them to the classes in this package.
|
||||
* `util/AreashopCommands` class in handles all command registration
|
||||
@@ -1,40 +1,59 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class ReloadCommand extends CommandAreaShop {
|
||||
public class ReloadCommand extends AreashopCommandBean {
|
||||
private final AreaShop plugin;
|
||||
|
||||
@Inject
|
||||
private AreaShop plugin;
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop reload";
|
||||
}
|
||||
@Inject
|
||||
public ReloadCommand(@Nonnull AreaShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.reload")) {
|
||||
return "help-reload";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(sender.hasPermission("areashop.reload")) {
|
||||
// Reload the configuration files and update all region flags/signs
|
||||
plugin.reload(sender);
|
||||
} else {
|
||||
messageBridge.message(sender, "reload-noPermission");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("reload")
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("reload");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getHelpKey(CommandSender target) {
|
||||
if (target.hasPermission("areashop.reload")) {
|
||||
return "help-reload";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
if (!context.hasPermission("areashop.reload")) {
|
||||
throw new AreaShopCommandException("reload-noPermission");
|
||||
}
|
||||
this.plugin.reload(context.sender().sender());
|
||||
}
|
||||
}
|
||||
@@ -1,79 +1,69 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class RentCommand extends CommandAreaShop {
|
||||
public class RentCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop rent";
|
||||
}
|
||||
private final CommandFlag<RentRegion> rentRegionFlag;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.rent")) {
|
||||
return "help-rent";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Inject
|
||||
public RentCommand(@Nonnull IFileManager fileManager) {
|
||||
this.rentRegionFlag = RegionParseUtil.createDefaultRent(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.rent")) {
|
||||
messageBridge.message(sender, "rent-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
if(args.length > 1 && args[1] != null) {
|
||||
RentRegion rent = fileManager.getRent(args[1]);
|
||||
if(rent == null) {
|
||||
messageBridge.message(sender, "rent-notRentable", args[1]);
|
||||
} else {
|
||||
rent.rent(player);
|
||||
}
|
||||
} else {
|
||||
// get the region by location
|
||||
List<RentRegion> regions = Utils.getImportantRentRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
} else {
|
||||
regions.get(0).rent(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return "Allows you to rent a region";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if(target.hasPermission("areashop.rent")) {
|
||||
return "help-rent";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nonnull CommandProperties properties() {
|
||||
return CommandProperties.of("rent");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder
|
||||
.literal("rent")
|
||||
.flag(this.rentRegionFlag)
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
if (!context.hasPermission("areashop.rent")) {
|
||||
throw new AreaShopCommandException("rent-noPermission");
|
||||
}
|
||||
Player sender = context.sender().sender();
|
||||
RentRegion region = RegionParseUtil.getOrParseRentRegion(context, sender, this.rentRegionFlag);
|
||||
region.rent(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(RentRegion region : fileManager.getRentsRef()) {
|
||||
if(!region.isRented()) {
|
||||
result.add(region.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,130 +1,130 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.BuyRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.DoubleParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class ResellCommand extends CommandAreaShop {
|
||||
public class ResellCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop resell";
|
||||
}
|
||||
private static final CloudKey<Double> KEY_PRICE = CloudKey.of("price", Double.class);
|
||||
private final CommandFlag<BuyRegion> regionFlag;
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.resellall") || target.hasPermission("areashop.resell")) {
|
||||
return "help-resell";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Inject
|
||||
public ResellCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
ParserDescriptor<CommandSource<?>, BuyRegion> regionParser = ParserDescriptor.of(
|
||||
new BuyRegionParser<>(fileManager, this::suggestBuyRegions),
|
||||
BuyRegion.class
|
||||
);
|
||||
this.regionFlag = CommandFlag.<CommandSource<?>>builder("region").withComponent(regionParser).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.resell") && !sender.hasPermission("areashop.resellall")) {
|
||||
messageBridge.message(sender, "resell-noPermissionOther");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(args.length <= 1) {
|
||||
messageBridge.message(sender, "resell-help");
|
||||
return;
|
||||
}
|
||||
double price;
|
||||
try {
|
||||
price = Double.parseDouble(args[1]);
|
||||
} catch(NumberFormatException e) {
|
||||
messageBridge.message(sender, "resell-wrongPrice", args[1]);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(@Nonnull Command.Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("resell")
|
||||
.required(KEY_PRICE, DoubleParser.doubleParser(0))
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
if(price < 0) {
|
||||
messageBridge.message(sender, "resell-wrongPrice", args[1]);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("resell");
|
||||
}
|
||||
|
||||
BuyRegion buy;
|
||||
if(args.length <= 2) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<BuyRegion> regions = Utils.getImportantBuyRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
buy = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
buy = fileManager.getBuy(args[2]);
|
||||
if(buy == null) {
|
||||
messageBridge.message(sender, "resell-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(buy == null) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
}
|
||||
if(!buy.isSold()) {
|
||||
messageBridge.message(sender, "resell-notBought", buy);
|
||||
return;
|
||||
}
|
||||
if(sender.hasPermission("areashop.resellall")) {
|
||||
buy.enableReselling(price);
|
||||
buy.update();
|
||||
messageBridge.message(sender, "resell-success", buy);
|
||||
} else if(sender.hasPermission("areashop.resell") && sender instanceof Player) {
|
||||
if(!buy.isOwner((Player)sender)) {
|
||||
messageBridge.message(sender, "resell-noPermissionOther", buy);
|
||||
return;
|
||||
}
|
||||
|
||||
if(buy.getBooleanSetting("buy.resellDisabled")) {
|
||||
messageBridge.message(sender, "resell-disabled", buy);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.resellall") || target.hasPermission("areashop.resell")) {
|
||||
return "help-resell";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
buy.enableReselling(price);
|
||||
buy.update();
|
||||
messageBridge.message(sender, "resell-success", buy);
|
||||
} else {
|
||||
messageBridge.message(sender, "resell-noPermission", buy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 3) {
|
||||
for(BuyRegion region : fileManager.getBuysRef()) {
|
||||
if(region.isSold() && !region.isInResellingMode()) {
|
||||
result.add(region.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.resell") && !sender.hasPermission("areashop.resellall")) {
|
||||
messageBridge.message(sender, "resell-noPermissionOther");
|
||||
return;
|
||||
}
|
||||
double price = context.get(KEY_PRICE);
|
||||
BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, sender, this.regionFlag);
|
||||
if (!buy.isSold()) {
|
||||
messageBridge.message(sender, "resell-notBought", buy);
|
||||
return;
|
||||
}
|
||||
if (sender.hasPermission("areashop.resellall")) {
|
||||
buy.enableReselling(price);
|
||||
buy.update();
|
||||
messageBridge.message(sender, "resell-success", buy);
|
||||
} else if (sender.hasPermission("areashop.resell") && sender instanceof Player player) {
|
||||
if (!buy.isOwner(player)) {
|
||||
messageBridge.message(sender, "resell-noPermissionOther", buy);
|
||||
return;
|
||||
}
|
||||
|
||||
if (buy.getBooleanSetting("buy.resellDisabled")) {
|
||||
messageBridge.message(sender, "resell-disabled", buy);
|
||||
return;
|
||||
}
|
||||
|
||||
buy.enableReselling(price);
|
||||
buy.update();
|
||||
messageBridge.message(sender, "resell-success", buy);
|
||||
} else {
|
||||
messageBridge.message(sender, "resell-noPermission", buy);
|
||||
}
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestBuyRegions(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
List<Suggestion> suggestions = this.fileManager.getBuysRef().stream()
|
||||
.filter(region -> region.isSold() && !region.isInResellingMode())
|
||||
.map(GeneralRegion::getName)
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.standard.EnumParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class SchematicEventCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<GeneralRegion> KEY_REGION = CloudKey.of("region", GeneralRegion.class);
|
||||
private static final CloudKey<GeneralRegion.RegionEvent> KEY_EVENT_TYPE = CloudKey.of("eventType",
|
||||
GeneralRegion.RegionEvent.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
|
||||
@Inject
|
||||
public SchematicEventCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("schemevent")
|
||||
.required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
|
||||
.required(KEY_EVENT_TYPE, EnumParser.enumParser(GeneralRegion.RegionEvent.class))
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("schemevent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.schematicevents")) {
|
||||
return "help-schemevent";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.schematicevents")) {
|
||||
throw new AreaShopCommandException("schemevent-noPermission");
|
||||
}
|
||||
|
||||
GeneralRegion region = context.get(KEY_REGION);
|
||||
GeneralRegion.RegionEvent event = context.get(KEY_EVENT_TYPE);
|
||||
if (region.getRegion() == null) {
|
||||
throw new AreaShopCommandException("general-noRegion", region);
|
||||
}
|
||||
region.handleSchematicEvent(event);
|
||||
region.update();
|
||||
this.messageBridge.message(sender, "schemevent-success", event.getValue(), region);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class SchematiceventCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop schemevent";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.schematicevents")) {
|
||||
return "help-schemevent";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.schematicevents")) {
|
||||
messageBridge.message(sender, "schemevent-noPermission");
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length < 3 || args[1] == null || args[2] == null) {
|
||||
messageBridge.message(sender, "schemevent-help");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region = fileManager.getRegion(args[1]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[1]);
|
||||
return;
|
||||
}
|
||||
if(region.getRegion() == null) {
|
||||
messageBridge.message(sender, "general-noRegion", region);
|
||||
return;
|
||||
}
|
||||
GeneralRegion.RegionEvent event = null;
|
||||
boolean exception = false;
|
||||
try {
|
||||
event = GeneralRegion.RegionEvent.valueOf(args[2].toUpperCase());
|
||||
} catch(IllegalArgumentException e) {
|
||||
exception = true;
|
||||
}
|
||||
// Check for a totally wrong event or a non matching event
|
||||
if(exception) {
|
||||
ArrayList<String> values = new ArrayList<>();
|
||||
for(GeneralRegion.RegionEvent value : GeneralRegion.RegionEvent.values()) {
|
||||
values.add(value.getValue().toLowerCase());
|
||||
}
|
||||
messageBridge.message(sender, "schemevent-wrongEvent", args[2], Utils.createCommaSeparatedList(values), region);
|
||||
return;
|
||||
}
|
||||
region.handleSchematicEvent(event);
|
||||
region.update();
|
||||
messageBridge.message(sender, "schemevent-success", args[2], region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
} else if(toComplete == 3) {
|
||||
GeneralRegion region = fileManager.getRegion(start[2]);
|
||||
if(region != null) {
|
||||
if(region instanceof RentRegion) {
|
||||
result.addAll(Arrays.asList("created", "deleted", "rented", "unrented"));
|
||||
} else if(region instanceof BuyRegion) {
|
||||
result.addAll(Arrays.asList("created", "deleted", "bought", "sold"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,106 +1,116 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.BuyRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class SellCommand extends CommandAreaShop {
|
||||
public class SellCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop sell";
|
||||
}
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
private final CommandFlag<BuyRegion> buyRegionFlag;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.sell") || target.hasPermission("areashop.sellown")) {
|
||||
return "help-sell";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Inject
|
||||
public SellCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
ParserDescriptor<CommandSource<?>, BuyRegion> regionParser =
|
||||
ParserDescriptor.of(new BuyRegionParser<>(fileManager, this::suggestBuyRegions), BuyRegion.class);
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
this.buyRegionFlag = CommandFlag.<CommandSource<?>>builder("region").withComponent(regionParser).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a person can sell the region.
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can sell it, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if(person.hasPermission("areashop.sell")) {
|
||||
return true;
|
||||
}
|
||||
if(person instanceof Player) {
|
||||
Player player = (Player)person;
|
||||
return region.isOwner(player) && person.hasPermission("areashop.sellown");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Check if a person can sell the region.
|
||||
*
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can sell it, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if (person.hasPermission("areashop.sell")) {
|
||||
return true;
|
||||
}
|
||||
if (person instanceof Player player) {
|
||||
return region.isOwner(player) && person.hasPermission("areashop.sellown");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.sell") && !sender.hasPermission("areashop.sellown")) {
|
||||
messageBridge.message(sender, "sell-noPermission");
|
||||
return;
|
||||
}
|
||||
BuyRegion buy;
|
||||
if(args.length <= 1) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<BuyRegion> regions = Utils.getImportantBuyRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
buy = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
buy = fileManager.getBuy(args[1]);
|
||||
}
|
||||
if(buy == null) {
|
||||
messageBridge.message(sender, "sell-notRegistered");
|
||||
return;
|
||||
}
|
||||
if(!buy.isSold()) {
|
||||
messageBridge.message(sender, "sell-notBought", buy);
|
||||
return;
|
||||
}
|
||||
buy.sell(true, sender);
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(BuyRegion region : fileManager.getBuysRef()) {
|
||||
if(region.isSold()) {
|
||||
result.add(region.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("sell")
|
||||
.flag(this.buyRegionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("sell");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(CommandSender target) {
|
||||
if (target.hasPermission("areashop.sell") || target.hasPermission("areashop.sellown")) {
|
||||
return "help-sell";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.sell") && !sender.hasPermission("areashop.sellown")) {
|
||||
this.messageBridge.message(sender, "sell-noPermission");
|
||||
return;
|
||||
}
|
||||
BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, sender, this.buyRegionFlag);
|
||||
if (!buy.isSold()) {
|
||||
messageBridge.message(sender, "sell-notBought", buy);
|
||||
return;
|
||||
}
|
||||
buy.sell(true, sender);
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestBuyRegions(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
List<Suggestion> suggestions = this.fileManager.getBuysRef().stream()
|
||||
.filter(BuyRegion::isSold)
|
||||
.map(GeneralRegion::getName)
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.DurationInput;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Singleton
|
||||
public class SetDurationCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_DURATION = CloudKey.of("duration", String.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final CommandFlag<RentRegion> regionFlag;
|
||||
|
||||
@Inject
|
||||
public SetDurationCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefaultRent(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.setduration")) {
|
||||
return "help-setduration";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("setduration")
|
||||
.required(KEY_DURATION, StringParser.stringParser())
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("setduration");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.setduration") && (!sender.hasPermission("areashop.setduration.landlord") && sender instanceof Player)) {
|
||||
this.messageBridge.message(sender, "setduration-noPermission");
|
||||
return;
|
||||
}
|
||||
RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, sender, this.regionFlag);
|
||||
if (!sender.hasPermission("areashop.setduration")
|
||||
&& !(sender instanceof Player player
|
||||
&& rent.isLandlord(player.getUniqueId()))
|
||||
) {
|
||||
this.messageBridge.message(sender, "setduration-noLandlord", rent);
|
||||
return;
|
||||
}
|
||||
String rawDuration = context.get(KEY_DURATION);
|
||||
if ("default".equalsIgnoreCase(rawDuration) || "reset".equalsIgnoreCase(rawDuration)) {
|
||||
rent.setDuration(null);
|
||||
rent.update();
|
||||
this.messageBridge.message(sender, "setduration-successRemoved", rent);
|
||||
return;
|
||||
}
|
||||
DurationInput duration = parseInternalDuration(rawDuration);
|
||||
sender.sendMessage(duration.toTinySpacedString());
|
||||
rent.setDuration(duration.toTinySpacedString());
|
||||
rent.update();
|
||||
this.messageBridge.message(sender, "setduration-success", rent);
|
||||
}
|
||||
|
||||
private DurationInput parseInternalDuration(String rawDuration) {
|
||||
int start = 0;
|
||||
for (int i = 0; i < rawDuration.length(); i++) {
|
||||
if (Character.isAlphabetic(rawDuration.charAt(i))) {
|
||||
start = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (start == 0) {
|
||||
throw new AreaShopCommandException("setduration-wrongFormat", rawDuration);
|
||||
}
|
||||
String duration = rawDuration.substring(0, start);
|
||||
String durationUnit = rawDuration.substring(start);
|
||||
int durationInt;
|
||||
try {
|
||||
durationInt = Integer.parseInt(duration);
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new AreaShopCommandException("setduration-wrongAmount", duration);
|
||||
}
|
||||
TimeUnit timeUnit = DurationInput.getTimeUnit(durationUnit)
|
||||
.orElseThrow(() -> new AreaShopCommandException("setduration-wrongFormat", durationUnit));
|
||||
|
||||
boolean invalid = !switch (timeUnit) {
|
||||
case DAYS, HOURS, MINUTES, SECONDS -> true;
|
||||
default -> false;
|
||||
};
|
||||
if (invalid) {
|
||||
throw new AreaShopCommandException("setduration-wrongFormat", durationUnit);
|
||||
}
|
||||
return new DurationInput(durationInt, timeUnit);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.OfflinePlayerParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class SetLandlordCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_PLAYER = CloudKey.of("player", String.class);
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
private final BukkitSchedulerExecutor executor;
|
||||
|
||||
@Inject
|
||||
public SetLandlordCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
|
||||
@Nonnull BukkitSchedulerExecutor executor
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
this.offlinePlayerHelper = offlinePlayerHelper;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.setlandlord")) {
|
||||
return "help-setlandlord";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("setlandlord")
|
||||
.required(KEY_PLAYER, OfflinePlayerParser.parser())
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("setlandlord");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.setlandlord")) {
|
||||
throw new AreaShopCommandException("setlandlord-noPermission");
|
||||
}
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
|
||||
.whenCompleteAsync((landlord, exception) -> {
|
||||
if (exception != null) {
|
||||
sender.sendMessage("failed to lookup offline player!");
|
||||
exception.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (!landlord.hasPlayedBefore() && !landlord.isOnline()) {
|
||||
this.messageBridge.message(sender, "cmd-invalidPlayer", landlord.getName());
|
||||
return;
|
||||
}
|
||||
String playerName = landlord.getName();
|
||||
region.setLandlord(landlord.getUniqueId(), playerName);
|
||||
region.update();
|
||||
this.messageBridge.message(sender, "setlandlord-success", playerName, region);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.IntegerParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class SetMaxExtends extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<Integer> KEY_EXTENDS = CloudKey.of("extends", Integer.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final CommandFlag<RentRegion> regionFlag;
|
||||
|
||||
@Inject
|
||||
public SetMaxExtends(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefaultRent(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.setmaxextends")) {
|
||||
return "help-setmaxextends";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("setmaxextends")
|
||||
.required(KEY_EXTENDS, IntegerParser.integerParser(0))
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("setmaxextends");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.setmaxextends") && (!sender.hasPermission("areashop.setmaxextends.landlord") && sender instanceof Player)) {
|
||||
this.messageBridge.message(sender, "setmaxextends-noPermission");
|
||||
return;
|
||||
}
|
||||
RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, sender, this.regionFlag);
|
||||
if (!sender.hasPermission("areashop.setmaxextends")
|
||||
&& !(sender instanceof Player player
|
||||
&& rent.isLandlord(player.getUniqueId()))
|
||||
) {
|
||||
this.messageBridge.message(sender, "setmaxextends-noLandlord", rent);
|
||||
return;
|
||||
}
|
||||
int extend = context.get(KEY_EXTENDS);
|
||||
|
||||
sender.sendMessage();
|
||||
rent.setMaxExtends(extend);
|
||||
rent.update();
|
||||
this.messageBridge.message(sender, "setmaxextends-success", rent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.OfflinePlayerParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
|
||||
@Singleton
|
||||
public class SetOwnerCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_PLAYER = CloudKey.of("player", String.class);
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
private final BukkitSchedulerExecutor executor;
|
||||
|
||||
@Inject
|
||||
public SetOwnerCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
|
||||
@Nonnull BukkitSchedulerExecutor executor
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
this.offlinePlayerHelper = offlinePlayerHelper;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.setownerrent") || target.hasPermission("areashop.setownerbuy")) {
|
||||
return "help-setowner";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("setowner")
|
||||
.required(KEY_PLAYER, OfflinePlayerParser.parser())
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("setowner");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.setownerrent") && !sender.hasPermission("areashop.setownerbuy")) {
|
||||
this.messageBridge.message(sender, "setowner-noPermission");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
if (region instanceof RentRegion && !sender.hasPermission("areashop.setownerrent")) {
|
||||
this.messageBridge.message(sender, "setowner-noPermissionRent", region);
|
||||
return;
|
||||
}
|
||||
if (region instanceof BuyRegion && !sender.hasPermission("areashop.setownerbuy")) {
|
||||
this.messageBridge.message(sender, "setowner-noPermissionBuy", region);
|
||||
return;
|
||||
}
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
|
||||
.whenCompleteAsync((offlinePlayer, exception) -> {
|
||||
if (exception != null) {
|
||||
sender.sendMessage("failed to lookup offline player!");
|
||||
exception.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
|
||||
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
|
||||
return;
|
||||
}
|
||||
setOwner(sender, offlinePlayer, region);
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
private void setOwner(@Nonnull CommandSender sender, @Nonnull OfflinePlayer player, GeneralRegion region) {
|
||||
final UUID uuid = player.getUniqueId();
|
||||
if (region instanceof RentRegion rent) {
|
||||
if (rent.isRenter(uuid)) {
|
||||
// extend
|
||||
rent.setRentedUntil(rent.getRentedUntil() + rent.getDuration());
|
||||
rent.setRenter(uuid);
|
||||
this.messageBridge.message(sender, "setowner-succesRentExtend", region);
|
||||
} else {
|
||||
// change
|
||||
if (!rent.isRented()) {
|
||||
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
|
||||
}
|
||||
rent.setRenter(uuid);
|
||||
this.messageBridge.message(sender, "setowner-succesRent", region);
|
||||
}
|
||||
} else if (region instanceof BuyRegion buy) {
|
||||
buy.setBuyer(uuid);
|
||||
this.messageBridge.message(sender, "setowner-succesBuy", region);
|
||||
}
|
||||
region.getFriendsFeature().deleteFriend(region.getOwner(), null);
|
||||
region.update();
|
||||
region.saveRequired();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class SetPriceCommand extends AreashopCommandBean {
|
||||
|
||||
|
||||
private static final CloudKey<String> KEY_PRICE = CloudKey.of("price", String.class);
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Inject
|
||||
public SetPriceCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(CommandSender target) {
|
||||
if (target.hasPermission("areashop.setprice")) {
|
||||
return "help-setprice";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("setprice")
|
||||
.required(KEY_PRICE, StringParser.stringParser())
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("setprice");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.setprice") && (!sender.hasPermission("areashop.setprice.landlord") && sender instanceof Player)) {
|
||||
this.messageBridge.message(sender, "setprice-noPermission");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
if (!sender.hasPermission("areashop.setprice")
|
||||
&& !(sender instanceof Player player && region.isLandlord(player.getUniqueId()))) {
|
||||
this.messageBridge.message(sender, "setprice-noLandlord", region);
|
||||
return;
|
||||
}
|
||||
String rawPrice = context.get(KEY_PRICE);
|
||||
if ("default".equalsIgnoreCase(rawPrice) || "reset".equalsIgnoreCase(rawPrice)) {
|
||||
if (region instanceof RentRegion rentRegion) {
|
||||
rentRegion.setPrice(null);
|
||||
} else if (region instanceof BuyRegion buyRegion) {
|
||||
buyRegion.setPrice(null);
|
||||
}
|
||||
region.update();
|
||||
this.messageBridge.message(sender, "setprice-successRemoved", region);
|
||||
return;
|
||||
}
|
||||
double price;
|
||||
try {
|
||||
price = Double.parseDouble(rawPrice);
|
||||
} catch (NumberFormatException e) {
|
||||
this.messageBridge.message(sender, "setprice-wrongPrice", rawPrice, region);
|
||||
return;
|
||||
}
|
||||
if (region instanceof RentRegion rentRegion) {
|
||||
rentRegion.setPrice(price);
|
||||
this.messageBridge.message(sender, "setprice-successRent", region);
|
||||
} else if (region instanceof BuyRegion buyRegion) {
|
||||
buyRegion.setPrice(price);
|
||||
this.messageBridge.message(sender, "setprice-successBuy", region);
|
||||
}
|
||||
region.update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class SetRestoreCommand extends AreashopCommandBean {
|
||||
|
||||
private static final List<String> RESTORE_TYPES = List.of("true", "false", "general");
|
||||
private static final CloudKey<GeneralRegion> KEY_REGION = CloudKey.of("region", GeneralRegion.class);
|
||||
private static final CloudKey<String> KEY_RESTORE = CloudKey.of("restore", String.class);
|
||||
|
||||
private static final CloudKey<String> KEY_PROFILE = CloudKey.of("profile", String.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
|
||||
@Inject
|
||||
public SetRestoreCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.setrestore")) {
|
||||
return "help-setrestore";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("setrestore")
|
||||
.required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
|
||||
.required(KEY_RESTORE, StringParser.stringParser(), this::suggestRestoreType)
|
||||
.optional(KEY_PROFILE, StringParser.stringParser(), this::suggestSchematicProfiles)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("setrestore");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.setrestore")) {
|
||||
throw new AreaShopCommandException("setrestore-noPermission");
|
||||
}
|
||||
GeneralRegion region = context.get(KEY_REGION);
|
||||
String restoreType = context.get(KEY_RESTORE);
|
||||
Optional<String> optionalProfile = context.optional(KEY_PROFILE);
|
||||
Boolean value = null;
|
||||
if (restoreType.equalsIgnoreCase("true")) {
|
||||
value = true;
|
||||
} else if (restoreType.equalsIgnoreCase("false")) {
|
||||
value = false;
|
||||
}
|
||||
region.setRestoreSetting(value);
|
||||
String valueString = "general";
|
||||
if (value != null) {
|
||||
valueString = value + "";
|
||||
}
|
||||
if (optionalProfile.isPresent()) {
|
||||
String profile = optionalProfile.get();
|
||||
region.setSchematicProfile(profile);
|
||||
this.messageBridge.message(sender, "setrestore-successProfile", valueString, profile, region);
|
||||
} else {
|
||||
this.messageBridge.message(sender, "setrestore-success", valueString, region);
|
||||
}
|
||||
region.update();
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestRestoreType(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
List<Suggestion> suggestions = RESTORE_TYPES.stream()
|
||||
.filter(type -> type.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestSchematicProfiles(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
ConfigurationSection schemProfiles = fileManager.getConfig().getConfigurationSection("schematicProfiles");
|
||||
if (schemProfiles == null) {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
String text = input.peekString();
|
||||
List<Suggestion> suggestions = schemProfiles.getKeys(false).stream()
|
||||
.filter(profile -> profile.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class SetTeleportCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CommandFlag<Void> FLAG_RESET = CommandFlag.builder("reset").build();
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Inject
|
||||
public SetTeleportCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a person can set the teleport location of the region.
|
||||
*
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can set the teleport location, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if (!(person instanceof Player player)) {
|
||||
return false;
|
||||
}
|
||||
return player.hasPermission("areashop.setteleportall")
|
||||
|| region.isOwner(player) && player.hasPermission("areashop.setteleport");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.setteleportall") || target.hasPermission("areashop.setteleport")) {
|
||||
return "help-setteleport";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("settp")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("settp");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player player = context.sender().sender();
|
||||
if (!player.hasPermission("areashop.setteleport") && !player.hasPermission("areashop.setteleportall")) {
|
||||
this.messageBridge.message(player, "setteleport-noPermission");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, player, this.regionFlag);
|
||||
|
||||
boolean owner;
|
||||
if (region instanceof RentRegion rentRegion) {
|
||||
owner = player.getUniqueId().equals(rentRegion.getRenter());
|
||||
} else if (region instanceof BuyRegion buyRegion) {
|
||||
owner = player.getUniqueId().equals(buyRegion.getBuyer());
|
||||
} else {
|
||||
// FIXME log error
|
||||
return;
|
||||
}
|
||||
if (!player.hasPermission("areashop.setteleport")) {
|
||||
throw new AreaShopCommandException("setteleport-noPermission", region);
|
||||
} else if (!owner && !player.hasPermission("areashop.setteleportall")) {
|
||||
throw new AreaShopCommandException("setteleport-noPermissionOther", region);
|
||||
}
|
||||
boolean reset = context.flags().contains(FLAG_RESET);
|
||||
if (reset) {
|
||||
region.getTeleportFeature().setTeleport(null);
|
||||
region.update();
|
||||
this.messageBridge.message(player, "setteleport-reset", region);
|
||||
}
|
||||
ProtectedRegion wgRegion = region.getRegion();
|
||||
Location location = player.getLocation();
|
||||
if (!player.hasPermission("areashop.setteleportoutsideregion") && (wgRegion == null || !wgRegion.contains(
|
||||
location.getBlockX(),
|
||||
location.getBlockY(),
|
||||
location.getBlockZ()))
|
||||
) {
|
||||
this.messageBridge.message(player, "setteleport-notInside", region);
|
||||
return;
|
||||
}
|
||||
region.getTeleportFeature().setTeleport(location);
|
||||
region.update();
|
||||
this.messageBridge.message(player, "setteleport-success", region);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.BooleanParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class SetTransferCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<Boolean> KEY_ENABLED = CloudKey.of("enabled", Boolean.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
|
||||
@Inject
|
||||
public SetTransferCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefault(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(CommandSender target) {
|
||||
if (target.hasPermission("areashop.settransfer")) {
|
||||
return "help-settransfer";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("settransfer")
|
||||
.required(KEY_ENABLED, BooleanParser.booleanParser(true))
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("settransfer");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.settransfer")) {
|
||||
throw new AreaShopCommandException("settransfer-noPermission");
|
||||
}
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
boolean enabled = context.get(KEY_ENABLED);
|
||||
region.setTransferEnabled(enabled);
|
||||
messageBridge.message(sender, "settransfer-success", enabled, region);
|
||||
region.update();
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class SetdurationCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop setduration";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.setduration")) {
|
||||
return "help-setduration";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setduration") && (!sender.hasPermission("areashop.setduration.landlord") && sender instanceof Player)) {
|
||||
messageBridge.message(sender, "setduration-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 3 || args[1] == null || args[2] == null) {
|
||||
messageBridge.message(sender, "setduration-help");
|
||||
return;
|
||||
}
|
||||
int regionArgument = 3;
|
||||
if(args.length >= 2 && ("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1]))) {
|
||||
regionArgument = 2;
|
||||
}
|
||||
RentRegion rent;
|
||||
if(args.length <= regionArgument) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<RentRegion> regions = Utils.getImportantRentRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
rent = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
rent = fileManager.getRent(args[regionArgument]);
|
||||
}
|
||||
if(rent == null) {
|
||||
messageBridge.message(sender, "setduration-notRegistered", args[regionArgument]);
|
||||
return;
|
||||
}
|
||||
if(!sender.hasPermission("areashop.setduration") && !(sender instanceof Player && rent.isLandlord(((Player)sender).getUniqueId()))) {
|
||||
messageBridge.message(sender, "setduration-noLandlord", rent);
|
||||
return;
|
||||
}
|
||||
if("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1])) {
|
||||
rent.setDuration(null);
|
||||
rent.update();
|
||||
messageBridge.message(sender, "setduration-successRemoved", rent);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Integer.parseInt(args[1]);
|
||||
} catch(NumberFormatException e) {
|
||||
messageBridge.message(sender, "setduration-wrongAmount", args[1], rent);
|
||||
return;
|
||||
}
|
||||
if(!Utils.checkTimeFormat(args[1] + " " + args[2])) {
|
||||
messageBridge.message(sender, "setduration-wrongFormat", args[1] + " " + args[2], rent);
|
||||
return;
|
||||
}
|
||||
rent.setDuration(args[1] + " " + args[2]);
|
||||
rent.update();
|
||||
messageBridge.message(sender, "setduration-success", rent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 3) {
|
||||
result.addAll(plugin.getConfig().getStringList("minutes"));
|
||||
result.addAll(plugin.getConfig().getStringList("hours"));
|
||||
result.addAll(plugin.getConfig().getStringList("days"));
|
||||
result.addAll(plugin.getConfig().getStringList("months"));
|
||||
result.addAll(plugin.getConfig().getStringList("years"));
|
||||
} else if(toComplete == 4) {
|
||||
result = fileManager.getRentNames();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class SetlandlordCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop setlandlord";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.setlandlord")) {
|
||||
return "help-setlandlord";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setlandlord")) {
|
||||
messageBridge.message(sender, "setlandlord-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2) {
|
||||
messageBridge.message(sender, "setlandlord-help");
|
||||
return;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
|
||||
GeneralRegion region;
|
||||
if(args.length < 3) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
}
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
String playerName = player.getName();
|
||||
if(playerName == null || playerName.isEmpty()) {
|
||||
playerName = args[1];
|
||||
}
|
||||
region.setLandlord(player.getUniqueId(), playerName);
|
||||
region.update();
|
||||
messageBridge.message(sender, "setlandlord-success", playerName, region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Singleton
|
||||
public class SetownerCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop setowner";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.setownerrent") || target.hasPermission("areashop.setownerbuy")) {
|
||||
return "help-setowner";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setownerrent") && !sender.hasPermission("areashop.setownerbuy")) {
|
||||
messageBridge.message(sender, "setowner-noPermission");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region;
|
||||
if(args.length < 2) {
|
||||
messageBridge.message(sender, "setowner-help");
|
||||
return;
|
||||
}
|
||||
if(args.length == 2) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
}
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "setowner-notRegistered");
|
||||
return;
|
||||
}
|
||||
|
||||
if(region instanceof RentRegion && !sender.hasPermission("areashop.setownerrent")) {
|
||||
messageBridge.message(sender, "setowner-noPermissionRent", region);
|
||||
return;
|
||||
}
|
||||
if(region instanceof BuyRegion && !sender.hasPermission("areashop.setownerbuy")) {
|
||||
messageBridge.message(sender, "setowner-noPermissionBuy", region);
|
||||
return;
|
||||
}
|
||||
|
||||
UUID uuid = null;
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(player != null) {
|
||||
uuid = player.getUniqueId();
|
||||
}
|
||||
if(uuid == null) {
|
||||
messageBridge.message(sender, "setowner-noPlayer", args[1], region);
|
||||
return;
|
||||
}
|
||||
|
||||
if(region instanceof RentRegion) {
|
||||
RentRegion rent = (RentRegion)region;
|
||||
if(rent.isRenter(uuid)) {
|
||||
// extend
|
||||
rent.setRentedUntil(rent.getRentedUntil() + rent.getDuration());
|
||||
rent.setRenter(uuid);
|
||||
messageBridge.message(sender, "setowner-succesRentExtend", region);
|
||||
} else {
|
||||
// change
|
||||
if(!rent.isRented()) {
|
||||
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
|
||||
}
|
||||
rent.setRenter(uuid);
|
||||
messageBridge.message(sender, "setowner-succesRent", region);
|
||||
}
|
||||
}
|
||||
if(region instanceof BuyRegion) {
|
||||
BuyRegion buy = (BuyRegion)region;
|
||||
buy.setBuyer(uuid);
|
||||
messageBridge.message(sender, "setowner-succesBuy", region);
|
||||
}
|
||||
region.getFriendsFeature().deleteFriend(region.getOwner(), null);
|
||||
region.update();
|
||||
region.saveRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Utils.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class SetpriceCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop setprice";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.setprice")) {
|
||||
return "help-setprice";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setprice") && (!sender.hasPermission("areashop.setprice.landlord") && sender instanceof Player)) {
|
||||
messageBridge.message(sender, "setprice-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2 || args[1] == null) {
|
||||
messageBridge.message(sender, "setprice-help");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region;
|
||||
if(args.length < 3) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[2]);
|
||||
}
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "setprice-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
if(!sender.hasPermission("areashop.setprice") && !(sender instanceof Player && region.isLandlord(((Player)sender).getUniqueId()))) {
|
||||
messageBridge.message(sender, "setprice-noLandlord", region);
|
||||
return;
|
||||
}
|
||||
if("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1])) {
|
||||
if(region instanceof RentRegion) {
|
||||
((RentRegion)region).setPrice(null);
|
||||
} else if(region instanceof BuyRegion) {
|
||||
((BuyRegion)region).setPrice(null);
|
||||
}
|
||||
region.update();
|
||||
messageBridge.message(sender, "setprice-successRemoved", region);
|
||||
return;
|
||||
}
|
||||
double price;
|
||||
try {
|
||||
price = Double.parseDouble(args[1]);
|
||||
} catch(NumberFormatException e) {
|
||||
messageBridge.message(sender, "setprice-wrongPrice", args[1], region);
|
||||
return;
|
||||
}
|
||||
if(region instanceof RentRegion) {
|
||||
((RentRegion)region).setPrice(price);
|
||||
messageBridge.message(sender, "setprice-successRent", region);
|
||||
} else if(region instanceof BuyRegion) {
|
||||
((BuyRegion)region).setPrice(price);
|
||||
messageBridge.message(sender, "setprice-successBuy", region);
|
||||
}
|
||||
region.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 3) {
|
||||
result = fileManager.getRegionNames();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class SetrestoreCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop setrestore";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.setrestore")) {
|
||||
return "help-setrestore";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setrestore")) {
|
||||
messageBridge.message(sender, "setrestore-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length <= 2 || args[1] == null || args[2] == null) {
|
||||
messageBridge.message(sender, "setrestore-help");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region = fileManager.getRegion(args[1]);
|
||||
if(region == null) {
|
||||
messageBridge.message(sender, "setrestore-notRegistered", args[1]);
|
||||
return;
|
||||
}
|
||||
Boolean value = null;
|
||||
if(args[2].equalsIgnoreCase("true")) {
|
||||
value = true;
|
||||
} else if(args[2].equalsIgnoreCase("false")) {
|
||||
value = false;
|
||||
}
|
||||
region.setRestoreSetting(value);
|
||||
String valueString = "general";
|
||||
if(value != null) {
|
||||
valueString = value + "";
|
||||
}
|
||||
if(args.length > 3) {
|
||||
region.setSchematicProfile(args[3]);
|
||||
messageBridge.message(sender, "setrestore-successProfile", valueString, args[3], region);
|
||||
} else {
|
||||
messageBridge.message(sender, "setrestore-success", valueString, region);
|
||||
}
|
||||
region.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result = fileManager.getRegionNames();
|
||||
} else if(toComplete == 3) {
|
||||
result.add("true");
|
||||
result.add("false");
|
||||
result.add("general");
|
||||
} else if(toComplete == 4) {
|
||||
result.addAll(plugin.getConfig().getConfigurationSection("schematicProfiles").getKeys(false));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class SetteleportCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop settp";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.setteleportall") || target.hasPermission("areashop.setteleport")) {
|
||||
return "help-setteleport";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a person can set the teleport location of the region.
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can set the teleport location, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if(!(person instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player)person;
|
||||
return player.hasPermission("areashop.setteleportall")
|
||||
|| region.isOwner(player) && player.hasPermission("areashop.setteleport");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.setteleport") && !sender.hasPermission("areashop.setteleportall")) {
|
||||
messageBridge.message(sender, "setteleport-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
GeneralRegion region;
|
||||
if(args.length < 2) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
region = fileManager.getRegion(args[1]);
|
||||
}
|
||||
|
||||
boolean owner;
|
||||
|
||||
if(region == null) {
|
||||
messageBridge.message(player, "setteleport-noRentOrBuy", args[1]);
|
||||
return;
|
||||
}
|
||||
if(region instanceof RentRegion) {
|
||||
owner = player.getUniqueId().equals(((RentRegion)region).getRenter());
|
||||
} else {
|
||||
owner = player.getUniqueId().equals(((BuyRegion)region).getBuyer());
|
||||
}
|
||||
if(!player.hasPermission("areashop.setteleport")) {
|
||||
messageBridge.message(player, "setteleport-noPermission", region);
|
||||
return;
|
||||
} else if(!owner && !player.hasPermission("areashop.setteleportall")) {
|
||||
messageBridge.message(player, "setteleport-noPermissionOther", region);
|
||||
return;
|
||||
}
|
||||
|
||||
ProtectedRegion wgRegion = region.getRegion();
|
||||
if(args.length > 2 && args[2] != null && (args[2].equalsIgnoreCase("reset") || args[2].equalsIgnoreCase("yes") || args[2].equalsIgnoreCase("true"))) {
|
||||
region.getTeleportFeature().setTeleport(null);
|
||||
region.update();
|
||||
messageBridge.message(player, "setteleport-reset", region);
|
||||
return;
|
||||
}
|
||||
if(!player.hasPermission("areashop.setteleportoutsideregion") && (wgRegion == null || !wgRegion.contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
|
||||
messageBridge.message(player, "setteleport-notInside", region);
|
||||
return;
|
||||
}
|
||||
region.getTeleportFeature().setTeleport(player.getLocation());
|
||||
region.update();
|
||||
messageBridge.message(player, "setteleport-success", region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
} else if(toComplete == 3) {
|
||||
result.add("reset");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,8 +2,13 @@ package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
@@ -21,254 +26,260 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.EnumParser;
|
||||
import org.incendo.cloud.parser.standard.IntegerParser;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Optional;
|
||||
|
||||
@Singleton
|
||||
public class StackCommand extends CommandAreaShop {
|
||||
public class StackCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
@Inject
|
||||
private WorldEditInterface worldEditInterface;
|
||||
@Inject
|
||||
private WorldGuardInterface worldGuardInterface;
|
||||
@Inject
|
||||
private RegionFactory regionFactory;
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop stack";
|
||||
}
|
||||
private static final CloudKey<Integer> KEY_AMOUNT = CloudKey.of("amount", Integer.class);
|
||||
private static final CloudKey<Integer> KEY_GAP = CloudKey.of("gap", Integer.class);
|
||||
private static final CloudKey<String> KEY_NAME = CloudKey.of("name", String.class);
|
||||
private static final CloudKey<GeneralRegion.RegionType> KEY_TYPE = CloudKey.of("type",
|
||||
GeneralRegion.RegionType.class);
|
||||
private static final CommandFlag<String> FLAG_GROUP = CommandFlag.builder("group")
|
||||
.withComponent(StringParser.stringParser())
|
||||
.build();
|
||||
private final MessageBridge messageBridge;
|
||||
private final Plugin plugin;
|
||||
private final WorldEditInterface worldEditInterface;
|
||||
private final WorldGuardInterface worldGuardInterface;
|
||||
private final RegionFactory regionFactory;
|
||||
private final IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.stack")) {
|
||||
return "help-stack";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Inject
|
||||
public StackCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull Plugin plugin,
|
||||
@Nonnull WorldEditInterface worldEditInterface,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface,
|
||||
@Nonnull RegionFactory regionFactory,
|
||||
@Nonnull IFileManager fileManager
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
// Check permission
|
||||
if(!sender.hasPermission("areashop.stack")) {
|
||||
messageBridge.message(sender, "stack-noPermission");
|
||||
return;
|
||||
}
|
||||
// Only from ingame
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
final Player player = (Player)sender;
|
||||
// Specify enough arguments
|
||||
if(args.length < 5) {
|
||||
messageBridge.message(sender, "stack-help");
|
||||
return;
|
||||
}
|
||||
// Check amount
|
||||
int tempAmount = -1;
|
||||
try {
|
||||
tempAmount = Integer.parseInt(args[1]);
|
||||
} catch(NumberFormatException e) {
|
||||
// Incorrect number
|
||||
}
|
||||
if(tempAmount <= 0) {
|
||||
messageBridge.message(player, "stack-wrongAmount", args[1]);
|
||||
return;
|
||||
}
|
||||
// Check gap
|
||||
int gap;
|
||||
try {
|
||||
gap = Integer.parseInt(args[2]);
|
||||
} catch(NumberFormatException e) {
|
||||
messageBridge.message(player, "stack-wrongGap", args[2]);
|
||||
return;
|
||||
}
|
||||
// Check region type
|
||||
if(!"rent".equalsIgnoreCase(args[4]) && !"buy".equalsIgnoreCase(args[4])) {
|
||||
messageBridge.message(sender, "stack-help");
|
||||
return;
|
||||
}
|
||||
// Get WorldEdit selection
|
||||
final WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if(selection == null) {
|
||||
messageBridge.message(player, "stack-noSelection");
|
||||
return;
|
||||
}
|
||||
// Get or create group
|
||||
RegionGroup group = null;
|
||||
if(args.length > 5) {
|
||||
group = fileManager.getGroup(args[5]);
|
||||
if(group == null) {
|
||||
group = regionFactory.createRegionGroup(args[5]);
|
||||
fileManager.addGroup(group);
|
||||
}
|
||||
}
|
||||
// Get facing of the player (must be clearly one of the four directions to make sure it is no mistake)
|
||||
BlockFace facing = Utils.yawToFacing(player.getLocation().getYaw());
|
||||
if(player.getLocation().getPitch() > 45) {
|
||||
facing = BlockFace.DOWN;
|
||||
} else if(player.getLocation().getPitch() < -45) {
|
||||
facing = BlockFace.UP;
|
||||
}
|
||||
if(!(facing == BlockFace.NORTH || facing == BlockFace.EAST || facing == BlockFace.SOUTH || facing == BlockFace.WEST || facing == BlockFace.UP || facing == BlockFace.DOWN)) {
|
||||
messageBridge.message(player, "stack-unclearDirection", facing.toString().toLowerCase().replace('_', '-'));
|
||||
return;
|
||||
}
|
||||
Vector shift = new Vector(0, 0, 0);
|
||||
if(facing == BlockFace.SOUTH) {
|
||||
shift = shift.setZ(-selection.getLength() - gap);
|
||||
} else if(facing == BlockFace.WEST) {
|
||||
shift = shift.setX(selection.getWidth() + gap);
|
||||
} else if(facing == BlockFace.NORTH) {
|
||||
shift = shift.setZ(selection.getLength() + gap);
|
||||
} else if(facing == BlockFace.EAST) {
|
||||
shift = shift.setX(-selection.getWidth() - gap);
|
||||
} else if(facing == BlockFace.DOWN) {
|
||||
shift = shift.setY(-selection.getHeight() - gap);
|
||||
} else if(facing == BlockFace.UP) {
|
||||
shift = shift.setY(selection.getHeight() + gap);
|
||||
}
|
||||
AreaShop.debug(" calculated shift vector: " + shift + ", with facing=" + facing);
|
||||
// Create regions and add them to AreaShop
|
||||
final String nameTemplate = args[3];
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.plugin = plugin;
|
||||
this.worldEditInterface = worldEditInterface;
|
||||
this.worldGuardInterface = worldGuardInterface;
|
||||
this.regionFactory = regionFactory;
|
||||
this.fileManager = fileManager;
|
||||
|
||||
}
|
||||
|
||||
final int regionsPerTick = plugin.getConfig().getInt("adding.regionsPerTick");
|
||||
final boolean rentRegions = "rent".equalsIgnoreCase(args[4]);
|
||||
final int amount = tempAmount;
|
||||
final RegionGroup finalGroup = group;
|
||||
final Vector finalShift = shift;
|
||||
String type;
|
||||
if(rentRegions) {
|
||||
type = "rent";
|
||||
} else {
|
||||
type = "buy";
|
||||
}
|
||||
Message groupsMessage = Message.empty();
|
||||
if(group != null) {
|
||||
groupsMessage = Message.fromKey("stack-addToGroup").replacements(group.getName());
|
||||
}
|
||||
messageBridge.message(player, "stack-accepted", amount, type, gap, nameTemplate, groupsMessage);
|
||||
messageBridge.message(player, "stack-addStart", amount, regionsPerTick * 20);
|
||||
@NotNull
|
||||
private static Vector calculateShift(BlockFace facing, WorldEditSelection selection, int gap) {
|
||||
Vector shift = new Vector(0, 0, 0);
|
||||
if (facing == BlockFace.SOUTH) {
|
||||
shift = shift.setZ(-selection.getLength() - gap);
|
||||
} else if (facing == BlockFace.WEST) {
|
||||
shift = shift.setX(selection.getWidth() + gap);
|
||||
} else if (facing == BlockFace.NORTH) {
|
||||
shift = shift.setZ(selection.getLength() + gap);
|
||||
} else if (facing == BlockFace.EAST) {
|
||||
shift = shift.setX(-selection.getWidth() - gap);
|
||||
} else if (facing == BlockFace.DOWN) {
|
||||
shift = shift.setY(-selection.getHeight() - gap);
|
||||
} else if (facing == BlockFace.UP) {
|
||||
shift = shift.setY(selection.getHeight() + gap);
|
||||
}
|
||||
return shift;
|
||||
}
|
||||
|
||||
Location minimumLocation = selection.getMinimumLocation();
|
||||
Vector minimumVector = new Vector(minimumLocation.getX(), minimumLocation.getY(), minimumLocation.getZ());
|
||||
Location maximumLocation = selection.getMaximumLocation();
|
||||
Vector maximumVector = new Vector(maximumLocation.getX(), maximumLocation.getY(), maximumLocation.getZ());
|
||||
new BukkitRunnable() {
|
||||
private int current = -1;
|
||||
private final RegionManager manager = AreaShop.getInstance().getRegionManager(selection.getWorld());
|
||||
private int counter = 1;
|
||||
private int tooLow = 0;
|
||||
private int tooHigh = 0;
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.stack")) {
|
||||
return "help-stack";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for(int i = 0; i < regionsPerTick; i++) {
|
||||
current++;
|
||||
if(current < amount) {
|
||||
// Create the region name
|
||||
String regionName = countToName(nameTemplate, counter);
|
||||
while(manager.getRegion(regionName) != null || AreaShop.getInstance().getFileManager().getRegion(regionName) != null) {
|
||||
counter++;
|
||||
regionName = countToName(nameTemplate, counter);
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Add the region to WorldGuard (at startposition shifted by the number of this region times the blocks it should shift)
|
||||
Vector minimum = minimumVector.clone().add(finalShift.clone().multiply(current));
|
||||
Vector maximum = maximumVector.clone().add(finalShift.clone().multiply(current));
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("stack")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.required(KEY_AMOUNT, IntegerParser.integerParser(0))
|
||||
.required(KEY_GAP, IntegerParser.integerParser(0))
|
||||
.required(KEY_NAME, StringParser.stringParser())
|
||||
.required(KEY_TYPE, EnumParser.enumParser(GeneralRegion.RegionType.class))
|
||||
.flag(FLAG_GROUP)
|
||||
.handler(this::handleCommand);
|
||||
|
||||
// Check for out of bounds
|
||||
if(minimum.getBlockY() < 0) {
|
||||
tooLow++;
|
||||
continue;
|
||||
} else if(maximum.getBlockY() > 256) {
|
||||
tooHigh++;
|
||||
continue;
|
||||
}
|
||||
ProtectedCuboidRegion region = worldGuardInterface.createCuboidRegion(regionName, minimum,maximum);
|
||||
manager.addRegion(region);
|
||||
}
|
||||
|
||||
// Add the region to AreaShop
|
||||
GeneralRegion newRegion;
|
||||
if(rentRegions) {
|
||||
newRegion = regionFactory.createRentRegion(regionName, selection.getWorld());
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("stack");
|
||||
}
|
||||
|
||||
} else {
|
||||
newRegion = regionFactory.createBuyRegion(regionName, selection.getWorld());
|
||||
}
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player player = context.sender().sender();
|
||||
if (!player.hasPermission("areashop.stack")) {
|
||||
throw new AreaShopCommandException("stack-noPermission");
|
||||
}
|
||||
int amount = context.get(KEY_AMOUNT);
|
||||
int gap = context.get(KEY_GAP);
|
||||
String name = context.get(KEY_NAME);
|
||||
GeneralRegion.RegionType regionType = context.get(KEY_TYPE);
|
||||
Optional<String> optionalGroup = context.flags().getValue(FLAG_GROUP);
|
||||
// Get WorldEdit selection
|
||||
final WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if (selection == null) {
|
||||
this.messageBridge.message(player, "stack-noSelection");
|
||||
return;
|
||||
}
|
||||
// Get or create group
|
||||
RegionGroup group = null;
|
||||
if (optionalGroup.isPresent()) {
|
||||
String groupName = optionalGroup.get();
|
||||
group = fileManager.getGroup(groupName);
|
||||
if (group == null) {
|
||||
group = regionFactory.createRegionGroup(groupName);
|
||||
fileManager.addGroup(group);
|
||||
}
|
||||
}
|
||||
// Get facing of the player (must be clearly one of the four directions to make sure it is no mistake)
|
||||
BlockFace facing = Utils.yawToFacing(player.getLocation().getYaw());
|
||||
if (player.getLocation().getPitch() > 45) {
|
||||
facing = BlockFace.DOWN;
|
||||
} else if (player.getLocation().getPitch() < -45) {
|
||||
facing = BlockFace.UP;
|
||||
}
|
||||
if (!(facing == BlockFace.NORTH || facing == BlockFace.EAST || facing == BlockFace.SOUTH || facing == BlockFace.WEST || facing == BlockFace.UP || facing == BlockFace.DOWN)) {
|
||||
this.messageBridge.message(player,
|
||||
"stack-unclearDirection",
|
||||
facing.toString().toLowerCase().replace('_', '-'));
|
||||
return;
|
||||
}
|
||||
Vector shift = calculateShift(facing, selection, gap);
|
||||
BukkitRunnable task = stackTask(player, name, amount, selection, regionType, shift, group);
|
||||
task.runTaskTimer(plugin, 1, 1);
|
||||
}
|
||||
|
||||
if(finalGroup != null) {
|
||||
finalGroup.addMember(newRegion);
|
||||
}
|
||||
AddingRegionEvent event = fileManager.addRegion(newRegion);
|
||||
if (event.isCancelled()) {
|
||||
messageBridge.message(player, "general-cancelled", event.getReason());
|
||||
continue;
|
||||
}
|
||||
newRegion.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||
newRegion.update();
|
||||
}
|
||||
}
|
||||
if(current >= amount) {
|
||||
if(player.isOnline()) {
|
||||
int added = amount - tooLow - tooHigh;
|
||||
Message wrong = Message.empty();
|
||||
if(tooHigh > 0) {
|
||||
wrong.append(Message.fromKey("stack-tooHigh").replacements(tooHigh));
|
||||
}
|
||||
if(tooLow > 0) {
|
||||
wrong.append(Message.fromKey("stack-tooLow").replacements(tooLow));
|
||||
}
|
||||
messageBridge.message(player, "stack-addComplete", added, wrong);
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 1, 1);
|
||||
}
|
||||
private BukkitRunnable stackTask(
|
||||
@Nonnull Player player,
|
||||
@Nonnull String name,
|
||||
int amount,
|
||||
@Nonnull WorldEditSelection selection,
|
||||
GeneralRegion.RegionType regionType,
|
||||
@Nonnull Vector shift,
|
||||
@Nullable RegionGroup group
|
||||
) {
|
||||
final int regionsPerTick = plugin.getConfig().getInt("adding.regionsPerTick");
|
||||
|
||||
/**
|
||||
* Build a name from a count, with the right length.
|
||||
* @param template Template to put the name in (# to put the count there, otherwise count is appended)
|
||||
* @param count Number to use
|
||||
* @return name with prepended 0's
|
||||
*/
|
||||
private String countToName(String template, int count) {
|
||||
StringBuilder counterName = new StringBuilder().append(count);
|
||||
int minimumLength = plugin.getConfig().getInt("stackRegionNumberLength");
|
||||
while(counterName.length() < minimumLength) {
|
||||
counterName.insert(0, "0");
|
||||
}
|
||||
Location minimumLocation = selection.getMinimumLocation();
|
||||
Vector minimumVector = new Vector(minimumLocation.getX(), minimumLocation.getY(), minimumLocation.getZ());
|
||||
Location maximumLocation = selection.getMaximumLocation();
|
||||
Vector maximumVector = new Vector(maximumLocation.getX(), maximumLocation.getY(), maximumLocation.getZ());
|
||||
return new BukkitRunnable() {
|
||||
private final RegionManager manager = worldGuardInterface.getRegionManager(selection.getWorld());
|
||||
private int current = -1;
|
||||
private int counter = 1;
|
||||
private int tooLow = 0;
|
||||
private int tooHigh = 0;
|
||||
|
||||
if(template.contains("#")) {
|
||||
return template.replace("#", counterName);
|
||||
} else {
|
||||
return template + counterName;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < regionsPerTick; i++) {
|
||||
current++;
|
||||
if (current >= amount) {
|
||||
continue;
|
||||
}
|
||||
// Create the region name
|
||||
String regionName = countToName(name, counter);
|
||||
while (manager.getRegion(regionName) != null || fileManager.getRegion(regionName) != null) {
|
||||
counter++;
|
||||
regionName = countToName(name, counter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if(toComplete == 5) {
|
||||
result.add("rent");
|
||||
result.add("buy");
|
||||
} else if(toComplete == 6) {
|
||||
result.addAll(fileManager.getGroupNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Add the region to WorldGuard (at startposition shifted by the number of this region times the blocks it should shift)
|
||||
Vector minimum = minimumVector.clone().add(shift.clone().multiply(current));
|
||||
Vector maximum = maximumVector.clone().add(shift.clone().multiply(current));
|
||||
|
||||
// Check for out of bounds
|
||||
if (minimum.getBlockY() < 0) {
|
||||
tooLow++;
|
||||
continue;
|
||||
} else if (maximum.getBlockY() > 256) {
|
||||
tooHigh++;
|
||||
continue;
|
||||
}
|
||||
ProtectedCuboidRegion region = worldGuardInterface.createCuboidRegion(regionName, minimum, maximum);
|
||||
manager.addRegion(region);
|
||||
|
||||
// Add the region to AreaShop
|
||||
GeneralRegion newRegion;
|
||||
if (regionType == GeneralRegion.RegionType.BUY) {
|
||||
newRegion = regionFactory.createRentRegion(regionName, selection.getWorld());
|
||||
} else {
|
||||
newRegion = regionFactory.createBuyRegion(regionName, selection.getWorld());
|
||||
}
|
||||
|
||||
if (group != null) {
|
||||
group.addMember(newRegion);
|
||||
}
|
||||
AddingRegionEvent event = fileManager.addRegion(newRegion);
|
||||
if (event.isCancelled()) {
|
||||
messageBridge.message(player, "general-cancelled", event.getReason());
|
||||
continue;
|
||||
}
|
||||
newRegion.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
|
||||
newRegion.update();
|
||||
}
|
||||
if (current >= amount) {
|
||||
if (player.isOnline()) {
|
||||
int added = amount - tooLow - tooHigh;
|
||||
Message wrong = Message.empty();
|
||||
if (tooHigh > 0) {
|
||||
wrong.append(Message.fromKey("stack-tooHigh").replacements(tooHigh));
|
||||
}
|
||||
if (tooLow > 0) {
|
||||
wrong.append(Message.fromKey("stack-tooLow").replacements(tooLow));
|
||||
}
|
||||
messageBridge.message(player, "stack-addComplete", added, wrong);
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a name from a count, with the right length.
|
||||
*
|
||||
* @param template Template to put the name in (# to put the count there, otherwise count is appended)
|
||||
* @param count Number to use
|
||||
* @return name with prepended 0's
|
||||
*/
|
||||
private String countToName(String template, int count) {
|
||||
StringBuilder counterName = new StringBuilder().append(count);
|
||||
int minimumLength = plugin.getConfig().getInt("stackRegionNumberLength");
|
||||
while (counterName.length() < minimumLength) {
|
||||
counterName.insert(0, "0");
|
||||
}
|
||||
|
||||
if (template.contains("#")) {
|
||||
return template.replace("#", counterName);
|
||||
} else {
|
||||
return template + counterName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.BuyRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class StopResellCommand extends AreashopCommandBean {
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
|
||||
private final CommandFlag<BuyRegion> regionFlag;
|
||||
|
||||
@Inject
|
||||
public StopResellCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
ParserDescriptor<CommandSource<?>, BuyRegion> regionParser =
|
||||
ParserDescriptor.of(new BuyRegionParser<>(fileManager, this::suggestBuyRegions), BuyRegion.class);
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
this.regionFlag = CommandFlag.<CommandSource<?>>builder("region")
|
||||
.withComponent(regionParser)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(CommandSender target) {
|
||||
if (target.hasPermission("areashop.stopresellall") || target.hasPermission("areashop.stopresell")) {
|
||||
return "help-stopResell";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("stopresell")
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("stopresell");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.stopresell") && !sender.hasPermission("areashop.stopresellall")) {
|
||||
this.messageBridge.message(sender, "stopresell-noPermissionOther");
|
||||
return;
|
||||
}
|
||||
|
||||
BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, sender, this.regionFlag);
|
||||
if (!buy.isInResellingMode()) {
|
||||
this.messageBridge.message(sender, "stopresell-notResell", buy);
|
||||
return;
|
||||
}
|
||||
if (sender.hasPermission("areashop.stopresellall")) {
|
||||
buy.disableReselling();
|
||||
buy.update();
|
||||
this.messageBridge.message(sender, "stopresell-success", buy);
|
||||
} else if (sender.hasPermission("areashop.stopresell") && sender instanceof Player player) {
|
||||
if (buy.isOwner(player)) {
|
||||
buy.disableReselling();
|
||||
buy.update();
|
||||
this.messageBridge.message(sender, "stopresell-success", buy);
|
||||
} else {
|
||||
this.messageBridge.message(sender, "stopresell-noPermissionOther", buy);
|
||||
}
|
||||
} else {
|
||||
this.messageBridge.message(sender, "stopresell-noPermission", buy);
|
||||
}
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestBuyRegions(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
List<Suggestion> suggestions = this.fileManager.getBuysRef().stream()
|
||||
.filter(region -> region.isSold() && region.isInResellingMode())
|
||||
.map(GeneralRegion::getName)
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class StopresellCommand extends CommandAreaShop {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop stopresell";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.stopresellall") || target.hasPermission("areashop.stopresell")) {
|
||||
return "help-stopResell";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.stopresell") && !sender.hasPermission("areashop.stopresellall")) {
|
||||
messageBridge.message(sender, "stopresell-noPermissionOther");
|
||||
return;
|
||||
}
|
||||
|
||||
BuyRegion buy;
|
||||
if(args.length <= 1) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<BuyRegion> regions = Utils.getImportantBuyRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
buy = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
buy = fileManager.getBuy(args[1]);
|
||||
if(buy == null) {
|
||||
messageBridge.message(sender, "stopresell-notRegistered", args[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(buy == null) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
}
|
||||
if(!buy.isInResellingMode()) {
|
||||
messageBridge.message(sender, "stopresell-notResell", buy);
|
||||
return;
|
||||
}
|
||||
if(sender.hasPermission("areashop.stopresellall")) {
|
||||
buy.disableReselling();
|
||||
buy.update();
|
||||
messageBridge.message(sender, "stopresell-success", buy);
|
||||
} else if(sender.hasPermission("areashop.stopresell") && sender instanceof Player) {
|
||||
if(buy.isOwner((Player)sender)) {
|
||||
buy.disableReselling();
|
||||
buy.update();
|
||||
messageBridge.message(sender, "stopresell-success", buy);
|
||||
} else {
|
||||
messageBridge.message(sender, "stopresell-noPermissionOther", buy);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "stopresell-noPermission", buy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(BuyRegion region : fileManager.getBuysRef()) {
|
||||
if(region.isSold() && region.isInResellingMode()) {
|
||||
result.add(region.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,92 +1,96 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class TeleportCommand extends CommandAreaShop {
|
||||
public class TeleportCommand extends AreashopCommandBean {
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop tp";
|
||||
}
|
||||
private static final CloudKey<GeneralRegion> KEY_REGION = CloudKey.of("region", GeneralRegion.class);
|
||||
private static final CommandFlag<Void> KEY_TO_SIGN = CommandFlag.builder("to-sign").build();
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.teleportall") || target.hasPermission("areashop.teleport")) {
|
||||
return "help-teleport";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private final IFileManager fileManager;
|
||||
|
||||
/**
|
||||
* Check if a person can teleport to the region (assuming he is not teleporting to a sign).
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can teleport to it, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if(!(person instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player)person;
|
||||
return player.hasPermission("areashop.teleportall")
|
||||
|| region.isOwner(player) && player.hasPermission("areashop.teleport")
|
||||
|| region.isAvailable() && player.hasPermission("areashop.teleportavailable")
|
||||
|| region.getFriendsFeature().getFriends().contains(player.getUniqueId()) && player.hasPermission("areashop.teleportfriend");
|
||||
}
|
||||
@Inject
|
||||
public TeleportCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.teleport") && !sender.hasPermission("areashop.teleportall") && !sender.hasPermission("areashop.teleportavailable") && !sender.hasPermission("areashop.teleportavailablesign") && !sender.hasPermission("areashop.teleportsign") && !sender.hasPermission("areashop.teleportsignall") && !sender.hasPermission("areashop.teleportfriend") && !sender.hasPermission("teleportfriendsign")) {
|
||||
messageBridge.message(sender, "teleport-noPermission");
|
||||
return;
|
||||
}
|
||||
if(!(sender instanceof Player)) {
|
||||
messageBridge.message(sender, "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
if(args.length <= 1 || args[1] == null) {
|
||||
messageBridge.message(sender, "teleport-help");
|
||||
return;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
GeneralRegion region = fileManager.getRegion(args[1]);
|
||||
if(region == null) {
|
||||
messageBridge.message(player, "teleport-noRentOrBuy", args[1]);
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Check if a person can teleport to the region (assuming he is not teleporting to a sign).
|
||||
*
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can teleport to it, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if (!(person instanceof Player player)) {
|
||||
return false;
|
||||
}
|
||||
return player.hasPermission("areashop.teleportall")
|
||||
|| region.isOwner(player) && player.hasPermission("areashop.teleport")
|
||||
|| region.isAvailable() && player.hasPermission("areashop.teleportavailable")
|
||||
|| region.getFriendsFeature().getFriends().contains(player.getUniqueId()) && player.hasPermission(
|
||||
"areashop.teleportfriend");
|
||||
}
|
||||
|
||||
boolean toSign = args.length >= 3 && (
|
||||
args[2].equalsIgnoreCase("sign")
|
||||
|| args[2].equalsIgnoreCase("yes")
|
||||
|| args[2].equalsIgnoreCase("true")
|
||||
);
|
||||
region.getTeleportFeature().teleportPlayer(player, toSign);
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.teleportall") || target.hasPermission("areashop.teleport")) {
|
||||
return "help-teleport";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
result.addAll(fileManager.getRegionNames());
|
||||
} else if(toComplete == 3) {
|
||||
result.add("sign");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("tp", "teleport")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager))
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("teleport", "tp");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player player = context.sender().sender();
|
||||
if (!player.hasPermission("areashop.teleport") && !player.hasPermission("areashop.teleportall") && !player.hasPermission(
|
||||
"areashop.teleportavailable") && !player.hasPermission("areashop.teleportavailablesign") && !player.hasPermission(
|
||||
"areashop.teleportsign") && !player.hasPermission("areashop.teleportsignall") && !player.hasPermission(
|
||||
"areashop.teleportfriend") && !player.hasPermission("teleportfriendsign")) {
|
||||
this.messageBridge.message(player, "teleport-noPermission");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region = context.get(KEY_REGION);
|
||||
boolean toSign = context.flags().contains(KEY_TO_SIGN);
|
||||
region.getTeleportFeature().teleportPlayer(player, toSign);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.features.homeaccess.HomeAccessFeature;
|
||||
import me.wiefferink.areashop.features.homeaccess.HomeAccessType;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.component.CommandComponent;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.description.Description;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.EnumParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Singleton
|
||||
public final class ToggleHomeCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<HomeAccessType> KEY_ACCESS_TYPE = CloudKey.of("accessType", HomeAccessType.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
|
||||
@Inject
|
||||
public ToggleHomeCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
this.regionFlag = CommandFlag.<CommandSource<?>>builder("region")
|
||||
.withComponent(
|
||||
CommandComponent.<CommandSource<?>, GeneralRegion>builder()
|
||||
.name("region")
|
||||
.description(Description.EMPTY)
|
||||
.valueType(GeneralRegion.class)
|
||||
.parser(GeneralRegionParser.generalRegionParser(fileManager))
|
||||
.suggestionProvider(this::suggestRegions)
|
||||
.build()
|
||||
).build();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (!target.hasPermission("sethomecontrol.control")) {
|
||||
return null;
|
||||
}
|
||||
return "help-togglehome";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("togglehome")
|
||||
.required(KEY_ACCESS_TYPE, EnumParser.enumParser(HomeAccessType.class))
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("togglehome");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.togglehome")) {
|
||||
throw new AreaShopCommandException("togglehome-noPermission");
|
||||
}
|
||||
final HomeAccessType accessType = context.get(KEY_ACCESS_TYPE);
|
||||
final GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
if (!(sender instanceof Player) && !sender.hasPermission("sethome.control.other")) {
|
||||
return;
|
||||
}
|
||||
if (sender instanceof Player player && !region.isOwner(player)) {
|
||||
throw new AreaShopCommandException("togglehome-noPermission");
|
||||
}
|
||||
region.getOrCreateFeature(HomeAccessFeature.class).homeAccessType(accessType);
|
||||
this.messageBridge.message(sender, "togglehome-success", accessType.name());
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestRegions(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
CommandSender sender = context.sender().sender();
|
||||
Stream<GeneralRegion> regions;
|
||||
if (sender.hasPermission("sethome.control.other")) {
|
||||
regions = this.fileManager.getRegionsRef().stream();
|
||||
} else if (!sender.hasPermission("sethome.control.other") && sender instanceof Player player) {
|
||||
regions = this.fileManager.getRegionsRef().stream()
|
||||
.filter(region -> region.isOwner(player.getUniqueId()));
|
||||
} else {
|
||||
regions = Stream.empty();
|
||||
}
|
||||
List<Suggestion> suggestions = regions.map(GeneralRegion::getName)
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.GeneralRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.OfflinePlayerParser;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class TransferCommand extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<String> KEY_PLAYER = CloudKey.of("player", String.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final IFileManager fileManager;
|
||||
private final CommandFlag<GeneralRegion> regionFlag;
|
||||
private final OfflinePlayerHelper offlinePlayerHelper;
|
||||
|
||||
@Inject
|
||||
public TransferCommand(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull OfflinePlayerHelper offlinePlayerHelper
|
||||
) {
|
||||
ParserDescriptor<PlayerCommandSource, GeneralRegion> regionParser =
|
||||
ParserDescriptor.of(new GeneralRegionParser<>(fileManager, this::suggestRegions), GeneralRegion.class);
|
||||
this.messageBridge = messageBridge;
|
||||
this.fileManager = fileManager;
|
||||
this.regionFlag = CommandFlag.<PlayerCommandSource>builder("region")
|
||||
.withComponent(regionParser)
|
||||
.build();
|
||||
this.offlinePlayerHelper = offlinePlayerHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (!target.hasPermission("areashop.transfer")) {
|
||||
return null;
|
||||
}
|
||||
return "help-transfer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("transfer")
|
||||
.senderType(PlayerCommandSource.class)
|
||||
.required(KEY_PLAYER, OfflinePlayerParser.parser())
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("transfer");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context) {
|
||||
Player sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.transfer")) {
|
||||
throw new AreaShopCommandException("transfer-noPermission");
|
||||
}
|
||||
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
|
||||
if (!region.isTransferEnabled()) {
|
||||
throw new AreaShopCommandException("transfer-disabled");
|
||||
}
|
||||
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
|
||||
.whenComplete((offlinePlayer, exception) -> {
|
||||
if (exception != null) {
|
||||
sender.sendMessage("failed to lookup offline player!");
|
||||
exception.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (!offlinePlayer.hasPlayedBefore() &&!offlinePlayer.isOnline()) {
|
||||
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
|
||||
return;
|
||||
}
|
||||
performTransfer(sender, offlinePlayer, region);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void performTransfer(
|
||||
@Nonnull Player sender,
|
||||
@Nonnull OfflinePlayer targetPlayer,
|
||||
@Nonnull GeneralRegion region
|
||||
) {
|
||||
String targetPlayerName = targetPlayer.getName();
|
||||
if (Objects.equals(sender, targetPlayer)) {
|
||||
throw new AreaShopCommandException("transfer-transferSelf");
|
||||
}
|
||||
if (!targetPlayer.hasPlayedBefore() && !targetPlayer.isOnline()) {
|
||||
// Unknown player
|
||||
throw new AreaShopCommandException("transfer-noPlayer", targetPlayerName);
|
||||
}
|
||||
if (region.isLandlord(sender.getUniqueId())) {
|
||||
// Transfer ownership if same as landlord
|
||||
region.getFriendsFeature().deleteFriend(region.getOwner(), null);
|
||||
region.setOwner(targetPlayer.getUniqueId());
|
||||
region.setLandlord(targetPlayer.getUniqueId(), targetPlayerName);
|
||||
this.messageBridge.message(sender, "transfer-transferred-owner", targetPlayerName, region);
|
||||
this.messageBridge.messagePersistent(targetPlayer, "transfer-transferred-owner", targetPlayerName, region);
|
||||
region.update();
|
||||
region.saveRequired();
|
||||
return;
|
||||
}
|
||||
if (!region.isOwner(sender.getUniqueId())) {
|
||||
// Cannot transfer tenant if we aren't the current tenant
|
||||
throw new AreaShopCommandException("transfer-notCurrentTenant");
|
||||
}
|
||||
region.getFriendsFeature().deleteFriend(region.getOwner(), null);
|
||||
// Swap the owner/occupant (renter or buyer)
|
||||
region.setOwner(targetPlayer.getUniqueId());
|
||||
|
||||
this.messageBridge.message(sender, "transfer-transferred-tenant", targetPlayerName, region);
|
||||
this.messageBridge.messagePersistent(targetPlayer, "transfer-transferred-tenant", targetPlayerName, region);
|
||||
region.update();
|
||||
region.saveRequired();
|
||||
}
|
||||
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestRegions(
|
||||
@Nonnull CommandContext<PlayerCommandSource> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
UUID uuid = context.sender().sender().getUniqueId();
|
||||
List<Suggestion> suggestions = this.fileManager.getRegions()
|
||||
.stream()
|
||||
.filter(region -> region.isOwner(uuid) || region.isLandlord(uuid))
|
||||
.map(GeneralRegion::getName)
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,106 +1,114 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.commands.util.AreaShopCommandException;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.RentRegionParser;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class UnrentCommand extends CommandAreaShop {
|
||||
public class UnrentCommand extends AreashopCommandBean {
|
||||
private final IFileManager fileManager;
|
||||
private final CommandFlag<RentRegion> regionFlag;
|
||||
|
||||
@Inject
|
||||
private MessageBridge messageBridge;
|
||||
@Inject
|
||||
private IFileManager fileManager;
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop unrent";
|
||||
}
|
||||
@Inject
|
||||
public UnrentCommand(@Nonnull IFileManager fileManager) {
|
||||
ParserDescriptor<CommandSource<?>, RentRegion> regionParser =
|
||||
ParserDescriptor.of(new RentRegionParser<>(fileManager, this::suggestRegions), RentRegion.class);
|
||||
this.fileManager = fileManager;
|
||||
this.regionFlag = CommandFlag.<CommandSource<?>>builder("region")
|
||||
.withComponent(regionParser)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.unrent") || target.hasPermission("areashop.unrentown")) {
|
||||
return "help-unrent";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Check if a person can unrent the region.
|
||||
*
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can unrent it, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if (person.hasPermission("areashop.unrent")) {
|
||||
return true;
|
||||
}
|
||||
if (person instanceof Player player) {
|
||||
return region.isOwner(player) && person.hasPermission("areashop.unrentown");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a person can unrent the region.
|
||||
* @param person The person to check
|
||||
* @param region The region to check for
|
||||
* @return true if the person can unrent it, otherwise false
|
||||
*/
|
||||
public static boolean canUse(CommandSender person, GeneralRegion region) {
|
||||
if(person.hasPermission("areashop.unrent")) {
|
||||
return true;
|
||||
}
|
||||
if(person instanceof Player) {
|
||||
Player player = (Player)person;
|
||||
return region.isOwner(player) && person.hasPermission("areashop.unrentown");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String getHelpKey(CommandSender target) {
|
||||
if (target.hasPermission("areashop.unrent") || target.hasPermission("areashop.unrentown")) {
|
||||
return "help-unrent";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("areashop.unrent") && !sender.hasPermission("areashop.unrentown")) {
|
||||
messageBridge.message(sender, "unrent-noPermission");
|
||||
return;
|
||||
}
|
||||
RentRegion rent;
|
||||
if(args.length <= 1) {
|
||||
if(sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<RentRegion> regions = Utils.getImportantRentRegions(((Player)sender).getLocation());
|
||||
if(regions.isEmpty()) {
|
||||
messageBridge.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if(regions.size() > 1) {
|
||||
messageBridge.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
rent = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
messageBridge.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
rent = fileManager.getRent(args[1]);
|
||||
}
|
||||
if(rent == null) {
|
||||
messageBridge.message(sender, "unrent-notRegistered");
|
||||
return;
|
||||
}
|
||||
if(!rent.isRented()) {
|
||||
messageBridge.message(sender, "unrent-notRented", rent);
|
||||
return;
|
||||
}
|
||||
rent.unRent(true, sender);
|
||||
}
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if(toComplete == 2) {
|
||||
for(RentRegion region : fileManager.getRentsRef()) {
|
||||
if(region.isRented()) {
|
||||
result.add(region.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("unrent")
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("unrent");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.unrent") && !sender.hasPermission("areashop.unrentown")) {
|
||||
throw new AreaShopCommandException("unrent-noPermission");
|
||||
}
|
||||
RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, sender, this.regionFlag);
|
||||
if (!rent.isRented()) {
|
||||
throw new AreaShopCommandException("unrent-notRented", rent);
|
||||
}
|
||||
rent.unRent(true, sender);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestRegions(
|
||||
@Nonnull CommandContext<CommandSource<?>> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
List<Suggestion> suggestions = this.fileManager.getRentsRef().stream()
|
||||
.filter(RentRegion::isRented)
|
||||
.map(GeneralRegion::getName)
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class AcceptedValuesParser<C> implements ArgumentParser<C, String>, SuggestionProvider<C> {
|
||||
|
||||
private final Supplier< Collection<String>> valuesProvider;
|
||||
private final boolean caseSensitive;
|
||||
|
||||
private final String failureMessageKey;
|
||||
|
||||
private AcceptedValuesParser(
|
||||
@Nonnull Supplier< Collection<String>> valuesProvider,
|
||||
@Nonnull String failureMessageKey,
|
||||
boolean caseSensitive
|
||||
|
||||
) {
|
||||
this.valuesProvider = valuesProvider;
|
||||
this.failureMessageKey = failureMessageKey;
|
||||
this.caseSensitive = caseSensitive;
|
||||
}
|
||||
|
||||
public static <C> AcceptedValuesParser<C> ofConstant(
|
||||
@Nonnull Collection<String> acceptedValues,
|
||||
@Nonnull String failureMessageKey,
|
||||
boolean caseSensitive
|
||||
) {
|
||||
Collection<String> copy = List.copyOf(acceptedValues);
|
||||
return new AcceptedValuesParser<>(() -> copy, failureMessageKey, caseSensitive);
|
||||
}
|
||||
|
||||
public static <C> AcceptedValuesParser<C> of(
|
||||
@Nonnull Supplier< Collection<String>> supplier,
|
||||
@Nonnull String failureMessageKey,
|
||||
boolean caseSensitive
|
||||
) {
|
||||
return new AcceptedValuesParser<>(supplier, failureMessageKey, caseSensitive);
|
||||
}
|
||||
|
||||
public static <C> AcceptedValuesParser<C> ofCached(
|
||||
@Nonnull Supplier< Collection<String>> supplier,
|
||||
@Nonnull String failureMessageKey,
|
||||
boolean caseSensitive
|
||||
) {
|
||||
return ofConstant(supplier.get(), failureMessageKey, caseSensitive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull ArgumentParseResult<String> parse(@Nonnull CommandContext<C> commandContext,
|
||||
@Nonnull CommandInput commandInput) {
|
||||
String toTest;
|
||||
if (this.caseSensitive) {
|
||||
toTest = commandInput.peekString().toLowerCase(Locale.ENGLISH);
|
||||
} else {
|
||||
toTest = commandInput.peekString();
|
||||
}
|
||||
Collection<String> acceptedValues = this.valuesProvider.get();
|
||||
if (acceptedValues.contains(toTest)) {
|
||||
return ArgumentParseResult.success(toTest);
|
||||
}
|
||||
return ArgumentParseResult.failure(new AreaShopCommandException(this.failureMessageKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull CompletableFuture<Iterable<Suggestion>> suggestionsFuture(
|
||||
@Nonnull CommandContext<C> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
Iterable<Suggestion> suggestions = this.valuesProvider.get().stream()
|
||||
.filter(s -> s.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class AreaShopCommandException extends RuntimeException {
|
||||
|
||||
private static final Object[] EMPTY = new Object[0];
|
||||
|
||||
private final String messageKey;
|
||||
private final Object[] replacements;
|
||||
|
||||
public AreaShopCommandException(@Nonnull String messageKey, @Nullable Object... replacements) {
|
||||
this.messageKey = messageKey;
|
||||
this.replacements = replacements == null ? EMPTY : replacements;
|
||||
}
|
||||
|
||||
public String messageKey() {
|
||||
return this.messageKey;
|
||||
}
|
||||
|
||||
public Object[] replacements() {
|
||||
return this.replacements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return this.messageKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandBean;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.processors.confirmation.ConfirmationManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* An extension of {@link CommandBean} which does extra pre-processing of the commands.
|
||||
* Adapted from <a href="https://github.com/Incendo/kitchensink">KitchenSink</a>
|
||||
*/
|
||||
public abstract class AreashopCommandBean extends CommandBean<CommandSource<?>> implements HelpProvider {
|
||||
|
||||
private boolean requireConfirmation;
|
||||
|
||||
protected void withConfirmation() {
|
||||
this.requireConfirmation = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final @Nonnull Command.Builder<? extends CommandSource<?>> configure(
|
||||
final @Nonnull Command.Builder<CommandSource<?>> builder
|
||||
) {
|
||||
return this.configureCommand(builder)
|
||||
.meta(CloudKey.of("bukkit_description", String.class), this.stringDescription())
|
||||
.meta(ConfirmationManager.META_CONFIRMATION_REQUIRED, this.requireConfirmation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a simple string description of this command.
|
||||
*
|
||||
* <p>This is primarily used in the platform-native help menus.</p>
|
||||
*
|
||||
* @return command description
|
||||
*/
|
||||
public abstract String stringDescription();
|
||||
|
||||
/**
|
||||
* Configures the command and returns the updated builder.
|
||||
*
|
||||
* @param builder builder to configure
|
||||
* @return the updated builder
|
||||
*/
|
||||
protected abstract @Nonnull Command.Builder<? extends CommandSource<?>> configureCommand(
|
||||
@Nonnull Command.Builder<CommandSource<?>> builder
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.AddCommand;
|
||||
import me.wiefferink.areashop.commands.AddFriendCommand;
|
||||
import me.wiefferink.areashop.commands.AddSignCommand;
|
||||
import me.wiefferink.areashop.commands.BuyCommand;
|
||||
import me.wiefferink.areashop.commands.DelCommand;
|
||||
import me.wiefferink.areashop.commands.DelFriendCommand;
|
||||
import me.wiefferink.areashop.commands.DelSignCommand;
|
||||
import me.wiefferink.areashop.commands.FindCommand;
|
||||
import me.wiefferink.areashop.commands.GroupAddCommand;
|
||||
import me.wiefferink.areashop.commands.GroupDelCommand;
|
||||
import me.wiefferink.areashop.commands.GroupInfoCommand;
|
||||
import me.wiefferink.areashop.commands.GroupListCommand;
|
||||
import me.wiefferink.areashop.commands.HelpCommand;
|
||||
import me.wiefferink.areashop.commands.InfoBaseCommand;
|
||||
import me.wiefferink.areashop.commands.InfoCommand;
|
||||
import me.wiefferink.areashop.commands.InfoPlayerCommand;
|
||||
import me.wiefferink.areashop.commands.InfoRegionCommand;
|
||||
import me.wiefferink.areashop.commands.LinkSignsCommand;
|
||||
import me.wiefferink.areashop.commands.MeCommand;
|
||||
import me.wiefferink.areashop.commands.MessageCommand;
|
||||
import me.wiefferink.areashop.commands.QuickBuyCommand;
|
||||
import me.wiefferink.areashop.commands.QuickDeleteCommand;
|
||||
import me.wiefferink.areashop.commands.QuickRentCommand;
|
||||
import me.wiefferink.areashop.commands.ReloadCommand;
|
||||
import me.wiefferink.areashop.commands.RentCommand;
|
||||
import me.wiefferink.areashop.commands.ResellCommand;
|
||||
import me.wiefferink.areashop.commands.SchematicEventCommand;
|
||||
import me.wiefferink.areashop.commands.SellCommand;
|
||||
import me.wiefferink.areashop.commands.SetDurationCommand;
|
||||
import me.wiefferink.areashop.commands.SetLandlordCommand;
|
||||
import me.wiefferink.areashop.commands.SetOwnerCommand;
|
||||
import me.wiefferink.areashop.commands.SetPriceCommand;
|
||||
import me.wiefferink.areashop.commands.SetRestoreCommand;
|
||||
import me.wiefferink.areashop.commands.SetTeleportCommand;
|
||||
import me.wiefferink.areashop.commands.SetTransferCommand;
|
||||
import me.wiefferink.areashop.commands.StackCommand;
|
||||
import me.wiefferink.areashop.commands.StopResellCommand;
|
||||
import me.wiefferink.areashop.commands.TeleportCommand;
|
||||
import me.wiefferink.areashop.commands.ToggleHomeCommand;
|
||||
import me.wiefferink.areashop.commands.TransferCommand;
|
||||
import me.wiefferink.areashop.commands.UnrentCommand;
|
||||
import me.wiefferink.areashop.commands.SetMaxExtends;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSourceMapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.incendo.cloud.exception.ArgumentParseException;
|
||||
import org.incendo.cloud.exception.CommandExecutionException;
|
||||
import org.incendo.cloud.exception.InvalidCommandSenderException;
|
||||
import org.incendo.cloud.exception.handling.ExceptionController;
|
||||
import org.incendo.cloud.exception.handling.ExceptionHandler;
|
||||
import org.incendo.cloud.execution.ExecutionCoordinator;
|
||||
import org.incendo.cloud.paper.PaperCommandManager;
|
||||
import org.incendo.cloud.processors.cache.GuavaCache;
|
||||
import org.incendo.cloud.processors.confirmation.ConfirmationConfiguration;
|
||||
import org.incendo.cloud.processors.confirmation.ConfirmationManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class AreashopCommands {
|
||||
|
||||
private static final List<Class<? extends AreashopCommandBean>> COMMAND_CLASSES = List.of(
|
||||
AddCommand.class,
|
||||
AddFriendCommand.class,
|
||||
AddSignCommand.class,
|
||||
BuyCommand.class,
|
||||
DelCommand.class,
|
||||
DelFriendCommand.class,
|
||||
DelSignCommand.class,
|
||||
FindCommand.class,
|
||||
GroupAddCommand.class,
|
||||
GroupDelCommand.class,
|
||||
GroupInfoCommand.class,
|
||||
GroupListCommand.class,
|
||||
HelpCommand.class,
|
||||
InfoCommand.class,
|
||||
InfoBaseCommand.class,
|
||||
InfoPlayerCommand.class,
|
||||
InfoRegionCommand.class,
|
||||
LinkSignsCommand.class,
|
||||
MeCommand.class,
|
||||
MessageCommand.class,
|
||||
QuickBuyCommand.class,
|
||||
QuickDeleteCommand.class,
|
||||
QuickRentCommand.class,
|
||||
ReloadCommand.class,
|
||||
RentCommand.class,
|
||||
ResellCommand.class,
|
||||
SchematicEventCommand.class,
|
||||
SellCommand.class,
|
||||
SetDurationCommand.class,
|
||||
SetLandlordCommand.class,
|
||||
SetOwnerCommand.class,
|
||||
SetPriceCommand.class,
|
||||
SetRestoreCommand.class,
|
||||
SetTeleportCommand.class,
|
||||
SetTransferCommand.class,
|
||||
StackCommand.class,
|
||||
StopResellCommand.class,
|
||||
TeleportCommand.class,
|
||||
ToggleHomeCommand.class,
|
||||
TransferCommand.class,
|
||||
UnrentCommand.class,
|
||||
SetMaxExtends.class
|
||||
);
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
private final Injector injector;
|
||||
private final PaperCommandManager<CommandSource<?>> commandManager;
|
||||
|
||||
private final List<AreashopCommandBean> commands = new ArrayList<>();
|
||||
private HelpRenderer helpRenderer;
|
||||
|
||||
@Inject
|
||||
AreashopCommands(@Nonnull Injector injector, @Nonnull Plugin plugin, @Nonnull MessageBridge messageBridge) {
|
||||
this.injector = injector;
|
||||
this.commandManager = PaperCommandManager.builder(new CommandSourceMapper())
|
||||
.executionCoordinator(ExecutionCoordinator.simpleCoordinator())
|
||||
.buildOnEnable(plugin);
|
||||
this.messageBridge = messageBridge;
|
||||
}
|
||||
|
||||
public void registerCommands() {
|
||||
this.commands.clear();
|
||||
initCommandManager();
|
||||
var builder = this.commandManager.commandBuilder("areashop", "as");
|
||||
for (Class<? extends AreashopCommandBean> commandClass : COMMAND_CLASSES) {
|
||||
AreashopCommandBean commandBean = injector.getInstance(commandClass);
|
||||
this.commands.add(commandBean);
|
||||
var configuredBuilder = commandBean.configureCommand(builder);
|
||||
this.commandManager.command(configuredBuilder);
|
||||
}
|
||||
// Show help by default
|
||||
this.commandManager.command(builder.handler(context -> showHelp(context.sender().sender())));
|
||||
this.helpRenderer = new HelpRenderer(this.messageBridge, this.commands);
|
||||
}
|
||||
|
||||
private void initCommandManager() {
|
||||
ExceptionController<CommandSource<?>> exceptionController = this.commandManager.exceptionController();
|
||||
// We need to unwrap ArgumentParseException because they wrap the custom exception messages
|
||||
exceptionController.registerHandler(InvalidCommandSenderException.class,
|
||||
new InvalidCommandSenderHandler(this.messageBridge));
|
||||
exceptionController.registerHandler(AreaShopCommandException.class,
|
||||
new ArgumentParseExceptionHandler<>(this.messageBridge));
|
||||
exceptionController.registerHandler(ArgumentParseException.class,
|
||||
ExceptionHandler.unwrappingHandler(AreaShopCommandException.class));
|
||||
exceptionController.registerHandler(CommandExecutionException.class,
|
||||
ExceptionHandler.unwrappingHandler(AreaShopCommandException.class));
|
||||
var confirmationConfiguration = ConfirmationConfiguration.<CommandSource<?>>builder()
|
||||
.cache(GuavaCache.of(CacheBuilder.newBuilder().build()))
|
||||
.noPendingCommandNotifier(x -> {
|
||||
})
|
||||
.confirmationRequiredNotifier((x, y) -> {
|
||||
})
|
||||
.build();
|
||||
var confirmationManager = ConfirmationManager.confirmationManager(confirmationConfiguration);
|
||||
commandManager.registerCommandPostProcessor(confirmationManager.createPostprocessor());
|
||||
}
|
||||
|
||||
public void showHelp(@Nonnull CommandSender sender) {
|
||||
if (this.helpRenderer == null) {
|
||||
throw new IllegalStateException("Command handler not yet initialized!");
|
||||
}
|
||||
this.helpRenderer.showHelp(sender);
|
||||
}
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import org.incendo.cloud.exception.handling.ExceptionContext;
|
||||
import org.incendo.cloud.exception.handling.ExceptionHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ArgumentParseExceptionHandler<C extends CommandSource<?>> implements ExceptionHandler<C, AreaShopCommandException> {
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
public ArgumentParseExceptionHandler(@Nonnull MessageBridge messageBridge) {
|
||||
this.messageBridge = messageBridge;
|
||||
}
|
||||
|
||||
public static void handleException(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull CommandSource<?> sender,
|
||||
@Nonnull AreaShopCommandException exception
|
||||
) {
|
||||
String key = exception.messageKey();
|
||||
Object[] replacements = exception.replacements();
|
||||
if (replacements.length == 0) {
|
||||
messageBridge.message(sender.sender(), key);
|
||||
return;
|
||||
}
|
||||
// Pass the values as a var-args and not as a string[]
|
||||
messageBridge.message(sender.sender(), key, replacements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(@Nonnull ExceptionContext<C, AreaShopCommandException> context) {
|
||||
handleException(this.messageBridge, context.context().sender(), context.exception());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuyRegionParser<C> implements ArgumentParser<C, BuyRegion> {
|
||||
|
||||
private final IFileManager fileManager;
|
||||
private final SuggestionProvider<C> suggestionProvider;
|
||||
|
||||
public BuyRegionParser(@Nonnull IFileManager fileManager, @Nonnull SuggestionProvider<C> suggestionProvider) {
|
||||
this.fileManager = fileManager;
|
||||
this.suggestionProvider = suggestionProvider;
|
||||
}
|
||||
|
||||
public BuyRegionParser(@Nonnull IFileManager fileManager) {
|
||||
this(fileManager, defaultSuggestionProvider(fileManager));
|
||||
}
|
||||
|
||||
private static <C> SuggestionProvider<C> defaultSuggestionProvider(@Nonnull IFileManager fileManager) {
|
||||
return SuggestionProvider.blockingStrings((ctx, input) -> {
|
||||
String text = input.peekString();
|
||||
return fileManager.getBuyNames()
|
||||
.stream()
|
||||
.filter(name -> name.startsWith(text))
|
||||
.toList();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull ArgumentParseResult<BuyRegion> parse(@Nonnull CommandContext<C> commandContext,
|
||||
@Nonnull CommandInput commandInput) {
|
||||
String input = commandInput.peekString();
|
||||
BuyRegion region = this.fileManager.getBuy(input);
|
||||
if (region != null) {
|
||||
commandInput.readString();
|
||||
return ArgumentParseResult.success(region);
|
||||
}
|
||||
AreaShopCommandException exception = new AreaShopCommandException("buy-noBuyable", input);
|
||||
return ArgumentParseResult.failure(exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull SuggestionProvider<C> suggestionProvider() {
|
||||
return this.suggestionProvider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.tools.DurationInput;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DurationInputParser<C> implements ArgumentParser<C, DurationInput>, SuggestionProvider<C> {
|
||||
|
||||
public static <C> ParserDescriptor<C, DurationInput> durationInputParser() {
|
||||
return ParserDescriptor.of(new DurationInputParser<>(), DurationInput.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<@NonNull DurationInput> parse(@NonNull CommandContext<@NonNull C> commandContext,
|
||||
@NonNull CommandInput commandInput) {
|
||||
String input = commandInput.peekString();
|
||||
int index = 0;
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
if (Character.isAlphabetic(input.charAt(i))) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index == commandInput.length() - 1) {
|
||||
return ArgumentParseResult.failure(new AreaShopCommandException("setduration-wrongAmount", input));
|
||||
}
|
||||
String duration = input.substring(0, index);
|
||||
String durationUnit = input.substring(index);
|
||||
int durationInt;
|
||||
try {
|
||||
durationInt = Integer.parseInt(duration);
|
||||
} catch (NumberFormatException ex) {
|
||||
return ArgumentParseResult.failure(new AreaShopCommandException("setduration-wrongAmount", duration));
|
||||
}
|
||||
Optional<TimeUnit> timeUnit = DurationInput.getTimeUnit(durationUnit.toLowerCase(Locale.ENGLISH));
|
||||
if (timeUnit.isEmpty()) {
|
||||
return ArgumentParseResult.failure(new AreaShopCommandException("setduration-wrongFormat", durationUnit));
|
||||
}
|
||||
DurationInput durationInput = new DurationInput(durationInt, timeUnit.get());
|
||||
commandInput.readString();
|
||||
return ArgumentParseResult.success(durationInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CompletableFuture<@NonNull Iterable<@NonNull Suggestion>> suggestionsFuture(
|
||||
@NonNull CommandContext<C> context,
|
||||
@NonNull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
int firstText = 0;
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
if (Character.isAlphabetic(c)) {
|
||||
firstText = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (firstText == 0) {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
String timeUnit = text.substring(firstText);
|
||||
List<String> suffixes = DurationInput.SUFFIXES;
|
||||
List<Suggestion> suggestions = suffixes.stream()
|
||||
.filter(suffix -> suffix.startsWith(timeUnit))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GeneralRegionParser<C> implements ArgumentParser<C, GeneralRegion> {
|
||||
|
||||
protected final IFileManager fileManager;
|
||||
private final SuggestionProvider<C> suggestionProvider;
|
||||
|
||||
public GeneralRegionParser(@Nonnull IFileManager fileManager, @Nonnull SuggestionProvider<C> suggestionProvider) {
|
||||
this.fileManager = fileManager;
|
||||
this.suggestionProvider = suggestionProvider;
|
||||
}
|
||||
|
||||
public GeneralRegionParser(@Nonnull IFileManager fileManager) {
|
||||
this(fileManager, defaultProvider(fileManager));
|
||||
}
|
||||
|
||||
public static <C> ParserDescriptor<C, GeneralRegion> generalRegionParser(@Nonnull IFileManager fileManager) {
|
||||
return ParserDescriptor.of(new GeneralRegionParser<>(fileManager), GeneralRegion.class);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static <C> SuggestionProvider<C> defaultProvider(@Nonnull IFileManager fileManager) {
|
||||
return SuggestionProvider.blockingStrings((ctx, input) -> fileManager.getRegionNames());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull ArgumentParseResult<GeneralRegion> parse(@Nonnull CommandContext<C> commandContext,
|
||||
@Nonnull CommandInput commandInput) {
|
||||
String input = commandInput.peekString();
|
||||
GeneralRegion region = this.fileManager.getRegion(input);
|
||||
if (region != null) {
|
||||
commandInput.readString();
|
||||
return ArgumentParseResult.success(region);
|
||||
}
|
||||
AreaShopCommandException exception = new AreaShopCommandException("cmd-notRegistered", input);
|
||||
return ArgumentParseResult.failure(exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull SuggestionProvider<C> suggestionProvider() {
|
||||
return this.suggestionProvider;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.interactivemessenger.source.LanguageManager;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.component.CommandComponent;
|
||||
import org.incendo.cloud.exception.CommandParseException;
|
||||
import org.incendo.cloud.exception.handling.ExceptionContext;
|
||||
import org.incendo.cloud.exception.handling.ExceptionHandler;
|
||||
|
||||
public class HelpForwardingHandler<C> implements ExceptionHandler<C, CommandParseException> {
|
||||
|
||||
private final LanguageManager languageManager;
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
public HelpForwardingHandler(@NonNull MessageBridge messageBridge, @NonNull LanguageManager languageManager) {
|
||||
this.languageManager = languageManager;
|
||||
this.messageBridge = messageBridge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(@NonNull ExceptionContext<C, CommandParseException> context) throws Throwable {
|
||||
CommandParseException exception = context.exception();
|
||||
// walk back to the first literal
|
||||
CommandComponent<?> literal = null;
|
||||
for (CommandComponent<?> component : exception.currentChain()) {
|
||||
if (component.type() == CommandComponent.ComponentType.LITERAL) {
|
||||
literal = component;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If we can't find the label, rethrow the exception
|
||||
if (literal == null) {
|
||||
throw exception;
|
||||
}
|
||||
String name = literal.name();
|
||||
String helpKey = name + "-help";
|
||||
if (languageManager.getMessage(helpKey).isEmpty()) {
|
||||
// We don't have a help message, rethrow the exception
|
||||
throw exception;
|
||||
}
|
||||
this.messageBridge.message(context.context().sender(), helpKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface HelpProvider {
|
||||
|
||||
@Nullable String getHelpKey(@Nonnull CommandSender target);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HelpRenderer {
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
private final List<HelpProvider> providers;
|
||||
|
||||
public HelpRenderer(@Nonnull MessageBridge messageBridge, @Nonnull List<? extends HelpProvider> providers) {
|
||||
this.providers = List.copyOf(providers);
|
||||
this.messageBridge = messageBridge;
|
||||
}
|
||||
|
||||
public void showHelp(@Nonnull CommandSender target) {
|
||||
if (!target.hasPermission("areashop.help")) {
|
||||
this.messageBridge.message(target, "help-noPermission");
|
||||
return;
|
||||
}
|
||||
// Add all messages to a list
|
||||
List<String> messages = new ArrayList<>();
|
||||
this.messageBridge.message(target, "help-header");
|
||||
this.messageBridge.message(target, "help-alias");
|
||||
for (HelpProvider provider : providers) {
|
||||
String help = provider.getHelpKey(target);
|
||||
if (help != null && !help.isEmpty()) {
|
||||
messages.add(help);
|
||||
}
|
||||
}
|
||||
// Send the messages to the target
|
||||
for (String message : messages) {
|
||||
this.messageBridge.messageNoPrefix(target, message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.exception.InvalidCommandSenderException;
|
||||
import org.incendo.cloud.exception.handling.ExceptionContext;
|
||||
import org.incendo.cloud.exception.handling.ExceptionHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class InvalidCommandSenderHandler implements ExceptionHandler<CommandSource<?>, InvalidCommandSenderException> {
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
|
||||
public InvalidCommandSenderHandler(@Nonnull MessageBridge messageBridge) {
|
||||
this.messageBridge = messageBridge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(@NonNull ExceptionContext<CommandSource<?>, InvalidCommandSenderException> context) throws Throwable {
|
||||
InvalidCommandSenderException exception = context.exception();
|
||||
if (exception.requiredSenderTypes().contains(PlayerCommandSource.class)) {
|
||||
this.messageBridge.message(exception.commandSender(), "cmd-onlyByPlayer");
|
||||
return;
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.suggestion.BlockingSuggestionProvider;
|
||||
|
||||
public class OfflinePlayerParser<C> implements ArgumentParser<C, String>, BlockingSuggestionProvider.Strings<C> {
|
||||
|
||||
|
||||
public static <C> ParserDescriptor<C, String> parser() {
|
||||
return ParserDescriptor.of(new OfflinePlayerParser<>(), String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<@NonNull String> parse(@NonNull CommandContext<@NonNull C> commandContext,
|
||||
@NonNull CommandInput commandInput) {
|
||||
final String input = commandInput.readString();
|
||||
if (input.length() > 16) {
|
||||
return ArgumentParseResult.failure(new AreaShopCommandException("cmd-invalidPlayer", input));
|
||||
}
|
||||
return ArgumentParseResult.success(input);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Iterable<@NonNull String> stringSuggestions(@NonNull CommandContext<C> commandContext,
|
||||
@NonNull CommandInput input) {
|
||||
return Bukkit.getServer().getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ParserWrapper<C, T> implements ArgumentParser<C, T> {
|
||||
|
||||
private final SuggestionProvider<C> suggestionProvider;
|
||||
private final ParserDescriptor<C, T> parser;
|
||||
|
||||
public static <C, T> ParserDescriptor<C, T> wrap(@Nonnull ParserDescriptor<C, T> parser, @Nonnull SuggestionProvider<C> suggestionProvider) {
|
||||
ArgumentParser<C, T> wrapped = new ParserWrapper<>(parser, suggestionProvider);
|
||||
return ParserDescriptor.of(wrapped, parser.valueType());
|
||||
}
|
||||
|
||||
public ParserWrapper(@Nonnull ParserDescriptor<C, T> parser, @Nonnull SuggestionProvider<C> suggestionProvider) {
|
||||
this.parser = parser;
|
||||
this.suggestionProvider = suggestionProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<@NonNull T> parse(@NonNull CommandContext<@NonNull C> commandContext,
|
||||
@NonNull CommandInput commandInput) {
|
||||
return this.parser.parser().parse(commandContext, commandInput);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SuggestionProvider<C> suggestionProvider() {
|
||||
return this.suggestionProvider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Singleton
|
||||
public class RegionCreationUtil {
|
||||
|
||||
|
||||
private final Plugin plugin;
|
||||
private final IFileManager fileManager;
|
||||
private final Server server;
|
||||
private final WorldGuardInterface worldGuardInterface;
|
||||
|
||||
@Inject
|
||||
public RegionCreationUtil(
|
||||
@Nonnull WorldGuardInterface worldGuardInterface,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull Server server,
|
||||
@Nonnull Plugin plugin
|
||||
) {
|
||||
this.worldGuardInterface = worldGuardInterface;
|
||||
this.fileManager = fileManager;
|
||||
this.plugin = plugin;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public CompletableFuture<ProtectedRegion> createRegion(
|
||||
@Nonnull CommandContext<?> context,
|
||||
@Nonnull Player sender,
|
||||
@Nonnull CloudKey<String> regionKey
|
||||
) {
|
||||
World world = sender.getWorld();
|
||||
String regionName = context.get(regionKey);
|
||||
if (this.fileManager.getRegion(regionName) != null) {
|
||||
return CompletableFuture.failedFuture(new AreaShopCommandException("add-failed", regionName));
|
||||
}
|
||||
this.server.dispatchCommand(sender, String.format("rg define %s", regionName));
|
||||
CompletableFuture<ProtectedRegion> future = new CompletableFuture<>();
|
||||
this.server.getScheduler().runTaskLater(this.plugin, () -> {
|
||||
ProtectedRegion region = this.worldGuardInterface.getRegionManager(world).getRegion(regionName);
|
||||
if (region == null) {
|
||||
future.completeExceptionally(new AreaShopCommandException("quickadd-failedCreateWGRegion"));
|
||||
return;
|
||||
}
|
||||
future.complete(region);
|
||||
}, 10);
|
||||
return future;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RegionGroup;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class RegionGroupParser<C> implements ArgumentParser<C, RegionGroup>, SuggestionProvider<C> {
|
||||
|
||||
private final IFileManager fileManager;
|
||||
private final String failureMessageKey;
|
||||
|
||||
public RegionGroupParser(@Nonnull IFileManager fileManager, @Nonnull String failureMessageKey) {
|
||||
this.fileManager = fileManager;
|
||||
this.failureMessageKey = failureMessageKey;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @Nonnull ArgumentParseResult<RegionGroup> parse(
|
||||
@Nonnull CommandContext<C> commandContext,
|
||||
@Nonnull CommandInput commandInput
|
||||
) {
|
||||
String input = commandInput.peekString();
|
||||
RegionGroup regionGroup = this.fileManager.getGroup(input);
|
||||
if (regionGroup != null) {
|
||||
commandInput.readString();
|
||||
return ArgumentParseResult.success(regionGroup);
|
||||
}
|
||||
return ArgumentParseResult.failure(new AreaShopCommandException(this.failureMessageKey, input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull CompletableFuture<Iterable<Suggestion>> suggestionsFuture(
|
||||
@Nonnull CommandContext<C> context,
|
||||
@Nonnull CommandInput input
|
||||
) {
|
||||
String text = input.peekString();
|
||||
List<Suggestion> suggestions = this.fileManager.getGroupNames().stream()
|
||||
.filter(name -> name.startsWith(text))
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class RegionInfoUtil {
|
||||
|
||||
public static void showRegionInfo(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager,
|
||||
@Nonnull CommandSender sender,
|
||||
@Nonnull OfflinePlayer owner
|
||||
) {
|
||||
// Get the regions owned by the player
|
||||
Set<RentRegion> rentRegions = new HashSet<>();
|
||||
for(RentRegion region : fileManager.getRentsRef()) {
|
||||
if(region.isOwner(owner)) {
|
||||
rentRegions.add(region);
|
||||
}
|
||||
}
|
||||
Set<BuyRegion> buyRegions = new HashSet<>();
|
||||
for(BuyRegion region : fileManager.getBuysRef()) {
|
||||
if(region.isOwner(owner)) {
|
||||
buyRegions.add(region);
|
||||
}
|
||||
}
|
||||
// Get the regions the player is added as friend
|
||||
Set<GeneralRegion> friendRegions = new HashSet<>();
|
||||
for(GeneralRegion region : fileManager.getRegionsRef()) {
|
||||
if(region.getFriendsFeature().getFriends().contains(owner.getUniqueId())) {
|
||||
friendRegions.add(region);
|
||||
}
|
||||
}
|
||||
|
||||
// Send messages
|
||||
boolean foundSome = !rentRegions.isEmpty() || !buyRegions.isEmpty() || !friendRegions.isEmpty();
|
||||
if(!foundSome) {
|
||||
messageBridge.message(sender, "me-nothing", owner.getName());
|
||||
return;
|
||||
}
|
||||
messageBridge.message(sender, "me-header", owner.getName());
|
||||
if(!rentRegions.isEmpty()) {
|
||||
for(RentRegion region : rentRegions) {
|
||||
messageBridge.messageNoPrefix(sender, "me-rentLine", region);
|
||||
}
|
||||
}
|
||||
if(!buyRegions.isEmpty()) {
|
||||
for(BuyRegion region : buyRegions) {
|
||||
messageBridge.messageNoPrefix(sender, "me-buyLine", region);
|
||||
}
|
||||
}
|
||||
if(!friendRegions.isEmpty()) {
|
||||
for(GeneralRegion region : friendRegions) {
|
||||
messageBridge.messageNoPrefix(sender, "me-friendLine", region);
|
||||
}
|
||||
}
|
||||
messageBridge.messageNoPrefix(sender, "me-clickHint");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public final class RegionParseUtil {
|
||||
|
||||
private RegionParseUtil() {
|
||||
throw new IllegalStateException("Cannot instantiate static utility class");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static CommandFlag<GeneralRegion> createDefault(@Nonnull IFileManager fileManager) {
|
||||
return CommandFlag.builder("region")
|
||||
.withComponent(GeneralRegionParser.generalRegionParser(fileManager))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static Collection<GeneralRegion> getOrParseRegionsInSel(
|
||||
@Nonnull CommandContext<?> context,
|
||||
@Nonnull CommandSender sender,
|
||||
@Nonnull CommandFlag<GeneralRegion> regionFlag
|
||||
) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
throw new AreaShopCommandException("cmd-weOnlyByPlayer");
|
||||
}
|
||||
GeneralRegion declaredRegion = context.flags().get(regionFlag);
|
||||
if (declaredRegion != null) {
|
||||
return List.of(declaredRegion);
|
||||
}
|
||||
Location location = player.getLocation();
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(location);
|
||||
if (!regions.isEmpty()) {
|
||||
return regions;
|
||||
|
||||
}
|
||||
throw new AreaShopCommandException("cmd-noRegionsAtLocation");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static GeneralRegion getOrParseRegion(
|
||||
@Nonnull CommandContext<?> context,
|
||||
@Nonnull CommandSender sender,
|
||||
@Nonnull CommandFlag<GeneralRegion> flag
|
||||
) throws AreaShopCommandException {
|
||||
GeneralRegion region = context.flags().get(flag);
|
||||
if (region != null) {
|
||||
return region;
|
||||
}
|
||||
if (!(sender instanceof Entity entity)) {
|
||||
throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer");
|
||||
}
|
||||
Location location = entity.getLocation();
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(location);
|
||||
String errorMessageKey;
|
||||
if (regions.isEmpty()) {
|
||||
errorMessageKey = "cmd-noRegionsAtLocation";
|
||||
} else if (regions.size() > 1) {
|
||||
errorMessageKey = "cmd-moreRegionsAtLocation";
|
||||
} else {
|
||||
return regions.getFirst();
|
||||
}
|
||||
throw new AreaShopCommandException(errorMessageKey);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static GeneralRegion getOrParseRegion(
|
||||
@Nonnull CommandContext<?> context,
|
||||
@Nonnull CommandSender sender,
|
||||
@Nonnull CloudKey<GeneralRegion> key
|
||||
) throws AreaShopCommandException {
|
||||
GeneralRegion region = context.getOrDefault(key, null);
|
||||
if (region != null) {
|
||||
return region;
|
||||
}
|
||||
if (!(sender instanceof Entity entity)) {
|
||||
throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer");
|
||||
}
|
||||
Location location = entity.getLocation();
|
||||
List<GeneralRegion> regions = Utils.getImportantRegions(location);
|
||||
String errorMessageKey;
|
||||
if (regions.isEmpty()) {
|
||||
errorMessageKey = "cmd-noRegionsAtLocation";
|
||||
} else if (regions.size() > 1) {
|
||||
errorMessageKey = "cmd-moreRegionsAtLocation";
|
||||
} else {
|
||||
return regions.getFirst();
|
||||
}
|
||||
throw new AreaShopCommandException(errorMessageKey);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
public static CommandFlag<BuyRegion> createDefaultBuy(@Nonnull IFileManager fileManager) {
|
||||
return CommandFlag.builder("region")
|
||||
.withComponent(ParserDescriptor.of(new BuyRegionParser<>(fileManager), BuyRegion.class))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static CommandFlag<RentRegion> createDefaultRent(@Nonnull IFileManager fileManager) {
|
||||
return CommandFlag.builder("region")
|
||||
.withComponent(ParserDescriptor.of(new RentRegionParser<>(fileManager), RentRegion.class))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static BuyRegion getOrParseBuyRegion(
|
||||
@Nonnull CommandContext<?> context,
|
||||
@Nonnull CommandSender sender,
|
||||
@Nonnull CommandFlag<BuyRegion> flag) {
|
||||
BuyRegion buyRegion = context.flags().get(flag);
|
||||
if (buyRegion != null) {
|
||||
return buyRegion;
|
||||
}
|
||||
if (!(sender instanceof Player player)) {
|
||||
throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer");
|
||||
}
|
||||
List<BuyRegion> regions = Utils.getImportantBuyRegions(player.getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
throw new AreaShopCommandException("cmd-noRegionsAtLocation");
|
||||
} else if (regions.size() != 1) {
|
||||
throw new AreaShopCommandException("cmd-moreRegionsAtLocation");
|
||||
}
|
||||
return regions.getFirst();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static RentRegion getOrParseRentRegion(
|
||||
@Nonnull CommandContext<?> context,
|
||||
@Nonnull CommandSender sender,
|
||||
@Nonnull CommandFlag<RentRegion> flag) {
|
||||
RentRegion rentRegion = context.flags().get(flag);
|
||||
if (rentRegion != null) {
|
||||
return rentRegion;
|
||||
}
|
||||
if (!(sender instanceof Player player)) {
|
||||
throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer");
|
||||
}
|
||||
List<RentRegion> regions = Utils.getImportantRentRegions(player.getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
throw new AreaShopCommandException("cmd-noRegionsAtLocation");
|
||||
} else if (regions.size() != 1) {
|
||||
throw new AreaShopCommandException("cmd-moreRegionsAtLocation");
|
||||
}
|
||||
return regions.getFirst();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class RentRegionParser<C> implements ArgumentParser<C, RentRegion> {
|
||||
|
||||
private final IFileManager fileManager;
|
||||
private final SuggestionProvider<C> suggestionProvider;
|
||||
|
||||
public RentRegionParser(@Nonnull IFileManager fileManager, @Nonnull SuggestionProvider<C> suggestionProvider) {
|
||||
this.fileManager = fileManager;
|
||||
this.suggestionProvider = suggestionProvider;
|
||||
}
|
||||
|
||||
public RentRegionParser(@Nonnull IFileManager fileManager) {
|
||||
this(fileManager, defaultSuggestionProvider(fileManager));
|
||||
}
|
||||
|
||||
private static <C> SuggestionProvider<C> defaultSuggestionProvider(@Nonnull IFileManager fileManager) {
|
||||
return SuggestionProvider.blockingStrings((ctx, input) -> {
|
||||
String text = input.peekString();
|
||||
return fileManager.getRentNames()
|
||||
.stream()
|
||||
.filter(name -> name.startsWith(text))
|
||||
.toList();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull ArgumentParseResult<RentRegion> parse(@Nonnull CommandContext<C> commandContext,
|
||||
@Nonnull CommandInput commandInput) {
|
||||
String input = commandInput.peekString();
|
||||
RentRegion region = this.fileManager.getRent(input);
|
||||
if (region != null) {
|
||||
commandInput.readString();
|
||||
return ArgumentParseResult.success(region);
|
||||
}
|
||||
AreaShopCommandException exception = new AreaShopCommandException("rent-notRentable", input);
|
||||
return ArgumentParseResult.failure(exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull SuggestionProvider<C> suggestionProvider() {
|
||||
return this.suggestionProvider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class SignProfileUtil {
|
||||
|
||||
public static final CommandFlag<String> DEFAULT_FLAG = CommandFlag.builder("profile")
|
||||
.withComponent(StringParser.stringParser(StringParser.StringMode.SINGLE))
|
||||
.build();
|
||||
|
||||
private SignProfileUtil() {
|
||||
throw new IllegalArgumentException("Static utility class cannot be instantiated");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static CommandFlag<String> createDefault(@Nonnull Plugin plugin) {
|
||||
Supplier<Collection<String>> valueSupplier = () -> {
|
||||
ConfigurationSection section = plugin.getConfig().getConfigurationSection("signProfiles");
|
||||
if (section == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return section.getKeys(false);
|
||||
};
|
||||
return CommandFlag.builder("profile")
|
||||
.withComponent(
|
||||
ParserDescriptor.of(
|
||||
AcceptedValuesParser.of(valueSupplier, "addsign-wrongProfile", false),
|
||||
String.class)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getOrParseProfile(@Nonnull CommandContext<?> context,
|
||||
@Nonnull Plugin plugin) {
|
||||
return getOrParseProfile(context, DEFAULT_FLAG, plugin);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getOrParseProfile(
|
||||
@Nonnull CommandContext<?> context,
|
||||
@Nonnull CommandFlag<String> flag,
|
||||
@Nonnull Plugin plugin
|
||||
) throws AreaShopCommandException {
|
||||
String profile = context.flags().get(flag);
|
||||
if (profile == null) {
|
||||
return null;
|
||||
}
|
||||
Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false);
|
||||
if (profiles.contains(profile.toLowerCase(Locale.ENGLISH))) {
|
||||
return profile.toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
throw new AreaShopCommandException("addsign-wrongProfile");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.incendo.cloud.bukkit.parser.WorldParser;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class WorldFlagUtil {
|
||||
|
||||
public static final CommandFlag<World> DEFAULT_WORLD_FLAG = CommandFlag.builder("world")
|
||||
.withComponent(WorldParser.worldParser())
|
||||
.build();
|
||||
|
||||
private WorldFlagUtil() {
|
||||
throw new IllegalStateException("Cannot instantiate static util class");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static World parseOrDetectWorld(@Nonnull CommandContext<?> context, @Nonnull Entity sender) {
|
||||
return parseOrDetectWorld(context, sender, DEFAULT_WORLD_FLAG);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static World parseOrDetectWorld(
|
||||
@Nonnull CommandContext<?> context,
|
||||
@Nonnull Entity sender,
|
||||
@Nonnull CommandFlag<World> flag
|
||||
) {
|
||||
World world = context.flags().get(flag);
|
||||
if (world != null) {
|
||||
return world;
|
||||
}
|
||||
return sender.getWorld();
|
||||
}
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.EntityCommandSource;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
|
||||
public class WorldGuardRegionParser<C extends EntityCommandSource> implements ArgumentParser<C, ProtectedRegion> {
|
||||
private final WorldGuardInterface worldGuardInterface;
|
||||
private final CommandFlag<World> worldFlag;
|
||||
|
||||
public WorldGuardRegionParser(
|
||||
@Nonnull CommandFlag<World> worldFlag,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface
|
||||
) {
|
||||
this.worldFlag = worldFlag;
|
||||
this.worldGuardInterface = worldGuardInterface;
|
||||
}
|
||||
|
||||
public static <C extends EntityCommandSource> ParserDescriptor<C, ProtectedRegion> worldGuardRegionParser(
|
||||
@Nonnull CommandFlag<World> worldFlag,
|
||||
@Nonnull WorldGuardInterface worldGuardInterface
|
||||
) {
|
||||
return ParserDescriptor.of(new WorldGuardRegionParser<>(worldFlag, worldGuardInterface), ProtectedRegion.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull ArgumentParseResult<ProtectedRegion> parse(@Nonnull CommandContext<C> commandContext,
|
||||
@Nonnull CommandInput commandInput) {
|
||||
Entity sender = commandContext.sender().sender();
|
||||
World world = WorldFlagUtil.parseOrDetectWorld(commandContext, sender, worldFlag);
|
||||
String regionName = commandInput.peekString();
|
||||
RegionManager regionManager = this.worldGuardInterface.getRegionManager(world);
|
||||
if (regionManager == null) {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("No region manager for world: " + world.getName()));
|
||||
}
|
||||
ProtectedRegion protectedRegion = regionManager.getRegion(regionName);
|
||||
if (protectedRegion != null) {
|
||||
commandInput.readString();
|
||||
return ArgumentParseResult.success(protectedRegion);
|
||||
}
|
||||
AreaShopCommandException exception = new AreaShopCommandException("cmd-noRegion", regionName);
|
||||
return ArgumentParseResult.failure(exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nonnull SuggestionProvider<C> suggestionProvider() {
|
||||
return SuggestionProvider.blockingStrings((commandContext, input) -> {
|
||||
Entity sender = commandContext.sender().sender();
|
||||
if (!(sender instanceof Player player)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return this.worldGuardInterface.getRegionManager(player.getWorld()).getRegions()
|
||||
.values()
|
||||
.stream()
|
||||
.map(ProtectedRegion::getId)
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package me.wiefferink.areashop.commands.util;
|
||||
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.yaml.snakeyaml.parser.ParserException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public record WorldSelection(@Nonnull World world, @Nonnull WorldEditSelection selection) {
|
||||
|
||||
public static WorldSelection fromPlayer(@Nonnull Player player,
|
||||
@Nonnull WorldEditInterface worldEditInterface) throws ParserException {
|
||||
WorldEditSelection selection = worldEditInterface.getPlayerSelection(player);
|
||||
if (selection == null) {
|
||||
throw new AreaShopCommandException("cmd-noSelection");
|
||||
}
|
||||
World world = selection.getWorld();
|
||||
return new WorldSelection(world, selection);
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package me.wiefferink.areashop.commands.util.commandsource;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface CommandSource<C extends CommandSender> {
|
||||
|
||||
@Nonnull
|
||||
CommandSourceStack sourceStack();
|
||||
|
||||
@Nonnull
|
||||
C sender();
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package me.wiefferink.areashop.commands.util.commandsource;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.SenderMapper;
|
||||
|
||||
public class CommandSourceMapper implements SenderMapper<CommandSourceStack, CommandSource<?>> {
|
||||
|
||||
@Override
|
||||
public @NonNull CommandSource<?> map(@NonNull CommandSourceStack base) {
|
||||
CommandSender sender = base.getSender();
|
||||
if (sender instanceof Player) {
|
||||
return new PlayerCommandSource(base);
|
||||
} else if (sender instanceof Entity) {
|
||||
return new EntityCommandSource(base);
|
||||
}
|
||||
return new GenericCommandSource(base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CommandSourceStack reverse(@NonNull CommandSource<?> mapped) {
|
||||
return mapped.sourceStack();
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package me.wiefferink.areashop.commands.util.commandsource;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public record CommandSourceWrapper(@Nonnull CommandSourceStack commandSourceStack) {
|
||||
|
||||
@Nonnull
|
||||
public CommandSender sender() {
|
||||
return commandSourceStack().getSender();
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package me.wiefferink.areashop.commands.util.commandsource;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public sealed class EntityCommandSource extends GenericCommandSource permits PlayerCommandSource {
|
||||
|
||||
public EntityCommandSource(@Nonnull CommandSourceStack sourceStack) {
|
||||
super(sourceStack);
|
||||
if (!(sourceStack.getSender() instanceof Entity)) {
|
||||
throw new IllegalArgumentException("Source stack sender is not an entity!");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Entity sender() {
|
||||
return (Entity) super.sender();
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package me.wiefferink.areashop.commands.util.commandsource;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GenericCommandSource implements CommandSource<CommandSender> {
|
||||
|
||||
private final CommandSourceStack sourceStack;
|
||||
|
||||
private final CommandSender sender;
|
||||
|
||||
public GenericCommandSource(@Nonnull CommandSourceStack sourceStack) {
|
||||
this.sourceStack = sourceStack;
|
||||
this.sender = sourceStack.getSender();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final CommandSourceStack sourceStack() {
|
||||
return this.sourceStack;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandSender sender() {
|
||||
return this.sender;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package me.wiefferink.areashop.commands.util.commandsource;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class PlayerCommandSource extends EntityCommandSource {
|
||||
|
||||
public PlayerCommandSource(@Nonnull CommandSourceStack sourceStack) {
|
||||
super(sourceStack);
|
||||
if (!(sourceStack.getSender() instanceof Player)) {
|
||||
throw new IllegalArgumentException("Source stack sender is not a player!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Player sender() {
|
||||
return (Player) super.sender();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package me.wiefferink.areashop.extensions;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
|
||||
public interface AreashopExtension {
|
||||
|
||||
void init(AreaShop plugin, Injector injector);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package me.wiefferink.areashop.features;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
|
||||
import me.wiefferink.areashop.events.ask.BuyingRegionEvent;
|
||||
@@ -21,8 +23,6 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
|
||||
Loaded 100 of 204 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user