mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 12:54:25 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff33ebfe8d | ||
|
|
5f04b6fa69 | ||
|
|
a4bca99126 | ||
|
|
a7d1b9cd1f | ||
|
|
56c4d3e7f1 | ||
|
|
1f44ea5987 | ||
|
|
cb8a78e82b | ||
|
|
04d37623eb | ||
|
|
1a4f513fb3 | ||
|
|
e187b62348 | ||
|
|
a9e19294f8 | ||
|
|
54a45fbeb8 | ||
|
|
435ff3f5de | ||
|
|
8b92c04c45 | ||
|
|
32e828f2c8 | ||
|
|
689db91622 | ||
|
|
06a8317860 | ||
|
|
180d257024 | ||
|
|
ce75880aba | ||
|
|
250edf099c | ||
|
|
207d9f6124 | ||
|
|
3939e6cf2b | ||
|
|
b1e4a6f0fe | ||
|
|
4d1231a09e | ||
|
|
53daf359cd | ||
|
|
7e2ed41169 | ||
|
|
a1a0ebdc3f | ||
|
|
495fd98bfd | ||
|
|
9ac8ce3389 | ||
|
|
7f77894cfc | ||
|
|
79c8765c51 | ||
|
|
bbd70a06f0 | ||
|
|
17ab0ccc22 | ||
|
|
a8f5fd3b87 | ||
|
|
e85c4c9259 | ||
|
|
eda6b72058 | ||
|
|
ffcc8f603f | ||
|
|
08a18a123e | ||
|
|
b45d06458f | ||
|
|
900a8889aa | ||
|
|
d37368efc8 | ||
|
|
710cb04f8d | ||
|
|
6c1330552b | ||
|
|
5ab2203a8a | ||
|
|
f30cbf78f3 | ||
|
|
06754a05d0 | ||
|
|
c1fa75d4cb | ||
|
|
64a94a4830 | ||
|
|
83c560e7c1 | ||
|
|
cef643777f | ||
|
|
fcdd552874 | ||
|
|
95da5e78c8 | ||
|
|
1ae5d1bc12 | ||
|
|
b43d8d9065 | ||
|
|
299d3f3bcc | ||
|
|
71d309eed1 | ||
|
|
382fb0cf9c | ||
|
|
20e3cdd1f0 | ||
|
|
78c4aed595 | ||
|
|
73594e46c0 | ||
|
|
4ba1358af2 | ||
|
|
049d0baf5f | ||
|
|
8bcdaf5f11 | ||
|
|
e3fad91547 | ||
|
|
f1a606e183 | ||
|
|
c5093b3227 | ||
|
|
8ae4ae26dc | ||
|
|
fdf6205b64 | ||
|
|
6571e09911 | ||
|
|
763174525d | ||
|
|
43c940f7ed | ||
|
|
9712813749 | ||
|
|
66e06849cb | ||
|
|
67a1650fb6 | ||
|
|
b64481dec1 | ||
|
|
6e1b2f957f | ||
|
|
f334980f22 | ||
|
|
f662944181 | ||
|
|
7a16cdf520 | ||
|
|
d4eddf4551 | ||
|
|
1d2e00a0fb | ||
|
|
311e45b010 | ||
|
|
34047e288e | ||
|
|
d4940f1208 | ||
|
|
7a9e8e22f3 | ||
|
|
70a8fa2849 | ||
|
|
4d8832a005 | ||
|
|
7e9dfbdb2e | ||
|
|
f0547cf876 | ||
|
|
080fa62771 | ||
|
|
b060daab44 | ||
|
|
1f17c6638e | ||
|
|
a1e886afe5 | ||
|
|
ffaf21d3d8 | ||
|
|
0aef78fd43 | ||
|
|
ab194fba22 | ||
|
|
2e9f0c1dd0 | ||
|
|
82bad818f9 | ||
|
|
debbd25f18 | ||
|
|
ba661de91f | ||
|
|
4e6d6b7082 | ||
|
|
c2fa74c541 | ||
|
|
150b8bfe2d | ||
|
|
9d288e9d09 | ||
|
|
f5ee7451f5 | ||
|
|
0033413235 | ||
|
|
a8e8566e7d | ||
|
|
79f2b9b52c | ||
|
|
58ff772e3c | ||
|
|
758485b4d0 | ||
|
|
cdc5cc0983 | ||
|
|
be9d664017 | ||
|
|
05df0509e1 | ||
|
|
c5c2590bc2 | ||
|
|
2d89b8d450 | ||
|
|
413236b0b5 | ||
|
|
98355a5fc1 | ||
|
|
05041464c1 | ||
|
|
d0bd5ff210 | ||
|
|
033d45878d | ||
|
|
cd487e1122 | ||
|
|
93bb6243db | ||
|
|
e27aade87d | ||
|
|
da0489296e | ||
|
|
a328a635d7 | ||
|
|
baf06e7162 | ||
|
|
4e0359902d | ||
|
|
c132db8299 | ||
|
|
f8b3dcee75 | ||
|
|
d482213c85 | ||
|
|
c4fdf1a7b6 | ||
|
|
53adb4c9a5 | ||
|
|
90c3fab6c7 | ||
|
|
58cd2bc535 | ||
|
|
50977543c0 | ||
|
|
9b7af03de3 | ||
|
|
6e59cc760f | ||
|
|
c3573d5d2c | ||
|
|
d41311147c | ||
|
|
dbf81895a9 | ||
|
|
a16a930237 | ||
|
|
0b9e727e0c | ||
|
|
6903726300 | ||
|
|
e585f11bb2 | ||
|
|
c4c1be3e2b | ||
|
|
f1b77fe94f | ||
|
|
0c1ce7ed7a | ||
|
|
f2286a382f | ||
|
|
865978a971 | ||
|
|
3d90ddab46 | ||
|
|
5818060656 | ||
|
|
4faa851078 | ||
|
|
b099e78093 | ||
|
|
ef05817991 | ||
|
|
56ab018320 | ||
|
|
ab9209e4f8 | ||
|
|
8b1fdc5132 | ||
|
|
3bd3a125b6 | ||
|
|
2640a6c7e0 | ||
|
|
3e23893e78 | ||
|
|
84b07f4f6f | ||
|
|
7135f1ad27 | ||
|
|
fe9bb02aea | ||
|
|
c023071ff0 | ||
|
|
294abe4d25 | ||
|
|
aeee864bf7 | ||
|
|
5dfe061bad | ||
|
|
faf335c831 | ||
|
|
b98f024fbd | ||
|
|
1c190fe5c4 | ||
|
|
a37b32c1a5 | ||
|
|
d7d968bf86 | ||
|
|
ce1f652d53 | ||
|
|
9f71370c1f | ||
|
|
9905aaaf0c | ||
|
|
05487a06a2 | ||
|
|
98605b7276 | ||
|
|
40154f9c53 | ||
|
|
2141c5c4ca | ||
|
|
83c16ae419 | ||
|
|
c3538836be | ||
|
|
7820e37180 | ||
|
|
cd3514aa73 | ||
|
|
19a1b629c8 | ||
|
|
3ee39e8b95 | ||
|
|
36183cd181 | ||
|
|
478e16d279 | ||
|
|
ea1f142571 | ||
|
|
e15e72d478 | ||
|
|
98e886703c | ||
|
|
cf6e6dd655 | ||
|
|
db330d0038 | ||
|
|
3ce7203978 | ||
|
|
d62b02410e | ||
|
|
cd12397927 | ||
|
|
5a38f9057f | ||
|
|
e8f657f7e6 | ||
|
|
36181d5165 | ||
|
|
f5a2ce27ff | ||
|
|
ccc16aa1ac | ||
|
|
64bb024e61 | ||
|
|
753a2a1927 | ||
|
|
a728ff13c1 | ||
|
|
eb899061bf | ||
|
|
3cac4e764f | ||
|
|
2ebe4ed9c5 | ||
|
|
8ed86f5ec7 | ||
|
|
efcdeecbf2 | ||
|
|
79955f549e | ||
|
|
598491fe8c | ||
|
|
78380c3e09 | ||
|
|
030b44035e | ||
|
|
fdd47691ae | ||
|
|
a5f661b679 | ||
|
|
972e930b31 | ||
|
|
90bd8aeb02 | ||
|
|
f62ff8a474 | ||
|
|
5c04b1aae6 | ||
|
|
690f2ca10d | ||
|
|
f84dd5477d | ||
|
|
5cbab2581c | ||
|
|
85165070e0 | ||
|
|
639e44f98f | ||
|
|
e316946915 | ||
|
|
f51c636b79 | ||
|
|
eb8b5387ea | ||
|
|
a2d4c4fd5a | ||
|
|
768f494631 | ||
|
|
de2e3ce4fb | ||
|
|
4dc8d8a971 | ||
|
|
7fc259e158 | ||
|
|
dac4ef66f3 | ||
|
|
025e1ada3c | ||
|
|
1ca70be090 | ||
|
|
114d9d0941 | ||
|
|
c94f928f5e | ||
|
|
4703faa515 | ||
|
|
7ee1b57763 | ||
|
|
def6f60553 | ||
|
|
fb39c6bd49 | ||
|
|
9b0272ef29 | ||
|
|
74b71a290d | ||
|
|
25d917c338 | ||
|
|
30aa37ba6f | ||
|
|
8909124fff | ||
|
|
4a1a092757 | ||
|
|
d394174108 | ||
|
|
6d80acb5f0 | ||
|
|
cb5b8898bb | ||
|
|
d9e6372acb | ||
|
|
44e5c8b4c5 | ||
|
|
6193f77bf5 | ||
|
|
fb87e2a72c | ||
|
|
42de9a0568 | ||
|
|
fb75f52806 | ||
|
|
4b8e0cd8c3 | ||
|
|
82dfbc8635 | ||
|
|
b7d57671b1 | ||
|
|
d510fe8a00 | ||
|
|
bd2eb0fe16 | ||
|
|
16d838d6eb | ||
|
|
8547c21474 | ||
|
|
3a00d08304 | ||
|
|
3c610e7105 | ||
|
|
cb2c7910cf | ||
|
|
16f2901fbc | ||
|
|
eb57a15417 | ||
|
|
afa5bd81bd | ||
|
|
f74984a014 | ||
|
|
0dfcae05f4 | ||
|
|
6d61c64cb6 | ||
|
|
936a56ddcb | ||
|
|
50acac65cd | ||
|
|
f00948ebdc | ||
|
|
5dd260bb42 | ||
|
|
4905b9400a | ||
|
|
0a04560243 | ||
|
|
0418aa11e4 | ||
|
|
3b9c38124e | ||
|
|
c6bb5b1b74 | ||
|
|
0f6d912743 | ||
|
|
d6c70167bf | ||
|
|
cb206348c5 | ||
|
|
411b4dac51 | ||
|
|
5d4088b9d1 | ||
|
|
79fc173e3b | ||
|
|
8e70e958f3 | ||
|
|
c2c101641f | ||
|
|
e5673a85e7 | ||
|
|
4d963b0205 | ||
|
|
2c4038dec8 | ||
|
|
272b1c5e5a | ||
|
|
de18cee44c | ||
|
|
901f2e8bc7 | ||
|
|
00af353e65 | ||
|
|
3f91be9498 | ||
|
|
155cacf3c1 | ||
|
|
9188499e7e | ||
|
|
4a064add75 | ||
|
|
adef51cd53 | ||
|
|
eef2e349de | ||
|
|
8d2ffdc5e3 | ||
|
|
b434600cbe | ||
|
|
88790cd207 | ||
|
|
097f1f9d1d | ||
|
|
7d37670494 | ||
|
|
a35db3f9e5 | ||
|
|
44684277ba | ||
|
|
def3102354 | ||
|
|
58cf52fd1f | ||
|
|
3240970252 | ||
|
|
f2041e855b | ||
|
|
de0e425b87 | ||
|
|
0072369fca | ||
|
|
ea8e52e8e6 | ||
|
|
d2c7e634ec | ||
|
|
070e032907 | ||
|
|
20a46e6007 | ||
|
|
65ac349c08 | ||
|
|
29e182e82d | ||
|
|
d45e550321 | ||
|
|
48dd7bedea | ||
|
|
9cda5503ed | ||
|
|
e9004aafa3 | ||
|
|
eeb6b2ea8b | ||
|
|
4202cb7271 | ||
|
|
8a270b1548 | ||
|
|
5de68934eb | ||
|
|
328a3d4186 | ||
|
|
f168eb34d5 | ||
|
|
5180e3cc4b | ||
|
|
7244d8fcd7 | ||
|
|
f2e85c1347 | ||
|
|
e963ead882 | ||
|
|
37ad1755fd | ||
|
|
21a1dd0ba9 | ||
|
|
002a64cb88 | ||
|
|
30714e92a5 | ||
|
|
3e6a5410ab | ||
|
|
48e3ae5271 | ||
|
|
dfb4c511cc | ||
|
|
a973eca54c | ||
|
|
ee727146a9 | ||
|
|
4f52e2674b | ||
|
|
1be707ce47 | ||
|
|
fc7b7f627d | ||
|
|
a0ace95d35 | ||
|
|
d84092eeaf | ||
|
|
64b033da65 | ||
|
|
334eca1b40 | ||
|
|
7a0c742833 | ||
|
|
50c6ab644b | ||
|
|
d28935ab58 | ||
|
|
e37519f4e3 | ||
|
|
268bd0f456 | ||
|
|
29c456ab4e | ||
|
|
c0dc526d41 | ||
|
|
de9b373973 | ||
|
|
e3cfdd5ee1 | ||
|
|
4ae8978399 | ||
|
|
fe7c24186d | ||
|
|
0f948a9d62 | ||
|
|
04fc429a53 | ||
|
|
d11f72eb0d | ||
|
|
c55ef6d0fc | ||
|
|
3d2a6954f9 | ||
|
|
4143298da3 | ||
|
|
10f12ad036 | ||
|
|
a41a320676 | ||
|
|
9841d158ff | ||
|
|
a5c3c6768b | ||
|
|
54a07ffb48 | ||
|
|
ea1f5b259d | ||
|
|
c5329a1c63 | ||
|
|
021989aa79 | ||
|
|
e6e860b895 | ||
|
|
94fc6e035c | ||
|
|
a2a3d94de6 | ||
|
|
a93c0fc3c6 | ||
|
|
0326947b23 | ||
|
|
20e44c919f | ||
|
|
fb32ca6e29 | ||
|
|
42fe078efd | ||
|
|
b0e4d555ce | ||
|
|
f314d9d826 | ||
|
|
f950ba0a22 | ||
|
|
57e41412dd | ||
|
|
b5d294dd20 | ||
|
|
4a1732c5f0 | ||
|
|
abfb06aa7a | ||
|
|
87eeebc1af | ||
|
|
5117c39a2f | ||
|
|
2677809c0e | ||
|
|
5ce4beab34 | ||
|
|
902fad4e6f | ||
|
|
28acfbc8f8 | ||
|
|
55d271abad | ||
|
|
21557ff857 | ||
|
|
864e1cb8c7 | ||
|
|
30e58dc049 | ||
|
|
7c2ad0749b | ||
|
|
601123811a | ||
|
|
47e30ac8b4 | ||
|
|
0124154380 | ||
|
|
7366b11077 | ||
|
|
bd783a2e98 | ||
|
|
364bf2414f | ||
|
|
b22105341f | ||
|
|
f2c34699b1 | ||
|
|
b15d64bd09 | ||
|
|
35da0f92f6 | ||
|
|
1e5cc66f2f | ||
|
|
3979d1895b | ||
|
|
9ea1385ac2 | ||
|
|
e77a1032d3 | ||
|
|
c2bc9c6c11 | ||
|
|
702df25036 | ||
|
|
68404d353f | ||
|
|
db2144116f | ||
|
|
da9ed1d60f | ||
|
|
db7473fd57 | ||
|
|
e042b2cfac | ||
|
|
c3179b36f2 | ||
|
|
43b0e7c23b | ||
|
|
a1f10db0de | ||
|
|
e8c3fc4d0a | ||
|
|
4f5f870e2b | ||
|
|
a70300c54b | ||
|
|
87cad579ae | ||
|
|
fb496ce1e2 | ||
|
|
ee8527f261 | ||
|
|
5d308b1f56 | ||
|
|
90605ee808 | ||
|
|
31c7ceacab | ||
|
|
e8e868993b | ||
|
|
1c97d84518 | ||
|
|
29f9774d1f | ||
|
|
4eae773f86 | ||
|
|
d91d4668d6 | ||
|
|
06275fffa6 | ||
|
|
de56032118 | ||
|
|
dcf3a0d8b0 | ||
|
|
f573259fd1 | ||
|
|
36c8b70eb4 | ||
|
|
5d41f5b939 | ||
|
|
19c31b985d | ||
|
|
476efb0317 | ||
|
|
5790926e51 | ||
|
|
882bce2d4b | ||
|
|
d2da5c6000 | ||
|
|
8a2a3e1ac3 | ||
|
|
ec133ce74c | ||
|
|
be6c318619 | ||
|
|
17eac9a690 | ||
|
|
36b2610d3d | ||
|
|
c95341b60b | ||
|
|
26f4158c17 | ||
|
|
4d2ced4528 | ||
|
|
2f5d5f84c2 | ||
|
|
8f4a5cdd16 | ||
|
|
81b4f7a0ef | ||
|
|
4aa0a96f1f | ||
|
|
db9ac7f7c4 | ||
|
|
435c31ddda | ||
|
|
62482c307c | ||
|
|
c7c981f4a7 | ||
|
|
52aa1a75c1 | ||
|
|
10edf72ed9 | ||
|
|
f6e3f867e0 | ||
|
|
bf604774c0 | ||
|
|
34d002191e | ||
|
|
572077b7e5 | ||
|
|
990419a411 | ||
|
|
0bb5dee58f | ||
|
|
b2b9248c55 | ||
|
|
a01297d437 | ||
|
|
437d365de3 | ||
|
|
64fdc9baa8 | ||
|
|
7a28d9107c | ||
|
|
179c7b6fb4 | ||
|
|
c36ac283e4 | ||
|
|
0a7a638040 | ||
|
|
6a59dc91a0 | ||
|
|
810d2ca12c | ||
|
|
f98b31c8d9 | ||
|
|
9f6f864a36 | ||
|
|
8c10235ee2 | ||
|
|
ca7debb51b | ||
|
|
600f225d7a | ||
|
|
d57571ea0d | ||
|
|
ad222657c4 | ||
|
|
213c02660b | ||
|
|
b81c038584 | ||
|
|
0a4abfca9e | ||
|
|
d0bff7cb6f | ||
|
|
a459a27872 | ||
|
|
f0ab36e4a1 | ||
|
|
e7f48ae70d | ||
|
|
a6bb327c08 | ||
|
|
5eb2e98305 |
No files matched your search
@@ -21,7 +21,7 @@ jobs:
|
||||
run: ./gradlew SetupCIWorkspace build
|
||||
- name: Build with Gradle (nomixin)
|
||||
run: ./gradlew build -Pnomixin
|
||||
- uses: actions/upload-artifact@v2
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Package
|
||||
path: build/libs
|
||||
path: build/libs
|
||||
+2
-2
@@ -5,7 +5,7 @@ plugins {
|
||||
id 'idea'
|
||||
}
|
||||
|
||||
version = "1.9.3"
|
||||
version = "1.10-testingbeta1"
|
||||
group= "kamkeel.customnpc-plus"
|
||||
archivesBaseName = "CustomNPC-Plus"
|
||||
|
||||
@@ -37,4 +37,4 @@ sourceSets {
|
||||
}
|
||||
|
||||
// Modify the existing 'build' task to depend on 'updateAPI'
|
||||
tasks.apiClasses.dependsOn 'updateAPI'
|
||||
//tasks.apiClasses.dependsOn 'updateAPI'
|
||||
+65
-5
@@ -1,3 +1,13 @@
|
||||
# ExampleMod tag to use as Blowdryer (Spotless, etc.) settings version, leave empty to disable.
|
||||
# LOCAL to test local config updates.
|
||||
gtnh.settings.blowdryerTag = 0.2.2
|
||||
|
||||
# Whether to automatically set the version based on the VERSION environment variable or the current git status.
|
||||
gtnh.modules.gitVersion = false
|
||||
|
||||
# Sets up code style plugins like Spotless and Checkstyle.
|
||||
gtnh.modules.codeStyle = true
|
||||
|
||||
# Human-readable mod name, available for mcmod.info population.
|
||||
modName = CustomNPC+
|
||||
|
||||
@@ -8,10 +18,6 @@ modId = customnpcs
|
||||
# Root package of the mod, used to find various classes in other properties,
|
||||
# mcmod.info substitution, enabling assertions in run tasks, etc.
|
||||
modGroup = noppes.npcs
|
||||
modVersion = 1.9.3
|
||||
|
||||
gtnh.modules.codeStyle=true
|
||||
gtnh.modules.gitVersion=false
|
||||
|
||||
# Whether to use modGroup as the maven publishing group.
|
||||
# Due to a history of using JitPack, the default is com.github.GTNewHorizons for all mods.
|
||||
@@ -22,10 +28,14 @@ autoUpdateBuildScript = false
|
||||
|
||||
# Version of Minecraft to target
|
||||
minecraftVersion = 1.7.10
|
||||
|
||||
# Version of Minecraft Forge to target
|
||||
forgeVersion = 10.13.4.1614
|
||||
|
||||
# Specify an MCP channel for dependency deobfuscation and the deobfParams task.
|
||||
channel = stable
|
||||
|
||||
# Specify an MCP mappings version for dependency deobfuscation and the deobfParams task.
|
||||
mappingsVersion = 12
|
||||
|
||||
# Defines other MCP mappings for dependency deobfuscation.
|
||||
@@ -71,25 +81,53 @@ accessTransformersFile = customnpcs_at.cfg
|
||||
|
||||
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
|
||||
usesMixins = true
|
||||
|
||||
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
|
||||
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
|
||||
# Mixin classes will have access to "main" classes, but not the other way around.
|
||||
separateMixinSourceSet =
|
||||
|
||||
# Adds some debug arguments like verbose output and class export.
|
||||
usesMixinDebug = true
|
||||
|
||||
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
|
||||
mixinPlugin = mixin.CustomNPCsMixinPlugin
|
||||
|
||||
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
|
||||
mixinsPackage = mixin
|
||||
|
||||
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
|
||||
# This parameter is for legacy compatibility only
|
||||
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
|
||||
coreModClass =
|
||||
|
||||
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
|
||||
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
|
||||
containsMixinsAndOrCoreModOnly = false
|
||||
|
||||
# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins.
|
||||
forceEnableMixins = false
|
||||
|
||||
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated into your jar. It is your
|
||||
# responsibility to check the license and request permission for distribution if required.
|
||||
usesShadowedDependencies = true
|
||||
|
||||
# If disabled, won't remove unused classes from shadowed dependencies. Some libraries use reflection to access
|
||||
# their own classes, making the minimization unreliable.
|
||||
minimizeShadowedDependencies = false
|
||||
|
||||
# If disabled, won't rename the shadowed classes.
|
||||
relocateShadowedDependencies = false
|
||||
|
||||
# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories.
|
||||
# Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
|
||||
includeWellKnownRepositories = true
|
||||
|
||||
# A list of repositories to exclude from the includeWellKnownRepositories setting. Should be a space separated
|
||||
# list of strings, with the acceptable keys being(case does not matter):
|
||||
# cursemaven
|
||||
# modrinth
|
||||
excludeWellKnownRepositories =
|
||||
|
||||
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
|
||||
# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables.
|
||||
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
|
||||
@@ -103,8 +141,28 @@ usesMavenPublishing = false
|
||||
# The project's ID on Modrinth. Can be either the slug or the ID.
|
||||
# Leave this empty if you don't want to publish to Modrinth.
|
||||
modrinthProjectId =
|
||||
|
||||
# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth.
|
||||
# Syntax: scope1-type1:name1;scope2-type2:name2;...
|
||||
# Where scope can be one of [required, optional, incompatible, embedded],
|
||||
# type can be one of [project, version],
|
||||
# and the name is the Modrinth project or version slug/id of the other mod.
|
||||
# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech
|
||||
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
|
||||
modrinthRelations =
|
||||
|
||||
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
|
||||
#
|
||||
# The project's numeric ID on CurseForge. You can find this in the About Project box.
|
||||
# Leave this empty if you don't want to publish on CurseForge.
|
||||
curseForgeProjectId =
|
||||
|
||||
# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge.
|
||||
# Syntax: type1:name1;type2:name2;...
|
||||
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
|
||||
# and the name is the CurseForge project slug of the other mod.
|
||||
# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft
|
||||
# Note: UniMixins is automatically set as a required dependency if usesMixins = true.
|
||||
curseForgeRelations =
|
||||
|
||||
# Optional parameter to customize the produced artifacts. Use this to preserve artifact naming when migrating older
|
||||
@@ -140,3 +198,5 @@ disableCheckstyle = true
|
||||
# This is meant to be set in $HOME/.gradle/gradle.properties.
|
||||
# ideaCheckSpotlessOnBuild = true
|
||||
|
||||
# Non-GTNH properties
|
||||
modVersion = 1.10
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
+1
-1
@@ -17,5 +17,5 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.14'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
|
||||
}
|
||||
+1
-1
Submodule src/api updated: 9fdd2c667e...c7a74a3e0e.
@@ -21,8 +21,8 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import java.util.List;
|
||||
|
||||
@Command(
|
||||
name = "clone",
|
||||
desc = "Clone operation (server side)"
|
||||
name = "clone",
|
||||
desc = "Clone operation (server side)"
|
||||
)
|
||||
public class CmdClone extends ChMcLogger {
|
||||
|
||||
@@ -31,17 +31,16 @@ public class CmdClone extends ChMcLogger {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Add NPC(s) to clone storage",
|
||||
usage = "<npc> <tab> [clonedname]",
|
||||
permissions = {OpOnly.class ,PlayerOnly.class, ParamCheck.class}
|
||||
desc = "Add NPC(s) to clone storage",
|
||||
usage = "<npc> <tab> [clonedname]",
|
||||
permissions = {OpOnly.class, PlayerOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean add(String[] args) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) pcParam;
|
||||
int tab = 0;
|
||||
try{
|
||||
tab = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
try {
|
||||
tab = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
|
||||
}
|
||||
List<EntityNPCInterface> list = Utils.getNearbeEntityFromPlayer(EntityNPCInterface.class, player, 80);
|
||||
@@ -51,24 +50,23 @@ public class CmdClone extends ChMcLogger {
|
||||
if (args.length > 2) {
|
||||
name = args[2];
|
||||
}
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if(!npc.writeToNBTOptional(compound))
|
||||
return false;
|
||||
ServerCloneController.Instance.addClone(compound, name, tab);
|
||||
return true;
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if (!npc.writeToNBTOptional(compound))
|
||||
return false;
|
||||
ServerCloneController.Instance.addClone(compound, name, tab);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(desc = "List NPC from clone storage", usage = "<tab>", permissions={OpOnly.class ,ParamCheck.class})
|
||||
@SubCommand(desc = "List NPC from clone storage", usage = "<tab>", permissions = {OpOnly.class, ParamCheck.class})
|
||||
public Boolean list(String[] args) {
|
||||
sendmessage("--- Stored NPCs --- (server side)");
|
||||
int tab = 0;
|
||||
try{
|
||||
tab = Integer.parseInt(args[0]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
try {
|
||||
tab = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
|
||||
}
|
||||
for (String name : ServerCloneController.Instance.getClones(tab)) {
|
||||
@@ -78,205 +76,201 @@ public class CmdClone extends ChMcLogger {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(desc = "Remove NPC from clone storage", usage = "<name> <tab>", permissions={OpOnly.class ,ParamCheck.class})
|
||||
@SubCommand(desc = "Remove NPC from clone storage", usage = "<name> <tab>", permissions = {OpOnly.class, ParamCheck.class})
|
||||
public Boolean del(String[] args) {
|
||||
String nametodel = args[0];
|
||||
int tab = 0;
|
||||
try{
|
||||
tab = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
try {
|
||||
tab = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
|
||||
}
|
||||
boolean deleted = false;
|
||||
for(String name : ServerCloneController.Instance.getClones(tab)){
|
||||
if(nametodel.equalsIgnoreCase(name)){
|
||||
ServerCloneController.Instance.removeClone(name, tab);
|
||||
deleted = true;
|
||||
break;
|
||||
}
|
||||
for (String name : ServerCloneController.Instance.getClones(tab)) {
|
||||
if (nametodel.equalsIgnoreCase(name)) {
|
||||
ServerCloneController.Instance.removeClone(name, tab);
|
||||
deleted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ServerCloneController.Instance.removeClone(nametodel, tab)) {
|
||||
sendmessage(String.format("Npc '%s' wasn't found", nametodel));
|
||||
return false;
|
||||
}
|
||||
;
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Spawn cloned NPC",
|
||||
usage = "<name> <tab> [[world:]x,y,z]] [newname]",
|
||||
permissions={OpOnly.class ,ParamCheck.class})
|
||||
desc = "Spawn cloned NPC",
|
||||
usage = "<name> <tab> [[world:]x,y,z]] [newname]",
|
||||
permissions = {OpOnly.class, ParamCheck.class})
|
||||
public boolean spawn(String[] args) {
|
||||
String name = args[0].replaceAll("%", " "); // if name of npc separed by space, user must use % in place of space
|
||||
int tab = 0;
|
||||
try{
|
||||
tab = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
try {
|
||||
tab = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
|
||||
}
|
||||
String newname=null;
|
||||
String newname = null;
|
||||
NBTTagCompound compound = ServerCloneController.Instance.getCloneData(this.pcParam, name, tab);
|
||||
if(compound == null){
|
||||
sendmessage("Unknown npc");
|
||||
return false;
|
||||
if (compound == null) {
|
||||
sendmessage("Unknown npc");
|
||||
return false;
|
||||
}
|
||||
World world = pcParam.getEntityWorld();
|
||||
double posX = pcParam.getPlayerCoordinates().posX;
|
||||
double posY = pcParam.getPlayerCoordinates().posY;
|
||||
double posZ = pcParam.getPlayerCoordinates().posZ;
|
||||
|
||||
if(args.length > 2){
|
||||
String location = args[2];
|
||||
String[] par;
|
||||
if (location.contains(":")){
|
||||
par = location.split(":");
|
||||
location = par[1];
|
||||
world = Utils.getWorld(par[0]);
|
||||
if (world == null){
|
||||
sendmessage (String.format("'%s' is an unknown world",par[0]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (args.length > 2) {
|
||||
String location = args[2];
|
||||
String[] par;
|
||||
if (location.contains(":")) {
|
||||
par = location.split(":");
|
||||
location = par[1];
|
||||
world = Utils.getWorld(par[0]);
|
||||
if (world == null) {
|
||||
sendmessage(String.format("'%s' is an unknown world", par[0]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (location.contains(",")){
|
||||
par = location.split(",");
|
||||
if (par.length != 3){
|
||||
sendmessage("Location need be x,y,z");
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
posX = CommandBase.func_110666_a(pcParam, posX, par[0]);
|
||||
posY = CommandBase.func_110665_a(pcParam, posY, par[1].trim(), 0, 0);
|
||||
posZ = CommandBase.func_110666_a(pcParam, posZ, par[2]);
|
||||
} catch(NumberFormatException ex){
|
||||
sendmessage("Location should be in numbers");
|
||||
return false;
|
||||
}
|
||||
if (args.length > 3){
|
||||
newname = args[3];
|
||||
}
|
||||
} else {
|
||||
newname = location;
|
||||
}
|
||||
if (location.contains(",")) {
|
||||
par = location.split(",");
|
||||
if (par.length != 3) {
|
||||
sendmessage("Location need be x,y,z");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
posX = CommandBase.func_110666_a(pcParam, posX, par[0]);
|
||||
posY = CommandBase.func_110665_a(pcParam, posY, par[1].trim(), 0, 0);
|
||||
posZ = CommandBase.func_110666_a(pcParam, posZ, par[2]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("Location should be in numbers");
|
||||
return false;
|
||||
}
|
||||
if (args.length > 3) {
|
||||
newname = args[3];
|
||||
}
|
||||
} else {
|
||||
newname = location;
|
||||
}
|
||||
}
|
||||
|
||||
if (posX == 0 && posY == 0 && posZ == 0){//incase it was called from the console and not pos was given
|
||||
sendmessage ("Location needed");
|
||||
if (posX == 0 && posY == 0 && posZ == 0) {//incase it was called from the console and not pos was given
|
||||
sendmessage("Location needed");
|
||||
return false;
|
||||
}
|
||||
|
||||
Entity entity = EntityList.createEntityFromNBT(compound, world);
|
||||
entity.setPosition(posX + 0.5, posY + 1, posZ + 0.5);
|
||||
if(entity instanceof EntityNPCInterface){
|
||||
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
||||
npc.ai.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
|
||||
if(newname != null && !newname.isEmpty())
|
||||
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
|
||||
if (entity instanceof EntityNPCInterface) {
|
||||
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
||||
npc.ais.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
|
||||
if (newname != null && !newname.isEmpty())
|
||||
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
|
||||
}
|
||||
world.spawnEntityInWorld(entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Spawn cloned NPC",
|
||||
usage = "<name> <tab> <lenght> <width> [[world:]x,y,z]] [newname]",
|
||||
permissions={OpOnly.class ,ParamCheck.class})
|
||||
desc = "Spawn cloned NPC",
|
||||
usage = "<name> <tab> <lenght> <width> [[world:]x,y,z]] [newname]",
|
||||
permissions = {OpOnly.class, ParamCheck.class})
|
||||
public boolean grid(String[] args) {
|
||||
String name = args[0].replaceAll("%", " "); // if name of npc separed by space, user must use % in place of space
|
||||
int tab = 0;
|
||||
try{
|
||||
tab = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
try {
|
||||
tab = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
|
||||
}
|
||||
|
||||
int width, height;
|
||||
try{
|
||||
width = Integer.parseInt(args[2]);
|
||||
height = Integer.parseInt(args[3]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
sendmessage("lenght or width wasnt a number");
|
||||
return false;
|
||||
try {
|
||||
width = Integer.parseInt(args[2]);
|
||||
height = Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("lenght or width wasnt a number");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
String newname=null;
|
||||
String newname = null;
|
||||
NBTTagCompound compound = ServerCloneController.Instance.getCloneData(this.pcParam, name, tab);
|
||||
if(compound == null){
|
||||
sendmessage("Unknown npc");
|
||||
return false;
|
||||
if (compound == null) {
|
||||
sendmessage("Unknown npc");
|
||||
return false;
|
||||
}
|
||||
World world = pcParam.getEntityWorld();
|
||||
double posX = pcParam.getPlayerCoordinates().posX;
|
||||
double posY = pcParam.getPlayerCoordinates().posY;
|
||||
double posZ = pcParam.getPlayerCoordinates().posZ;
|
||||
|
||||
if(args.length > 4){
|
||||
String location = args[4];
|
||||
String[] par;
|
||||
if (location.contains(":")){
|
||||
par = location.split(":");
|
||||
location = par[1];
|
||||
world = Utils.getWorld(par[0]);
|
||||
if (world == null){
|
||||
sendmessage (String.format("'%s' is an unknown world",par[0]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (args.length > 4) {
|
||||
String location = args[4];
|
||||
String[] par;
|
||||
if (location.contains(":")) {
|
||||
par = location.split(":");
|
||||
location = par[1];
|
||||
world = Utils.getWorld(par[0]);
|
||||
if (world == null) {
|
||||
sendmessage(String.format("'%s' is an unknown world", par[0]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (location.contains(",")){
|
||||
par = location.split(",");
|
||||
if (par.length != 3){
|
||||
sendmessage("Location need be x,y,z");
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
posX = CommandBase.func_110666_a(pcParam, posX, par[0]);
|
||||
posY = CommandBase.func_110665_a(pcParam, posY, par[1].trim(), 0, 0);
|
||||
posZ = CommandBase.func_110666_a(pcParam, posZ, par[2]);
|
||||
} catch(NumberFormatException ex){
|
||||
sendmessage("Location should be in numbers");
|
||||
return false;
|
||||
}
|
||||
if (args.length > 5){
|
||||
newname = args[5];
|
||||
}
|
||||
} else {
|
||||
newname = location;
|
||||
}
|
||||
if (location.contains(",")) {
|
||||
par = location.split(",");
|
||||
if (par.length != 3) {
|
||||
sendmessage("Location need be x,y,z");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
posX = CommandBase.func_110666_a(pcParam, posX, par[0]);
|
||||
posY = CommandBase.func_110665_a(pcParam, posY, par[1].trim(), 0, 0);
|
||||
posZ = CommandBase.func_110666_a(pcParam, posZ, par[2]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("Location should be in numbers");
|
||||
return false;
|
||||
}
|
||||
if (args.length > 5) {
|
||||
newname = args[5];
|
||||
}
|
||||
} else {
|
||||
newname = location;
|
||||
}
|
||||
}
|
||||
|
||||
if (posX == 0 && posY == 0 && posZ == 0){//incase it was called from the console and not pos was given
|
||||
sendmessage ("Location needed");
|
||||
if (posX == 0 && posY == 0 && posZ == 0) {//incase it was called from the console and not pos was given
|
||||
sendmessage("Location needed");
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int x = 0; x < width; x++){
|
||||
for(int z = 0; z < height; z++){
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int z = 0; z < height; z++) {
|
||||
Entity entity = EntityList.createEntityFromNBT(compound, world);
|
||||
int xx = MathHelper.floor_double(posX) + x;
|
||||
int yy = Math.max(MathHelper.floor_double(posY) - 2, 1);
|
||||
int zz = MathHelper.floor_double(posZ) + z;
|
||||
|
||||
for(int y = 0; y < 10; y++){
|
||||
Block b = world.getBlock(xx, yy + y, zz);
|
||||
Block b2 = world.getBlock(xx, yy + y + 1, zz);
|
||||
if(b != null && (b2 == null || b2.getCollisionBoundingBoxFromPool(world, xx, yy + y + 1, zz) == null)){
|
||||
yy += y;
|
||||
break;
|
||||
}
|
||||
for (int y = 0; y < 10; y++) {
|
||||
Block b = world.getBlock(xx, yy + y, zz);
|
||||
Block b2 = world.getBlock(xx, yy + y + 1, zz);
|
||||
if (b != null && (b2 == null || b2.getCollisionBoundingBoxFromPool(world, xx, yy + y + 1, zz) == null)) {
|
||||
yy += y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
entity.setPosition(posX + 0.5 + x, yy + 1, posZ + 0.5 + z);
|
||||
if(entity instanceof EntityNPCInterface){
|
||||
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
||||
npc.ai.startPos = new int[]{xx, yy, zz};
|
||||
if(newname != null && !newname.isEmpty())
|
||||
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
|
||||
if (entity instanceof EntityNPCInterface) {
|
||||
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
||||
npc.ais.startPos = new int[]{xx, yy, zz};
|
||||
if (newname != null && !newname.isEmpty())
|
||||
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
|
||||
}
|
||||
world.spawnEntityInWorld(entity);
|
||||
}
|
||||
|
||||
@@ -5,208 +5,202 @@ import foxz.commandhelper.annotations.Command;
|
||||
import foxz.commandhelper.annotations.SubCommand;
|
||||
import foxz.commandhelper.permissions.OpOnly;
|
||||
import foxz.commandhelper.permissions.PlayerOnly;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumConfigOperation;
|
||||
import kamkeel.npcs.network.packets.data.ConfigCommandPacket;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockIce;
|
||||
import net.minecraft.block.BlockLeavesBase;
|
||||
import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.config.ConfigItem;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.controllers.ChunkController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
@Command(
|
||||
name="config",
|
||||
desc="Some config things you can set ",
|
||||
usage=""
|
||||
name = "config",
|
||||
desc = "Some config things you can set ",
|
||||
usage = ""
|
||||
)
|
||||
public class CmdConfig extends ChMcLogger {
|
||||
|
||||
public CmdConfig(Object sender) {
|
||||
super (sender);
|
||||
super(sender);
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Disable/Enable the natural leaves decay",
|
||||
usage="<true/false>",
|
||||
permissions={OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
desc = "Disable/Enable the natural leaves decay",
|
||||
usage = "<true/false>",
|
||||
permissions = {OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
)
|
||||
public boolean leavesdecay(String[] args){
|
||||
if(args.length == 0){
|
||||
sendmessage("LeavesDecay: " + ConfigMain.LeavesDecayEnabled);
|
||||
}
|
||||
else{
|
||||
ConfigMain.LeavesDecayEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.LeavesDecayEnabledProperty.set(ConfigMain.LeavesDecayEnabled);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
public boolean leavesdecay(String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendmessage("LeavesDecay: " + ConfigMain.LeavesDecayEnabled);
|
||||
} else {
|
||||
ConfigMain.LeavesDecayEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.LeavesDecayEnabledProperty.set(ConfigMain.LeavesDecayEnabled);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
Set<String> names = Block.blockRegistry.getKeys();
|
||||
for(String name : names){
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if(block instanceof BlockLeavesBase){
|
||||
block.setTickRandomly(ConfigMain.LeavesDecayEnabled);
|
||||
}
|
||||
for (String name : names) {
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if (block instanceof BlockLeavesBase) {
|
||||
block.setTickRandomly(ConfigMain.LeavesDecayEnabled);
|
||||
}
|
||||
}
|
||||
sendmessage("LeavesDecay is now " + ConfigMain.LeavesDecayEnabled);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Disable/Enable the vines growing",
|
||||
usage="<true/false>",
|
||||
permissions={OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
desc = "Disable/Enable the vines growing",
|
||||
usage = "<true/false>",
|
||||
permissions = {OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
)
|
||||
public boolean vinegrowth(String[] args){
|
||||
if(args.length == 0){
|
||||
sendmessage("VineGrowth: " + ConfigMain.VineGrowthEnabled);
|
||||
}
|
||||
else{
|
||||
ConfigMain.VineGrowthEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.VineGrowthEnabledProperty.set(ConfigMain.VineGrowthEnabled);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
public boolean vinegrowth(String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendmessage("VineGrowth: " + ConfigMain.VineGrowthEnabled);
|
||||
} else {
|
||||
ConfigMain.VineGrowthEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.VineGrowthEnabledProperty.set(ConfigMain.VineGrowthEnabled);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
Set<String> names = Block.blockRegistry.getKeys();
|
||||
for(String name : names){
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if(block instanceof BlockVine){
|
||||
block.setTickRandomly(ConfigMain.VineGrowthEnabled);
|
||||
}
|
||||
for (String name : names) {
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if (block instanceof BlockVine) {
|
||||
block.setTickRandomly(ConfigMain.VineGrowthEnabled);
|
||||
}
|
||||
}
|
||||
sendmessage("VineGrowth is now " + ConfigMain.VineGrowthEnabled);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Disable/Enable the ice melting",
|
||||
usage="<true/false>",
|
||||
permissions={OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
desc = "Disable/Enable the ice melting",
|
||||
usage = "<true/false>",
|
||||
permissions = {OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
)
|
||||
public boolean icemelts(String[] args){
|
||||
if(args.length == 0){
|
||||
sendmessage("IceMelts: " + ConfigMain.IceMeltsEnabled);
|
||||
}
|
||||
else{
|
||||
ConfigMain.IceMeltsEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.IceMeltsEnabledProperty.set(ConfigMain.IceMeltsEnabled);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
public boolean icemelts(String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendmessage("IceMelts: " + ConfigMain.IceMeltsEnabled);
|
||||
} else {
|
||||
ConfigMain.IceMeltsEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.IceMeltsEnabledProperty.set(ConfigMain.IceMeltsEnabled);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
Set<String> names = Block.blockRegistry.getKeys();
|
||||
for(String name : names){
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if(block instanceof BlockIce){
|
||||
block.setTickRandomly(ConfigMain.IceMeltsEnabled);
|
||||
}
|
||||
for (String name : names) {
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if (block instanceof BlockIce) {
|
||||
block.setTickRandomly(ConfigMain.IceMeltsEnabled);
|
||||
}
|
||||
}
|
||||
sendmessage("IceMelts is now " + ConfigMain.IceMeltsEnabled);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Disable/Enable guns shooting",
|
||||
usage="<true/false>",
|
||||
permissions={OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
desc = "Disable/Enable guns shooting",
|
||||
usage = "<true/false>",
|
||||
permissions = {OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
)
|
||||
public boolean guns(String[] args){
|
||||
if(args.length == 0){
|
||||
sendmessage("GunsEnabled: " + ConfigMain.GunsEnabled);
|
||||
}
|
||||
else{
|
||||
ConfigMain.GunsEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.GunsEnabledProperty.set(ConfigMain.GunsEnabled);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendmessage("GunsEnabled is now " + ConfigMain.GunsEnabled);
|
||||
}
|
||||
public boolean guns(String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendmessage("GunsEnabled: " + ConfigItem.GunsEnabled);
|
||||
} else {
|
||||
ConfigItem.GunsEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigItem.GunsEnabledProperty.set(ConfigItem.GunsEnabled);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendmessage("GunsEnabled is now " + ConfigItem.GunsEnabled);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Freezes/Unfreezes npcs",
|
||||
usage="<true/false>",
|
||||
permissions={OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
desc = "Freezes/Unfreezes npcs",
|
||||
usage = "<true/false>",
|
||||
permissions = {OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
)
|
||||
public boolean freezenpcs(String[] args){
|
||||
if(args.length == 0){
|
||||
sendmessage("Frozen NPCs: " + CustomNpcs.FreezeNPCs);
|
||||
}
|
||||
else{
|
||||
CustomNpcs.FreezeNPCs = Boolean.parseBoolean(args[0]);
|
||||
public boolean freezenpcs(String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendmessage("Frozen NPCs: " + CustomNpcs.FreezeNPCs);
|
||||
} else {
|
||||
CustomNpcs.FreezeNPCs = Boolean.parseBoolean(args[0]);
|
||||
sendmessage("FrozenNPCs is now " + CustomNpcs.FreezeNPCs);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Set how many active chunkloaders you can have",
|
||||
usage="<number>",
|
||||
permissions={OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
desc = "Set how many active chunkloaders you can have",
|
||||
usage = "<number>",
|
||||
permissions = {OpOnly.class},
|
||||
hasEmptyCall = true
|
||||
)
|
||||
public boolean chunkloaders(String[] args){
|
||||
if(args.length == 0){
|
||||
sendmessage("ChunkLoaders: " + ChunkController.Instance.size() + "/" + ConfigMain.ChunkLoaders);
|
||||
}
|
||||
else{
|
||||
try{
|
||||
ConfigMain.ChunkLoaders = Integer.parseInt(args[0]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
sendmessage("Didnt get a number");
|
||||
return false;
|
||||
}
|
||||
public boolean chunkloaders(String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendmessage("ChunkLoaders: " + ChunkController.Instance.size() + "/" + ConfigMain.ChunkLoaders);
|
||||
} else {
|
||||
try {
|
||||
ConfigMain.ChunkLoaders = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("Didnt get a number");
|
||||
return false;
|
||||
}
|
||||
|
||||
ConfigMain.ChunkLoadersProperty.set(ConfigMain.ChunkLoaders);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
int size = ChunkController.Instance.size();
|
||||
if(size > ConfigMain.ChunkLoaders){
|
||||
ChunkController.Instance.unload(size - ConfigMain.ChunkLoaders);
|
||||
sendmessage(size - ConfigMain.ChunkLoaders + " chunksloaders unloaded");
|
||||
}
|
||||
sendmessage("ChunkLoaders: " + ChunkController.Instance.size() + "/" + ConfigMain.ChunkLoaders);
|
||||
}
|
||||
ConfigMain.ChunkLoadersProperty.set(ConfigMain.ChunkLoaders);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
int size = ChunkController.Instance.size();
|
||||
if (size > ConfigMain.ChunkLoaders) {
|
||||
ChunkController.Instance.unload(size - ConfigMain.ChunkLoaders);
|
||||
sendmessage(size - ConfigMain.ChunkLoaders + " chunksloaders unloaded");
|
||||
}
|
||||
sendmessage("ChunkLoaders: " + ChunkController.Instance.size() + "/" + ConfigMain.ChunkLoaders);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc="Get/Set font",
|
||||
usage="[type] [size]",
|
||||
permissions={PlayerOnly.class},
|
||||
hasEmptyCall = true
|
||||
desc = "Get/Set font",
|
||||
usage = "[type] [size]",
|
||||
permissions = {PlayerOnly.class},
|
||||
hasEmptyCall = true
|
||||
)
|
||||
public void font(String[] args){
|
||||
int size = 18;
|
||||
if(args.length > 1){
|
||||
try{
|
||||
size = Integer.parseInt(args[args.length - 1]);
|
||||
args = Arrays.copyOfRange(args, 0, args.length - 1);
|
||||
}
|
||||
catch(Exception e){
|
||||
public void font(String[] args) {
|
||||
int size = 18;
|
||||
if (args.length > 1) {
|
||||
try {
|
||||
size = Integer.parseInt(args[args.length - 1]);
|
||||
args = Arrays.copyOfRange(args, 0, args.length - 1);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
String font = "";
|
||||
for(int i = 0; i < args.length; i++){
|
||||
font += " " + args[i];
|
||||
}
|
||||
Server.sendData((EntityPlayerMP)this.pcParam, EnumPacketClient.CONFIG, 0, font.trim(), size);
|
||||
}
|
||||
}
|
||||
String font = "";
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
font += " " + args[i];
|
||||
}
|
||||
PacketHandler.Instance.sendToPlayer(new ConfigCommandPacket(EnumConfigOperation.FONT, font.trim(), size), (EntityPlayerMP) this.pcParam);
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ import foxz.commandhelper.annotations.Command;
|
||||
import foxz.commandhelper.annotations.SubCommand;
|
||||
import foxz.commandhelper.permissions.OpOnly;
|
||||
import foxz.commandhelper.permissions.ParamCheck;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.client.EntityUtil;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogOption;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
@@ -19,9 +19,9 @@ import noppes.npcs.entity.EntityDialogNpc;
|
||||
import java.util.List;
|
||||
|
||||
@Command(
|
||||
name="dialog",
|
||||
desc="dialog operations",
|
||||
usage="help"
|
||||
name = "dialog",
|
||||
desc = "dialog operations",
|
||||
usage = "help"
|
||||
)
|
||||
public class CmdDialog extends ChMcLogger {
|
||||
|
||||
@@ -31,15 +31,15 @@ public class CmdDialog extends ChMcLogger {
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc="force read",
|
||||
usage="<player> <dialog>",
|
||||
permissions={OpOnly.class, ParamCheck.class}
|
||||
desc = "force read",
|
||||
usage = "<player> <dialog>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public boolean read(String args[]){
|
||||
String playername=args[0];
|
||||
public boolean read(String args[]) {
|
||||
String playername = args[0];
|
||||
int diagid;
|
||||
try {
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("DialogID must be an integer");
|
||||
return false;
|
||||
@@ -49,24 +49,24 @@ public class CmdDialog extends ChMcLogger {
|
||||
sendmessage(String.format("Unknow player '%s'", playername));
|
||||
return false;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.dialogData.dialogsRead.add(diagid);
|
||||
playerdata.save();
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.dialogData.dialogsRead.add(diagid);
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="force unread dialog",
|
||||
usage="<player> <dialog>",
|
||||
permissions={OpOnly.class, ParamCheck.class}
|
||||
desc = "force unread dialog",
|
||||
usage = "<player> <dialog>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public boolean unread(String args[]){
|
||||
String playername=args[0];
|
||||
public boolean unread(String args[]) {
|
||||
String playername = args[0];
|
||||
int diagid;
|
||||
try {
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("DialogID must be an integer");
|
||||
return false;
|
||||
@@ -76,56 +76,57 @@ public class CmdDialog extends ChMcLogger {
|
||||
sendmessage(String.format("Unknow player '%s'", playername));
|
||||
return false;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.dialogData.dialogsRead.remove(diagid);
|
||||
playerdata.save();
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.dialogData.dialogsRead.remove(diagid);
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="reload dialogs from disk",
|
||||
permissions={OpOnly.class}
|
||||
desc = "reload dialogs from disk",
|
||||
permissions = {OpOnly.class}
|
||||
)
|
||||
public boolean reload(String args[]){
|
||||
new DialogController().load();
|
||||
public boolean reload(String args[]) {
|
||||
new DialogController().load();
|
||||
SyncController.syncAllDialogs();
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc="show dialog",
|
||||
usage="<player> <dialog> <name>",
|
||||
permissions={OpOnly.class}
|
||||
desc = "show dialog",
|
||||
usage = "<player> <dialog> <name>",
|
||||
permissions = {OpOnly.class}
|
||||
)
|
||||
public void show(String args[]){
|
||||
EntityPlayer player = CommandBase.getPlayer(pcParam, args[0]);
|
||||
if(player == null){
|
||||
public void show(String args[]) {
|
||||
EntityPlayer player = CommandBase.getPlayer(pcParam, args[0]);
|
||||
if (player == null) {
|
||||
sendmessage(String.format("Unknow player '%s'", args[0]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int diagid;
|
||||
try {
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("DialogID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
Dialog dialog = DialogController.Instance.dialogs.get(diagid);
|
||||
if(dialog == null){
|
||||
if (dialog == null) {
|
||||
sendmessage("Unknown dialog id: " + args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
EntityDialogNpc npc = new EntityDialogNpc(this.pcParam.getEntityWorld());
|
||||
npc.display.name = args[2];
|
||||
EntityUtil.Copy(player, npc);
|
||||
DialogOption option = new DialogOption();
|
||||
option.dialogId = diagid;
|
||||
option.title = dialog.title;
|
||||
npc.dialogs.put(0, option);
|
||||
NoppesUtilServer.openDialog(player, npc, dialog, 0);
|
||||
EntityDialogNpc npc = new EntityDialogNpc(this.pcParam.getEntityWorld());
|
||||
npc.display.name = args[2];
|
||||
EntityUtil.Copy(player, npc);
|
||||
DialogOption option = new DialogOption();
|
||||
option.dialogId = diagid;
|
||||
option.title = dialog.title;
|
||||
npc.dialogs.put(0, option);
|
||||
NoppesUtilServer.openDialog(player, npc, dialog, 0);
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ import noppes.npcs.controllers.data.PlayerFactionData;
|
||||
import java.util.List;
|
||||
|
||||
@Command(
|
||||
name = "faction",
|
||||
desc = "operations about relationship between player and faction"
|
||||
name = "faction",
|
||||
desc = "operations about relationship between player and faction"
|
||||
)
|
||||
public class CmdFaction extends ChMcLogger {
|
||||
|
||||
@@ -27,9 +27,9 @@ public class CmdFaction extends ChMcLogger {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Add points",
|
||||
usage = "<points>",
|
||||
permissions={OpOnly.class, ParamCheck.class}
|
||||
desc = "Add points",
|
||||
usage = "<points>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean add(String[] args) {
|
||||
int points;
|
||||
@@ -41,8 +41,8 @@ public class CmdFaction extends ChMcLogger {
|
||||
}
|
||||
int factionid = this.selectedFaction.id;
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
for (PlayerData playerdata : data) {
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.increasePoints(factionid, points, playerdata.player);
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
@@ -50,9 +50,9 @@ public class CmdFaction extends ChMcLogger {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Substract points",
|
||||
usage = "<points>",
|
||||
permissions={OpOnly.class, ParamCheck.class}
|
||||
desc = "Substract points",
|
||||
usage = "<points>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean subtract(String[] args) {
|
||||
int points;
|
||||
@@ -63,8 +63,8 @@ public class CmdFaction extends ChMcLogger {
|
||||
return false;
|
||||
}
|
||||
int factionid = this.selectedFaction.id;
|
||||
for(PlayerData playerdata : data){
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
for (PlayerData playerdata : data) {
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.increasePoints(factionid, -points, playerdata.player);
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
@@ -72,22 +72,22 @@ public class CmdFaction extends ChMcLogger {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Reset points to default",
|
||||
usage = "",
|
||||
permissions={OpOnly.class}
|
||||
desc = "Reset points to default",
|
||||
usage = "",
|
||||
permissions = {OpOnly.class}
|
||||
)
|
||||
public Boolean reset(String[] args) {
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.factionData.factionData.put(this.selectedFaction.id, this.selectedFaction.defaultPoints);
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.factionData.factionData.put(this.selectedFaction.id, this.selectedFaction.defaultPoints);
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set points",
|
||||
usage = "<points>",
|
||||
permissions={OpOnly.class, ParamCheck.class}
|
||||
desc = "Set points",
|
||||
usage = "<points>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean set(String[] args) {
|
||||
int points;
|
||||
@@ -97,22 +97,22 @@ public class CmdFaction extends ChMcLogger {
|
||||
sendmessage("Must be an integer");
|
||||
return false;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.factionData.put(this.selectedFaction.id,points);
|
||||
for (PlayerData playerdata : data) {
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.factionData.put(this.selectedFaction.id, points);
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Drop relationship",
|
||||
usage="",
|
||||
permissions={OpOnly.class}
|
||||
desc = "Drop relationship",
|
||||
usage = "",
|
||||
permissions = {OpOnly.class}
|
||||
)
|
||||
public Boolean drop(String[] args){
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.factionData.factionData.remove(this.selectedFaction.id);
|
||||
public Boolean drop(String[] args) {
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.factionData.factionData.remove(this.selectedFaction.id);
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -30,194 +30,194 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import java.util.*;
|
||||
|
||||
@Command(
|
||||
name = "noppes",
|
||||
desc = "noppes root command",
|
||||
sub = {CmdClone.class, CmdScript.class, CmdQuest.class, CmdDialog.class, CmdConfig.class}
|
||||
name = "noppes",
|
||||
desc = "noppes root command",
|
||||
sub = {CmdClone.class, CmdScript.class, CmdQuest.class, CmdDialog.class, CmdConfig.class}
|
||||
)
|
||||
public class CmdNoppes extends ChMcLogger {
|
||||
|
||||
public CmdFaction cmdfaction = new CmdFaction(ctorParm);
|
||||
public CmdNpc cmdnpc = new CmdNpc(ctorParm);
|
||||
public static Map<String, Class<?>> SlayMap = new LinkedHashMap<String, Class<?>>();
|
||||
public CmdFaction cmdfaction = new CmdFaction(ctorParm);
|
||||
public CmdNpc cmdnpc = new CmdNpc(ctorParm);
|
||||
public static Map<String, Class<?>> SlayMap = new LinkedHashMap<String, Class<?>>();
|
||||
|
||||
public CmdNoppes(Object sender) {
|
||||
super(sender);
|
||||
public CmdNoppes(Object sender) {
|
||||
super(sender);
|
||||
|
||||
SlayMap.clear();
|
||||
SlayMap.clear();
|
||||
|
||||
SlayMap.put("all", EntityLivingBase.class);
|
||||
SlayMap.put("mobs", EntityMob.class);
|
||||
SlayMap.put("animals", EntityAnimal.class);
|
||||
SlayMap.put("items", EntityItem.class);
|
||||
SlayMap.put("xporbs", EntityXPOrb.class);
|
||||
SlayMap.put("npcs", EntityNPCInterface.class);
|
||||
SlayMap.put("all", EntityLivingBase.class);
|
||||
SlayMap.put("mobs", EntityMob.class);
|
||||
SlayMap.put("animals", EntityAnimal.class);
|
||||
SlayMap.put("items", EntityItem.class);
|
||||
SlayMap.put("xporbs", EntityXPOrb.class);
|
||||
SlayMap.put("npcs", EntityNPCInterface.class);
|
||||
|
||||
HashMap<String, Class<?>> list = new HashMap<String, Class<?>>(EntityList.stringToClassMapping);
|
||||
for (String name : list.keySet()) {
|
||||
Class<?> cls = list.get(name);
|
||||
if (EntityNPCInterface.class.isAssignableFrom(cls))
|
||||
continue;
|
||||
if (!EntityLivingBase.class.isAssignableFrom(cls))
|
||||
continue;
|
||||
SlayMap.put(name.toLowerCase(), list.get(name));
|
||||
}
|
||||
HashMap<String, Class<?>> list = new HashMap<String, Class<?>>(EntityList.stringToClassMapping);
|
||||
for (String name : list.keySet()) {
|
||||
Class<?> cls = list.get(name);
|
||||
if (EntityNPCInterface.class.isAssignableFrom(cls))
|
||||
continue;
|
||||
if (!EntityLivingBase.class.isAssignableFrom(cls))
|
||||
continue;
|
||||
SlayMap.put(name.toLowerCase(), list.get(name));
|
||||
}
|
||||
|
||||
SlayMap.remove("monster");
|
||||
SlayMap.remove("mob");
|
||||
}
|
||||
SlayMap.remove("monster");
|
||||
SlayMap.remove("mob");
|
||||
}
|
||||
|
||||
|
||||
@SubCommand(
|
||||
name = "faction",
|
||||
desc = "Faction operations",
|
||||
usage = "<player> <faction> <command>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean faction(String[] args) {
|
||||
String playername = args[0];
|
||||
String factionname = args[1];
|
||||
@SubCommand(
|
||||
name = "faction",
|
||||
desc = "Faction operations",
|
||||
usage = "<player> <faction> <command>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean faction(String[] args) {
|
||||
String playername = args[0];
|
||||
String factionname = args[1];
|
||||
|
||||
cmdfaction.data = getPlayersData(playername);
|
||||
if (cmdfaction.data.isEmpty()) {
|
||||
sendmessage(String.format("Unknow player '%s'", playername));
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
cmdfaction.selectedFaction = FactionController.getInstance().get(Integer.parseInt(factionname));
|
||||
} catch (NumberFormatException e) {
|
||||
cmdfaction.selectedFaction = FactionController.getInstance().getFactionFromName(factionname); // get faction data
|
||||
}
|
||||
if (cmdfaction.selectedFaction == null) {
|
||||
sendmessage(String.format("Unknow facion '%s", factionname));
|
||||
return false;
|
||||
}
|
||||
args = Arrays.copyOfRange(args, 2, args.length);
|
||||
cmdfaction.processCommand(this.pcParam, args);
|
||||
cmdfaction.data = getPlayersData(playername);
|
||||
if (cmdfaction.data.isEmpty()) {
|
||||
sendmessage(String.format("Unknow player '%s'", playername));
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
cmdfaction.selectedFaction = FactionController.getInstance().get(Integer.parseInt(factionname));
|
||||
} catch (NumberFormatException e) {
|
||||
cmdfaction.selectedFaction = FactionController.getInstance().getFactionFromName(factionname); // get faction data
|
||||
}
|
||||
if (cmdfaction.selectedFaction == null) {
|
||||
sendmessage(String.format("Unknow facion '%s", factionname));
|
||||
return false;
|
||||
}
|
||||
args = Arrays.copyOfRange(args, 2, args.length);
|
||||
cmdfaction.processCommand(this.pcParam, args);
|
||||
|
||||
for (PlayerData playerdata : cmdfaction.data) {
|
||||
playerdata.save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
for (PlayerData playerdata : cmdfaction.data) {
|
||||
playerdata.save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "NPC manipulations",
|
||||
usage = "<npc> <command>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public boolean npc(String[] args) {
|
||||
String npcname = args[0].replace("%", " ");
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
if (args[0].equalsIgnoreCase("create")) {
|
||||
cmdnpc.processCommand(this.pcParam, new String[]{args[0], npcname});
|
||||
return true;
|
||||
}
|
||||
int x = pcParam.getPlayerCoordinates().posX;
|
||||
int y = pcParam.getPlayerCoordinates().posY;
|
||||
int z = pcParam.getPlayerCoordinates().posZ;
|
||||
List<EntityNPCInterface> list = getNearbeEntityFromPlayer(EntityNPCInterface.class, pcParam.getEntityWorld(), x, y, z, 80);
|
||||
EntityNPCInterface closest = null;
|
||||
for (EntityNPCInterface npc : list) {
|
||||
String name = npc.display.name.replace(" ", "_");
|
||||
if (name.equalsIgnoreCase(npcname)) {
|
||||
if (closest == null || closest.getDistanceSq(x, y, z) > npc.getDistanceSq(x, y, z))
|
||||
closest = npc;
|
||||
}
|
||||
}
|
||||
if (closest != null) {
|
||||
cmdnpc.selectedNpc = closest;
|
||||
cmdnpc.processCommand(this.pcParam, args);
|
||||
cmdnpc.selectedNpc = null;
|
||||
} else
|
||||
sendmessage(String.format("NPC '%s' was not found", npcname));
|
||||
return true;
|
||||
}
|
||||
@SubCommand(
|
||||
desc = "NPC manipulations",
|
||||
usage = "<npc> <command>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public boolean npc(String[] args) {
|
||||
String npcname = args[0].replace("%", " ");
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
if (args[0].equalsIgnoreCase("create")) {
|
||||
cmdnpc.processCommand(this.pcParam, new String[]{args[0], npcname});
|
||||
return true;
|
||||
}
|
||||
int x = pcParam.getPlayerCoordinates().posX;
|
||||
int y = pcParam.getPlayerCoordinates().posY;
|
||||
int z = pcParam.getPlayerCoordinates().posZ;
|
||||
List<EntityNPCInterface> list = getNearbeEntityFromPlayer(EntityNPCInterface.class, pcParam.getEntityWorld(), x, y, z, 80);
|
||||
EntityNPCInterface closest = null;
|
||||
for (EntityNPCInterface npc : list) {
|
||||
String name = npc.display.name.replace(" ", "_");
|
||||
if (name.equalsIgnoreCase(npcname)) {
|
||||
if (closest == null || closest.getDistanceSq(x, y, z) > npc.getDistanceSq(x, y, z))
|
||||
closest = npc;
|
||||
}
|
||||
}
|
||||
if (closest != null) {
|
||||
cmdnpc.selectedNpc = closest;
|
||||
cmdnpc.processCommand(this.pcParam, args);
|
||||
cmdnpc.selectedNpc = null;
|
||||
} else
|
||||
sendmessage(String.format("NPC '%s' was not found", npcname));
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
name = "slay",
|
||||
desc = "Kills given entity within range. Also has all, mobs, animal options. Can have multiple types",
|
||||
usage = "<type>.. [range]",
|
||||
permissions = {PlayerOnly.class, OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean slay(String[] args) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) pcParam;
|
||||
ArrayList<Class<?>> toDelete = new ArrayList<Class<?>>();
|
||||
boolean deleteNPCs = false;
|
||||
for (String delete : args) {
|
||||
delete = delete.toLowerCase();
|
||||
Class<?> cls = SlayMap.get(delete);
|
||||
if (cls != null)
|
||||
toDelete.add(cls);
|
||||
if (delete.equals("mobs")) {
|
||||
toDelete.add(EntityGhast.class);
|
||||
toDelete.add(EntityDragon.class);
|
||||
}
|
||||
if (delete.equals("npcs"))
|
||||
deleteNPCs = true;
|
||||
}
|
||||
int count = 0;
|
||||
int range = 120;
|
||||
try {
|
||||
range = Integer.parseInt(args[args.length - 1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
@SubCommand(
|
||||
name = "slay",
|
||||
desc = "Kills given entity within range. Also has all, mobs, animal options. Can have multiple types",
|
||||
usage = "<type>.. [range]",
|
||||
permissions = {PlayerOnly.class, OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean slay(String[] args) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) pcParam;
|
||||
ArrayList<Class<?>> toDelete = new ArrayList<Class<?>>();
|
||||
boolean deleteNPCs = false;
|
||||
for (String delete : args) {
|
||||
delete = delete.toLowerCase();
|
||||
Class<?> cls = SlayMap.get(delete);
|
||||
if (cls != null)
|
||||
toDelete.add(cls);
|
||||
if (delete.equals("mobs")) {
|
||||
toDelete.add(EntityGhast.class);
|
||||
toDelete.add(EntityDragon.class);
|
||||
}
|
||||
if (delete.equals("npcs"))
|
||||
deleteNPCs = true;
|
||||
}
|
||||
int count = 0;
|
||||
int range = 120;
|
||||
try {
|
||||
range = Integer.parseInt(args[args.length - 1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
|
||||
}
|
||||
AxisAlignedBB box = player.boundingBox.expand(range, range, range);
|
||||
List<Entity> list = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, box);
|
||||
}
|
||||
AxisAlignedBB box = player.boundingBox.expand(range, range, range);
|
||||
List<Entity> list = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, box);
|
||||
|
||||
for (Entity entity : list) {
|
||||
if (entity instanceof EntityPlayer)
|
||||
continue;
|
||||
if (entity instanceof EntityTameable && ((EntityTameable) entity).isTamed())
|
||||
continue;
|
||||
if (entity instanceof EntityNPCInterface && !deleteNPCs)
|
||||
continue;
|
||||
if (delete(entity, toDelete))
|
||||
count++;
|
||||
}
|
||||
if (toDelete.contains(EntityXPOrb.class)) {
|
||||
list = player.worldObj.getEntitiesWithinAABB(EntityXPOrb.class, box);
|
||||
for (Entity entity : list) {
|
||||
entity.isDead = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (toDelete.contains(EntityItem.class)) {
|
||||
list = player.worldObj.getEntitiesWithinAABB(EntityItem.class, box);
|
||||
for (Entity entity : list) {
|
||||
entity.isDead = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
for (Entity entity : list) {
|
||||
if (entity instanceof EntityPlayer)
|
||||
continue;
|
||||
if (entity instanceof EntityTameable && ((EntityTameable) entity).isTamed())
|
||||
continue;
|
||||
if (entity instanceof EntityNPCInterface && !deleteNPCs)
|
||||
continue;
|
||||
if (delete(entity, toDelete))
|
||||
count++;
|
||||
}
|
||||
if (toDelete.contains(EntityXPOrb.class)) {
|
||||
list = player.worldObj.getEntitiesWithinAABB(EntityXPOrb.class, box);
|
||||
for (Entity entity : list) {
|
||||
entity.isDead = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (toDelete.contains(EntityItem.class)) {
|
||||
list = player.worldObj.getEntitiesWithinAABB(EntityItem.class, box);
|
||||
for (Entity entity : list) {
|
||||
entity.isDead = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
player.addChatMessage(new ChatComponentTranslation(count + " entities deleted"));
|
||||
return true;
|
||||
}
|
||||
player.addChatMessage(new ChatComponentTranslation(count + " entities deleted"));
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean delete(Entity entity, ArrayList<Class<?>> toDelete) {
|
||||
for (Class<?> delete : toDelete) {
|
||||
if (delete == EntityAnimal.class && (entity instanceof EntityHorse)) {
|
||||
continue;
|
||||
}
|
||||
if (delete.isAssignableFrom(entity.getClass())) {
|
||||
entity.isDead = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private boolean delete(Entity entity, ArrayList<Class<?>> toDelete) {
|
||||
for (Class<?> delete : toDelete) {
|
||||
if (delete == EntityAnimal.class && (entity instanceof EntityHorse)) {
|
||||
continue;
|
||||
}
|
||||
if (delete.isAssignableFrom(entity.getClass())) {
|
||||
entity.isDead = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
if (args[0].equalsIgnoreCase("slay")) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, SlayMap.keySet().toArray(new String[SlayMap.size()]));
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("npc") && args.length == 3) {
|
||||
return cmdnpc.addTabCompletion(par1, Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("faction") && args.length == 4) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, new String[]{"add", "subtract", "set", "reset", "drop", "create"});
|
||||
}
|
||||
return super.addTabCompletion(par1, args);
|
||||
}
|
||||
@Override
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
if (args[0].equalsIgnoreCase("slay")) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, SlayMap.keySet().toArray(new String[SlayMap.size()]));
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("npc") && args.length == 3) {
|
||||
return cmdnpc.addTabCompletion(par1, Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("faction") && args.length == 4) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, new String[]{"add", "subtract", "set", "reset", "drop", "create"});
|
||||
}
|
||||
return super.addTabCompletion(par1, args);
|
||||
}
|
||||
}
|
||||
@@ -22,143 +22,142 @@ import noppes.npcs.roles.RoleFollower;
|
||||
import java.util.List;
|
||||
|
||||
@Command(
|
||||
name="npc",
|
||||
desc="NPC manipulation",
|
||||
usage="<name> <command>"
|
||||
name = "npc",
|
||||
desc = "NPC manipulation",
|
||||
usage = "<name> <command>"
|
||||
)
|
||||
public class CmdNpc extends ChMcLogger {
|
||||
|
||||
CmdNpc(Object ctorParm) {
|
||||
super (ctorParm);
|
||||
super(ctorParm);
|
||||
}
|
||||
|
||||
public EntityNPCInterface selectedNpc;
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc="Set Home (respawn place)",
|
||||
usage=""
|
||||
desc = "Set Home (respawn place)",
|
||||
usage = ""
|
||||
)
|
||||
public void home(String[] args){
|
||||
public void home(String[] args) {
|
||||
double posX = pcParam.getPlayerCoordinates().posX;
|
||||
double posY = pcParam.getPlayerCoordinates().posY;
|
||||
double posZ = pcParam.getPlayerCoordinates().posZ;
|
||||
|
||||
if(args.length == 3){
|
||||
if (args.length == 3) {
|
||||
posX = CommandBase.func_110666_a(pcParam, selectedNpc.posX, args[0]);
|
||||
posY = CommandBase.func_110665_a(pcParam, selectedNpc.posY, args[1].trim(), 0, 0);
|
||||
posZ = CommandBase.func_110666_a(pcParam, selectedNpc.posZ, args[2]);
|
||||
}
|
||||
|
||||
selectedNpc.ai.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
|
||||
selectedNpc.ais.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Set npc visibility",
|
||||
usage=""
|
||||
desc = "Set npc visibility",
|
||||
usage = ""
|
||||
)
|
||||
public void visible(String[] args){
|
||||
if(args.length < 1)
|
||||
return;
|
||||
boolean bo = args[0].equalsIgnoreCase("true");
|
||||
boolean semi = args[0].equalsIgnoreCase("semi");
|
||||
public void visible(String[] args) {
|
||||
if (args.length < 1)
|
||||
return;
|
||||
boolean bo = args[0].equalsIgnoreCase("true");
|
||||
boolean semi = args[0].equalsIgnoreCase("semi");
|
||||
|
||||
int current = selectedNpc.display.visible;
|
||||
if(semi)
|
||||
selectedNpc.display.visible = 2;
|
||||
else if(bo)
|
||||
selectedNpc.display.visible = 0;
|
||||
else
|
||||
selectedNpc.display.visible = 1;
|
||||
int current = selectedNpc.display.visible;
|
||||
if (semi)
|
||||
selectedNpc.display.visible = 2;
|
||||
else if (bo)
|
||||
selectedNpc.display.visible = 0;
|
||||
else
|
||||
selectedNpc.display.visible = 1;
|
||||
|
||||
if(current != selectedNpc.display.visible)
|
||||
selectedNpc.updateClient = true;
|
||||
if (current != selectedNpc.display.visible)
|
||||
selectedNpc.updateClient = true;
|
||||
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Delete an NPC",
|
||||
usage=""
|
||||
desc = "Delete an NPC",
|
||||
usage = ""
|
||||
)
|
||||
public void delete(String[] args){
|
||||
selectedNpc.delete();
|
||||
public void delete(String[] args) {
|
||||
selectedNpc.delete();
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="Owner",
|
||||
usage=""
|
||||
desc = "Owner",
|
||||
usage = ""
|
||||
)
|
||||
public void owner(String[] args){
|
||||
if(args.length < 1){
|
||||
EntityPlayer player = null;
|
||||
if(selectedNpc.roleInterface instanceof RoleFollower)
|
||||
player = ((RoleFollower)selectedNpc.roleInterface).owner;
|
||||
public void owner(String[] args) {
|
||||
if (args.length < 1) {
|
||||
EntityPlayer player = null;
|
||||
if (selectedNpc.roleInterface instanceof RoleFollower)
|
||||
player = ((RoleFollower) selectedNpc.roleInterface).owner;
|
||||
|
||||
if(selectedNpc.roleInterface instanceof RoleCompanion)
|
||||
player = ((RoleCompanion)selectedNpc.roleInterface).owner;
|
||||
if (selectedNpc.roleInterface instanceof RoleCompanion)
|
||||
player = ((RoleCompanion) selectedNpc.roleInterface).owner;
|
||||
|
||||
if(player == null)
|
||||
sendmessage("No owner");
|
||||
else
|
||||
sendmessage("Owner is: " + player.getCommandSenderName());
|
||||
}
|
||||
else{
|
||||
EntityPlayerMP player = CommandBase.getPlayer(pcParam, args[0]);
|
||||
if(selectedNpc.roleInterface instanceof RoleFollower)
|
||||
((RoleFollower)selectedNpc.roleInterface).setOwner(player);
|
||||
if (player == null)
|
||||
sendmessage("No owner");
|
||||
else
|
||||
sendmessage("Owner is: " + player.getCommandSenderName());
|
||||
} else {
|
||||
EntityPlayerMP player = CommandBase.getPlayer(pcParam, args[0]);
|
||||
if (selectedNpc.roleInterface instanceof RoleFollower)
|
||||
((RoleFollower) selectedNpc.roleInterface).setOwner(player);
|
||||
|
||||
if(selectedNpc.roleInterface instanceof RoleCompanion)
|
||||
((RoleCompanion)selectedNpc.roleInterface).setOwner(player);
|
||||
}
|
||||
if (selectedNpc.roleInterface instanceof RoleCompanion)
|
||||
((RoleCompanion) selectedNpc.roleInterface).setOwner(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc="Set npc name",
|
||||
usage=""
|
||||
desc = "Set npc name",
|
||||
usage = ""
|
||||
)
|
||||
public void name(String[] args){
|
||||
if(args.length < 1)
|
||||
return;
|
||||
public void name(String[] args) {
|
||||
if (args.length < 1)
|
||||
return;
|
||||
|
||||
String name = args[0];
|
||||
for(int i = 1; i < args.length; i++){
|
||||
name += " " + args[i];
|
||||
}
|
||||
String name = args[0];
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
name += " " + args[i];
|
||||
}
|
||||
|
||||
if(!selectedNpc.display.name.equals(name)){
|
||||
selectedNpc.display.name = name;
|
||||
selectedNpc.updateClient = true;
|
||||
}
|
||||
if (!selectedNpc.display.name.equals(name)) {
|
||||
selectedNpc.display.name = name;
|
||||
selectedNpc.updateClient = true;
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Creates an NPC",
|
||||
usage = "[name]",
|
||||
permissions = {PlayerOnly.class, OpOnly.class}
|
||||
desc = "Creates an NPC",
|
||||
usage = "[name]",
|
||||
permissions = {PlayerOnly.class, OpOnly.class}
|
||||
)
|
||||
public void create(String[] args) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) pcParam;
|
||||
World pw = player.getEntityWorld();
|
||||
EntityCustomNpc npc = new EntityCustomNpc(pw);
|
||||
if(args.length > 0)
|
||||
npc.display.name = args[0];
|
||||
if (args.length > 0)
|
||||
npc.display.name = args[0];
|
||||
npc.setPositionAndRotation(player.posX, player.posY, player.posZ, player.cameraYaw, player.cameraPitch);
|
||||
npc.ai.startPos = new int[]{MathHelper.floor_double(player.posX),MathHelper.floor_double(player.posY),MathHelper.floor_double(player.posZ)};
|
||||
npc.ais.startPos = new int[]{MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ)};
|
||||
pw.spawnEntityInWorld(npc);
|
||||
npc.setHealth(npc.getMaxHealth());
|
||||
NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay, npc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
if(args.length == 2){
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, new String[]{"create", "home", "visible", "delete", "owner", "name"});
|
||||
}
|
||||
if(args.length == 3 && args[1].equalsIgnoreCase("owner")){
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
}
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
if (args.length == 2) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, new String[]{"create", "home", "visible", "delete", "owner", "name"});
|
||||
}
|
||||
if (args.length == 3 && args[1].equalsIgnoreCase("owner")) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
}
|
||||
|
||||
return super.addTabCompletion(par1, args);
|
||||
return super.addTabCompletion(par1, args);
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,11 @@ import foxz.commandhelper.annotations.Command;
|
||||
import foxz.commandhelper.annotations.SubCommand;
|
||||
import foxz.commandhelper.permissions.OpOnly;
|
||||
import foxz.commandhelper.permissions.ParamCheck;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
import noppes.npcs.controllers.data.QuestData;
|
||||
@@ -17,26 +17,26 @@ import noppes.npcs.controllers.data.QuestData;
|
||||
import java.util.List;
|
||||
|
||||
@Command(
|
||||
name = "quest",
|
||||
usage = "help",
|
||||
desc = "Quest operations"
|
||||
name = "quest",
|
||||
usage = "help",
|
||||
desc = "Quest operations"
|
||||
)
|
||||
public class CmdQuest extends ChMcLogger{
|
||||
public class CmdQuest extends ChMcLogger {
|
||||
|
||||
public CmdQuest(Object sender) {
|
||||
super(sender);
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Start a quest",
|
||||
usage = "<player> <quest>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
desc = "Start a quest",
|
||||
usage = "<player> <quest>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean start(String[] args) {
|
||||
String playername=args[0];
|
||||
String playername = args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
questid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("QuestID must be an integer");
|
||||
return false;
|
||||
@@ -47,37 +47,36 @@ public class CmdQuest extends ChMcLogger{
|
||||
return false;
|
||||
}
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
if (quest == null) {
|
||||
sendmessage("Unknown QuestID");
|
||||
return false;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
if(playerdata.questData.activeQuests.containsKey(questid))
|
||||
continue;
|
||||
QuestData questdata = new QuestData(quest);
|
||||
playerdata.questData.activeQuests.put(questid, questdata);
|
||||
playerdata.save();
|
||||
if(playerdata.player != null){
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
||||
}
|
||||
for (PlayerData playerdata : data) {
|
||||
if (playerdata.questData.activeQuests.containsKey(questid))
|
||||
continue;
|
||||
QuestData questdata = new QuestData(quest);
|
||||
playerdata.questData.activeQuests.put(questid, questdata);
|
||||
playerdata.save();
|
||||
if (playerdata.player != null) {
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.newquest", quest.title);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.newquest", ": ", quest.title);
|
||||
}
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Finish a quest",
|
||||
usage = "<player> <quest>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
desc = "Finish a quest",
|
||||
usage = "<player> <quest>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean finish(String args[]){
|
||||
String playername=args[0];
|
||||
public Boolean finish(String args[]) {
|
||||
String playername = args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("QuestID must be an integer");
|
||||
return false;
|
||||
}
|
||||
@@ -88,28 +87,28 @@ public class CmdQuest extends ChMcLogger{
|
||||
}
|
||||
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
if (quest == null) {
|
||||
sendmessage("Unknown QuestID");
|
||||
return false;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.questData.finishedQuests.put(questid, System.currentTimeMillis());
|
||||
playerdata.save();
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.questData.finishedQuests.put(questid, System.currentTimeMillis());
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Stop a started quest",
|
||||
usage = "<player> <quest>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
desc = "Stop a started quest",
|
||||
usage = "<player> <quest>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean stop(String[] args) {
|
||||
String playername=args[0];
|
||||
String playername = args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
questid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("QuestID must be an integer");
|
||||
return false;
|
||||
@@ -120,28 +119,28 @@ public class CmdQuest extends ChMcLogger{
|
||||
return false;
|
||||
}
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
if (quest == null) {
|
||||
sendmessage("Unknown QuestID");
|
||||
return false;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
playerdata.save();
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Removes a quest from finished and active quests",
|
||||
usage = "<player> <quest>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
desc = "Removes a quest from finished and active quests",
|
||||
usage = "<player> <quest>",
|
||||
permissions = {OpOnly.class, ParamCheck.class}
|
||||
)
|
||||
public Boolean remove(String[] args) {
|
||||
String playername=args[0];
|
||||
String playername = args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
questid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendmessage("QuestID must be an integer");
|
||||
return false;
|
||||
@@ -152,26 +151,27 @@ public class CmdQuest extends ChMcLogger{
|
||||
return false;
|
||||
}
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
if (quest == null) {
|
||||
sendmessage("Unknown QuestID");
|
||||
return false;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
playerdata.questData.finishedQuests.remove(questid);
|
||||
playerdata.save();
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
playerdata.questData.finishedQuests.remove(questid);
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="reload quests from disk",
|
||||
permissions={OpOnly.class}
|
||||
desc = "reload quests from disk",
|
||||
permissions = {OpOnly.class}
|
||||
)
|
||||
public boolean reload(String args[]){
|
||||
new QuestController().load();
|
||||
public boolean reload(String args[]) {
|
||||
new QuestController().load();
|
||||
SyncController.syncAllQuests();
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import foxz.commandhelper.permissions.OpOnly;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
@Command(
|
||||
name = "script",
|
||||
desc = "Script operation"
|
||||
name = "script",
|
||||
desc = "Script operation"
|
||||
)
|
||||
public class CmdScript extends ChMcLogger {
|
||||
|
||||
@@ -17,14 +17,14 @@ public class CmdScript extends ChMcLogger {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Reload scripts and saved data from disks script folder.",
|
||||
permissions={OpOnly.class}
|
||||
desc = "Reload scripts and saved data from disks script folder.",
|
||||
permissions = {OpOnly.class}
|
||||
)
|
||||
public Boolean reload(String args[]) {
|
||||
if(ScriptController.Instance.loadStoredData())
|
||||
sendmessage("Reload succesful");
|
||||
else
|
||||
sendmessage("Failed reloading stored data");
|
||||
if (ScriptController.Instance.loadStoredData())
|
||||
sendmessage("Reload succesful");
|
||||
else
|
||||
sendmessage("Failed reloading stored data");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,12 @@ public class CommandNoppes extends CommandBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender par1, String[] par2){
|
||||
public List addTabCompletionOptions(ICommandSender par1, String[] par2) {
|
||||
return noppes.addTabCompletion(par1, par2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel(){
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -51,12 +51,13 @@ public class ScriptedCommand extends CommandBase implements ICommand {
|
||||
public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) {
|
||||
}
|
||||
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
public int getRequiredPermissionLevel() {
|
||||
return this.permissionLevel;
|
||||
}
|
||||
|
||||
public int getPermissionLevel() { return this.getRequiredPermissionLevel(); }
|
||||
public int getPermissionLevel() {
|
||||
return this.getRequiredPermissionLevel();
|
||||
}
|
||||
|
||||
public List<?> getCommandAliases() {
|
||||
return this.aliases;
|
||||
|
||||
@@ -99,16 +99,17 @@ public abstract class AbstractCommandHelper extends CommandHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
String[] np = currentHelper.usage.split(" ");
|
||||
if(np.length < args.length)
|
||||
return null;
|
||||
if (np.length < args.length)
|
||||
return null;
|
||||
String parameter = np[args.length - 1];
|
||||
if(parameter.equals("<player>"))
|
||||
if (parameter.equals("<player>"))
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public Method method;
|
||||
@@ -144,7 +145,7 @@ public abstract class AbstractCommandHelper extends CommandHelper {
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
if ((cmd.equals("HELP") || args.length == 0) && doHelp(param, args, cmd)) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
CommandHelper ch = commands.get(cmd);
|
||||
@@ -157,8 +158,7 @@ public abstract class AbstractCommandHelper extends CommandHelper {
|
||||
f.parentCmdHelper = this;
|
||||
f.rootCmdHelper = this.rootCmdHelper;
|
||||
return f.processCommand(param, args);
|
||||
}
|
||||
else if (ch instanceof MethodSubCmd) {
|
||||
} else if (ch instanceof MethodSubCmd) {
|
||||
MethodSubCmd m = (MethodSubCmd) ch;
|
||||
m.method.setAccessible(true);
|
||||
currentHelper = ch.commandHelper;
|
||||
@@ -174,72 +174,68 @@ public abstract class AbstractCommandHelper extends CommandHelper {
|
||||
Logger.getLogger(AbstractCommandHelper.class.getName()).log(Level.SEVERE, m.commandHelper.name, ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
} else
|
||||
cmdError(cmd);
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean doHelp(ICommandSender param, String[] args, String cmd){
|
||||
boolean isHelp = cmd.equals("HELP");
|
||||
if(args.length > 0){
|
||||
cmd = args[0];
|
||||
}
|
||||
CommandHelper ch = commands.get(cmd.toUpperCase());
|
||||
if(ch != null){
|
||||
if(ch.commandHelper.hasEmptyCall && !isHelp)
|
||||
return false;
|
||||
if(ch instanceof AbstractCommandHelper){
|
||||
((AbstractCommandHelper)ch).pcParam = param;
|
||||
((AbstractCommandHelper)ch).allHelp();
|
||||
}
|
||||
else if(ch instanceof MethodSubCmd && ((MethodSubCmd)ch).commandHelper.usage.isEmpty())
|
||||
return false;
|
||||
else
|
||||
help(ch.commandHelper.name, ch.commandHelper.desc, ch.commandHelper.usage);
|
||||
}
|
||||
else
|
||||
allHelp();
|
||||
private boolean doHelp(ICommandSender param, String[] args, String cmd) {
|
||||
boolean isHelp = cmd.equals("HELP");
|
||||
if (args.length > 0) {
|
||||
cmd = args[0];
|
||||
}
|
||||
CommandHelper ch = commands.get(cmd.toUpperCase());
|
||||
if (ch != null) {
|
||||
if (ch.commandHelper.hasEmptyCall && !isHelp)
|
||||
return false;
|
||||
if (ch instanceof AbstractCommandHelper) {
|
||||
((AbstractCommandHelper) ch).pcParam = param;
|
||||
((AbstractCommandHelper) ch).allHelp();
|
||||
} else if (ch instanceof MethodSubCmd && ((MethodSubCmd) ch).commandHelper.usage.isEmpty())
|
||||
return false;
|
||||
else
|
||||
help(ch.commandHelper.name, ch.commandHelper.desc, ch.commandHelper.usage);
|
||||
} else
|
||||
allHelp();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
if(args.length <= 1){
|
||||
List<String> list = new ArrayList<String>();
|
||||
for(String command : commands.keySet())
|
||||
list.add(command.toLowerCase());
|
||||
list.add("help");
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, list.toArray(new String[list.size()]));
|
||||
}
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
if (args.length <= 1) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (String command : commands.keySet())
|
||||
list.add(command.toLowerCase());
|
||||
list.add("help");
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, list.toArray(new String[list.size()]));
|
||||
}
|
||||
CommandHelper ch = commands.get(args[0].toUpperCase());
|
||||
if(ch == null)
|
||||
return null;
|
||||
if (ch == null)
|
||||
return null;
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
currentHelper = ch.commandHelper;
|
||||
return ch.addTabCompletion(par1, args);
|
||||
}
|
||||
return ch.addTabCompletion(par1, args);
|
||||
}
|
||||
|
||||
public List<PlayerData> getPlayersData(String username){
|
||||
ArrayList<PlayerData> list = new ArrayList<PlayerData>();
|
||||
EntityPlayerMP[] players = PlayerSelector.matchPlayers(pcParam, username);
|
||||
if(players == null || players.length == 0){
|
||||
PlayerData data = PlayerDataController.Instance.getDataFromUsername(username);
|
||||
if(data != null)
|
||||
list.add(data);
|
||||
}
|
||||
else{
|
||||
for(EntityPlayer player : players){
|
||||
list.add(PlayerDataController.Instance.getPlayerData(player));
|
||||
public List<PlayerData> getPlayersData(String username) {
|
||||
ArrayList<PlayerData> list = new ArrayList<PlayerData>();
|
||||
EntityPlayerMP[] players = PlayerSelector.matchPlayers(pcParam, username);
|
||||
if (players == null || players.length == 0) {
|
||||
PlayerData data = PlayerDataController.Instance.getDataFromUsername(username);
|
||||
if (data != null)
|
||||
list.add(data);
|
||||
} else {
|
||||
for (EntityPlayer player : players) {
|
||||
list.add(PlayerDataController.Instance.getPlayerData(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
return list;
|
||||
}
|
||||
|
||||
public <T> List<T> getNearbeEntityFromPlayer(Class<? extends T> cls, World world, int x, int y, int z, int range) {
|
||||
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1).expand(range, range, range);
|
||||
List<T> list = world.getEntitiesWithinAABB(cls, bb);
|
||||
return list;
|
||||
}
|
||||
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1).expand(range, range, range);
|
||||
List<T> list = world.getEntitiesWithinAABB(cls, bb);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,10 @@ public class ChMcLogger extends AbstractCommandHelper {
|
||||
|
||||
@Override
|
||||
public void help(String cmd, String desc, String usa) {
|
||||
if(usa.isEmpty())
|
||||
sendmessage(String.format("%s = %s", cmd, desc));
|
||||
else
|
||||
sendmessage(String.format("%s %s = %s", cmd, usa, desc));
|
||||
if (usa.isEmpty())
|
||||
sendmessage(String.format("%s = %s", cmd, desc));
|
||||
else
|
||||
sendmessage(String.format("%s %s = %s", cmd, usa, desc));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,8 +13,10 @@ public abstract class CommandHelper {
|
||||
public String desc;
|
||||
public boolean hasEmptyCall;
|
||||
}
|
||||
|
||||
public Helper commandHelper = new Helper();
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List addTabCompletion(ICommandSender par1, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,9 @@ public class OpOnly extends AbstractPermission {
|
||||
|
||||
@Override
|
||||
public boolean delegate(AbstractCommandHelper parent, String[] args) {
|
||||
if(!(parent.pcParam instanceof EntityPlayer))
|
||||
return true;
|
||||
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(((EntityPlayer)parent.pcParam).getGameProfile());
|
||||
if (!(parent.pcParam instanceof EntityPlayer))
|
||||
return true;
|
||||
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(((EntityPlayer) parent.pcParam).getGameProfile());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,9 +15,9 @@ public class ParamCheck extends AbstractPermission {
|
||||
public boolean delegate(AbstractCommandHelper parent, String[] args) {
|
||||
String[] np = parent.currentHelper.usage.split(" ");
|
||||
int countRequired = 0;
|
||||
for(String command : np){
|
||||
if(command.startsWith("<"))
|
||||
countRequired++;
|
||||
for (String command : np) {
|
||||
if (command.startsWith("<"))
|
||||
countRequired++;
|
||||
}
|
||||
if (args.length < countRequired) {
|
||||
err = np[args.length] + " missing";
|
||||
|
||||
@@ -9,7 +9,6 @@ import foxz.commandhelper.AbstractCommandHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author foxz
|
||||
*/
|
||||
public class PlayerOnly extends AbstractPermission {
|
||||
|
||||
@@ -25,13 +25,13 @@ public class Market {
|
||||
private static final CacheHashMap<String, MarketCachedObject> marketCache = new CacheHashMap<>(5 * 60 * 1000, 1 * 60 * 1000);
|
||||
|
||||
public static void save(RoleTrader r, String name) {
|
||||
if(name.isEmpty())
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
NBTTagCompound roleCompound = r.writeNBT(new NBTTagCompound());
|
||||
roleCompound.setString("SaveName", name);
|
||||
putMarketCache(name, roleCompound);
|
||||
if(r.recordHistory)
|
||||
if (r.recordHistory)
|
||||
return;
|
||||
|
||||
saveFile(roleCompound);
|
||||
@@ -43,12 +43,12 @@ public class Market {
|
||||
File file1 = getFile(name);
|
||||
customNPCThread.execute(() -> {
|
||||
try {
|
||||
if(ConfigMain.MarketDatFormat){
|
||||
if (ConfigMain.MarketDatFormat) {
|
||||
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(file));
|
||||
} else {
|
||||
NBTJsonUtil.SaveFile(file, compound);
|
||||
}
|
||||
if(file1.exists()){
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file.renameTo(file1);
|
||||
@@ -58,9 +58,9 @@ public class Market {
|
||||
});
|
||||
}
|
||||
|
||||
public static void getMarket(RoleTrader role, String name){
|
||||
public static void getMarket(RoleTrader role, String name) {
|
||||
NBTTagCompound data = getMarketCache(name);
|
||||
if(data != null){
|
||||
if (data != null) {
|
||||
role.readNBT(data);
|
||||
return;
|
||||
}
|
||||
@@ -84,56 +84,53 @@ public class Market {
|
||||
}
|
||||
|
||||
|
||||
static public void load(RoleTrader role, String name){
|
||||
if(role.npc.worldObj.isRemote)
|
||||
static public void load(RoleTrader role, String name) {
|
||||
if (role.npc.worldObj.isRemote)
|
||||
return;
|
||||
File file = getFile(name);
|
||||
if(!file.exists())
|
||||
if (!file.exists())
|
||||
return;
|
||||
|
||||
try {
|
||||
if(ConfigMain.MarketDatFormat){
|
||||
if (ConfigMain.MarketDatFormat) {
|
||||
NBTTagCompound compound = NBTJsonUtil.loadNBTData(file);
|
||||
role.readNBT(compound);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
role.readNBT(NBTJsonUtil.LoadFile(file));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static File getMarketDir(){
|
||||
try{
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(),"markets");
|
||||
if(!file.exists())
|
||||
public static File getMarketDir() {
|
||||
try {
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(), "markets");
|
||||
if (!file.exists())
|
||||
file.mkdir();
|
||||
return file;
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static File getNewMarketDir(){
|
||||
try{
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(),"markets_new");
|
||||
if(file.exists()){
|
||||
public static File getNewMarketDir() {
|
||||
try {
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(), "markets_new");
|
||||
if (file.exists()) {
|
||||
return null;
|
||||
}
|
||||
file.mkdir();
|
||||
return file;
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static File getFile(String name){
|
||||
private static File getFile(String name) {
|
||||
String filename = name.toLowerCase();
|
||||
if(ConfigMain.MarketDatFormat){
|
||||
if (ConfigMain.MarketDatFormat) {
|
||||
filename += ".dat";
|
||||
} else {
|
||||
filename += ".json";
|
||||
@@ -143,27 +140,26 @@ public class Market {
|
||||
}
|
||||
|
||||
static public void setMarket(EntityNPCInterface npc, String marketName) {
|
||||
if(marketName.isEmpty())
|
||||
if (marketName.isEmpty())
|
||||
return;
|
||||
if(!getFile(marketName).exists())
|
||||
if (!getFile(marketName).exists())
|
||||
Market.save((RoleTrader) npc.roleInterface, marketName);
|
||||
|
||||
Market.getMarket((RoleTrader) npc.roleInterface, marketName);
|
||||
}
|
||||
|
||||
|
||||
public static void convertMarketFiles(final EntityPlayerMP sender, final boolean type){
|
||||
public static void convertMarketFiles(final EntityPlayerMP sender, final boolean type) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
executor.execute(() -> {
|
||||
String fileType;
|
||||
if(type){
|
||||
if (type) {
|
||||
fileType = ".dat";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fileType = ".json";
|
||||
}
|
||||
|
||||
if(sender != null){
|
||||
if (sender != null) {
|
||||
LogWriter.info("Market Conversion queued by " + sender.getCommandSenderName());
|
||||
sender.addChatMessage(new ChatComponentText("Market Conversion to " + fileType + " format"));
|
||||
}
|
||||
@@ -171,58 +167,58 @@ public class Market {
|
||||
File dir = getMarketDir();
|
||||
LogWriter.info("Converting Market to " + fileType + " format");
|
||||
File[] files = dir.listFiles(); // Get an array of all files in the directory
|
||||
if(files != null){
|
||||
if (files != null) {
|
||||
int length = files.length;
|
||||
if(length != 0){
|
||||
if(length > 100){
|
||||
if (length != 0) {
|
||||
if (length > 100) {
|
||||
LogWriter.info("Found " + length + " Market files... This may take a few minutes");
|
||||
}
|
||||
int tenPercent = (int) ((double) length * 0.1);
|
||||
int progress = 0;
|
||||
File saveDir = getNewMarketDir();
|
||||
if(saveDir == null){
|
||||
if(sender != null){
|
||||
if (saveDir == null) {
|
||||
if (sender != null) {
|
||||
sender.addChatMessage(new ChatComponentText("markets_new folder already exists please delete it or rename it"));
|
||||
}
|
||||
LogWriter.error("markets_new folder already exists please delete it or rename it");
|
||||
return;
|
||||
}
|
||||
// Load the files in parallel using a stream
|
||||
for(int i = 0; i < length; i++){
|
||||
for (int i = 0; i < length; i++) {
|
||||
File file = files[i];
|
||||
if(file.isDirectory() || (!file.getName().endsWith(".json") && !file.getName().endsWith(".dat")))
|
||||
if (file.isDirectory() || (!file.getName().endsWith(".json") && !file.getName().endsWith(".dat")))
|
||||
continue;
|
||||
try {
|
||||
String filename = "error";
|
||||
boolean valid = false;
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if(type){
|
||||
if(file.getName().endsWith(".json")){
|
||||
if (type) {
|
||||
if (file.getName().endsWith(".json")) {
|
||||
compound = NBTJsonUtil.LoadFile(file);
|
||||
if(compound.hasKey("PlayerName")) {
|
||||
if (compound.hasKey("PlayerName")) {
|
||||
filename = file.getName().substring(0, file.getName().length() - 5);
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(file.getName().endsWith(".dat")){
|
||||
if (file.getName().endsWith(".dat")) {
|
||||
compound = NBTJsonUtil.loadNBTData(file);
|
||||
if(compound.hasKey("PlayerName")){
|
||||
if (compound.hasKey("PlayerName")) {
|
||||
filename = file.getName().substring(0, file.getName().length() - 4);
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(valid){
|
||||
if (valid) {
|
||||
try {
|
||||
File newFile = new File(saveDir, filename + "_new" + fileType);
|
||||
File oldFile = new File(saveDir, filename + fileType);
|
||||
if(type){
|
||||
if (type) {
|
||||
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(newFile));
|
||||
} else {
|
||||
NBTJsonUtil.SaveFile(newFile, compound);
|
||||
}
|
||||
if(oldFile.exists()){
|
||||
if (oldFile.exists()) {
|
||||
oldFile.delete();
|
||||
}
|
||||
newFile.renameTo(oldFile);
|
||||
@@ -233,8 +229,8 @@ public class Market {
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
if(tenPercent != 0 ){
|
||||
if(progress != 100){
|
||||
if (tenPercent != 0) {
|
||||
if (progress != 100) {
|
||||
if (i % tenPercent == 0) {
|
||||
progress += 10;
|
||||
LogWriter.info("Converting Market: Progress: " + progress + "%");
|
||||
@@ -244,7 +240,7 @@ public class Market {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(sender != null){
|
||||
if (sender != null) {
|
||||
sender.addChatMessage(new ChatComponentText("Market Conversion complete"));
|
||||
}
|
||||
LogWriter.info("Market Converted - Please rename the markets_new folder to markets and restart");
|
||||
|
||||
@@ -11,23 +11,23 @@ import java.util.List;
|
||||
|
||||
public class Utils {
|
||||
|
||||
static public <T> List<T> getNearbeEntityFromPlayer(Class<? extends T> cls,EntityPlayerMP player, int dis) {
|
||||
static public <T> List<T> getNearbeEntityFromPlayer(Class<? extends T> cls, EntityPlayerMP player, int dis) {
|
||||
AxisAlignedBB range = player.boundingBox.expand(dis, dis, dis);
|
||||
List<T> list = player.worldObj.getEntitiesWithinAABB(cls, range);
|
||||
return list;
|
||||
}
|
||||
|
||||
static public EntityPlayer getOnlinePlayer(String playername){
|
||||
static public EntityPlayer getOnlinePlayer(String playername) {
|
||||
return MinecraftServer.getServer().getConfigurationManager().func_152612_a(playername);
|
||||
}
|
||||
|
||||
static public World getWorld(String t){
|
||||
WorldServer[] ws=MinecraftServer.getServer().worldServers;
|
||||
for (WorldServer w:ws){
|
||||
if (w!=null){
|
||||
if ((w.provider.dimensionId + "").equalsIgnoreCase(t)){
|
||||
return w;
|
||||
}
|
||||
static public World getWorld(String t) {
|
||||
WorldServer[] ws = MinecraftServer.getServer().worldServers;
|
||||
for (WorldServer w : ws) {
|
||||
if (w != null) {
|
||||
if ((w.provider.dimensionId + "").equalsIgnoreCase(t)) {
|
||||
return w;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
package kamkeel.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandKamkeel extends CommandBase{
|
||||
|
||||
public Map<String, CommandKamkeelBase> map = new HashMap<String, CommandKamkeelBase>();
|
||||
public HelpCommand help = new HelpCommand(this);
|
||||
public String[] alias = {"kam"};
|
||||
|
||||
public CommandKamkeel(){
|
||||
registerCommand(help);
|
||||
registerCommand(new ScriptCommand());
|
||||
registerCommand(new SlayCommand());
|
||||
registerCommand(new QuestCommand());
|
||||
registerCommand(new QuestCategoryCommand());
|
||||
registerCommand(new DialogCommand());
|
||||
registerCommand(new DialogCategoryCommand());
|
||||
registerCommand(new FactionCommand());
|
||||
registerCommand(new NpcCommand());
|
||||
registerCommand(new CloneCommand());
|
||||
registerCommand(new ConfigCommand());
|
||||
registerCommand(new AnimationCommand());
|
||||
registerCommand(new OverlayCommand());
|
||||
registerCommand(new CommandCommand());
|
||||
}
|
||||
|
||||
public void registerCommand(CommandKamkeelBase command){
|
||||
String name = command.getCommandName().toLowerCase();
|
||||
if(map.containsKey(name))
|
||||
throw new CustomNPCsException("Already a subcommand with the name: " + name);
|
||||
map.put(name, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "kamkeel";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getCommandAliases()
|
||||
{
|
||||
return Arrays.asList(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "Use as /kamkeel subcommand";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(args.length == 0){
|
||||
help.processCommand(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
CommandKamkeelBase command = getCommand(args);
|
||||
if(command == null)
|
||||
throw new CommandException("Unknown command " + args[0]);
|
||||
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
if(command.subcommands.isEmpty() || !command.runSubCommands()){
|
||||
if(!canSendCommand(sender, command))
|
||||
throw new CommandException("You are not allowed to use this command: " + command);
|
||||
command.canRun(sender, command.getUsage(), args);
|
||||
command.processCommand(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length == 0){
|
||||
help.processCommand(sender, new String[]{command.getCommandName()});
|
||||
return;
|
||||
}
|
||||
|
||||
command.processSubCommand(sender, args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args){
|
||||
if(args.length == 1)
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, map.keySet().toArray(new String[map.size()]));
|
||||
CommandKamkeelBase command = getCommand(args);
|
||||
if(command == null)
|
||||
return null;
|
||||
if(args.length == 2 && command.runSubCommands())
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, command.subcommands.keySet().toArray(new String[command.subcommands.keySet().size()]));
|
||||
String[] useArgs = command.getUsage().split(" ");
|
||||
if(command.runSubCommands()) {
|
||||
Method m = command.subcommands.get(args[1].toLowerCase());
|
||||
if(m != null) {
|
||||
useArgs = m.getAnnotation(CommandKamkeelBase.SubCommand.class).usage().split(" ");
|
||||
}
|
||||
}
|
||||
if(args.length <= useArgs.length + 2) {
|
||||
if(args.length - 3 >= 0){
|
||||
String usage = useArgs[args.length - 3];
|
||||
if(usage.equals("<player>") || usage.equals("[player]")) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
}
|
||||
}
|
||||
}
|
||||
return command.addTabCompletionOptions(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
|
||||
public CommandKamkeelBase getCommand(String[] args){
|
||||
if(args.length == 0)
|
||||
return null;
|
||||
return map.get(args[0].toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public static String getCommandPermission(String command){
|
||||
return "cnpc.kamkeel." + command.toLowerCase();
|
||||
}
|
||||
|
||||
public static String getUniversalPermission(){
|
||||
return "cnpc.kamkeel.*";
|
||||
}
|
||||
|
||||
public static boolean canSendCommand(ICommandSender sender, CommandKamkeelBase command){
|
||||
if(sender.canCommandSenderUseCommand(command.getRequiredPermissionLevel(), getUniversalPermission())){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(sender.canCommandSenderUseCommand(command.getRequiredPermissionLevel(), getCommandPermission(command.getCommandName()))){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(sender instanceof EntityPlayer){
|
||||
return CustomNpcsPermissions.hasCustomPermission((EntityPlayer) sender, getCommandPermission(command.getCommandName()));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
package kamkeel.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class CommandKamkeelBase extends CommandBase{
|
||||
public Map<String, Method> subcommands = new HashMap<String, Method>();
|
||||
|
||||
public CommandKamkeelBase(){
|
||||
for (Method m : this.getClass().getDeclaredMethods()) {
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
if (sc != null) {
|
||||
String name = sc.name();
|
||||
if (name.equals(""))
|
||||
name = m.getName();
|
||||
subcommands.put(name.toLowerCase(), m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return getDescription();
|
||||
}
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
/**
|
||||
* @return Should return a string in the format of <arg> <arg2> <arg3> [arg4] where <> is a required parameter and [] optional
|
||||
*/
|
||||
public String getUsage(){
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean runSubCommands(){
|
||||
return !subcommands.isEmpty();
|
||||
}
|
||||
|
||||
protected static void sendMessage(ICommandSender sender, String message, Object... obs) {
|
||||
sender.addChatMessage(new ChatComponentTranslation(message, obs));
|
||||
}
|
||||
|
||||
protected static void sendResult(ICommandSender sender, String message, Object... obs) {
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A77 " + message, obs));
|
||||
}
|
||||
|
||||
protected static void sendError(ICommandSender sender, String message, Object... obs) {
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A74 Error:\u00A7c " + message, obs));
|
||||
}
|
||||
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface SubCommand {
|
||||
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* @return Should return a string in the format of <arg> <arg2> <arg3> [arg4] where <> is a required parameter and [] optional
|
||||
*/
|
||||
String usage() default "";
|
||||
|
||||
String desc();
|
||||
|
||||
int permission() default 2;
|
||||
}
|
||||
|
||||
public void processSubCommand(ICommandSender sender, String command, String[] args) throws CommandException {
|
||||
Method m = subcommands.get(command.toLowerCase());
|
||||
if(m == null)
|
||||
throw new CommandException("Unknown subcommand " + command);
|
||||
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
if(!canSendCommand(sender, sc, command))
|
||||
throw new CommandException("You are not allowed to use this command: " + command);
|
||||
|
||||
canRun(sender, sc.usage(), args);
|
||||
try {
|
||||
m.invoke(this, sender, args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void canRun(ICommandSender sender, String usage, String[] args) throws CommandException{
|
||||
String[] np = usage.split(" ");
|
||||
List<String> required = new ArrayList<String>();
|
||||
for(int i = 0; i < np.length; i++){
|
||||
String command = np[i];
|
||||
if(command.startsWith("<")){
|
||||
required.add(command);
|
||||
}
|
||||
if(command.equals("<player>") && args.length > i){
|
||||
CommandBase.getPlayer(sender, args[i]); //throws PlayerNotFoundException if no player is found
|
||||
}
|
||||
|
||||
}
|
||||
if (args.length < required.size()) {
|
||||
throw new CommandException("Missing parameter: " + required.get(args.length));
|
||||
}
|
||||
}
|
||||
|
||||
public int getRequiredPermissionLevel(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public String getSubCommandPermission(String subCommand){
|
||||
return "cnpc.kamkeel." + getCommandName().toLowerCase() + "." + subCommand.toLowerCase();
|
||||
}
|
||||
|
||||
public String getSubUniversalPermission(){
|
||||
return "cnpc.kamkeel." + getCommandName().toLowerCase() + "*";
|
||||
}
|
||||
|
||||
public boolean canSendCommand(ICommandSender sender, SubCommand command, String subCommand){
|
||||
if(sender.canCommandSenderUseCommand(command.permission(), getSubUniversalPermission())){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(sender.canCommandSenderUseCommand(command.permission(), getSubCommandPermission(subCommand))){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(sender instanceof EntityPlayer){
|
||||
return CustomNpcsPermissions.hasCustomPermission((EntityPlayer) sender, getSubCommandPermission(subCommand));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,298 +0,0 @@
|
||||
package kamkeel.command;
|
||||
|
||||
import foxz.utils.Market;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockIce;
|
||||
import net.minecraft.block.BlockLeavesBase;
|
||||
import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.controllers.ChunkController;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigCommand extends CommandKamkeelBase {
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "config";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Some config things you can set";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable/Enable the natural leaves decay",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void leavesdecay(ICommandSender sender, String[] args){
|
||||
if(args.length == 0){
|
||||
sendResult(sender, "LeavesDecay: \u00A7c" + ConfigMain.LeavesDecayEnabled);
|
||||
}
|
||||
else{
|
||||
ConfigMain.LeavesDecayEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.LeavesDecayEnabledProperty.set(ConfigMain.LeavesDecayEnabled);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
Set<ResourceLocation> names = Block.blockRegistry.getKeys();
|
||||
for(ResourceLocation name : names){
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if(block instanceof BlockLeavesBase){
|
||||
block.setTickRandomly(ConfigMain.LeavesDecayEnabled);
|
||||
}
|
||||
}
|
||||
sendResult(sender, "LeavesDecay is now \u00A7c" + ConfigMain.LeavesDecayEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable/Enable the vines growing",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void vinegrowth(ICommandSender sender, String[] args){
|
||||
if(args.length == 0){
|
||||
sendResult(sender, "VineGrowth: \u00A7c" + ConfigMain.VineGrowthEnabled);
|
||||
}
|
||||
else{
|
||||
ConfigMain.VineGrowthEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.VineGrowthEnabledProperty.set(ConfigMain.VineGrowthEnabled);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
Set<ResourceLocation> names = Block.blockRegistry.getKeys();
|
||||
for(ResourceLocation name : names){
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if(block instanceof BlockVine){
|
||||
block.setTickRandomly(ConfigMain.VineGrowthEnabled);
|
||||
}
|
||||
}
|
||||
sendResult(sender, "VineGrowth is now \u00A7c" + ConfigMain.VineGrowthEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable/Enable the ice melting",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void icemelts(ICommandSender sender, String[] args){
|
||||
if(args.length == 0){
|
||||
sendResult(sender, "IceMelts: \u00A7c" + ConfigMain.IceMeltsEnabled);
|
||||
}
|
||||
else{
|
||||
ConfigMain.IceMeltsEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.IceMeltsEnabledProperty.set(ConfigMain.IceMeltsEnabled);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
Set<ResourceLocation> names = Block.blockRegistry.getKeys();
|
||||
for(ResourceLocation name : names){
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if(block instanceof BlockIce){
|
||||
block.setTickRandomly(ConfigMain.IceMeltsEnabled);
|
||||
}
|
||||
}
|
||||
sendResult(sender, "IceMelts is now \u00A7c" + ConfigMain.IceMeltsEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable/Enable guns shooting",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void guns(ICommandSender sender, String[] args){
|
||||
if(args.length == 0){
|
||||
sendResult(sender, "GunsEnabled: \u00A7c" + ConfigMain.GunsEnabled);
|
||||
}
|
||||
else{
|
||||
ConfigMain.GunsEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.GunsEnabledProperty.set(ConfigMain.GunsEnabled);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "GunsEnabled is now \u00A7c" + ConfigMain.GunsEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Freezes/Unfreezes npcs",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void freezenpcs(ICommandSender sender, String[] args){
|
||||
if(args.length == 0){
|
||||
sendResult(sender, "Frozen NPCs: \u00A7c" + CustomNpcs.FreezeNPCs);
|
||||
}
|
||||
else{
|
||||
CustomNpcs.FreezeNPCs = Boolean.parseBoolean(args[0]);
|
||||
sendResult(sender, "FrozenNPCs is now \u00A7c" + CustomNpcs.FreezeNPCs);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set number of active chunkloaders",
|
||||
usage = "<number>",
|
||||
permission = 4
|
||||
)
|
||||
public void chunkloaders(ICommandSender sender, String[] args) throws CommandException{
|
||||
if(args.length == 0){
|
||||
sendResult(sender, "ChunkLoaders: \u00A7c" + ChunkController.Instance.size() + "\u00A77/\u00A7c" + ConfigMain.ChunkLoaders);
|
||||
}
|
||||
else{
|
||||
try{
|
||||
ConfigMain.ChunkLoaders = Integer.parseInt(args[0]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
sendError(sender, "Did not get a number: " + args[0]);
|
||||
return;
|
||||
}
|
||||
ConfigMain.ChunkLoadersProperty.set(ConfigMain.ChunkLoaders);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
|
||||
int size = ChunkController.Instance.size();
|
||||
if(size > ConfigMain.ChunkLoaders){
|
||||
ChunkController.Instance.unload(size - ConfigMain.ChunkLoaders);
|
||||
sendResult(sender, size - ConfigMain.ChunkLoaders + " chunksloaders unloaded");
|
||||
}
|
||||
sendResult(sender, "ChunkLoaders: \u00A7c" + ChunkController.Instance.size() + "\u00A77/\u00A7c" + ConfigMain.ChunkLoaders);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Generate PlayerData to JSON/DAT",
|
||||
usage = "[fileType] [convert]",
|
||||
permission = 4
|
||||
)
|
||||
public void playerdata(ICommandSender sender, String[] args) throws CommandException{
|
||||
String fileType;
|
||||
if(ConfigMain.DatFormat){
|
||||
fileType = "DAT";
|
||||
}
|
||||
else {
|
||||
fileType = "JSON";
|
||||
}
|
||||
if(args.length == 0){
|
||||
sendResult(sender, "PlayerData Filetype: \u00A7c" + fileType);
|
||||
}
|
||||
else if(args.length == 1){
|
||||
sendResult(sender, "Please write the word 'convert' at the end to confirm. \u00A7c<dat/json> convert");
|
||||
}
|
||||
else{
|
||||
if(args.length != 2){
|
||||
sendError(sender, "Two many arguments");
|
||||
return;
|
||||
}
|
||||
String formatType = args[0].toLowerCase();
|
||||
if(!formatType.equals("dat") && !formatType.equals("json")){
|
||||
sendError(sender, "Invalid Format Type - Please use dat or json");
|
||||
return;
|
||||
}
|
||||
|
||||
String convert = args[1].toLowerCase();
|
||||
if(!convert.equals("convert")){
|
||||
sendError(sender, "Please enter the word 'convert' at the end");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean convertToDat = formatType.equals("dat");
|
||||
EntityPlayerMP send = null;
|
||||
if(sender instanceof EntityPlayerMP){
|
||||
send = (EntityPlayerMP) sender;
|
||||
}
|
||||
|
||||
sendResult(sender, "Started Conversion Process for PlayerData");
|
||||
PlayerDataController.Instance.convertPlayerFiles(send, convertToDat);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Generate Market to JSON/DAT",
|
||||
usage = "[fileType] [convert]",
|
||||
permission = 4
|
||||
)
|
||||
public void market(ICommandSender sender, String[] args) throws CommandException{
|
||||
String fileType;
|
||||
if(ConfigMain.MarketDatFormat){
|
||||
fileType = "DAT";
|
||||
}
|
||||
else {
|
||||
fileType = "JSON";
|
||||
}
|
||||
if(args.length == 0){
|
||||
sendResult(sender, "Market Filetype: \u00A7c" + fileType);
|
||||
}
|
||||
else if(args.length == 1){
|
||||
sendResult(sender, "Please write the word 'convert' at the end to confirm. \u00A7c<dat/json> convert");
|
||||
}
|
||||
else{
|
||||
if(args.length != 2){
|
||||
sendError(sender, "Two many arguments");
|
||||
return;
|
||||
}
|
||||
String formatType = args[0].toLowerCase();
|
||||
if(!formatType.equals("dat") && !formatType.equals("json")){
|
||||
sendError(sender, "Invalid Format Type - Please use dat or json");
|
||||
return;
|
||||
}
|
||||
|
||||
String convert = args[1].toLowerCase();
|
||||
if(!convert.equals("convert")){
|
||||
sendError(sender, "Please enter the word 'convert' at the end");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean convertToDat = formatType.equals("dat");
|
||||
EntityPlayerMP send = null;
|
||||
if(sender instanceof EntityPlayerMP){
|
||||
send = (EntityPlayerMP) sender;
|
||||
}
|
||||
|
||||
sendResult(sender, "Started Conversion Process for Market");
|
||||
Market.convertMarketFiles(send, convertToDat);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Get/Set font",
|
||||
usage = "[type] [size]",
|
||||
permission = 4
|
||||
)
|
||||
public void font(ICommandSender sender, String[] args){
|
||||
if(!(sender instanceof EntityPlayerMP))
|
||||
return;
|
||||
int size = 18;
|
||||
if(args.length > 1){
|
||||
try{
|
||||
size = Integer.parseInt(args[args.length - 1]);
|
||||
args = Arrays.copyOfRange(args, 0, args.length - 1);
|
||||
}
|
||||
catch(Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
String font = "";
|
||||
for(int i = 0; i < args.length; i++){
|
||||
font += " " + args[i];
|
||||
}
|
||||
Server.sendData((EntityPlayerMP)sender, EnumPacketClient.CONFIG, 0, font.trim(), size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
package kamkeel.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class HelpCommand extends CommandKamkeelBase{
|
||||
private CommandKamkeel parent;
|
||||
|
||||
public HelpCommand(CommandKamkeel parent){
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "help [command]";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(args.length == 0){
|
||||
sendMessage(sender, "\u00A78------ \u00A7cKamkeel Commands \u00A78------");
|
||||
for(Entry<String, CommandKamkeelBase> entry : parent.map.entrySet()){
|
||||
sendMessage(sender, "\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getCommandUsage(sender));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CommandKamkeelBase command = parent.getCommand(args);
|
||||
if(command == null){
|
||||
sendError(sender, "Unknown command " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
if(command.subcommands.isEmpty()){
|
||||
sender.addChatMessage(new ChatComponentTranslation(command.getCommandUsage(sender)));
|
||||
return;
|
||||
}
|
||||
|
||||
Method m = null;
|
||||
if(args.length > 1){
|
||||
m = command.subcommands.get(args[1].toLowerCase());
|
||||
}
|
||||
if(m == null){
|
||||
sendMessage(sender, "\u00A78------ \u00A7a" + command.getCommandName().toUpperCase() + " SubCommands \u00A78------");
|
||||
sendMessage(sender, "\u00A77Usage: \u00A76" + command.getUsage());
|
||||
for(Entry<String, Method> entry : command.subcommands.entrySet()){
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getAnnotation(SubCommand.class).desc()));
|
||||
}
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + CommandKamkeel.getCommandPermission(command.getCommandName())));
|
||||
}
|
||||
else{
|
||||
sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase() + "." + args[1].toUpperCase() + " Command \u00A78------");
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A77" + sc.desc()));
|
||||
if(!sc.usage().isEmpty())
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A77Usage: \u00A76" + sc.usage()));
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + getSubCommandPermission(args[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
package kamkeel.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.PlayerNotFoundException;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.RoleCompanion;
|
||||
import noppes.npcs.roles.RoleFollower;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class NpcCommand extends CommandKamkeelBase {
|
||||
|
||||
public EntityNPCInterface selectedNpc;
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "npc";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NPC operation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<name> <command>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runSubCommands(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
String npcname = args[0].replace("%", " ");
|
||||
String command = args[1];
|
||||
args = Arrays.copyOfRange(args, 2, args.length);
|
||||
if(command.equalsIgnoreCase("create")){
|
||||
args = ArrayUtils.add(args, 0, npcname);
|
||||
processSubCommand(sender, command, args);
|
||||
return;
|
||||
}
|
||||
|
||||
int x = sender.getPlayerCoordinates().posX;
|
||||
int y = sender.getPlayerCoordinates().posY;
|
||||
int z = sender.getPlayerCoordinates().posZ;
|
||||
List<EntityNPCInterface> list = getEntities(EntityNPCInterface.class, sender.getEntityWorld(), x, y, z, 80);
|
||||
for (EntityNPCInterface npc : list) {
|
||||
String name = npc.display.getName().replace(" ", "_");
|
||||
if (name.equalsIgnoreCase(npcname)){
|
||||
if(selectedNpc == null || selectedNpc.getDistanceSq(x, y, z) > npc.getDistanceSq(x, y, z))
|
||||
selectedNpc = npc;
|
||||
}
|
||||
}
|
||||
if(selectedNpc == null){
|
||||
sendError(sender, "Npc " + npcname + " was not found");
|
||||
return;
|
||||
}
|
||||
|
||||
processSubCommand(sender, command, args);
|
||||
selectedNpc = null;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set Home (respawn place)",
|
||||
usage = "[x] [y] [z]"
|
||||
)
|
||||
public void home(ICommandSender sender, String[] args) {
|
||||
double posX = sender.getPlayerCoordinates().posX;
|
||||
double posY = sender.getPlayerCoordinates().posY;
|
||||
double posZ = sender.getPlayerCoordinates().posZ;
|
||||
|
||||
if(args.length == 3){
|
||||
posX = CommandBase.func_110666_a(sender, selectedNpc.posX, args[0]);
|
||||
posY = CommandBase.func_110665_a(sender, selectedNpc.posY, args[1].trim(), 0, 0);
|
||||
posZ = CommandBase.func_110666_a(sender, selectedNpc.posZ, args[2]);
|
||||
}
|
||||
|
||||
selectedNpc.ai.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
|
||||
sendResult(sender, String.format("Set NPC \u00A7e%s\u00A77 Home to \u00A7b[%.1f] [%.1f] [%.1f]\u00A77", selectedNpc.display.name, posX, posY, posZ));
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set NPC visibility",
|
||||
usage = "[true/false/semi]"
|
||||
)
|
||||
public void visible(ICommandSender sender, String[] args){
|
||||
if(args.length < 1)
|
||||
return;
|
||||
boolean bo = args[0].equalsIgnoreCase("true");
|
||||
boolean semi = args[0].equalsIgnoreCase("semi");
|
||||
|
||||
int current = selectedNpc.display.visible;
|
||||
if(semi)
|
||||
selectedNpc.display.visible = 2;
|
||||
else if(bo)
|
||||
selectedNpc.display.visible = 0;
|
||||
else
|
||||
selectedNpc.display.visible = 1;
|
||||
|
||||
String[] list = new String[]{"True", "False", "Semi"};
|
||||
|
||||
if(current != selectedNpc.display.visible)
|
||||
selectedNpc.updateClient = true;
|
||||
|
||||
sendResult(sender, String.format("Set NPC \u00A7e%s\u00A77 Visibility to \u00A7b%s\u00A77", selectedNpc.display.name, list[selectedNpc.display.visible]));
|
||||
}
|
||||
|
||||
@SubCommand(desc = "Delete an NPC")
|
||||
public void delete(ICommandSender sender, String[] args){
|
||||
selectedNpc.delete();
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Sets the owner of an follower/companion",
|
||||
usage = "[player]"
|
||||
)
|
||||
public void owner(ICommandSender sender, String[] args){
|
||||
if(args.length < 1){
|
||||
EntityPlayer player = null;
|
||||
if(selectedNpc.roleInterface instanceof RoleFollower)
|
||||
player = ((RoleFollower)selectedNpc.roleInterface).owner;
|
||||
|
||||
if(selectedNpc.roleInterface instanceof RoleCompanion)
|
||||
player = ((RoleCompanion)selectedNpc.roleInterface).owner;
|
||||
|
||||
if(player == null)
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Owner: \u00A7b%s\u00A77", selectedNpc.display.name, "NULL"));
|
||||
else
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Owner: \u00A7b%s\u00A77", selectedNpc.display.name, player.getDisplayName()));
|
||||
}
|
||||
else{
|
||||
EntityPlayerMP player = null;
|
||||
try {
|
||||
player = CommandBase.getPlayer(sender, args[0]);
|
||||
} catch (PlayerNotFoundException e) {
|
||||
|
||||
}
|
||||
if(selectedNpc.roleInterface instanceof RoleFollower)
|
||||
((RoleFollower)selectedNpc.roleInterface).setOwner(player);
|
||||
|
||||
if(selectedNpc.roleInterface instanceof RoleCompanion)
|
||||
((RoleCompanion)selectedNpc.roleInterface).setOwner(player);
|
||||
|
||||
if(player == null)
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Owner: \u00A7b%s\u00A77", selectedNpc.display.name, "NULL"));
|
||||
else
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Owner: \u00A7b%s\u00A77", selectedNpc.display.name, player.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set NPC name",
|
||||
usage = "[name]"
|
||||
)
|
||||
public void name(ICommandSender sender, String[] args){
|
||||
if(args.length < 1)
|
||||
return;
|
||||
|
||||
String name = args[0];
|
||||
for(int i = 1; i < args.length; i++){
|
||||
name += " " + args[i];
|
||||
}
|
||||
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Name set to \u00A7b%s\u00A77", selectedNpc.display.name, name));
|
||||
|
||||
if(!selectedNpc.display.getName().equals(name)){
|
||||
selectedNpc.display.setName(name);
|
||||
selectedNpc.updateClient = true;
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Creates an NPC",
|
||||
usage = "[name]"
|
||||
)
|
||||
public void create(ICommandSender sender, String[] args) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) sender;
|
||||
World pw = player.getEntityWorld();
|
||||
EntityCustomNpc npc = new EntityCustomNpc(pw);
|
||||
if(args.length > 0)
|
||||
npc.display.name = args[0];
|
||||
npc.setPositionAndRotation(player.posX, player.posY, player.posZ, player.cameraYaw, player.cameraPitch);
|
||||
npc.ai.startPos = new int[]{MathHelper.floor_double(player.posX),MathHelper.floor_double(player.posY),MathHelper.floor_double(player.posZ)};
|
||||
pw.spawnEntityInWorld(npc);
|
||||
npc.setHealth(npc.getMaxHealth());
|
||||
NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay, npc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender par1, String[] args) {
|
||||
if(args.length == 2){
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, new String[]{"create", "home", "visible", "delete", "owner", "name"});
|
||||
}
|
||||
if(args.length == 3 && args[1].equalsIgnoreCase("owner")){
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel(){
|
||||
return 4;
|
||||
}
|
||||
|
||||
public <T extends Entity> List<T> getEntities(Class<? extends T> cls, World world, int x, int y, int z, int range) {
|
||||
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1).expand(range, range, range);
|
||||
List<T> list = world.getEntitiesWithinAABB(cls, bb);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package kamkeel.command;
|
||||
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
|
||||
public class ScriptCommand extends CommandKamkeelBase {
|
||||
|
||||
@SubCommand(desc = "Reload scripts data and folders.")
|
||||
public Boolean reload(ICommandSender sender, String args[]) {
|
||||
ScriptController.Instance.loadCategories();
|
||||
|
||||
if(ScriptController.Instance.loadPlayerScripts())
|
||||
sendResult(sender, "Reload player scripts successfully");
|
||||
else
|
||||
sendError(sender, "Failed reloading player scripts");
|
||||
|
||||
if(ScriptController.Instance.loadForgeScripts())
|
||||
sendResult(sender, "Reload forge scripts successfully");
|
||||
else
|
||||
sendError(sender, "Failed reloading forge scripts");
|
||||
|
||||
if(ScriptController.Instance.loadStoredData())
|
||||
sendResult(sender, "Reload stored data successfully");
|
||||
else
|
||||
sendError(sender, "Failed reloading stored data");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "script";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Commands for scripts";
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
package kamkeel.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.boss.EntityDragon;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.item.EntityXPOrb;
|
||||
import net.minecraft.entity.monster.EntityGhast;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.passive.EntityHorse;
|
||||
import net.minecraft.entity.passive.EntityTameable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SlayCommand extends CommandKamkeelBase {
|
||||
public Map<String, Class<?>> SlayMap = new LinkedHashMap<String, Class<?>>();
|
||||
|
||||
public SlayCommand(){
|
||||
SlayMap.clear();
|
||||
|
||||
SlayMap.put("all",EntityLivingBase.class);
|
||||
SlayMap.put("mobs",EntityMob.class);
|
||||
SlayMap.put("animals", EntityAnimal.class);
|
||||
SlayMap.put("items", EntityItem.class);
|
||||
SlayMap.put("xporbs", EntityXPOrb.class);
|
||||
SlayMap.put("npcs", EntityNPCInterface.class);
|
||||
|
||||
HashMap<String,Class<?>> list = new HashMap<String,Class<?>>(EntityList.stringToClassMapping);
|
||||
for(String name : list.keySet()){
|
||||
Class<?> cls = list.get(name);
|
||||
if(EntityNPCInterface.class.isAssignableFrom(cls))
|
||||
continue;
|
||||
if(!EntityLivingBase.class.isAssignableFrom(cls))
|
||||
continue;
|
||||
SlayMap.put(name.toLowerCase(), list.get(name));
|
||||
}
|
||||
|
||||
SlayMap.remove("monster");
|
||||
SlayMap.remove("mob");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "slay";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Kills given entity within range. Tab to see options.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(){
|
||||
return "<type>.. [range]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
EntityPlayerMP player = (EntityPlayerMP) sender;
|
||||
ArrayList<Class<?>> toDelete = new ArrayList<Class<?>>();
|
||||
boolean deleteNPCs = false;
|
||||
for(String delete : args){
|
||||
delete = delete.toLowerCase();
|
||||
Class<?> cls = SlayMap.get(delete);
|
||||
if(cls != null)
|
||||
toDelete.add(cls);
|
||||
if(delete.equals("mobs")){
|
||||
toDelete.add(EntityGhast.class);
|
||||
toDelete.add(EntityDragon.class);
|
||||
}
|
||||
if(delete.equals("npcs"))
|
||||
deleteNPCs = true;
|
||||
}
|
||||
int count = 0;
|
||||
int range = 120;
|
||||
try{
|
||||
range = Integer.parseInt(args[args.length - 1]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
|
||||
}
|
||||
AxisAlignedBB box = player.boundingBox.expand(range, range, range);
|
||||
List<? extends Entity> list = sender.getEntityWorld().getEntitiesWithinAABB(EntityLivingBase.class, box);
|
||||
|
||||
for(Entity entity : list){
|
||||
if(entity instanceof EntityPlayer)
|
||||
continue;
|
||||
if(entity instanceof EntityTameable && ((EntityTameable)entity).isTamed())
|
||||
continue;
|
||||
if(entity instanceof EntityNPCInterface && !deleteNPCs)
|
||||
continue;
|
||||
if(delete(entity,toDelete))
|
||||
count++;
|
||||
}
|
||||
if(toDelete.contains(EntityXPOrb.class)){
|
||||
list = sender.getEntityWorld().getEntitiesWithinAABB(EntityXPOrb.class, box);
|
||||
for(Entity entity : list){
|
||||
entity.isDead = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(toDelete.contains(EntityItem.class)){
|
||||
list = sender.getEntityWorld().getEntitiesWithinAABB(EntityItem.class, box);
|
||||
for(Entity entity : list){
|
||||
entity.isDead = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
sendResult(sender, count + " entities deleted");
|
||||
}
|
||||
|
||||
private boolean delete(Entity entity, ArrayList<Class<?>> toDelete) {
|
||||
for(Class<?> delete : toDelete){
|
||||
if(delete == EntityAnimal.class && (entity instanceof EntityHorse)){
|
||||
continue;
|
||||
}
|
||||
if(delete.isAssignableFrom(entity.getClass())){
|
||||
entity.isDead = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args){
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, SlayMap.keySet().toArray(new String[SlayMap.size()]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package kamkeel.npcs;
|
||||
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeValueType;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.RequirementCheckerRegistry;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.types.QuestActiveRequirement;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.types.QuestCompletedRequirement;
|
||||
|
||||
/**
|
||||
* ModAttributes registers the core attributes (both non–magic and magic–based).
|
||||
*/
|
||||
public class CustomAttributes {
|
||||
public static final String HEALTH_KEY = "health";
|
||||
public static final String MAIN_ATTACK_KEY = "main_attack";
|
||||
public static final String MAIN_ATTACK_BOOST_KEY = "main_attack_boost";
|
||||
public static final String NEUTRAL_KEY = "neutral";
|
||||
public static final String NEUTRAL_BOOST_KEY = "neutral_boost";
|
||||
public static final String CRITICAL_DAMAGE_KEY = "critical_damage";
|
||||
public static final String CRITICAL_CHANCE_KEY = "critical_chance";
|
||||
public static final String MAGIC_DAMAGE_KEY = "magic_damage";
|
||||
public static final String MAGIC_BOOST_KEY = "magic_boost";
|
||||
public static final String MAGIC_DEFENSE_KEY = "magic_defense";
|
||||
public static final String MAGIC_RESISTANCE_KEY = "magic_resistance";
|
||||
|
||||
|
||||
public static AttributeDefinition MAIN_ATTACK;
|
||||
public static AttributeDefinition MAIN_BOOST;
|
||||
public static AttributeDefinition NEUTRAL_ATTACK;
|
||||
public static AttributeDefinition NEUTRAL_BOOST;
|
||||
|
||||
public static AttributeDefinition HEALTH;
|
||||
public static AttributeDefinition CRITICAL_CHANCE;
|
||||
public static AttributeDefinition CRITICAL_DAMAGE;
|
||||
|
||||
public static AttributeDefinition MAGIC_DAMAGE;
|
||||
public static AttributeDefinition MAGIC_BOOST;
|
||||
public static AttributeDefinition MAGIC_DEFENSE;
|
||||
public static AttributeDefinition MAGIC_RESISTANCE;
|
||||
|
||||
public CustomAttributes() {
|
||||
HEALTH = AttributeController.registerAttribute(HEALTH_KEY, "Health", 'c', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.BASE);
|
||||
|
||||
MAIN_ATTACK = AttributeController.registerAttribute(MAIN_ATTACK_KEY, "Main Attack Damage", '4', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.BASE);
|
||||
MAIN_BOOST = AttributeController.registerAttribute(MAIN_ATTACK_BOOST_KEY, "Main Attack Damage", '4', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
|
||||
NEUTRAL_ATTACK = AttributeController.registerAttribute(NEUTRAL_KEY, "Neutral Damage", '6', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.BASE);
|
||||
NEUTRAL_BOOST = AttributeController.registerAttribute(NEUTRAL_BOOST_KEY, "Neutral Damage", '6', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
|
||||
CRITICAL_CHANCE = AttributeController.registerAttribute(CRITICAL_CHANCE_KEY, "Critical Chance", '6', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.INFO);
|
||||
CRITICAL_DAMAGE = AttributeController.registerAttribute(CRITICAL_DAMAGE_KEY, "Critical Damage", '6', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.INFO);
|
||||
|
||||
MAGIC_DAMAGE = AttributeController.registerAttribute(MAGIC_DAMAGE_KEY, "Magic Damage", '3', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.BASE);
|
||||
MAGIC_BOOST = AttributeController.registerAttribute(MAGIC_BOOST_KEY, "Magic Damage", '3', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
|
||||
MAGIC_DEFENSE = AttributeController.registerAttribute(MAGIC_DEFENSE_KEY, "Magic Defense", 'b', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.BASE);
|
||||
MAGIC_RESISTANCE = AttributeController.registerAttribute(MAGIC_RESISTANCE_KEY, "Magic Resistance", 'b', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
|
||||
|
||||
// TODO: Attributes
|
||||
// Durability Attribute
|
||||
// Unique Name Attribute
|
||||
|
||||
// Requirement
|
||||
RequirementCheckerRegistry.registerChecker(new QuestCompletedRequirement());
|
||||
RequirementCheckerRegistry.registerChecker(new QuestActiveRequirement());
|
||||
|
||||
// TODO: Requirements
|
||||
// Player Requirement : Soulbound UUID
|
||||
// Profile Requirement : Slot Number
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package kamkeel.addon;
|
||||
package kamkeel.npcs.addon;
|
||||
|
||||
import kamkeel.addon.client.DBCClient;
|
||||
import kamkeel.addon.client.GeckoAddonClient;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import kamkeel.npcs.addon.client.GeckoAddonClient;
|
||||
|
||||
public class AddonManager {
|
||||
public static AddonManager Instance;
|
||||
@@ -9,12 +9,12 @@ public class AddonManager {
|
||||
// Manager class to easily disable mixin manipulated
|
||||
// addons for debugging and testing
|
||||
|
||||
public AddonManager(){
|
||||
public AddonManager() {
|
||||
Instance = this;
|
||||
load();
|
||||
}
|
||||
|
||||
public void load(){
|
||||
public void load() {
|
||||
// Gecko Addon Initialization
|
||||
new GeckoAddon();
|
||||
new GeckoAddonClient();
|
||||
+22
-10
@@ -1,6 +1,6 @@
|
||||
package kamkeel.addon;
|
||||
package kamkeel.npcs.addon;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -18,25 +18,37 @@ public class DBCAddon {
|
||||
* The Addon Mod will replace all blank functions within
|
||||
* this class to change the ongoing code.
|
||||
*/
|
||||
public DBCAddon(){
|
||||
public DBCAddon() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void dbcCopyData(EntityLivingBase copied, EntityLivingBase entity){}
|
||||
public static boolean IsAvailable() {
|
||||
return Loader.isModLoaded("npcdbc");
|
||||
}
|
||||
|
||||
public void dbcCopyData(EntityLivingBase copied, EntityLivingBase entity) {
|
||||
}
|
||||
|
||||
// AI / STATS
|
||||
public boolean canDBCAttack(EntityNPCInterface npc, float attackStrength, Entity receiver){
|
||||
public boolean canDBCAttack(EntityNPCInterface npc, float attackStrength, Entity receiver) {
|
||||
return false;
|
||||
}
|
||||
public void doDBCDamage(EntityNPCInterface npc, float attackStrength, Entity receiver){}
|
||||
public boolean isKO(EntityNPCInterface npc, EntityPlayer player){
|
||||
|
||||
public void doDBCDamage(EntityNPCInterface npc, float attackStrength, Entity receiver) {
|
||||
}
|
||||
|
||||
public boolean isKO(EntityNPCInterface npc, EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// PlayerData NBT
|
||||
public void writeToNBT(PlayerData playerData, NBTTagCompound nbtTagCompound){}
|
||||
public void readFromNBT(PlayerData playerData, NBTTagCompound nbtTagCompound){}
|
||||
public void writeToNBT(PlayerData playerData, NBTTagCompound nbtTagCompound) {
|
||||
}
|
||||
|
||||
public void readFromNBT(PlayerData playerData, NBTTagCompound nbtTagCompound) {
|
||||
}
|
||||
|
||||
// Client Sync
|
||||
public void syncPlayer(EntityPlayerMP playerMP){}
|
||||
public void syncPlayer(EntityPlayerMP playerMP) {
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -1,4 +1,4 @@
|
||||
package kamkeel.addon;
|
||||
package kamkeel.npcs.addon;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
@@ -11,10 +11,11 @@ public class GeckoAddon {
|
||||
* The Addon Mod will replace all blank functions within
|
||||
* this class to change the ongoing code.
|
||||
*/
|
||||
public GeckoAddon(){
|
||||
public GeckoAddon() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void geckoCopyData(EntityLivingBase copied, EntityLivingBase entity){}
|
||||
public void geckoCopyData(EntityLivingBase copied, EntityLivingBase entity) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -1,15 +1,9 @@
|
||||
package kamkeel.addon.client;
|
||||
package kamkeel.npcs.addon.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.client.gui.mainmenu.GuiNpcStats;
|
||||
import noppes.npcs.client.gui.model.GuiCreationScreen;
|
||||
import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface2;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.model.ModelMPM;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
public class DBCClient {
|
||||
@@ -23,23 +17,29 @@ public class DBCClient {
|
||||
* The fewer classes modified by mixins the safer.
|
||||
* These are for mixins affecting only client-side classes.
|
||||
*/
|
||||
public DBCClient(){
|
||||
public DBCClient() {
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
// Stat Buttons
|
||||
public void showDBCStatButtons(GuiNpcStats stats, EntityLivingBase entity){}
|
||||
public void showDBCStatActionPerformed(GuiNpcStats stats, GuiNpcButton btn){}
|
||||
public void showDBCStatButtons(GuiNpcStats stats, EntityLivingBase entity) {
|
||||
}
|
||||
|
||||
public void showDBCStatActionPerformed(GuiNpcStats stats, GuiNpcButton btn) {
|
||||
}
|
||||
|
||||
|
||||
// Render Auras
|
||||
public void renderDBCAuras(EntityNPCInterface npcInterface){}
|
||||
public void renderDBCAuras(EntityNPCInterface npcInterface) {
|
||||
}
|
||||
|
||||
// Manage Custom Forms
|
||||
public GuiNPCInterface2 manageCustomForms(EntityNPCInterface npcInterface){ return null; }
|
||||
// Manage Custom Forms
|
||||
public GuiNPCInterface2 manageCustomAuras(EntityNPCInterface npcInterface){ return null; }
|
||||
public GuiNPCInterface2 manageCustomForms(EntityNPCInterface npcInterface) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Inventory GUI
|
||||
public GuiCNPCInventory inventoryGUI(){ return null; }
|
||||
// Manage Custom Forms
|
||||
public GuiNPCInterface2 manageCustomAuras(EntityNPCInterface npcInterface) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+18
-8
@@ -1,4 +1,4 @@
|
||||
package kamkeel.addon.client;
|
||||
package kamkeel.npcs.addon.client;
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -19,19 +19,29 @@ public class GeckoAddonClient {
|
||||
* The fewer classes modified by mixins the safer.
|
||||
* These are for mixins affecting only client-side classes.
|
||||
*/
|
||||
public GeckoAddonClient(){
|
||||
public GeckoAddonClient() {
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
// Creation Screen Mixins
|
||||
public void showGeckoButtons(GuiCreationScreen creationScreen, EntityLivingBase entity){}
|
||||
public void geckoGuiCreationScreenActionPerformed(GuiCreationScreen creationScreen, GuiNpcButton btn){}
|
||||
public void showGeckoButtons(GuiCreationScreen creationScreen, EntityLivingBase entity) {
|
||||
}
|
||||
|
||||
public void geckoGuiCreationScreenActionPerformed(GuiCreationScreen creationScreen, GuiNpcButton btn) {
|
||||
}
|
||||
|
||||
// Npc Display Mixins
|
||||
public void geckoNpcDisplayInitGui(GuiNPCInterface2 guiNPCInterface){}
|
||||
public void geckoNpcDisplayActionPerformed(GuiNPCInterface2 guiNPCInterface, GuiNpcButton btn){}
|
||||
public void geckoNpcDisplayInitGui(GuiNPCInterface2 guiNPCInterface) {
|
||||
}
|
||||
|
||||
public void geckoNpcDisplayActionPerformed(GuiNPCInterface2 guiNPCInterface, GuiNpcButton btn) {
|
||||
}
|
||||
|
||||
// Render Npc Mixins
|
||||
public boolean isGeckoModel(ModelBase mainModel){ return false;}
|
||||
public void geckoRenderModel(ModelMPM mainModel, EntityNPCInterface npc, float rotationYaw, float renderPartialTicks) {}
|
||||
public boolean isGeckoModel(ModelBase mainModel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void geckoRenderModel(ModelMPM mainModel, EntityNPCInterface npc, float rotationYaw, float renderPartialTicks) {
|
||||
}
|
||||
}
|
||||
+36
-33
@@ -1,4 +1,4 @@
|
||||
package kamkeel.command;
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
@@ -9,24 +9,27 @@ import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class AnimationCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "animation";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "animation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Animation operations";
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Animation operations";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "set an animation to a player",
|
||||
usage = "<player> <num>"
|
||||
desc = "set an animation to a player",
|
||||
usage = "<player> <num>"
|
||||
)
|
||||
public void set(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void set(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int animationId;
|
||||
try {
|
||||
animationId = Integer.parseInt(args[1]);
|
||||
@@ -41,12 +44,12 @@ public class AnimationCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
IAnimation animation = AnimationController.getInstance().get(animationId);
|
||||
if(animation == null){
|
||||
if (animation == null) {
|
||||
sendError(sender, "No Animation ID found: " + animationId);
|
||||
return;
|
||||
}
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.animationData.setEnabled(false);
|
||||
playerdata.animationData.setAnimation(animation);
|
||||
playerdata.animationData.updateClient();
|
||||
@@ -57,18 +60,18 @@ public class AnimationCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "clear an animation from a player",
|
||||
usage = "<player>"
|
||||
desc = "clear an animation from a player",
|
||||
usage = "<player>"
|
||||
)
|
||||
public void clear(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void clear(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.animationData.setEnabled(false);
|
||||
playerdata.animationData.setAnimation(null);
|
||||
playerdata.animationData.updateClient();
|
||||
@@ -79,19 +82,19 @@ public class AnimationCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "enable an animation on a player",
|
||||
usage = "<player>"
|
||||
desc = "enable an animation on a player",
|
||||
usage = "<player>"
|
||||
)
|
||||
public void enable(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void enable(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
if(playerdata.animationData.getAnimation() == null){
|
||||
for (PlayerData playerdata : data) {
|
||||
if (playerdata.animationData.getAnimation() == null) {
|
||||
sendError(sender, String.format("Player '\u00A7b%s\u00A74' does not have an animation set", playerdata.playername));
|
||||
return;
|
||||
}
|
||||
@@ -105,19 +108,19 @@ public class AnimationCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "disable an animation on a player",
|
||||
usage = "<player>"
|
||||
desc = "disable an animation on a player",
|
||||
usage = "<player>"
|
||||
)
|
||||
public void disable(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void disable(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
if(playerdata.animationData.getAnimation() == null){
|
||||
for (PlayerData playerdata : data) {
|
||||
if (playerdata.animationData.getAnimation() == null) {
|
||||
sendError(sender, String.format("Player '\u00A7b%s\u00A74' does not have an animation set", playerdata.playername));
|
||||
return;
|
||||
}
|
||||
@@ -131,7 +134,7 @@ public class AnimationCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "reload animations"
|
||||
desc = "reload animations"
|
||||
)
|
||||
public void reload(ICommandSender sender, String args[]) {
|
||||
AnimationController.Instance.load();
|
||||
@@ -0,0 +1,245 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeValueType;
|
||||
import kamkeel.npcs.util.AttributeItemUtil;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class AttributeCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "attribute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Manage attributes on your held item";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
name = "list",
|
||||
usage = "[page]",
|
||||
desc = "Lists all available attributes"
|
||||
)
|
||||
public void list(ICommandSender sender, String[] args) throws CommandException {
|
||||
// Get all registered attributes.
|
||||
List<AttributeDefinition> defs = new ArrayList<AttributeDefinition>(AttributeController.getAllAttributes());
|
||||
if (defs.isEmpty()) {
|
||||
sendError(sender, "No attributes found.");
|
||||
return;
|
||||
}
|
||||
// Sort attributes by display name.
|
||||
Collections.sort(defs, new Comparator<AttributeDefinition>() {
|
||||
@Override
|
||||
public int compare(AttributeDefinition a, AttributeDefinition b) {
|
||||
return a.getKey().compareToIgnoreCase(b.getKey());
|
||||
}
|
||||
});
|
||||
|
||||
// Determine which page to show.
|
||||
int page = 1;
|
||||
if (args.length > 0) {
|
||||
try {
|
||||
page = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
// If parsing fails, default to page 1.
|
||||
}
|
||||
}
|
||||
int perPage = 10;
|
||||
int total = defs.size();
|
||||
int totalPages = (int) Math.ceil(total / (double) perPage);
|
||||
if (page < 1) page = 1;
|
||||
if (page > totalPages) page = totalPages;
|
||||
int startIndex = (page - 1) * perPage;
|
||||
int endIndex = Math.min(startIndex + perPage, total);
|
||||
|
||||
sendResult(sender, "--------------------");
|
||||
sendResult(sender, "Attributes (Page " + page + "/" + totalPages + "):");
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
AttributeDefinition def = defs.get(i);
|
||||
// First line: numbered display name.
|
||||
sendResult(sender, (i + 1) + ". " + def.getDisplayName());
|
||||
// Second line: key and value type.
|
||||
sendResult(sender, " - " + def.getKey() + ", " + def.getValueType());
|
||||
}
|
||||
sendResult(sender, "--------------------");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
name = "apply",
|
||||
usage = "<attribute> <value> [magicID]",
|
||||
desc = "Applies an attribute to your held item. For magic attributes, provide a magicID."
|
||||
)
|
||||
public void apply(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "Only players can use this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
ItemStack held = player.getHeldItem();
|
||||
if (held == null) {
|
||||
sendError(sender, "You are not holding an item.");
|
||||
return;
|
||||
}
|
||||
|
||||
String attrKey = args[0];
|
||||
AttributeDefinition def = AttributeController.getAttribute(attrKey);
|
||||
if (def == null) {
|
||||
sendError(sender, "Unknown attribute: " + attrKey);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this is a magic attribute.
|
||||
if (def.getValueType() == AttributeValueType.MAGIC) {
|
||||
if (args.length < 3) {
|
||||
sendError(sender, "Usage for magic attribute: apply <attribute> <value> <magicID>");
|
||||
return;
|
||||
}
|
||||
int magicId;
|
||||
float value;
|
||||
try {
|
||||
value = Float.parseFloat(args[1]);
|
||||
magicId = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
sendError(sender, "Invalid number format for magicID or value.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (MagicController.getInstance().getMagic(magicId) == null) {
|
||||
sendError(sender, "No Magic Found for Magic ID %d", magicId);
|
||||
return;
|
||||
}
|
||||
|
||||
AttributeItemUtil.writeMagicAttribute(held, attrKey, magicId, value);
|
||||
sendResult(sender, "Applied magic attribute " + attrKey + " with magicID " + magicId + " and value " + value + " to held item.");
|
||||
} else {
|
||||
if (args.length < 2) {
|
||||
sendError(sender, "Usage: <attribute> <value>");
|
||||
return;
|
||||
}
|
||||
float value;
|
||||
try {
|
||||
value = Float.parseFloat(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
sendError(sender, "Invalid number format for value.");
|
||||
return;
|
||||
}
|
||||
AttributeItemUtil.applyAttribute(held, attrKey, value);
|
||||
sendResult(sender, "Applied attribute " + attrKey + " with value " + value + " to held item.");
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
name = "remove",
|
||||
usage = "<attribute> [magicID)",
|
||||
desc = "Removes an attribute from your held item. For magic attributes, provide a magicID."
|
||||
)
|
||||
public void remove(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "Only players can use this command.");
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
ItemStack held = player.getHeldItem();
|
||||
if (held == null) {
|
||||
sendError(sender, "You are not holding an item.");
|
||||
return;
|
||||
}
|
||||
|
||||
String attrKey = args[0];
|
||||
AttributeDefinition def = AttributeController.getAttribute(attrKey);
|
||||
if (def == null) {
|
||||
sendError(sender, "Unknown attribute: " + attrKey);
|
||||
return;
|
||||
}
|
||||
|
||||
if (def.getValueType() == AttributeValueType.MAGIC) {
|
||||
if (args.length < 2) {
|
||||
sendError(sender, "Usage for magic attribute: remove <attribute> <magicID>");
|
||||
return;
|
||||
}
|
||||
int magicId;
|
||||
try {
|
||||
magicId = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
sendError(sender, "Invalid magicID format.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (MagicController.getInstance().getMagic(magicId) == null) {
|
||||
sendError(sender, "No Magic Found for Magic ID %d", magicId);
|
||||
return;
|
||||
}
|
||||
|
||||
AttributeItemUtil.removeMagicAttribute(held, attrKey, magicId);
|
||||
sendResult(sender, "Removed magic attribute " + attrKey + " (magicID " + magicId + ") from held item.");
|
||||
} else {
|
||||
AttributeItemUtil.removeAttribute(held, attrKey);
|
||||
sendResult(sender, "Removed attribute " + attrKey + " from held item.");
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
name = "requirement",
|
||||
usage = "<apply|remove> <requirement> [value]",
|
||||
desc = "Apply or remove a requirement from your held item."
|
||||
)
|
||||
public void requirement(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "Only players can use this command.");
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
ItemStack held = player.getHeldItem();
|
||||
if (held == null) {
|
||||
sendError(sender, "You are not holding an item.");
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sendError(sender, "Usage: requirement <apply|remove> <requirementKey> [value]");
|
||||
return;
|
||||
}
|
||||
String action = args[0];
|
||||
String reqKey = args[1];
|
||||
if (action.equalsIgnoreCase("apply")) {
|
||||
if (args.length < 3) {
|
||||
sendError(sender, "Usage: requirement apply <requirementKey> <value>");
|
||||
return;
|
||||
}
|
||||
String valueStr = args[2];
|
||||
Object value;
|
||||
try {
|
||||
value = Integer.parseInt(valueStr);
|
||||
} catch (NumberFormatException e1) {
|
||||
try {
|
||||
value = Float.parseFloat(valueStr);
|
||||
} catch (NumberFormatException e2) {
|
||||
value = valueStr;
|
||||
}
|
||||
}
|
||||
|
||||
AttributeItemUtil.applyRequirement(held, reqKey, value);
|
||||
sendResult(sender, "Applied requirement " + reqKey + " with value " + value + " to held item.");
|
||||
} else if (action.equalsIgnoreCase("remove")) {
|
||||
AttributeItemUtil.removeRequirement(held, reqKey);
|
||||
sendResult(sender, "Removed requirement " + reqKey + " from held item.");
|
||||
} else {
|
||||
sendError(sender, "Invalid action. Use apply or remove.");
|
||||
}
|
||||
}
|
||||
}
|
||||
+99
-104
@@ -1,8 +1,7 @@
|
||||
package kamkeel.command;
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import foxz.utils.Utils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -18,33 +17,34 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.*;
|
||||
|
||||
public class CloneCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "clone";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "clone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Clone operation (server side)";
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Clone operation (server side)";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Add NPC(s) to clone storage",
|
||||
usage = "<npc> <tab> [clonedname]",
|
||||
permission = 4
|
||||
desc = "Add NPC(s) to clone storage",
|
||||
usage = "<npc> <tab> [clonedname]",
|
||||
permission = 4
|
||||
)
|
||||
public void add(ICommandSender sender, String[] args) {
|
||||
int tab = 0;
|
||||
try{
|
||||
tab = Integer.parseInt(args[1]);
|
||||
if(tab < 0 || tab > 15){
|
||||
try {
|
||||
tab = Integer.parseInt(args[1]);
|
||||
if (tab < 0 || tab > 15) {
|
||||
sendError(sender, "Tab must be within 1-15");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, String.format("Tab is not a number: %s", args[1]));
|
||||
return;
|
||||
}
|
||||
@@ -59,31 +59,30 @@ public class CloneCommand extends CommandKamkeelBase {
|
||||
if (args.length > 2) {
|
||||
name = args[2];
|
||||
}
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if(!npc.writeToNBTOptional(compound))
|
||||
return;
|
||||
ServerCloneController.Instance.addClone(compound, name, tab);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if (!npc.writeToNBTOptional(compound))
|
||||
return;
|
||||
ServerCloneController.Instance.addClone(compound, name, tab);
|
||||
sendResult(sender, String.format("Added NPC \u00A7e%s\u00A77 to Tab \u00A7b%d\u00A77", name, tab));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "List NPC from clone storage",
|
||||
usage = "<tab>",
|
||||
permission = 2
|
||||
desc = "List NPC from clone storage",
|
||||
usage = "<tab>",
|
||||
permission = 2
|
||||
)
|
||||
public void list(ICommandSender sender, String[] args) {
|
||||
sendMessage(sender, "--- Stored NPCs --- (server side)");
|
||||
int tab = 0;
|
||||
try{
|
||||
try {
|
||||
tab = Integer.parseInt(args[1]);
|
||||
if(tab < 0 || tab > 15){
|
||||
if (tab < 0 || tab > 15) {
|
||||
sendError(sender, "Tab must be within 1-15");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, String.format("Tab is not a number: %s", args[1]));
|
||||
return;
|
||||
}
|
||||
@@ -95,32 +94,31 @@ public class CloneCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Remove NPC from clone storage",
|
||||
usage = "<name> <tab>",
|
||||
permission = 4
|
||||
desc = "Remove NPC from clone storage",
|
||||
usage = "<name> <tab>",
|
||||
permission = 4
|
||||
)
|
||||
public void del(ICommandSender sender, String[] args) throws CommandException {
|
||||
String nametodel = args[0];
|
||||
int tab = 0;
|
||||
try{
|
||||
try {
|
||||
tab = Integer.parseInt(args[1]);
|
||||
if(tab < 0 || tab > 15){
|
||||
if (tab < 0 || tab > 15) {
|
||||
sendError(sender, String.format("Tab must be within 1-15"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, String.format("Tab is not a number: %s", args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
boolean deleted = false;
|
||||
for(String name : ServerCloneController.Instance.getClones(tab)){
|
||||
if(nametodel.equalsIgnoreCase(name)){
|
||||
ServerCloneController.Instance.removeClone(name, tab);
|
||||
deleted = true;
|
||||
break;
|
||||
}
|
||||
for (String name : ServerCloneController.Instance.getClones(tab)) {
|
||||
if (nametodel.equalsIgnoreCase(name)) {
|
||||
ServerCloneController.Instance.removeClone(name, tab);
|
||||
deleted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ServerCloneController.Instance.removeClone(nametodel, tab)) {
|
||||
sendError(sender, String.format("NPC '%s' was not found", nametodel));
|
||||
@@ -130,28 +128,27 @@ public class CloneCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Spawn cloned NPC",
|
||||
usage = "<name> <tab> [[world:]x,y,z]] [newname]",
|
||||
permission = 2
|
||||
desc = "Spawn cloned NPC",
|
||||
usage = "<name> <tab> [[world:]x,y,z]] [newname]",
|
||||
permission = 2
|
||||
)
|
||||
public void spawn(ICommandSender sender, String[] args) throws CommandException {
|
||||
String name = args[0].replaceAll("%", " "); // if name of npc separed by space, user must use % in place of space
|
||||
int tab = 0;
|
||||
try{
|
||||
try {
|
||||
tab = Integer.parseInt(args[1]);
|
||||
if(tab < 0 || tab > 15){
|
||||
if (tab < 0 || tab > 15) {
|
||||
sendError(sender, String.format("Tab must be within 1-15"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, String.format("Tab is not a number: %s", args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
String newname=null;
|
||||
String newname = null;
|
||||
NBTTagCompound compound = ServerCloneController.Instance.getCloneData(sender, name, tab);
|
||||
if(compound == null){
|
||||
if (compound == null) {
|
||||
sendError(sender, "Unknown npc");
|
||||
return;
|
||||
}
|
||||
@@ -160,34 +157,34 @@ public class CloneCommand extends CommandKamkeelBase {
|
||||
double posY = sender.getPlayerCoordinates().posY;
|
||||
double posZ = sender.getPlayerCoordinates().posZ;
|
||||
|
||||
if(args.length > 2){
|
||||
if (args.length > 2) {
|
||||
String location = args[2];
|
||||
String[] par;
|
||||
if (location.contains(":")){
|
||||
if (location.contains(":")) {
|
||||
par = location.split(":");
|
||||
location = par[1];
|
||||
world = Utils.getWorld(par[0]);
|
||||
if (world == null){
|
||||
if (world == null) {
|
||||
sendError(sender, String.format("'%s' is an unknown world", par[0]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (location.contains(",")){
|
||||
if (location.contains(",")) {
|
||||
par = location.split(",");
|
||||
if (par.length != 3){
|
||||
if (par.length != 3) {
|
||||
sendError(sender, "Location need be x,y,z");
|
||||
return;
|
||||
}
|
||||
try{
|
||||
posX = CommandBase.func_110666_a(sender, posX, par[0]);
|
||||
posY = CommandBase.func_110665_a(sender, posY, par[1].trim(), 0, 0);
|
||||
posZ = CommandBase.func_110666_a(sender, posZ, par[2]);
|
||||
} catch(NumberFormatException ex){
|
||||
try {
|
||||
posX = func_110666_a(sender, posX, par[0]);
|
||||
posY = func_110665_a(sender, posY, par[1].trim(), 0, 0);
|
||||
posZ = func_110666_a(sender, posZ, par[2]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Location should be in numbers");
|
||||
return;
|
||||
}
|
||||
if (args.length > 3){
|
||||
if (args.length > 3) {
|
||||
newname = args[3];
|
||||
}
|
||||
} else {
|
||||
@@ -195,56 +192,54 @@ public class CloneCommand extends CommandKamkeelBase {
|
||||
}
|
||||
}
|
||||
|
||||
if (posX == 0 && posY == 0 && posZ == 0){//incase it was called from the console and not pos was given
|
||||
if (posX == 0 && posY == 0 && posZ == 0) {//incase it was called from the console and not pos was given
|
||||
sendError(sender, "Location needed");
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = EntityList.createEntityFromNBT(compound, world);
|
||||
entity.setPosition(posX + 0.5, posY + 1, posZ + 0.5);
|
||||
if(entity instanceof EntityNPCInterface){
|
||||
if (entity instanceof EntityNPCInterface) {
|
||||
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
||||
npc.ai.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
|
||||
if(newname != null && !newname.isEmpty())
|
||||
npc.ais.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
|
||||
if (newname != null && !newname.isEmpty())
|
||||
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
|
||||
}
|
||||
world.spawnEntityInWorld(entity);
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Spawn cloned NPC",
|
||||
usage = "<name> <tab> [[world:]x,y,z]] [newname]",
|
||||
permission = 2
|
||||
desc = "Spawn cloned NPC",
|
||||
usage = "<name> <tab> [[world:]x,y,z]] [newname]",
|
||||
permission = 2
|
||||
)
|
||||
public void grid(ICommandSender sender, String[] args) throws CommandException {
|
||||
String name = args[0].replaceAll("%", " "); // if name of npc separed by space, user must use % in place of space
|
||||
int tab = 0;
|
||||
try{
|
||||
try {
|
||||
tab = Integer.parseInt(args[1]);
|
||||
if(tab < 0 || tab > 15){
|
||||
if (tab < 0 || tab > 15) {
|
||||
sendError(sender, String.format("Tab must be within 1-15"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, String.format("Tab is not a number: %s", args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
int width, height;
|
||||
try{
|
||||
try {
|
||||
width = Integer.parseInt(args[2]);
|
||||
height = Integer.parseInt(args[3]);
|
||||
}
|
||||
catch(NumberFormatException ex){
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "length or width was not a number");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String newname=null;
|
||||
String newname = null;
|
||||
NBTTagCompound compound = ServerCloneController.Instance.getCloneData(sender, name, tab);
|
||||
if(compound == null){
|
||||
if (compound == null) {
|
||||
sendError(sender, "Unknown npc");
|
||||
return;
|
||||
}
|
||||
@@ -253,33 +248,33 @@ public class CloneCommand extends CommandKamkeelBase {
|
||||
double posY = sender.getPlayerCoordinates().posY;
|
||||
double posZ = sender.getPlayerCoordinates().posZ;
|
||||
|
||||
if(args.length > 4){
|
||||
if (args.length > 4) {
|
||||
String location = args[4];
|
||||
String[] par;
|
||||
if (location.contains(":")){
|
||||
if (location.contains(":")) {
|
||||
par = location.split(":");
|
||||
location = par[1];
|
||||
world = Utils.getWorld(par[0]);
|
||||
if (world == null){
|
||||
if (world == null) {
|
||||
sendError(sender, String.format("'%s' is an unknown world", par[0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (location.contains(",")){
|
||||
if (location.contains(",")) {
|
||||
par = location.split(",");
|
||||
if (par.length != 3){
|
||||
if (par.length != 3) {
|
||||
sendError(sender, "Location need be x,y,z");
|
||||
return;
|
||||
}
|
||||
try{
|
||||
posX = CommandBase.func_110666_a(sender, posX, par[0]);
|
||||
posY = CommandBase.func_110665_a(sender, posY, par[1].trim(), 0, 0);
|
||||
posZ = CommandBase.func_110666_a(sender, posZ, par[2]);
|
||||
} catch(NumberFormatException ex){
|
||||
try {
|
||||
posX = func_110666_a(sender, posX, par[0]);
|
||||
posY = func_110665_a(sender, posY, par[1].trim(), 0, 0);
|
||||
posZ = func_110666_a(sender, posZ, par[2]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Location should be in numbers");
|
||||
return;
|
||||
}
|
||||
if (args.length > 5){
|
||||
if (args.length > 5) {
|
||||
newname = args[5];
|
||||
}
|
||||
} else {
|
||||
@@ -287,31 +282,31 @@ public class CloneCommand extends CommandKamkeelBase {
|
||||
}
|
||||
}
|
||||
|
||||
if (posX == 0 && posY == 0 && posZ == 0){//incase it was called from the console and not pos was given
|
||||
if (posX == 0 && posY == 0 && posZ == 0) {//incase it was called from the console and not pos was given
|
||||
sendError(sender, "Location needed");
|
||||
return;
|
||||
}
|
||||
|
||||
for(int x = 0; x < width; x++){
|
||||
for(int z = 0; z < height; z++){
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int z = 0; z < height; z++) {
|
||||
Entity entity = EntityList.createEntityFromNBT(compound, world);
|
||||
int xx = MathHelper.floor_double(posX) + x;
|
||||
int yy = Math.max(MathHelper.floor_double(posY) - 2, 1);
|
||||
int zz = MathHelper.floor_double(posZ) + z;
|
||||
|
||||
for(int y = 0; y < 10; y++){
|
||||
for (int y = 0; y < 10; y++) {
|
||||
Block b = world.getBlock(xx, yy + y, zz);
|
||||
Block b2 = world.getBlock(xx, yy + y + 1, zz);
|
||||
if(b != null && (b2 == null || b2.getCollisionBoundingBoxFromPool(world, xx, yy + y + 1, zz) == null)){
|
||||
if (b != null && (b2 == null || b2.getCollisionBoundingBoxFromPool(world, xx, yy + y + 1, zz) == null)) {
|
||||
yy += y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
entity.setPosition(posX + 0.5 + x, yy + 1, posZ + 0.5 + z);
|
||||
if(entity instanceof EntityNPCInterface){
|
||||
if (entity instanceof EntityNPCInterface) {
|
||||
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
||||
npc.ai.startPos = new int[]{xx, yy, zz};
|
||||
if(newname != null && !newname.isEmpty())
|
||||
npc.ais.startPos = new int[]{xx, yy, zz};
|
||||
if (newname != null && !newname.isEmpty())
|
||||
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
|
||||
}
|
||||
world.spawnEntityInWorld(entity);
|
||||
@@ -320,13 +315,13 @@ public class CloneCommand extends CommandKamkeelBase {
|
||||
return;
|
||||
}
|
||||
|
||||
public World getWorld(String t){
|
||||
WorldServer[] ws=MinecraftServer.getServer().worldServers;
|
||||
for (WorldServer w:ws){
|
||||
if (w!=null){
|
||||
if ((w.provider.dimensionId + "").equalsIgnoreCase(t)){
|
||||
return w;
|
||||
}
|
||||
public World getWorld(String t) {
|
||||
WorldServer[] ws = MinecraftServer.getServer().worldServers;
|
||||
for (WorldServer w : ws) {
|
||||
if (w != null) {
|
||||
if ((w.provider.dimensionId + "").equalsIgnoreCase(t)) {
|
||||
return w;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
+4
-1
@@ -1,4 +1,4 @@
|
||||
package kamkeel.command;
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
@@ -10,6 +10,9 @@ import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.CustomNPCsEvent;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendMessage;
|
||||
|
||||
public class CommandCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,171 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.RequirementCheckerRegistry;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
import static kamkeel.npcs.command.EffectCommand.getSortedEffectNames;
|
||||
|
||||
public class CommandKamkeel extends CommandBase {
|
||||
|
||||
public Map<String, CommandKamkeelBase> map = new HashMap<String, CommandKamkeelBase>();
|
||||
public HelpCommand help = new HelpCommand(this);
|
||||
public String[] alias = {"kam"};
|
||||
|
||||
public CommandKamkeel() {
|
||||
registerCommand(help);
|
||||
registerCommand(new ScriptCommand());
|
||||
registerCommand(new SlayCommand());
|
||||
registerCommand(new QuestCommand());
|
||||
registerCommand(new QuestCategoryCommand());
|
||||
registerCommand(new DialogCommand());
|
||||
registerCommand(new DialogCategoryCommand());
|
||||
registerCommand(new FactionCommand());
|
||||
registerCommand(new NpcCommand());
|
||||
registerCommand(new CloneCommand());
|
||||
registerCommand(new ConfigCommand());
|
||||
registerCommand(new AnimationCommand());
|
||||
registerCommand(new OverlayCommand());
|
||||
registerCommand(new CommandCommand());
|
||||
registerCommand(new EffectCommand());
|
||||
if (ConfigMain.AttributesEnabled)
|
||||
registerCommand(new AttributeCommand());
|
||||
}
|
||||
|
||||
public void registerCommand(CommandKamkeelBase command) {
|
||||
String name = command.getCommandName().toLowerCase();
|
||||
if (map.containsKey(name))
|
||||
throw new CustomNPCsException("Already a subcommand with the name: " + name);
|
||||
map.put(name, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "kamkeel";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getCommandAliases() {
|
||||
return Arrays.asList(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "Use as /kamkeel subcommand";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length == 0) {
|
||||
help.processCommand(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
CommandKamkeelBase command = getCommand(args);
|
||||
if (command == null)
|
||||
throw new CommandException("Unknown command " + args[0]);
|
||||
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
if (command.subcommands.isEmpty() || !command.runSubCommands()) {
|
||||
if (!canSendCommand(sender, command))
|
||||
throw new CommandException("You are not allowed to use this command: " + command);
|
||||
command.canRun(sender, command.getUsage(), args);
|
||||
command.processCommand(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
help.processCommand(sender, new String[]{command.getCommandName()});
|
||||
return;
|
||||
}
|
||||
|
||||
command.processSubCommand(sender, args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
|
||||
if (args.length == 1)
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, map.keySet().toArray(new String[map.size()]));
|
||||
CommandKamkeelBase command = getCommand(args);
|
||||
if (command == null)
|
||||
return null;
|
||||
if (args.length == 2 && command.runSubCommands())
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, command.subcommands.keySet().toArray(new String[command.subcommands.keySet().size()]));
|
||||
String[] useArgs = command.getUsage().split(" ");
|
||||
if (command.runSubCommands()) {
|
||||
Method m = command.subcommands.get(args[1].toLowerCase());
|
||||
if (m != null) {
|
||||
useArgs = m.getAnnotation(CommandKamkeelBase.SubCommand.class).usage().split(" ");
|
||||
}
|
||||
}
|
||||
if (args.length <= useArgs.length + 2) {
|
||||
if (args.length - 3 >= 0) {
|
||||
String usage = useArgs[args.length - 3];
|
||||
if (usage.equals("<player>") || usage.equals("[player]")) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
} else if (usage.equals("<attribute>")) {
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (AttributeDefinition def : AttributeController.getAllAttributes()) {
|
||||
keys.add(def.getKey());
|
||||
}
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, keys.toArray(new String[keys.size()]));
|
||||
} else if (usage.equals("<requirement>")) {
|
||||
List<String> keys = new ArrayList<>(RequirementCheckerRegistry.getAllKeys());
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, keys.toArray(new String[keys.size()]));
|
||||
} else if (usage.equals("<effectName>")) {
|
||||
List<String> keys = getSortedEffectNames();
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, keys.toArray(new String[keys.size()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return command.addTabCompletionOptions(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
|
||||
public CommandKamkeelBase getCommand(String[] args) {
|
||||
if (args.length == 0)
|
||||
return null;
|
||||
return map.get(args[0].toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public static String getCommandPermission(String command) {
|
||||
return "cnpc.kamkeel." + command.toLowerCase();
|
||||
}
|
||||
|
||||
public static String getUniversalPermission() {
|
||||
return "cnpc.kamkeel.*";
|
||||
}
|
||||
|
||||
public static boolean canSendCommand(ICommandSender sender, CommandKamkeelBase command) {
|
||||
if (sender.canCommandSenderUseCommand(command.getRequiredPermissionLevel(), getUniversalPermission())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.canCommandSenderUseCommand(command.getRequiredPermissionLevel(), getCommandPermission(command.getCommandName()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender instanceof EntityPlayer) {
|
||||
return CustomNpcsPermissions.hasCustomPermission((EntityPlayer) sender, getCommandPermission(command.getCommandName()));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class CommandKamkeelBase extends CommandBase {
|
||||
public Map<String, Method> subcommands = new HashMap<String, Method>();
|
||||
|
||||
public CommandKamkeelBase() {
|
||||
for (Method m : this.getClass().getDeclaredMethods()) {
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
if (sc != null) {
|
||||
String name = sc.name();
|
||||
if (name.equals(""))
|
||||
name = m.getName();
|
||||
subcommands.put(name.toLowerCase(), m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return getDescription();
|
||||
}
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
/**
|
||||
* @return Should return a string in the format of <arg> <arg2> <arg3> [arg4] where <> is a required parameter and [] optional
|
||||
*/
|
||||
public String getUsage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean runSubCommands() {
|
||||
return !subcommands.isEmpty();
|
||||
}
|
||||
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface SubCommand {
|
||||
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* @return Should return a string in the format of <arg> <arg2> <arg3> [arg4] where <> is a required parameter and [] optional
|
||||
*/
|
||||
String usage() default "";
|
||||
|
||||
String desc();
|
||||
|
||||
int permission() default 2;
|
||||
}
|
||||
|
||||
public void processSubCommand(ICommandSender sender, String command, String[] args) throws CommandException {
|
||||
Method m = subcommands.get(command.toLowerCase());
|
||||
if (m == null)
|
||||
throw new CommandException("Unknown subcommand " + command);
|
||||
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
if (!canSendCommand(sender, sc, command))
|
||||
throw new CommandException("You are not allowed to use this command: " + command);
|
||||
|
||||
canRun(sender, sc.usage(), args);
|
||||
try {
|
||||
m.invoke(this, sender, args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void canRun(ICommandSender sender, String usage, String[] args) throws CommandException {
|
||||
String[] np = usage.split(" ");
|
||||
List<String> required = new ArrayList<String>();
|
||||
for (int i = 0; i < np.length; i++) {
|
||||
String command = np[i];
|
||||
if (command.startsWith("<")) {
|
||||
required.add(command);
|
||||
}
|
||||
if (command.equals("<player>") && args.length > i) {
|
||||
CommandBase.getPlayer(sender, args[i]); //throws PlayerNotFoundException if no player is found
|
||||
}
|
||||
|
||||
}
|
||||
if (args.length < required.size()) {
|
||||
throw new CommandException("Missing parameter: " + required.get(args.length));
|
||||
}
|
||||
}
|
||||
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public String getSubCommandPermission(String subCommand) {
|
||||
return "cnpc.kamkeel." + getCommandName().toLowerCase() + "." + subCommand.toLowerCase();
|
||||
}
|
||||
|
||||
public String getSubUniversalPermission() {
|
||||
return "cnpc.kamkeel." + getCommandName().toLowerCase() + "*";
|
||||
}
|
||||
|
||||
public boolean canSendCommand(ICommandSender sender, SubCommand command, String subCommand) {
|
||||
if (sender.canCommandSenderUseCommand(command.permission(), getSubUniversalPermission())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.canCommandSenderUseCommand(command.permission(), getSubCommandPermission(subCommand))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender instanceof EntityPlayer) {
|
||||
return CustomNpcsPermissions.hasCustomPermission((EntityPlayer) sender, getSubCommandPermission(subCommand));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import foxz.utils.Market;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumConfigOperation;
|
||||
import kamkeel.npcs.network.packets.data.ConfigCommandPacket;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockIce;
|
||||
import net.minecraft.block.BlockLeavesBase;
|
||||
import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.config.ConfigItem;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.controllers.ChunkController;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class ConfigCommand extends CommandKamkeelBase {
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "config";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Some config things you can set";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable/Enable the natural leaves decay",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void leavesdecay(ICommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendResult(sender, "LeavesDecay: \u00A7c" + ConfigMain.LeavesDecayEnabled);
|
||||
} else {
|
||||
ConfigMain.LeavesDecayEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.LeavesDecayEnabledProperty.set(ConfigMain.LeavesDecayEnabled);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
Set<ResourceLocation> names = Block.blockRegistry.getKeys();
|
||||
for (ResourceLocation name : names) {
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if (block instanceof BlockLeavesBase) {
|
||||
block.setTickRandomly(ConfigMain.LeavesDecayEnabled);
|
||||
}
|
||||
}
|
||||
sendResult(sender, "LeavesDecay is now \u00A7c" + ConfigMain.LeavesDecayEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable/Enable the vines growing",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void vinegrowth(ICommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendResult(sender, "VineGrowth: \u00A7c" + ConfigMain.VineGrowthEnabled);
|
||||
} else {
|
||||
ConfigMain.VineGrowthEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.VineGrowthEnabledProperty.set(ConfigMain.VineGrowthEnabled);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
Set<ResourceLocation> names = Block.blockRegistry.getKeys();
|
||||
for (ResourceLocation name : names) {
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if (block instanceof BlockVine) {
|
||||
block.setTickRandomly(ConfigMain.VineGrowthEnabled);
|
||||
}
|
||||
}
|
||||
sendResult(sender, "VineGrowth is now \u00A7c" + ConfigMain.VineGrowthEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable/Enable the ice melting",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void icemelts(ICommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendResult(sender, "IceMelts: \u00A7c" + ConfigMain.IceMeltsEnabled);
|
||||
} else {
|
||||
ConfigMain.IceMeltsEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigMain.IceMeltsEnabledProperty.set(ConfigMain.IceMeltsEnabled);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
Set<ResourceLocation> names = Block.blockRegistry.getKeys();
|
||||
for (ResourceLocation name : names) {
|
||||
Block block = (Block) Block.blockRegistry.getObject(name);
|
||||
if (block instanceof BlockIce) {
|
||||
block.setTickRandomly(ConfigMain.IceMeltsEnabled);
|
||||
}
|
||||
}
|
||||
sendResult(sender, "IceMelts is now \u00A7c" + ConfigMain.IceMeltsEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable/Enable guns shooting",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void guns(ICommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendResult(sender, "GunsEnabled: \u00A7c" + ConfigItem.GunsEnabled);
|
||||
} else {
|
||||
ConfigItem.GunsEnabled = Boolean.parseBoolean(args[0]);
|
||||
ConfigItem.GunsEnabledProperty.set(ConfigItem.GunsEnabled);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "GunsEnabled is now \u00A7c" + ConfigItem.GunsEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Freezes/Unfreezes npcs",
|
||||
usage = "[true/false]",
|
||||
permission = 4
|
||||
)
|
||||
public void freezenpcs(ICommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendResult(sender, "Frozen NPCs: \u00A7c" + CustomNpcs.FreezeNPCs);
|
||||
} else {
|
||||
CustomNpcs.FreezeNPCs = Boolean.parseBoolean(args[0]);
|
||||
sendResult(sender, "FrozenNPCs is now \u00A7c" + CustomNpcs.FreezeNPCs);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set number of active chunkloaders",
|
||||
usage = "<number>",
|
||||
permission = 4
|
||||
)
|
||||
public void chunkloaders(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length == 0) {
|
||||
sendResult(sender, "ChunkLoaders: \u00A7c" + ChunkController.Instance.size() + "\u00A77/\u00A7c" + ConfigMain.ChunkLoaders);
|
||||
} else {
|
||||
try {
|
||||
ConfigMain.ChunkLoaders = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Did not get a number: " + args[0]);
|
||||
return;
|
||||
}
|
||||
ConfigMain.ChunkLoadersProperty.set(ConfigMain.ChunkLoaders);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
|
||||
int size = ChunkController.Instance.size();
|
||||
if (size > ConfigMain.ChunkLoaders) {
|
||||
ChunkController.Instance.unload(size - ConfigMain.ChunkLoaders);
|
||||
sendResult(sender, size - ConfigMain.ChunkLoaders + " chunksloaders unloaded");
|
||||
}
|
||||
sendResult(sender, "ChunkLoaders: \u00A7c" + ChunkController.Instance.size() + "\u00A77/\u00A7c" + ConfigMain.ChunkLoaders);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Generate PlayerData to JSON/DAT",
|
||||
usage = "[fileType] [convert]",
|
||||
permission = 4
|
||||
)
|
||||
public void playerdata(ICommandSender sender, String[] args) throws CommandException {
|
||||
String fileType;
|
||||
if (ConfigMain.DatFormat) {
|
||||
fileType = "DAT";
|
||||
} else {
|
||||
fileType = "JSON";
|
||||
}
|
||||
if (args.length == 0) {
|
||||
sendResult(sender, "PlayerData Filetype: \u00A7c" + fileType);
|
||||
} else if (args.length == 1) {
|
||||
sendResult(sender, "Please write the word 'convert' at the end to confirm. \u00A7c<dat/json> convert");
|
||||
} else {
|
||||
if (args.length != 2) {
|
||||
sendError(sender, "Two many arguments");
|
||||
return;
|
||||
}
|
||||
String formatType = args[0].toLowerCase();
|
||||
if (!formatType.equals("dat") && !formatType.equals("json")) {
|
||||
sendError(sender, "Invalid Format Type - Please use dat or json");
|
||||
return;
|
||||
}
|
||||
|
||||
String convert = args[1].toLowerCase();
|
||||
if (!convert.equals("convert")) {
|
||||
sendError(sender, "Please enter the word 'convert' at the end");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean convertToDat = formatType.equals("dat");
|
||||
EntityPlayerMP send = null;
|
||||
if (sender instanceof EntityPlayerMP) {
|
||||
send = (EntityPlayerMP) sender;
|
||||
}
|
||||
|
||||
sendResult(sender, "Started Conversion Process for PlayerData");
|
||||
PlayerDataController.Instance.convertPlayerFiles(send, convertToDat);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Generate Market to JSON/DAT",
|
||||
usage = "[fileType] [convert]",
|
||||
permission = 4
|
||||
)
|
||||
public void market(ICommandSender sender, String[] args) throws CommandException {
|
||||
String fileType;
|
||||
if (ConfigMain.MarketDatFormat) {
|
||||
fileType = "DAT";
|
||||
} else {
|
||||
fileType = "JSON";
|
||||
}
|
||||
if (args.length == 0) {
|
||||
sendResult(sender, "Market Filetype: \u00A7c" + fileType);
|
||||
} else if (args.length == 1) {
|
||||
sendResult(sender, "Please write the word 'convert' at the end to confirm. \u00A7c<dat/json> convert");
|
||||
} else {
|
||||
if (args.length != 2) {
|
||||
sendError(sender, "Two many arguments");
|
||||
return;
|
||||
}
|
||||
String formatType = args[0].toLowerCase();
|
||||
if (!formatType.equals("dat") && !formatType.equals("json")) {
|
||||
sendError(sender, "Invalid Format Type - Please use dat or json");
|
||||
return;
|
||||
}
|
||||
|
||||
String convert = args[1].toLowerCase();
|
||||
if (!convert.equals("convert")) {
|
||||
sendError(sender, "Please enter the word 'convert' at the end");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean convertToDat = formatType.equals("dat");
|
||||
EntityPlayerMP send = null;
|
||||
if (sender instanceof EntityPlayerMP) {
|
||||
send = (EntityPlayerMP) sender;
|
||||
}
|
||||
|
||||
sendResult(sender, "Started Conversion Process for Market");
|
||||
Market.convertMarketFiles(send, convertToDat);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Get/Set font",
|
||||
usage = "[type] [size]",
|
||||
permission = 4
|
||||
)
|
||||
public void font(ICommandSender sender, String[] args) {
|
||||
if (!(sender instanceof EntityPlayerMP))
|
||||
return;
|
||||
int size = 18;
|
||||
if (args.length > 1) {
|
||||
try {
|
||||
size = Integer.parseInt(args[args.length - 1]);
|
||||
args = Arrays.copyOfRange(args, 0, args.length - 1);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
String font = "";
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
font += " " + args[i];
|
||||
}
|
||||
PacketHandler.Instance.sendToPlayer(new ConfigCommandPacket(EnumConfigOperation.FONT, font.trim(), size), (EntityPlayerMP) sender);
|
||||
}
|
||||
}
|
||||
|
||||
+38
-37
@@ -1,4 +1,4 @@
|
||||
package kamkeel.command;
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
@@ -11,24 +11,27 @@ import noppes.npcs.controllers.data.PlayerData;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class DialogCategoryCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "dialogcat";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "dialogcat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Dialog Category operations";
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Dialog Category operations";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Find dialog category id number by its name",
|
||||
usage = "<dialog cat name>"
|
||||
desc = "Find dialog category id number by its name",
|
||||
usage = "<dialog cat name>"
|
||||
)
|
||||
public void id(ICommandSender sender, String args[]) throws CommandException {
|
||||
if(args.length == 0){
|
||||
if (args.length == 0) {
|
||||
sendError(sender, "Please provide a name for the dialog category");
|
||||
return;
|
||||
}
|
||||
@@ -36,48 +39,47 @@ public class DialogCategoryCommand extends CommandKamkeelBase {
|
||||
String catName = String.join(" ", args).toLowerCase();
|
||||
final Collection<DialogCategory> dialogCats = DialogController.Instance.categories.values();
|
||||
int count = 0;
|
||||
for(DialogCategory cat : dialogCats){
|
||||
if(cat.getName().toLowerCase().contains(catName)){
|
||||
for (DialogCategory cat : dialogCats) {
|
||||
if (cat.getName().toLowerCase().contains(catName)) {
|
||||
sendResult(sender, String.format("Dialog Cat \u00A7e%d\u00A77 - \u00A7c'%s'", cat.id, cat.getName()));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(count == 0){
|
||||
if (count == 0) {
|
||||
sendResult(sender, String.format("No Dialog Cat found with name: \u00A7c'%s'", catName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc = "Read a dialog category for a player",
|
||||
usage = "<player> <dialogcatid>"
|
||||
desc = "Read a dialog category for a player",
|
||||
usage = "<player> <dialogcatid>"
|
||||
)
|
||||
public void read(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void read(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int dialogCatId;
|
||||
try {
|
||||
dialogCatId = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
sendError(sender, "DialogCatID must be an integer: " + args[1]);
|
||||
dialogCatId = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "DialogCatID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, String.format("Unknown player '%s'", playername));
|
||||
sendError(sender, String.format("Unknown player '%s'", playername));
|
||||
return;
|
||||
}
|
||||
|
||||
DialogCategory dialogCategory = DialogController.Instance.categories.get(dialogCatId);
|
||||
if (dialogCategory == null){
|
||||
sendError(sender, "Unknown DialogCatID: " + dialogCatId);
|
||||
if (dialogCategory == null) {
|
||||
sendError(sender, "Unknown DialogCatID: " + dialogCatId);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for(PlayerData playerdata : data){
|
||||
for(Dialog dialog : dialogCategory.dialogs.values()){
|
||||
for (PlayerData playerdata : data) {
|
||||
for (Dialog dialog : dialogCategory.dialogs.values()) {
|
||||
playerdata.dialogData.dialogsRead.add(dialog.id);
|
||||
count++;
|
||||
}
|
||||
@@ -91,16 +93,15 @@ public class DialogCategoryCommand extends CommandKamkeelBase {
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc = "Unread a dialog category for a player",
|
||||
usage = "<player> <dialogcatid>"
|
||||
desc = "Unread a dialog category for a player",
|
||||
usage = "<player> <dialogcatid>"
|
||||
)
|
||||
public void unread(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void unread(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int dialogCatId;
|
||||
try {
|
||||
dialogCatId = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "DialogCatID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
@@ -112,14 +113,14 @@ public class DialogCategoryCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
DialogCategory dialogCategory = DialogController.Instance.categories.get(dialogCatId);
|
||||
if (dialogCategory == null){
|
||||
if (dialogCategory == null) {
|
||||
sendError(sender, "Unknown DialogCatID: " + dialogCatId);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for(PlayerData playerdata : data){
|
||||
for(Dialog dialog : dialogCategory.dialogs.values()){
|
||||
for (PlayerData playerdata : data) {
|
||||
for (Dialog dialog : dialogCategory.dialogs.values()) {
|
||||
playerdata.dialogData.dialogsRead.remove(dialog.id);
|
||||
count++;
|
||||
}
|
||||
+73
-69
@@ -1,5 +1,6 @@
|
||||
package kamkeel.command;
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
@@ -10,7 +11,6 @@ import noppes.npcs.constants.EnumAvailabilityDialog;
|
||||
import noppes.npcs.constants.EnumAvailabilityQuest;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
import noppes.npcs.controllers.data.Availability;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogOption;
|
||||
@@ -20,27 +20,30 @@ import noppes.npcs.entity.EntityDialogNpc;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class DialogCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "dialog";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "dialog";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Dialog operations";
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Dialog operations";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "force read",
|
||||
usage = "<player> <dialog>"
|
||||
desc = "force read",
|
||||
usage = "<player> <dialog>"
|
||||
)
|
||||
public void read(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void read(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int diagid;
|
||||
try {
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "DialogID must be an integer: " + args[1]);
|
||||
return;
|
||||
@@ -50,8 +53,8 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.dialogData.dialogsRead.add(diagid);
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.dialogData.dialogsRead.add(diagid);
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Forced Read for Dialog \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", diagid, playerdata.playername));
|
||||
@@ -59,14 +62,14 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "force unread dialog",
|
||||
usage = "<player> <dialog>"
|
||||
desc = "force unread dialog",
|
||||
usage = "<player> <dialog>"
|
||||
)
|
||||
public void unread(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void unread(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int diagid;
|
||||
try {
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "DialogID must be an integer: " + args[1]);
|
||||
return;
|
||||
@@ -76,64 +79,65 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.dialogData.dialogsRead.remove(diagid);
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.dialogData.dialogsRead.remove(diagid);
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Forced Unread for Dialog \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", diagid, playerdata.playername));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="reload dialogs from disk",
|
||||
permission = 4
|
||||
desc = "reload dialogs from disk",
|
||||
permission = 4
|
||||
)
|
||||
public void reload(ICommandSender sender, String args[]){
|
||||
new DialogController().load();
|
||||
public void reload(ICommandSender sender, String args[]) {
|
||||
new DialogController().load();
|
||||
SyncController.syncAllDialogs();
|
||||
sendResult(sender, "Dialogs Reloaded");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="show dialog",
|
||||
usage="<player> <dialog> <name>"
|
||||
desc = "show dialog",
|
||||
usage = "<player> <dialog> <name>"
|
||||
)
|
||||
public void show(ICommandSender sender, String args[]) throws CommandException{
|
||||
EntityPlayer player = CommandBase.getPlayer(sender, args[0]);
|
||||
if(player == null){
|
||||
public void show(ICommandSender sender, String args[]) throws CommandException {
|
||||
EntityPlayer player = CommandBase.getPlayer(sender, args[0]);
|
||||
if (player == null) {
|
||||
sendError(sender, "Unknown player: " + args[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int diagid;
|
||||
try {
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
diagid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "DialogID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
Dialog dialog = DialogController.Instance.dialogs.get(diagid);
|
||||
if(dialog == null){
|
||||
if (dialog == null) {
|
||||
sendError(sender, "Unknown dialog id: " + args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
EntityDialogNpc npc = new EntityDialogNpc(sender.getEntityWorld());
|
||||
npc.display.setName(args[2]);
|
||||
EntityUtil.Copy(player, npc);
|
||||
DialogOption option = new DialogOption();
|
||||
option.dialogId = diagid;
|
||||
option.title = dialog.title;
|
||||
npc.dialogs.put(0, option);
|
||||
NoppesUtilServer.openDialog(player, npc, dialog, 0);
|
||||
EntityDialogNpc npc = new EntityDialogNpc(sender.getEntityWorld());
|
||||
npc.display.setName(args[2]);
|
||||
EntityUtil.Copy(player, npc);
|
||||
DialogOption option = new DialogOption();
|
||||
option.dialogId = diagid;
|
||||
option.title = dialog.title;
|
||||
npc.dialogs.put(0, option);
|
||||
NoppesUtilServer.openDialog(player, npc, dialog, 0);
|
||||
sendResult(sender, String.format("Displayed Dialog \u00A7e%d\u00A77 to Player '\u00A7b%s\u00A77'", diagid, player.getCommandSenderName()));
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Find dialog id number by its name",
|
||||
usage = "<dialogName>"
|
||||
desc = "Find dialog id number by its name",
|
||||
usage = "<dialogName>"
|
||||
)
|
||||
public void id(ICommandSender sender, String args[]) throws CommandException {
|
||||
if(args.length == 0){
|
||||
if (args.length == 0) {
|
||||
sendError(sender, "Please provide a name for the dialog");
|
||||
return;
|
||||
}
|
||||
@@ -141,23 +145,23 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
String dialogName = String.join(" ", args).toLowerCase();
|
||||
final Collection<Dialog> quests = DialogController.Instance.dialogs.values();
|
||||
int count = 0;
|
||||
for(Dialog dialog : quests){
|
||||
if(dialog.getName().toLowerCase().contains(dialogName)){
|
||||
for (Dialog dialog : quests) {
|
||||
if (dialog.getName().toLowerCase().contains(dialogName)) {
|
||||
sendResult(sender, String.format("Dialog \u00A7e%d\u00A77 - \u00A7c'%s'", dialog.id, dialog.getName()));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(count == 0){
|
||||
if (count == 0) {
|
||||
sendResult(sender, String.format("No Dialog found with name: \u00A7c'%s'", dialogName));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "List a dialogs availability options",
|
||||
usage = "<dialogId>"
|
||||
desc = "List a dialogs availability options",
|
||||
usage = "<dialogId>"
|
||||
)
|
||||
public void availability(ICommandSender sender, String args[]) throws CommandException {
|
||||
if(args.length == 0){
|
||||
if (args.length == 0) {
|
||||
sendError(sender, "Please provide an id for the dialog");
|
||||
return;
|
||||
}
|
||||
@@ -170,56 +174,56 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
return;
|
||||
}
|
||||
Dialog dialog = DialogController.Instance.dialogs.get(diagid);
|
||||
if(dialog == null){
|
||||
if (dialog == null) {
|
||||
sendError(sender, "Unknown dialog id: " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
Availability avail = dialog.availability;
|
||||
if(avail != null){
|
||||
if (avail != null) {
|
||||
sendResult(sender, String.format("Availability Options for Dialog: \u00A7c%d", dialog.id));
|
||||
sendResult(sender, "--------------------");
|
||||
boolean diagFound = false;
|
||||
if(avail.dialogId != -1 && avail.dialogAvailable != EnumAvailabilityDialog.Always){
|
||||
if (avail.dialogId != -1 && avail.dialogAvailable != EnumAvailabilityDialog.Always) {
|
||||
sendResult(sender, String.format("%s Dialog: \u00A7c%d", avail.dialogAvailable.toString(), avail.dialogId));
|
||||
diagFound = true;
|
||||
}
|
||||
if(avail.dialog2Id != -1 && avail.dialog2Available != EnumAvailabilityDialog.Always){
|
||||
if (avail.dialog2Id != -1 && avail.dialog2Available != EnumAvailabilityDialog.Always) {
|
||||
sendResult(sender, String.format("%s Dialog: \u00A7c%d", avail.dialog2Available.toString(), avail.dialog2Id));
|
||||
diagFound = true;
|
||||
}
|
||||
if(avail.dialog3Id != -1 && avail.dialog3Available != EnumAvailabilityDialog.Always){
|
||||
if (avail.dialog3Id != -1 && avail.dialog3Available != EnumAvailabilityDialog.Always) {
|
||||
sendResult(sender, String.format("%s Dialog: \u00A7c%d", avail.dialog3Available.toString(), avail.dialog3Id));
|
||||
diagFound = true;
|
||||
}
|
||||
if(avail.dialog4Id != -1 && avail.dialog4Available != EnumAvailabilityDialog.Always){
|
||||
if (avail.dialog4Id != -1 && avail.dialog4Available != EnumAvailabilityDialog.Always) {
|
||||
sendResult(sender, String.format("%s Dialog: \u00A7c%d", avail.dialog4Available.toString(), avail.dialog4Id));
|
||||
diagFound = true;
|
||||
}
|
||||
|
||||
if(!diagFound){
|
||||
if (!diagFound) {
|
||||
sendResult(sender, "No Dialog Availability Options");
|
||||
}
|
||||
sendResult(sender, "--------------------");
|
||||
|
||||
boolean questFound = false;
|
||||
if(avail.questId != -1 && avail.questAvailable != EnumAvailabilityQuest.Always){
|
||||
if (avail.questId != -1 && avail.questAvailable != EnumAvailabilityQuest.Always) {
|
||||
sendResult(sender, String.format("%s Quest: \u00A7c%d", avail.questAvailable.toString(), avail.questId));
|
||||
questFound = true;
|
||||
}
|
||||
if(avail.quest2Id != -1 && avail.quest2Available != EnumAvailabilityQuest.Always){
|
||||
if (avail.quest2Id != -1 && avail.quest2Available != EnumAvailabilityQuest.Always) {
|
||||
sendResult(sender, String.format("%s Quest: \u00A7c%d", avail.quest2Available.toString(), avail.quest2Id));
|
||||
questFound = true;
|
||||
}
|
||||
if(avail.quest3Id != -1 && avail.quest3Available != EnumAvailabilityQuest.Always){
|
||||
if (avail.quest3Id != -1 && avail.quest3Available != EnumAvailabilityQuest.Always) {
|
||||
sendResult(sender, String.format("%s Quest: \u00A7c%d", avail.quest3Available.toString(), avail.quest3Id));
|
||||
questFound = true;
|
||||
}
|
||||
if(avail.quest4Id != -1 && avail.quest4Available != EnumAvailabilityQuest.Always){
|
||||
if (avail.quest4Id != -1 && avail.quest4Available != EnumAvailabilityQuest.Always) {
|
||||
sendResult(sender, String.format("%s Quest: \u00A7c%d", avail.quest4Available.toString(), avail.quest4Id));
|
||||
questFound = true;
|
||||
}
|
||||
if(!questFound){
|
||||
if (!questFound) {
|
||||
sendResult(sender, "No Quest Availability Options");
|
||||
}
|
||||
sendResult(sender, "--------------------");
|
||||
@@ -227,11 +231,11 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Quick info on a dialog",
|
||||
usage = "<dialogId>"
|
||||
desc = "Quick info on a dialog",
|
||||
usage = "<dialogId>"
|
||||
)
|
||||
public void info(ICommandSender sender, String args[]) throws CommandException {
|
||||
if(args.length == 0){
|
||||
if (args.length == 0) {
|
||||
sendError(sender, "Please provide an id for the quest");
|
||||
return;
|
||||
}
|
||||
@@ -244,7 +248,7 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
return;
|
||||
}
|
||||
Dialog dialog = DialogController.Instance.dialogs.get(diagid);
|
||||
if(dialog == null){
|
||||
if (dialog == null) {
|
||||
sendError(sender, "Unknown dialog id: " + args[0]);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.scripted.event.PlayerEvent.EffectEvent.ExpirationType;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class EffectCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Custom Effect operations";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "effect";
|
||||
}
|
||||
|
||||
// List command with pagination
|
||||
@SubCommand(desc = "Lists all Effects", usage = "[page]")
|
||||
public void list(ICommandSender sender, String[] args) throws CommandException {
|
||||
CustomEffectController controller = CustomEffectController.getInstance();
|
||||
if (controller.indexMapper.isEmpty()) {
|
||||
sendError(sender, "No effects found.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Flatten effects into a list
|
||||
List<EffectEntry> effectsList = new ArrayList<>();
|
||||
for (Map.Entry<Integer, HashMap<Integer, CustomEffect>> entry : controller.indexMapper.entrySet()) {
|
||||
int idx = entry.getKey();
|
||||
Map<Integer, CustomEffect> effects = entry.getValue();
|
||||
if (effects == null || effects.isEmpty())
|
||||
continue;
|
||||
for (Map.Entry<Integer, CustomEffect> effectEntry : effects.entrySet()) {
|
||||
int id = effectEntry.getKey();
|
||||
CustomEffect effect = effectEntry.getValue();
|
||||
effectsList.add(new EffectEntry(idx, id, effect));
|
||||
}
|
||||
}
|
||||
// Sort by index then by effect ID
|
||||
Collections.sort(effectsList, Comparator.comparingInt((EffectEntry e) -> e.index)
|
||||
.thenComparingInt(e -> e.id));
|
||||
|
||||
// Determine page number
|
||||
int page = 1;
|
||||
if (args.length > 0) {
|
||||
try {
|
||||
page = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
// default to page 1
|
||||
}
|
||||
}
|
||||
int perPage = 10;
|
||||
int total = effectsList.size();
|
||||
int totalPages = (int) Math.ceil(total / (double) perPage);
|
||||
if (page < 1) page = 1;
|
||||
if (page > totalPages) page = totalPages;
|
||||
int startIndex = (page - 1) * perPage;
|
||||
int endIndex = Math.min(startIndex + perPage, total);
|
||||
|
||||
sendResult(sender, "--------------------");
|
||||
sendResult(sender, "Effects (Page " + page + "/" + totalPages + "):");
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
EffectEntry entry = effectsList.get(i);
|
||||
sendResult(sender, String.format("\u00a7b%s \u00a77(ID: %d, INDEX: %d)",
|
||||
entry.effect.getName(),
|
||||
entry.id,
|
||||
entry.index));
|
||||
}
|
||||
sendResult(sender, "--------------------");
|
||||
}
|
||||
|
||||
|
||||
// Give effect by name.
|
||||
// Usage: <player> <time> <effectName>
|
||||
@SubCommand(desc = "Gives an effect to a player", usage = "<player> <time> <effectName>")
|
||||
public void give(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 3) {
|
||||
sendError(sender, "Usage: <player> <time> <effectName>");
|
||||
return;
|
||||
}
|
||||
|
||||
String playername = args[0];
|
||||
int time;
|
||||
try {
|
||||
time = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
sendError(sender, "Invalid time: " + args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Join all remaining arguments as the effect name.
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
sb.append(args[i]).append(i < args.length - 1 ? " " : "");
|
||||
}
|
||||
String effectName = sb.toString();
|
||||
|
||||
List<EffectEntry> matches = findEffectsByName(effectName);
|
||||
if (matches.isEmpty()) {
|
||||
sendError(sender, "Unknown effect: " + effectName);
|
||||
return;
|
||||
}
|
||||
if (matches.size() > 1) {
|
||||
StringBuilder ambig = new StringBuilder();
|
||||
ambig.append("Ambiguous effect name '").append(effectName).append("'. Multiple matches: ");
|
||||
for (EffectEntry match : matches) {
|
||||
ambig.append(match.effect.getName())
|
||||
.append(" (ID: ").append(match.id)
|
||||
.append(", INDEX: ").append(match.index)
|
||||
.append("), ");
|
||||
}
|
||||
sendError(sender, ambig.substring(0, ambig.length() - 2));
|
||||
return;
|
||||
}
|
||||
EffectEntry match = matches.get(0);
|
||||
|
||||
List<PlayerData> players = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (players.isEmpty()) {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
|
||||
for (PlayerData pdata : players) {
|
||||
if (pdata.player != null) {
|
||||
CustomEffectController.getInstance().applyEffect(pdata.player, match.id, time, (byte) 1, match.index);
|
||||
sendResult(sender, String.format("%s §agiven to §7'§b%s§7'", match.effect.getName(), pdata.playername));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove effect by name.
|
||||
// Usage: <player> <effectName>
|
||||
@SubCommand(desc = "Removes an effect from a player", usage = "<player> <effectName>")
|
||||
public void remove(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 2) {
|
||||
sendError(sender, "Usage: <player> <effectName>");
|
||||
return;
|
||||
}
|
||||
|
||||
String playername = args[0];
|
||||
// Join all remaining arguments as the effect name.
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
sb.append(args[i]).append(i < args.length - 1 ? " " : "");
|
||||
}
|
||||
String effectName = sb.toString();
|
||||
|
||||
List<EffectEntry> matches = findEffectsByName(effectName);
|
||||
if (matches.isEmpty()) {
|
||||
sendError(sender, "Unknown effect: " + effectName);
|
||||
return;
|
||||
}
|
||||
if (matches.size() > 1) {
|
||||
StringBuilder ambig = new StringBuilder();
|
||||
ambig.append("Ambiguous effect name '").append(effectName).append("'. Multiple matches: ");
|
||||
for (EffectEntry match : matches) {
|
||||
ambig.append(match.effect.getName())
|
||||
.append(" (ID: ").append(match.id)
|
||||
.append(", INDEX: ").append(match.index)
|
||||
.append("), ");
|
||||
}
|
||||
sendError(sender, ambig.substring(0, ambig.length() - 2));
|
||||
return;
|
||||
}
|
||||
EffectEntry match = matches.get(0);
|
||||
|
||||
List<PlayerData> players = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (players.isEmpty()) {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
|
||||
for (PlayerData pdata : players) {
|
||||
if (pdata.player != null) {
|
||||
CustomEffectController.getInstance().removeEffect(pdata.player, match.id, match.index, ExpirationType.REMOVED);
|
||||
sendResult(sender, String.format("Effect %s removed from %s", match.effect.getName(), pdata.playername));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Give effect by ID.
|
||||
// Usage: <player> <time> <effectId> [index]
|
||||
@SubCommand(desc = "Gives an effect to a player by ID", usage = "<player> <time> <effectId> [index]")
|
||||
public void giveId(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 3) {
|
||||
sendError(sender, "Usage: <player> <time> <effectId> [index]");
|
||||
return;
|
||||
}
|
||||
|
||||
String playername = args[0];
|
||||
int time;
|
||||
try {
|
||||
time = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
sendError(sender, "Invalid time: " + args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
int effectId;
|
||||
int index = 0;
|
||||
try {
|
||||
effectId = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
sendError(sender, "Invalid effect ID: " + args[2]);
|
||||
return;
|
||||
}
|
||||
if (args.length > 3) {
|
||||
try {
|
||||
index = Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException e) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
List<PlayerData> players = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (players.isEmpty()) {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
|
||||
CustomEffect effect = CustomEffectController.getInstance().get(effectId, index);
|
||||
if (effect == null) {
|
||||
sendError(sender, "Unknown effect with ID: " + effectId + " and index " + index);
|
||||
return;
|
||||
}
|
||||
|
||||
for (PlayerData pdata : players) {
|
||||
if (pdata.player != null) {
|
||||
CustomEffectController.getInstance().applyEffect(pdata.player, effect.id, time, (byte) 1, effect.index);
|
||||
sendResult(sender, String.format("%s §agiven to §7'§b%s§7'", effect.getName(), pdata.playername));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove effect by ID.
|
||||
// Usage: <player> <effectId> [index]
|
||||
@SubCommand(desc = "Removes an effect from a player by ID", usage = "<player> <effectId> [index]")
|
||||
public void removeId(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 2) {
|
||||
sendError(sender, "Usage: <player> <effectId> [index]");
|
||||
return;
|
||||
}
|
||||
|
||||
String playername = args[0];
|
||||
int effectId;
|
||||
int index = 0;
|
||||
try {
|
||||
effectId = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
sendError(sender, "Invalid effect ID: " + args[1]);
|
||||
return;
|
||||
}
|
||||
if (args.length > 2) {
|
||||
try {
|
||||
index = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
List<PlayerData> players = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (players.isEmpty()) {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
|
||||
CustomEffect effect = CustomEffectController.getInstance().get(effectId, index);
|
||||
if (effect == null) {
|
||||
sendError(sender, "Unknown effect with ID: " + effectId + " and index " + index);
|
||||
return;
|
||||
}
|
||||
|
||||
for (PlayerData pdata : players) {
|
||||
if (pdata.player != null) {
|
||||
CustomEffectController.getInstance().removeEffect(pdata.player, effect.id, effect.index, ExpirationType.REMOVED);
|
||||
sendResult(sender, String.format("Effect %s removed from %s", effect.getName(), pdata.playername));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class EffectEntry {
|
||||
int index;
|
||||
int id;
|
||||
CustomEffect effect;
|
||||
|
||||
public EffectEntry(int index, int id, CustomEffect effect) {
|
||||
this.index = index;
|
||||
this.id = id;
|
||||
this.effect = effect;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to find effects by name.
|
||||
private List<EffectEntry> findEffectsByName(String name) {
|
||||
List<EffectEntry> matches = new ArrayList<>();
|
||||
CustomEffectController controller = CustomEffectController.getInstance();
|
||||
for (Map.Entry<Integer, HashMap<Integer, CustomEffect>> entry : controller.indexMapper.entrySet()) {
|
||||
int idx = entry.getKey();
|
||||
Map<Integer, CustomEffect> effects = entry.getValue();
|
||||
if (effects == null) continue;
|
||||
for (Map.Entry<Integer, CustomEffect> effectEntry : effects.entrySet()) {
|
||||
int id = effectEntry.getKey();
|
||||
CustomEffect effect = effectEntry.getValue();
|
||||
if (effect.getName().equalsIgnoreCase(name)) {
|
||||
List<EffectEntry> exact = new ArrayList<>();
|
||||
exact.add(new EffectEntry(idx, id, effect));
|
||||
return exact;
|
||||
} else if (effect.getName().toLowerCase().contains(name.toLowerCase())) {
|
||||
matches.add(new EffectEntry(idx, id, effect));
|
||||
}
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
public static List<String> getSortedEffectNames() {
|
||||
List<EffectEntry> entries = new ArrayList<>();
|
||||
CustomEffectController controller = CustomEffectController.getInstance();
|
||||
for (Map.Entry<Integer, HashMap<Integer, CustomEffect>> indexEntry : controller.indexMapper.entrySet()) {
|
||||
int index = indexEntry.getKey();
|
||||
Map<Integer, CustomEffect> effects = indexEntry.getValue();
|
||||
if (effects != null) {
|
||||
for (Map.Entry<Integer, CustomEffect> effectEntry : effects.entrySet()) {
|
||||
int id = effectEntry.getKey();
|
||||
CustomEffect effect = effectEntry.getValue();
|
||||
entries.add(new EffectEntry(index, id, effect));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sort entries by index then by effect ID.
|
||||
entries.sort(Comparator.comparingInt((EffectEntry e) -> e.index)
|
||||
.thenComparingInt(e -> e.id));
|
||||
List<String> effectNames = new ArrayList<>();
|
||||
for (EffectEntry entry : entries) {
|
||||
effectNames.add(entry.effect.getName());
|
||||
}
|
||||
return effectNames;
|
||||
}
|
||||
}
|
||||
+51
-50
@@ -1,6 +1,5 @@
|
||||
package kamkeel.command;
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.controllers.FactionController;
|
||||
@@ -12,34 +11,37 @@ import noppes.npcs.controllers.data.PlayerFactionData;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class FactionCommand extends CommandKamkeelBase {
|
||||
|
||||
public Faction selectedFaction;
|
||||
public List<PlayerData> data;
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "faction";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "faction";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Faction operations";
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Faction operations";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<player> <faction> <command>";
|
||||
}
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<player> <faction> <command>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runSubCommands(){
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean runSubCommands() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
String playername = args[0];
|
||||
String factionname = args[1];
|
||||
|
||||
@@ -49,10 +51,9 @@ public class FactionCommand extends CommandKamkeelBase {
|
||||
return;
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
selectedFaction = FactionController.getInstance().getFaction(Integer.parseInt(factionname));
|
||||
}
|
||||
catch(NumberFormatException e){
|
||||
} catch (NumberFormatException e) {
|
||||
selectedFaction = FactionController.getInstance().getFactionFromName(factionname);
|
||||
}
|
||||
|
||||
@@ -63,15 +64,15 @@ public class FactionCommand extends CommandKamkeelBase {
|
||||
|
||||
processSubCommand(sender, args[2], Arrays.copyOfRange(args, 3, args.length));
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Add points",
|
||||
usage = "<points>"
|
||||
desc = "Add points",
|
||||
usage = "<points>"
|
||||
)
|
||||
public void add(ICommandSender sender, String[] args) throws CommandException {
|
||||
int points;
|
||||
@@ -83,17 +84,17 @@ public class FactionCommand extends CommandKamkeelBase {
|
||||
}
|
||||
int factionid = this.selectedFaction.id;
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.increasePoints(factionid, points, playerdata.player);
|
||||
for (PlayerData playerdata : data) {
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.increasePoints(factionid, points, playerdata.player);
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Added Points \u00A7a%d\u00A77, Faction \u00A7e%s (%d)\u00A77 for Player \u00A7b%s\u00A77", points, this.selectedFaction.getName(), this.selectedFaction.id, playerdata.playername));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Substract points",
|
||||
usage = "<points>"
|
||||
desc = "Substract points",
|
||||
usage = "<points>"
|
||||
)
|
||||
public void subtract(ICommandSender sender, String[] args) throws CommandException {
|
||||
int points;
|
||||
@@ -104,9 +105,9 @@ public class FactionCommand extends CommandKamkeelBase {
|
||||
return;
|
||||
}
|
||||
int factionid = this.selectedFaction.id;
|
||||
for(PlayerData playerdata : data){
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.increasePoints(factionid, -points, playerdata.player);
|
||||
for (PlayerData playerdata : data) {
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.increasePoints(factionid, -points, playerdata.player);
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Subtracted Points \u00A7a%d\u00A77, Faction \u00A7e%s (%d)\u00A77 for Player \u00A7b%s\u00A77", points, this.selectedFaction.getName(), this.selectedFaction.id, playerdata.playername));
|
||||
}
|
||||
@@ -114,16 +115,16 @@ public class FactionCommand extends CommandKamkeelBase {
|
||||
|
||||
@SubCommand(desc = "Reset points to default")
|
||||
public void reset(ICommandSender sender, String[] args) {
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.factionData.factionData.put(this.selectedFaction.id, this.selectedFaction.defaultPoints);
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.factionData.factionData.put(this.selectedFaction.id, this.selectedFaction.defaultPoints);
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Reset Faction \u00A7e%s (%d)\u00A77 for Player \u00A7b%s\u00A77", this.selectedFaction.getName(), this.selectedFaction.id, playerdata.playername));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set points",
|
||||
usage = "<points>"
|
||||
desc = "Set points",
|
||||
usage = "<points>"
|
||||
)
|
||||
public void set(ICommandSender sender, String[] args) throws CommandException {
|
||||
int points;
|
||||
@@ -133,28 +134,28 @@ public class FactionCommand extends CommandKamkeelBase {
|
||||
sendError(sender, "Must be an integer: " + args[0]);
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.factionData.put(this.selectedFaction.id, points);
|
||||
for (PlayerData playerdata : data) {
|
||||
PlayerFactionData playerfactiondata = playerdata.factionData;
|
||||
playerfactiondata.factionData.put(this.selectedFaction.id, points);
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Set Points \u00A7a%d\u00A77, Faction \u00A7e%s (%d)\u00A77 for Player \u00A7b%s\u00A77", points, this.selectedFaction.getName(), this.selectedFaction.id, playerdata.playername));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(desc = "Drop relationship")
|
||||
public void drop(ICommandSender sender, String[] args){
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.factionData.factionData.remove(this.selectedFaction.id);
|
||||
public void drop(ICommandSender sender, String[] args) {
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.factionData.factionData.remove(this.selectedFaction.id);
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Dropped Faction \u00A7e%s (%d)\u00A77 from Player \u00A7b%s\u00A77", this.selectedFaction.getName(), this.selectedFaction.id, playerdata.playername));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender par1, String[] args) {
|
||||
if(args.length == 3){
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, new String[]{"add", "subtract", "set", "reset", "drop", "create"});
|
||||
}
|
||||
return null;
|
||||
public List addTabCompletionOptions(ICommandSender par1, String[] args) {
|
||||
if (args.length == 3) {
|
||||
return getListOfStringsMatchingLastWord(args, new String[]{"add", "subtract", "set", "reset", "drop", "create"});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendMessage;
|
||||
|
||||
public class HelpCommand extends CommandKamkeelBase {
|
||||
private CommandKamkeel parent;
|
||||
|
||||
public HelpCommand(CommandKamkeel parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "help [command]";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length == 0) {
|
||||
sendMessage(sender, "\u00A78------ \u00A7cKamkeel Commands \u00A78------");
|
||||
for (Entry<String, CommandKamkeelBase> entry : parent.map.entrySet()) {
|
||||
sendMessage(sender, "\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getCommandUsage(sender));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CommandKamkeelBase command = parent.getCommand(args);
|
||||
if (command == null) {
|
||||
sendError(sender, "Unknown command " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.subcommands.isEmpty()) {
|
||||
sendMessage(sender, (command.getCommandUsage(sender)));
|
||||
return;
|
||||
}
|
||||
|
||||
Method m = null;
|
||||
if (args.length > 1) {
|
||||
m = command.subcommands.get(args[1].toLowerCase());
|
||||
}
|
||||
if (m == null) {
|
||||
sendMessage(sender, "\u00A78------ \u00A7a" + command.getCommandName().toUpperCase() + " SubCommands \u00A78------");
|
||||
sendMessage(sender, "\u00A77Usage: \u00A76" + command.getUsage());
|
||||
for (Entry<String, Method> entry : command.subcommands.entrySet()) {
|
||||
sendMessage(sender, ("\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getAnnotation(SubCommand.class).desc()));
|
||||
}
|
||||
sendMessage(sender, ("\u00A78Permission:\u00A77 " + CommandKamkeel.getCommandPermission(command.getCommandName())));
|
||||
} else {
|
||||
sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase() + "." + args[1].toUpperCase() + " Command \u00A78------");
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
sendMessage(sender, ("\u00A77" + sc.desc()));
|
||||
if (!sc.usage().isEmpty())
|
||||
sendMessage(sender, ("\u00A77Usage: \u00A76" + sc.usage()));
|
||||
sendMessage(sender, ("\u00A78Permission:\u00A77 " + getSubCommandPermission(args[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.PlayerNotFoundException;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.RoleCompanion;
|
||||
import noppes.npcs.roles.RoleFollower;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class NpcCommand extends CommandKamkeelBase {
|
||||
|
||||
public EntityNPCInterface selectedNpc;
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "npc";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NPC operation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<name> <command>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runSubCommands() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
String npcname = args[0].replace("%", " ");
|
||||
String command = args[1];
|
||||
args = Arrays.copyOfRange(args, 2, args.length);
|
||||
if (command.equalsIgnoreCase("create")) {
|
||||
args = ArrayUtils.add(args, 0, npcname);
|
||||
processSubCommand(sender, command, args);
|
||||
return;
|
||||
}
|
||||
|
||||
int x = sender.getPlayerCoordinates().posX;
|
||||
int y = sender.getPlayerCoordinates().posY;
|
||||
int z = sender.getPlayerCoordinates().posZ;
|
||||
List<EntityNPCInterface> list = getEntities(EntityNPCInterface.class, sender.getEntityWorld(), x, y, z, 80);
|
||||
for (EntityNPCInterface npc : list) {
|
||||
String name = npc.display.getName().replace(" ", "_");
|
||||
if (name.equalsIgnoreCase(npcname)) {
|
||||
if (selectedNpc == null || selectedNpc.getDistanceSq(x, y, z) > npc.getDistanceSq(x, y, z))
|
||||
selectedNpc = npc;
|
||||
}
|
||||
}
|
||||
if (selectedNpc == null) {
|
||||
sendError(sender, "Npc " + npcname + " was not found");
|
||||
return;
|
||||
}
|
||||
|
||||
processSubCommand(sender, command, args);
|
||||
selectedNpc = null;
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set Home (respawn place)",
|
||||
usage = "[x] [y] [z]"
|
||||
)
|
||||
public void home(ICommandSender sender, String[] args) {
|
||||
double posX = sender.getPlayerCoordinates().posX;
|
||||
double posY = sender.getPlayerCoordinates().posY;
|
||||
double posZ = sender.getPlayerCoordinates().posZ;
|
||||
|
||||
if (args.length == 3) {
|
||||
posX = CommandBase.func_110666_a(sender, selectedNpc.posX, args[0]);
|
||||
posY = CommandBase.func_110665_a(sender, selectedNpc.posY, args[1].trim(), 0, 0);
|
||||
posZ = CommandBase.func_110666_a(sender, selectedNpc.posZ, args[2]);
|
||||
}
|
||||
|
||||
selectedNpc.ais.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
|
||||
sendResult(sender, String.format("Set NPC \u00A7e%s\u00A77 Home to \u00A7b[%.1f] [%.1f] [%.1f]\u00A77", selectedNpc.display.name, posX, posY, posZ));
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set NPC visibility",
|
||||
usage = "[true/false/semi]"
|
||||
)
|
||||
public void visible(ICommandSender sender, String[] args) {
|
||||
if (args.length < 1)
|
||||
return;
|
||||
boolean bo = args[0].equalsIgnoreCase("true");
|
||||
boolean semi = args[0].equalsIgnoreCase("semi");
|
||||
|
||||
int current = selectedNpc.display.visible;
|
||||
if (semi)
|
||||
selectedNpc.display.visible = 2;
|
||||
else if (bo)
|
||||
selectedNpc.display.visible = 0;
|
||||
else
|
||||
selectedNpc.display.visible = 1;
|
||||
|
||||
String[] list = new String[]{"True", "False", "Semi"};
|
||||
|
||||
if (current != selectedNpc.display.visible)
|
||||
selectedNpc.updateClient = true;
|
||||
|
||||
sendResult(sender, String.format("Set NPC \u00A7e%s\u00A77 Visibility to \u00A7b%s\u00A77", selectedNpc.display.name, list[selectedNpc.display.visible]));
|
||||
}
|
||||
|
||||
@SubCommand(desc = "Delete an NPC")
|
||||
public void delete(ICommandSender sender, String[] args) {
|
||||
selectedNpc.delete();
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Sets the owner of an follower/companion",
|
||||
usage = "[player]"
|
||||
)
|
||||
public void owner(ICommandSender sender, String[] args) {
|
||||
if (args.length < 1) {
|
||||
EntityPlayer player = null;
|
||||
if (selectedNpc.roleInterface instanceof RoleFollower)
|
||||
player = ((RoleFollower) selectedNpc.roleInterface).owner;
|
||||
|
||||
if (selectedNpc.roleInterface instanceof RoleCompanion)
|
||||
player = ((RoleCompanion) selectedNpc.roleInterface).owner;
|
||||
|
||||
if (player == null)
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Owner: \u00A7b%s\u00A77", selectedNpc.display.name, "NULL"));
|
||||
else
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Owner: \u00A7b%s\u00A77", selectedNpc.display.name, player.getDisplayName()));
|
||||
} else {
|
||||
EntityPlayerMP player = null;
|
||||
try {
|
||||
player = CommandBase.getPlayer(sender, args[0]);
|
||||
} catch (PlayerNotFoundException e) {
|
||||
|
||||
}
|
||||
if (selectedNpc.roleInterface instanceof RoleFollower)
|
||||
((RoleFollower) selectedNpc.roleInterface).setOwner(player);
|
||||
|
||||
if (selectedNpc.roleInterface instanceof RoleCompanion)
|
||||
((RoleCompanion) selectedNpc.roleInterface).setOwner(player);
|
||||
|
||||
if (player == null)
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Owner: \u00A7b%s\u00A77", selectedNpc.display.name, "NULL"));
|
||||
else
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Owner: \u00A7b%s\u00A77", selectedNpc.display.name, player.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc = "Set NPC name",
|
||||
usage = "[name]"
|
||||
)
|
||||
public void name(ICommandSender sender, String[] args) {
|
||||
if (args.length < 1)
|
||||
return;
|
||||
|
||||
String name = args[0];
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
name += " " + args[i];
|
||||
}
|
||||
|
||||
sendResult(sender, String.format("NPC \u00A7e%s\u00A77 Name set to \u00A7b%s\u00A77", selectedNpc.display.name, name));
|
||||
|
||||
if (!selectedNpc.display.getName().equals(name)) {
|
||||
selectedNpc.display.setName(name);
|
||||
selectedNpc.updateClient = true;
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Creates an NPC",
|
||||
usage = "[name]"
|
||||
)
|
||||
public void create(ICommandSender sender, String[] args) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) sender;
|
||||
World pw = player.getEntityWorld();
|
||||
EntityCustomNpc npc = new EntityCustomNpc(pw);
|
||||
if (args.length > 0)
|
||||
npc.display.name = args[0];
|
||||
npc.setPositionAndRotation(player.posX, player.posY, player.posZ, player.cameraYaw, player.cameraPitch);
|
||||
npc.ais.startPos = new int[]{MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ)};
|
||||
pw.spawnEntityInWorld(npc);
|
||||
npc.setHealth(npc.getMaxHealth());
|
||||
NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay, npc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender par1, String[] args) {
|
||||
if (args.length == 2) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, new String[]{"create", "home", "visible", "delete", "owner", "name"});
|
||||
}
|
||||
if (args.length == 3 && args[1].equalsIgnoreCase("owner")) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
public <T extends Entity> List<T> getEntities(Class<? extends T> cls, World world, int x, int y, int z, int range) {
|
||||
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1).expand(range, range, range);
|
||||
List<T> list = world.getEntitiesWithinAABB(cls, bb);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+48
-48
@@ -1,4 +1,4 @@
|
||||
package kamkeel.command;
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
@@ -9,24 +9,27 @@ import noppes.npcs.controllers.data.SkinOverlay;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class OverlayCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "overlay";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "overlay";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Overlay operations";
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Overlay operations";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "set an overlay to a player",
|
||||
usage = "<player> <num> <texture>"
|
||||
desc = "set an overlay to a player",
|
||||
usage = "<player> <num> <texture>"
|
||||
)
|
||||
public void set(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void set(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int overlayID;
|
||||
try {
|
||||
overlayID = Integer.parseInt(args[1]);
|
||||
@@ -39,7 +42,7 @@ public class OverlayCommand extends CommandKamkeelBase {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
for (PlayerData playerdata : data) {
|
||||
SkinOverlay skinOverlay = new SkinOverlay(args[2]);
|
||||
playerdata.skinOverlays.add(overlayID, skinOverlay);
|
||||
playerdata.save();
|
||||
@@ -49,11 +52,11 @@ public class OverlayCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "remove an overlay from a player",
|
||||
usage = "<player> <num>"
|
||||
desc = "remove an overlay from a player",
|
||||
usage = "<player> <num>"
|
||||
)
|
||||
public void remove(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void remove(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int overlayID;
|
||||
try {
|
||||
overlayID = Integer.parseInt(args[1]);
|
||||
@@ -66,13 +69,12 @@ public class OverlayCommand extends CommandKamkeelBase {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
if(playerdata.skinOverlays.has(overlayID)){
|
||||
for (PlayerData playerdata : data) {
|
||||
if (playerdata.skinOverlays.has(overlayID)) {
|
||||
playerdata.skinOverlays.remove(overlayID);
|
||||
playerdata.save();
|
||||
sendResult(sender, String.format("Overlay removed to Player '\u00A7b%s\u00A77' on ID \u00A7d%d", playerdata.playername, overlayID));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sendError(sender, String.format("No overlay found for Player '\u00A7b%s\u00A74' on ID \u00A7d%d", playerdata.playername, overlayID));
|
||||
}
|
||||
return;
|
||||
@@ -80,11 +82,11 @@ public class OverlayCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "modify an overlay for a player",
|
||||
usage = "<player> <num> <blend/glow> <true/false>"
|
||||
desc = "modify an overlay for a player",
|
||||
usage = "<player> <num> <blend/glow> <true/false>"
|
||||
)
|
||||
public void modify(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void modify(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int overlayID;
|
||||
try {
|
||||
overlayID = Integer.parseInt(args[1]);
|
||||
@@ -98,35 +100,34 @@ public class OverlayCommand extends CommandKamkeelBase {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!args[2].equalsIgnoreCase("blend") && !args[2].equalsIgnoreCase("glow")){
|
||||
if (!args[2].equalsIgnoreCase("blend") && !args[2].equalsIgnoreCase("glow")) {
|
||||
sendError(sender, "Unknown Entry: " + args[2]);
|
||||
return;
|
||||
}
|
||||
boolean isBlend = args[2].equalsIgnoreCase("blend");
|
||||
|
||||
if(!args[3].equalsIgnoreCase("true") && !args[3].equalsIgnoreCase("false")){
|
||||
if (!args[3].equalsIgnoreCase("true") && !args[3].equalsIgnoreCase("false")) {
|
||||
sendError(sender, "Unknown Bool: " + args[3]);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isTrue = args[3].equalsIgnoreCase("true");
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
if(!playerdata.skinOverlays.has(overlayID)){
|
||||
for (PlayerData playerdata : data) {
|
||||
if (!playerdata.skinOverlays.has(overlayID)) {
|
||||
sendError(sender, String.format("Player '\u00A7b%s\u00A7c' does not have Overlay ID \u00A7d%d", playerdata.playername, overlayID));
|
||||
return;
|
||||
}
|
||||
|
||||
ISkinOverlay skinOverlay = playerdata.skinOverlays.get(overlayID);
|
||||
if(skinOverlay == null){
|
||||
if (skinOverlay == null) {
|
||||
sendError(sender, String.format("Player '\u00A7b%s\u00A7c' does not have Overlay ID \u00A7d%d", playerdata.playername, overlayID));
|
||||
return;
|
||||
}
|
||||
|
||||
if(isBlend){
|
||||
if (isBlend) {
|
||||
skinOverlay.setBlend(isTrue);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
skinOverlay.setGlow(isTrue);
|
||||
}
|
||||
playerdata.skinOverlays.add(overlayID, skinOverlay);
|
||||
@@ -137,17 +138,17 @@ public class OverlayCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "clears all overlays from a player",
|
||||
usage = "<player>"
|
||||
desc = "clears all overlays from a player",
|
||||
usage = "<player>"
|
||||
)
|
||||
public void clear(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void clear(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.skinOverlays.clear();
|
||||
playerdata.save();
|
||||
sendResult(sender, String.format("Overlays cleared from Player '\u00A7b%s\u00A77'", playerdata.playername));
|
||||
@@ -156,25 +157,24 @@ public class OverlayCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "List all overlays on a player",
|
||||
usage = "<player>"
|
||||
desc = "List all overlays on a player",
|
||||
usage = "<player>"
|
||||
)
|
||||
public void info(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername=args[0];
|
||||
String playername = args[0];
|
||||
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, "Unknown player: " + playername);
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
for (PlayerData playerdata : data) {
|
||||
sendResult(sender, "--------------------");
|
||||
if(playerdata.skinOverlays.size() == 0){
|
||||
if (playerdata.skinOverlays.size() == 0) {
|
||||
sendResult(sender, String.format("No Overlays found for Player '\u00A7b%s\u00A77'", playerdata.playername));
|
||||
}
|
||||
else {
|
||||
for(ISkinOverlay overlay : playerdata.skinOverlays.overlayList.values()){
|
||||
if(overlay != null){
|
||||
} else {
|
||||
for (ISkinOverlay overlay : playerdata.skinOverlays.overlayList.values()) {
|
||||
if (overlay != null) {
|
||||
sendResult(sender, String.format("%s", overlay.getTexture()));
|
||||
}
|
||||
}
|
||||
+79
-71
@@ -1,10 +1,13 @@
|
||||
package kamkeel.command;
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumProfileSync;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
@@ -16,24 +19,27 @@ import noppes.npcs.controllers.data.QuestData;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "questcat";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "questcat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Quest Category operations";
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Quest Category operations";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Find quest category id number by its name",
|
||||
usage = "<quest cat name>"
|
||||
desc = "Find quest category id number by its name",
|
||||
usage = "<quest cat name>"
|
||||
)
|
||||
public void id(ICommandSender sender, String args[]) throws CommandException {
|
||||
if(args.length == 0){
|
||||
if (args.length == 0) {
|
||||
sendError(sender, "Please provide a name for the quest category");
|
||||
return;
|
||||
}
|
||||
@@ -41,60 +47,65 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
String catName = String.join(" ", args).toLowerCase();
|
||||
final Collection<QuestCategory> questCats = QuestController.Instance.categories.values();
|
||||
int count = 0;
|
||||
for(QuestCategory cat : questCats){
|
||||
if(cat.getName().toLowerCase().contains(catName)){
|
||||
for (QuestCategory cat : questCats) {
|
||||
if (cat.getName().toLowerCase().contains(catName)) {
|
||||
sendResult(sender, String.format("Quest Cat \u00A7e%d\u00A77 - \u00A7c'%s'", cat.id, cat.getName()));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(count == 0){
|
||||
if (count == 0) {
|
||||
sendResult(sender, String.format("No Quest Cat found with name: \u00A7c'%s'", catName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc = "Finish a quest category for a player",
|
||||
usage = "<player> <questcatid>"
|
||||
desc = "Finish a quest category for a player",
|
||||
usage = "<player> <questcatid>"
|
||||
)
|
||||
public void finish(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void finish(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int questcatid;
|
||||
try {
|
||||
questcatid = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestCatID must be an integer: " + args[1]);
|
||||
questcatid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestCatID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, String.format("Unknown player '%s'", playername));
|
||||
sendError(sender, String.format("Unknown player '%s'", playername));
|
||||
return;
|
||||
}
|
||||
|
||||
QuestCategory questCategory = QuestController.Instance.categories.get(questcatid);
|
||||
if (questCategory == null){
|
||||
sendError(sender, "Unknown QuestCatID: " + questcatid);
|
||||
if (questCategory == null) {
|
||||
sendError(sender, "Unknown QuestCatID: " + questcatid);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for(PlayerData playerdata : data){
|
||||
for(Quest quest : questCategory.quests.values()){
|
||||
if(playerdata.questData.activeQuests.containsKey(quest.id)){
|
||||
playerdata.questData.activeQuests.remove(quest.id);
|
||||
for (PlayerData playerdata : data) {
|
||||
count = 0;
|
||||
for (Quest quest : questCategory.quests.values()) {
|
||||
playerdata.questData.activeQuests.remove(quest.id);
|
||||
long completeTime;
|
||||
if (quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY || quest.repeat == EnumQuestRepeat.RLCUSTOM) {
|
||||
completeTime = System.currentTimeMillis();
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
} else {
|
||||
completeTime = sender.getEntityWorld().getTotalWorldTime();
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
}
|
||||
|
||||
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY)
|
||||
playerdata.questData.finishedQuests.put(quest.id, System.currentTimeMillis());
|
||||
else
|
||||
playerdata.questData.finishedQuests.put(quest.id, sender.getEntityWorld().getTotalWorldTime());
|
||||
if (ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
ProfileController.Instance.shareQuestCompletion(playerdata.player, quest.id, completeTime);
|
||||
;
|
||||
|
||||
if(playerdata.player != null){
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.completed", quest.title);
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.completed", ": ", quest.title);
|
||||
if (playerdata.player != null) {
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.completed", quest.title);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.completed", ": ", quest.title);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
@@ -107,16 +118,15 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Stop a quest category for a players active quests",
|
||||
usage = "<player> <questcatid>"
|
||||
desc = "Stop a quest category for a players active quests",
|
||||
usage = "<player> <questcatid>"
|
||||
)
|
||||
public void stop(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void stop(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int questcatid;
|
||||
try {
|
||||
questcatid = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestCatID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
@@ -128,15 +138,15 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
QuestCategory questCategory = QuestController.Instance.categories.get(questcatid);
|
||||
if (questCategory == null){
|
||||
if (questCategory == null) {
|
||||
sendError(sender, "Unknown QuestCatID: " + questcatid);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for(PlayerData playerdata : data){
|
||||
for(Quest quest : questCategory.quests.values()){
|
||||
if(playerdata.questData.activeQuests.containsKey(quest.id)){
|
||||
for (PlayerData playerdata : data) {
|
||||
for (Quest quest : questCategory.quests.values()) {
|
||||
if (playerdata.questData.activeQuests.containsKey(quest.id)) {
|
||||
playerdata.questData.activeQuests.remove(quest.id);
|
||||
count++;
|
||||
}
|
||||
@@ -150,16 +160,15 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Start a quest category for a player",
|
||||
usage = "<player> <questcatid>"
|
||||
desc = "Start a quest category for a player",
|
||||
usage = "<player> <questcatid>"
|
||||
)
|
||||
public void start(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void start(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int questcatid;
|
||||
try {
|
||||
questcatid = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestCatID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
@@ -171,22 +180,22 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
QuestCategory questCategory = QuestController.Instance.categories.get(questcatid);
|
||||
if (questCategory == null){
|
||||
if (questCategory == null) {
|
||||
sendError(sender, "Unknown QuestCatID: " + questcatid);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for(PlayerData playerdata : data){
|
||||
for(Quest quest : questCategory.quests.values()){
|
||||
if(!playerdata.questData.activeQuests.containsKey(quest.id)){
|
||||
for (PlayerData playerdata : data) {
|
||||
for (Quest quest : questCategory.quests.values()) {
|
||||
if (!playerdata.questData.activeQuests.containsKey(quest.id)) {
|
||||
QuestData questData = new QuestData(quest);
|
||||
playerdata.questData.activeQuests.put(quest.id, questData);
|
||||
count++;
|
||||
|
||||
if(playerdata.player != null && questData.sendAlerts){
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
||||
if (playerdata.player != null && questData.sendAlerts) {
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.newquest", quest.title);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.newquest", ": ", quest.title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,16 +209,15 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
|
||||
|
||||
@SubCommand(
|
||||
desc = "Remove a quest cat from active/finished",
|
||||
usage = "<player> <questcatid>"
|
||||
desc = "Remove a quest cat from active/finished",
|
||||
usage = "<player> <questcatid>"
|
||||
)
|
||||
public void remove(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void remove(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int questcatid;
|
||||
try {
|
||||
questcatid = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestCatID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
@@ -221,14 +229,14 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
QuestCategory questCategory = QuestController.Instance.categories.get(questcatid);
|
||||
if (questCategory == null){
|
||||
if (questCategory == null) {
|
||||
sendError(sender, "Unknown QuestCatID: " + questcatid);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for(PlayerData playerdata : data){
|
||||
for(Quest quest : questCategory.quests.values()){
|
||||
for (PlayerData playerdata : data) {
|
||||
for (Quest quest : questCategory.quests.values()) {
|
||||
playerdata.questData.activeQuests.remove(quest.id);
|
||||
playerdata.questData.finishedQuests.remove(quest.id);
|
||||
count++;
|
||||
+155
-148
@@ -1,19 +1,20 @@
|
||||
package kamkeel.command;
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.data.IQuestObjective;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumProfileSync;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
import noppes.npcs.controllers.data.Party;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
@@ -23,27 +24,30 @@ import noppes.npcs.util.ValueUtil;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class QuestCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "quest";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "quest";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Quest operations";
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Quest operations";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Start a quest",
|
||||
usage = "<player> <quest>"
|
||||
desc = "Start a quest",
|
||||
usage = "<player> <quest>"
|
||||
)
|
||||
public void start(ICommandSender sender, String[] args) throws CommandException {
|
||||
String playername = args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
questid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestID must be an integer: " + args[1]);
|
||||
return;
|
||||
@@ -57,18 +61,18 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
sendError(sender, "Unknown QuestID: " + questid);
|
||||
if (quest == null) {
|
||||
sendError(sender, "Unknown QuestID: " + questid);
|
||||
return;
|
||||
}
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
QuestData questdata = new QuestData(quest);
|
||||
playerdata.questData.activeQuests.put(questid, questdata);
|
||||
for (PlayerData playerdata : data) {
|
||||
QuestData questdata = new QuestData(quest);
|
||||
playerdata.questData.activeQuests.put(questid, questdata);
|
||||
playerdata.save();
|
||||
if(playerdata.player != null && questdata.sendAlerts){
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
||||
if (playerdata.player != null && questdata.sendAlerts) {
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.newquest", quest.title);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.newquest", ": ", quest.title);
|
||||
}
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Started Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
|
||||
@@ -76,91 +80,14 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Finish a quest",
|
||||
usage = "<player> <quest>"
|
||||
desc = "Finish a quest",
|
||||
usage = "<player> <quest>"
|
||||
)
|
||||
public void finish(ICommandSender sender, String args[]) throws CommandException{
|
||||
String playername=args[0];
|
||||
public void finish(ICommandSender sender, String args[]) throws CommandException {
|
||||
String playername = args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, String.format("Unknown player '%s'", playername));
|
||||
return;
|
||||
}
|
||||
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
sendError(sender, "Unknown QuestID: " + questid);
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
if(playerdata.questData.activeQuests.containsKey(questid)){
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
}
|
||||
|
||||
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY)
|
||||
playerdata.questData.finishedQuests.put(quest.id, System.currentTimeMillis());
|
||||
else
|
||||
playerdata.questData.finishedQuests.put(quest.id, sender.getEntityWorld().getTotalWorldTime());
|
||||
|
||||
playerdata.save();
|
||||
if(playerdata.player != null){
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.completed", quest.title);
|
||||
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.completed", ": ", quest.title);
|
||||
}
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Finished Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Stop a started quest",
|
||||
usage = "<player> <quest>"
|
||||
)
|
||||
public void stop(ICommandSender sender, String[] args) throws CommandException {
|
||||
String playername=args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, String.format("Unknown player '%s'", playername));
|
||||
return;
|
||||
}
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
sendError(sender, "Unknown QuestID: " + questid);
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Stopped Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Removes a quest from finished and active quests",
|
||||
usage = "<player> <quest>"
|
||||
)
|
||||
public void remove(ICommandSender sender, String[] args) throws CommandException {
|
||||
String playername=args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
questid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestID must be an integer: " + args[1]);
|
||||
return;
|
||||
@@ -173,14 +100,94 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
sendError(sender, "Unknown QuestID");
|
||||
if (quest == null) {
|
||||
sendError(sender, "Unknown QuestID: " + questid);
|
||||
return;
|
||||
}
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
long completeTime;
|
||||
if (quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY || quest.repeat == EnumQuestRepeat.RLCUSTOM) {
|
||||
completeTime = System.currentTimeMillis();
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
} else {
|
||||
completeTime = sender.getEntityWorld().getTotalWorldTime();
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
}
|
||||
|
||||
if (ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
ProfileController.Instance.shareQuestCompletion(playerdata.player, quest.id, completeTime);
|
||||
|
||||
playerdata.save();
|
||||
if (playerdata.player != null) {
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.completed", quest.title);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.completed", ": ", quest.title);
|
||||
}
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Finished Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Stop a started quest",
|
||||
usage = "<player> <quest>"
|
||||
)
|
||||
public void stop(ICommandSender sender, String[] args) throws CommandException {
|
||||
String playername = args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, String.format("Unknown player '%s'", playername));
|
||||
return;
|
||||
}
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null) {
|
||||
sendError(sender, "Unknown QuestID: " + questid);
|
||||
return;
|
||||
}
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Stopped Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Removes a quest from finished and active quests",
|
||||
usage = "<player> <quest>"
|
||||
)
|
||||
public void remove(ICommandSender sender, String[] args) throws CommandException {
|
||||
String playername = args[0];
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "QuestID must be an integer: " + args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
for(PlayerData playerdata : data){
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
playerdata.questData.finishedQuests.remove(questid);
|
||||
List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
|
||||
if (data.isEmpty()) {
|
||||
sendError(sender, String.format("Unknown player '%s'", playername));
|
||||
return;
|
||||
}
|
||||
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null) {
|
||||
sendError(sender, "Unknown QuestID");
|
||||
return;
|
||||
}
|
||||
|
||||
for (PlayerData playerdata : data) {
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
playerdata.questData.finishedQuests.remove(questid);
|
||||
playerdata.save();
|
||||
playerdata.updateClient = true;
|
||||
sendResult(sender, String.format("Removed Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
|
||||
@@ -188,11 +195,11 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc= "Get/Set objectives for quests progress",
|
||||
desc = "Get/Set objectives for quests progress",
|
||||
usage = "<player> <quest> [objective] [value]"
|
||||
)
|
||||
public void objective(ICommandSender sender, String[] args) throws CommandException {
|
||||
EntityPlayer player = CommandBase.getPlayer(sender, args[0]);
|
||||
EntityPlayer player = getPlayer(sender, args[0]);
|
||||
int questid;
|
||||
try {
|
||||
questid = Integer.parseInt(args[1]);
|
||||
@@ -202,13 +209,13 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
if (quest == null) {
|
||||
sendError(sender, "Unknown QuestID");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
|
||||
if (data == null){
|
||||
if (data == null) {
|
||||
sendError(sender, "No PlayerData found for:" + player);
|
||||
return;
|
||||
}
|
||||
@@ -216,21 +223,21 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
Party party = data.getPlayerParty();
|
||||
boolean partyValid = party != null && party.getQuest() != null && party.getQuest().getId() == quest.id;
|
||||
|
||||
if(!partyValid && !data.questData.activeQuests.containsKey(quest.id)) {
|
||||
if (!partyValid && !data.questData.activeQuests.containsKey(quest.id)) {
|
||||
sendError(sender, "Player does not have quest active");
|
||||
return;
|
||||
}
|
||||
|
||||
IQuestObjective[] objectives;
|
||||
if(partyValid)
|
||||
if (partyValid)
|
||||
objectives = quest.questInterface.getPartyObjectives(party);
|
||||
else
|
||||
objectives = quest.questInterface.getObjectives(player);
|
||||
|
||||
if(args.length <= 2) {
|
||||
if(partyValid)
|
||||
if (args.length <= 2) {
|
||||
if (partyValid)
|
||||
sendResult(sender, "For Party: ");
|
||||
for(IQuestObjective ob : objectives) {
|
||||
for (IQuestObjective ob : objectives) {
|
||||
sendResult(sender, ob.getText());
|
||||
}
|
||||
return;
|
||||
@@ -244,12 +251,12 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
return;
|
||||
}
|
||||
|
||||
if(objective < 0 || objective >= objectives.length) {
|
||||
if (objective < 0 || objective >= objectives.length) {
|
||||
sendError(sender, "Invalid objective number was given");
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length <= 3) {
|
||||
if (args.length <= 3) {
|
||||
sendResult(sender, objectives[objective].getText());
|
||||
return;
|
||||
}
|
||||
@@ -264,11 +271,11 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
return;
|
||||
}
|
||||
|
||||
if(s.startsWith("-") || s.startsWith("+")) {
|
||||
if (s.startsWith("-") || s.startsWith("+")) {
|
||||
value = ValueUtil.CorrectInt(object.getProgress() + value, 0, object.getMaxProgress());
|
||||
}
|
||||
|
||||
if(partyValid)
|
||||
if (partyValid)
|
||||
object.setPlayerProgress(player.getCommandSenderName(), value);
|
||||
else
|
||||
object.setProgress(value);
|
||||
@@ -276,11 +283,11 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Find quest id number by its name",
|
||||
usage = "<questName>"
|
||||
desc = "Find quest id number by its name",
|
||||
usage = "<questName>"
|
||||
)
|
||||
public void id(ICommandSender sender, String args[]) throws CommandException {
|
||||
if(args.length == 0){
|
||||
if (args.length == 0) {
|
||||
sendError(sender, "Please provide a name for the quest");
|
||||
return;
|
||||
}
|
||||
@@ -288,23 +295,23 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
String catName = String.join(" ", args).toLowerCase();
|
||||
final Collection<Quest> quests = QuestController.Instance.quests.values();
|
||||
int count = 0;
|
||||
for(Quest quest : quests){
|
||||
if(quest.getName().toLowerCase().contains(catName)){
|
||||
for (Quest quest : quests) {
|
||||
if (quest.getName().toLowerCase().contains(catName)) {
|
||||
sendResult(sender, String.format("Quest \u00A7e%d\u00A77 - \u00A7c'%s'", quest.id, quest.getName()));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(count == 0){
|
||||
if (count == 0) {
|
||||
sendResult(sender, String.format("No Quest found with name: \u00A7c'%s'", catName));
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Find prerequisite quests for an id",
|
||||
usage = "<questId>"
|
||||
desc = "Find prerequisite quests for an id",
|
||||
usage = "<questId>"
|
||||
)
|
||||
public void prereq(ICommandSender sender, String args[]) throws CommandException {
|
||||
if(args.length == 0){
|
||||
if (args.length == 0) {
|
||||
sendError(sender, "Please provide an id for the quest");
|
||||
return;
|
||||
}
|
||||
@@ -318,7 +325,7 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
if (quest == null) {
|
||||
sendError(sender, "Unknown QuestID");
|
||||
return;
|
||||
}
|
||||
@@ -326,25 +333,25 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
sendResult(sender, "Prerequisites:");
|
||||
sendResult(sender, "--------------------");
|
||||
boolean foundOne = false;
|
||||
for(Quest allQuest : quests){
|
||||
if(allQuest.nextQuestid == questid){
|
||||
for (Quest allQuest : quests) {
|
||||
if (allQuest.nextQuestid == questid) {
|
||||
foundOne = true;
|
||||
sendResult(sender, String.format("Quest %d: \u00A7a'%s'", allQuest.id, allQuest.title));
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundOne){
|
||||
if (!foundOne) {
|
||||
sendResult(sender, String.format("No Prerequisites found for Quest \u00A7c%d", questid));
|
||||
}
|
||||
sendResult(sender, "--------------------");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Quick info on a quest",
|
||||
usage = "<questId>"
|
||||
desc = "Quick info on a quest",
|
||||
usage = "<questId>"
|
||||
)
|
||||
public void info(ICommandSender sender, String args[]) throws CommandException {
|
||||
if(args.length == 0){
|
||||
if (args.length == 0) {
|
||||
sendError(sender, "Please provide an id for the quest");
|
||||
return;
|
||||
}
|
||||
@@ -358,7 +365,7 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
Quest quest = QuestController.Instance.quests.get(questid);
|
||||
if (quest == null){
|
||||
if (quest == null) {
|
||||
sendError(sender, "Unknown QuestID");
|
||||
return;
|
||||
}
|
||||
@@ -369,21 +376,21 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
sendResult(sender, String.format("Type: \u00A76%s", quest.type.toString()));
|
||||
sendResult(sender, String.format("Repeatable: \u00A76%s", quest.repeat.toString()));
|
||||
sendResult(sender, String.format("Complete: \u00A76%s", quest.completion.toString()));
|
||||
if(quest.completion == EnumQuestCompletion.Npc){
|
||||
if (quest.completion == EnumQuestCompletion.Npc) {
|
||||
sendResult(sender, String.format("NPC: \u00A76%s", quest.completerNpc));
|
||||
}
|
||||
if(quest.nextQuestid != -1){
|
||||
if (quest.nextQuestid != -1) {
|
||||
sendResult(sender, String.format("Next Quest ID: \u00A7c%d", quest.nextQuestid));
|
||||
}
|
||||
sendResult(sender, "--------------------");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc="reload quests from disk",
|
||||
permission = 4
|
||||
desc = "reload quests from disk",
|
||||
permission = 4
|
||||
)
|
||||
public void reload(ICommandSender sender, String args[]){
|
||||
new QuestController().load();
|
||||
public void reload(ICommandSender sender, String args[]) {
|
||||
new QuestController().load();
|
||||
SyncController.syncAllQuests();
|
||||
sendResult(sender, "Quests Reloaded");
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
|
||||
public class ScriptCommand extends CommandKamkeelBase {
|
||||
|
||||
@SubCommand(desc = "Reload scripts data and folders.")
|
||||
public Boolean reload(ICommandSender sender, String args[]) {
|
||||
ScriptController.Instance.loadCategories();
|
||||
|
||||
if (ScriptController.Instance.loadPlayerScripts())
|
||||
sendResult(sender, "Reload player scripts successfully");
|
||||
else
|
||||
sendError(sender, "Failed reloading player scripts");
|
||||
|
||||
if (ScriptController.Instance.loadForgeScripts())
|
||||
sendResult(sender, "Reload forge scripts successfully");
|
||||
else
|
||||
sendError(sender, "Failed reloading forge scripts");
|
||||
|
||||
if (ScriptController.Instance.loadStoredData())
|
||||
sendResult(sender, "Reload stored data successfully");
|
||||
else
|
||||
sendError(sender, "Failed reloading stored data");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "script";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Commands for scripts";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.boss.EntityDragon;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.item.EntityXPOrb;
|
||||
import net.minecraft.entity.monster.EntityGhast;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.passive.EntityHorse;
|
||||
import net.minecraft.entity.passive.EntityTameable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class SlayCommand extends CommandKamkeelBase {
|
||||
public Map<String, Class<?>> SlayMap = new LinkedHashMap<String, Class<?>>();
|
||||
|
||||
public SlayCommand() {
|
||||
SlayMap.clear();
|
||||
|
||||
SlayMap.put("all", EntityLivingBase.class);
|
||||
SlayMap.put("mobs", EntityMob.class);
|
||||
SlayMap.put("animals", EntityAnimal.class);
|
||||
SlayMap.put("items", EntityItem.class);
|
||||
SlayMap.put("xporbs", EntityXPOrb.class);
|
||||
SlayMap.put("npcs", EntityNPCInterface.class);
|
||||
|
||||
HashMap<String, Class<?>> list = new HashMap<String, Class<?>>(EntityList.stringToClassMapping);
|
||||
for (String name : list.keySet()) {
|
||||
Class<?> cls = list.get(name);
|
||||
if (EntityNPCInterface.class.isAssignableFrom(cls))
|
||||
continue;
|
||||
if (!EntityLivingBase.class.isAssignableFrom(cls))
|
||||
continue;
|
||||
SlayMap.put(name.toLowerCase(), list.get(name));
|
||||
}
|
||||
|
||||
SlayMap.remove("monster");
|
||||
SlayMap.remove("mob");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "slay";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Kills given entity within range. Tab to see options.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<type>.. [range]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
EntityPlayerMP player = (EntityPlayerMP) sender;
|
||||
ArrayList<Class<?>> toDelete = new ArrayList<Class<?>>();
|
||||
boolean deleteNPCs = false;
|
||||
for (String delete : args) {
|
||||
delete = delete.toLowerCase();
|
||||
Class<?> cls = SlayMap.get(delete);
|
||||
if (cls != null)
|
||||
toDelete.add(cls);
|
||||
if (delete.equals("mobs")) {
|
||||
toDelete.add(EntityGhast.class);
|
||||
toDelete.add(EntityDragon.class);
|
||||
}
|
||||
if (delete.equals("npcs"))
|
||||
deleteNPCs = true;
|
||||
}
|
||||
int count = 0;
|
||||
int range = 120;
|
||||
try {
|
||||
range = Integer.parseInt(args[args.length - 1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
|
||||
}
|
||||
AxisAlignedBB box = player.boundingBox.expand(range, range, range);
|
||||
List<? extends Entity> list = sender.getEntityWorld().getEntitiesWithinAABB(EntityLivingBase.class, box);
|
||||
|
||||
for (Entity entity : list) {
|
||||
if (entity instanceof EntityPlayer)
|
||||
continue;
|
||||
if (entity instanceof EntityTameable && ((EntityTameable) entity).isTamed())
|
||||
continue;
|
||||
if (entity instanceof EntityNPCInterface && !deleteNPCs)
|
||||
continue;
|
||||
if (delete(entity, toDelete))
|
||||
count++;
|
||||
}
|
||||
if (toDelete.contains(EntityXPOrb.class)) {
|
||||
list = sender.getEntityWorld().getEntitiesWithinAABB(EntityXPOrb.class, box);
|
||||
for (Entity entity : list) {
|
||||
entity.isDead = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (toDelete.contains(EntityItem.class)) {
|
||||
list = sender.getEntityWorld().getEntitiesWithinAABB(EntityItem.class, box);
|
||||
for (Entity entity : list) {
|
||||
entity.isDead = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
sendResult(sender, count + " entities deleted");
|
||||
}
|
||||
|
||||
private boolean delete(Entity entity, ArrayList<Class<?>> toDelete) {
|
||||
for (Class<?> delete : toDelete) {
|
||||
if (delete == EntityAnimal.class && (entity instanceof EntityHorse)) {
|
||||
continue;
|
||||
}
|
||||
if (delete.isAssignableFrom(entity.getClass())) {
|
||||
entity.isDead = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
|
||||
return getListOfStringsMatchingLastWord(args, SlayMap.keySet().toArray(new String[SlayMap.size()]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendMessage;
|
||||
|
||||
public class CommandHelpProfile extends CommandProfileBase {
|
||||
private CommandProfile parent;
|
||||
|
||||
public CommandHelpProfile(CommandProfile parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "help [command]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length == 0) {
|
||||
sendMessage(sender, "\u00A78------ \u00A7aProfile Commands \u00A78------");
|
||||
for (Entry<String, CommandProfileBase> entry : parent.map.entrySet()) {
|
||||
sendMessage(sender, "\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77"
|
||||
+ entry.getValue().getCommandUsage(sender));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CommandProfileBase command = parent.getCommand(args);
|
||||
if (command == null) {
|
||||
sendError(sender, "Unknown command " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.subcommands.isEmpty()) {
|
||||
sendMessage(sender, (command.getCommandUsage(sender)));
|
||||
return;
|
||||
}
|
||||
|
||||
Method m = null;
|
||||
if (args.length > 1) {
|
||||
m = command.subcommands.get(args[1].toLowerCase());
|
||||
}
|
||||
if (m == null) {
|
||||
sendMessage(sender, "\u00A78------ \u00A7a" + command.getCommandName().toUpperCase()
|
||||
+ " SubCommands \u00A78------");
|
||||
sendMessage(sender, "\u00A77Usage: \u00A76" + command.getUsage());
|
||||
for (Entry<String, Method> entry : command.subcommands.entrySet()) {
|
||||
SubCommand sc = entry.getValue().getAnnotation(SubCommand.class);
|
||||
// For players, only list subcommands if they have permission; for console, show all.
|
||||
if (!(sender instanceof EntityPlayer) || command.canSendCommand(sender, sc, entry.getKey())) {
|
||||
sendMessage(sender, ("\u00A77> "
|
||||
+ "\u00A7e" + entry.getKey()
|
||||
+ "\u00A78: \u00A77" + sc.desc()));
|
||||
}
|
||||
}
|
||||
// Show permission node only if sender is console or has permission.
|
||||
if (!(sender instanceof EntityPlayer) ||
|
||||
CustomNpcsPermissions.hasPermission((EntityPlayer) sender, CustomNpcsPermissions.PROFILE_ADMIN)) {
|
||||
sendMessage(sender, ("\u00A78Permission:\u00A77 "
|
||||
+ CommandProfile.getCommandPermission(command.getCommandName())));
|
||||
}
|
||||
} else {
|
||||
sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase()
|
||||
+ "." + args[1].toUpperCase() + " Command \u00A78------");
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
sendMessage(sender, ("\u00A77" + sc.desc()));
|
||||
if (!sc.usage().isEmpty()) {
|
||||
sendMessage(sender, ("\u00A77Usage: \u00A76" + sc.usage()));
|
||||
}
|
||||
if (!(sender instanceof EntityPlayer) ||
|
||||
CustomNpcsPermissions.hasPermission((EntityPlayer) sender, CustomNpcsPermissions.PROFILE_ADMIN)) {
|
||||
sendMessage(sender, ("\u00A78Permission:\u00A77 "
|
||||
+ getSubCommandPermission(args[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandProfile extends CommandBase {
|
||||
|
||||
public Map<String, CommandProfileBase> map = new HashMap<String, CommandProfileBase>();
|
||||
public CommandHelpProfile help = new CommandHelpProfile(this);
|
||||
public String[] alias = {"profile"};
|
||||
|
||||
public CommandProfile() {
|
||||
registerCommand(help);
|
||||
registerCommand(new CommandProfileChange());
|
||||
registerCommand(new CommandProfileCreate());
|
||||
registerCommand(new CommandProfileRemove());
|
||||
registerCommand(new CommandProfileAdmin());
|
||||
registerCommand(new CommandProfileRegion());
|
||||
registerCommand(new CommandProfileList());
|
||||
registerCommand(new CommandProfileRename());
|
||||
}
|
||||
|
||||
public void registerCommand(CommandProfileBase command) {
|
||||
String name = command.getCommandName().toLowerCase();
|
||||
if (map.containsKey(name))
|
||||
throw new CustomNPCsException("Already a subcommand with the name: " + name);
|
||||
map.put(name, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "profile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getCommandAliases() {
|
||||
return Arrays.asList(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "Use as /profile subcommand";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length == 0) {
|
||||
help.processCommand(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
CommandProfileBase command = getCommand(args);
|
||||
if (command == null)
|
||||
throw new CommandException("Unknown command " + args[0]);
|
||||
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
if (command.subcommands.isEmpty() || !command.runSubCommands()) {
|
||||
if (!canSendCommand(sender, command))
|
||||
throw new CommandException("You are not allowed to use this command: " + command);
|
||||
command.canRun(sender, command.getUsage(), args);
|
||||
command.processCommand(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
help.processCommand(sender, new String[]{command.getCommandName()});
|
||||
return;
|
||||
}
|
||||
|
||||
command.processSubCommand(sender, args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
|
||||
if (args.length == 1)
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, map.keySet().toArray(new String[map.size()]));
|
||||
CommandProfileBase command = getCommand(args);
|
||||
if (command == null)
|
||||
return null;
|
||||
if (args.length == 2 && command.runSubCommands())
|
||||
return getListOfStringsMatchingLastWord(args, command.subcommands.keySet().toArray(new String[command.subcommands.keySet().size()]));
|
||||
String[] useArgs = command.getUsage().split(" ");
|
||||
if (command.runSubCommands()) {
|
||||
Method m = command.subcommands.get(args[1].toLowerCase());
|
||||
if (m != null) {
|
||||
useArgs = m.getAnnotation(CommandProfileBase.SubCommand.class).usage().split(" ");
|
||||
}
|
||||
}
|
||||
if (args.length <= useArgs.length + 2) {
|
||||
if (args.length - 3 >= 0) {
|
||||
String usage = useArgs[args.length - 3];
|
||||
if (usage.equals("<player>") || usage.equals("[player]") || usage.equals("<targetPlayer>")
|
||||
|| usage.equals("<sourcePlayer>") || usage.equals("<destinationPlayer>")) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
}
|
||||
}
|
||||
}
|
||||
return command.addTabCompletionOptions(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
|
||||
public CommandProfileBase getCommand(String[] args) {
|
||||
if (args.length == 0)
|
||||
return null;
|
||||
return map.get(args[0].toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
public static String getCommandPermission(String command) {
|
||||
return "profile.kamkeel." + command.toLowerCase();
|
||||
}
|
||||
|
||||
public static String getUniversalPermission() {
|
||||
return "profile.kamkeel.*";
|
||||
}
|
||||
|
||||
public static boolean canSendCommand(ICommandSender sender, CommandProfileBase command) {
|
||||
if (sender.canCommandSenderUseCommand(command.getRequiredPermissionLevel(), getUniversalPermission())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.canCommandSenderUseCommand(command.getRequiredPermissionLevel(), getCommandPermission(command.getCommandName()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender instanceof EntityPlayer) {
|
||||
return CustomNpcsPermissions.hasCustomPermission((EntityPlayer) sender, getCommandPermission(command.getCommandName()));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.profile.EnumProfileOperation;
|
||||
import kamkeel.npcs.controllers.data.profile.Profile;
|
||||
import kamkeel.npcs.controllers.data.profile.ProfileOperation;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.*;
|
||||
|
||||
public class CommandProfileAdmin extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Admin profile management: clone, remove, change, list, rename, and rollback profiles.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<subcommand>";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Clone a slot from one player's profile to another player.",
|
||||
usage = "<sourcePlayer> <destinationPlayer> <sourceSlot> <destinationSlot> [temp]"
|
||||
)
|
||||
public void clone(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 4) {
|
||||
sendError(sender, "Usage: /profile admin clone <sourcePlayer> <destinationPlayer> <sourceSlot> <destinationSlot> [temp]");
|
||||
return;
|
||||
}
|
||||
String sourcePlayer = args[0];
|
||||
String destinationPlayer = args[1];
|
||||
int sourceSlot, destinationSlot;
|
||||
try {
|
||||
sourceSlot = Integer.parseInt(args[2]);
|
||||
destinationSlot = Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Slot IDs must be numbers.");
|
||||
return;
|
||||
}
|
||||
boolean temporary = (args.length >= 5 && args[4].equalsIgnoreCase("temp"));
|
||||
ProfileOperation result = ProfileController.Instance.cloneSlot(sourcePlayer, sourceSlot, destinationSlot, temporary);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully cloned slot %d from %s to slot %d for %s.", sourceSlot, sourcePlayer, destinationSlot, destinationPlayer);
|
||||
} else if (result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
// Detail message for admins – note: using result.getMessage() for further details.
|
||||
sendError(sender, "Clone failed for %s: Profile is locked. Details: %s", sourcePlayer, result.getMessage());
|
||||
} else if (result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error cloning slot for %s: %s", sourcePlayer, result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error cloning slot: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Remove a specified slot from a player's profile.",
|
||||
usage = "<targetPlayer> <slotId>"
|
||||
)
|
||||
public void remove(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 2) {
|
||||
sendError(sender, "Usage: /profile admin remove <targetPlayer> <slotId>");
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number.");
|
||||
return;
|
||||
}
|
||||
ProfileOperation result = ProfileController.Instance.removeSlot(targetPlayer, slotId);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully removed slot %d from %s.", slotId, targetPlayer);
|
||||
} else if (result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Remove failed for %s: Profile is locked. Details: %s", targetPlayer, result.getMessage());
|
||||
} else if (result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error removing slot %d from %s: %s", slotId, targetPlayer, result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error during removal: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Change a specified player's active slot.",
|
||||
usage = "<targetPlayer> <newSlotId>"
|
||||
)
|
||||
public void change(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 2) {
|
||||
sendError(sender, "Usage: /profile admin change <targetPlayer> <newSlotId>");
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
int newSlotId;
|
||||
try {
|
||||
newSlotId = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number.");
|
||||
return;
|
||||
}
|
||||
ProfileOperation result = ProfileController.Instance.changeSlot(targetPlayer, newSlotId);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully changed %s's active slot to %d.", targetPlayer, newSlotId);
|
||||
} else if (result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Change failed for %s: Profile is locked. Details: %s", targetPlayer, result.getMessage());
|
||||
} else if (result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error changing active slot for %s: %s", targetPlayer, result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error during change: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Create a new slot for a specified player's profile.",
|
||||
usage = "<targetPlayer>"
|
||||
)
|
||||
public void create(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 1) {
|
||||
sendError(sender, "Usage: /profile admin create <targetPlayer>");
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
Profile profile = ProfileController.Instance.getProfile(targetPlayer);
|
||||
if (profile == null) {
|
||||
sendError(sender, "Profile not found for player: %s", targetPlayer);
|
||||
return;
|
||||
}
|
||||
ProfileOperation result = ProfileController.Instance.createSlotInternal(profile);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "New slot created successfully for %s.", targetPlayer);
|
||||
} else if (result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Create failed for %s: Profile is locked. Details: %s", targetPlayer, result.getMessage());
|
||||
} else if (result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error creating new slot for %s: %s", targetPlayer, result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error during slot creation: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "List all slots (IDs and names) for a specified player's profile.",
|
||||
usage = "<targetPlayer>"
|
||||
)
|
||||
public void list(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 1) {
|
||||
sendError(sender, "Usage: /profile admin list <targetPlayer>");
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
Profile profile = ProfileController.Instance.getProfile(targetPlayer);
|
||||
if (profile == null) {
|
||||
sendError(sender, "Profile not found for player: %s", targetPlayer);
|
||||
return;
|
||||
}
|
||||
sendMessage(sender, "Profile Slots for %s:", targetPlayer);
|
||||
for (Map.Entry<Integer, ISlot> entry : profile.getSlots().entrySet()) {
|
||||
int id = entry.getKey();
|
||||
String name = entry.getValue().getName();
|
||||
String prefix = (id == profile.currentSlotId) ? "* " : "- ";
|
||||
sendMessage(sender, prefix + "Slot " + id + ": " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Rename a specified player's slot.",
|
||||
usage = "<targetPlayer> <slotId> <newName>"
|
||||
)
|
||||
public void rename(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 3) {
|
||||
sendError(sender, "Usage: /profile admin rename <targetPlayer> <slotId> <newName>");
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number.");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
if (i > 2) sb.append(" ");
|
||||
sb.append(args[i]);
|
||||
}
|
||||
String newName = sb.toString().trim();
|
||||
if (newName.length() > 20) {
|
||||
newName = newName.substring(0, 20);
|
||||
}
|
||||
if (!newName.matches("[A-Za-z ]+")) {
|
||||
sendError(sender, "Invalid name. Only alphabetic characters and spaces are allowed.");
|
||||
return;
|
||||
}
|
||||
Profile profile = ProfileController.Instance.getProfile(targetPlayer);
|
||||
if (profile == null) {
|
||||
sendError(sender, "Profile not found for player: %s", targetPlayer);
|
||||
return;
|
||||
}
|
||||
if (profile.isLocked()) {
|
||||
sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer);
|
||||
return;
|
||||
}
|
||||
if (!profile.getSlots().containsKey(slotId)) {
|
||||
sendError(sender, "Slot %d not found in %s's profile.", slotId, targetPlayer);
|
||||
return;
|
||||
}
|
||||
profile.getSlots().get(slotId).setName(newName);
|
||||
if (profile.getPlayer() != null) {
|
||||
ProfileController.Instance.save(profile.player, profile);
|
||||
} else {
|
||||
UUID uuid = ProfileController.Instance.getUUIDFromUsername(targetPlayer);
|
||||
if (uuid != null)
|
||||
ProfileController.Instance.saveOffline(profile, uuid);
|
||||
}
|
||||
sendResult(sender, "Successfully renamed slot %d for %s to '%s'.", slotId, targetPlayer, newName);
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Rollback a player's profile to one of their backups.",
|
||||
usage = "<targetPlayer> <backupFileName>"
|
||||
)
|
||||
public void rollback(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 2) {
|
||||
sendError(sender, "Usage: /profile admin rollback <targetPlayer> <backupFileName>");
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
String backupFileName = args[1] + ".dat";
|
||||
|
||||
Profile profile = ProfileController.Instance.getProfile(targetPlayer);
|
||||
if (profile == null || profile.player == null)
|
||||
return;
|
||||
|
||||
File backupDir = new File(ProfileController.getBackupDir(), profile.getPlayer().getUniqueID().toString());
|
||||
File backupFile = new File(backupDir, backupFileName);
|
||||
if (!backupFile.exists()) {
|
||||
sendError(sender, "Backup file %s not found for player %s.", backupFileName, targetPlayer);
|
||||
return;
|
||||
}
|
||||
boolean success = ProfileController.Instance.rollbackProfile(targetPlayer, backupFile);
|
||||
if (success) {
|
||||
sendResult(sender, "Successfully rolled back %s's profile to backup %s.", targetPlayer, backupFileName);
|
||||
} else {
|
||||
sendError(sender, "Failed to rollback %s's profile.", targetPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class CommandProfileBase extends CommandBase {
|
||||
public Map<String, Method> subcommands = new HashMap<String, Method>();
|
||||
|
||||
public CommandProfileBase() {
|
||||
for (Method m : this.getClass().getDeclaredMethods()) {
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
if (sc != null) {
|
||||
String name = sc.name();
|
||||
if (name.equals(""))
|
||||
name = m.getName();
|
||||
subcommands.put(name.toLowerCase(), m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return getDescription();
|
||||
}
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
/**
|
||||
* @return Should return a string in the format of <arg> <arg2> <arg3> [arg4] where <> is a required parameter and [] optional
|
||||
*/
|
||||
public String getUsage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean runSubCommands() {
|
||||
return !subcommands.isEmpty();
|
||||
}
|
||||
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface SubCommand {
|
||||
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* @return Should return a string in the format of <arg> <arg2> <arg3> [arg4] where <> is a required parameter and [] optional
|
||||
*/
|
||||
String usage() default "";
|
||||
|
||||
String desc();
|
||||
|
||||
int permission() default 2;
|
||||
}
|
||||
|
||||
public void processSubCommand(ICommandSender sender, String command, String[] args) throws CommandException {
|
||||
Method m = subcommands.get(command.toLowerCase());
|
||||
if (m == null)
|
||||
throw new CommandException("Unknown subcommand " + command);
|
||||
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
if (!canSendCommand(sender, sc, command))
|
||||
throw new CommandException("You are not allowed to use this command: " + command);
|
||||
|
||||
canRun(sender, sc.usage(), args);
|
||||
try {
|
||||
m.invoke(this, sender, args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void canRun(ICommandSender sender, String usage, String[] args) throws CommandException {
|
||||
String[] np = usage.split(" ");
|
||||
List<String> required = new ArrayList<String>();
|
||||
for (int i = 0; i < np.length; i++) {
|
||||
String command = np[i];
|
||||
if (command.startsWith("<")) {
|
||||
required.add(command);
|
||||
}
|
||||
if (command.equals("<player>") && args.length > i) {
|
||||
CommandBase.getPlayer(sender, args[i]); //throws PlayerNotFoundException if no player is found
|
||||
}
|
||||
|
||||
}
|
||||
if (args.length < required.size()) {
|
||||
throw new CommandException("Missing parameter: " + required.get(args.length));
|
||||
}
|
||||
}
|
||||
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public String getSubCommandPermission(String subCommand) {
|
||||
return "profile.kamkeel." + getCommandName().toLowerCase() + "." + subCommand.toLowerCase();
|
||||
}
|
||||
|
||||
public String getSubUniversalPermission() {
|
||||
return "profile.kamkeel." + getCommandName().toLowerCase() + "*";
|
||||
}
|
||||
|
||||
public boolean canSendCommand(ICommandSender sender, SubCommand command, String subCommand) {
|
||||
if (sender.canCommandSenderUseCommand(command.permission(), getSubUniversalPermission())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.canCommandSenderUseCommand(command.permission(), getSubCommandPermission(subCommand))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender instanceof EntityPlayer) {
|
||||
return CustomNpcsPermissions.hasCustomPermission((EntityPlayer) sender, getSubCommandPermission(subCommand));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.profile.EnumProfileOperation;
|
||||
import kamkeel.npcs.controllers.data.profile.ProfileOperation;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class CommandProfileChange extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "change";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Change your active profile slot.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<slotId>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runSubCommands() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "This command can only be used by a player.");
|
||||
return;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
sendError(sender, "Usage: " + getUsage());
|
||||
return;
|
||||
}
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number: " + args[0]);
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
ProfileOperation result = ProfileController.Instance.changeSlot(player, slotId);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully changed profile slot to %d.", slotId);
|
||||
} else if (result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Profile is locked. Details: %s", result.getMessage());
|
||||
} else if (result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error changing your profile slot: %s", result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.profile.EnumProfileOperation;
|
||||
import kamkeel.npcs.controllers.data.profile.ProfileOperation;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class CommandProfileCreate extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "create";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Create a new profile slot.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runSubCommands() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "This command can only be used by a player.");
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
if (ProfileController.Instance.getProfile(player) == null) {
|
||||
sendError(sender, "Profile not found.");
|
||||
return;
|
||||
}
|
||||
ProfileOperation result = ProfileController.Instance.createSlotInternal(ProfileController.Instance.getProfile(player));
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "New profile slot created successfully.");
|
||||
} else if (result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Profile is locked. Details: %s", result.getMessage());
|
||||
} else if (result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error creating new profile slot: %s", result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.profile.Profile;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendMessage;
|
||||
|
||||
public class CommandProfileList extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "list";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "List all your current profile slots (IDs and names).";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return ""; // No extra parameters.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "This command can only be used by a player.");
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
if (profile == null) {
|
||||
sendError(sender, "Profile not found.");
|
||||
return;
|
||||
}
|
||||
if (profile.getSlots().isEmpty()) {
|
||||
sendMessage(sender, "No slots found. Using default slot 0.");
|
||||
}
|
||||
sendMessage(sender, "Your Profile Slots:");
|
||||
for (Map.Entry<Integer, ISlot> entry : profile.getSlots().entrySet()) {
|
||||
int id = entry.getKey();
|
||||
String name = entry.getValue().getName();
|
||||
String prefix = (id == profile.currentSlotId) ? "* " : "- ";
|
||||
sendMessage(sender, prefix + "Slot " + id + ": " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.*;
|
||||
|
||||
public class CommandProfileRegion extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "region";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Manage profile region switching and restricted regions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<subcommand>";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Enable region-based profile switching",
|
||||
usage = ""
|
||||
)
|
||||
public void enable(ICommandSender sender, String[] args) throws CommandException {
|
||||
ConfigMain.RegionProfileSwitching = true;
|
||||
ConfigMain.RegionProfileSwitchingProperty.set(true);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "Profile region switching enabled.");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable region-based profile switching",
|
||||
usage = ""
|
||||
)
|
||||
public void disable(ICommandSender sender, String[] args) throws CommandException {
|
||||
ConfigMain.RegionProfileSwitching = false;
|
||||
ConfigMain.RegionProfileSwitchingProperty.set(false);
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "Profile region switching disabled.");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Add a new region. Format: DIM X1 Y1 Z1 X2 Y2 Z2",
|
||||
usage = "<dim> <x1> <y1> <z1> <x2> <y2> <z2>"
|
||||
)
|
||||
public void add(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length != 7) {
|
||||
sendError(sender, "Usage: /profile region add <dim> <x1> <y1> <z1> <x2> <y2> <z2>");
|
||||
return;
|
||||
}
|
||||
List<Integer> regionList = new ArrayList<>();
|
||||
try {
|
||||
for (String arg : args) {
|
||||
regionList.add(Integer.parseInt(arg));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sendError(sender, "Invalid number format in region data.");
|
||||
return;
|
||||
}
|
||||
ConfigMain.RestrictedProfileRegions.add(regionList);
|
||||
// Update config property value
|
||||
List<String> regionStrings = new ArrayList<>();
|
||||
for (List<Integer> region : ConfigMain.RestrictedProfileRegions) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < region.size(); i++) {
|
||||
if (i > 0) sb.append(" ");
|
||||
sb.append(region.get(i));
|
||||
}
|
||||
regionStrings.add(sb.toString());
|
||||
}
|
||||
ConfigMain.RestrictedProfileRegionsProperty.set(regionStrings.toArray(new String[0]));
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "Region added successfully.");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Remove a region by its index (1-based).",
|
||||
usage = "<index>"
|
||||
)
|
||||
public void remove(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 1) {
|
||||
sendError(sender, "Usage: /profile region remove <index>");
|
||||
return;
|
||||
}
|
||||
int index;
|
||||
try {
|
||||
index = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
sendError(sender, "Index must be a number.");
|
||||
return;
|
||||
}
|
||||
index = index - 1; // Convert to 0-based index
|
||||
if (index < 0 || index >= ConfigMain.RestrictedProfileRegions.size()) {
|
||||
sendError(sender, "Invalid index. Must be between 1 and " + ConfigMain.RestrictedProfileRegions.size());
|
||||
return;
|
||||
}
|
||||
ConfigMain.RestrictedProfileRegions.remove(index);
|
||||
// Update config property value
|
||||
List<String> regionStrings = new ArrayList<>();
|
||||
for (List<Integer> region : ConfigMain.RestrictedProfileRegions) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < region.size(); i++) {
|
||||
if (i > 0) sb.append(", ");
|
||||
sb.append(region.get(i));
|
||||
}
|
||||
regionStrings.add(sb.toString());
|
||||
}
|
||||
ConfigMain.RestrictedProfileRegionsProperty.set(regionStrings.toArray(new String[0]));
|
||||
if (ConfigMain.config.hasChanged()) {
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "Region removed successfully.");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "List all restricted profile regions.",
|
||||
usage = ""
|
||||
)
|
||||
public void list(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (ConfigMain.RestrictedProfileRegions.isEmpty()) {
|
||||
sendMessage(sender, "No restricted profile regions configured.");
|
||||
return;
|
||||
}
|
||||
sendMessage(sender, "Restricted Profile Regions:");
|
||||
int i = 1;
|
||||
for (List<Integer> region : ConfigMain.RestrictedProfileRegions) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(i).append(": ");
|
||||
for (int j = 0; j < region.size(); j++) {
|
||||
if (j > 0) sb.append(", ");
|
||||
sb.append(region.get(j));
|
||||
}
|
||||
sendMessage(sender, sb.toString());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.profile.EnumProfileOperation;
|
||||
import kamkeel.npcs.controllers.data.profile.ProfileOperation;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class CommandProfileRemove extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "remove";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Remove a slot from your profile. You cannot remove your active slot.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<slotId>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runSubCommands() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "This command can only be used by a player.");
|
||||
return;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
sendError(sender, "Usage: " + getUsage());
|
||||
return;
|
||||
}
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number: " + args[0]);
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
ProfileOperation result = ProfileController.Instance.removeSlot(player, slotId);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully removed slot %d from your profile.", slotId);
|
||||
} else if (result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Profile is locked. Details: %s", result.getMessage());
|
||||
} else if (result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error removing slot: %s", result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class CommandProfileRename extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "rename";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Rename one of your profile slots. Only letters and spaces are allowed (max 20 characters).";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<slotId> <newName>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "This command can only be used by a player.");
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sendError(sender, "Usage: " + getUsage());
|
||||
return;
|
||||
}
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number.");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (i > 1) sb.append(" ");
|
||||
sb.append(args[i]);
|
||||
}
|
||||
String newName = sb.toString().trim();
|
||||
if (newName.length() > 20) {
|
||||
newName = newName.substring(0, 20);
|
||||
}
|
||||
if (!newName.matches("[A-Za-z ]+")) {
|
||||
sendError(sender, "Invalid name. Only alphabetic characters and spaces are allowed.");
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
if (ProfileController.Instance.getProfile(player) == null) {
|
||||
sendError(sender, "Profile not found.");
|
||||
return;
|
||||
}
|
||||
if (!ProfileController.Instance.getProfile(player).getSlots().containsKey(slotId)) {
|
||||
sendError(sender, "Slot %d not found in your profile.", slotId);
|
||||
return;
|
||||
}
|
||||
ProfileController.Instance.getProfile(player).getSlots().get(slotId).setName(newName);
|
||||
ProfileController.Instance.save(player, ProfileController.Instance.getProfile(player));
|
||||
sendResult(sender, "Successfully renamed slot %d to '%s'.", slotId, newName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package kamkeel.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.CustomAttributes;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeValueType;
|
||||
import kamkeel.npcs.controllers.data.attribute.tracker.PlayerAttributeTracker;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* AttributeController is the central registry for attribute definitions.
|
||||
* It ensures that keys are unique.
|
||||
*/
|
||||
public class AttributeController {
|
||||
|
||||
public AttributeController Instance;
|
||||
public CustomAttributes attributes;
|
||||
|
||||
// Tracking Player Attributes
|
||||
private static final Map<UUID, PlayerAttributeTracker> trackers = new HashMap<>();
|
||||
private static final Map<String, AttributeDefinition> definitions = new HashMap<>();
|
||||
|
||||
public AttributeController() {
|
||||
this.Instance = this;
|
||||
definitions.clear();
|
||||
trackers.clear();
|
||||
attributes = new CustomAttributes();
|
||||
}
|
||||
|
||||
|
||||
public static AttributeDefinition registerAttribute(String key, String displayName, char colorCode, AttributeValueType valueType, AttributeDefinition.AttributeSection section) {
|
||||
if (definitions.containsKey(key)) {
|
||||
throw new IllegalArgumentException("Attribute already registered with key: " + key);
|
||||
}
|
||||
AttributeDefinition def = new AttributeDefinition(key, displayName, colorCode, valueType, section);
|
||||
definitions.put(key, def);
|
||||
return def;
|
||||
}
|
||||
|
||||
public static AttributeDefinition registerAttribute(AttributeDefinition definition) {
|
||||
if (definitions.containsKey(definition.getKey())) {
|
||||
throw new IllegalArgumentException("Attribute already registered with key: " + definition.getKey());
|
||||
} else {
|
||||
definitions.put(definition.getKey(), definition);
|
||||
return definition;
|
||||
}
|
||||
}
|
||||
|
||||
public static AttributeDefinition getAttribute(String key) {
|
||||
return definitions.get(key);
|
||||
}
|
||||
|
||||
public static Collection<AttributeDefinition> getAllAttributes() {
|
||||
return definitions.values();
|
||||
}
|
||||
|
||||
public static PlayerAttributeTracker getTracker(EntityPlayer player) {
|
||||
return trackers.computeIfAbsent(player.getUniqueID(), id -> new PlayerAttributeTracker(id));
|
||||
}
|
||||
|
||||
public static void removeTracker(UUID playerId) {
|
||||
trackers.remove(playerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all trackers (e.g. called every 10 ticks for all online players).
|
||||
*/
|
||||
public static void updateAllTrackers(Iterable<EntityPlayer> players) {
|
||||
for (EntityPlayer player : players) {
|
||||
PlayerAttributeTracker tracker = getTracker(player);
|
||||
tracker.updateIfChanged(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,830 @@
|
||||
package kamkeel.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.data.profile.*;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.*;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.IPlayerData;
|
||||
import noppes.npcs.api.handler.IProfileHandler;
|
||||
import noppes.npcs.api.handler.data.IProfile;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
import noppes.npcs.controllers.data.PlayerQuestData;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.util.CustomNPCsThreader;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import static noppes.npcs.CustomNpcsPermissions.*;
|
||||
|
||||
public class ProfileController implements IProfileHandler {
|
||||
|
||||
// Message constants
|
||||
private static final String MSG_PLAYER_NOT_FOUND = "Player not found.";
|
||||
private static final String MSG_PROFILE_LOCKED_CLONE = "Profile is locked; cannot clone slot.";
|
||||
private static final String MSG_SOURCE_SLOT_NOT_EXIST = "Source slot does not exist.";
|
||||
private static final String MSG_CANNOT_CLONE_CURRENT = "Cannot clone to the current active slot.";
|
||||
private static final String MSG_INVALID_DEST_SLOT = "Invalid destination slot id.";
|
||||
private static final String MSG_CLONE_SUCCESS = "Slot cloned successfully.";
|
||||
private static final String MSG_PROFILE_LOCKED_REMOVE = "Profile is locked; cannot remove slot.";
|
||||
private static final String MSG_CANNOT_REMOVE_ACTIVE = "Cannot remove the currently active slot.";
|
||||
private static final String MSG_SLOT_NOT_EXIST = "Slot does not exist.";
|
||||
private static final String MSG_REMOVE_SUCCESS = "Slot removed successfully.";
|
||||
private static final String MSG_PROFILE_LOCKED_CREATE = "Profile is locked; cannot create slot.";
|
||||
private static final String MSG_MAX_SLOTS_REACHED = "Maximum allowed slots reached.";
|
||||
private static final String MSG_NEW_SLOT_CREATED = "New slot created successfully.";
|
||||
private static final String MSG_PROFILE_LOCKED_CHANGE = "Profile is locked; cannot change slot.";
|
||||
private static final String MSG_SLOT_ALREADY_ACTIVE = "Slot is already active.";
|
||||
private static final String MSG_REGION_NOT_ALLOWED = "Profile switching not allowed from your current location.";
|
||||
private static final String MSG_CHANGE_SUCCESS = "Slot changed successfully.";
|
||||
private static final String MSG_CANCELLED = "Operation cancelled.";
|
||||
|
||||
public static Map<String, IProfileData> profileTypes = new HashMap<>();
|
||||
public static Map<UUID, Profile> activeProfiles = new HashMap<>();
|
||||
public static String profile_directory = "profiles";
|
||||
|
||||
public static ProfileController Instance;
|
||||
|
||||
public ProfileController() {
|
||||
Instance = this;
|
||||
profileTypes = new HashMap<>();
|
||||
activeProfiles = new HashMap<>();
|
||||
}
|
||||
|
||||
public static boolean registerProfileType(IProfileData type) {
|
||||
if (profileTypes.containsKey(type.getTagName()))
|
||||
return false;
|
||||
profileTypes.put(type.getTagName(), type);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static File getProfileDir() {
|
||||
try {
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(), profile_directory);
|
||||
if (!file.exists())
|
||||
file.mkdir();
|
||||
return file;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static File getBackupDir() {
|
||||
File base = getProfileDir();
|
||||
File backup = new File(base, "backup");
|
||||
if (!backup.exists()) {
|
||||
backup.mkdir();
|
||||
}
|
||||
return backup;
|
||||
}
|
||||
|
||||
public synchronized void login(EntityPlayer player) {
|
||||
if (!ConfigMain.ProfilesEnabled)
|
||||
return;
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
Profile profile;
|
||||
if (activeProfiles.containsKey(player.getUniqueID())) {
|
||||
profile = activeProfiles.get(player.getUniqueID());
|
||||
profile.player = player;
|
||||
} else {
|
||||
NBTTagCompound compound = load(player);
|
||||
profile = new Profile(player, compound);
|
||||
if (profile.getSlots().isEmpty()) {
|
||||
Slot defaultSlot = new Slot(0, "Default Slot");
|
||||
defaultSlot.setLastLoaded(System.currentTimeMillis());
|
||||
profile.getSlots().put(0, defaultSlot);
|
||||
profile.currentSlotId = 0;
|
||||
saveSlotData(player);
|
||||
}
|
||||
profile.player = player;
|
||||
activeProfiles.put(player.getUniqueID(), profile);
|
||||
verifySlotQuests(profile.player);
|
||||
save(player, profile);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized NBTTagCompound load(EntityPlayer player) {
|
||||
File saveDir = getProfileDir();
|
||||
String filename = player.getUniqueID().toString() + ".dat";
|
||||
try {
|
||||
File file = new File(saveDir, filename);
|
||||
if (file.exists()) {
|
||||
return NBTJsonUtil.loadNBTData(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading profile file: " + filename, e);
|
||||
}
|
||||
return new NBTTagCompound();
|
||||
}
|
||||
|
||||
public synchronized NBTTagCompound load(UUID uuid) {
|
||||
File saveDir = getProfileDir();
|
||||
String filename = uuid.toString() + ".dat";
|
||||
try {
|
||||
File file = new File(saveDir, filename);
|
||||
if (file.exists()) {
|
||||
return NBTJsonUtil.loadNBTData(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading profile file: " + filename, e);
|
||||
}
|
||||
return new NBTTagCompound();
|
||||
}
|
||||
|
||||
public synchronized void saveOffline(Profile profile, UUID uuid) {
|
||||
profile.setLocked(true);
|
||||
CustomNPCsThreader.customNPCThread.execute(() -> {
|
||||
final NBTTagCompound compound = profile.writeToNBT();
|
||||
final String filename = uuid.toString() + ".dat";
|
||||
try {
|
||||
File saveDir = getProfileDir();
|
||||
File fileNew = new File(saveDir, filename + "_new");
|
||||
File fileOld = new File(saveDir, filename);
|
||||
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew));
|
||||
if (fileOld.exists()) {
|
||||
fileOld.delete();
|
||||
}
|
||||
fileNew.renameTo(fileOld);
|
||||
backupProfile(uuid, compound);
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
} finally {
|
||||
profile.setLocked(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void save(EntityPlayer player, Profile profile) {
|
||||
profile.setLocked(true);
|
||||
CustomNPCsThreader.customNPCThread.execute(() -> {
|
||||
final NBTTagCompound compound = profile.writeToNBT();
|
||||
final String filename = player.getUniqueID() + ".dat";
|
||||
try {
|
||||
File saveDir = getProfileDir();
|
||||
File fileNew = new File(saveDir, filename + "_new");
|
||||
File fileOld = new File(saveDir, filename);
|
||||
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew));
|
||||
if (fileOld.exists()) {
|
||||
fileOld.delete();
|
||||
}
|
||||
fileNew.renameTo(fileOld);
|
||||
if (ConfigMain.AllowProfileBackups) {
|
||||
backupProfile(player.getUniqueID(), compound);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
} finally {
|
||||
profile.setLocked(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void backupProfile(UUID uuid, NBTTagCompound compound) {
|
||||
try {
|
||||
File backupDir = new File(getBackupDir(), uuid.toString());
|
||||
if (!backupDir.exists()) {
|
||||
backupDir.mkdirs();
|
||||
}
|
||||
String dateStr = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
||||
File backupFile = new File(backupDir, dateStr + ".dat");
|
||||
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(backupFile));
|
||||
File[] backups = backupDir.listFiles((dir, name) -> name.endsWith(".dat"));
|
||||
if (backups != null && backups.length > ConfigMain.ProfileBackupAmount) {
|
||||
Arrays.sort(backups, Comparator.comparingLong(File::lastModified));
|
||||
for (int i = 0; i < backups.length - ConfigMain.ProfileBackupAmount; i++) {
|
||||
backups[i].delete();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean rollbackProfile(String username, File backupFile) {
|
||||
UUID uuid = getUUIDFromUsername(username);
|
||||
if (uuid == null)
|
||||
return false;
|
||||
try (FileInputStream fis = new FileInputStream(backupFile)) {
|
||||
NBTTagCompound compound = CompressedStreamTools.readCompressed(fis);
|
||||
File saveDir = getProfileDir();
|
||||
File mainFile = new File(saveDir, uuid.toString() + ".dat");
|
||||
File fileNew = new File(saveDir, uuid.toString() + "_new");
|
||||
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew));
|
||||
if (mainFile.exists()) {
|
||||
mainFile.delete();
|
||||
}
|
||||
fileNew.renameTo(mainFile);
|
||||
EntityPlayer player = NoppesUtilServer.getPlayerByName(username);
|
||||
Profile newProfile;
|
||||
if (player != null) {
|
||||
newProfile = new Profile(player, compound);
|
||||
activeProfiles.put(uuid, newProfile);
|
||||
loadSlotData(player);
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized void logout(EntityPlayer player) {
|
||||
if (player != null) {
|
||||
activeProfiles.remove(player.getUniqueID());
|
||||
}
|
||||
}
|
||||
|
||||
public Profile getProfile(EntityPlayer player) {
|
||||
if (player == null)
|
||||
return null;
|
||||
if (!activeProfiles.containsKey(player.getUniqueID()))
|
||||
login(player);
|
||||
return activeProfiles.get(player.getUniqueID());
|
||||
}
|
||||
|
||||
public Profile getProfile(UUID uuid) {
|
||||
if (activeProfiles.containsKey(uuid))
|
||||
return activeProfiles.get(uuid);
|
||||
NBTTagCompound compound = load(uuid);
|
||||
return new Profile(null, compound);
|
||||
}
|
||||
|
||||
public Profile getProfile(String username) {
|
||||
EntityPlayer player = NoppesUtilServer.getPlayerByName(username);
|
||||
if (player != null) {
|
||||
return getProfile(player);
|
||||
} else {
|
||||
UUID uuid = getUUIDFromUsername(username);
|
||||
if (uuid == null)
|
||||
return null;
|
||||
return getProfile(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getUUIDFromUsername(String username) {
|
||||
try {
|
||||
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + username);
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
con.setConnectTimeout(5000);
|
||||
con.setReadTimeout(5000);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
StringBuilder temp = new StringBuilder();
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
temp.append(line);
|
||||
}
|
||||
in.close();
|
||||
con.disconnect();
|
||||
String response = temp.toString();
|
||||
if (response.contains("\"id\"")) {
|
||||
int idIndex = response.indexOf("\"id\"");
|
||||
int colonIndex = response.indexOf(":", idIndex);
|
||||
int quoteStart = response.indexOf("\"", colonIndex);
|
||||
int quoteEnd = response.indexOf("\"", quoteStart + 1);
|
||||
String idString = response.substring(quoteStart + 1, quoteEnd);
|
||||
idString = idString.replaceFirst(
|
||||
"(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)",
|
||||
"$1-$2-$3-$4-$5"
|
||||
);
|
||||
return UUID.fromString(idString);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LogWriter.error("Error retrieving UUID for " + username, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getNextAvailableTempSlot(Profile profile) {
|
||||
int id = -1;
|
||||
while (profile.getSlots().containsKey(id)) {
|
||||
id--;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
private ProfileOperation cloneSlotInternal(Profile profile, int sourceSlotId, int destinationSlotId, boolean temporary) {
|
||||
if (profile.isLocked()) {
|
||||
return ProfileOperation.locked(MSG_PROFILE_LOCKED_CLONE);
|
||||
}
|
||||
if (profile.player != null) {
|
||||
List<IProfileData> dataList = new ArrayList<>(profileTypes.values());
|
||||
dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority));
|
||||
for (IProfileData pd : dataList) {
|
||||
if (pd.verifySwitch(profile.player).getResult() != EnumProfileOperation.SUCCESS) {
|
||||
return pd.verifySwitch(profile.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!profile.getSlots().containsKey(sourceSlotId)) {
|
||||
return ProfileOperation.error(MSG_SOURCE_SLOT_NOT_EXIST);
|
||||
}
|
||||
if (destinationSlotId == profile.getCurrentSlotId()) {
|
||||
return ProfileOperation.error(MSG_CANNOT_CLONE_CURRENT);
|
||||
}
|
||||
if (temporary) {
|
||||
destinationSlotId = getNextAvailableTempSlot(profile);
|
||||
} else {
|
||||
if (destinationSlotId <= 0) {
|
||||
return ProfileOperation.error(MSG_INVALID_DEST_SLOT);
|
||||
}
|
||||
}
|
||||
ISlot sourceSlot = profile.getSlots().get(sourceSlotId);
|
||||
Map<String, NBTTagCompound> newComponents = new HashMap<>();
|
||||
for (String key : sourceSlot.getComponents().keySet()) {
|
||||
newComponents.put(key, (NBTTagCompound) sourceSlot.getComponentData(key).copy());
|
||||
}
|
||||
Slot clonedSlot = new Slot(destinationSlotId, "Cloned Slot " + destinationSlotId, System.currentTimeMillis(), temporary, newComponents);
|
||||
profile.getSlots().put(destinationSlotId, clonedSlot);
|
||||
return ProfileOperation.success(MSG_CLONE_SUCCESS);
|
||||
}
|
||||
|
||||
private ProfileOperation removeSlotInternal(Profile profile, int slotId) {
|
||||
if (profile.isLocked()) {
|
||||
return ProfileOperation.locked(MSG_PROFILE_LOCKED_REMOVE);
|
||||
}
|
||||
if (slotId == profile.getCurrentSlotId()) {
|
||||
return ProfileOperation.error(MSG_CANNOT_REMOVE_ACTIVE);
|
||||
}
|
||||
if (!profile.getSlots().containsKey(slotId)) {
|
||||
return ProfileOperation.error(MSG_SLOT_NOT_EXIST);
|
||||
}
|
||||
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
if (profile.player != null) {
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(profile.player);
|
||||
if (EventHooks.onProfileRemove(handler, scriptPlayer, profile, slotId, false))
|
||||
return ProfileOperation.error(MSG_CANCELLED);
|
||||
}
|
||||
|
||||
profile.getSlots().remove(slotId);
|
||||
|
||||
if (profile.player != null) {
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(profile.player);
|
||||
EventHooks.onProfileRemove(handler, scriptPlayer, profile, slotId, true);
|
||||
}
|
||||
|
||||
return ProfileOperation.success(MSG_REMOVE_SUCCESS);
|
||||
}
|
||||
|
||||
public ProfileOperation createSlotInternal(Profile profile) {
|
||||
if (profile.isLocked()) {
|
||||
return ProfileOperation.locked(MSG_PROFILE_LOCKED_CREATE);
|
||||
}
|
||||
int newSlotId = 0;
|
||||
while (profile.getSlots().containsKey(newSlotId)) {
|
||||
newSlotId++;
|
||||
}
|
||||
if (!allowSlotPermission(profile.player)) {
|
||||
return ProfileOperation.error(MSG_MAX_SLOTS_REACHED);
|
||||
}
|
||||
if (profile.player != null) {
|
||||
List<IProfileData> dataList = new ArrayList<>(profileTypes.values());
|
||||
dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority));
|
||||
for (IProfileData pd : dataList) {
|
||||
if (pd.verifySwitch(profile.player).getResult() != EnumProfileOperation.SUCCESS) {
|
||||
return pd.verifySwitch(profile.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
if (profile.player != null) {
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(profile.player);
|
||||
if (EventHooks.onProfileCreate(handler, scriptPlayer, profile, newSlotId, false))
|
||||
return ProfileOperation.error(MSG_CANCELLED);
|
||||
}
|
||||
|
||||
Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId);
|
||||
newSlot.setLastLoaded(System.currentTimeMillis());
|
||||
profile.getSlots().put(newSlotId, newSlot);
|
||||
if (profile.player != null) {
|
||||
verifySlotQuests(profile.player);
|
||||
save(profile.player, profile);
|
||||
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(profile.player);
|
||||
EventHooks.onProfileCreate(handler, scriptPlayer, profile, newSlotId, true);
|
||||
}
|
||||
return ProfileOperation.success(MSG_NEW_SLOT_CREATED);
|
||||
}
|
||||
|
||||
private ProfileOperation changeSlotInternal(Profile profile, int newSlotId) {
|
||||
if (profile.isLocked()) {
|
||||
return ProfileOperation.locked(MSG_PROFILE_LOCKED_CHANGE);
|
||||
}
|
||||
if (profile.getCurrentSlotId() == newSlotId) {
|
||||
return ProfileOperation.error(MSG_SLOT_ALREADY_ACTIVE);
|
||||
}
|
||||
if (!profile.getSlots().containsKey(newSlotId)) {
|
||||
return ProfileOperation.error(MSG_SLOT_NOT_EXIST);
|
||||
}
|
||||
if (profile.player != null) {
|
||||
if (ConfigMain.RegionProfileSwitching) {
|
||||
boolean allowed = hasPermission(profile.player, PROFILE_REGION_BYPASS);
|
||||
if (!allowed) {
|
||||
int playerDim = profile.player.dimension;
|
||||
int playerX = (int) profile.player.posX;
|
||||
int playerY = (int) profile.player.posY;
|
||||
int playerZ = (int) profile.player.posZ;
|
||||
for (List<Integer> region : ConfigMain.RestrictedProfileRegions) {
|
||||
if (region.size() == 7) {
|
||||
int dim = region.get(0);
|
||||
int x1 = Math.min(region.get(1), region.get(4));
|
||||
int y1 = Math.min(region.get(2), region.get(5));
|
||||
int z1 = Math.min(region.get(3), region.get(6));
|
||||
int x2 = Math.max(region.get(1), region.get(4));
|
||||
int y2 = Math.max(region.get(2), region.get(5));
|
||||
int z2 = Math.max(region.get(3), region.get(6));
|
||||
if (playerDim == dim &&
|
||||
playerX >= x1 && playerX <= x2 &&
|
||||
playerY >= y1 && playerY <= y2 &&
|
||||
playerZ >= z1 && playerZ <= z2) {
|
||||
allowed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!allowed) {
|
||||
return ProfileOperation.error(MSG_REGION_NOT_ALLOWED);
|
||||
}
|
||||
}
|
||||
|
||||
List<IProfileData> dataList = new ArrayList<>(profileTypes.values());
|
||||
dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority));
|
||||
for (IProfileData pd : dataList) {
|
||||
if (pd.verifySwitch(profile.player).getResult() != EnumProfileOperation.SUCCESS) {
|
||||
return pd.verifySwitch(profile.player);
|
||||
}
|
||||
}
|
||||
|
||||
int prevSlot = profile.getCurrentSlotId();
|
||||
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(profile.player);
|
||||
if (EventHooks.onProfileChange(handler, scriptPlayer, profile, newSlotId, prevSlot, false))
|
||||
return ProfileOperation.error(MSG_CANCELLED);
|
||||
|
||||
|
||||
saveSlotData(profile.player);
|
||||
profile.currentSlotId = newSlotId;
|
||||
loadSlotData(profile.player);
|
||||
|
||||
EventHooks.onProfileChange(handler, scriptPlayer, profile, newSlotId, prevSlot, true);
|
||||
} else {
|
||||
return ProfileOperation.error(MSG_PLAYER_NOT_FOUND);
|
||||
}
|
||||
return ProfileOperation.success(MSG_CHANGE_SUCCESS);
|
||||
}
|
||||
|
||||
public ProfileOperation cloneSlot(EntityPlayer player, int sourceSlotId, int destinationSlotId, boolean temporary) {
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null)
|
||||
return ProfileOperation.error(MSG_PLAYER_NOT_FOUND);
|
||||
ProfileOperation result = cloneSlotInternal(profile, sourceSlotId, destinationSlotId, temporary);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS && player != null) {
|
||||
save(player, profile);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ProfileOperation cloneSlot(UUID uuid, int sourceSlotId, int destinationSlotId, boolean temporary) {
|
||||
Profile profile = getProfile(uuid);
|
||||
if (profile == null)
|
||||
return ProfileOperation.error(MSG_PLAYER_NOT_FOUND);
|
||||
ProfileOperation result = cloneSlotInternal(profile, sourceSlotId, destinationSlotId, temporary);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
if (profile.player != null)
|
||||
save(profile.player, profile);
|
||||
else
|
||||
saveOffline(profile, uuid);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ProfileOperation cloneSlot(String username, int sourceSlotId, int destinationSlotId, boolean temporary) {
|
||||
Profile profile = getProfile(username);
|
||||
if (profile == null)
|
||||
return ProfileOperation.error(MSG_PLAYER_NOT_FOUND);
|
||||
ProfileOperation result = cloneSlotInternal(profile, sourceSlotId, destinationSlotId, temporary);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
if (profile.player != null)
|
||||
save(profile.player, profile);
|
||||
else {
|
||||
UUID uuid = getUUIDFromUsername(username);
|
||||
if (uuid != null)
|
||||
saveOffline(profile, uuid);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ProfileOperation removeSlot(EntityPlayer player, int slotId) {
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null)
|
||||
return ProfileOperation.error(MSG_PLAYER_NOT_FOUND);
|
||||
ProfileOperation result = removeSlotInternal(profile, slotId);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS && player != null) {
|
||||
save(player, profile);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ProfileOperation removeSlot(String username, int slotId) {
|
||||
Profile profile = getProfile(username);
|
||||
if (profile == null)
|
||||
return ProfileOperation.error(MSG_PLAYER_NOT_FOUND);
|
||||
ProfileOperation result = removeSlotInternal(profile, slotId);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
if (profile.player != null)
|
||||
save(profile.player, profile);
|
||||
else {
|
||||
UUID uuid = getUUIDFromUsername(username);
|
||||
if (uuid != null)
|
||||
saveOffline(profile, uuid);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ProfileOperation changeSlot(EntityPlayer player, int newSlotId) {
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null)
|
||||
return ProfileOperation.error(MSG_PLAYER_NOT_FOUND);
|
||||
ProfileOperation result = changeSlotInternal(profile, newSlotId);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS && player != null)
|
||||
save(player, profile);
|
||||
return result;
|
||||
}
|
||||
|
||||
public ProfileOperation changeSlot(String username, int newSlotId) {
|
||||
Profile profile = getProfile(username);
|
||||
if (profile == null)
|
||||
return ProfileOperation.error(MSG_PLAYER_NOT_FOUND);
|
||||
ProfileOperation result = changeSlotInternal(profile, newSlotId);
|
||||
if (result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
if (profile.player != null)
|
||||
save(profile.player, profile);
|
||||
else {
|
||||
UUID uuid = getUUIDFromUsername(username);
|
||||
if (uuid != null)
|
||||
saveOffline(profile, uuid);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void saveSlotData(EntityPlayer player) {
|
||||
if (player == null || !activeProfiles.containsKey(player.getUniqueID()))
|
||||
return;
|
||||
Profile profile = activeProfiles.get(player.getUniqueID());
|
||||
if (profile.isLocked()) {
|
||||
return;
|
||||
}
|
||||
ISlot slot = profile.getSlots().get(profile.getCurrentSlotId());
|
||||
if (slot == null) {
|
||||
slot = new Slot(profile.getCurrentSlotId(), "Slot " + profile.getCurrentSlotId());
|
||||
profile.getSlots().put(profile.getCurrentSlotId(), slot);
|
||||
}
|
||||
for (IProfileData profileData : profileTypes.values()) {
|
||||
NBTTagCompound cloned = (NBTTagCompound) profileData.getCurrentNBT(player).copy();
|
||||
slot.setComponentData(profileData.getTagName(), cloned);
|
||||
}
|
||||
slot.setLastLoaded(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void loadSlotData(EntityPlayer player) {
|
||||
if (player == null || !activeProfiles.containsKey(player.getUniqueID()))
|
||||
return;
|
||||
Profile profile = activeProfiles.get(player.getUniqueID());
|
||||
ISlot slot = profile.getSlots().get(profile.getCurrentSlotId());
|
||||
if (slot == null)
|
||||
return;
|
||||
for (IProfileData profileData : profileTypes.values()) {
|
||||
NBTTagCompound data;
|
||||
if (slot.getComponents().containsKey(profileData.getTagName()))
|
||||
data = slot.getComponentData(profileData.getTagName());
|
||||
else
|
||||
data = new NBTTagCompound();
|
||||
profileData.setNBT(player, data);
|
||||
}
|
||||
for (IProfileData profileData : profileTypes.values()) {
|
||||
profileData.save(player);
|
||||
}
|
||||
|
||||
PlayerData pdata = PlayerData.get(player);
|
||||
pdata.profileSlot = profile.getCurrentSlotId();
|
||||
pdata.save();
|
||||
|
||||
if (ConfigMain.AttributesEnabled)
|
||||
AttributeController.getTracker(player).recalcAttributes(player);
|
||||
}
|
||||
|
||||
public List<ProfileInfoEntry> getProfileInfo(EntityPlayer player, int slotId) {
|
||||
List<ProfileInfoEntry> infoList = new ArrayList<>();
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null)
|
||||
return infoList;
|
||||
|
||||
List<IProfileData> dataList = new ArrayList<>(profileTypes.values());
|
||||
dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority));
|
||||
if (slotId == profile.getCurrentSlotId()) {
|
||||
for (IProfileData pd : dataList) {
|
||||
NBTTagCompound currentNBT = pd.getCurrentNBT(player);
|
||||
List<ProfileInfoEntry> subInfo = pd.getInfo(player, currentNBT);
|
||||
infoList.addAll(subInfo);
|
||||
}
|
||||
} else {
|
||||
if (!profile.getSlots().containsKey(slotId))
|
||||
return infoList;
|
||||
ISlot slot = profile.getSlots().get(slotId);
|
||||
for (IProfileData pd : dataList) {
|
||||
if (slot.getComponents().containsKey(pd.getTagName())) {
|
||||
NBTTagCompound sub = slot.getComponentData(pd.getTagName());
|
||||
List<ProfileInfoEntry> subInfo = pd.getInfo(player, sub);
|
||||
infoList.addAll(subInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return infoList;
|
||||
}
|
||||
|
||||
public boolean allowSlotPermission(EntityPlayer player) {
|
||||
Profile profile = getProfile(player);
|
||||
int currentSlots = profile.getSlots().size();
|
||||
if (CustomNpcsPermissions.hasCustomPermission(player, PROFILE_MAX.name)) {
|
||||
return true;
|
||||
}
|
||||
int highestAllowed = 0;
|
||||
for (int i = 1; i <= 50; i++) {
|
||||
String perm = "customnpcs.profile.max." + i;
|
||||
if (CustomNpcsPermissions.hasCustomPermission(player, perm)) {
|
||||
highestAllowed = i;
|
||||
}
|
||||
}
|
||||
if (highestAllowed == 0) {
|
||||
highestAllowed = 1;
|
||||
}
|
||||
return currentSlots < highestAllowed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProfile getProfile(IPlayer player) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return null;
|
||||
return getProfile((EntityPlayer) player.getMCEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean changeSlot(IPlayer player, int slotID) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return false;
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity();
|
||||
ProfileOperation profileOperation = changeSlot(entityPlayer, slotID);
|
||||
return profileOperation.getResult() == EnumProfileOperation.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlot(IPlayer player, int slotID) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return false;
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity();
|
||||
Profile profile = getProfile(entityPlayer);
|
||||
if (profile == null)
|
||||
return false;
|
||||
return profile.getSlots().containsKey(slotID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeSlot(IPlayer player, int slotID) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return false;
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity();
|
||||
ProfileOperation profileOperation = removeSlot(entityPlayer, slotID);
|
||||
return profileOperation.getResult() == EnumProfileOperation.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayerData getSlotPlayerData(IPlayer player, int slotID) {
|
||||
PlayerData playerData;
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return null;
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity();
|
||||
Profile profile = getProfile(entityPlayer);
|
||||
if (profile == null)
|
||||
return null;
|
||||
return getSlotPlayerData(entityPlayer, slotID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSlotData(IPlayer player) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return;
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity();
|
||||
saveSlotData(entityPlayer);
|
||||
}
|
||||
|
||||
public IPlayerData getSlotPlayerData(EntityPlayer player, int slotID) {
|
||||
PlayerData playerData;
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null)
|
||||
return null;
|
||||
|
||||
if (profile.currentSlotId == slotID) {
|
||||
playerData = PlayerData.get(player);
|
||||
} else {
|
||||
Slot slot = (Slot) profile.getSlots().get(slotID);
|
||||
playerData = getSlotPlayerData(player, slot);
|
||||
}
|
||||
return playerData;
|
||||
}
|
||||
|
||||
public PlayerData getSlotPlayerData(EntityPlayer player, Slot slot) {
|
||||
if (slot == null)
|
||||
return null;
|
||||
|
||||
PlayerData playerData = new PlayerData();
|
||||
playerData.player = player;
|
||||
|
||||
NBTTagCompound compound = slot.getComponentData(new CNPCData().getTagName());
|
||||
if (compound == null)
|
||||
compound = new NBTTagCompound();
|
||||
playerData.setNBT(compound);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
public void verifySlotQuests(EntityPlayer player) {
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Integer, Long> universalFinished = new HashMap<>();
|
||||
for (Integer questId : QuestController.Instance.sharedQuests.keySet()) {
|
||||
long maxTime = 0;
|
||||
for (ISlot slot : profile.getSlots().values()) {
|
||||
IPlayerData data = getSlotPlayerData(player, slot.getId());
|
||||
if (data == null) {
|
||||
continue;
|
||||
}
|
||||
PlayerQuestData questData = (PlayerQuestData) data.getQuestData();
|
||||
Long t = questData.finishedQuests.get(questId);
|
||||
if (t != null && t > maxTime) {
|
||||
maxTime = t;
|
||||
}
|
||||
}
|
||||
if (maxTime > 0) {
|
||||
universalFinished.put(questId, maxTime);
|
||||
}
|
||||
}
|
||||
|
||||
// Push the universal shared completion times into every slot.
|
||||
for (ISlot slot : profile.getSlots().values()) {
|
||||
IPlayerData data = getSlotPlayerData(player, slot.getId());
|
||||
if (data != null) {
|
||||
PlayerData playerData = (PlayerData) data;
|
||||
PlayerQuestData questData = (PlayerQuestData) data.getQuestData();
|
||||
questData.finishedQuests.putAll(universalFinished);
|
||||
slot.setComponentData(new CNPCData().getTagName(), playerData.getNBT());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void shareQuestCompletion(EntityPlayer player, int questId, long completeTime) {
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
for (ISlot slot : profile.getSlots().values()) {
|
||||
IPlayerData playerData = getSlotPlayerData(player, slot.getId());
|
||||
if (playerData != null) {
|
||||
PlayerQuestData questData = (PlayerQuestData) playerData.getQuestData();
|
||||
Long existing = questData.finishedQuests.get(questId);
|
||||
if (existing == null || completeTime > existing) {
|
||||
questData.finishedQuests.put(questId, completeTime);
|
||||
}
|
||||
playerData.save();
|
||||
}
|
||||
}
|
||||
save(player, profile);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,670 @@
|
||||
package kamkeel.npcs.controllers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.packets.data.LoginPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncEffectPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.controllers.*;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class SyncController {
|
||||
|
||||
public static void syncPlayer(EntityPlayerMP player) {
|
||||
|
||||
// Login Packet
|
||||
PacketHandler.Instance.sendToPlayer(new LoginPacket(), player);
|
||||
|
||||
// 1) Factions
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.FACTION,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
factionsNBT()
|
||||
), player);
|
||||
|
||||
// 2) Dialog Categories
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.DIALOG_CATEGORY,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
dialogCategoriesNBT()
|
||||
), player);
|
||||
|
||||
// 3) Quest Categories
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.QUEST_CATEGORY,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
questCategoriesNBT()
|
||||
), player);
|
||||
|
||||
// 4) Workbench Recipes
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.WORKBENCH_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
workbenchNBT()
|
||||
), player);
|
||||
|
||||
// 5) Carpentry Recipes
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.CARPENTRY_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
carpentryNBT()
|
||||
), player);
|
||||
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.ANVIL_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
anvilNBT()
|
||||
), player);
|
||||
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.CUSTOM_EFFECTS,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
customEffectsNBT()
|
||||
), player);
|
||||
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.MAGIC,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
magicsNBT()
|
||||
), player);
|
||||
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.MAGIC_CYCLE,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
magicCyclesNBT()
|
||||
), player);
|
||||
|
||||
DBCAddon.instance.syncPlayer(player);
|
||||
syncPlayerData(player, false);
|
||||
}
|
||||
|
||||
public static NBTTagCompound workbenchNBT() {
|
||||
RecipeController controller = RecipeController.Instance;
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (RecipeCarpentry recipe : controller.globalRecipes.values()) {
|
||||
list.appendTag(recipe.writeNBT());
|
||||
}
|
||||
compound.setTag("recipes", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound carpentryNBT() {
|
||||
RecipeController controller = RecipeController.Instance;
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (RecipeCarpentry recipe : controller.carpentryRecipes.values()) {
|
||||
list.appendTag(recipe.writeNBT());
|
||||
}
|
||||
compound.setTag("recipes", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound anvilNBT() {
|
||||
RecipeController controller = RecipeController.Instance;
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (RecipeAnvil recipe : controller.anvilRecipes.values()) {
|
||||
list.appendTag(recipe.writeNBT());
|
||||
}
|
||||
compound.setTag("recipes", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound factionsNBT() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (Faction faction : FactionController.getInstance().factions.values()) {
|
||||
NBTTagCompound factioNBT = new NBTTagCompound();
|
||||
faction.writeNBT(factioNBT);
|
||||
list.appendTag(factioNBT);
|
||||
}
|
||||
compound.setTag("Factions", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound dialogCategoriesNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList categoryList = new NBTTagList();
|
||||
for (DialogCategory category : DialogController.Instance.categories.values()) {
|
||||
NBTTagCompound questCompound = new NBTTagCompound();
|
||||
NBTTagList dialogList = new NBTTagList();
|
||||
for (int dialogID : category.dialogs.keySet()) {
|
||||
Dialog quest = category.dialogs.get(dialogID);
|
||||
dialogList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
questCompound.setTag("Data", dialogList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
categoryList.appendTag(questCompound);
|
||||
}
|
||||
compound.setTag("DialogCategories", categoryList);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound questCategoriesNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList categoryList = new NBTTagList();
|
||||
for (QuestCategory category : QuestController.Instance.categories.values()) {
|
||||
NBTTagCompound questCompound = new NBTTagCompound();
|
||||
;
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for (int questID : category.quests.keySet()) {
|
||||
Quest quest = category.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
categoryList.appendTag(questCompound);
|
||||
}
|
||||
compound.setTag("QuestCategories", categoryList);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound customEffectsNBT() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (CustomEffect effect : CustomEffectController.getInstance().getCustomEffects().values()) {
|
||||
list.appendTag(effect.writeToNBT(false));
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound magicsNBT() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (Magic magic : MagicController.getInstance().magics.values()) {
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
magic.writeNBT(magicCompound);
|
||||
list.appendTag(magicCompound);
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound magicCyclesNBT() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
NBTTagCompound cycleCompound = new NBTTagCompound();
|
||||
cycle.writeNBT(cycleCompound);
|
||||
list.appendTag(cycleCompound);
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static void syncPlayerData(EntityPlayerMP player, boolean update) {
|
||||
PlayerData data = PlayerData.get(player);
|
||||
if (data != null) {
|
||||
if (update) {
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.PLAYERDATA,
|
||||
EnumSyncAction.UPDATE,
|
||||
-1,
|
||||
data.getSyncNBT())
|
||||
, player);
|
||||
} else {
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.PLAYERDATA,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
data.getSyncNBTFull()), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncRemove(EnumSyncType enumSyncType, int id) {
|
||||
PacketHandler.Instance.sendToAll(new SyncPacket(
|
||||
enumSyncType,
|
||||
EnumSyncAction.REMOVE,
|
||||
id,
|
||||
new NBTTagCompound()
|
||||
));
|
||||
}
|
||||
|
||||
public static void syncAllDialogs() {
|
||||
PacketHandler.Instance.sendToAll(new SyncPacket(
|
||||
EnumSyncType.DIALOG_CATEGORY,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
dialogCategoriesNBT()
|
||||
));
|
||||
}
|
||||
|
||||
public static void syncAllQuests() {
|
||||
PacketHandler.Instance.sendToAll(new SyncPacket(
|
||||
EnumSyncType.QUEST_CATEGORY,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
questCategoriesNBT()
|
||||
));
|
||||
}
|
||||
|
||||
public static void syncAllWorkbenchRecipes() {
|
||||
PacketHandler.Instance.sendToAll(new SyncPacket(
|
||||
EnumSyncType.WORKBENCH_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
workbenchNBT()
|
||||
));
|
||||
}
|
||||
|
||||
public static void syncAllCarpentryRecipes() {
|
||||
PacketHandler.Instance.sendToAll(new SyncPacket(
|
||||
EnumSyncType.CARPENTRY_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
carpentryNBT()
|
||||
));
|
||||
}
|
||||
|
||||
public static void syncAllAnvilRecipes() {
|
||||
PacketHandler.Instance.sendToAll(new SyncPacket(
|
||||
EnumSyncType.ANVIL_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
anvilNBT()
|
||||
));
|
||||
}
|
||||
|
||||
public static void syncAllCustomEffects() {
|
||||
PacketHandler.Instance.sendToAll(new SyncPacket(
|
||||
EnumSyncType.CUSTOM_EFFECTS,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
customEffectsNBT()
|
||||
));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientSync(EnumSyncType enumSyncType, NBTTagCompound fullCompound) {
|
||||
switch (enumSyncType) {
|
||||
case FACTION: {
|
||||
NBTTagList list = fullCompound.getTagList("Factions", 10);
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(list.getCompoundTagAt(i));
|
||||
FactionController.getInstance().factionsSync.put(faction.id, faction);
|
||||
}
|
||||
FactionController.getInstance().factions = FactionController.getInstance().factionsSync;
|
||||
FactionController.getInstance().factionsSync = new HashMap<Integer, Faction>();
|
||||
break;
|
||||
}
|
||||
case DIALOG_CATEGORY: {
|
||||
if (!fullCompound.hasNoTags()) {
|
||||
NBTTagList categories = fullCompound.getTagList("DialogCategories", 10);
|
||||
for (int j = 0; j < fullCompound.getTagList("DialogCategories", 10).tagCount(); j++) {
|
||||
NBTTagCompound categoryCompound = categories.getCompoundTagAt(j);
|
||||
if (categoryCompound.hasNoTags())
|
||||
continue;
|
||||
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
NBTTagList dialogList = categoryCompound.getTagList("Data", 10);
|
||||
if (DialogController.Instance.categoriesSync.containsKey(category.id)) {
|
||||
category = DialogController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for (int i = 0; i < dialogList.tagCount(); i++) {
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.readNBT(dialogList.getCompoundTagAt(i));
|
||||
dialog.category = category;
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
DialogController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<Integer, Dialog> dialogs = new HashMap<Integer, Dialog>();
|
||||
for (DialogCategory category : DialogController.Instance.categoriesSync.values()) {
|
||||
for (Dialog dialog : category.dialogs.values()) {
|
||||
dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
}
|
||||
|
||||
DialogController.Instance.categories = DialogController.Instance.categoriesSync;
|
||||
DialogController.Instance.dialogs = dialogs;
|
||||
DialogController.Instance.categoriesSync = new HashMap<Integer, DialogCategory>();
|
||||
break;
|
||||
}
|
||||
case QUEST_CATEGORY: {
|
||||
if (!fullCompound.hasNoTags()) {
|
||||
NBTTagList categories = fullCompound.getTagList("QuestCategories", 10);
|
||||
for (int j = 0; j < fullCompound.getTagList("QuestCategories", 10).tagCount(); j++) {
|
||||
NBTTagCompound categoryCompound = categories.getCompoundTagAt(j);
|
||||
if (categoryCompound.hasNoTags())
|
||||
continue;
|
||||
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
NBTTagList questList = categoryCompound.getTagList("Data", 10);
|
||||
if (QuestController.Instance.categoriesSync.containsKey(category.id)) {
|
||||
category = QuestController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for (int i = 0; i < questList.tagCount(); i++) {
|
||||
Quest quest = new Quest();
|
||||
quest.readNBT(questList.getCompoundTagAt(i));
|
||||
quest.category = category;
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
QuestController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<Integer, Quest> quests = new HashMap<Integer, Quest>();
|
||||
for (QuestCategory category : QuestController.Instance.categoriesSync.values()) {
|
||||
for (Quest quest : category.quests.values()) {
|
||||
quests.put(quest.id, quest);
|
||||
}
|
||||
}
|
||||
|
||||
QuestController.Instance.categories = QuestController.Instance.categoriesSync;
|
||||
QuestController.Instance.quests = quests;
|
||||
QuestController.Instance.categoriesSync = new HashMap<Integer, QuestCategory>();
|
||||
break;
|
||||
}
|
||||
case PLAYERDATA: {
|
||||
ClientCacheHandler.playerData.setSyncNBTFull(fullCompound);
|
||||
break;
|
||||
}
|
||||
case MAGIC: {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
MagicController mc = MagicController.getInstance();
|
||||
mc.magicSync.clear();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Magic magic = new Magic();
|
||||
magic.readNBT(list.getCompoundTagAt(i));
|
||||
mc.magicSync.put(magic.id, magic);
|
||||
}
|
||||
|
||||
mc.magics.clear();
|
||||
mc.magics.putAll(mc.magicSync);
|
||||
mc.magicSync.clear();
|
||||
break;
|
||||
}
|
||||
case MAGIC_CYCLE: {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
MagicController mc = MagicController.getInstance();
|
||||
mc.cyclesSync.clear();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
cycle.readNBT(list.getCompoundTagAt(i));
|
||||
mc.cyclesSync.put(cycle.id, cycle);
|
||||
}
|
||||
|
||||
mc.cycles.clear();
|
||||
mc.cycles.putAll(mc.cyclesSync);
|
||||
mc.cyclesSync.clear();
|
||||
break;
|
||||
}
|
||||
case WORKBENCH_RECIPES: {
|
||||
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
|
||||
RecipeController.syncRecipes.put(recipe.id, recipe);
|
||||
}
|
||||
|
||||
RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes);
|
||||
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
break;
|
||||
}
|
||||
case CARPENTRY_RECIPES: {
|
||||
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
|
||||
RecipeController.syncRecipes.put(recipe.id, recipe);
|
||||
}
|
||||
|
||||
RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes;
|
||||
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
break;
|
||||
}
|
||||
case ANVIL_RECIPES: {
|
||||
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
RecipeAnvil recipe = RecipeAnvil.read(list.getCompoundTagAt(i));
|
||||
RecipeController.syncAnvilRecipes.put(recipe.id, recipe);
|
||||
}
|
||||
|
||||
RecipeController.Instance.anvilRecipes = RecipeController.syncAnvilRecipes;
|
||||
RecipeController.syncAnvilRecipes = new HashMap<Integer, RecipeAnvil>();
|
||||
break;
|
||||
}
|
||||
case CUSTOM_EFFECTS: {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
CustomEffectController ce = CustomEffectController.getInstance();
|
||||
ce.customEffectsSync.clear();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
CustomEffect effect = new CustomEffect();
|
||||
effect.readFromNBT(list.getCompoundTagAt(i));
|
||||
ClientCacheHandler.getImageData(effect.icon);
|
||||
ce.customEffectsSync.put(effect.id, effect);
|
||||
}
|
||||
|
||||
ce.getCustomEffects().clear();
|
||||
ce.getCustomEffects().putAll(ce.customEffectsSync);
|
||||
ce.customEffectsSync.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Related Tasks
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientUpdate(EnumSyncType enumSyncType, int category_id, NBTTagCompound compound) {
|
||||
switch (enumSyncType) {
|
||||
case FACTION: {
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(compound);
|
||||
FactionController.getInstance().factions.put(faction.id, faction);
|
||||
break;
|
||||
}
|
||||
case DIALOG: {
|
||||
DialogCategory category = DialogController.Instance.categories.get(category_id);
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.category = category;
|
||||
dialog.readNBT(compound);
|
||||
DialogController.Instance.dialogs.put(dialog.id, dialog);
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
break;
|
||||
}
|
||||
case QUEST: {
|
||||
QuestCategory category = QuestController.Instance.categories.get(category_id);
|
||||
Quest quest = new Quest();
|
||||
quest.category = category;
|
||||
quest.readNBT(compound);
|
||||
QuestController.Instance.quests.put(quest.id, quest);
|
||||
category.quests.put(quest.id, quest);
|
||||
break;
|
||||
}
|
||||
case QUEST_CATEGORY: {
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if (QuestController.Instance.categoriesSync.containsKey(category.id)) {
|
||||
category = QuestController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Quest quest = new Quest();
|
||||
quest.readNBT(list.getCompoundTagAt(i));
|
||||
quest.category = category;
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
QuestController.Instance.categories.put(category.id, category);
|
||||
break;
|
||||
}
|
||||
case DIALOG_CATEGORY: {
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if (DialogController.Instance.categoriesSync.containsKey(category.id)) {
|
||||
category = DialogController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.readNBT(list.getCompoundTagAt(i));
|
||||
dialog.category = category;
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
DialogController.Instance.categories.put(category.id, category);
|
||||
break;
|
||||
}
|
||||
case MAGIC_CYCLE: {
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
cycle.readNBT(compound);
|
||||
MagicController.getInstance().cycles.put(cycle.id, cycle);
|
||||
break;
|
||||
}
|
||||
case MAGIC: {
|
||||
Magic magic = new Magic();
|
||||
magic.readNBT(compound);
|
||||
MagicController.getInstance().magics.put(magic.id, magic);
|
||||
break;
|
||||
}
|
||||
case PLAYERDATA: {
|
||||
ClientCacheHandler.playerData.setSyncNBT(compound);
|
||||
break;
|
||||
}
|
||||
case CUSTOM_EFFECTS: {
|
||||
CustomEffect effect = new CustomEffect();
|
||||
effect.readFromNBT(compound);
|
||||
ClientCacheHandler.getImageData(effect.icon);
|
||||
|
||||
CustomEffectController.Instance.getCustomEffects().put(effect.id, effect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncUpdate(EnumSyncType type, int cat, NBTTagCompound compound) {
|
||||
PacketHandler.Instance.sendToAll(new SyncPacket(
|
||||
type,
|
||||
EnumSyncAction.UPDATE,
|
||||
cat,
|
||||
compound
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public static NBTTagCompound updateQuestCat(QuestCategory questCategory) {
|
||||
NBTTagCompound questCompound = new NBTTagCompound();
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for (int questID : questCategory.quests.keySet()) {
|
||||
Quest quest = questCategory.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
return questCompound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound updateDialogCat(DialogCategory dialogCategory) {
|
||||
NBTTagCompound dialogCompound = new NBTTagCompound();
|
||||
NBTTagList dialogList = new NBTTagList();
|
||||
for (int questID : dialogCategory.dialogs.keySet()) {
|
||||
Dialog dialog = dialogCategory.dialogs.get(questID);
|
||||
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
return dialogCompound;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientSyncRemove(EnumSyncType enumSyncType, int id) {
|
||||
switch (enumSyncType) {
|
||||
case FACTION:
|
||||
FactionController.getInstance().factions.remove(id);
|
||||
break;
|
||||
case DIALOG:
|
||||
Dialog dialog = DialogController.Instance.dialogs.remove(id);
|
||||
if (dialog != null) {
|
||||
dialog.category.dialogs.remove(id);
|
||||
}
|
||||
break;
|
||||
case DIALOG_CATEGORY:
|
||||
DialogCategory dialogCategory = DialogController.Instance.categories.remove(id);
|
||||
if (dialogCategory != null) {
|
||||
DialogController.Instance.dialogs.keySet().removeAll(dialogCategory.dialogs.keySet());
|
||||
}
|
||||
break;
|
||||
case QUEST:
|
||||
Quest quest = QuestController.Instance.quests.remove(id);
|
||||
if (quest != null) {
|
||||
quest.category.quests.remove(id);
|
||||
}
|
||||
break;
|
||||
case QUEST_CATEGORY:
|
||||
QuestCategory questCategory = QuestController.Instance.categories.remove(id);
|
||||
if (questCategory != null) {
|
||||
QuestController.Instance.quests.keySet().removeAll(questCategory.quests.keySet());
|
||||
}
|
||||
break;
|
||||
case MAGIC:
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
cycle.associations.remove(id);
|
||||
}
|
||||
MagicController.getInstance().cycles.remove(id);
|
||||
break;
|
||||
case MAGIC_CYCLE:
|
||||
MagicController.getInstance().cycles.remove(id);
|
||||
break;
|
||||
case CUSTOM_EFFECTS:
|
||||
CustomEffectController.Instance.getCustomEffects().remove(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncEffects(EntityPlayerMP playerMP) {
|
||||
ConcurrentHashMap<EffectKey, PlayerEffect> playerEffects = CustomEffectController.getInstance().getPlayerEffects(playerMP);
|
||||
PlayerData playerData = PlayerData.get(playerMP);
|
||||
playerData.effectData.setEffects(playerEffects);
|
||||
|
||||
NBTTagCompound compound = playerData.getPlayerEffects();
|
||||
PacketHandler.Instance.sendToPlayer(new SyncEffectPacket(compound), playerMP);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientSyncEffects(NBTTagCompound compound) {
|
||||
PlayerData playerData = PlayerData.get(Minecraft.getMinecraft().thePlayer);
|
||||
if (playerData != null) {
|
||||
playerData.setPlayerEffects(compound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package kamkeel.npcs.controllers.data.attribute;
|
||||
|
||||
public class AttributeDefinition {
|
||||
private final String key;
|
||||
private String translationKey;// e.g., "main_attack_flat"
|
||||
private final String displayName; // Human‑readable name
|
||||
private final char colorCode;
|
||||
private final AttributeValueType attributeValueType;
|
||||
private final AttributeSection section;
|
||||
|
||||
public AttributeDefinition(String key, String displayName, char colorCode, AttributeValueType attributeValueType, AttributeSection section) {
|
||||
this.key = key;
|
||||
this.translationKey = "rpgcore:attribute." + key;
|
||||
this.displayName = displayName;
|
||||
this.attributeValueType = attributeValueType;
|
||||
this.section = section;
|
||||
this.colorCode = colorCode;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public String getTranslationKey() {
|
||||
return translationKey;
|
||||
}
|
||||
|
||||
public void setTranslationKey(String translationKey) {
|
||||
this.translationKey = translationKey;
|
||||
}
|
||||
|
||||
public AttributeValueType getValueType() {
|
||||
return attributeValueType;
|
||||
}
|
||||
|
||||
public AttributeSection getSection() {
|
||||
return section;
|
||||
}
|
||||
|
||||
public char getColorCode() {
|
||||
return colorCode;
|
||||
}
|
||||
|
||||
public enum AttributeSection {
|
||||
BASE,
|
||||
MODIFIER,
|
||||
STATS,
|
||||
INFO,
|
||||
EXTRA;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package kamkeel.npcs.controllers.data.attribute;
|
||||
|
||||
public enum AttributeValueType {
|
||||
FLAT, // e.g., +10 Health or +3 Damage
|
||||
PERCENT, // e.g., +0.25 means +25% bonus
|
||||
MAGIC // Represents a container of magic–based values (summed up as a float)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package kamkeel.npcs.controllers.data.attribute;
|
||||
|
||||
/**
|
||||
* IAttributeInstance represents an instance of an attribute (with a base value and applied modifiers).
|
||||
*/
|
||||
public interface ICustomAttribute {
|
||||
AttributeDefinition getAttribute();
|
||||
|
||||
float getValue();
|
||||
|
||||
void setValue(float value);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package kamkeel.npcs.controllers.data.attribute;
|
||||
|
||||
|
||||
public class PlayerAttribute implements ICustomAttribute {
|
||||
private final AttributeDefinition attribute;
|
||||
private float baseValue;
|
||||
|
||||
public PlayerAttribute(AttributeDefinition attribute, float baseValue) {
|
||||
this.attribute = attribute;
|
||||
this.baseValue = baseValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeDefinition getAttribute() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getValue() {
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(float value) {
|
||||
this.baseValue = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package kamkeel.npcs.controllers.data.attribute;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* CustomAttributeMap holds a set of attribute instances for an entity (or item).
|
||||
*/
|
||||
public class PlayerAttributeMap {
|
||||
private final Map<AttributeDefinition, ICustomAttribute> map = new HashMap<>();
|
||||
|
||||
public ICustomAttribute registerAttribute(AttributeDefinition attribute, float baseValue) {
|
||||
if (map.containsKey(attribute)) {
|
||||
throw new IllegalArgumentException("Attribute already registered: " + attribute.getKey());
|
||||
}
|
||||
ICustomAttribute instance = new PlayerAttribute(attribute, baseValue);
|
||||
map.put(attribute, instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ICustomAttribute getAttributeInstance(AttributeDefinition attribute) {
|
||||
return map.get(attribute);
|
||||
}
|
||||
|
||||
public Collection<ICustomAttribute> getAllAttributes() {
|
||||
return map.values();
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.requirement;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface IRequirementChecker {
|
||||
|
||||
public String getKey();
|
||||
|
||||
public String getTranslation();
|
||||
|
||||
String getTooltipValue(NBTTagCompound nbt);
|
||||
|
||||
void apply(NBTTagCompound nbt, Object value);
|
||||
|
||||
/**
|
||||
* Checks the requirement in the provided NBT.
|
||||
* Return false if the requirement isn’t met.
|
||||
*/
|
||||
boolean check(EntityPlayer player, NBTTagCompound nbt);
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.requirement;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class RequirementCheckerRegistry {
|
||||
private static final Map<String, IRequirementChecker> checkers = new HashMap<>();
|
||||
|
||||
public static void registerChecker(IRequirementChecker checker) {
|
||||
if (!checkers.containsKey(checker.getKey())) {
|
||||
checkers.put(checker.getKey(), checker);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loops over all registered requirement keys.
|
||||
* For each key present in the NBT, its checker must return true.
|
||||
*/
|
||||
public static boolean checkRequirements(EntityPlayer player, NBTTagCompound nbt) {
|
||||
for (Map.Entry<String, IRequirementChecker> entry : checkers.entrySet()) {
|
||||
String reqKey = entry.getKey();
|
||||
if (nbt.hasKey(reqKey)) {
|
||||
if (!entry.getValue().check(player, nbt)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Set<String> getAllKeys() {
|
||||
return checkers.keySet();
|
||||
}
|
||||
|
||||
public static IRequirementChecker getChecker(String key) {
|
||||
return checkers.get(key);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.requirement.types;
|
||||
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.IRequirementChecker;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
public class QuestActiveRequirement implements IRequirementChecker {
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "cnpc_quest_active";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslation() {
|
||||
return "quest.active";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltipValue(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
int questID = nbt.getInteger(getKey());
|
||||
if (QuestController.Instance.get(questID) != null) {
|
||||
return QuestController.Instance.get(questID).getName();
|
||||
}
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(NBTTagCompound nbt, Object value) {
|
||||
if (value instanceof Integer) {
|
||||
nbt.setInteger(getKey(), (Integer) value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(EntityPlayer player, NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
int questID = nbt.getInteger(getKey());
|
||||
return PlayerData.get(player).questData.hasActiveQuest(questID);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.requirement.types;
|
||||
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.IRequirementChecker;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
public class QuestCompletedRequirement implements IRequirementChecker {
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "cnpc_quest_completed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslation() {
|
||||
return "quest.quest";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltipValue(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
int questID = nbt.getInteger(getKey());
|
||||
if (QuestController.Instance.get(questID) != null) {
|
||||
return QuestController.Instance.get(questID).getName();
|
||||
}
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(NBTTagCompound nbt, Object value) {
|
||||
if (value instanceof Integer) {
|
||||
nbt.setInteger(getKey(), (Integer) value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(EntityPlayer player, NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
int questID = nbt.getInteger(getKey());
|
||||
return PlayerData.get(player).questData.hasFinishedQuest(questID);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.tracker;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AttributeRecalcEvent {
|
||||
private static final List<IAttributeRecalcListener> listeners = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Allows other mods to register a listener that is called after attribute recalculation.
|
||||
*/
|
||||
public static void registerListener(IAttributeRecalcListener listener) {
|
||||
if (listener != null && !listeners.contains(listener)) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts an event to all registered listeners.
|
||||
*/
|
||||
public static void post(EntityPlayer player, PlayerAttributeTracker tracker) {
|
||||
for (IAttributeRecalcListener listener : listeners) {
|
||||
listener.onAttributesRecalculated(player, tracker);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.tracker;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
* Implement this interface to receive a callback after a player's attributes have been recalculated.
|
||||
*/
|
||||
public interface IAttributeRecalcListener {
|
||||
void onAttributesRecalculated(EntityPlayer player, PlayerAttributeTracker tracker);
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.tracker;
|
||||
|
||||
import kamkeel.npcs.CustomAttributes;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
|
||||
import kamkeel.npcs.controllers.data.attribute.ICustomAttribute;
|
||||
import kamkeel.npcs.controllers.data.attribute.PlayerAttributeMap;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.RequirementCheckerRegistry;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
import kamkeel.npcs.util.AttributeItemUtil;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerAttributeTracker {
|
||||
|
||||
public static UUID healthUUID = UUID.fromString("48a0ad75-2cf8-4838-ad2f-9a0aadc57dfe");
|
||||
|
||||
|
||||
private final UUID playerId;
|
||||
private PlayerAttributeMap playerAttributes = new PlayerAttributeMap();
|
||||
|
||||
public float extraHealth = 0;
|
||||
public float gearOutput = 0.0f;
|
||||
|
||||
public final Map<Integer, Float> magicDamage = new HashMap<>();
|
||||
public final Map<Integer, Float> magicBoost = new HashMap<>();
|
||||
public final Map<Integer, Float> magicDefense = new HashMap<>();
|
||||
public final Map<Integer, Float> magicResistance = new HashMap<>();
|
||||
|
||||
private PlayerEquipmentTracker equipmentTracker = new PlayerEquipmentTracker();
|
||||
|
||||
public PlayerAttributeTracker(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
// Initial recalc with base damage 0.
|
||||
recalcAttributes(null);
|
||||
}
|
||||
|
||||
public PlayerAttributeMap getPlayerAttributes() {
|
||||
return playerAttributes;
|
||||
}
|
||||
|
||||
public void recalcAttributes(EntityPlayer player) {
|
||||
// Reset aggregated attributes and magic maps.
|
||||
playerAttributes = new PlayerAttributeMap();
|
||||
magicDamage.clear();
|
||||
magicBoost.clear();
|
||||
magicDefense.clear();
|
||||
magicResistance.clear();
|
||||
if (player != null) {
|
||||
// Update equipment tracker.
|
||||
PlayerEquipmentTracker currentEquip = new PlayerEquipmentTracker();
|
||||
currentEquip.updateFrom(player);
|
||||
ItemStack[] equipment = new ItemStack[]{currentEquip.heldItem, currentEquip.boots, currentEquip.leggings, currentEquip.chestplate, currentEquip.helmet};
|
||||
for (ItemStack piece : equipment) {
|
||||
if (piece != null) {
|
||||
if (piece.stackTagCompound != null && piece.stackTagCompound.hasKey(AttributeItemUtil.TAG_RPGCORE)) {
|
||||
NBTTagCompound rpgCore = piece.stackTagCompound.getCompoundTag(AttributeItemUtil.TAG_RPGCORE);
|
||||
if (rpgCore.hasKey(AttributeItemUtil.TAG_REQUIREMENTS)) {
|
||||
NBTTagCompound reqTag = rpgCore.getCompoundTag(AttributeItemUtil.TAG_REQUIREMENTS);
|
||||
if (!RequirementCheckerRegistry.checkRequirements(player, reqTag)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Entry<String, Float> entry : AttributeItemUtil.readAttributes(piece).entrySet()) {
|
||||
String key = entry.getKey();
|
||||
float value = entry.getValue();
|
||||
AttributeDefinition def = AttributeController.getAttribute(key);
|
||||
if (def != null) {
|
||||
ICustomAttribute inst = playerAttributes.getAttributeInstance(def);
|
||||
if (inst == null) {
|
||||
inst = playerAttributes.registerAttribute(def, 0.0f);
|
||||
}
|
||||
inst.setValue(inst.getValue() + value);
|
||||
}
|
||||
}
|
||||
// Process Magic
|
||||
|
||||
// OFFENSIVE MAGIC
|
||||
Map<Integer, Float> magicFlat = AttributeItemUtil.readMagicAttributeMap(piece, CustomAttributes.MAGIC_DAMAGE_KEY);
|
||||
for (Entry<Integer, Float> entry : magicFlat.entrySet()) {
|
||||
int magicId = entry.getKey();
|
||||
float value = entry.getValue();
|
||||
magicDamage.put(magicId, magicDamage.getOrDefault(magicId, 0.0f) + value);
|
||||
}
|
||||
Map<Integer, Float> magicPercent = AttributeItemUtil.readMagicAttributeMap(piece, CustomAttributes.MAGIC_BOOST_KEY);
|
||||
for (Entry<Integer, Float> entry : magicPercent.entrySet()) {
|
||||
int magicId = entry.getKey();
|
||||
float value = entry.getValue();
|
||||
magicBoost.put(magicId, magicBoost.getOrDefault(magicId, 0.0f) + value);
|
||||
}
|
||||
|
||||
// DEFENSIVE MAGIC
|
||||
Map<Integer, Float> magicDefFlat = AttributeItemUtil.readMagicAttributeMap(piece, CustomAttributes.MAGIC_DEFENSE_KEY);
|
||||
for (Entry<Integer, Float> entry : magicDefFlat.entrySet()) {
|
||||
int magicId = entry.getKey();
|
||||
float value = entry.getValue();
|
||||
magicDefense.put(magicId, magicDefense.getOrDefault(magicId, 0.0f) + value);
|
||||
}
|
||||
Map<Integer, Float> magicResist = AttributeItemUtil.readMagicAttributeMap(piece, CustomAttributes.MAGIC_RESISTANCE_KEY);
|
||||
for (Entry<Integer, Float> entry : magicResist.entrySet()) {
|
||||
int magicId = entry.getKey();
|
||||
float value = entry.getValue();
|
||||
magicResistance.put(magicId, magicResistance.getOrDefault(magicId, 0.0f) + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
equipmentTracker = currentEquip;
|
||||
gearOutput = AttributeAttackUtil.calculateGearOutput(this);
|
||||
extraHealth = getAttributeValue(CustomAttributes.HEALTH);
|
||||
|
||||
updatePlayerMaxHealth(player);
|
||||
|
||||
// Post Recalculation Event to Listeners
|
||||
AttributeRecalcEvent.post(player, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the player's maximum health attribute by applying a custom attribute modifier.
|
||||
* In this system, the aggregated HEALTH attribute is treated as bonus health on top of a base of 20.
|
||||
*
|
||||
* @param player The EntityPlayer whose max health should be updated.
|
||||
*/
|
||||
public void updatePlayerMaxHealth(EntityPlayer player) {
|
||||
float bonusHealth = extraHealth;
|
||||
IAttributeInstance maxHealthAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth);
|
||||
try {
|
||||
AttributeModifier old = maxHealthAttr.getModifier(healthUUID);
|
||||
if (old != null) {
|
||||
maxHealthAttr.removeModifier(old);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
if (bonusHealth != 0) {
|
||||
maxHealthAttr.applyModifier(new AttributeModifier(healthUUID, "RPGCoreHealthBonus", bonusHealth, 0));
|
||||
}
|
||||
// Ensure the player's current health does not exceed the new maximum.
|
||||
float currentHealth = player.getHealth();
|
||||
if (currentHealth > maxHealthAttr.getAttributeValue()) {
|
||||
player.setHealth((float) maxHealthAttr.getAttributeValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player's equipment has changed and recalculates attributes if needed.
|
||||
*/
|
||||
public void updateIfChanged(EntityPlayer player) {
|
||||
PlayerEquipmentTracker currentEquip = new PlayerEquipmentTracker();
|
||||
currentEquip.updateFrom(player);
|
||||
if (!equipmentTracker.equals(player)) {
|
||||
recalcAttributes(player);
|
||||
}
|
||||
}
|
||||
|
||||
public float getAttributeValue(AttributeDefinition def) {
|
||||
ICustomAttribute inst = playerAttributes.getAttributeInstance(def);
|
||||
return inst != null ? inst.getValue() : 0.0f;
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.tracker;
|
||||
|
||||
import kamkeel.npcs.util.AttributeItemUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class PlayerEquipmentTracker {
|
||||
public ItemStack heldItem;
|
||||
public ItemStack helmet;
|
||||
public ItemStack chestplate;
|
||||
public ItemStack leggings;
|
||||
public ItemStack boots;
|
||||
|
||||
/**
|
||||
* Updates the stored equipment based on the player's current held item and armor.
|
||||
*/
|
||||
public void updateFrom(EntityPlayer player) {
|
||||
heldItem = copyIfNotNull(player.getHeldItem());
|
||||
ItemStack[] armor = player.inventory.armorInventory;
|
||||
// Armor inventory order: 0=boots, 1=leggings, 2=chestplate, 3=helmet.
|
||||
boots = copyIfNotNull(armor[0]);
|
||||
leggings = copyIfNotNull(armor[1]);
|
||||
chestplate = copyIfNotNull(armor[2]);
|
||||
helmet = copyIfNotNull(armor[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the stored equipment with the player's current equipment.
|
||||
* Ignores changes like durability by comparing the item and the CNPCAttributes NBT only.
|
||||
*/
|
||||
public boolean equals(EntityPlayer player) {
|
||||
if (player == null) return false;
|
||||
if (!areItemStacksEquivalent(heldItem, player.getHeldItem())) return false;
|
||||
ItemStack[] armor = player.inventory.armorInventory;
|
||||
if (!areItemStacksEquivalent(boots, armor[0])) return false;
|
||||
if (!areItemStacksEquivalent(leggings, armor[1])) return false;
|
||||
if (!areItemStacksEquivalent(chestplate, armor[2])) return false;
|
||||
if (!areItemStacksEquivalent(helmet, armor[3])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the given ItemStack, or null if it is null.
|
||||
*/
|
||||
private ItemStack copyIfNotNull(ItemStack stack) {
|
||||
return (stack == null) ? null : stack.copy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two ItemStacks for equivalence, ignoring durability differences.
|
||||
* It checks if the items are the same and if the "CNPCAttributes" NBT compound is equal.
|
||||
*/
|
||||
private boolean areItemStacksEquivalent(ItemStack a, ItemStack b) {
|
||||
if (a == b) return true;
|
||||
if (a == null || b == null) return false;
|
||||
if (a.getItem() != b.getItem()) return false;
|
||||
NBTTagCompound tagA = a.stackTagCompound;
|
||||
NBTTagCompound tagB = b.stackTagCompound;
|
||||
String attrA = (tagA != null && tagA.hasKey(AttributeItemUtil.TAG_RPGCORE))
|
||||
? tagA.getCompoundTag(AttributeItemUtil.TAG_RPGCORE).toString() : "";
|
||||
String attrB = (tagB != null && tagB.hasKey(AttributeItemUtil.TAG_RPGCORE))
|
||||
? tagB.getCompoundTag(AttributeItemUtil.TAG_RPGCORE).toString() : "";
|
||||
return attrA.equals(attrB);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CNPCData implements IProfileData {
|
||||
|
||||
@Override
|
||||
public String getTagName() {
|
||||
return "CNPC+";
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getCurrentNBT(EntityPlayer player) {
|
||||
PlayerData customNPCData = PlayerData.get(player);
|
||||
return customNPCData.getNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(EntityPlayer player) {
|
||||
PlayerData customNPCData = PlayerData.get(player);
|
||||
customNPCData.save();
|
||||
SyncController.syncPlayerData((EntityPlayerMP) player, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNBT(EntityPlayer player, NBTTagCompound replace) {
|
||||
PlayerData customNPCData = PlayerData.get(player);
|
||||
if (replace.hasNoTags()) {
|
||||
PlayerData newData = new PlayerData();
|
||||
newData.player = player;
|
||||
customNPCData.setNBT((NBTTagCompound) newData.getNBT().copy());
|
||||
} else {
|
||||
customNPCData.setNBT(replace);
|
||||
}
|
||||
customNPCData.updateClient = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSwitchPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileOperation verifySwitch(EntityPlayer player) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
if (playerData.partyUUID != null)
|
||||
return ProfileOperation.error("Cannot switch while in Party");
|
||||
|
||||
return ProfileOperation.success("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProfileInfoEntry> getInfo(EntityPlayer player, NBTTagCompound compound) {
|
||||
PlayerData playerData = new PlayerData();
|
||||
playerData.player = player;
|
||||
playerData.setNBT(compound);
|
||||
|
||||
List<ProfileInfoEntry> info = new ArrayList<>();
|
||||
info.add(new ProfileInfoEntry("profile.info.quest.finished", 0x60fa57, playerData.questData.finishedQuests.size(), 0xFFFFFF));
|
||||
info.add(new ProfileInfoEntry("profile.info.quest.active", 0xf75336, playerData.questData.activeQuests.size(), 0xFFFFFF));
|
||||
info.add(new ProfileInfoEntry("profile.info.dialog.read", 0x47acf5, playerData.dialogData.dialogsRead.size(), 0xFFFFFF));
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
public enum EnumProfileOperation {
|
||||
SUCCESS,
|
||||
ERROR,
|
||||
LOCKED
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IProfileData {
|
||||
|
||||
/**
|
||||
* Do not use the tags: Name, lastLoaded, ID.
|
||||
*
|
||||
* @return The save tag utilized in the Profile.
|
||||
*/
|
||||
public String getTagName();
|
||||
|
||||
/**
|
||||
* @return NBTTagCompound of the current data for a given EntityPlayer.
|
||||
*/
|
||||
public NBTTagCompound getCurrentNBT(EntityPlayer player);
|
||||
|
||||
/**
|
||||
* Called immediately after setNBT() to replace existing NBT.
|
||||
*/
|
||||
public void save(EntityPlayer player);
|
||||
|
||||
/**
|
||||
* Replaces the current data operation when changing profiles.
|
||||
*/
|
||||
public void setNBT(EntityPlayer player, NBTTagCompound replace);
|
||||
|
||||
/**
|
||||
* Returns the priority for this ProfileData's verification check.
|
||||
* Lower numbers run first.
|
||||
*/
|
||||
public int getSwitchPriority();
|
||||
|
||||
/**
|
||||
* Called before a profile switch occurs.
|
||||
*
|
||||
* @param player The player switching profiles.
|
||||
* @return true if allowed, false if not.
|
||||
*/
|
||||
public ProfileOperation verifySwitch(EntityPlayer player);
|
||||
|
||||
/**
|
||||
* NEW: Builds and returns a list of informational strings about this profile data,
|
||||
* based on the provided NBTTagCompound from the slot.
|
||||
*
|
||||
* @param player The player in question.
|
||||
* @param compound The NBT data from the slot under this profile data's tag.
|
||||
* @return A list of InfoEntry with information
|
||||
*/
|
||||
public List<ProfileInfoEntry> getInfo(EntityPlayer player, NBTTagCompound compound);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.IProfile;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Profile implements IProfile {
|
||||
public EntityPlayer player;
|
||||
public int currentSlotId;
|
||||
private Map<Integer, ISlot> slots = new HashMap<>();
|
||||
private boolean locked = false;
|
||||
|
||||
public Profile(EntityPlayer player, NBTTagCompound compound) {
|
||||
this.player = player;
|
||||
if (compound.hasKey("CurrentSlotId")) {
|
||||
this.currentSlotId = compound.getInteger("CurrentSlotId");
|
||||
} else {
|
||||
this.currentSlotId = 0;
|
||||
}
|
||||
|
||||
if (compound.hasKey("Slots")) {
|
||||
NBTTagCompound slotsCompound = compound.getCompoundTag("Slots");
|
||||
Set<String> keys = slotsCompound.func_150296_c();
|
||||
for (String key : keys) {
|
||||
try {
|
||||
int slotId = Integer.parseInt(key);
|
||||
NBTTagCompound slotNBT = slotsCompound.getCompoundTag(key);
|
||||
ISlot slot = Slot.fromNBT(slotId, slotNBT);
|
||||
slots.put(slotId, slot);
|
||||
} catch (NumberFormatException e) {
|
||||
// Skip keys that are not valid slot IDs.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Profile(EntityPlayer player) {
|
||||
this.player = player;
|
||||
this.currentSlotId = 0;
|
||||
// Create a default slot.
|
||||
Slot defaultSlot = new Slot(0, "Default Slot");
|
||||
defaultSlot.setLastLoaded(System.currentTimeMillis());
|
||||
slots.put(0, defaultSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return NoppesUtilServer.getIPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentSlotId() {
|
||||
return currentSlotId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ISlot> getSlots() {
|
||||
return slots;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if (player != null)
|
||||
compound.setString("Name", player.getCommandSenderName());
|
||||
compound.setInteger("CurrentSlotId", currentSlotId);
|
||||
NBTTagCompound slotsCompound = new NBTTagCompound();
|
||||
for (Map.Entry<Integer, ISlot> entry : slots.entrySet()) {
|
||||
// Save only non-temporary slots.
|
||||
if (entry.getValue().isTemporary())
|
||||
continue;
|
||||
slotsCompound.setTag(String.valueOf(entry.getKey()), entry.getValue().toNBT());
|
||||
}
|
||||
compound.setTag("Slots", slotsCompound);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ProfileInfoEntry {
|
||||
private String label;
|
||||
private String result;
|
||||
private int labelColor;
|
||||
private int resultColor;
|
||||
|
||||
public ProfileInfoEntry() {
|
||||
}
|
||||
|
||||
public ProfileInfoEntry(String label, int labelColor, String result, int resultColor) {
|
||||
this.label = label;
|
||||
this.result = result;
|
||||
this.labelColor = labelColor;
|
||||
this.resultColor = resultColor;
|
||||
}
|
||||
|
||||
public ProfileInfoEntry(String label, int labelColor, int result, int resultColor) {
|
||||
this(label, labelColor, String.valueOf(result), resultColor);
|
||||
}
|
||||
|
||||
public ProfileInfoEntry(String label, String result) {
|
||||
this(label, 0xFFFFFF, result, 0xFFFFFF);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setString("Label", label);
|
||||
tag.setInteger("LabelColor", labelColor);
|
||||
tag.setString("Result", result);
|
||||
tag.setInteger("ResultColor", resultColor);
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static ProfileInfoEntry readFromNBT(NBTTagCompound tag) {
|
||||
return new ProfileInfoEntry(
|
||||
tag.getString("Label"),
|
||||
tag.getInteger("LabelColor"),
|
||||
tag.getString("Result"),
|
||||
tag.getInteger("ResultColor")
|
||||
);
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getLabelColor() {
|
||||
return labelColor;
|
||||
}
|
||||
|
||||
public int getResultColor() {
|
||||
return resultColor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
public class ProfileOperation {
|
||||
private final EnumProfileOperation result;
|
||||
private final String message;
|
||||
|
||||
public ProfileOperation(EnumProfileOperation result, String message) {
|
||||
this.result = result;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public EnumProfileOperation getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static ProfileOperation success(String message) {
|
||||
return new ProfileOperation(EnumProfileOperation.SUCCESS, message);
|
||||
}
|
||||
|
||||
public static ProfileOperation error(String message) {
|
||||
return new ProfileOperation(EnumProfileOperation.ERROR, message);
|
||||
}
|
||||
|
||||
public static ProfileOperation locked(String message) {
|
||||
return new ProfileOperation(EnumProfileOperation.LOCKED, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Slot implements ISlot {
|
||||
private int id;
|
||||
private String name;
|
||||
private long lastLoaded;
|
||||
private boolean temporary;
|
||||
private Map<String, NBTTagCompound> components = new HashMap<>();
|
||||
|
||||
public Slot(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Slot(int id, String name, long lastLoaded, boolean temporary, Map<String, NBTTagCompound> components) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lastLoaded = lastLoaded;
|
||||
this.temporary = temporary;
|
||||
this.components = components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastLoaded() {
|
||||
return lastLoaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastLoaded(long time) {
|
||||
this.lastLoaded = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTemporary() {
|
||||
return temporary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemporary(boolean temporary) {
|
||||
this.temporary = temporary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, NBTTagCompound> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComponentData(String key, NBTTagCompound data) {
|
||||
components.put(key, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getComponentData(String key) {
|
||||
return components.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound toNBT() {
|
||||
NBTTagCompound slotNBT = new NBTTagCompound();
|
||||
slotNBT.setString("Name", name);
|
||||
slotNBT.setLong("LastLoaded", lastLoaded);
|
||||
slotNBT.setBoolean("Temporary", temporary);
|
||||
NBTTagCompound compCompound = new NBTTagCompound();
|
||||
for (Map.Entry<String, NBTTagCompound> entry : components.entrySet()) {
|
||||
compCompound.setTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
slotNBT.setTag("Components", compCompound);
|
||||
return slotNBT;
|
||||
}
|
||||
|
||||
public static Slot fromNBT(int id, NBTTagCompound slotNBT) {
|
||||
String name = slotNBT.getString("Name");
|
||||
long lastLoaded = slotNBT.getLong("LastLoaded");
|
||||
boolean temporary = slotNBT.getBoolean("Temporary");
|
||||
Slot slot = new Slot(id, name);
|
||||
slot.setLastLoaded(lastLoaded);
|
||||
slot.setTemporary(temporary);
|
||||
if (slotNBT.hasKey("Components")) {
|
||||
NBTTagCompound compCompound = slotNBT.getCompoundTag("Components");
|
||||
Set<String> keys = compCompound.func_150296_c();
|
||||
for (String key : keys) {
|
||||
slot.setComponentData(key, compCompound.getCompoundTag(key));
|
||||
}
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
package kamkeel.developer;
|
||||
package kamkeel.npcs.developer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
@@ -11,31 +11,31 @@ public class Developer {
|
||||
public static HashSet<UUID> QuestMaker = new HashSet<>();
|
||||
public static Developer Instance;
|
||||
|
||||
public Developer(){
|
||||
public Developer() {
|
||||
Instance = this;
|
||||
// Temp for testing
|
||||
Universal.add(UUID.fromString("29cc52dd-2c50-4e8f-a388-be6c497cf0b4"));
|
||||
}
|
||||
|
||||
public boolean hasUniversal(UUID uuid){
|
||||
if(Universal == null){
|
||||
public boolean hasUniversal(UUID uuid) {
|
||||
if (Universal == null) {
|
||||
Universal = new HashSet<>();
|
||||
}
|
||||
return Universal.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean hasScriptUser(UUID uuid){
|
||||
if(ScriptUser == null){
|
||||
public boolean hasScriptUser(UUID uuid) {
|
||||
if (ScriptUser == null) {
|
||||
ScriptUser = new HashSet<>();
|
||||
}
|
||||
return ScriptUser.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean hasWandUser(UUID uuid){
|
||||
public boolean hasWandUser(UUID uuid) {
|
||||
return WandUser.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean hasQuestMaker(UUID uuid){
|
||||
public boolean hasQuestMaker(UUID uuid) {
|
||||
return QuestMaker.contains(uuid);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package kamkeel.npcs.network;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractPacket {
|
||||
|
||||
public EntityNPCInterface npc;
|
||||
|
||||
public FMLProxyPacket generatePacket() {
|
||||
PacketChannel packetChannel = getChannel();
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
try {
|
||||
buf.writeInt(packetChannel.getChannelType().ordinal());
|
||||
buf.writeInt(getType().ordinal());
|
||||
sendData(buf);
|
||||
return new FMLProxyPacket(buf, packetChannel.getChannelName());
|
||||
} catch (Exception e) {
|
||||
// For debugging, you might want to log it
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<FMLProxyPacket> generatePackets() {
|
||||
FMLProxyPacket single = generatePacket();
|
||||
if (single == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(single);
|
||||
}
|
||||
|
||||
public abstract Enum getType();
|
||||
|
||||
public abstract PacketChannel getChannel();
|
||||
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean needsNPC() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setNPC(EntityNPCInterface npc) {
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
public abstract void sendData(ByteBuf out) throws IOException;
|
||||
|
||||
//"player" on the server side is the client who sent this packet
|
||||
//"player" on the client side is the client player
|
||||
public abstract void receiveData(ByteBuf in, EntityPlayer player) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package kamkeel.npcs.network;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.LogWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class LargeAbstractPacket extends AbstractPacket {
|
||||
|
||||
private static final Map<UUID, PacketStorage> packetChunks = new ConcurrentHashMap<>();
|
||||
private static final int CHUNK_SIZE = 10000;
|
||||
|
||||
/**
|
||||
* Create multiple FMLProxyPacket objects, each containing up to CHUNK_SIZE bytes.
|
||||
*/
|
||||
@Override
|
||||
public List<FMLProxyPacket> generatePackets() {
|
||||
List<FMLProxyPacket> packets = new ArrayList<>();
|
||||
PacketChannel packetChannel = getChannel();
|
||||
|
||||
byte[] fullData;
|
||||
try {
|
||||
fullData = getData();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return packets;
|
||||
}
|
||||
|
||||
int totalSize = fullData.length;
|
||||
UUID packetId = UUID.randomUUID();
|
||||
|
||||
// Break data into CHUNK_SIZE chunks
|
||||
for (int offset = 0; offset < totalSize; offset += CHUNK_SIZE) {
|
||||
int chunkSize = Math.min(CHUNK_SIZE, totalSize - offset);
|
||||
ByteBuf chunkBuf = Unpooled.buffer();
|
||||
|
||||
chunkBuf.writeInt(packetChannel.getChannelType().ordinal());
|
||||
chunkBuf.writeInt(getType().ordinal());
|
||||
|
||||
chunkBuf.writeLong(packetId.getMostSignificantBits());
|
||||
chunkBuf.writeLong(packetId.getLeastSignificantBits());
|
||||
chunkBuf.writeInt(totalSize);
|
||||
chunkBuf.writeInt(offset);
|
||||
chunkBuf.writeInt((totalSize + CHUNK_SIZE - 1) / CHUNK_SIZE);
|
||||
|
||||
chunkBuf.writeBytes(fullData, offset, chunkSize);
|
||||
|
||||
FMLProxyPacket proxyPacket = new FMLProxyPacket(chunkBuf, packetChannel.getChannelName());
|
||||
packets.add(proxyPacket);
|
||||
}
|
||||
return packets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
UUID packetId = null;
|
||||
PacketStorage storage = null;
|
||||
ByteBuf chunk = null;
|
||||
ByteBuf completeData = null;
|
||||
|
||||
try {
|
||||
// Read UUID from the buffer
|
||||
long mostSigBits = in.readLong();
|
||||
long leastSigBits = in.readLong();
|
||||
packetId = new UUID(mostSigBits, leastSigBits);
|
||||
|
||||
// Read packet metadata
|
||||
int totalSize = in.readInt();
|
||||
int offset = in.readInt();
|
||||
int totalChunks = in.readInt(); // Debugging info
|
||||
int chunkSize = Math.min(CHUNK_SIZE, totalSize - offset);
|
||||
|
||||
// Basic validation to ensure the chunk won't overwrite out of bounds
|
||||
if (chunkSize <= 0 || offset < 0 || (offset + chunkSize) > totalSize) {
|
||||
throw new IndexOutOfBoundsException("Invalid chunk size/offset: chunkSize="
|
||||
+ chunkSize + ", offset=" + offset + ", totalSize=" + totalSize);
|
||||
}
|
||||
|
||||
// Read the exact chunk data
|
||||
chunk = in.readBytes(chunkSize);
|
||||
|
||||
// Store the received chunk in a PacketStorage
|
||||
storage = packetChunks.computeIfAbsent(packetId, k -> new PacketStorage(Unpooled.buffer(totalSize), 0, totalSize));
|
||||
|
||||
// Write this chunk into the buffer at the correct offset
|
||||
storage.data.setBytes(offset, chunk);
|
||||
storage.receivedSoFar += chunkSize;
|
||||
|
||||
// If we've received all bytes, finalize
|
||||
if (storage.receivedSoFar >= totalSize) {
|
||||
packetChunks.remove(packetId);
|
||||
completeData = storage.data.copy(0, totalSize);
|
||||
|
||||
try {
|
||||
handleCompleteData(completeData, player);
|
||||
} finally {
|
||||
completeData.release();
|
||||
}
|
||||
|
||||
storage.data.release();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Log the exception with contextual information
|
||||
LogWriter.error("Error in receiveData for packetId " + (packetId != null ? packetId.toString() : "null") + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
||||
// If storage was created but the packet is incomplete, release storage.data
|
||||
if (storage != null && storage.receivedSoFar < storage.totalSize) {
|
||||
storage.data.release();
|
||||
if (packetId != null) {
|
||||
packetChunks.remove(packetId);
|
||||
}
|
||||
}
|
||||
|
||||
throw e; // Rethrow the exception after logging
|
||||
} finally {
|
||||
// Ensure that 'chunk' is released if it was allocated
|
||||
if (chunk != null && chunk.refCnt() > 0) {
|
||||
chunk.release();
|
||||
}
|
||||
|
||||
// Ensure that 'completeData' is released if it was created and not yet released
|
||||
if (completeData != null && completeData.refCnt() > 0) {
|
||||
completeData.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract byte[] getData() throws IOException;
|
||||
|
||||
protected abstract void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException;
|
||||
|
||||
@Override
|
||||
public final FMLProxyPacket generatePacket() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple storage class to keep track of partial data and how many bytes we've received so far.
|
||||
*/
|
||||
private static class PacketStorage {
|
||||
final ByteBuf data;
|
||||
int receivedSoFar;
|
||||
final int totalSize;
|
||||
|
||||
PacketStorage(ByteBuf data, int receivedSoFar, int totalSize) {
|
||||
this.data = data;
|
||||
this.receivedSoFar = receivedSoFar;
|
||||
this.totalSize = totalSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package kamkeel.npcs.network;
|
||||
|
||||
import kamkeel.npcs.network.enums.EnumChannelType;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
public class PacketChannel {
|
||||
|
||||
private String channelName;
|
||||
private EnumChannelType channelType;
|
||||
|
||||
public Map<Integer, AbstractPacket> packets = new Hashtable<>();
|
||||
|
||||
public PacketChannel(String channelName, EnumChannelType channelType) {
|
||||
this.channelName = channelName;
|
||||
this.channelType = channelType;
|
||||
}
|
||||
|
||||
public String getChannelName() {
|
||||
return channelName;
|
||||
}
|
||||
|
||||
public void setChannelName(String channelName) {
|
||||
this.channelName = channelName;
|
||||
}
|
||||
|
||||
public EnumChannelType getChannelType() {
|
||||
return channelType;
|
||||
}
|
||||
|
||||
public void setChannelType(EnumChannelType channelType) {
|
||||
this.channelType = channelType;
|
||||
}
|
||||
|
||||
public void registerPacket(AbstractPacket packet) {
|
||||
if (packets.containsKey(packet.getType().ordinal())) {
|
||||
System.out.println("Packet ID: " + packet.getType().ordinal() + " is already registered in " + this.channelName);
|
||||
return;
|
||||
}
|
||||
this.packets.put(packet.getType().ordinal(), packet);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package kamkeel.npcs.network;
|
||||
|
||||
public class PacketClient extends PacketHandler {
|
||||
|
||||
public static void sendClient(AbstractPacket packet) {
|
||||
PacketHandler.Instance.sendToServer(packet);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,594 @@
|
||||
package kamkeel.npcs.network;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.network.FMLEventChannel;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.enums.EnumChannelType;
|
||||
import kamkeel.npcs.network.packets.data.*;
|
||||
import kamkeel.npcs.network.packets.data.gui.*;
|
||||
import kamkeel.npcs.network.packets.data.large.*;
|
||||
import kamkeel.npcs.network.packets.data.npc.*;
|
||||
import kamkeel.npcs.network.packets.data.script.ScriptOverlayClosePacket;
|
||||
import kamkeel.npcs.network.packets.data.script.ScriptOverlayDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.script.ScriptedParticlePacket;
|
||||
import kamkeel.npcs.network.packets.player.*;
|
||||
import kamkeel.npcs.network.packets.player.customgui.CustomGuiButtonPacket;
|
||||
import kamkeel.npcs.network.packets.player.customgui.CustomGuiClosePacket;
|
||||
import kamkeel.npcs.network.packets.player.customgui.CustomGuiUnfocusedPacket;
|
||||
import kamkeel.npcs.network.packets.player.customgui.CustomScrollClickPacket;
|
||||
import kamkeel.npcs.network.packets.player.profile.*;
|
||||
import kamkeel.npcs.network.packets.request.*;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationsGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.bank.BankGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.bank.BankRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.bank.BankSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.bank.BanksGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.clone.*;
|
||||
import kamkeel.npcs.network.packets.request.dialog.*;
|
||||
import kamkeel.npcs.network.packets.request.effects.EffectGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.effects.EffectRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.effects.EffectSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.effects.EffectsGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.faction.*;
|
||||
import kamkeel.npcs.network.packets.request.feather.DimensionTeleportPacket;
|
||||
import kamkeel.npcs.network.packets.request.item.ColorBrushPacket;
|
||||
import kamkeel.npcs.network.packets.request.item.ColorSetPacket;
|
||||
import kamkeel.npcs.network.packets.request.item.HammerPacket;
|
||||
import kamkeel.npcs.network.packets.request.jobs.JobGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.jobs.JobSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.jobs.JobSpawnerAddPacket;
|
||||
import kamkeel.npcs.network.packets.request.jobs.JobSpawnerRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.*;
|
||||
import kamkeel.npcs.network.packets.request.magic.*;
|
||||
import kamkeel.npcs.network.packets.request.mainmenu.*;
|
||||
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.npc.*;
|
||||
import kamkeel.npcs.network.packets.request.party.*;
|
||||
import kamkeel.npcs.network.packets.request.pather.MovingPathGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.playerdata.*;
|
||||
import kamkeel.npcs.network.packets.request.quest.*;
|
||||
import kamkeel.npcs.network.packets.request.recipe.RecipeGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.recipe.RecipeRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.recipe.RecipeSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.recipe.RecipesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.role.RoleCompanionUpdatePacket;
|
||||
import kamkeel.npcs.network.packets.request.role.RoleGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.role.RoleSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.script.*;
|
||||
import kamkeel.npcs.network.packets.request.script.item.ItemScriptErrorPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.item.ItemScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.item.LinkedItemScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.tags.*;
|
||||
import kamkeel.npcs.network.packets.request.transform.TransformGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.transform.TransformLoadPacket;
|
||||
import kamkeel.npcs.network.packets.request.transform.TransformSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.transport.*;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PacketHandler {
|
||||
public static PacketHandler Instance;
|
||||
|
||||
// Channels
|
||||
public Map<EnumChannelType, FMLEventChannel> channels = new Hashtable<>();
|
||||
|
||||
// Client to Server
|
||||
public static final PacketChannel REQUEST_PACKET = new PacketChannel("CNPC+|Req", EnumChannelType.REQUEST);
|
||||
|
||||
// Client to Server - Typically information
|
||||
public static final PacketChannel PLAYER_PACKET = new PacketChannel("CNPC+|Player", EnumChannelType.PLAYER);
|
||||
|
||||
// Server to Client
|
||||
public static final PacketChannel DATA_PACKET = new PacketChannel("CNPC+|Data", EnumChannelType.DATA);
|
||||
|
||||
public static final List<PacketChannel> packetChannels = new ArrayList<>();
|
||||
|
||||
public PacketHandler() {
|
||||
// Register Channels
|
||||
packetChannels.add(REQUEST_PACKET);
|
||||
packetChannels.add(PLAYER_PACKET);
|
||||
packetChannels.add(DATA_PACKET);
|
||||
|
||||
this.registerDataPackets();
|
||||
this.registerRequestPackets();
|
||||
this.registerPlayerPackets();
|
||||
}
|
||||
|
||||
public void registerRequestPackets() {
|
||||
// NPC Packets
|
||||
REQUEST_PACKET.registerPacket(new NpcClosePacket());
|
||||
REQUEST_PACKET.registerPacket(new NpcDeletePacket());
|
||||
|
||||
// Script Packets
|
||||
REQUEST_PACKET.registerPacket(new BlockScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new EventScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new ForgeScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new GlobalNPCScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new ItemScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new ItemScriptErrorPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedItemScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new NPCScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new ScriptInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new EffectScriptPacket());
|
||||
|
||||
// Cloner Packets
|
||||
REQUEST_PACKET.registerPacket(new CloneListPacket());
|
||||
REQUEST_PACKET.registerPacket(new SpawnMobPacket());
|
||||
REQUEST_PACKET.registerPacket(new MobSpawnerPacket());
|
||||
REQUEST_PACKET.registerPacket(new ClonePreSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new CloneSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new CloneRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new CloneTagListPacket());
|
||||
REQUEST_PACKET.registerPacket(new CloneAllTagsPacket());
|
||||
REQUEST_PACKET.registerPacket(new CloneAllTagsShortPacket());
|
||||
|
||||
|
||||
// Linked Packets
|
||||
REQUEST_PACKET.registerPacket(new LinkedGetAllPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedNPCRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedSetPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedNPCAddPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedItemSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedItemRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedItemBuildPacket());
|
||||
|
||||
|
||||
// Bank Packets
|
||||
REQUEST_PACKET.registerPacket(new BanksGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new BankGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new BankRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new BankSavePacket());
|
||||
|
||||
// Recipe Packets
|
||||
REQUEST_PACKET.registerPacket(new RecipesGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new RecipeGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new RecipeRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new RecipeSavePacket());
|
||||
|
||||
// Natural Spawn Packets
|
||||
REQUEST_PACKET.registerPacket(new NaturalSpawnGetAllPacket());
|
||||
REQUEST_PACKET.registerPacket(new NaturalSpawnGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new NaturalSpawnSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new NaturalSpawnRemovePacket());
|
||||
|
||||
// Dialog Category Packets
|
||||
REQUEST_PACKET.registerPacket(new DialogCategorySavePacket());
|
||||
REQUEST_PACKET.registerPacket(new DialogCategoryRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new DialogCategoryGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new DialogCategoriesGetPacket());
|
||||
|
||||
// Dialog Packets
|
||||
REQUEST_PACKET.registerPacket(new DialogSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new DialogRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new DialogsGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new DialogGetPacket());
|
||||
|
||||
REQUEST_PACKET.registerPacket(new DialogNpcGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new DialogNpcSetPacket());
|
||||
REQUEST_PACKET.registerPacket(new DialogNpcRemovePacket());
|
||||
|
||||
// Quest Category Packets
|
||||
REQUEST_PACKET.registerPacket(new QuestCategorySavePacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestCategoryRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestCategoryGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestCategoriesGetPacket());
|
||||
|
||||
// Quest Packets
|
||||
REQUEST_PACKET.registerPacket(new QuestOpenGuiPacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestDialogGetTitlePacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestLogToServerPacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestUntrackPacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new QuestsGetPacket());
|
||||
|
||||
// Faction Packets
|
||||
REQUEST_PACKET.registerPacket(new FactionSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new FactionRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new FactionSetPacket());
|
||||
REQUEST_PACKET.registerPacket(new FactionGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new FactionsGetPacket());
|
||||
|
||||
// Tag Packets
|
||||
REQUEST_PACKET.registerPacket(new TagsGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new TagGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new TagsNpcGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new TagSetPacket());
|
||||
REQUEST_PACKET.registerPacket(new TagSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new TagRemovePacket());
|
||||
|
||||
// PlayerData Packets
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataGetNamesPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataGetInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataDeleteInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataSaveInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataMapRegenPacket());
|
||||
|
||||
// Main Menu Packets
|
||||
REQUEST_PACKET.registerPacket(new MainmenuDisplayGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new MainmenuDisplaySavePacket());
|
||||
|
||||
REQUEST_PACKET.registerPacket(new MainmenuStatsGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new MainmenuStatsSavePacket());
|
||||
|
||||
REQUEST_PACKET.registerPacket(new MainmenuAIGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new MainmenuAISavePacket());
|
||||
|
||||
REQUEST_PACKET.registerPacket(new MainmenuAdvancedGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new MainmenuAdvancedSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MainmenuAdvancedMarkDataPacket());
|
||||
|
||||
REQUEST_PACKET.registerPacket(new MainmenuInvGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new MainmenuInvSavePacket());
|
||||
|
||||
// Transport Packets
|
||||
REQUEST_PACKET.registerPacket(new TransportCategoriesGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new TransportCategorySavePacket());
|
||||
REQUEST_PACKET.registerPacket(new TransportCategoryRemovePacket());
|
||||
|
||||
REQUEST_PACKET.registerPacket(new TransportRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new TransportsGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new TransportSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new TransportGetLocationPacket());
|
||||
|
||||
// Remote Packets Packets
|
||||
REQUEST_PACKET.registerPacket(new RemoteMainMenuPacket());
|
||||
REQUEST_PACKET.registerPacket(new RemoteGlobalMenuPacket());
|
||||
REQUEST_PACKET.registerPacket(new RemoteDeletePacket());
|
||||
REQUEST_PACKET.registerPacket(new RemoteNpcsGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new RemoteFreezeGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new RemoteFreezePacket());
|
||||
REQUEST_PACKET.registerPacket(new RemoteResetPacket());
|
||||
REQUEST_PACKET.registerPacket(new RemoteTpToNpcPacket());
|
||||
|
||||
// Job Packets
|
||||
REQUEST_PACKET.registerPacket(new JobGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new JobSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new JobSpawnerAddPacket());
|
||||
REQUEST_PACKET.registerPacket(new JobSpawnerRemovePacket());
|
||||
|
||||
// Role Packets
|
||||
REQUEST_PACKET.registerPacket(new RoleCompanionUpdatePacket());
|
||||
REQUEST_PACKET.registerPacket(new RoleSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new RoleGetPacket());
|
||||
|
||||
// Transform Packets
|
||||
REQUEST_PACKET.registerPacket(new TransformSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new TransformGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new TransformLoadPacket());
|
||||
|
||||
// Trader Packets
|
||||
REQUEST_PACKET.registerPacket(new TraderMarketSavePacket());
|
||||
|
||||
// Party Packets
|
||||
REQUEST_PACKET.registerPacket(new PartySavePacket());
|
||||
REQUEST_PACKET.registerPacket(new PartyInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new PartyDisbandPacket());
|
||||
REQUEST_PACKET.registerPacket(new PartySetLeaderPacket());
|
||||
REQUEST_PACKET.registerPacket(new PartyKickPacket());
|
||||
REQUEST_PACKET.registerPacket(new PartyLeavePacket());
|
||||
REQUEST_PACKET.registerPacket(new PartySetQuestPacket());
|
||||
REQUEST_PACKET.registerPacket(new PartyInvitePacket());
|
||||
REQUEST_PACKET.registerPacket(new PartyAcceptInvitePacket());
|
||||
REQUEST_PACKET.registerPacket(new PartyIgnoreInvitePacket());
|
||||
REQUEST_PACKET.registerPacket(new PartyLogToServerPacket());
|
||||
|
||||
// Animation Packets
|
||||
REQUEST_PACKET.registerPacket(new AnimationsGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new AnimationGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new AnimationRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new AnimationSavePacket());
|
||||
|
||||
// Moving Path
|
||||
REQUEST_PACKET.registerPacket(new MovingPathSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MovingPathGetPacket());
|
||||
|
||||
// Tool Packets
|
||||
REQUEST_PACKET.registerPacket(new ColorBrushPacket());
|
||||
REQUEST_PACKET.registerPacket(new ColorSetPacket());
|
||||
REQUEST_PACKET.registerPacket(new HammerPacket());
|
||||
|
||||
// Custom Effect Packets
|
||||
REQUEST_PACKET.registerPacket(new EffectGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new EffectsGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new EffectSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new EffectRemovePacket());
|
||||
|
||||
// Magic Packets
|
||||
REQUEST_PACKET.registerPacket(new MagicCycleRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicCycleSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicGetAllPacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicNpcGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicNpcSavePacket());
|
||||
|
||||
// Other Packets
|
||||
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
|
||||
REQUEST_PACKET.registerPacket(new GuiRequestPacket());
|
||||
REQUEST_PACKET.registerPacket(new DimensionsGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new MerchantUpdatePacket());
|
||||
REQUEST_PACKET.registerPacket(new ModelDataSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MailOpenSetupPacket());
|
||||
REQUEST_PACKET.registerPacket(new TileEntityGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new TileEntitySavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MountPacket());
|
||||
REQUEST_PACKET.registerPacket(new DimensionTeleportPacket());
|
||||
}
|
||||
|
||||
public void registerDataPackets() {
|
||||
// Data Packets
|
||||
DATA_PACKET.registerPacket(new LoginPacket());
|
||||
DATA_PACKET.registerPacket(new AchievementPacket());
|
||||
DATA_PACKET.registerPacket(new ChatAlertPacket());
|
||||
DATA_PACKET.registerPacket(new ChatBubblePacket());
|
||||
DATA_PACKET.registerPacket(new ConfigCommandPacket());
|
||||
DATA_PACKET.registerPacket(new DisableMouseInputPacket());
|
||||
DATA_PACKET.registerPacket(new MarkDataPacket());
|
||||
DATA_PACKET.registerPacket(new OverlayQuestTrackingPacket());
|
||||
DATA_PACKET.registerPacket(new ParticlePacket());
|
||||
DATA_PACKET.registerPacket(new PlayerUpdateSkinOverlaysPacket());
|
||||
DATA_PACKET.registerPacket(new QuestCompletionPacket());
|
||||
DATA_PACKET.registerPacket(new ScrollSelectedPacket());
|
||||
DATA_PACKET.registerPacket(new SoundManagementPacket());
|
||||
DATA_PACKET.registerPacket(new SwingPlayerArmPacket());
|
||||
DATA_PACKET.registerPacket(new UpdateAnimationsPacket());
|
||||
DATA_PACKET.registerPacket(new VillagerListPacket());
|
||||
DATA_PACKET.registerPacket(new PlayerDataInfoPacket());
|
||||
|
||||
// Data | GUI Packets
|
||||
DATA_PACKET.registerPacket(new GuiClosePacket());
|
||||
DATA_PACKET.registerPacket(new GuiOpenPacket());
|
||||
DATA_PACKET.registerPacket(new GuiErrorPacket());
|
||||
DATA_PACKET.registerPacket(new GuiRedstonePacket());
|
||||
DATA_PACKET.registerPacket(new GuiTeleporterPacket());
|
||||
DATA_PACKET.registerPacket(new GuiWaypointPacket());
|
||||
DATA_PACKET.registerPacket(new IsGuiOpenPacket());
|
||||
DATA_PACKET.registerPacket(new GuiOpenBookPacket());
|
||||
|
||||
// Data | NPC Packets
|
||||
DATA_PACKET.registerPacket(new DeleteNpcPacket());
|
||||
DATA_PACKET.registerPacket(new EditNpcPacket());
|
||||
DATA_PACKET.registerPacket(new UpdateNpcPacket());
|
||||
DATA_PACKET.registerPacket(new DialogPacket());
|
||||
DATA_PACKET.registerPacket(new RolePacket());
|
||||
DATA_PACKET.registerPacket(new WeaponNpcPacket());
|
||||
|
||||
// Data | Script Packets
|
||||
DATA_PACKET.registerPacket(new ScriptedParticlePacket());
|
||||
DATA_PACKET.registerPacket(new ScriptOverlayClosePacket());
|
||||
DATA_PACKET.registerPacket(new ScriptOverlayDataPacket());
|
||||
|
||||
// Data | Large Packets
|
||||
DATA_PACKET.registerPacket(new ClonerPacket());
|
||||
DATA_PACKET.registerPacket(new ScrollDataPacket());
|
||||
DATA_PACKET.registerPacket(new ScrollListPacket());
|
||||
DATA_PACKET.registerPacket(new SyncPacket());
|
||||
DATA_PACKET.registerPacket(new SyncEffectPacket());
|
||||
DATA_PACKET.registerPacket(new GuiDataPacket());
|
||||
DATA_PACKET.registerPacket(new PartyDataPacket());
|
||||
}
|
||||
|
||||
public void registerPlayerPackets() {
|
||||
PLAYER_PACKET.registerPacket(new FollowerPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new TransportPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new BankActionPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new DialogSelectPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new CheckPlayerValue());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new MailActionPacket());
|
||||
PLAYER_PACKET.registerPacket(new MailActionPacket.MailSendPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new SaveSignPacket());
|
||||
PLAYER_PACKET.registerPacket(new SaveBookPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new CompanionActionPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new GetNPCRole());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new InputDevicePacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new ScreenSizePacket());
|
||||
|
||||
// CustomGUI Packets
|
||||
PLAYER_PACKET.registerPacket(new CustomGuiButtonPacket());
|
||||
PLAYER_PACKET.registerPacket(new CustomGuiClosePacket());
|
||||
PLAYER_PACKET.registerPacket(new CustomGuiUnfocusedPacket());
|
||||
PLAYER_PACKET.registerPacket(new CustomScrollClickPacket());
|
||||
|
||||
// Profile Packets
|
||||
PLAYER_PACKET.registerPacket(new ProfileCreatePacket());
|
||||
PLAYER_PACKET.registerPacket(new ProfileRemovePacket());
|
||||
PLAYER_PACKET.registerPacket(new ProfileRenamePacket());
|
||||
PLAYER_PACKET.registerPacket(new ProfileChangePacket());
|
||||
PLAYER_PACKET.registerPacket(new ProfileGetPacket());
|
||||
PLAYER_PACKET.registerPacket(new ProfileGetInfoPacket());
|
||||
}
|
||||
|
||||
public void registerChannels() {
|
||||
for (PacketChannel channel : packetChannels) {
|
||||
FMLEventChannel eventChannel =
|
||||
NetworkRegistry.INSTANCE.newEventDrivenChannel(channel.getChannelName());
|
||||
eventChannel.register(this);
|
||||
channels.put(channel.getChannelType(), eventChannel);
|
||||
}
|
||||
}
|
||||
|
||||
public PacketChannel getPacketChannel(EnumChannelType type) {
|
||||
return packetChannels.stream()
|
||||
.filter(channel -> channel.getChannelType() == type)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public FMLEventChannel getEventChannel(AbstractPacket abstractPacket) {
|
||||
PacketChannel packetChannel = getPacketChannel(abstractPacket.getChannel().getChannelType());
|
||||
if (packetChannel == null) {
|
||||
return null;
|
||||
}
|
||||
return channels.get(packetChannel.getChannelType());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerPacket(FMLNetworkEvent.ServerCustomPacketEvent event) {
|
||||
handlePacket(event.packet, ((NetHandlerPlayServer) event.handler).playerEntity, Side.SERVER);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientPacket(FMLNetworkEvent.ClientCustomPacketEvent event) {
|
||||
handlePacket(event.packet, CustomNpcs.proxy.getPlayer(), Side.CLIENT);
|
||||
}
|
||||
|
||||
private void handlePacket(FMLProxyPacket packet, EntityPlayer player, Side side) {
|
||||
ByteBuf buf = packet.payload();
|
||||
try {
|
||||
int packetTypeOrdinal = buf.readInt();
|
||||
EnumChannelType packetType = EnumChannelType.values()[packetTypeOrdinal];
|
||||
|
||||
PacketChannel packetChannel = getPacketChannel(packetType);
|
||||
if (packetChannel == null) {
|
||||
LogWriter.error("Error: Packet channel is null for packet type: " + packetType);
|
||||
return;
|
||||
}
|
||||
|
||||
int packetId = buf.readInt();
|
||||
AbstractPacket abstractPacket = packetChannel.packets.get(packetId);
|
||||
if (abstractPacket == null) {
|
||||
LogWriter.error("Error: Abstract packet is null for packet ID: " + packetId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (side == Side.SERVER) {
|
||||
if (abstractPacket.getChannel() == REQUEST_PACKET && ConfigMain.OpsOnly && !NoppesUtilServer.isOp(player)) {
|
||||
LogWriter.error(String.format("%s tried to use CNPC+ without being an op", player.getCommandSenderName()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if permission is allowed
|
||||
if (abstractPacket.getPermission() != null && !CustomNpcsPermissions.hasPermission(player, abstractPacket.getPermission())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for required NPC
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if (abstractPacket.needsNPC() && npc == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
abstractPacket.setNPC(npc);
|
||||
}
|
||||
|
||||
// Let the packet parse the rest
|
||||
abstractPacket.receiveData(buf, player);
|
||||
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
LogWriter.error("Error: IndexOutOfBoundsException in handlePacket: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error: Exception in handlePacket: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends every FMLProxyPacket produced by packet.generatePackets()
|
||||
*/
|
||||
private void sendAllPackets(AbstractPacket packet, SendAction action) {
|
||||
// get all generated FMLProxyPacket objects (could be 1 for normal, or many for large)
|
||||
List<FMLProxyPacket> proxyPackets = packet.generatePackets();
|
||||
if (proxyPackets.isEmpty()) {
|
||||
LogWriter.error("Warning: No packets generated for " + packet.getClass().getName());
|
||||
}
|
||||
|
||||
for (FMLProxyPacket proxy : proxyPackets) {
|
||||
action.send(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Public API methods for sending
|
||||
|
||||
public void sendToPlayer(AbstractPacket packet, EntityPlayerMP player) {
|
||||
FMLEventChannel eventChannel = getEventChannel(packet);
|
||||
if (eventChannel == null) {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
sendAllPackets(packet, p -> eventChannel.sendTo(p, player));
|
||||
}
|
||||
|
||||
public void sendToServer(AbstractPacket packet) {
|
||||
FMLEventChannel eventChannel = getEventChannel(packet);
|
||||
if (eventChannel == null) {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
sendAllPackets(packet, eventChannel::sendToServer);
|
||||
}
|
||||
|
||||
public void sendToAll(AbstractPacket packet) {
|
||||
FMLEventChannel eventChannel = getEventChannel(packet);
|
||||
if (eventChannel == null) {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
sendAllPackets(packet, eventChannel::sendToAll);
|
||||
}
|
||||
|
||||
public void sendToDimension(AbstractPacket packet, final int dimensionId) {
|
||||
FMLEventChannel eventChannel = getEventChannel(packet);
|
||||
if (eventChannel == null) {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
sendAllPackets(packet, p -> eventChannel.sendToDimension(p, dimensionId));
|
||||
}
|
||||
|
||||
public void sendTracking(AbstractPacket packet, final Entity entity) {
|
||||
FMLEventChannel eventChannel = getEventChannel(packet);
|
||||
if (eventChannel == null) {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
final NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 60);
|
||||
sendAllPackets(packet, p -> eventChannel.sendToAllAround(p, point));
|
||||
}
|
||||
|
||||
// Simple functional interface to unify the "send" action
|
||||
private interface SendAction {
|
||||
void send(FMLProxyPacket proxy);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package kamkeel.npcs.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PacketUtil {
|
||||
|
||||
public static boolean verifyItemPacket(EnumItemPacketType type, EntityPlayer player) {
|
||||
if (player == null)
|
||||
return false;
|
||||
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
if (item == null) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without an item, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case WAND:
|
||||
if (item.getItem() != CustomItems.wand) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Wand, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case MOUNTER:
|
||||
if (item.getItem() != CustomItems.mount) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Mounter, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case CLONER:
|
||||
if (item.getItem() != CustomItems.cloner) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Cloner, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case TELEPORTER:
|
||||
if (item.getItem() != CustomItems.teleporter) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Teleporter, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case SCRIPTER:
|
||||
if (item.getItem() != CustomItems.scripter) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Scripter, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case PATHER:
|
||||
if (item.getItem() != CustomItems.moving) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Pather, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BLOCK:
|
||||
if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint)
|
||||
|| item.getItem() == Item.getItemFromBlock(CustomItems.border)
|
||||
|| item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a valid Block, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BRUSH:
|
||||
if (item.getItem() != CustomItems.tool || item.getItemDamage() != 1) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Pather, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case HAMMER:
|
||||
if (item.getItem() != CustomItems.tool || item.getItemDamage() != 0) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Pather, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* New method that accepts multiple EnumItemPacketTypes.
|
||||
* It returns true if any one of the provided types is valid.
|
||||
* If none are valid, a merged error message is logged.
|
||||
*/
|
||||
public static boolean verifyItemPacket(EntityPlayer player, EnumItemPacketType... types) {
|
||||
if (player == null)
|
||||
return false;
|
||||
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
if (item == null) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a Packet without an item. Expected one of: %s, they could be a hacker",
|
||||
player.getCommandSenderName(), getExpectedItemNames(types)));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (EnumItemPacketType type : types) {
|
||||
if (isValidItemForType(item, type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// None passed; log one merged error message listing all expected items.
|
||||
LogWriter.error(String.format("%s attempted to utilize a Packet without a valid item. Expected one of: %s, they could be a hacker",
|
||||
player.getCommandSenderName(), getExpectedItemNames(types)));
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isValidItemForType(ItemStack item, EnumItemPacketType type) {
|
||||
if (item == null || item.getItem() == null)
|
||||
return false;
|
||||
|
||||
switch (type) {
|
||||
case WAND:
|
||||
return item.getItem() == CustomItems.wand;
|
||||
case MOUNTER:
|
||||
return item.getItem() == CustomItems.mount;
|
||||
case CLONER:
|
||||
return item.getItem() == CustomItems.cloner;
|
||||
case TELEPORTER:
|
||||
return item.getItem() == CustomItems.teleporter;
|
||||
case SCRIPTER:
|
||||
return item.getItem() == CustomItems.scripter;
|
||||
case PATHER:
|
||||
return item.getItem() == CustomItems.moving;
|
||||
case BLOCK:
|
||||
// For BLOCK, the item is valid as long as it is NOT one of these blocks.
|
||||
return !(item.getItem() == Item.getItemFromBlock(CustomItems.waypoint)
|
||||
|| item.getItem() == Item.getItemFromBlock(CustomItems.border)
|
||||
|| item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock));
|
||||
case BRUSH:
|
||||
return item.getItem() == CustomItems.tool && item.getItemDamage() == 1;
|
||||
case HAMMER:
|
||||
return item.getItem() == CustomItems.tool && item.getItemDamage() == 0;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a comma‐separated list of expected item names for the given types.
|
||||
*/
|
||||
private static String getExpectedItemNames(EnumItemPacketType... types) {
|
||||
Set<String> expectedNames = new LinkedHashSet<>();
|
||||
for (EnumItemPacketType type : types) {
|
||||
expectedNames.add(getExpectedItemName(type));
|
||||
}
|
||||
return String.join(", ", expectedNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected item name for the given EnumItemPacketType.
|
||||
*/
|
||||
private static String getExpectedItemName(EnumItemPacketType type) {
|
||||
switch (type) {
|
||||
case WAND:
|
||||
return "Wand";
|
||||
case MOUNTER:
|
||||
return "Mounter";
|
||||
case CLONER:
|
||||
return "Cloner";
|
||||
case TELEPORTER:
|
||||
return "Teleporter";
|
||||
case SCRIPTER:
|
||||
return "Scripter";
|
||||
case PATHER:
|
||||
return "Pather";
|
||||
case BLOCK:
|
||||
return "valid Block";
|
||||
case BRUSH:
|
||||
return "Paintbrush";
|
||||
case HAMMER:
|
||||
return "Hammer";
|
||||
default:
|
||||
return type.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void getScripts(IScriptHandler data, EntityPlayerMP player) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setBoolean("ScriptEnabled", data.getEnabled());
|
||||
compound.setString("ScriptLanguage", data.getLanguage());
|
||||
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
|
||||
compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(data.getConsoleText()));
|
||||
GuiDataPacket.sendGuiData(player, compound);
|
||||
List<ScriptContainer> containers = data.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
NBTTagCompound tabCompound = new NBTTagCompound();
|
||||
tabCompound.setInteger("Tab", i);
|
||||
tabCompound.setTag("Script", container.writeToNBT(new NBTTagCompound()));
|
||||
tabCompound.setInteger("TotalScripts", containers.size());
|
||||
GuiDataPacket.sendGuiData(player, tabCompound);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveScripts(IScriptHandler data, ByteBuf buffer) throws IOException {
|
||||
int tab = buffer.readInt();
|
||||
int totalScripts = buffer.readInt();
|
||||
if (totalScripts == 0) {
|
||||
data.getScripts().clear();
|
||||
}
|
||||
|
||||
if (tab >= 0) {
|
||||
if (data.getScripts().size() > totalScripts) {
|
||||
data.setScripts(data.getScripts().subList(0, totalScripts));
|
||||
} else while (data.getScripts().size() < totalScripts) {
|
||||
data.getScripts().add(new ScriptContainer(data));
|
||||
}
|
||||
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
|
||||
ScriptContainer script = new ScriptContainer(data);
|
||||
script.readFromNBT(tabCompound);
|
||||
data.getScripts().set(tab, script);
|
||||
} else {
|
||||
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
|
||||
data.setLanguage(compound.getString("ScriptLanguage"));
|
||||
if (!ScriptController.Instance.languages.containsKey(data.getLanguage())) {
|
||||
if (!ScriptController.Instance.languages.isEmpty()) {
|
||||
data.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
|
||||
} else {
|
||||
data.setLanguage("ECMAScript");
|
||||
}
|
||||
}
|
||||
data.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumChannelType {
|
||||
REQUEST,
|
||||
PLAYER,
|
||||
DATA,
|
||||
INFO
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumConfigOperation {
|
||||
FONT,
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
// Packets to the Client
|
||||
public enum EnumDataPacket {
|
||||
// Synchronization
|
||||
SYNC,
|
||||
SYNC_EFFECTS,
|
||||
CONFIG_COMMAND,
|
||||
|
||||
// Messages
|
||||
CHAT_ALERT,
|
||||
ACHIEVEMENT,
|
||||
CHATBUBBLE,
|
||||
SOUND,
|
||||
DIALOG,
|
||||
QUEST_COMPLETION,
|
||||
|
||||
|
||||
// NPC
|
||||
EDIT_NPC,
|
||||
UPDATE_NPC,
|
||||
ROLE_NPC,
|
||||
DELETE_NPC,
|
||||
CLONE_NPC,
|
||||
WEAPON_NPC,
|
||||
|
||||
// Data
|
||||
SCROLL_LIST,
|
||||
SCROLL_DATA,
|
||||
SCROLL_GROUP,
|
||||
SCROLL_SELECTED,
|
||||
PARTY_DATA,
|
||||
|
||||
// GUI
|
||||
GUI_OPEN,
|
||||
GUI_REDSTONE,
|
||||
GUI_WAYPOINT,
|
||||
GUI_TELEPORTER,
|
||||
GUI_BOOK,
|
||||
GUI_DATA,
|
||||
PLAYER_DATA,
|
||||
GUI_ERROR,
|
||||
GUI_CLOSE,
|
||||
ISGUIOPEN,
|
||||
|
||||
// Visual
|
||||
SCRIPTED_PARTICLE,
|
||||
PARTICLE,
|
||||
PLAYER_UPDATE_SKIN_OVERLAYS,
|
||||
UPDATE_ANIMATIONS,
|
||||
SCRIPT_OVERLAY_DATA,
|
||||
SCRIPT_OVERLAY_CLOSE,
|
||||
OVERLAY_QUEST_TRACKING,
|
||||
MARK_DATA,
|
||||
|
||||
// Other
|
||||
VILLAGER_LIST,
|
||||
SWING_PLAYER_ARM,
|
||||
DISABLE_MOUSE_INPUT,
|
||||
LOGIN,
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumItemPacketType {
|
||||
WAND,
|
||||
MOUNTER,
|
||||
CLONER,
|
||||
TELEPORTER,
|
||||
SCRIPTER,
|
||||
PATHER,
|
||||
BLOCK,
|
||||
BRUSH,
|
||||
HAMMER
|
||||
}
|
||||
Loaded 100 of 1481 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user