mirror of
https://github.com/essentials/Essentials.git
synced 2025-09-05 20:23:01 +02:00
Compare commits
448 Commits
stable-2.9
...
stable-2.1
Author | SHA1 | Date | |
---|---|---|---|
|
d522a4230f | ||
|
f17485b112 | ||
|
1f932434c2 | ||
|
92b0178ca7 | ||
|
d30c3ca2a6 | ||
|
fb60272439 | ||
|
80ad075f02 | ||
|
3f31dc179b | ||
|
5b975672e8 | ||
|
335d8b7f20 | ||
|
379e75f3e6 | ||
|
2ca171a3f4 | ||
|
8036cc9924 | ||
|
6442e793a9 | ||
|
d745b866c0 | ||
|
4493d7d00c | ||
|
631692d763 | ||
|
d0e3c1d946 | ||
|
82137e0703 | ||
|
a3b2ffdeef | ||
|
46fc6c192c | ||
|
6506c290c8 | ||
|
b1bc73f938 | ||
|
09851acd1b | ||
|
df42c9051b | ||
|
24c93c11c0 | ||
|
5a13e9bbe5 | ||
|
05f337c63c | ||
|
eea0c9682c | ||
|
2f567812d2 | ||
|
88c1b785af | ||
|
5225fb22f8 | ||
|
fae5780e09 | ||
|
7ec65bf213 | ||
|
d40484d016 | ||
|
971902ae38 | ||
|
844be04d75 | ||
|
ef01332114 | ||
|
705b193450 | ||
|
20b9111495 | ||
|
1661eddc02 | ||
|
15be319d3e | ||
|
fddbd7a52a | ||
|
360e3e8801 | ||
|
4edc39360a | ||
|
cd126264e0 | ||
|
df0ccb5832 | ||
|
8afcd41ab2 | ||
|
b8a71761ec | ||
|
738ded7ae5 | ||
|
5535435215 | ||
|
4167dd2590 | ||
|
623ff0f629 | ||
|
6e4ba4302f | ||
|
3d4d616414 | ||
|
d6c91d2d04 | ||
|
cef8cf7b75 | ||
|
12786a260e | ||
|
6ea956b11c | ||
|
132aa0cc1d | ||
|
b5733d6597 | ||
|
7fc4a75d4d | ||
|
e9e9efd2d7 | ||
|
9e4493fbb4 | ||
|
a64cb31211 | ||
|
57de3f3ed2 | ||
|
74b63a6f2d | ||
|
faad91849d | ||
|
ce7d83adb6 | ||
|
76d1ea5cab | ||
|
9fb42375b8 | ||
|
2a7f3c6525 | ||
|
c65353350f | ||
|
1ae58d05b4 | ||
|
4f35a72174 | ||
|
addd55228b | ||
|
bb29d48268 | ||
|
d9ee9b036c | ||
|
95e630de92 | ||
|
2836c0862d | ||
|
286091cd32 | ||
|
20786654a4 | ||
|
8fde5102b9 | ||
|
133fdac343 | ||
|
2361b9e724 | ||
|
972d831d0d | ||
|
bfa34130a0 | ||
|
befe1fb39e | ||
|
378eaaaf1f | ||
|
51a55318d0 | ||
|
4663c89dd6 | ||
|
2a1c3fb8e0 | ||
|
0ac1a90b93 | ||
|
ab6b3bff90 | ||
|
2d00fd0c1e | ||
|
e5f4cb9a4d | ||
|
91701e8c2f | ||
|
9cef107bc3 | ||
|
76fd829e8c | ||
|
6ea422015c | ||
|
443a317184 | ||
|
50dca9abf5 | ||
|
f1e3d48248 | ||
|
63ce4a99b9 | ||
|
1ccda52e9f | ||
|
1679790157 | ||
|
6170540a24 | ||
|
987b2ff4d5 | ||
|
23a15cb11a | ||
|
41547e3243 | ||
|
a586edfd0b | ||
|
762bb65677 | ||
|
73c92bf742 | ||
|
2b8435342d | ||
|
9566499a2f | ||
|
343c3a1bdd | ||
|
9aeb49f6c3 | ||
|
7dae04759f | ||
|
e2f6e5a7fd | ||
|
d26fa6c5b8 | ||
|
82f9505a2e | ||
|
f8ce80c18a | ||
|
313fd30ce9 | ||
|
da216b05d9 | ||
|
d8132548f6 | ||
|
6fdeddd96b | ||
|
8082508db9 | ||
|
78e6da9504 | ||
|
0014d5cfcb | ||
|
6aeba173b9 | ||
|
a2813358af | ||
|
8e663b53ce | ||
|
214d9414da | ||
|
6d7881f876 | ||
|
19ccdf2193 | ||
|
35036ecc18 | ||
|
b3cc4dbe09 | ||
|
04bd9e8baf | ||
|
fdc262a205 | ||
|
32ea86bfd3 | ||
|
4807fb39e5 | ||
|
4ffe61a505 | ||
|
d74952927a | ||
|
f8cf3be87f | ||
|
ada266a0f9 | ||
|
115c4fa1d0 | ||
|
0c19b2feed | ||
|
04c833f648 | ||
|
4533d09fc9 | ||
|
7337b86a16 | ||
|
3db015b1c1 | ||
|
659d602b57 | ||
|
f82d7e806f | ||
|
a8088fb8c8 | ||
|
84c06fb746 | ||
|
ffe2a283d2 | ||
|
7e3fd48956 | ||
|
bd22aec38a | ||
|
675c4b7897 | ||
|
ad7009c77e | ||
|
3f783bb43b | ||
|
9fe7712bd6 | ||
|
24f56892ad | ||
|
b860e943f6 | ||
|
5dc2665377 | ||
|
dd9b7e0d3c | ||
|
18a15ca63c | ||
|
ef1492a2a2 | ||
|
298ab846c1 | ||
|
7fdb2ad7d3 | ||
|
3afe8d18f4 | ||
|
0b581580c7 | ||
|
01e78cd666 | ||
|
29d28456aa | ||
|
f3812786d0 | ||
|
999d922fb9 | ||
|
2d4a07b95b | ||
|
5c99eee0c0 | ||
|
1fc502a4ff | ||
|
e73983649f | ||
|
465cdae989 | ||
|
341cb89bb7 | ||
|
79004c7098 | ||
|
2988db08ca | ||
|
b04fa82be2 | ||
|
5d210d81dc | ||
|
c14b32123f | ||
|
f256930269 | ||
|
cde95d832e | ||
|
b9af4fb35c | ||
|
5056210a38 | ||
|
eacb847305 | ||
|
27ff43c0ac | ||
|
368c33a843 | ||
|
c210e8730b | ||
|
6c48e02c14 | ||
|
c54d68a660 | ||
|
33d3123104 | ||
|
df0b1cedd8 | ||
|
2b57381fb8 | ||
|
67b9a82e51 | ||
|
c4e10da646 | ||
|
fbb1c1278c | ||
|
9b49c5e0f4 | ||
|
186d4e2fd1 | ||
|
437b01e371 | ||
|
3bf36fecf9 | ||
|
c57332be63 | ||
|
292fb0cea1 | ||
|
3c4388f8be | ||
|
f930ff48a2 | ||
|
ef7b940e96 | ||
|
6497db837d | ||
|
87cb6190eb | ||
|
74c4c604da | ||
|
0937a35470 | ||
|
121f09caf0 | ||
|
ef8bd3422a | ||
|
2232d859fd | ||
|
0258abee29 | ||
|
9b8991788b | ||
|
9a91c99391 | ||
|
c6dd921f0c | ||
|
63e622374d | ||
|
ca25c71010 | ||
|
b5e559ff66 | ||
|
555bb76428 | ||
|
f210f8e20b | ||
|
e572e7c94c | ||
|
5c9d3c6b1a | ||
|
ccfc23d629 | ||
|
b5dd0fc671 | ||
|
8e3ee8576e | ||
|
4cec7fe5c1 | ||
|
6c3b2076ff | ||
|
cbc1aeacbe | ||
|
a1b2773bf5 | ||
|
9ecb501e00 | ||
|
3dcdad2233 | ||
|
3725a5e6d4 | ||
|
ed88f8aa06 | ||
|
d551e8c6d2 | ||
|
69ad186839 | ||
|
fc89867e4a | ||
|
bbb478c51f | ||
|
03445e5b9b | ||
|
0755fbf089 | ||
|
3a789bdcfe | ||
|
93db8bc7c1 | ||
|
62832ad43a | ||
|
52b104aca5 | ||
|
1f98fe710f | ||
|
a73986a358 | ||
|
257165584e | ||
|
8e92150cb7 | ||
|
4bb275e1b7 | ||
|
e5fc579071 | ||
|
26306f6fa3 | ||
|
0bfb079cbb | ||
|
6b18259af6 | ||
|
99c750d18b | ||
|
bb64fa468a | ||
|
66db3c6cfb | ||
|
c97763c3c8 | ||
|
ad3e8a3aba | ||
|
617959a11b | ||
|
a480091617 | ||
|
13a847e0ab | ||
|
a8a8b52977 | ||
|
226a75472c | ||
|
a1c88a140e | ||
|
2c3218b056 | ||
|
27db9e8c3b | ||
|
cf0e36c973 | ||
|
1218a0b217 | ||
|
adb75b69c2 | ||
|
010df964a1 | ||
|
0e2e8e16af | ||
|
6f28540d59 | ||
|
ce78125028 | ||
|
10b972bd07 | ||
|
371a6437ae | ||
|
78666ade2b | ||
|
8f00aa5542 | ||
|
b2d68fe213 | ||
|
a6c13974c4 | ||
|
fb0cd8fbf0 | ||
|
01d1ae442e | ||
|
dc13f46ff1 | ||
|
f125ac3b4a | ||
|
be29a373ab | ||
|
b28db7e435 | ||
|
3ac6cc11e3 | ||
|
9097bef728 | ||
|
68e401821f | ||
|
7f9a52c3f7 | ||
|
79671d08e4 | ||
|
d01d6bcd1b | ||
|
79a44b919c | ||
|
477e1a4f58 | ||
|
c028c385b6 | ||
|
f9bcc3100c | ||
|
3ea3d18922 | ||
|
3faedec602 | ||
|
2a88a314ce | ||
|
38293560d7 | ||
|
f57b3595ed | ||
|
e2e6bb3876 | ||
|
4e399778b4 | ||
|
9ba5f43315 | ||
|
0bde364125 | ||
|
87f5ec491e | ||
|
1f8a0a811f | ||
|
74d5590d3b | ||
|
258fbdb0e8 | ||
|
bd4a48c441 | ||
|
00bd6a3e02 | ||
|
28ad7b96d2 | ||
|
97204c0e8c | ||
|
46645cb39f | ||
|
dfd6fc78f0 | ||
|
ecf5d47e97 | ||
|
77df82eaff | ||
|
020f2c3ea5 | ||
|
5a855eede5 | ||
|
8b4273cbd1 | ||
|
30bc597851 | ||
|
13efadbb65 | ||
|
6bc3d7f0f4 | ||
|
e706614a3b | ||
|
cf68031110 | ||
|
5741cea3f5 | ||
|
7b879331db | ||
|
0a27a631e3 | ||
|
d8c6587532 | ||
|
d600f160fe | ||
|
d23c324035 | ||
|
52bfeff5b4 | ||
|
3dcb2a828e | ||
|
0b95a691a6 | ||
|
eba2bad113 | ||
|
4f21490ec8 | ||
|
f7daa20be8 | ||
|
a9ace1163f | ||
|
ba380e61ee | ||
|
bbc306970f | ||
|
7b997634ef | ||
|
1efbc3856c | ||
|
f769f96f74 | ||
|
3f69473072 | ||
|
d7bcf6508d | ||
|
61c4d8cb5e | ||
|
f7361eed98 | ||
|
deaa72b05d | ||
|
92bdd51cd4 | ||
|
0ed29c029d | ||
|
61903355cd | ||
|
889f60e58e | ||
|
c4f292f4ef | ||
|
36687e2659 | ||
|
948647926d | ||
|
4a4f443fee | ||
|
18d52821b7 | ||
|
ad7d751856 | ||
|
1151f1a29c | ||
|
0b1625f4c1 | ||
|
1363406b84 | ||
|
4b875ed4d9 | ||
|
42872650d2 | ||
|
fd87933aa9 | ||
|
269cf85457 | ||
|
5728f964a5 | ||
|
a7aa8be37a | ||
|
237c896fff | ||
|
fbb3d7344f | ||
|
8b660d32ac | ||
|
98bccf6cec | ||
|
936606ce7c | ||
|
a63748ca3a | ||
|
a1ce340ce0 | ||
|
a8df79661a | ||
|
f52e0ae7a8 | ||
|
648a5ef8dd | ||
|
0d610f761b | ||
|
e7afe4109e | ||
|
b11a1a7cf2 | ||
|
6a8a2dd28b | ||
|
a370a8e01c | ||
|
5e38a2180c | ||
|
f3bc94a547 | ||
|
ba0db53c44 | ||
|
ef98a6b54c | ||
|
8c9b755671 | ||
|
6c1da1d552 | ||
|
0df0be5762 | ||
|
83120f707f | ||
|
9d98edb4ee | ||
|
a50b0ac71d | ||
|
d674e65c11 | ||
|
4967279b8c | ||
|
4722e687fa | ||
|
332a59f3fc | ||
|
587f532991 | ||
|
10244d5f90 | ||
|
6f1a70dc8b | ||
|
7369155166 | ||
|
28d4609c8c | ||
|
d2966b64eb | ||
|
c8f8680ce9 | ||
|
9fcb412774 | ||
|
296af1069e | ||
|
b22e97b3cf | ||
|
dcf90cbf5a | ||
|
4dc2e2e3fd | ||
|
4d4779ecdc | ||
|
1c25d317dd | ||
|
651a62890a | ||
|
39b38f0619 | ||
|
4a194e8758 | ||
|
5a35da53a0 | ||
|
bea3583192 | ||
|
618d115233 | ||
|
5e476f4d61 | ||
|
5bc1b8df70 | ||
|
72e0ab2cb2 | ||
|
e0d189a5e0 | ||
|
91c193b773 | ||
|
4a18130354 | ||
|
7c6268fe20 | ||
|
6f213c23e2 | ||
|
cc606fe1aa | ||
|
ee8638841d | ||
|
9864a75c32 | ||
|
520427239f | ||
|
614a229ea7 | ||
|
2a4d40020e | ||
|
d6efae202a | ||
|
7b9c711486 | ||
|
e2bd22d984 | ||
|
2310b41b21 | ||
|
2ae9c577db | ||
|
7c9375ce2e | ||
|
9addc2ccd5 | ||
|
e180f6e6b3 | ||
|
2ea453110a | ||
|
a86efb5ebe | ||
|
cd0fde05b7 | ||
|
778f5649c8 |
@@ -12,9 +12,9 @@ is divided into following sections:
|
||||
- execution
|
||||
- debugging
|
||||
- javadoc
|
||||
- junit compilation
|
||||
- junit execution
|
||||
- junit debugging
|
||||
- test compilation
|
||||
- test execution
|
||||
- test debugging
|
||||
- applet
|
||||
- cleanup
|
||||
|
||||
@@ -181,6 +181,7 @@ is divided into following sections:
|
||||
</and>
|
||||
</condition>
|
||||
<property name="run.jvmargs" value=""/>
|
||||
<property name="run.jvmargs.ide" value=""/>
|
||||
<property name="javac.compilerargs" value=""/>
|
||||
<property name="work.dir" value="${basedir}"/>
|
||||
<condition property="no.deps">
|
||||
@@ -225,6 +226,27 @@ is divided into following sections:
|
||||
<property name="jar.index.metainf" value="${jar.index}"/>
|
||||
<property name="copylibs.rebase" value="true"/>
|
||||
<available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/>
|
||||
<condition property="junit.available">
|
||||
<or>
|
||||
<available classname="org.junit.Test" classpath="${run.test.classpath}"/>
|
||||
<available classname="junit.framework.Test" classpath="${run.test.classpath}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="testng.available">
|
||||
<available classname="org.testng.annotations.Test" classpath="${run.test.classpath}"/>
|
||||
</condition>
|
||||
<condition property="junit+testng.available">
|
||||
<and>
|
||||
<istrue value="${junit.available}"/>
|
||||
<istrue value="${testng.available}"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition else="testng" property="testng.mode" value="mixed">
|
||||
<istrue value="${junit+testng.available}"/>
|
||||
</condition>
|
||||
<condition else="" property="testng.debug.mode" value="-mixed">
|
||||
<istrue value="${junit+testng.available}"/>
|
||||
</condition>
|
||||
</target>
|
||||
<target name="-post-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
@@ -357,11 +379,52 @@ is divided into following sections:
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-junit">
|
||||
<target if="${junit.available}" name="-init-macrodef-junit-init">
|
||||
<condition else="false" property="nb.junit.batch" value="true">
|
||||
<and>
|
||||
<istrue value="${junit.available}"/>
|
||||
<not>
|
||||
<isset property="test.method"/>
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition else="false" property="nb.junit.single" value="true">
|
||||
<and>
|
||||
<istrue value="${junit.available}"/>
|
||||
<isset property="test.method"/>
|
||||
</and>
|
||||
</condition>
|
||||
</target>
|
||||
<target if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}">
|
||||
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<property name="junit.forkmode" value="perTest"/>
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
||||
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
</syspropertyset>
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<formatter type="xml"/>
|
||||
<jvmarg value="-ea"/>
|
||||
<customize/>
|
||||
</junit>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}">
|
||||
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<property name="junit.forkmode" value="perTest"/>
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
||||
@@ -370,32 +433,270 @@ is divided into following sections:
|
||||
<filename name="@{testincludes}"/>
|
||||
</fileset>
|
||||
</batchtest>
|
||||
<classpath>
|
||||
<path path="${run.test.classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
</syspropertyset>
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<formatter type="xml"/>
|
||||
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
|
||||
<jvmarg value="-ea"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<customize/>
|
||||
</junit>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" name="profile-init"/>
|
||||
<target name="-profile-pre-init">
|
||||
<target depends="-init-macrodef-junit-init,-init-macrodef-junit-single, -init-macrodef-junit-batch" if="${junit.available}" name="-init-macrodef-junit"/>
|
||||
<target if="${testng.available}" name="-init-macrodef-testng">
|
||||
<macrodef name="testng" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}">
|
||||
<isset property="test.method"/>
|
||||
</condition>
|
||||
<union id="test.set">
|
||||
<fileset dir="${test.src.dir}" excludes="@{excludes},**/*.xml,${excludes}" includes="@{includes}">
|
||||
<filename name="@{testincludes}"/>
|
||||
</fileset>
|
||||
</union>
|
||||
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
|
||||
<testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="BuildAll" testname="TestNG tests" workingDir="${work.dir}">
|
||||
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
||||
<propertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
</propertyset>
|
||||
<customize/>
|
||||
</testng>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-test-impl">
|
||||
<macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<element implicit="true" name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<echo>No tests executed.</echo>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-init-macrodef-junit" if="${junit.available}" name="-init-macrodef-junit-impl">
|
||||
<macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<element implicit="true" name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<j2seproject3:junit excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
|
||||
<customize/>
|
||||
</j2seproject3:junit>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-init-macrodef-testng" if="${testng.available}" name="-init-macrodef-testng-impl">
|
||||
<macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<element implicit="true" name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<j2seproject3:testng excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
|
||||
<customize/>
|
||||
</j2seproject3:testng>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-init-macrodef-test-impl,-init-macrodef-junit-impl,-init-macrodef-testng-impl" name="-init-macrodef-test">
|
||||
<macrodef name="test" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<sequential>
|
||||
<j2seproject3:test-impl excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
|
||||
<customize>
|
||||
<classpath>
|
||||
<path path="${run.test.classpath}"/>
|
||||
</classpath>
|
||||
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<jvmarg line="${run.jvmargs.ide}"/>
|
||||
</customize>
|
||||
</j2seproject3:test-impl>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target if="${junit.available}" name="-init-macrodef-junit-debug" unless="${nb.junit.batch}">
|
||||
<macrodef name="junit-debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<property name="junit.forkmode" value="perTest"/>
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
||||
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
</syspropertyset>
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<formatter type="xml"/>
|
||||
<jvmarg value="-ea"/>
|
||||
<jvmarg line="${debug-args-line}"/>
|
||||
<jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
|
||||
<customize/>
|
||||
</junit>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target if="${nb.junit.batch}" name="-init-macrodef-junit-debug-batch">
|
||||
<macrodef name="junit-debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<property name="junit.forkmode" value="perTest"/>
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
||||
<batchtest todir="${build.test.results.dir}">
|
||||
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
|
||||
<filename name="@{testincludes}"/>
|
||||
</fileset>
|
||||
</batchtest>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
</syspropertyset>
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<formatter type="xml"/>
|
||||
<jvmarg value="-ea"/>
|
||||
<jvmarg line="${debug-args-line}"/>
|
||||
<jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
|
||||
<customize/>
|
||||
</junit>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-init-macrodef-junit-debug,-init-macrodef-junit-debug-batch" if="${junit.available}" name="-init-macrodef-junit-debug-impl">
|
||||
<macrodef name="test-debug-impl" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<element implicit="true" name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<j2seproject3:junit-debug excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
|
||||
<customize/>
|
||||
</j2seproject3:junit-debug>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target if="${testng.available}" name="-init-macrodef-testng-debug">
|
||||
<macrodef name="testng-debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${main.class}" name="testClass"/>
|
||||
<attribute default="" name="testMethod"/>
|
||||
<element name="customize2" optional="true"/>
|
||||
<sequential>
|
||||
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
|
||||
<isset property="test.method"/>
|
||||
</condition>
|
||||
<condition else="-suitename BuildAll -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
|
||||
<matches pattern=".*\.xml" string="@{testClass}"/>
|
||||
</condition>
|
||||
<delete dir="${build.test.results.dir}" quiet="true"/>
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
<j2seproject3:debug classname="org.testng.TestNG" classpath="${debug.test.classpath}">
|
||||
<customize>
|
||||
<customize2/>
|
||||
<jvmarg value="-ea"/>
|
||||
<arg line="${testng.debug.mode}"/>
|
||||
<arg line="-d ${build.test.results.dir}"/>
|
||||
<arg line="-listener org.testng.reporters.VerboseReporter"/>
|
||||
<arg line="${testng.cmd.args}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-init-macrodef-testng-debug" if="${testng.available}" name="-init-macrodef-testng-debug-impl">
|
||||
<macrodef name="testng-debug-impl" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${main.class}" name="testClass"/>
|
||||
<attribute default="" name="testMethod"/>
|
||||
<element implicit="true" name="customize2" optional="true"/>
|
||||
<sequential>
|
||||
<j2seproject3:testng-debug testClass="@{testClass}" testMethod="@{testMethod}">
|
||||
<customize2/>
|
||||
</j2seproject3:testng-debug>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-init-macrodef-junit-debug-impl" if="${junit.available}" name="-init-macrodef-test-debug-junit">
|
||||
<macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<attribute default="${main.class}" name="testClass"/>
|
||||
<attribute default="" name="testMethod"/>
|
||||
<sequential>
|
||||
<j2seproject3:test-debug-impl excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
|
||||
<customize>
|
||||
<classpath>
|
||||
<path path="${run.test.classpath}"/>
|
||||
</classpath>
|
||||
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<jvmarg line="${run.jvmargs.ide}"/>
|
||||
</customize>
|
||||
</j2seproject3:test-debug-impl>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-init-macrodef-testng-debug-impl" if="${testng.available}" name="-init-macrodef-test-debug-testng">
|
||||
<macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute default="${includes}" name="includes"/>
|
||||
<attribute default="${excludes}" name="excludes"/>
|
||||
<attribute default="**" name="testincludes"/>
|
||||
<attribute default="" name="testmethods"/>
|
||||
<attribute default="${main.class}" name="testClass"/>
|
||||
<attribute default="" name="testMethod"/>
|
||||
<sequential>
|
||||
<j2seproject3:testng-debug-impl testClass="@{testClass}" testMethod="@{testMethod}">
|
||||
<customize2>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
</syspropertyset>
|
||||
</customize2>
|
||||
</j2seproject3:testng-debug-impl>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-init-macrodef-test-debug-junit,-init-macrodef-test-debug-testng" name="-init-macrodef-test-debug"/>
|
||||
<!--
|
||||
pre NB7.2 profiling section; consider it deprecated
|
||||
-->
|
||||
<target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" if="profiler.info.jvmargs.agent" name="profile-init"/>
|
||||
<target if="profiler.info.jvmargs.agent" name="-profile-pre-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-profile-post-init">
|
||||
<target if="profiler.info.jvmargs.agent" name="-profile-post-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-profile-init-macrodef-profile">
|
||||
<target if="profiler.info.jvmargs.agent" name="-profile-init-macrodef-profile">
|
||||
<macrodef name="resolve">
|
||||
<attribute name="name"/>
|
||||
<attribute name="value"/>
|
||||
@@ -427,10 +728,13 @@ is divided into following sections:
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile" name="-profile-init-check">
|
||||
<target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile" if="profiler.info.jvmargs.agent" name="-profile-init-check">
|
||||
<fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
|
||||
<fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
|
||||
</target>
|
||||
<!--
|
||||
end of pre NB7.2 profiling section
|
||||
-->
|
||||
<target depends="-init-debug-args" name="-init-macrodef-nbjpda">
|
||||
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute default="${main.class}" name="name"/>
|
||||
@@ -488,6 +792,7 @@ is divided into following sections:
|
||||
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
|
||||
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<jvmarg line="${run.jvmargs.ide}"/>
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
@@ -504,6 +809,7 @@ is divided into following sections:
|
||||
<macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute default="${main.class}" name="classname"/>
|
||||
<attribute default="${run.classpath}" name="classpath"/>
|
||||
<attribute default="jvm" name="jvm"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java classname="@{classname}" dir="${work.dir}" fork="true">
|
||||
@@ -511,6 +817,7 @@ is divided into following sections:
|
||||
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
|
||||
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<jvmarg line="${run.jvmargs.ide}"/>
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
@@ -537,6 +844,9 @@ is divided into following sections:
|
||||
<path path="${run.classpath.without.build.classes.dir}"/>
|
||||
<chainedmapper>
|
||||
<flattenmapper/>
|
||||
<filtermapper>
|
||||
<replacestring from=" " to="%20"/>
|
||||
</filtermapper>
|
||||
<globmapper from="*" to="lib/*"/>
|
||||
</chainedmapper>
|
||||
</pathconvert>
|
||||
@@ -582,7 +892,7 @@ is divided into following sections:
|
||||
<target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline">
|
||||
<property name="ap.cmd.line.internal" value=""/>
|
||||
</target>
|
||||
<target depends="-pre-init,-init-private,-init-libraries,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/>
|
||||
<target depends="-pre-init,-init-private,-init-libraries,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-test,-init-macrodef-test-debug,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/>
|
||||
<!--
|
||||
===================
|
||||
COMPILATION SECTION
|
||||
@@ -861,7 +1171,11 @@ is divided into following sections:
|
||||
PROFILING SECTION
|
||||
=================
|
||||
-->
|
||||
<target depends="profile-init,compile" description="Profile a project in the IDE." if="netbeans.home" name="profile">
|
||||
<!--
|
||||
pre NB7.2 profiler integration
|
||||
-->
|
||||
<target depends="profile-init,compile" description="Profile a project in the IDE." if="profiler.info.jvmargs.agent" name="-profile-pre72">
|
||||
<fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
|
||||
<nbprofiledirect>
|
||||
<classpath>
|
||||
<path path="${run.classpath}"/>
|
||||
@@ -869,8 +1183,9 @@ is divided into following sections:
|
||||
</nbprofiledirect>
|
||||
<profile/>
|
||||
</target>
|
||||
<target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="netbeans.home" name="profile-single">
|
||||
<target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="profiler.info.jvmargs.agent" name="-profile-single-pre72">
|
||||
<fail unless="profile.class">Must select one file in the IDE or set profile.class</fail>
|
||||
<fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
|
||||
<nbprofiledirect>
|
||||
<classpath>
|
||||
<path path="${run.classpath}"/>
|
||||
@@ -878,12 +1193,8 @@ is divided into following sections:
|
||||
</nbprofiledirect>
|
||||
<profile classname="${profile.class}"/>
|
||||
</target>
|
||||
<!--
|
||||
=========================
|
||||
APPLET PROFILING SECTION
|
||||
=========================
|
||||
-->
|
||||
<target depends="profile-init,compile-single" if="netbeans.home" name="profile-applet">
|
||||
<target depends="profile-init,compile-single" if="profiler.info.jvmargs.agent" name="-profile-applet-pre72">
|
||||
<fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
|
||||
<nbprofiledirect>
|
||||
<classpath>
|
||||
<path path="${run.classpath}"/>
|
||||
@@ -895,12 +1206,8 @@ is divided into following sections:
|
||||
</customize>
|
||||
</profile>
|
||||
</target>
|
||||
<!--
|
||||
=========================
|
||||
TESTS PROFILING SECTION
|
||||
=========================
|
||||
-->
|
||||
<target depends="profile-init,compile-test-single" if="netbeans.home" name="profile-test-single">
|
||||
<target depends="profile-init,compile-test-single" if="profiler.info.jvmargs.agent" name="-profile-test-single-pre72">
|
||||
<fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
|
||||
<nbprofiledirect>
|
||||
<classpath>
|
||||
<path path="${run.test.classpath}"/>
|
||||
@@ -922,6 +1229,42 @@ is divided into following sections:
|
||||
<formatter type="xml"/>
|
||||
</junit>
|
||||
</target>
|
||||
<!--
|
||||
end of pre NB72 profiling section
|
||||
-->
|
||||
<target if="netbeans.home" name="-profile-check">
|
||||
<condition property="profiler.configured">
|
||||
<or>
|
||||
<contains casesensitive="true" string="${run.jvmargs.ide}" substring="-agentpath:"/>
|
||||
<contains casesensitive="true" string="${run.jvmargs.ide}" substring="-javaagent:"/>
|
||||
</or>
|
||||
</condition>
|
||||
</target>
|
||||
<target depends="-profile-check,-profile-pre72" description="Profile a project in the IDE." if="profiler.configured" name="profile" unless="profiler.info.jvmargs.agent">
|
||||
<startprofiler/>
|
||||
<antcall target="run"/>
|
||||
</target>
|
||||
<target depends="-profile-check,-profile-single-pre72" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-single" unless="profiler.info.jvmargs.agent">
|
||||
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
|
||||
<startprofiler/>
|
||||
<antcall target="run-single"/>
|
||||
</target>
|
||||
<target depends="-profile-test-single-pre72" description="Profile a selected test in the IDE." name="profile-test-single"/>
|
||||
<target depends="-profile-check" description="Profile a selected test in the IDE." if="profiler.configured" name="profile-test" unless="profiler.info.jvmargs">
|
||||
<fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
|
||||
<startprofiler/>
|
||||
<antcall target="test-single"/>
|
||||
</target>
|
||||
<target depends="-profile-check" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-test-with-main">
|
||||
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
|
||||
<startprofiler/>
|
||||
<antcal target="run-test-with-main"/>
|
||||
</target>
|
||||
<target depends="-profile-check,-profile-applet-pre72" if="profiler.configured" name="profile-applet" unless="profiler.info.jvmargs.agent">
|
||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||
<startprofiler/>
|
||||
<antcall target="run-applet"/>
|
||||
</target>
|
||||
<!--
|
||||
===============
|
||||
JAVADOC SECTION
|
||||
@@ -965,7 +1308,7 @@ is divided into following sections:
|
||||
<target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
|
||||
<!--
|
||||
=========================
|
||||
JUNIT COMPILATION SECTION
|
||||
TEST COMPILATION SECTION
|
||||
=========================
|
||||
-->
|
||||
<target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
|
||||
@@ -1008,14 +1351,14 @@ is divided into following sections:
|
||||
<target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT EXECUTION SECTION
|
||||
TEST EXECUTION SECTION
|
||||
=======================
|
||||
-->
|
||||
<target depends="init" if="have.tests" name="-pre-test-run">
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
</target>
|
||||
<target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
|
||||
<j2seproject3:junit testincludes="**/*Test.java"/>
|
||||
<j2seproject3:test testincludes="**/*Test.java"/>
|
||||
</target>
|
||||
<target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
|
||||
<fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
|
||||
@@ -1028,39 +1371,40 @@ is divided into following sections:
|
||||
</target>
|
||||
<target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
|
||||
<fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
|
||||
<j2seproject3:junit excludes="" includes="${test.includes}"/>
|
||||
<j2seproject3:test excludes="" includes="${test.includes}" testincludes="${test.includes}"/>
|
||||
</target>
|
||||
<target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
|
||||
<fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
|
||||
<target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single-method">
|
||||
<fail unless="test.class">Must select some files in the IDE or set test.class</fail>
|
||||
<fail unless="test.method">Must select some method in the IDE or set test.method</fail>
|
||||
<j2seproject3:test excludes="" includes="${javac.includes}" testincludes="${test.class}" testmethods="${test.method}"/>
|
||||
</target>
|
||||
<target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single-method" if="have.tests" name="-post-test-run-single-method">
|
||||
<fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single-method,-post-test-run-single-method" description="Run single unit test." name="test-single-method"/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT DEBUGGING SECTION
|
||||
TEST DEBUGGING SECTION
|
||||
=======================
|
||||
-->
|
||||
<target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
|
||||
<target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test">
|
||||
<fail unless="test.class">Must select one file in the IDE or set test.class</fail>
|
||||
<property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
|
||||
<delete file="${test.report.file}"/>
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
<j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
|
||||
<customize>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
</syspropertyset>
|
||||
<arg value="${test.class}"/>
|
||||
<arg value="showoutput=true"/>
|
||||
<arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
|
||||
<arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
<j2seproject3:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testincludes="${javac.includes}"/>
|
||||
</target>
|
||||
<target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test-method">
|
||||
<fail unless="test.class">Must select one file in the IDE or set test.class</fail>
|
||||
<fail unless="test.method">Must select some method in the IDE or set test.method</fail>
|
||||
<j2seproject3:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testMethod="${test.method}" testincludes="${test.class}" testmethods="${test.method}"/>
|
||||
</target>
|
||||
<target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
|
||||
<j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
|
||||
</target>
|
||||
<target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
|
||||
<target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test-method" name="debug-test-method"/>
|
||||
<target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
|
||||
<j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
@@ -1188,9 +1532,12 @@ is divided into following sections:
|
||||
<target name="-check-call-dep">
|
||||
<property file="${call.built.properties}" prefix="already.built."/>
|
||||
<condition property="should.call.dep">
|
||||
<not>
|
||||
<isset property="already.built.${call.subproject}"/>
|
||||
</not>
|
||||
<and>
|
||||
<not>
|
||||
<isset property="already.built.${call.subproject}"/>
|
||||
</not>
|
||||
<available file="${call.script}"/>
|
||||
</and>
|
||||
</condition>
|
||||
</target>
|
||||
<target depends="-check-call-dep" if="should.call.dep" name="-maybe-call-dep">
|
||||
|
@@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.50.3.46
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=b4df970c
|
||||
nbproject/build-impl.xml.script.CRC32=1fd6d3cc
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.3.46
|
||||
nbproject/build-impl.xml.script.CRC32=8905537e
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46
|
||||
|
@@ -68,7 +68,6 @@ file.reference.BOSEconomy7.jar=../lib/BOSEconomy7.jar
|
||||
file.reference.bPermissions.jar=../lib/bPermissions.jar
|
||||
file.reference.bpermissions2.jar=../lib/bpermissions2.jar
|
||||
file.reference.bukkit.jar=../lib/bukkit.jar
|
||||
file.reference.craftbukkit.jar=../lib/craftbukkit.jar
|
||||
file.reference.iCo4.jar=../lib/iCo4.jar
|
||||
file.reference.iCo5.jar=../lib/iCo5.jar
|
||||
file.reference.iCo6.jar=../lib/iCo6.jar
|
||||
@@ -79,6 +78,7 @@ file.reference.PermissionsBukkit-1.2.jar=../lib/PermissionsBukkit-1.2.jar
|
||||
file.reference.PermissionsEx.jar=../lib/PermissionsEx.jar
|
||||
file.reference.Privileges.jar=..\\lib\\Privileges.jar
|
||||
file.reference.Vault.jar=../lib/Vault.jar
|
||||
file.reference.SimplyPerms.jar=../lib/SimplyPerms.jar
|
||||
includes=**
|
||||
jar.archive.disabled=${jnlp.enabled}
|
||||
jar.compress=true
|
||||
@@ -96,12 +96,12 @@ javac.classpath=\
|
||||
${file.reference.lombok.jar}:\
|
||||
${reference.EssentialsGroupManager.jar}:\
|
||||
${file.reference.bukkit.jar}:\
|
||||
${file.reference.craftbukkit.jar}:\
|
||||
${file.reference.Vault.jar}:\
|
||||
${file.reference.Privileges.jar}:\
|
||||
${file.reference.bpermissions2.jar}
|
||||
${file.reference.bpermissions2.jar}:\
|
||||
${file.reference.SimplyPerms.jar}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.compilerargs=-Xlint:unchecked
|
||||
javac.deprecation=false
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
|
18
Essentials/src/book.txt
Normal file
18
Essentials/src/book.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
This is the book file.
|
||||
|
||||
This file format works similar to the info.txt, motd.txt and rules.txt
|
||||
|
||||
Place content in here that you would like to be used by books ingame.
|
||||
|
||||
You can use this content by using the book:<section> meta option in kits or item spawning.
|
||||
|
||||
#Colors
|
||||
Minecraft colors:
|
||||
&0 &&0 &1 &&1 &2 &&2 &3 &&3
|
||||
&4 &&4 &5 &&5 &6 &&6 &7 &&7
|
||||
&8 &&8 &9 &&9 &a &&a &b &&b
|
||||
&c &&c &d &&d &e &&e &f &&f
|
||||
&0
|
||||
&&k &kMagic&r &&l &lBold
|
||||
&&m &mStrike&r &&n &nUline
|
||||
&&o &oItalic&r &&r &rReset
|
@@ -121,13 +121,14 @@ public class AlternativeCommandsHandler
|
||||
return commands.get(0);
|
||||
}
|
||||
|
||||
public void executed(final String label, final String otherLabel)
|
||||
public void executed(final String label, final PluginCommand pc)
|
||||
{
|
||||
final String altString = pc.getPlugin().getName() + ":" + pc.getLabel();
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + otherLabel);
|
||||
LOGGER.log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString);
|
||||
}
|
||||
disabledList.put(label, otherLabel);
|
||||
disabledList.put(label, altString);
|
||||
}
|
||||
|
||||
public Map<String, String> disabledCommands()
|
||||
|
@@ -72,7 +72,7 @@ public class Backup implements Runnable
|
||||
server.dispatchCommand(cs, "save-all");
|
||||
server.dispatchCommand(cs, "save-off");
|
||||
|
||||
ess.scheduleAsyncDelayedTask(
|
||||
ess.runTaskAsynchronously(
|
||||
new Runnable()
|
||||
{
|
||||
@Override
|
||||
|
@@ -5,13 +5,11 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
|
||||
public class Enchantments
|
||||
{
|
||||
private static final transient Pattern NUMPATTERN = Pattern.compile("\\d+");
|
||||
private static final Map<String, Enchantment> ENCHANTMENTS = new HashMap<String, Enchantment>();
|
||||
private static final Map<String, Enchantment> ALIASENCHANTMENTS = new HashMap<String, Enchantment>();
|
||||
|
||||
@@ -20,7 +18,7 @@ public class Enchantments
|
||||
ENCHANTMENTS.put("alldamage", Enchantment.DAMAGE_ALL);
|
||||
ALIASENCHANTMENTS.put("alldmg", Enchantment.DAMAGE_ALL);
|
||||
ENCHANTMENTS.put("sharpness", Enchantment.DAMAGE_ALL);
|
||||
ENCHANTMENTS.put("sharp", Enchantment.DAMAGE_ALL);
|
||||
ALIASENCHANTMENTS.put("sharp", Enchantment.DAMAGE_ALL);
|
||||
ALIASENCHANTMENTS.put("dal", Enchantment.DAMAGE_ALL);
|
||||
|
||||
ENCHANTMENTS.put("ardmg", Enchantment.DAMAGE_ARTHROPODS);
|
||||
@@ -38,12 +36,19 @@ public class Enchantments
|
||||
ALIASENCHANTMENTS.put("minespeed", Enchantment.DIG_SPEED);
|
||||
ALIASENCHANTMENTS.put("cutspeed", Enchantment.DIG_SPEED);
|
||||
ALIASENCHANTMENTS.put("ds", Enchantment.DIG_SPEED);
|
||||
ALIASENCHANTMENTS.put("eff", Enchantment.DIG_SPEED);
|
||||
|
||||
ENCHANTMENTS.put("durability", Enchantment.DURABILITY);
|
||||
ENCHANTMENTS.put("dura", Enchantment.DURABILITY);
|
||||
ALIASENCHANTMENTS.put("dura", Enchantment.DURABILITY);
|
||||
ENCHANTMENTS.put("unbreaking", Enchantment.DURABILITY);
|
||||
ALIASENCHANTMENTS.put("d", Enchantment.DURABILITY);
|
||||
|
||||
ENCHANTMENTS.put("thorns", Enchantment.THORNS);
|
||||
ENCHANTMENTS.put("highcrit", Enchantment.THORNS);
|
||||
ALIASENCHANTMENTS.put("thorn", Enchantment.THORNS);
|
||||
ALIASENCHANTMENTS.put("highercrit", Enchantment.THORNS);
|
||||
ALIASENCHANTMENTS.put("t", Enchantment.THORNS);
|
||||
|
||||
ENCHANTMENTS.put("fireaspect", Enchantment.FIRE_ASPECT);
|
||||
ENCHANTMENTS.put("fire", Enchantment.FIRE_ASPECT);
|
||||
ALIASENCHANTMENTS.put("meleefire", Enchantment.FIRE_ASPECT);
|
||||
@@ -51,10 +56,13 @@ public class Enchantments
|
||||
ALIASENCHANTMENTS.put("fa", Enchantment.FIRE_ASPECT);
|
||||
|
||||
ENCHANTMENTS.put("knockback", Enchantment.KNOCKBACK);
|
||||
ALIASENCHANTMENTS.put("kback", Enchantment.KNOCKBACK);
|
||||
ALIASENCHANTMENTS.put("kb", Enchantment.KNOCKBACK);
|
||||
ALIASENCHANTMENTS.put("k", Enchantment.KNOCKBACK);
|
||||
|
||||
ALIASENCHANTMENTS.put("blockslootbonus", Enchantment.LOOT_BONUS_BLOCKS);
|
||||
ENCHANTMENTS.put("fortune", Enchantment.LOOT_BONUS_BLOCKS);
|
||||
ALIASENCHANTMENTS.put("fort", Enchantment.LOOT_BONUS_BLOCKS);
|
||||
ALIASENCHANTMENTS.put("lbb", Enchantment.LOOT_BONUS_BLOCKS);
|
||||
|
||||
ALIASENCHANTMENTS.put("mobslootbonus", Enchantment.LOOT_BONUS_MOBS);
|
||||
@@ -83,7 +91,7 @@ public class Enchantments
|
||||
ALIASENCHANTMENTS.put("fallprotection", Enchantment.PROTECTION_FALL);
|
||||
ENCHANTMENTS.put("fallprot", Enchantment.PROTECTION_FALL);
|
||||
ENCHANTMENTS.put("featherfall", Enchantment.PROTECTION_FALL);
|
||||
ENCHANTMENTS.put("featherfalling", Enchantment.PROTECTION_FALL);
|
||||
ALIASENCHANTMENTS.put("featherfalling", Enchantment.PROTECTION_FALL);
|
||||
ALIASENCHANTMENTS.put("pfa", Enchantment.PROTECTION_FALL);
|
||||
|
||||
ALIASENCHANTMENTS.put("fireprotection", Enchantment.PROTECTION_FIRE);
|
||||
@@ -129,12 +137,12 @@ public class Enchantments
|
||||
ALIASENCHANTMENTS.put("infinite", Enchantment.ARROW_INFINITE);
|
||||
ALIASENCHANTMENTS.put("unlimited", Enchantment.ARROW_INFINITE);
|
||||
ALIASENCHANTMENTS.put("unlimitedarrows", Enchantment.ARROW_INFINITE);
|
||||
ALIASENCHANTMENTS.put("ai", Enchantment.ARROW_INFINITE);
|
||||
ALIASENCHANTMENTS.put("ai", Enchantment.ARROW_INFINITE);
|
||||
}
|
||||
|
||||
public static Enchantment getByName(String name) {
|
||||
Enchantment enchantment;
|
||||
if (NUMPATTERN.matcher(name).matches()) {
|
||||
if (Util.isInt(name)) {
|
||||
enchantment = Enchantment.getById(Integer.parseInt(name));
|
||||
} else {
|
||||
enchantment = Enchantment.getByName(name.toUpperCase(Locale.ENGLISH));
|
||||
|
@@ -47,9 +47,12 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.command.defaults.VanillaCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
@@ -60,12 +63,13 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
|
||||
public class Essentials extends JavaPlugin implements IEssentials
|
||||
{
|
||||
public static final int BUKKIT_VERSION = 2396;
|
||||
public static final int BUKKIT_VERSION = 2624;
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private transient ISettings settings;
|
||||
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);
|
||||
@@ -84,6 +88,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
private transient Metrics metrics;
|
||||
private transient EssentialsTimer timer;
|
||||
private transient List<String> vanishedPlayers = new ArrayList<String>();
|
||||
private transient SimpleCommandMap scm;
|
||||
|
||||
@Override
|
||||
public ISettings getSettings()
|
||||
@@ -122,6 +127,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
i18n = new I18n(this);
|
||||
i18n.onEnable();
|
||||
execTimer.mark("I18n1");
|
||||
scm = new SimpleCommandMap(this.getServer());
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
for (Plugin plugin : pm.getPlugins())
|
||||
{
|
||||
@@ -176,6 +182,8 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
itemDb = new ItemDb(this);
|
||||
confList.add(itemDb);
|
||||
execTimer.mark("Init(Worth/ItemDB)");
|
||||
jails = new Jails(this);
|
||||
confList.add(jails);
|
||||
reload();
|
||||
}
|
||||
catch (YAMLException exception)
|
||||
@@ -207,6 +215,40 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
backup = new Backup(this);
|
||||
permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
|
||||
alternativeCommandsHandler = new AlternativeCommandsHandler(this);
|
||||
|
||||
timer = new EssentialsTimer(this);
|
||||
getScheduler().scheduleSyncRepeatingTask(this, timer, 100, 100);
|
||||
|
||||
Economy.setEss(this);
|
||||
execTimer.mark("RegHandler");
|
||||
|
||||
final MetricsStarter metricsStarter = new MetricsStarter(this);
|
||||
if (metricsStarter.getStart() != null && metricsStarter.getStart() == true)
|
||||
{
|
||||
getScheduler().runTaskLaterAsynchronously(this, metricsStarter, 1);
|
||||
}
|
||||
else if (metricsStarter.getStart() != null && metricsStarter.getStart() == false)
|
||||
{
|
||||
final MetricsListener metricsListener = new MetricsListener(this, metricsStarter);
|
||||
pm.registerEvents(metricsListener, this);
|
||||
}
|
||||
|
||||
final String timeroutput = execTimer.end();
|
||||
if (getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Essentials load " + timeroutput);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListeners(PluginManager pm)
|
||||
{
|
||||
HandlerList.unregisterAll(this);
|
||||
|
||||
if (getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Registering Listeners");
|
||||
}
|
||||
|
||||
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
|
||||
pm.registerEvents(serverListener, this);
|
||||
confList.add(serverListener);
|
||||
@@ -232,34 +274,9 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
final EssentialsWorldListener worldListener = new EssentialsWorldListener(this);
|
||||
pm.registerEvents(worldListener, this);
|
||||
|
||||
//TODO: Check if this should be here, and not above before reload()
|
||||
jails = new Jails(this);
|
||||
confList.add(jails);
|
||||
|
||||
pm.registerEvents(tntListener, this);
|
||||
|
||||
timer = new EssentialsTimer(this);
|
||||
getScheduler().scheduleSyncRepeatingTask(this, timer, 100, 100);
|
||||
|
||||
Economy.setEss(this);
|
||||
execTimer.mark("RegListeners");
|
||||
|
||||
final MetricsStarter metricsStarter = new MetricsStarter(this);
|
||||
if (metricsStarter.getStart() != null && metricsStarter.getStart() == true)
|
||||
{
|
||||
getScheduler().scheduleAsyncDelayedTask(this, metricsStarter, 1);
|
||||
}
|
||||
else if (metricsStarter.getStart() != null && metricsStarter.getStart() == false)
|
||||
{
|
||||
final MetricsListener metricsListener = new MetricsListener(this, metricsStarter);
|
||||
pm.registerEvents(metricsListener, this);
|
||||
}
|
||||
|
||||
final String timeroutput = execTimer.end();
|
||||
if (getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Essentials load " + timeroutput);
|
||||
}
|
||||
jails.resetListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -291,6 +308,9 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
|
||||
i18n.updateLocale(settings.getLocale());
|
||||
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
registerListeners(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -308,7 +328,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
final PluginCommand pc = alternativeCommandsHandler.getAlternative(commandLabel);
|
||||
if (pc != null)
|
||||
{
|
||||
alternativeCommandsHandler.executed(commandLabel, pc.getLabel());
|
||||
alternativeCommandsHandler.executed(commandLabel, pc);
|
||||
try
|
||||
{
|
||||
return pc.execute(sender, commandLabel, args);
|
||||
@@ -343,6 +363,16 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
// Check for disabled commands
|
||||
if (getSettings().isCommandDisabled(commandLabel))
|
||||
{
|
||||
if (scm != null)
|
||||
{
|
||||
for (VanillaCommand cmd : scm.getFallbackCommands())
|
||||
{
|
||||
if (cmd.matches(commandLabel))
|
||||
{
|
||||
cmd.execute(sender, commandLabel, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -368,6 +398,19 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return true;
|
||||
}
|
||||
|
||||
if (user != null && user.isJailed() && !user.isAuthorized(cmd, "essentials.jail.allow."))
|
||||
{
|
||||
if (user.getJailTimeout() > 0)
|
||||
{
|
||||
user.sendMessage(_("playerJailedFor", user.getName(), Util.formatDateDiff(user.getJailTimeout())));
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("jailMessage"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Run the command
|
||||
try
|
||||
{
|
||||
@@ -471,7 +514,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public User getOfflineUser(final String name)
|
||||
{
|
||||
@@ -566,9 +609,14 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scheduleAsyncDelayedTask(final Runnable run)
|
||||
public BukkitTask runTaskAsynchronously(final Runnable run)
|
||||
{
|
||||
return this.getScheduler().scheduleAsyncDelayedTask(this, run);
|
||||
return this.getScheduler().runTaskAsynchronously(this, run);
|
||||
}
|
||||
@Override
|
||||
public BukkitTask runTaskLaterAsynchronously(final Runnable run, final long delay)
|
||||
{
|
||||
return this.getScheduler().runTaskLaterAsynchronously(this, run, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -28,8 +28,7 @@ public class EssentialsBlockListener implements Listener
|
||||
return;
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final boolean unlimitedForUser = user.hasUnlimited(is);
|
||||
if (unlimitedForUser && user.getGameMode() == GameMode.SURVIVAL)
|
||||
if (user.hasUnlimited(is) && user.getGameMode() == GameMode.SURVIVAL)
|
||||
{
|
||||
ess.scheduleSyncDelayedTask(
|
||||
new Runnable()
|
||||
|
@@ -221,6 +221,69 @@ public class EssentialsConf extends YamlConfiguration
|
||||
this.resourceClass = resClass;
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
save(configFile);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveWithError() throws IOException
|
||||
{
|
||||
save(configFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void save(final File file) throws IOException
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
}
|
||||
|
||||
Files.createParentDirs(file);
|
||||
|
||||
final String data = saveToString();
|
||||
|
||||
if (data.length() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!configFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
LOGGER.log(Level.INFO, _("creatingEmptyConfig", configFile.toString()));
|
||||
if (!configFile.createNewFile())
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()));
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), UTF8);
|
||||
|
||||
try
|
||||
{
|
||||
writer.write(data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasProperty(final String path)
|
||||
{
|
||||
return isSet(path);
|
||||
@@ -305,94 +368,14 @@ public class EssentialsConf extends YamlConfiguration
|
||||
set(path, map);
|
||||
}
|
||||
|
||||
public long getLong(final String path, final long def)
|
||||
public void setProperty(String path, List object)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Number num = (Number)get(path);
|
||||
return num == null ? def : num.longValue();
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
set(path, new ArrayList(object));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(final String path, final double def)
|
||||
public void setProperty(String path, Map object)
|
||||
{
|
||||
try
|
||||
{
|
||||
Number num = (Number)get(path);
|
||||
return num == null ? def : num.doubleValue();
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
save(configFile);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveWithError() throws IOException
|
||||
{
|
||||
save(configFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void save(final File file) throws IOException
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
}
|
||||
|
||||
Files.createParentDirs(file);
|
||||
|
||||
final String data = saveToString();
|
||||
|
||||
if (data.length() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!configFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
LOGGER.log(Level.INFO, _("creatingEmptyConfig", configFile.toString()));
|
||||
if (!configFile.createNewFile())
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()));
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), UTF8);
|
||||
|
||||
try
|
||||
{
|
||||
writer.write(data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
writer.close();
|
||||
}
|
||||
set(path, new LinkedHashMap(object));
|
||||
}
|
||||
|
||||
public Object getProperty(String path)
|
||||
@@ -464,6 +447,12 @@ public class EssentialsConf extends YamlConfiguration
|
||||
return super.getDouble(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized double getDouble(final String path, final double def)
|
||||
{
|
||||
return super.getDouble(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<Double> getDoubleList(String path)
|
||||
{
|
||||
@@ -524,6 +513,12 @@ public class EssentialsConf extends YamlConfiguration
|
||||
return super.getLong(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long getLong(final String path, final long def)
|
||||
{
|
||||
return super.getLong(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<Long> getLongList(String path)
|
||||
{
|
||||
|
@@ -5,15 +5,12 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
@@ -33,73 +30,90 @@ public class EssentialsEntityListener implements Listener
|
||||
{
|
||||
final Entity eAttack = event.getDamager();
|
||||
final Entity eDefend = event.getEntity();
|
||||
if (eDefend instanceof Player && eAttack instanceof Player)
|
||||
if (eAttack instanceof Player)
|
||||
{
|
||||
final User defender = ess.getUser(eDefend);
|
||||
final User attacker = ess.getUser(eAttack);
|
||||
|
||||
if (ess.getSettings().getLoginAttackDelay() > 0 && !attacker.isAuthorized("essentials.pvpdelay.exempt")
|
||||
&& (System.currentTimeMillis() < (attacker.getLastLogin() + ess.getSettings().getLoginAttackDelay())))
|
||||
if (eDefend instanceof Player)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
onPlayerVsPlayerDamage(event, (Player)eDefend, attacker);
|
||||
}
|
||||
|
||||
if (attacker.hasInvulnerabilityAfterTeleport() || defender.hasInvulnerabilityAfterTeleport())
|
||||
else if (eDefend instanceof Ageable)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (attacker.isGodModeEnabled() && !attacker.isAuthorized("essentials.god.pvp"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (attacker.isHidden() && !attacker.isAuthorized("essentials.vanish.pvp"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
attacker.updateActivity(true);
|
||||
final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
|
||||
if (commandList != null && !commandList.isEmpty())
|
||||
{
|
||||
for (final String command : commandList)
|
||||
{
|
||||
if (command != null && !command.isEmpty())
|
||||
{
|
||||
ess.scheduleSyncDelayedTask(
|
||||
new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
attacker.getServer().dispatchCommand(attacker.getBase(), command.replaceAll("\\{player\\}", defender.getName()));
|
||||
LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command));
|
||||
}
|
||||
});
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (eAttack instanceof Player)
|
||||
{
|
||||
final User player = ess.getUser(eAttack);
|
||||
player.updateActivity(true);
|
||||
if (eDefend instanceof Ageable)
|
||||
{
|
||||
final ItemStack hand = player.getItemInHand();
|
||||
final ItemStack hand = attacker.getItemInHand();
|
||||
if (hand != null && hand.getType() == Material.MILK_BUCKET)
|
||||
{
|
||||
((Ageable)eDefend).setBaby();
|
||||
hand.setType(Material.BUCKET);
|
||||
player.setItemInHand(hand);
|
||||
player.updateInventory();
|
||||
attacker.setItemInHand(hand);
|
||||
attacker.updateInventory();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
attacker.updateActivity(true);
|
||||
}
|
||||
else if (eAttack instanceof Projectile && eDefend instanceof Player)
|
||||
{
|
||||
Entity shooter = ((Projectile)event.getDamager()).getShooter();
|
||||
if (shooter instanceof Player)
|
||||
{
|
||||
final User attacker = ess.getUser(shooter);
|
||||
onPlayerVsPlayerDamage(event, (Player)eDefend, attacker);
|
||||
attacker.updateActivity(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onPlayerVsPlayerDamage(final EntityDamageByEntityEvent event, final Player defender, final User attacker)
|
||||
{
|
||||
if (ess.getSettings().getLoginAttackDelay() > 0 && !attacker.isAuthorized("essentials.pvpdelay.exempt")
|
||||
&& (System.currentTimeMillis() < (attacker.getLastLogin() + ess.getSettings().getLoginAttackDelay())))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (!defender.equals(attacker.getBase()) && (attacker.hasInvulnerabilityAfterTeleport() || ess.getUser(defender).hasInvulnerabilityAfterTeleport()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (attacker.isGodModeEnabled() && !attacker.isAuthorized("essentials.god.pvp"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (attacker.isHidden() && !attacker.isAuthorized("essentials.vanish.pvp"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
onPlayerVsPlayerPowertool(event, defender, attacker);
|
||||
}
|
||||
|
||||
private void onPlayerVsPlayerPowertool(final EntityDamageByEntityEvent event, final Player defender, final User attacker)
|
||||
{
|
||||
final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
|
||||
if (commandList != null && !commandList.isEmpty())
|
||||
{
|
||||
for (final String tempCommand : commandList)
|
||||
{
|
||||
final String command = tempCommand.replaceAll("\\{player\\}", defender.getName());
|
||||
if (command != null && !command.isEmpty() && !command.equals(tempCommand))
|
||||
{
|
||||
ess.scheduleSyncDelayedTask(
|
||||
new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
attacker.getServer().dispatchCommand(attacker.getBase(), command);
|
||||
LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command));
|
||||
}
|
||||
});
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,6 +169,9 @@ public class EssentialsEntityListener implements Listener
|
||||
{
|
||||
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
|
||||
{
|
||||
final Player player = (Player)event.getEntity();
|
||||
player.setFoodLevel(20);
|
||||
player.setSaturation(10);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.TextInput;
|
||||
import com.earth2me.essentials.textreader.TextPager;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -15,6 +14,7 @@ import java.util.logging.Logger;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -23,9 +23,10 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -76,10 +77,20 @@ public class EssentialsPlayerListener implements Listener
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerMove(final PlayerMoveEvent event)
|
||||
{
|
||||
if ((!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers())
|
||||
|| event.getFrom().getBlockX() == event.getTo().getBlockX()
|
||||
&& event.getFrom().getBlockZ() == event.getTo().getBlockZ()
|
||||
&& event.getFrom().getBlockY() == event.getTo().getBlockY())
|
||||
if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Unregistering move listener");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if (event.getFrom().getBlockX() == event.getTo().getBlockX()
|
||||
&& event.getFrom().getBlockZ() == event.getTo().getBlockZ()
|
||||
&& event.getFrom().getBlockY() == event.getTo().getBlockY())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -127,9 +138,10 @@ public class EssentialsPlayerListener implements Listener
|
||||
{
|
||||
user.toggleVanished();
|
||||
}
|
||||
if (!user.isJailed())
|
||||
user.setLogoutLocation();
|
||||
if (user.isRecipeSee())
|
||||
{
|
||||
user.setLastLocation();
|
||||
user.getPlayer().getOpenInventory().getTopInventory().clear();
|
||||
}
|
||||
user.updateActivity(false);
|
||||
user.dispose();
|
||||
@@ -138,7 +150,7 @@ public class EssentialsPlayerListener implements Listener
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event)
|
||||
{
|
||||
ess.scheduleAsyncDelayedTask(new Runnable()
|
||||
ess.runTaskAsynchronously(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
@@ -156,61 +168,93 @@ public class EssentialsPlayerListener implements Listener
|
||||
}
|
||||
ess.getBackup().onPlayerJoin();
|
||||
final User user = ess.getUser(player);
|
||||
user.setDisplayNick();
|
||||
updateCompass(user);
|
||||
user.setLastLogin(System.currentTimeMillis());
|
||||
user.updateActivity(false);
|
||||
|
||||
if (!ess.getVanishedPlayers().isEmpty() && !user.isAuthorized("essentials.vanish.see"))
|
||||
ess.scheduleSyncDelayedTask(new Runnable()
|
||||
{
|
||||
for (String p : ess.getVanishedPlayers())
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Player toVanish = ess.getUser(p).getBase();
|
||||
if (toVanish.isOnline()) {
|
||||
user.hidePlayer(toVanish);
|
||||
}
|
||||
}
|
||||
}
|
||||
user.setDisplayNick();
|
||||
updateCompass(user);
|
||||
|
||||
if (user.isAuthorized("essentials.sleepingignored"))
|
||||
{
|
||||
user.setSleepingIgnored(true);
|
||||
}
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
|
||||
{
|
||||
try
|
||||
{
|
||||
final IText input = new TextInput(user, "motd", true, ess);
|
||||
final IText output = new KeywordReplacer(input, user, ess);
|
||||
final TextPager pager = new TextPager(output, true);
|
||||
pager.showPage("1", null, "motd", user);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
if (ess.getSettings().isDebug())
|
||||
if (!ess.getVanishedPlayers().isEmpty() && !user.isAuthorized("essentials.vanish.see"))
|
||||
{
|
||||
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
|
||||
for (String p : ess.getVanishedPlayers())
|
||||
{
|
||||
Player toVanish = ess.getServer().getPlayerExact(p);
|
||||
if (toVanish != null && toVanish.isOnline())
|
||||
{
|
||||
user.hidePlayer(toVanish);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.log(Level.WARNING, ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
|
||||
{
|
||||
final List<String> mail = user.getMails();
|
||||
if (mail.isEmpty())
|
||||
{
|
||||
user.sendMessage(_("noNewMail"));
|
||||
if (user.isAuthorized("essentials.sleepingignored"))
|
||||
{
|
||||
user.setSleepingIgnored(true);
|
||||
}
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
|
||||
{
|
||||
try
|
||||
{
|
||||
final IText input = new TextInput(user, "motd", true, ess);
|
||||
final IText output = new KeywordReplacer(input, user, ess);
|
||||
final TextPager pager = new TextPager(output, true);
|
||||
pager.showPage("1", null, "motd", user);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.log(Level.WARNING, ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
|
||||
{
|
||||
final List<String> mail = user.getMails();
|
||||
if (mail.isEmpty())
|
||||
{
|
||||
final String msg = _("noNewMail");
|
||||
if (!msg.isEmpty())
|
||||
{
|
||||
user.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("youHaveNewMail", mail.size()));
|
||||
}
|
||||
}
|
||||
|
||||
if (user.isAuthorized("essentials.fly.safelogin"))
|
||||
{
|
||||
final World world = user.getLocation().getWorld();
|
||||
final int x = user.getLocation().getBlockX();
|
||||
int y = user.getLocation().getBlockY();
|
||||
final int z = user.getLocation().getBlockZ();
|
||||
while (Util.isBlockUnsafe(world, x, y, z) && y > -1)
|
||||
{
|
||||
y--;
|
||||
}
|
||||
|
||||
if (user.getLocation().getBlockY() - y > 1 || y < 0)
|
||||
{
|
||||
user.setAllowFlight(true);
|
||||
user.setFlying(true);
|
||||
user.sendMessage(_("flyMode", _("enabled"), user.getDisplayName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("youHaveNewMail", mail.size()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Makes the compass item ingame always point to the first essentials home. #EasterEgg
|
||||
@@ -224,14 +268,7 @@ public class EssentialsPlayerListener implements Listener
|
||||
if (loc != null)
|
||||
{
|
||||
final Location updateLoc = loc;
|
||||
ess.scheduleSyncDelayedTask(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
user.setCompassTarget(updateLoc);
|
||||
}
|
||||
});
|
||||
user.setCompassTarget(updateLoc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,8 +298,17 @@ public class EssentialsPlayerListener implements Listener
|
||||
|
||||
if (!banExpired && (user.isBanned() || event.getResult() == Result.KICK_BANNED))
|
||||
{
|
||||
final String banReason = user.getBanReason();
|
||||
event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : _("defaultBanReason"));
|
||||
String banReason = user.getBanReason();
|
||||
if (banReason == null || banReason.isEmpty() || banReason.equalsIgnoreCase("ban"))
|
||||
{
|
||||
banReason = _("defaultBanReason");
|
||||
}
|
||||
if (user.getBanTimeout() > 0)
|
||||
{
|
||||
//TODO: TL This
|
||||
banReason += "\n\n" + "Expires in " + Util.formatDateDiff(user.getBanTimeout());
|
||||
}
|
||||
event.disallow(Result.KICK_BANNED, banReason);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -323,14 +369,13 @@ public class EssentialsPlayerListener implements Listener
|
||||
});
|
||||
}
|
||||
}
|
||||
private final static List<String> COMMANDS = Arrays.asList("msg", "r", "mail", "m", "t", "whisper", "emsg", "tell", "er", "reply", "ereply", "email", "action", "describe", "eme", "eaction", "edescribe", "etell", "ewhisper", "pm");
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final String cmd = event.getMessage().toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
if (COMMANDS.contains(cmd))
|
||||
if (ess.getSettings().getSocialSpyCommands().contains(cmd))
|
||||
{
|
||||
for (Player onlinePlayer : ess.getServer().getOnlinePlayers())
|
||||
{
|
||||
@@ -348,13 +393,14 @@ public class EssentialsPlayerListener implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerChangedWorldHack(final PlayerChangedWorldEvent event)
|
||||
{
|
||||
final Player user = event.getPlayer();
|
||||
if (user.getGameMode() != GameMode.CREATIVE) {
|
||||
user.setAllowFlight(false);
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (user.getGameMode() != GameMode.CREATIVE && !user.isAuthorized("essentials.fly"))
|
||||
{
|
||||
user.setAllowFlight(false);
|
||||
}
|
||||
user.setFlySpeed(0.1f);
|
||||
user.setWalkSpeed(0.2f);
|
||||
}
|
||||
@@ -371,10 +417,14 @@ public class EssentialsPlayerListener implements Listener
|
||||
user.sendMessage(_("noGodWorldWarning"));
|
||||
}
|
||||
|
||||
if (!event.getPlayer().getWorld().getName().equals(newWorld))
|
||||
if (!user.getWorld().getName().equals(newWorld))
|
||||
{
|
||||
user.sendMessage(_("currentWorld", newWorld));
|
||||
}
|
||||
if (user.isVanished())
|
||||
{
|
||||
user.setVanished(user.isAuthorized("essentials.vanish"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
@@ -385,9 +435,12 @@ public class EssentialsPlayerListener implements Listener
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
if (!event.isCancelled() && event.getClickedBlock().getTypeId() == BED && ess.getSettings().getUpdateBedAtDaytime())
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
player.setBedSpawnLocation(event.getClickedBlock().getLocation());
|
||||
player.sendMessage(_("homeSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
|
||||
User player = ess.getUser(event.getPlayer());
|
||||
if (player.isAuthorized("essentials.sethome.bed"))
|
||||
{
|
||||
player.setBedSpawnLocation(event.getClickedBlock().getLocation());
|
||||
player.sendMessage(_("homeSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LEFT_CLICK_AIR:
|
||||
@@ -404,6 +457,7 @@ public class EssentialsPlayerListener implements Listener
|
||||
if (event.getItem() != null && event.getItem().getTypeId() != AIR)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
user.updateActivity(true);
|
||||
if (user.hasPowerTools() && user.arePowerToolsEnabled() && usePowertools(user, event.getItem().getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
@@ -501,10 +555,13 @@ public class EssentialsPlayerListener implements Listener
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onInventoryClickEvent(final InventoryClickEvent event)
|
||||
{
|
||||
if (event.getView().getTopInventory().getType() == InventoryType.PLAYER)
|
||||
final Inventory top = event.getView().getTopInventory();
|
||||
final InventoryType type = top.getType();
|
||||
|
||||
if (type == InventoryType.PLAYER)
|
||||
{
|
||||
final User user = ess.getUser(event.getWhoClicked());
|
||||
final InventoryHolder invHolder = event.getView().getTopInventory().getHolder();
|
||||
final InventoryHolder invHolder = top.getHolder();
|
||||
if (invHolder != null && invHolder instanceof HumanEntity)
|
||||
{
|
||||
final User invOwner = ess.getUser((HumanEntity)invHolder);
|
||||
@@ -513,10 +570,11 @@ public class EssentialsPlayerListener implements Listener
|
||||
|| !invOwner.isOnline()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
user.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event.getView().getTopInventory().getType() == InventoryType.ENDER_CHEST)
|
||||
else if (type == InventoryType.ENDER_CHEST)
|
||||
{
|
||||
final User user = ess.getUser(event.getWhoClicked());
|
||||
if (user.isEnderSee() && (!user.isAuthorized("essentials.enderchest.modify")))
|
||||
@@ -524,20 +582,64 @@ public class EssentialsPlayerListener implements Listener
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
else if (type == InventoryType.WORKBENCH)
|
||||
{
|
||||
User user = ess.getUser(event.getWhoClicked());
|
||||
if (user.isRecipeSee())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
else if (type == InventoryType.CHEST && top.getSize() == 9)
|
||||
{
|
||||
final User user = ess.getUser(event.getWhoClicked());
|
||||
final InventoryHolder invHolder = top.getHolder();
|
||||
if (invHolder != null && invHolder instanceof HumanEntity && user.isInvSee())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryCloseEvent(final InventoryCloseEvent event)
|
||||
{
|
||||
if (event.getView().getTopInventory().getType() == InventoryType.PLAYER)
|
||||
final Inventory top = event.getView().getTopInventory();
|
||||
final InventoryType type = top.getType();
|
||||
if (type == InventoryType.PLAYER)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
user.setInvSee(false);
|
||||
}
|
||||
else if (event.getView().getTopInventory().getType() == InventoryType.ENDER_CHEST)
|
||||
else if (type == InventoryType.ENDER_CHEST)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
user.setEnderSee(false);
|
||||
}
|
||||
else if (type == InventoryType.WORKBENCH)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (user.isRecipeSee())
|
||||
{
|
||||
user.setRecipeSee(false);
|
||||
event.getView().getTopInventory().clear();
|
||||
}
|
||||
}
|
||||
else if (type == InventoryType.CHEST && top.getSize() == 9)
|
||||
{
|
||||
final InventoryHolder invHolder = top.getHolder();
|
||||
if (invHolder != null && invHolder instanceof HumanEntity)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
user.setInvSee(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerFishEvent(final PlayerFishEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
user.updateActivity(true);
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
|
||||
public interface IEssentials extends Plugin
|
||||
@@ -44,7 +45,9 @@ public interface IEssentials extends Plugin
|
||||
|
||||
Methods getPaymentMethod();
|
||||
|
||||
int scheduleAsyncDelayedTask(Runnable run);
|
||||
BukkitTask runTaskAsynchronously(Runnable run);
|
||||
|
||||
BukkitTask runTaskLaterAsynchronously(Runnable run, long delay);
|
||||
|
||||
int scheduleSyncDelayedTask(Runnable run);
|
||||
|
||||
|
@@ -42,6 +42,8 @@ public interface ISettings extends IConf
|
||||
|
||||
double getHealCooldown();
|
||||
|
||||
Set<String> getSocialSpyCommands();
|
||||
|
||||
Map<String, Object> getKit(String name);
|
||||
|
||||
ConfigurationSection getKits();
|
||||
@@ -141,6 +143,8 @@ public interface ISettings extends IConf
|
||||
boolean getFreezeAfkPlayers();
|
||||
|
||||
boolean cancelAfkOnMove();
|
||||
|
||||
boolean cancelAfkOnInteract();
|
||||
|
||||
boolean areDeathMessagesEnabled();
|
||||
|
||||
@@ -149,6 +153,8 @@ public interface ISettings extends IConf
|
||||
Set<String> getNoGodWorlds();
|
||||
|
||||
boolean getUpdateBedAtDaytime();
|
||||
|
||||
boolean allowUnsafeEnchantments();
|
||||
|
||||
boolean getRepairEnchanted();
|
||||
|
||||
@@ -183,4 +189,6 @@ public interface ISettings extends IConf
|
||||
public int getMailsPerMinute();
|
||||
|
||||
public void setEssentialsChatActive(boolean b);
|
||||
|
||||
long getMaxTempban();
|
||||
}
|
||||
|
@@ -42,4 +42,14 @@ public interface IUser extends Player
|
||||
Teleport getTeleport();
|
||||
|
||||
void setJail(String jail);
|
||||
|
||||
boolean isIgnoreExempt();
|
||||
|
||||
boolean isAfk();
|
||||
|
||||
void setAfk(final boolean set);
|
||||
|
||||
void setLogoutLocation();
|
||||
|
||||
Location getLogoutLocation();
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package com.earth2me.essentials;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.api.IItemDb;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -20,6 +21,7 @@ public class ItemDb implements IConf, IItemDb
|
||||
private final transient Map<ItemData, List<String>> names = new HashMap<ItemData, List<String>>();
|
||||
private final transient Map<String, Short> durabilities = new HashMap<String, Short>();
|
||||
private final transient ManagedFile file;
|
||||
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
||||
|
||||
@Override
|
||||
public void reloadConfig()
|
||||
@@ -84,19 +86,20 @@ public class ItemDb implements IConf, IItemDb
|
||||
int itemid = 0;
|
||||
String itemname = null;
|
||||
short metaData = 0;
|
||||
String[] parts = splitPattern.split(id);;
|
||||
if (id.matches("^\\d+[:+',;.]\\d+$"))
|
||||
{
|
||||
itemid = Integer.parseInt(id.split("[:+',;.]")[0]);
|
||||
metaData = Short.parseShort(id.split("[:+',;.]")[1]);
|
||||
itemid = Integer.parseInt(parts[0]);
|
||||
metaData = Short.parseShort(parts[1]);
|
||||
}
|
||||
else if (id.matches("^\\d+$"))
|
||||
else if (Util.isInt(id))
|
||||
{
|
||||
itemid = Integer.parseInt(id);
|
||||
}
|
||||
else if (id.matches("^[^:+',;.]+[:+',;.]\\d+$"))
|
||||
{
|
||||
itemname = id.split("[:+',;.]")[0].toLowerCase(Locale.ENGLISH);
|
||||
metaData = Short.parseShort(id.split("[:+',;.]")[1]);
|
||||
itemname = parts[0].toLowerCase(Locale.ENGLISH);
|
||||
metaData = Short.parseShort(parts[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -134,19 +137,21 @@ public class ItemDb implements IConf, IItemDb
|
||||
retval.setDurability(metaData);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
public String names(ItemStack item)
|
||||
{
|
||||
ItemData itemData = new ItemData(item.getTypeId(), item.getDurability());
|
||||
List<String> nameList = names.get(itemData);
|
||||
if (nameList == null) {
|
||||
itemData = new ItemData(item.getTypeId(), (short) 0);
|
||||
if (nameList == null)
|
||||
{
|
||||
itemData = new ItemData(item.getTypeId(), (short)0);
|
||||
nameList = names.get(itemData);
|
||||
if (nameList == null) {
|
||||
if (nameList == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (nameList.size() > 15)
|
||||
{
|
||||
nameList = nameList.subList(0, 14);
|
||||
@@ -154,6 +159,7 @@ public class ItemDb implements IConf, IItemDb
|
||||
return Util.joinList(", ", nameList);
|
||||
}
|
||||
|
||||
|
||||
class ItemData
|
||||
{
|
||||
final private int itemNo;
|
||||
@@ -198,6 +204,7 @@ public class ItemDb implements IConf, IItemDb
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class LengthCompare implements java.util.Comparator<String>
|
||||
{
|
||||
public LengthCompare()
|
||||
|
@@ -44,6 +44,10 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
|
||||
final PluginManager pluginManager = ess.getServer().getPluginManager();
|
||||
final JailListener blockListener = new JailListener();
|
||||
pluginManager.registerEvents(blockListener, ess);
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Registering Jail listener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,16 +59,24 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
|
||||
@Override
|
||||
public void finishRead()
|
||||
{
|
||||
if (enabled == false && getCount() > 0)
|
||||
{
|
||||
registerListeners();
|
||||
}
|
||||
checkRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishWrite()
|
||||
{
|
||||
if (enabled == false)
|
||||
checkRegister();
|
||||
}
|
||||
|
||||
public void resetListener()
|
||||
{
|
||||
enabled = false;
|
||||
checkRegister();
|
||||
}
|
||||
|
||||
private void checkRegister()
|
||||
{
|
||||
if (enabled == false && getCount() > 0)
|
||||
{
|
||||
registerListeners();
|
||||
}
|
||||
|
@@ -6,9 +6,7 @@ import com.earth2me.essentials.commands.NoChargeException;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
@@ -37,16 +35,17 @@ public class Kit
|
||||
|
||||
}
|
||||
|
||||
public static void checkTime(final User user, final String kitName, final Map<String, Object> els) throws NoChargeException
|
||||
public static void checkTime(final User user, final String kitName, final Map<String, Object> els) throws Exception
|
||||
{
|
||||
if (user.isAuthorized("essentials.kit.exemptdelay")) {
|
||||
if (user.isAuthorized("essentials.kit.exemptdelay"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final Calendar time = new GregorianCalendar();
|
||||
|
||||
// Take the current time, and remove the delay from it.
|
||||
final double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L;
|
||||
final double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0.0d;
|
||||
final Calendar earliestTime = new GregorianCalendar();
|
||||
earliestTime.add(Calendar.SECOND, -(int)delay);
|
||||
earliestTime.add(Calendar.MILLISECOND, -(int)((delay * 1000.0) % 1000.0));
|
||||
@@ -56,7 +55,7 @@ public class Kit
|
||||
// When was the last kit used?
|
||||
final long lastTime = user.getKitTimestamp(kitName);
|
||||
|
||||
if (lastTime < earliestLong)
|
||||
if (lastTime < earliestLong || lastTime == 0L)
|
||||
{
|
||||
user.setKitTimestamp(kitName, time.getTimeInMillis());
|
||||
}
|
||||
@@ -66,6 +65,11 @@ public class Kit
|
||||
// If this happens, let's give the user the benifit of the doubt.
|
||||
user.setKitTimestamp(kitName, time.getTimeInMillis());
|
||||
}
|
||||
else if (earliestLong < 0L)
|
||||
{
|
||||
user.sendMessage(_("kitOnce"));
|
||||
throw new NoChargeException();
|
||||
}
|
||||
else
|
||||
{
|
||||
time.setTimeInMillis(lastTime);
|
||||
@@ -82,7 +86,6 @@ public class Kit
|
||||
{
|
||||
throw new Exception(_("kitError2"));
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
@@ -100,57 +103,34 @@ public class Kit
|
||||
try
|
||||
{
|
||||
boolean spew = false;
|
||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
|
||||
for (String d : items)
|
||||
{
|
||||
final String[] parts = d.split(" ");
|
||||
final String[] item = parts[0].split("[:+',;.]", 2);
|
||||
final int id = Material.getMaterial(Integer.parseInt(item[0])).getId();
|
||||
final short data = item.length > 1 ? Short.parseShort(item[1]) : 0;
|
||||
final int amount = parts.length > 1 ? Integer.parseInt(parts[1]) : 1;
|
||||
if (d.startsWith(ess.getSettings().getCurrencySymbol()))
|
||||
{
|
||||
Double value = Double.parseDouble(d.substring(ess.getSettings().getCurrencySymbol().length()).trim());
|
||||
Trade t = new Trade(value, ess);
|
||||
t.pay(user);
|
||||
continue;
|
||||
}
|
||||
|
||||
final String[] parts = d.split(" ");
|
||||
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
|
||||
final MetaItemStack metaStack = new MetaItemStack(parseStack);
|
||||
|
||||
final ItemStack stack = new ItemStack(id, amount, data);
|
||||
if (parts.length > 2)
|
||||
{
|
||||
for (int i = 2; i < parts.length; i++)
|
||||
{
|
||||
final String[] split = parts[i].split("[:+',;.]", 2);
|
||||
if (split.length < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final Enchantment enchantment = Enchantments.getByName(split[0]);
|
||||
if (enchantment == null)
|
||||
{
|
||||
throw new Exception("Enchantment not found: " + split[0]);
|
||||
}
|
||||
int level;
|
||||
if (split.length > 1)
|
||||
{
|
||||
level = Integer.parseInt(split[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
}
|
||||
try
|
||||
{
|
||||
stack.addEnchantment(enchantment, level);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
metaStack.parseStringMeta(user, allowUnsafe, parts, 2, ess);
|
||||
}
|
||||
|
||||
final Map<Integer, ItemStack> overfilled;
|
||||
if (user.isAuthorized("essentials.oversizedstacks"))
|
||||
{
|
||||
overfilled = InventoryWorkaround.addItem(user.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack);
|
||||
overfilled = InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), metaStack.getItemStack());
|
||||
}
|
||||
else
|
||||
{
|
||||
overfilled = InventoryWorkaround.addItem(user.getInventory(), true, 0, stack);
|
||||
overfilled = InventoryWorkaround.addItems(user.getInventory(), metaStack.getItemStack());
|
||||
}
|
||||
for (ItemStack itemStack : overfilled.values())
|
||||
{
|
||||
|
361
Essentials/src/com/earth2me/essentials/MetaItemStack.java
Normal file
361
Essentials/src/com/earth2me/essentials/MetaItemStack.java
Normal file
@@ -0,0 +1,361 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.textreader.*;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
|
||||
|
||||
public class MetaItemStack
|
||||
{
|
||||
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
||||
private final ItemStack stack;
|
||||
private final static Map<String, DyeColor> colorMap = new HashMap<String, DyeColor>();
|
||||
private final static Map<String, FireworkEffect.Type> fireworkShape = new HashMap<String, FireworkEffect.Type>();
|
||||
private FireworkEffect.Builder builder = FireworkEffect.builder();
|
||||
private boolean validFirework = false;
|
||||
|
||||
static
|
||||
{
|
||||
for (DyeColor color : DyeColor.values())
|
||||
{
|
||||
colorMap.put(color.name(), color);
|
||||
}
|
||||
for (FireworkEffect.Type type : FireworkEffect.Type.values())
|
||||
{
|
||||
fireworkShape.put(type.name(), type);
|
||||
}
|
||||
}
|
||||
|
||||
public MetaItemStack(final ItemStack stack)
|
||||
{
|
||||
this.stack = stack.clone();
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
public boolean isValidFirework()
|
||||
{
|
||||
return validFirework;
|
||||
}
|
||||
|
||||
public FireworkEffect.Builder getFireworkBuilder()
|
||||
{
|
||||
return builder;
|
||||
}
|
||||
|
||||
public void parseStringMeta(final CommandSender user, final boolean allowUnsafe, String[] string, int fromArg, final IEssentials ess) throws Exception
|
||||
{
|
||||
|
||||
for (int i = fromArg; i < string.length; i++)
|
||||
{
|
||||
addStringMeta(user, allowUnsafe, string[i], ess);
|
||||
}
|
||||
if (validFirework)
|
||||
{
|
||||
FireworkEffect effect = builder.build();
|
||||
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
||||
fmeta.addEffect(effect);
|
||||
stack.setItemMeta(fmeta);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: TL this
|
||||
private void addStringMeta(final CommandSender user, final boolean allowUnsafe, final String string, final IEssentials ess) throws Exception
|
||||
{
|
||||
final String[] split = splitPattern.split(string, 2);
|
||||
if (split.length < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (split.length > 1 && split[0].equalsIgnoreCase("name"))
|
||||
{
|
||||
final String displayName = Util.replaceFormat(split[1].replace('_', ' '));
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(displayName);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
else if (split.length > 1 && (split[0].equalsIgnoreCase("lore") || split[0].equalsIgnoreCase("desc")))
|
||||
{
|
||||
final List<String> lore = new ArrayList<String>();
|
||||
for (String line : split[1].split("\\|"))
|
||||
{
|
||||
lore.add(Util.replaceFormat(line.replace('_', ' ')));
|
||||
}
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
else if (split.length > 1 && (split[0].equalsIgnoreCase("player") || split[0].equalsIgnoreCase("owner")) && stack.getType() == Material.SKULL_ITEM)
|
||||
{
|
||||
if (stack.getDurability() == 3)
|
||||
{
|
||||
final String owner = split[1];
|
||||
final SkullMeta meta = (SkullMeta)stack.getItemMeta();
|
||||
boolean result = meta.setOwner(owner);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("You can only set the owner of player skulls (397:3)");
|
||||
}
|
||||
}
|
||||
else if (split.length > 1 && split[0].equalsIgnoreCase("book") && stack.getType() == Material.WRITTEN_BOOK)
|
||||
{
|
||||
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
||||
final IText input = new BookInput("book", true, ess);
|
||||
final BookPager pager = new BookPager(input);
|
||||
|
||||
List<String> pages = pager.getPages(split[1]);
|
||||
meta.setPages(pages);
|
||||
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
else if (split.length > 1 && split[0].equalsIgnoreCase("author") && stack.getType() == Material.WRITTEN_BOOK)
|
||||
{
|
||||
final String author = split[1];
|
||||
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
||||
meta.setAuthor(author);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == Material.WRITTEN_BOOK)
|
||||
{
|
||||
final String title = Util.replaceFormat(split[1].replace('_', ' '));
|
||||
final BookMeta meta = (BookMeta)stack.getItemMeta();
|
||||
meta.setTitle(title);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
else if (split.length > 1 && split[0].equalsIgnoreCase("power") && stack.getType() == Material.FIREWORK)
|
||||
{
|
||||
final int power = Util.isInt(split[1]) ? Integer.parseInt(split[1]) : 0;
|
||||
final FireworkMeta meta = (FireworkMeta)stack.getItemMeta();
|
||||
meta.setPower(power > 3 ? 4 : power);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
else if (stack.getType() == Material.FIREWORK) //WARNING - Meta for fireworks will be ignored after this point.
|
||||
{
|
||||
addFireworkMeta(user, false, string, ess);
|
||||
}
|
||||
else if (split.length > 1 && (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour"))
|
||||
&& (stack.getType() == Material.LEATHER_BOOTS
|
||||
|| stack.getType() == Material.LEATHER_CHESTPLATE
|
||||
|| stack.getType() == Material.LEATHER_HELMET
|
||||
|| stack.getType() == Material.LEATHER_LEGGINGS))
|
||||
{
|
||||
final String[] color = split[1].split("(\\||,)");
|
||||
if (color.length == 3)
|
||||
{
|
||||
final int red = Util.isInt(color[0]) ? Integer.parseInt(color[0]) : 0;
|
||||
final int green = Util.isInt(color[1]) ? Integer.parseInt(color[1]) : 0;
|
||||
final int blue = Util.isInt(color[2]) ? Integer.parseInt(color[2]) : 0;
|
||||
final LeatherArmorMeta meta = (LeatherArmorMeta)stack.getItemMeta();
|
||||
meta.setColor(Color.fromRGB(red, green, blue));
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Leather Color Syntax: color:<red>,<green>,<blue> eg: color:255,0,0");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
parseEnchantmentStrings(user, allowUnsafe, split);
|
||||
}
|
||||
}
|
||||
|
||||
public void addFireworkMeta(final CommandSender user, final boolean allowShortName, final String string, final IEssentials ess) throws Exception
|
||||
{
|
||||
if (stack.getType() == Material.FIREWORK)
|
||||
{
|
||||
final String[] split = splitPattern.split(string, 2);
|
||||
|
||||
if (split.length < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour") || (allowShortName && split[0].equalsIgnoreCase("c")))
|
||||
{
|
||||
if (validFirework)
|
||||
{
|
||||
FireworkEffect effect = builder.build();
|
||||
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
||||
fmeta.addEffect(effect);
|
||||
stack.setItemMeta(fmeta);
|
||||
builder = FireworkEffect.builder();
|
||||
}
|
||||
|
||||
List<Color> primaryColors = new ArrayList<Color>();
|
||||
String[] colors = split[1].split(",");
|
||||
for (String color : colors)
|
||||
{
|
||||
if (colorMap.containsKey(color.toUpperCase()))
|
||||
{
|
||||
validFirework = true;
|
||||
primaryColors.add(colorMap.get(color.toUpperCase()).getFireworkColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("fireworkSyntax"));
|
||||
throw new Exception(_("invalidFireworkFormat", split[1], split[0]));
|
||||
|
||||
}
|
||||
}
|
||||
builder.withColor(primaryColors);
|
||||
}
|
||||
else if (split[0].equalsIgnoreCase("shape") || split[0].equalsIgnoreCase("type") || (allowShortName && (split[0].equalsIgnoreCase("s") || split[0].equalsIgnoreCase("t"))))
|
||||
{
|
||||
FireworkEffect.Type finalEffect = null;
|
||||
split[1] = (split[1].equalsIgnoreCase("large") ? "BALL_LARGE" : split[1]);
|
||||
if (fireworkShape.containsKey(split[1].toUpperCase()))
|
||||
{
|
||||
finalEffect = fireworkShape.get(split[1].toUpperCase());
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("fireworkSyntax"));
|
||||
throw new Exception(_("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
if (finalEffect != null)
|
||||
{
|
||||
builder.with(finalEffect);
|
||||
}
|
||||
}
|
||||
else if (split[0].equalsIgnoreCase("fade") || (allowShortName && split[0].equalsIgnoreCase("f")))
|
||||
{
|
||||
List<Color> fadeColors = new ArrayList<Color>();
|
||||
String[] colors = split[1].split(",");
|
||||
for (String color : colors)
|
||||
{
|
||||
if (colorMap.containsKey(color.toUpperCase()))
|
||||
{
|
||||
fadeColors.add(colorMap.get(color.toUpperCase()).getFireworkColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("fireworkSyntax"));
|
||||
throw new Exception(_("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
}
|
||||
if (!fadeColors.isEmpty())
|
||||
{
|
||||
builder.withFade(fadeColors);
|
||||
}
|
||||
}
|
||||
else if (split[0].equalsIgnoreCase("effect") || (allowShortName && split[0].equalsIgnoreCase("e")))
|
||||
{
|
||||
String[] effects = split[1].split(",");
|
||||
for (String effect : effects)
|
||||
{
|
||||
if (effect.equalsIgnoreCase("twinkle"))
|
||||
{
|
||||
builder.flicker(true);
|
||||
}
|
||||
else if (effect.equalsIgnoreCase("trail"))
|
||||
{
|
||||
builder.trail(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("fireworkSyntax"));
|
||||
throw new Exception(_("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseEnchantmentStrings(final CommandSender user, final boolean allowUnsafe, final String[] split) throws Exception
|
||||
{
|
||||
Enchantment enchantment = getEnchantment(null, split[0]);
|
||||
|
||||
int level = -1;
|
||||
if (split.length > 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
level = Integer.parseInt(split[1]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
level = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel()))
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
}
|
||||
addEnchantment(user, allowUnsafe, enchantment, level);
|
||||
}
|
||||
|
||||
public void addEnchantment(final CommandSender user, final boolean allowUnsafe, final Enchantment enchantment, final int level) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
if (stack.getType().equals(Material.ENCHANTED_BOOK))
|
||||
{
|
||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta)stack.getItemMeta();
|
||||
if (level == 0)
|
||||
{
|
||||
meta.removeStoredEnchant(enchantment);
|
||||
}
|
||||
else
|
||||
{
|
||||
meta.addStoredEnchant(enchantment, level, allowUnsafe);
|
||||
}
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
else // all other material types besides ENCHANTED_BOOK
|
||||
{
|
||||
if (level == 0)
|
||||
{
|
||||
stack.removeEnchantment(enchantment);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (allowUnsafe)
|
||||
{
|
||||
stack.addUnsafeEnchantment(enchantment, level);
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.addEnchantment(enchantment, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Properly TL this
|
||||
public Enchantment getEnchantment(final User user, final String name) throws Exception
|
||||
{
|
||||
final Enchantment enchantment = Enchantments.getByName(name);
|
||||
if (enchantment == null)
|
||||
{
|
||||
throw new Exception(_("enchantmentNotFound") + ": " + name);
|
||||
}
|
||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
if (user != null && !user.isAuthorized("essentials.enchant." + enchantmentName))
|
||||
{
|
||||
throw new Exception(_("enchantmentPerm", enchantmentName));
|
||||
}
|
||||
return enchantment;
|
||||
}
|
||||
}
|
@@ -6,11 +6,14 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
// Suffixes can be appended on the end of a mob name to make it plural
|
||||
// Entities without a suffix, will default to 's'
|
||||
public enum Mob
|
||||
{
|
||||
CHICKEN("Chicken", Enemies.FRIENDLY, EntityType.CHICKEN),
|
||||
@@ -37,8 +40,14 @@ public enum Mob
|
||||
MAGMACUBE("MagmaCube", Enemies.ENEMY, EntityType.MAGMA_CUBE),
|
||||
SNOWMAN("Snowman", Enemies.FRIENDLY, "", EntityType.SNOWMAN),
|
||||
OCELOT("Ocelot", Enemies.NEUTRAL, EntityType.OCELOT),
|
||||
IRONGOLEM("IronGolem", Enemies.NEUTRAL, EntityType.IRON_GOLEM);
|
||||
|
||||
IRONGOLEM("IronGolem", Enemies.NEUTRAL, EntityType.IRON_GOLEM),
|
||||
WITHER("Wither", Enemies.ENEMY, EntityType.WITHER),
|
||||
BAT("Bat", Enemies.FRIENDLY, EntityType.BAT),
|
||||
WITCH("Witch", Enemies.ENEMY, EntityType.WITCH),
|
||||
BOAT("Boat", Enemies.NEUTRAL, EntityType.BOAT),
|
||||
MINECART("Minecart", Enemies.NEUTRAL, EntityType.MINECART),
|
||||
ENDERCRYSTAL("EnderCrystal", Enemies.NEUTRAL, EntityType.ENDER_CRYSTAL),
|
||||
EXPERIENCEORB("ExperienceOrb", Enemies.NEUTRAL, EntityType.EXPERIENCE_ORB);
|
||||
public static final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
private Mob(String n, Enemies en, String s, EntityType type)
|
||||
@@ -68,14 +77,20 @@ public enum Mob
|
||||
hashMap.put(mob.name.toLowerCase(Locale.ENGLISH), mob);
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> getMobList() {
|
||||
|
||||
public static Set<String> getMobList()
|
||||
{
|
||||
return Collections.unmodifiableSet(hashMap.keySet());
|
||||
}
|
||||
|
||||
public LivingEntity spawn(final Player player, final Server server, final Location loc) throws MobException
|
||||
public Entity spawn(final Player player, final Server server, final Location loc) throws MobException
|
||||
{
|
||||
final LivingEntity entity = player.getWorld().spawn(loc, (Class<? extends LivingEntity>)this.bukkitType.getEntityClass());
|
||||
return spawn(player.getWorld(), server, loc);
|
||||
}
|
||||
|
||||
public Entity spawn(final World world, final Server server, final Location loc) throws MobException
|
||||
{
|
||||
final Entity entity = world.spawn(loc, (Class<? extends Entity>)this.bukkitType.getEntityClass());
|
||||
if (entity == null)
|
||||
{
|
||||
logger.log(Level.WARNING, _("unableToSpawnMob"));
|
||||
|
@@ -11,11 +11,8 @@ import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.inventory.InventoryView.Property;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.map.MapView;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@@ -841,6 +838,12 @@ public class OfflinePlayer implements Player
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBedSpawnLocation(Location lctn, boolean force)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playEffect(EntityEffect ee)
|
||||
{
|
||||
@@ -1105,4 +1108,64 @@ public class OfflinePlayer implements Player
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveExpLevels(int i)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRemoveWhenFarAway()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemoveWhenFarAway(boolean bln)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityEquipment getEquipment()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCanPickupItems(boolean bln)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getCanPickupItems()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation(Location lctn)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexturePack(String string)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxHealth(int i)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetMaxHealth()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -189,6 +190,11 @@ public class Settings implements ISettings
|
||||
final ConfigurationSection newSection = new MemoryConfiguration();
|
||||
for (String command : section.getKeys(false))
|
||||
{
|
||||
PluginCommand cmd = ess.getServer().getPluginCommand(command);
|
||||
if (command.charAt(0) == '/')
|
||||
{
|
||||
ess.getLogger().warning("Invalid command cost. '" + command + "' should not start with '/'.");
|
||||
}
|
||||
if (section.isDouble(command))
|
||||
{
|
||||
newSection.set(command.toLowerCase(Locale.ENGLISH), section.getDouble(command));
|
||||
@@ -197,6 +203,24 @@ public class Settings implements ISettings
|
||||
{
|
||||
newSection.set(command.toLowerCase(Locale.ENGLISH), (double)section.getInt(command));
|
||||
}
|
||||
else if (section.isString(command))
|
||||
{
|
||||
String costString = section.getString(command);
|
||||
try
|
||||
{
|
||||
double cost = Double.parseDouble(costString.trim().replace(getCurrencySymbol(), "").replaceAll("\\W", ""));
|
||||
newSection.set(command.toLowerCase(Locale.ENGLISH), cost);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
ess.getLogger().warning("Invalid command cost for: " + command + " (" + costString + ")");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ess.getLogger().warning("Invalid command cost for: " + command);
|
||||
}
|
||||
}
|
||||
return newSection;
|
||||
}
|
||||
@@ -213,6 +237,31 @@ public class Settings implements ISettings
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
private Set<String> socialSpyCommands = new HashSet<String>();
|
||||
|
||||
public Set<String> _getSocialSpyCommands()
|
||||
{
|
||||
Set<String> socialspyCommands = new HashSet<String>();
|
||||
|
||||
if (config.isConfigurationSection("socialspy-commands"))
|
||||
{
|
||||
for (String c : config.getStringList("socialspy-commands"))
|
||||
{
|
||||
socialspyCommands.add(c.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
socialspyCommands.addAll(Arrays.asList("msg", "r", "mail", "m", "whisper", "emsg", "t", "tell", "er", "reply", "ereply", "email", "action", "describe", "eme", "eaction", "edescribe", "etell", "ewhisper", "pm"));
|
||||
}
|
||||
|
||||
return socialspyCommands;
|
||||
}
|
||||
|
||||
public Set<String> getSocialSpyCommands()
|
||||
{
|
||||
return socialSpyCommands;
|
||||
}
|
||||
private String nicknamePrefix = "~";
|
||||
|
||||
private String _getNicknamePrefix()
|
||||
@@ -419,7 +468,8 @@ public class Settings implements ISettings
|
||||
teleportInvulnerability = _isTeleportInvulnerability();
|
||||
disableItemPickupWhileAfk = _getDisableItemPickupWhileAfk();
|
||||
registerBackInListener = _registerBackInListener();
|
||||
cancelAfkOnMove = _cancelAfkOnMove();
|
||||
cancelAfkOnInteract = _cancelAfkOnInteract();
|
||||
cancelAfkOnMove = _cancelAfkOnMove() && cancelAfkOnInteract;
|
||||
getFreezeAfkPlayers = _getFreezeAfkPlayers();
|
||||
itemSpawnBl = _getItemSpawnBlacklist();
|
||||
loginAttackDelay = _getLoginAttackDelay();
|
||||
@@ -438,6 +488,7 @@ public class Settings implements ISettings
|
||||
disableSuffix = _disableSuffix();
|
||||
chatRadius = _getChatRadius();
|
||||
commandCosts = _getCommandCosts();
|
||||
socialSpyCommands = _getSocialSpyCommands();
|
||||
warnOnBuildDisallow = _warnOnBuildDisallow();
|
||||
mailsPerMinute = _getMailsPerMinute();
|
||||
}
|
||||
@@ -558,6 +609,8 @@ public class Settings implements ISettings
|
||||
return config.getString("locale", "");
|
||||
}
|
||||
|
||||
//This method should always only return one character due to the implementation of the calling methods
|
||||
//If you need to use a string currency, for example "coins", use the translation key 'currency'.
|
||||
@Override
|
||||
public String getCurrencySymbol()
|
||||
{
|
||||
@@ -779,6 +832,18 @@ public class Settings implements ISettings
|
||||
{
|
||||
return config.getBoolean("cancel-afk-on-move", true);
|
||||
}
|
||||
private boolean cancelAfkOnInteract;
|
||||
|
||||
@Override
|
||||
public boolean cancelAfkOnInteract()
|
||||
{
|
||||
return cancelAfkOnInteract;
|
||||
}
|
||||
|
||||
private boolean _cancelAfkOnInteract()
|
||||
{
|
||||
return config.getBoolean("cancel-afk-on-interact", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areDeathMessagesEnabled()
|
||||
@@ -805,6 +870,12 @@ public class Settings implements ISettings
|
||||
return config.getBoolean("repair-enchanted", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowUnsafeEnchantments()
|
||||
{
|
||||
return config.getBoolean("unsafe-enchantments", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorldTeleportPermissions()
|
||||
{
|
||||
@@ -871,7 +942,7 @@ public class Settings implements ISettings
|
||||
@Override
|
||||
public long getTpaAcceptCancellation()
|
||||
{
|
||||
return config.getLong("tpa-accept-cancellation", 0);
|
||||
return config.getLong("tpa-accept-cancellation", 120);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -944,15 +1015,22 @@ public class Settings implements ISettings
|
||||
double maxSpeed = config.getDouble("max-walk-speed", 0.8);
|
||||
return maxSpeed > 1.0 ? 1.0 : Math.abs(maxSpeed);
|
||||
}
|
||||
|
||||
private int mailsPerMinute;
|
||||
|
||||
private int _getMailsPerMinute() {
|
||||
private int _getMailsPerMinute()
|
||||
{
|
||||
return config.getInt("mails-per-minute", 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMailsPerMinute()
|
||||
{
|
||||
return mailsPerMinute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxTempban()
|
||||
{
|
||||
return config.getLong("max-tempban-time", -1);
|
||||
}
|
||||
}
|
||||
|
295
Essentials/src/com/earth2me/essentials/SpawnMob.java
Normal file
295
Essentials/src/com/earth2me/essentials/SpawnMob.java
Normal file
@@ -0,0 +1,295 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Mob.MobException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||
import org.bukkit.material.Colorable;
|
||||
|
||||
|
||||
public class SpawnMob
|
||||
{
|
||||
public static String mobList(final User user)
|
||||
{
|
||||
final Set<String> mobList = Mob.getMobList();
|
||||
final Set<String> availableList = new HashSet<String>();
|
||||
for (String mob : mobList)
|
||||
{
|
||||
if (user.isAuthorized("essentials.spawnmob." + mob.toLowerCase()))
|
||||
{
|
||||
availableList.add(mob);
|
||||
}
|
||||
}
|
||||
if (availableList.isEmpty())
|
||||
{
|
||||
availableList.add(_("none"));
|
||||
}
|
||||
return Util.joinList(availableList);
|
||||
}
|
||||
|
||||
public static String[] mobData(final String mobString)
|
||||
{
|
||||
String[] returnString = new String[4];
|
||||
|
||||
final String[] parts = mobString.split(",");
|
||||
String[] mobParts = parts[0].split(":");
|
||||
|
||||
returnString[0] = mobParts[0];
|
||||
if (mobParts.length == 2)
|
||||
{
|
||||
returnString[1] = mobParts[1];
|
||||
}
|
||||
|
||||
if (parts.length > 1)
|
||||
{
|
||||
String[] mountParts = parts[1].split(":");
|
||||
returnString[2] = mountParts[0];
|
||||
if (mountParts.length == 2)
|
||||
{
|
||||
returnString[3] = mountParts[1];
|
||||
}
|
||||
}
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
// This method spawns a mob where the user is looking, owned by user
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final User user, final String[] Data, int mobCount) throws Exception
|
||||
{
|
||||
final Block block = Util.getTarget(user).getBlock();
|
||||
if (block == null)
|
||||
{
|
||||
throw new Exception(_("unableToSpawnMob"));
|
||||
}
|
||||
spawnmob(ess, server, user, user, block.getLocation(), Data, mobCount);
|
||||
}
|
||||
|
||||
// This method spawns a mob at loc, owned by noone
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final Location loc, final String[] Data, int mobCount) throws Exception
|
||||
{
|
||||
spawnmob(ess, server, sender, null, loc, Data, mobCount);
|
||||
}
|
||||
|
||||
// This method spawns a mob at target, owned by target
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final User target, final String[] Data, int mobCount) throws Exception
|
||||
{
|
||||
spawnmob(ess, server, sender, target, target.getLocation(), Data, mobCount);
|
||||
}
|
||||
|
||||
// This method spawns a mob at loc, owned by target
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final User target, final Location loc, final String[] Data, int mobCount) throws Exception
|
||||
{
|
||||
final Location sloc = Util.getSafeDestination(loc);
|
||||
final String mobType = Data[0];
|
||||
final String mobData = Data[1];
|
||||
final String mountType = Data[2];
|
||||
final String mountData = Data[3];
|
||||
|
||||
Mob mob = Mob.fromName(mobType);
|
||||
Mob mobMount = null;
|
||||
|
||||
checkSpawnable(ess, sender, mob);
|
||||
|
||||
if (mountType != null)
|
||||
{
|
||||
mobMount = Mob.fromName(mountType);
|
||||
checkSpawnable(ess, sender, mobMount);
|
||||
}
|
||||
|
||||
int serverLimit = ess.getSettings().getSpawnMobLimit();
|
||||
if (mobCount > serverLimit)
|
||||
{
|
||||
mobCount = serverLimit;
|
||||
sender.sendMessage(_("mobSpawnLimit"));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < mobCount; i++)
|
||||
{
|
||||
spawnMob(ess, server, sender, target, sloc, mob, mobData, mobMount, mountData);
|
||||
}
|
||||
sender.sendMessage(mobCount + " " + mob.name.toLowerCase(Locale.ENGLISH) + mob.suffix + " " + _("spawned"));
|
||||
}
|
||||
catch (MobException e1)
|
||||
{
|
||||
throw new Exception(_("unableToSpawnMob"), e1);
|
||||
}
|
||||
catch (NumberFormatException e2)
|
||||
{
|
||||
throw new Exception(_("numberRequired"), e2);
|
||||
}
|
||||
catch (NullPointerException np)
|
||||
{
|
||||
throw new Exception(_("soloMob"), np);
|
||||
}
|
||||
}
|
||||
|
||||
private static void spawnMob(final IEssentials ess, final Server server, final CommandSender sender, final User target, final Location sloc, Mob mob, String mobData, Mob mobMount, String mountData) throws Exception
|
||||
{
|
||||
Entity spawnedMob = mob.spawn(sloc.getWorld(), server, sloc);
|
||||
Entity spawnedMount = null;
|
||||
|
||||
if (mobMount != null)
|
||||
{
|
||||
spawnedMount = mobMount.spawn(sloc.getWorld(), server, sloc);
|
||||
spawnedMob.setPassenger(spawnedMount);
|
||||
}
|
||||
if (mobData != null)
|
||||
{
|
||||
changeMobData(mob.getType(), spawnedMob, mobData, target);
|
||||
}
|
||||
if (spawnedMount != null && mountData != null)
|
||||
{
|
||||
changeMobData(mobMount.getType(), spawnedMount, mountData, target);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkSpawnable(IEssentials ess, CommandSender sender, Mob mob) throws Exception
|
||||
{
|
||||
if (mob == null)
|
||||
{
|
||||
throw new Exception(_("invalidMob"));
|
||||
}
|
||||
|
||||
if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH)))
|
||||
{
|
||||
throw new Exception(_("disabledToSpawnMob"));
|
||||
}
|
||||
|
||||
if (sender instanceof User && !((User)sender).isAuthorized("essentials.spawnmob." + mob.name.toLowerCase()))
|
||||
{
|
||||
throw new Exception(_("noPermToSpawnMob"));
|
||||
}
|
||||
}
|
||||
|
||||
private static void changeMobData(final EntityType type, final Entity spawned, String data, final User target) throws Exception
|
||||
{
|
||||
data = data.toLowerCase(Locale.ENGLISH);
|
||||
|
||||
if (spawned instanceof Slime)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Slime)spawned).setSize(Integer.parseInt(data));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(_("slimeMalformedSize"), e);
|
||||
}
|
||||
}
|
||||
|
||||
if ((spawned instanceof Ageable) && data.contains("baby"))
|
||||
{
|
||||
((Ageable)spawned).setBaby();
|
||||
data = data.replace("baby", "");
|
||||
}
|
||||
|
||||
if (spawned instanceof Colorable)
|
||||
{
|
||||
final String color = data.toUpperCase(Locale.ENGLISH);
|
||||
try
|
||||
{
|
||||
if (color.equals("RANDOM"))
|
||||
{
|
||||
final Random rand = new Random();
|
||||
((Colorable)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]);
|
||||
}
|
||||
else if (color.length() > 1)
|
||||
{
|
||||
((Colorable)spawned).setColor(DyeColor.valueOf(color));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(_("sheepMalformedColor"), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (spawned instanceof Tameable && data.contains("tamed") && target != null)
|
||||
{
|
||||
final Tameable tameable = ((Tameable)spawned);
|
||||
tameable.setTamed(true);
|
||||
tameable.setOwner(target.getBase());
|
||||
data = data.replace("tamed", "");
|
||||
}
|
||||
|
||||
if (type == EntityType.WOLF)
|
||||
{
|
||||
if (data.contains("angry"))
|
||||
{
|
||||
((Wolf)spawned).setAngry(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == EntityType.CREEPER && data.contains("powered"))
|
||||
{
|
||||
((Creeper)spawned).setPowered(true);
|
||||
}
|
||||
|
||||
if (type == EntityType.OCELOT)
|
||||
{
|
||||
if (data.contains("siamese") || data.contains("white"))
|
||||
{
|
||||
((Ocelot)spawned).setCatType(Ocelot.Type.SIAMESE_CAT);
|
||||
}
|
||||
else if (data.contains("red") || data.contains("orange") || data.contains("tabby"))
|
||||
{
|
||||
((Ocelot)spawned).setCatType(Ocelot.Type.RED_CAT);
|
||||
}
|
||||
else if (data.contains("black") || data.contains("tuxedo"))
|
||||
{
|
||||
((Ocelot)spawned).setCatType(Ocelot.Type.BLACK_CAT);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == EntityType.VILLAGER)
|
||||
{
|
||||
for (Villager.Profession prof : Villager.Profession.values())
|
||||
{
|
||||
if (data.contains(prof.toString().toLowerCase(Locale.ENGLISH)))
|
||||
{
|
||||
((Villager)spawned).setProfession(prof);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (spawned instanceof Zombie)
|
||||
{
|
||||
if (data.contains("villager"))
|
||||
{
|
||||
((Zombie)spawned).setVillager(true);
|
||||
}
|
||||
if (data.contains("baby"))
|
||||
{
|
||||
((Zombie)spawned).setBaby(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == EntityType.SKELETON)
|
||||
{
|
||||
if (data.contains("wither"))
|
||||
{
|
||||
((Skeleton)spawned).setSkeletonType(SkeletonType.WITHER);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == EntityType.EXPERIENCE_ORB)
|
||||
{
|
||||
if (Util.isInt(data))
|
||||
{
|
||||
((ExperienceOrb)spawned).setExperience(Integer.parseInt(data));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -24,13 +24,13 @@ public class TNTExplodeListener implements Listener, Runnable
|
||||
if (!enabled)
|
||||
{
|
||||
enabled = true;
|
||||
timer = ess.scheduleSyncDelayedTask(this, 1000);
|
||||
timer = ess.scheduleSyncDelayedTask(this, 200);
|
||||
return;
|
||||
}
|
||||
if (timer != -1)
|
||||
{
|
||||
ess.getScheduler().cancelTask(timer);
|
||||
timer = ess.scheduleSyncDelayedTask(this, 1000);
|
||||
timer = ess.scheduleSyncDelayedTask(this, 200);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
@@ -14,30 +15,30 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
public class Teleport implements Runnable, ITeleport
|
||||
{
|
||||
private static final double MOVE_CONSTANT = 0.3;
|
||||
|
||||
|
||||
|
||||
|
||||
private class Target
|
||||
{
|
||||
private final Location location;
|
||||
private final String name;
|
||||
|
||||
|
||||
Target(Location location)
|
||||
{
|
||||
this.location = location;
|
||||
this.name = null;
|
||||
}
|
||||
|
||||
|
||||
Target(Player entity)
|
||||
{
|
||||
this.name = entity.getName();
|
||||
this.location = null;
|
||||
}
|
||||
|
||||
|
||||
public Location getLocation()
|
||||
{
|
||||
if (this.name != null)
|
||||
{
|
||||
|
||||
|
||||
return ess.getServer().getPlayerExact(name).getLocation();
|
||||
}
|
||||
return location;
|
||||
@@ -56,17 +57,18 @@ public class Teleport implements Runnable, ITeleport
|
||||
private long initY;
|
||||
private long initZ;
|
||||
private Target teleportTarget;
|
||||
private boolean respawn;
|
||||
private Trade chargeFor;
|
||||
private final IEssentials ess;
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
private TeleportCause cause;
|
||||
|
||||
|
||||
private void initTimer(long delay, Target target, Trade chargeFor, TeleportCause cause)
|
||||
{
|
||||
initTimer(delay, user, target, chargeFor, cause);
|
||||
initTimer(delay, user, target, chargeFor, cause, false);
|
||||
}
|
||||
|
||||
private void initTimer(long delay, IUser teleportUser, Target target, Trade chargeFor, TeleportCause cause)
|
||||
|
||||
private void initTimer(long delay, IUser teleportUser, Target target, Trade chargeFor, TeleportCause cause, boolean respawn)
|
||||
{
|
||||
this.started = System.currentTimeMillis();
|
||||
this.tpdelay = delay;
|
||||
@@ -78,12 +80,13 @@ public class Teleport implements Runnable, ITeleport
|
||||
this.teleportTarget = target;
|
||||
this.chargeFor = chargeFor;
|
||||
this.cause = cause;
|
||||
this.respawn = respawn;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
|
||||
|
||||
if (user == null || !user.isOnline() || user.getLocation() == null)
|
||||
{
|
||||
cancel(false);
|
||||
@@ -94,7 +97,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
cancel(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!user.isAuthorized("essentials.teleport.timer.move")
|
||||
&& (Math.round(teleportUser.getLocation().getX() * MOVE_CONSTANT) != initX
|
||||
|| Math.round(teleportUser.getLocation().getY() * MOVE_CONSTANT) != initY
|
||||
@@ -115,8 +118,14 @@ public class Teleport implements Runnable, ITeleport
|
||||
teleportUser.sendMessage(_("teleportationCommencing"));
|
||||
try
|
||||
{
|
||||
|
||||
teleportUser.getTeleport().now(teleportTarget, cause);
|
||||
if (respawn)
|
||||
{
|
||||
teleportUser.getTeleport().respawn(cause);
|
||||
}
|
||||
else
|
||||
{
|
||||
teleportUser.getTeleport().now(teleportTarget, cause);
|
||||
}
|
||||
cancel(false);
|
||||
if (chargeFor != null)
|
||||
{
|
||||
@@ -138,13 +147,13 @@ public class Teleport implements Runnable, ITeleport
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Teleport(IUser user, IEssentials ess)
|
||||
{
|
||||
this.user = user;
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
|
||||
public void cooldown(boolean check) throws Exception
|
||||
{
|
||||
final Calendar time = new GregorianCalendar();
|
||||
@@ -160,7 +169,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
|
||||
// When was the last teleport used?
|
||||
final Long lastTime = user.getLastTeleportTimestamp();
|
||||
|
||||
|
||||
if (lastTime > time.getTimeInMillis())
|
||||
{
|
||||
// This is to make sure time didn't get messed up on last kit use.
|
||||
@@ -217,7 +226,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
}
|
||||
now(new Target(loc), cause);
|
||||
}
|
||||
|
||||
|
||||
public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception
|
||||
{
|
||||
if (cooldown)
|
||||
@@ -226,7 +235,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
}
|
||||
now(new Target(entity), cause);
|
||||
}
|
||||
|
||||
|
||||
private void now(Target target, TeleportCause cause) throws Exception
|
||||
{
|
||||
cancel(false);
|
||||
@@ -241,21 +250,21 @@ public class Teleport implements Runnable, ITeleport
|
||||
{
|
||||
teleport(loc, chargeFor, TeleportCause.PLUGIN);
|
||||
}
|
||||
|
||||
|
||||
public void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
teleport(new Target(loc), chargeFor, cause);
|
||||
}
|
||||
|
||||
|
||||
public void teleport(Player entity, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
teleport(new Target(entity), chargeFor, cause);
|
||||
}
|
||||
|
||||
|
||||
private void teleport(Target target, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
|
||||
|
||||
if (chargeFor != null)
|
||||
{
|
||||
chargeFor.isAffordableFor(user);
|
||||
@@ -271,11 +280,11 @@ public class Teleport implements Runnable, ITeleport
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
cancel(false);
|
||||
warnUser(user, delay);
|
||||
initTimer((long)(delay * 1000.0), target, chargeFor, cause);
|
||||
|
||||
|
||||
teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
|
||||
}
|
||||
|
||||
@@ -283,9 +292,8 @@ public class Teleport implements Runnable, ITeleport
|
||||
public void teleportToMe(User otherUser, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
Target target = new Target(user);
|
||||
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
|
||||
|
||||
if (chargeFor != null)
|
||||
{
|
||||
chargeFor.isAffordableFor(user);
|
||||
@@ -301,14 +309,13 @@ public class Teleport implements Runnable, ITeleport
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
cancel(false);
|
||||
warnUser(otherUser, delay);
|
||||
initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause);
|
||||
|
||||
initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause, false);
|
||||
teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
|
||||
}
|
||||
|
||||
|
||||
private void warnUser(final IUser user, final double delay)
|
||||
{
|
||||
Calendar c = new GregorianCalendar();
|
||||
@@ -319,12 +326,48 @@ public class Teleport implements Runnable, ITeleport
|
||||
|
||||
//The respawn function is a wrapper used to handle tp fallback, on /jail and /home
|
||||
public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
if (chargeFor != null)
|
||||
{
|
||||
chargeFor.isAffordableFor(user);
|
||||
}
|
||||
cooldown(true);
|
||||
if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass"))
|
||||
{
|
||||
cooldown(false);
|
||||
respawn(cause);
|
||||
if (chargeFor != null)
|
||||
{
|
||||
chargeFor.charge(user);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cancel(false);
|
||||
warnUser(user, delay);
|
||||
initTimer((long)(delay * 1000.0), user, null, chargeFor, cause, true);
|
||||
teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
|
||||
}
|
||||
|
||||
public void respawn(TeleportCause cause) throws Exception
|
||||
{
|
||||
final Player player = user.getBase();
|
||||
final Location bed = player.getBedSpawnLocation();
|
||||
final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, bed == null ? player.getWorld().getSpawnLocation() : bed, bed != null);
|
||||
ess.getServer().getPluginManager().callEvent(pre);
|
||||
teleport(new Target(pre.getRespawnLocation()), chargeFor, cause);
|
||||
Location bed = player.getBedSpawnLocation();
|
||||
if (bed != null)
|
||||
{
|
||||
now(new Target(bed), cause);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
ess.getLogger().info("Could not find bed spawn, forcing respawn event.");
|
||||
}
|
||||
final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false);
|
||||
ess.getServer().getPluginManager().callEvent(pre);
|
||||
now(new Target(pre.getRespawnLocation()), cause);
|
||||
}
|
||||
}
|
||||
|
||||
//The warp function is a wrapper used to teleport a player to a /warp
|
||||
@@ -332,7 +375,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
{
|
||||
Location loc = ess.getWarps().getWarp(warp);
|
||||
user.sendMessage(_("warpingTo", warp));
|
||||
teleport(new Target(loc), chargeFor, cause);
|
||||
teleport(new Target(loc), chargeFor, cause);
|
||||
}
|
||||
|
||||
//The back function is a wrapper used to teleport a player /back to their previous location.
|
||||
|
@@ -77,7 +77,7 @@ public class Trade
|
||||
}
|
||||
|
||||
if (getItemStack() != null
|
||||
&& !InventoryWorkaround.containsItem(user.getInventory(), true, true, itemStack))
|
||||
&& !user.getInventory().containsAtLeast(itemStack, itemStack.getAmount()))
|
||||
{
|
||||
throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public class Trade
|
||||
{
|
||||
if (dropItems)
|
||||
{
|
||||
final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItem(user.getInventory(), true, getItemStack());
|
||||
final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItems(user.getInventory(), getItemStack());
|
||||
final Location loc = user.getLocation();
|
||||
for (ItemStack itemStack : leftOver.values())
|
||||
{
|
||||
@@ -137,7 +137,7 @@ public class Trade
|
||||
}
|
||||
else
|
||||
{
|
||||
success = InventoryWorkaround.addAllItems(user.getInventory(), true, getItemStack());
|
||||
success = InventoryWorkaround.addAllItems(user.getInventory(), getItemStack());
|
||||
}
|
||||
user.updateInventory();
|
||||
}
|
||||
@@ -165,11 +165,11 @@ public class Trade
|
||||
}
|
||||
if (getItemStack() != null)
|
||||
{
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, true, itemStack))
|
||||
if (!user.getInventory().containsAtLeast(itemStack, itemStack.getAmount()))
|
||||
{
|
||||
throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
||||
}
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, true, getItemStack());
|
||||
user.getInventory().removeItem(getItemStack());
|
||||
user.updateInventory();
|
||||
}
|
||||
if (command != null)
|
||||
|
@@ -12,6 +12,8 @@ import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
|
||||
public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
@@ -29,6 +31,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
private boolean rightClickJump = false;
|
||||
private transient Location afkPosition = null;
|
||||
private boolean invSee = false;
|
||||
private boolean recipeSee = false;
|
||||
private boolean enderSee = false;
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
@@ -70,8 +73,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isAuthorizedCheck(final String node)
|
||||
|
||||
private boolean isAuthorizedCheck(final String node)
|
||||
{
|
||||
|
||||
if (base instanceof OfflinePlayer)
|
||||
@@ -79,11 +82,6 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isJailed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return ess.getPermissionsHandler().hasPermission(base, node);
|
||||
@@ -255,6 +253,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
{
|
||||
setLastLocation(getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogoutLocation()
|
||||
{
|
||||
setLogoutLocation(getLocation());
|
||||
}
|
||||
|
||||
public void requestTeleport(final User player, final boolean here)
|
||||
{
|
||||
@@ -532,13 +536,17 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
|
||||
public void updateActivity(final boolean broadcast)
|
||||
{
|
||||
if (isAfk())
|
||||
if (isAfk() && ess.getSettings().cancelAfkOnInteract())
|
||||
{
|
||||
setAfk(false);
|
||||
if (broadcast && !isHidden())
|
||||
{
|
||||
setDisplayNick();
|
||||
ess.broadcastMessage(this, _("userIsNotAway", getDisplayName()));
|
||||
final String msg = _("userIsNotAway", getDisplayName());
|
||||
if (!msg.isEmpty())
|
||||
{
|
||||
ess.broadcastMessage(this, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
lastActivity = System.currentTimeMillis();
|
||||
@@ -571,7 +579,11 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
if (!isHidden())
|
||||
{
|
||||
setDisplayNick();
|
||||
ess.broadcastMessage(this, _("userIsAway", getDisplayName()));
|
||||
final String msg = _("userIsAway", getDisplayName());
|
||||
if (!msg.isEmpty())
|
||||
{
|
||||
ess.broadcastMessage(this, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -681,6 +693,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
}
|
||||
setHidden(true);
|
||||
ess.getVanishedPlayers().add(getName());
|
||||
if (isAuthorized("essentials.vanish.effect"))
|
||||
{
|
||||
this.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -690,6 +706,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
}
|
||||
setHidden(false);
|
||||
ess.getVanishedPlayers().remove(getName());
|
||||
if (isAuthorized("essentials.vanish.effect"))
|
||||
{
|
||||
this.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -729,4 +749,20 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
{
|
||||
this.rightClickJump = rightClickJump;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIgnoreExempt()
|
||||
{
|
||||
return this.isAuthorized("essentials.chat.ignoreexempt");
|
||||
}
|
||||
|
||||
public boolean isRecipeSee()
|
||||
{
|
||||
return recipeSee;
|
||||
}
|
||||
|
||||
public void setRecipeSee(boolean recipeSee)
|
||||
{
|
||||
this.recipeSee = recipeSee;
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import java.io.File;
|
||||
import java.util.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -49,23 +48,24 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
lastHealTimestamp = _getLastHealTimestamp();
|
||||
jail = _getJail();
|
||||
mails = _getMails();
|
||||
teleportEnabled = getTeleportEnabled();
|
||||
ignoredPlayers = getIgnoredPlayers();
|
||||
teleportEnabled = _getTeleportEnabled();
|
||||
godmode = _getGodModeEnabled();
|
||||
muted = getMuted();
|
||||
muted = _getMuted();
|
||||
muteTimeout = _getMuteTimeout();
|
||||
jailed = getJailed();
|
||||
jailed = _getJailed();
|
||||
jailTimeout = _getJailTimeout();
|
||||
lastLogin = _getLastLogin();
|
||||
lastLogout = _getLastLogout();
|
||||
lastLoginAddress = _getLastLoginAddress();
|
||||
afk = getAfk();
|
||||
afk = _getAfk();
|
||||
geolocation = _getGeoLocation();
|
||||
isSocialSpyEnabled = _isSocialSpyEnabled();
|
||||
isNPC = _isNPC();
|
||||
arePowerToolsEnabled = _arePowerToolsEnabled();
|
||||
kitTimestamps = _getKitTimestamps();
|
||||
nickname = _getNickname();
|
||||
setIgnoredPlayers(_getIgnoredPlayers());
|
||||
logoutLocation = _getLogoutLocation();
|
||||
}
|
||||
private double money;
|
||||
|
||||
@@ -319,6 +319,37 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
config.setProperty("lastlocation", loc);
|
||||
config.save();
|
||||
}
|
||||
|
||||
private Location logoutLocation;
|
||||
|
||||
private Location _getLogoutLocation()
|
||||
{
|
||||
try
|
||||
{
|
||||
return config.getLocation("logoutlocation", getServer());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLogoutLocation()
|
||||
{
|
||||
return logoutLocation;
|
||||
}
|
||||
|
||||
public void setLogoutLocation(Location loc)
|
||||
{
|
||||
if (loc == null || loc.getWorld() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
logoutLocation = loc;
|
||||
config.setProperty("logoutlocation", loc);
|
||||
config.save();
|
||||
}
|
||||
|
||||
private long lastTeleportTimestamp;
|
||||
|
||||
private long _getLastTeleportTimestamp()
|
||||
@@ -415,7 +446,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
}
|
||||
private boolean teleportEnabled;
|
||||
|
||||
private boolean getTeleportEnabled()
|
||||
private boolean _getTeleportEnabled()
|
||||
{
|
||||
return config.getBoolean("teleportenabled", true);
|
||||
}
|
||||
@@ -447,7 +478,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
}
|
||||
private List<String> ignoredPlayers;
|
||||
|
||||
public List<String> getIgnoredPlayers()
|
||||
public List<String> _getIgnoredPlayers()
|
||||
{
|
||||
return Collections.synchronizedList(config.getStringList("ignore"));
|
||||
}
|
||||
@@ -480,7 +511,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
|
||||
public boolean isIgnoredPlayer(IUser user)
|
||||
{
|
||||
return (ignoredPlayers.contains(user.getName().toLowerCase(Locale.ENGLISH)) && !user.isAuthorized("essentials.chat.ignoreexempt"));
|
||||
return (ignoredPlayers.contains(user.getName().toLowerCase(Locale.ENGLISH)) && !user.isIgnoreExempt());
|
||||
}
|
||||
|
||||
public void setIgnoredPlayer(IUser user, boolean set)
|
||||
@@ -515,10 +546,15 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
}
|
||||
private boolean muted;
|
||||
|
||||
public boolean getMuted()
|
||||
public boolean _getMuted()
|
||||
{
|
||||
return config.getBoolean("muted", false);
|
||||
}
|
||||
|
||||
public boolean getMuted()
|
||||
{
|
||||
return muted;
|
||||
}
|
||||
|
||||
public boolean isMuted()
|
||||
{
|
||||
@@ -551,7 +587,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
}
|
||||
private boolean jailed;
|
||||
|
||||
private boolean getJailed()
|
||||
private boolean _getJailed()
|
||||
{
|
||||
return config.getBoolean("jailed", false);
|
||||
}
|
||||
@@ -678,7 +714,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
}
|
||||
private boolean afk;
|
||||
|
||||
private boolean getAfk()
|
||||
private boolean _getAfk()
|
||||
{
|
||||
return config.getBoolean("afk", false);
|
||||
}
|
||||
@@ -789,44 +825,44 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
{
|
||||
return config.getBoolean("powertoolsenabled", true);
|
||||
}
|
||||
private ConfigurationSection kitTimestamps;
|
||||
|
||||
private ConfigurationSection _getKitTimestamps()
|
||||
private Map<String, Long> kitTimestamps;
|
||||
|
||||
private Map<String, Long> _getKitTimestamps()
|
||||
{
|
||||
|
||||
|
||||
if (config.isConfigurationSection("timestamps.kits"))
|
||||
{
|
||||
final ConfigurationSection section = config.getConfigurationSection("timestamps.kits");
|
||||
final ConfigurationSection newSection = new MemoryConfiguration();
|
||||
final Map<String, Long> timestamps = new HashMap<String, Long>();
|
||||
for (String command : section.getKeys(false))
|
||||
{
|
||||
if (section.isLong(command))
|
||||
{
|
||||
newSection.set(command.toLowerCase(Locale.ENGLISH), section.getLong(command));
|
||||
timestamps.put(command.toLowerCase(Locale.ENGLISH), section.getLong(command));
|
||||
}
|
||||
else if (section.isInt(command))
|
||||
{
|
||||
newSection.set(command.toLowerCase(Locale.ENGLISH), (long)section.getInt(command));
|
||||
timestamps.put(command.toLowerCase(Locale.ENGLISH), (long)section.getInt(command));
|
||||
}
|
||||
}
|
||||
return newSection;
|
||||
return timestamps;
|
||||
}
|
||||
return new MemoryConfiguration();
|
||||
return new HashMap<String, Long>();
|
||||
}
|
||||
|
||||
|
||||
public long getKitTimestamp(String name)
|
||||
{
|
||||
name = name.replace('.', '_').replace('/', '_');
|
||||
if (kitTimestamps != null)
|
||||
if (kitTimestamps != null && kitTimestamps.containsKey(name))
|
||||
{
|
||||
return kitTimestamps.getLong(name, 0l);
|
||||
return kitTimestamps.get(name);
|
||||
}
|
||||
return 0l;
|
||||
}
|
||||
|
||||
public void setKitTimestamp(final String name, final long time)
|
||||
{
|
||||
kitTimestamps.set(name.toLowerCase(Locale.ENGLISH), time);
|
||||
kitTimestamps.put(name.toLowerCase(Locale.ENGLISH), time);
|
||||
config.setProperty("timestamps.kits", kitTimestamps);
|
||||
config.save();
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||
|
||||
private void loadAllUsersAsync(final IEssentials ess)
|
||||
{
|
||||
ess.scheduleAsyncDelayedTask(new Runnable()
|
||||
ess.runTaskAsynchronously(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
|
@@ -604,7 +604,8 @@ public class Util
|
||||
return input.substring(pos, pos + 2);
|
||||
}
|
||||
private static transient final Pattern URL_PATTERN = Pattern.compile("((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-z]{2,3}(?:/\\S+)?)");
|
||||
private static transient final Pattern VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]");
|
||||
private static transient final Pattern VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]?");
|
||||
private static transient final Pattern LOGCOLOR_PATTERN = Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]");
|
||||
private static transient final Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])");
|
||||
private static transient final Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-Fa-f]");
|
||||
private static transient final Pattern VANILLA_MAGIC_PATTERN = Pattern.compile("\u00A7+[Kk]");
|
||||
@@ -613,6 +614,7 @@ public class Util
|
||||
private static transient final Pattern REPLACE_MAGIC_PATTERN = Pattern.compile("&(k)");
|
||||
private static transient final Pattern REPLACE_FORMAT_PATTERN = Pattern.compile("&([l-or])");
|
||||
|
||||
//This method is used to simply strip the native minecraft colour codes
|
||||
public static String stripFormat(final String input)
|
||||
{
|
||||
if (input == null)
|
||||
@@ -622,6 +624,16 @@ public class Util
|
||||
return VANILLA_PATTERN.matcher(input).replaceAll("");
|
||||
}
|
||||
|
||||
public static String stripLogColorFormat(final String input)
|
||||
{
|
||||
if (input == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return LOGCOLOR_PATTERN.matcher(input).replaceAll("");
|
||||
}
|
||||
|
||||
//This method is used to simply replace the ess colour codes with minecraft ones, ie &c
|
||||
public static String replaceFormat(final String input)
|
||||
{
|
||||
if (input == null)
|
||||
@@ -631,20 +643,7 @@ public class Util
|
||||
return REPLACE_PATTERN.matcher(input).replaceAll("\u00a7$1");
|
||||
}
|
||||
|
||||
public static String blockURL(final String input)
|
||||
{
|
||||
if (input == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String text = URL_PATTERN.matcher(input).replaceAll("$1 $2");
|
||||
while (URL_PATTERN.matcher(text).find())
|
||||
{
|
||||
text = URL_PATTERN.matcher(text).replaceAll("$1 $2");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
//This is the general permission sensitive message format function, does not touch urls.
|
||||
public static String formatString(final IUser user, final String permBase, final String input)
|
||||
{
|
||||
if (input == null)
|
||||
@@ -679,6 +678,7 @@ public class Util
|
||||
return message;
|
||||
}
|
||||
|
||||
//This is the general permission sensitive message format function, checks for urls.
|
||||
public static String formatMessage(final IUser user, final String permBase, final String input)
|
||||
{
|
||||
if (input == null)
|
||||
@@ -692,6 +692,20 @@ public class Util
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
private static String blockURL(final String input)
|
||||
{
|
||||
if (input == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String text = URL_PATTERN.matcher(input).replaceAll("$1 $2");
|
||||
while (URL_PATTERN.matcher(text).find())
|
||||
{
|
||||
text = URL_PATTERN.matcher(text).replaceAll("$1 $2");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static String stripColor(final String input, final Pattern pattern)
|
||||
{
|
||||
|
@@ -32,12 +32,13 @@ public class Commandafk extends EssentialsCommand
|
||||
private void toggleAfk(User user)
|
||||
{
|
||||
user.setDisplayNick();
|
||||
String msg = "";
|
||||
if (!user.toggleAfk())
|
||||
{
|
||||
//user.sendMessage(_("markedAsNotAway"));
|
||||
if (!user.isHidden())
|
||||
{
|
||||
ess.broadcastMessage(user, _("userIsNotAway", user.getDisplayName()));
|
||||
msg = _("userIsNotAway", user.getDisplayName());
|
||||
}
|
||||
user.updateActivity(false);
|
||||
}
|
||||
@@ -46,8 +47,12 @@ public class Commandafk extends EssentialsCommand
|
||||
//user.sendMessage(_("markedAsAway"));
|
||||
if (!user.isHidden())
|
||||
{
|
||||
ess.broadcastMessage(user, _("userIsAway", user.getDisplayName()));
|
||||
msg = _("userIsAway", user.getDisplayName());
|
||||
}
|
||||
}
|
||||
if (!msg.isEmpty())
|
||||
{
|
||||
ess.broadcastMessage(user, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
//TODO: Remove op and replace with perm
|
||||
public class Commandbalancetop extends EssentialsCommand
|
||||
{
|
||||
public Commandbalancetop()
|
||||
@@ -63,7 +63,7 @@ public class Commandbalancetop extends EssentialsCommand
|
||||
{
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
ess.scheduleAsyncDelayedTask(new Viewer(sender, page, force));
|
||||
ess.runTaskAsynchronously(new Viewer(sender, page, force));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -71,7 +71,7 @@ public class Commandbalancetop extends EssentialsCommand
|
||||
{
|
||||
sender.sendMessage(_("orderBalances", ess.getUserMap().getUniqueUsers()));
|
||||
}
|
||||
ess.scheduleAsyncDelayedTask(new Viewer(sender, page, force));
|
||||
ess.runTaskAsynchronously(new Viewer(sender, page, force));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class Commandbalancetop extends EssentialsCommand
|
||||
cal.setTimeInMillis(cacheage);
|
||||
final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
sender.sendMessage(_("balanceTop", format.format(cal.getTime())));
|
||||
new TextPager(cache).showPage(Integer.toString(page), "", "balancetop", sender);
|
||||
new TextPager(cache).showPage(Integer.toString(page), null, "balancetop", sender);
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ public class Commandbalancetop extends EssentialsCommand
|
||||
{
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
ess.scheduleAsyncDelayedTask(viewer);
|
||||
ess.runTaskAsynchronously(viewer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ public class Commandbalancetop extends EssentialsCommand
|
||||
{
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
ess.scheduleAsyncDelayedTask(new Calculator(new Viewer(sender, page, force), force));
|
||||
ess.runTaskAsynchronously(new Calculator(new Viewer(sender, page, force), force));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import com.earth2me.essentials.Console;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.OfflinePlayer;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -57,21 +58,22 @@ public class Commandban extends EssentialsCommand
|
||||
String banReason;
|
||||
if (args.length > 1)
|
||||
{
|
||||
banReason = _("banFormat", getFinalArg(args, 1), senderName);
|
||||
banReason = Util.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
banReason = _("banFormat", _("defaultBanReason"), senderName);
|
||||
banReason = _("defaultBanReason");
|
||||
}
|
||||
|
||||
user.setBanReason(banReason);
|
||||
user.setBanReason(_("banFormat", banReason, senderName));
|
||||
user.setBanned(true);
|
||||
user.kickPlayer(banReason);
|
||||
user.setBanTimeout(0);
|
||||
user.kickPlayer(_("banFormat", banReason, senderName));
|
||||
|
||||
server.getLogger().log(Level.INFO, _("playerBanned", senderName, user.getName(), banReason));
|
||||
|
||||
if (nomatch) {
|
||||
sender.sendMessage(_("userUnknown", user.getName()));
|
||||
sender.sendMessage(_("userUnknown", args[0]));
|
||||
}
|
||||
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
|
@@ -0,0 +1,92 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
|
||||
public class Commandbook extends EssentialsCommand
|
||||
{
|
||||
public Commandbook()
|
||||
{
|
||||
super("book");
|
||||
}
|
||||
|
||||
//TODO: Translate this
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
final ItemStack item = user.getItemInHand();
|
||||
final String player = user.getName();
|
||||
if (item.getType() == Material.WRITTEN_BOOK)
|
||||
{
|
||||
BookMeta bmeta = (BookMeta)item.getItemMeta();
|
||||
|
||||
if (args.length > 1 && args[0].equalsIgnoreCase("author"))
|
||||
{
|
||||
if (user.isAuthorized("essentals.book.author"))
|
||||
{
|
||||
bmeta.setAuthor(args[1]);
|
||||
item.setItemMeta(bmeta);
|
||||
user.sendMessage(_("bookAuthorSet", getFinalArg(args, 1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(_("denyChangeAuthor"));
|
||||
}
|
||||
}
|
||||
else if (args.length > 1 && args[0].equalsIgnoreCase("title"))
|
||||
{
|
||||
if (user.isAuthorized("essentials.book.title") && (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others")))
|
||||
{
|
||||
bmeta.setTitle(args[1]);
|
||||
item.setItemMeta(bmeta);
|
||||
user.sendMessage(_("bookTitleSet", getFinalArg(args, 1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(_("denyChangeTitle"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others"))
|
||||
{
|
||||
ItemStack newItem = new ItemStack(Material.BOOK_AND_QUILL, item.getAmount());
|
||||
newItem.setItemMeta(bmeta);
|
||||
user.setItemInHand(newItem);
|
||||
user.sendMessage(_("editBookContents"));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(_("denyBookEdit"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item.getType() == Material.BOOK_AND_QUILL)
|
||||
{
|
||||
BookMeta bmeta = (BookMeta)item.getItemMeta();
|
||||
if (!user.isAuthorized("essentals.book.author"))
|
||||
{
|
||||
bmeta.setAuthor(player);
|
||||
}
|
||||
ItemStack newItem = new ItemStack(Material.WRITTEN_BOOK, item.getAmount());
|
||||
newItem.setItemMeta(bmeta);
|
||||
user.setItemInHand(newItem);
|
||||
user.sendMessage(_("bookLocked"));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(_("holdBook"));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAuthor(BookMeta bmeta, String player)
|
||||
{
|
||||
String author = bmeta.getAuthor();
|
||||
return author != null && author.equalsIgnoreCase(player);
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -13,6 +14,17 @@ public class Commandbroadcast extends EssentialsCommand
|
||||
super("broadcast");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
ess.broadcastMessage(null, _("broadcast", Util.replaceFormat(getFinalArg(args, 0)), user.getDisplayName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
@@ -21,6 +33,6 @@ public class Commandbroadcast extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
ess.broadcastMessage(null, _("broadcast", Util.replaceFormat(getFinalArg(args, 0))));
|
||||
ess.broadcastMessage(null, _("broadcast", Util.replaceFormat(getFinalArg(args, 0)), sender.getName()));
|
||||
}
|
||||
}
|
||||
|
@@ -2,10 +2,12 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.List;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Commandclearinventory extends EssentialsCommand
|
||||
@@ -21,78 +23,134 @@ public class Commandclearinventory extends EssentialsCommand
|
||||
{
|
||||
if (args.length > 0 && user.isAuthorized("essentials.clearinventory.others"))
|
||||
{
|
||||
//TODO: Fix fringe user match case.
|
||||
if (args[0].length() >= 3)
|
||||
if (args[0].contentEquals("*") && user.isAuthorized("essentials.clearinventory.all"))
|
||||
{
|
||||
List<Player> online = server.matchPlayer(args[0]);
|
||||
|
||||
if (!online.isEmpty())
|
||||
{
|
||||
for (Player p : online)
|
||||
{
|
||||
p.getInventory().clear();
|
||||
user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new Exception(_("playerNotFound"));
|
||||
cleanInventoryAll(server, user, args);
|
||||
}
|
||||
else if (args[0].trim().length() < 2)
|
||||
{
|
||||
cleanInventorySelf(server, user, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
Player p = server.getPlayer(args[0]);
|
||||
if (p != null)
|
||||
{
|
||||
p.getInventory().clear();
|
||||
user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
cleanInventoryOthers(server, user, args);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
user.getInventory().clear();
|
||||
user.sendMessage(_("inventoryCleared"));
|
||||
cleanInventorySelf(server, user, args);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
if (args.length > 0)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
if (args[0].length() >= 3)
|
||||
{
|
||||
List<Player> online = server.matchPlayer(args[0]);
|
||||
|
||||
if (!online.isEmpty())
|
||||
if (args[0].contentEquals("*"))
|
||||
{
|
||||
for (Player p : online)
|
||||
{
|
||||
p.getInventory().clear();
|
||||
sender.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
|
||||
}
|
||||
return;
|
||||
cleanInventoryAll(server, sender, args);
|
||||
}
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Player u = server.getPlayer(args[0]);
|
||||
if (u != null)
|
||||
{
|
||||
u.getInventory().clear();
|
||||
sender.sendMessage(_("inventoryClearedOthers", u.getDisplayName()));
|
||||
}
|
||||
else
|
||||
else if (args[0].trim().length() < 2)
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
else
|
||||
{
|
||||
cleanInventoryOthers(server, sender, args);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanInventoryAll(Server server, CommandSender sender, String[] args) throws Exception
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
clearInventory(onlinePlayer, args[1]);
|
||||
}
|
||||
sender.sendMessage("Cleared everyone's inventory");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanInventoryOthers(Server server, CommandSender user, String[] args) throws Exception
|
||||
{
|
||||
List<Player> online = server.matchPlayer(args[0]);
|
||||
|
||||
if (!online.isEmpty())
|
||||
{
|
||||
for (Player p : online)
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
clearInventory(p, args[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.getInventory().clear();
|
||||
}
|
||||
user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanInventorySelf(Server server, User user, String[] args) throws Exception
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
clearInventory(user, args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.getInventory().clear();
|
||||
}
|
||||
user.sendMessage(_("inventoryCleared"));
|
||||
}
|
||||
|
||||
private void clearInventory(Player player, String arg) throws Exception
|
||||
{
|
||||
if (arg.equalsIgnoreCase("*"))
|
||||
{
|
||||
player.getInventory().clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
final String[] split = arg.split(":");
|
||||
final ItemStack item = ess.getItemDb().get(split[0]);
|
||||
final int type = item.getTypeId();
|
||||
|
||||
if (split.length > 1 && Util.isInt(split[1]))
|
||||
{
|
||||
player.getInventory().clear(type, Integer.parseInt(split[1]));
|
||||
}
|
||||
else if (split.length > 1 && split[1].equalsIgnoreCase("*"))
|
||||
{
|
||||
player.getInventory().clear(type, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Util.isInt(split[0]))
|
||||
{
|
||||
player.getInventory().clear(type, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().clear(type, item.getDurability());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -50,10 +50,10 @@ public class Commanddelhome extends EssentialsCommand
|
||||
{
|
||||
name = expandedArg[0];
|
||||
}
|
||||
//TODO: Think up a nice error message
|
||||
/*
|
||||
* if (name.equalsIgnoreCase("bed")) { throw new Exception("You cannot remove the vanilla home point"); }
|
||||
*/
|
||||
|
||||
|
||||
if (name.equalsIgnoreCase("bed")) { throw new Exception(_("invalidHomeName")); }
|
||||
|
||||
user.delHome(name.toLowerCase(Locale.ENGLISH));
|
||||
sender.sendMessage(_("deleteHome", name));
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -18,6 +19,9 @@ public class Commandeco extends EssentialsCommand
|
||||
@Override
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
Double broadcast = null;
|
||||
Double broadcastAll = null;
|
||||
final double startingBalance = (double)ess.getSettings().getStartingBalance();
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
@@ -34,6 +38,8 @@ public class Commandeco extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException(ex);
|
||||
}
|
||||
|
||||
final double minBalance = ess.getSettings().getMinMoney();
|
||||
|
||||
if (args[1].contentEquals("**"))
|
||||
{
|
||||
for (String sUser : ess.getUserMap().getAllUniqueUsers())
|
||||
@@ -49,11 +55,25 @@ public class Commandeco extends EssentialsCommand
|
||||
if (player.canAfford(amount, false))
|
||||
{
|
||||
player.takeMoney(amount);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.getMoney() > 0)
|
||||
{
|
||||
player.setMoney(0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RESET:
|
||||
player.setMoney(amount == 0 ? ess.getSettings().getStartingBalance() : amount);
|
||||
player.setMoney(startingBalance);
|
||||
broadcastAll = startingBalance;
|
||||
break;
|
||||
|
||||
case SET:
|
||||
boolean underMinimum = (player.getMoney() - amount) < minBalance;
|
||||
player.setMoney(underMinimum ? minBalance : amount);
|
||||
broadcastAll = underMinimum ? minBalance : amount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -70,15 +90,28 @@ public class Commandeco extends EssentialsCommand
|
||||
break;
|
||||
|
||||
case TAKE:
|
||||
if (!player.canAfford(amount, false))
|
||||
if (player.canAfford(amount))
|
||||
{
|
||||
throw new Exception(_("notEnoughMoney"));
|
||||
player.takeMoney(amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.getMoney() > 0)
|
||||
{
|
||||
player.setMoney(0);
|
||||
}
|
||||
}
|
||||
player.takeMoney(amount);
|
||||
break;
|
||||
|
||||
case RESET:
|
||||
player.setMoney(amount == 0 ? ess.getSettings().getStartingBalance() : amount);
|
||||
player.setMoney(startingBalance);
|
||||
broadcast = startingBalance;
|
||||
break;
|
||||
|
||||
case SET:
|
||||
boolean underMinimum = (player.getMoney() - amount) < minBalance;
|
||||
player.setMoney(underMinimum ? minBalance : amount);
|
||||
broadcast = underMinimum ? minBalance : amount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -93,23 +126,38 @@ public class Commandeco extends EssentialsCommand
|
||||
break;
|
||||
|
||||
case TAKE:
|
||||
if (!player.canAfford(amount, false))
|
||||
if (!player.canAfford(amount))
|
||||
{
|
||||
throw new Exception(_("notEnoughMoney"));
|
||||
|
||||
}
|
||||
player.takeMoney(amount, sender);
|
||||
break;
|
||||
|
||||
case RESET:
|
||||
player.setMoney(amount == 0 ? ess.getSettings().getStartingBalance() : amount);
|
||||
player.setMoney(startingBalance);
|
||||
break;
|
||||
|
||||
case SET:
|
||||
boolean underMinimum = (player.getMoney() - amount) < minBalance;
|
||||
player.setMoney(underMinimum ? minBalance : amount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (broadcast != null)
|
||||
{
|
||||
server.broadcastMessage(_("resetBal", Util.formatAsCurrency(broadcast)));
|
||||
}
|
||||
if (broadcastAll != null)
|
||||
{
|
||||
server.broadcastMessage(_("resetBalAll", Util.formatAsCurrency(broadcastAll)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private enum EcoCommands
|
||||
{
|
||||
GIVE, TAKE, RESET
|
||||
GIVE, TAKE, RESET, SET
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Enchantments;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.MetaItemStack;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.Locale;
|
||||
@@ -35,7 +36,7 @@ public class Commandenchant extends EssentialsCommand
|
||||
for (Map.Entry<String, Enchantment> entry : Enchantments.entrySet())
|
||||
{
|
||||
final String enchantmentName = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
|
||||
if (enchantmentslist.contains(enchantmentName) || user.isAuthorized("essentials.enchant." + enchantmentName))
|
||||
if (enchantmentslist.contains(enchantmentName) || (user.isAuthorized("essentials.enchant." + enchantmentName) && entry.getValue().canEnchantItem(stack)))
|
||||
{
|
||||
enchantmentslist.add(entry.getKey());
|
||||
//enchantmentslist.add(enchantmentName);
|
||||
@@ -43,6 +44,7 @@ public class Commandenchant extends EssentialsCommand
|
||||
}
|
||||
throw new NotEnoughArgumentsException(_("enchantments", Util.joinList(enchantmentslist.toArray())));
|
||||
}
|
||||
|
||||
int level = -1;
|
||||
if (args.length > 1)
|
||||
{
|
||||
@@ -55,20 +57,14 @@ public class Commandenchant extends EssentialsCommand
|
||||
level = -1;
|
||||
}
|
||||
}
|
||||
final Enchantment enchantment = getEnchantment(args[0], user);
|
||||
if (level < 0 || level > enchantment.getMaxLevel())
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
}
|
||||
if (level == 0)
|
||||
{
|
||||
stack.removeEnchantment(enchantment);
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.addEnchantment(enchantment, level);
|
||||
}
|
||||
user.getInventory().setItemInHand(stack);
|
||||
|
||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe");
|
||||
|
||||
final MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
final Enchantment enchantment = metaStack.getEnchantment(user, args[0]);
|
||||
metaStack.addEnchantment(user, allowUnsafe, enchantment, level);
|
||||
user.getInventory().setItemInHand(metaStack.getItemStack());
|
||||
|
||||
user.updateInventory();
|
||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
if (level == 0)
|
||||
@@ -80,20 +76,4 @@ public class Commandenchant extends EssentialsCommand
|
||||
user.sendMessage(_("enchantmentApplied", enchantmentName.replace('_', ' ')));
|
||||
}
|
||||
}
|
||||
|
||||
public static Enchantment getEnchantment(final String name, final User user) throws Exception
|
||||
{
|
||||
|
||||
final Enchantment enchantment = Enchantments.getByName(name);
|
||||
if (enchantment == null)
|
||||
{
|
||||
throw new Exception(_("enchantmentNotFound"));
|
||||
}
|
||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
if (user != null && !user.isAuthorized("essentials.enchant." + enchantmentName))
|
||||
{
|
||||
throw new Exception(_("enchantmentPerm", enchantmentName));
|
||||
}
|
||||
return enchantment;
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import com.earth2me.essentials.craftbukkit.SetExpFix;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Server;
|
||||
@@ -45,21 +46,40 @@ public class Commandexp extends EssentialsCommand
|
||||
setExp(user, user, args[1], true);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (args[0].equalsIgnoreCase("show"))
|
||||
{
|
||||
String match = args[0].trim();
|
||||
if (args.length == 2)
|
||||
if (args.length >= 2 && user.isAuthorized("essentials.exp.others"))
|
||||
{
|
||||
match = args[1].trim();
|
||||
}
|
||||
if (match.equalsIgnoreCase("show") || !user.isAuthorized("essentials.exp.others"))
|
||||
{
|
||||
showExp(user, user);
|
||||
String match = args[1].trim();
|
||||
showMatch(server, user, match);
|
||||
}
|
||||
else
|
||||
{
|
||||
showExp(user, user);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.length >= 1 && Util.isInt(args[0].toLowerCase(Locale.ENGLISH).replace("l", "")) && user.isAuthorized("essentials.exp.give"))
|
||||
{
|
||||
if (args.length >= 2 && user.isAuthorized("essentials.exp.give.others"))
|
||||
{
|
||||
expMatch(server, user, args[1], args[0], true);
|
||||
}
|
||||
else
|
||||
{
|
||||
setExp(user, user, args[0], true);
|
||||
}
|
||||
}
|
||||
else if (args.length >= 1 && user.isAuthorized("essentials.exp.others"))
|
||||
{
|
||||
String match = args[0].trim();
|
||||
showMatch(server, user, match);
|
||||
}
|
||||
else
|
||||
{
|
||||
showExp(user, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,9 +101,14 @@ public class Commandexp extends EssentialsCommand
|
||||
else
|
||||
{
|
||||
String match = args[0].trim();
|
||||
if (args.length == 2)
|
||||
if (args.length >= 2 && Util.isInt(args[0].toLowerCase(Locale.ENGLISH).replace("l", "")))
|
||||
{
|
||||
match = args[1].trim();
|
||||
expMatch(server, sender, match, args[0], true);
|
||||
}
|
||||
else if (args.length == 1)
|
||||
{
|
||||
match = args[0].trim();
|
||||
}
|
||||
showMatch(server, sender, match);
|
||||
}
|
||||
@@ -104,13 +129,13 @@ public class Commandexp extends EssentialsCommand
|
||||
}
|
||||
}
|
||||
|
||||
private void expMatch(final Server server, final CommandSender sender, final String match, String amount, final boolean toggle) throws NotEnoughArgumentsException
|
||||
private void expMatch(final Server server, final CommandSender sender, final String match, String amount, final boolean give) throws NotEnoughArgumentsException
|
||||
{
|
||||
boolean foundUser = false;
|
||||
for (Player matchPlayer : server.matchPlayer(match))
|
||||
{
|
||||
final User target = ess.getUser(matchPlayer);
|
||||
setExp(sender, target, amount, toggle);
|
||||
setExp(sender, target, amount, give);
|
||||
foundUser = true;
|
||||
}
|
||||
if (!foundUser)
|
||||
@@ -121,17 +146,17 @@ public class Commandexp extends EssentialsCommand
|
||||
|
||||
private void showExp(final CommandSender sender, final User target)
|
||||
{
|
||||
final int totalExp = SetExpFix.getTotalExperience(target);
|
||||
sender.sendMessage(_("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target), target.getLevel(), SetExpFix.getExpUntilNextLevel(target)));
|
||||
}
|
||||
|
||||
private void setExp(final CommandSender sender, final User target, String strAmount, final boolean give)
|
||||
//TODO: Limit who can give negative exp?
|
||||
private void setExp(final CommandSender sender, final User target, String strAmount, final boolean give) throws NotEnoughArgumentsException
|
||||
{
|
||||
Long amount;
|
||||
long amount;
|
||||
strAmount = strAmount.toLowerCase(Locale.ENGLISH);
|
||||
if (strAmount.startsWith("l"))
|
||||
if (strAmount.contains("l"))
|
||||
{
|
||||
strAmount = strAmount.substring(1);
|
||||
strAmount = strAmount.replaceAll("l", "");
|
||||
int neededLevel = Integer.parseInt(strAmount);
|
||||
if (give)
|
||||
{
|
||||
@@ -140,8 +165,13 @@ public class Commandexp extends EssentialsCommand
|
||||
amount = (long)SetExpFix.getExpToLevel(neededLevel);
|
||||
SetExpFix.setTotalExperience(target, 0);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
amount = Long.parseLong(strAmount);
|
||||
if (amount > Integer.MAX_VALUE || amount < Integer.MIN_VALUE)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
}
|
||||
|
||||
if (give)
|
||||
@@ -152,7 +182,11 @@ public class Commandexp extends EssentialsCommand
|
||||
{
|
||||
amount = (long)Integer.MAX_VALUE;
|
||||
}
|
||||
SetExpFix.setTotalExperience(target, amount.intValue());
|
||||
if (amount < 0l)
|
||||
{
|
||||
amount = 0l;
|
||||
}
|
||||
SetExpFix.setTotalExperience(target, (int)amount);
|
||||
sender.sendMessage(_("expSet", target.getDisplayName(), amount));
|
||||
}
|
||||
}
|
||||
|
@@ -2,8 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.SmallFireball;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
|
||||
@@ -18,12 +17,43 @@ public class Commandfireball extends EssentialsCommand
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
boolean small = false;
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("small"))
|
||||
Class<? extends Entity> type = Fireball.class;
|
||||
Projectile projectile;
|
||||
int speed = 2;
|
||||
if (args.length > 0)
|
||||
{
|
||||
small = true;
|
||||
if (args[0].equalsIgnoreCase("small"))
|
||||
{
|
||||
type = SmallFireball.class;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("arrow"))
|
||||
{
|
||||
type = Arrow.class;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("skull"))
|
||||
{
|
||||
type = WitherSkull.class;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("egg"))
|
||||
{
|
||||
type = Egg.class;
|
||||
}
|
||||
else if(args[0].equalsIgnoreCase("snowball"))
|
||||
{
|
||||
type = Snowball.class;
|
||||
}
|
||||
else if(args[0].equalsIgnoreCase("expbottle"))
|
||||
{
|
||||
type = ThrownExpBottle.class;
|
||||
}
|
||||
else if(args[0].equalsIgnoreCase("large"))
|
||||
{
|
||||
type = LargeFireball.class;
|
||||
}
|
||||
}
|
||||
final Vector direction = user.getEyeLocation().getDirection().multiply(2);
|
||||
Fireball fireball = user.getWorld().spawn(user.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), small ? SmallFireball.class : Fireball.class);
|
||||
fireball.setShooter(user.getBase());
|
||||
final Vector direction = user.getEyeLocation().getDirection().multiply(speed);
|
||||
projectile = (Projectile)user.getWorld().spawn(user.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), type);
|
||||
projectile.setShooter(user.getBase());
|
||||
projectile.setVelocity(direction);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,156 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.MetaItemStack;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
//This command has quite a complicated syntax, in theory it has 4 seperate syntaxes which are all variable:
|
||||
//
|
||||
//1: /firework clear - This clears all of the effects on a firework stack
|
||||
//
|
||||
//2: /firework power <int> - This changes the base power of a firework
|
||||
//
|
||||
//3: /firework fire - This 'fires' a copy of the firework held.
|
||||
//3: /firework fire <int> - This 'fires' a number of copies of the firework held.
|
||||
//3: /firework fire <other> - This 'fires' a copy of the firework held, in the direction you are looking, #easteregg
|
||||
//
|
||||
//4: /firework [meta] - This will add an effect to the firework stack held
|
||||
//4: /firework color:<color> - The minimum you need to set an effect is 'color'
|
||||
//4: Full Syntax: color:<color[,color,..]> [fade:<color[,color,..]>] [shape:<shape>] [effect:<effect[,effect]>]
|
||||
//4: Possible Shapes: star, ball, large, creeper, burst
|
||||
//4: Possible Effects trail, twinkle
|
||||
|
||||
public class Commandfirework extends EssentialsCommand
|
||||
{
|
||||
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
||||
private final static Map<String, DyeColor> colorMap = new HashMap<String, DyeColor>();
|
||||
private final static Map<String, FireworkEffect.Type> fireworkShape = new HashMap<String, FireworkEffect.Type>();
|
||||
|
||||
static
|
||||
{
|
||||
for (DyeColor color : DyeColor.values())
|
||||
{
|
||||
colorMap.put(color.name(), color);
|
||||
}
|
||||
for (FireworkEffect.Type type : FireworkEffect.Type.values())
|
||||
{
|
||||
fireworkShape.put(type.name(), type);
|
||||
}
|
||||
}
|
||||
|
||||
public Commandfirework()
|
||||
{
|
||||
super("firework");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
final ItemStack stack = user.getItemInHand();
|
||||
if (stack.getType() == Material.FIREWORK)
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("clear"))
|
||||
{
|
||||
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
||||
fmeta.clearEffects();
|
||||
stack.setItemMeta(fmeta);
|
||||
user.sendMessage(_("fireworkEffectsCleared"));
|
||||
}
|
||||
else if (args.length > 1 && (args[0].equalsIgnoreCase("power") || (args[0].equalsIgnoreCase("p"))))
|
||||
{
|
||||
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
||||
try
|
||||
{
|
||||
int power = Integer.parseInt(args[1]);
|
||||
fmeta.setPower(power > 3 ? 4 : power);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new Exception(_("invalidFireworkFormat", args[1], args[0]));
|
||||
}
|
||||
stack.setItemMeta(fmeta);
|
||||
}
|
||||
else if ((args[0].equalsIgnoreCase("fire") || (args[0].equalsIgnoreCase("p")))
|
||||
&& user.isAuthorized("essentials.firework.fire"))
|
||||
{
|
||||
int amount = 1;
|
||||
boolean direction = false;
|
||||
if (Util.isInt(args[1]))
|
||||
{
|
||||
final int serverLimit = ess.getSettings().getSpawnMobLimit();
|
||||
amount = Integer.parseInt(args[1]);
|
||||
if (amount > serverLimit)
|
||||
{
|
||||
amount = serverLimit;
|
||||
user.sendMessage(_("mobSpawnLimit"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = true;
|
||||
}
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
Firework firework = (Firework)user.getWorld().spawnEntity(user.getLocation(), EntityType.FIREWORK);
|
||||
FireworkMeta fmeta = (FireworkMeta)stack.getItemMeta();
|
||||
if (direction)
|
||||
{
|
||||
final Vector vector = user.getEyeLocation().getDirection().multiply(0.070);
|
||||
if (fmeta.getPower() > 1)
|
||||
{
|
||||
fmeta.setPower(1);
|
||||
}
|
||||
firework.setVelocity(vector);
|
||||
}
|
||||
firework.setFireworkMeta(fmeta);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final MetaItemStack mStack = new MetaItemStack(stack);
|
||||
for (String arg : args)
|
||||
{
|
||||
final String[] split = splitPattern.split(arg, 2);
|
||||
mStack.addFireworkMeta(user, true, arg, ess);
|
||||
}
|
||||
|
||||
if (mStack.isValidFirework())
|
||||
{
|
||||
FireworkMeta fmeta = (FireworkMeta)mStack.getItemStack().getItemMeta();
|
||||
FireworkEffect effect = mStack.getFireworkBuilder().build();
|
||||
fmeta.addEffect(effect);
|
||||
stack.setItemMeta(fmeta);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("fireworkSyntax"));
|
||||
throw new Exception(_("fireworkColor"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(_("holdFirework"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -28,15 +28,34 @@ public class Commandfly extends EssentialsCommand
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length > 0 && args[0].trim().length() > 2 && user.isAuthorized("essentials.fly.others"))
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("on") || args[0].startsWith("ena") || args[0].equalsIgnoreCase("1"))
|
||||
{
|
||||
user.setAllowFlight(true);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("off") || args[0].startsWith("dis") || args[0].equalsIgnoreCase("0"))
|
||||
{
|
||||
user.setAllowFlight(false);
|
||||
}
|
||||
else if (user.isAuthorized("essentials.fly.others"))
|
||||
{
|
||||
flyOtherPlayers(server, user, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (args.length == 2 && user.isAuthorized("essentials.fly.others"))
|
||||
{
|
||||
flyOtherPlayers(server, user, args);
|
||||
return;
|
||||
}
|
||||
user.setAllowFlight(!user.getAllowFlight());
|
||||
if (!user.getAllowFlight())
|
||||
else
|
||||
{
|
||||
user.setFlying(false);
|
||||
user.setAllowFlight(!user.getAllowFlight());
|
||||
if (!user.getAllowFlight())
|
||||
{
|
||||
user.setFlying(false);
|
||||
}
|
||||
}
|
||||
user.sendMessage(_("flyMode", _(user.getAllowFlight() ? "enabled" : "disabled"), user.getDisplayName()));
|
||||
}
|
||||
|
@@ -19,12 +19,22 @@ public class Commandgamemode extends EssentialsCommand
|
||||
@Override
|
||||
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 2)
|
||||
GameMode gameMode;
|
||||
if (args.length == 0)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
GameMode gameMode = matchGameMode(args[0].toLowerCase(Locale.ENGLISH));
|
||||
gamemodeOtherPlayers(server, sender, gameMode, args[1]);
|
||||
else if (args.length == 1)
|
||||
{
|
||||
gameMode = matchGameMode(commandLabel);
|
||||
gamemodeOtherPlayers(server, sender, gameMode, args[0]);
|
||||
}
|
||||
else if (args.length == 2)
|
||||
{
|
||||
gameMode = matchGameMode(args[0].toLowerCase(Locale.ENGLISH));
|
||||
gamemodeOtherPlayers(server, sender, gameMode, args[1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,7 +51,7 @@ public class Commandgamemode extends EssentialsCommand
|
||||
gamemodeOtherPlayers(server, user, gameMode, args[1]);
|
||||
return;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
@@ -33,14 +34,15 @@ public class Commandgc extends EssentialsCommand
|
||||
{
|
||||
color = ChatColor.RED;
|
||||
}
|
||||
|
||||
|
||||
sender.sendMessage(_("uptime", Util.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime())));
|
||||
sender.sendMessage(_("tps", "" + color + tps));
|
||||
sender.sendMessage(_("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024)));
|
||||
sender.sendMessage(_("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024)));
|
||||
sender.sendMessage(_("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024)));
|
||||
sender.sendMessage(_("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024)));
|
||||
|
||||
for (World w : server.getWorlds())
|
||||
List<World> worlds = server.getWorlds();
|
||||
for (World w : worlds)
|
||||
{
|
||||
String worldType = "World";
|
||||
switch (w.getEnvironment())
|
||||
@@ -55,6 +57,5 @@ public class Commandgc extends EssentialsCommand
|
||||
|
||||
sender.sendMessage(_("gcWorld", worldType, w.getName(), w.getLoadedChunks().length, w.getEntities().size()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.MetaItemStack;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
@@ -8,7 +9,6 @@ import java.util.Locale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Commandgive extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
final ItemStack stack = ess.getItemDb().get(args[1]);
|
||||
ItemStack stack = ess.getItemDb().get(args[1]);
|
||||
|
||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||
if (sender instanceof Player
|
||||
@@ -44,45 +44,43 @@ public class Commandgive extends EssentialsCommand
|
||||
|
||||
final User giveTo = getPlayer(server, args, 0);
|
||||
|
||||
if (args.length > 3 && Util.isInt(args[2]) && Util.isInt(args[3]))
|
||||
try
|
||||
{
|
||||
stack.setAmount(Integer.parseInt(args[2]));
|
||||
stack.setDurability(Short.parseShort(args[3]));
|
||||
if (args.length > 3 && Util.isInt(args[2]) && Util.isInt(args[3]))
|
||||
{
|
||||
stack.setAmount(Integer.parseInt(args[2]));
|
||||
stack.setDurability(Short.parseShort(args[3]));
|
||||
}
|
||||
else if (args.length > 2 && Integer.parseInt(args[2]) > 0)
|
||||
{
|
||||
stack.setAmount(Integer.parseInt(args[2]));
|
||||
}
|
||||
else if (ess.getSettings().getDefaultStackSize() > 0)
|
||||
{
|
||||
stack.setAmount(ess.getSettings().getDefaultStackSize());
|
||||
}
|
||||
else if (ess.getSettings().getOversizedStackSize() > 0 && giveTo.isAuthorized("essentials.oversizedstacks"))
|
||||
{
|
||||
stack.setAmount(ess.getSettings().getOversizedStackSize());
|
||||
}
|
||||
}
|
||||
else if (args.length > 2 && Integer.parseInt(args[2]) > 0)
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
stack.setAmount(Integer.parseInt(args[2]));
|
||||
}
|
||||
else if (ess.getSettings().getDefaultStackSize() > 0)
|
||||
{
|
||||
stack.setAmount(ess.getSettings().getDefaultStackSize());
|
||||
}
|
||||
else if (ess.getSettings().getOversizedStackSize() > 0 && giveTo.isAuthorized("essentials.oversizedstacks"))
|
||||
{
|
||||
stack.setAmount(ess.getSettings().getOversizedStackSize());
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
if (args.length > 3)
|
||||
{
|
||||
for (int i = Util.isInt(args[3]) ? 4 : 3; i < args.length; i++)
|
||||
MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
|
||||
if (allowUnsafe && sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.enchant.allowunsafe"))
|
||||
{
|
||||
final String[] split = args[i].split("[:+',;.]", 2);
|
||||
if (split.length < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final Enchantment enchantment = Commandenchant.getEnchantment(split[0], sender instanceof Player ? ess.getUser(sender) : null);
|
||||
int level;
|
||||
if (split.length > 1)
|
||||
{
|
||||
level = Integer.parseInt(split[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
}
|
||||
stack.addEnchantment(enchantment, level);
|
||||
allowUnsafe = false;
|
||||
}
|
||||
|
||||
metaStack.parseStringMeta(sender, allowUnsafe, args, Util.isInt(args[3]) ? 4 : 3, ess);
|
||||
|
||||
stack = metaStack.getItemStack();
|
||||
}
|
||||
|
||||
if (stack.getType() == Material.AIR)
|
||||
@@ -94,11 +92,11 @@ public class Commandgive extends EssentialsCommand
|
||||
sender.sendMessage(_("giveSpawn", stack.getAmount(), itemName, giveTo.getDisplayName()));
|
||||
if (giveTo.isAuthorized("essentials.oversizedstacks"))
|
||||
{
|
||||
InventoryWorkaround.addItem(giveTo.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack);
|
||||
InventoryWorkaround.addOversizedItems(giveTo.getInventory(), ess.getSettings().getOversizedStackSize(), stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
InventoryWorkaround.addItem(giveTo.getInventory(), true, stack);
|
||||
InventoryWorkaround.addItems(giveTo.getInventory(), stack);
|
||||
}
|
||||
giveTo.updateInventory();
|
||||
}
|
||||
|
@@ -33,10 +33,20 @@ public class Commandgod extends EssentialsCommand
|
||||
godOtherPlayers(server, user, args);
|
||||
return;
|
||||
}
|
||||
user.setGodModeEnabled(!user.isGodModeEnabled());
|
||||
godPlayer(user, !user.isGodModeEnabled());
|
||||
user.sendMessage(_("godMode", (user.isGodModeEnabled() ? _("enabled") : _("disabled"))));
|
||||
}
|
||||
|
||||
private void godPlayer(User player, boolean enabled)
|
||||
{
|
||||
player.setGodModeEnabled(enabled);
|
||||
if (enabled)
|
||||
{
|
||||
player.setHealth(player.getMaxHealth());
|
||||
player.setFoodLevel(20);
|
||||
}
|
||||
}
|
||||
|
||||
private void godOtherPlayers(final Server server, final CommandSender sender, final String[] args)
|
||||
{
|
||||
for (Player matchPlayer : server.matchPlayer(args[0]))
|
||||
@@ -47,28 +57,24 @@ public class Commandgod extends EssentialsCommand
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean enabled;
|
||||
if (args.length > 1)
|
||||
{
|
||||
if (args[1].contains("on") || args[1].contains("ena") || args[1].equalsIgnoreCase("1"))
|
||||
{
|
||||
player.setGodModeEnabled(true);
|
||||
enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.setGodModeEnabled(false);
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.setGodModeEnabled(!player.isGodModeEnabled());
|
||||
}
|
||||
|
||||
final boolean enabled = player.isGodModeEnabled();
|
||||
if (enabled)
|
||||
{
|
||||
player.setFoodLevel(20);
|
||||
enabled = !player.isGodModeEnabled();
|
||||
}
|
||||
|
||||
godPlayer(player, enabled);
|
||||
player.sendMessage(_("godMode", (enabled ? _("enabled") : _("disabled"))));
|
||||
sender.sendMessage(_("godMode", _(enabled ? "godEnabledFor" : "godDisabledFor", matchPlayer.getDisplayName())));
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ public class Commandhat extends EssentialsCommand
|
||||
{
|
||||
final ItemStack air = new ItemStack(Material.AIR);
|
||||
inv.setHelmet(air);
|
||||
InventoryWorkaround.addItem(user.getInventory(), true, head);
|
||||
InventoryWorkaround.addItems(user.getInventory(), head);
|
||||
user.sendMessage(_("hatRemoved"));
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
|
||||
public class Commandheal extends EssentialsCommand
|
||||
@@ -68,14 +67,15 @@ public class Commandheal extends EssentialsCommand
|
||||
}
|
||||
}
|
||||
|
||||
private void healPlayer(final Player p)
|
||||
private void healPlayer(final Player player)
|
||||
{
|
||||
p.setHealth(20);
|
||||
p.setFoodLevel(20);
|
||||
p.sendMessage(_("heal"));
|
||||
for (PotionEffect effect : p.getActivePotionEffects())
|
||||
player.setHealth(player.getMaxHealth());
|
||||
player.setFoodLevel(20);
|
||||
player.setFireTicks(0);
|
||||
player.sendMessage(_("heal"));
|
||||
for (PotionEffect effect : player.getActivePotionEffects())
|
||||
{
|
||||
p.removePotionEffect(effect.getType());
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ public class Commandhome extends EssentialsCommand
|
||||
if ("bed".equalsIgnoreCase(homeName) && user.isAuthorized("essentials.home.bed"))
|
||||
{
|
||||
final Location bed = player.getBedSpawnLocation();
|
||||
if (bed != null && bed.getBlock().getType() == Material.BED_BLOCK)
|
||||
if (bed != null)
|
||||
{
|
||||
user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
|
||||
throw new NoChargeException();
|
||||
@@ -58,24 +58,14 @@ public class Commandhome extends EssentialsCommand
|
||||
catch (NotEnoughArgumentsException e)
|
||||
{
|
||||
Location bed = player.getBedSpawnLocation();
|
||||
if (bed != null && bed.getBlock().getType() != Material.BED_BLOCK)
|
||||
{
|
||||
bed = null;
|
||||
}
|
||||
final List<String> homes = player.getHomes();
|
||||
if (homes.isEmpty() && player.equals(user))
|
||||
{
|
||||
if (bed != null)
|
||||
{
|
||||
user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
|
||||
throw new NoChargeException();
|
||||
}
|
||||
user.getTeleport().respawn(charge, TeleportCause.COMMAND);
|
||||
|
||||
}
|
||||
else if (homes.isEmpty())
|
||||
{
|
||||
throw new Exception(player == user ? _("noHomeSet") : _("noHomeSetPlayer"));
|
||||
throw new Exception(_("noHomeSetPlayer"));
|
||||
}
|
||||
else if (homes.size() == 1 && player.equals(user))
|
||||
{
|
||||
@@ -83,9 +73,9 @@ public class Commandhome extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bed != null)
|
||||
if (bed != null && user.isAuthorized("essentials.home.bed"))
|
||||
{
|
||||
homes.add("bed");
|
||||
homes.add(_("bed"));
|
||||
}
|
||||
user.sendMessage(_("homes", Util.joinList(homes)));
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
|
||||
public class Commandinvsee extends EssentialsCommand
|
||||
@@ -10,6 +11,8 @@ public class Commandinvsee extends EssentialsCommand
|
||||
{
|
||||
super("invsee");
|
||||
}
|
||||
|
||||
//This method has a hidden param, which if given will display the equip slots. #easteregg
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
@@ -18,8 +21,20 @@ public class Commandinvsee extends EssentialsCommand
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
final User invUser = getPlayer(server, args, 0);
|
||||
Inventory inv;
|
||||
|
||||
if (args.length > 1 && user.isAuthorized("essentials.invsee.equip"))
|
||||
{
|
||||
inv = server.createInventory(invUser, 9, "Equipped");
|
||||
inv.setContents(invUser.getInventory().getArmorContents());
|
||||
}
|
||||
else
|
||||
{
|
||||
inv = invUser.getInventory();
|
||||
}
|
||||
user.openInventory(inv);
|
||||
user.setInvSee(true);
|
||||
user.openInventory(invUser.getInventory());
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.MetaItemStack;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Commanditem extends EssentialsCommand
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
final ItemStack stack = ess.getItemDb().get(args[0]);
|
||||
ItemStack stack = ess.getItemDb().get(args[0]);
|
||||
|
||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||
if (ess.getSettings().permissionBasedItemSpawn()
|
||||
@@ -50,33 +50,21 @@ public class Commanditem extends EssentialsCommand
|
||||
{
|
||||
stack.setAmount(ess.getSettings().getOversizedStackSize());
|
||||
}
|
||||
if (args.length > 2)
|
||||
{
|
||||
for (int i = 2; i < args.length; i++)
|
||||
{
|
||||
final String[] split = args[i].split("[:+',;.]", 2);
|
||||
if (split.length < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final Enchantment enchantment = Commandenchant.getEnchantment(split[0], user);
|
||||
int level;
|
||||
if (split.length > 1)
|
||||
{
|
||||
level = Integer.parseInt(split[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
}
|
||||
stack.addEnchantment(enchantment, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
if (args.length > 2)
|
||||
{
|
||||
MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe");
|
||||
|
||||
metaStack.parseStringMeta(user, allowUnsafe, args, 2, ess);
|
||||
|
||||
stack = metaStack.getItemStack();
|
||||
}
|
||||
|
||||
|
||||
if (stack.getType() == Material.AIR)
|
||||
{
|
||||
@@ -87,11 +75,11 @@ public class Commanditem extends EssentialsCommand
|
||||
user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
|
||||
if (user.isAuthorized("essentials.oversizedstacks"))
|
||||
{
|
||||
InventoryWorkaround.addItem(user.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack);
|
||||
InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
InventoryWorkaround.addItem(user.getInventory(), true, stack);
|
||||
InventoryWorkaround.addItems(user.getInventory(), stack);
|
||||
}
|
||||
user.updateInventory();
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Console;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -25,9 +26,11 @@ public class Commandkick extends EssentialsCommand
|
||||
}
|
||||
|
||||
final User target = getPlayer(server, args, 0, true);
|
||||
if (sender instanceof Player) {
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
User user = ess.getUser(sender);
|
||||
if (target.isHidden() && !user.isAuthorized("essentials.list.hidden")) {
|
||||
if (target.isHidden() && !user.isAuthorized("essentials.list.hidden"))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
if (target.isAuthorized("essentials.kick.exempt"))
|
||||
@@ -35,10 +38,13 @@ public class Commandkick extends EssentialsCommand
|
||||
throw new Exception(_("kickExempt"));
|
||||
}
|
||||
}
|
||||
final String kickReason = args.length > 1 ? getFinalArg(args, 1) : _("kickDefault");
|
||||
|
||||
String kickReason = args.length > 1 ? getFinalArg(args, 1) : _("kickDefault");
|
||||
kickReason = Util.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n"));
|
||||
|
||||
target.kickPlayer(kickReason);
|
||||
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
|
||||
|
||||
|
||||
server.getLogger().log(Level.INFO, _("playerKicked", senderName, target.getName(), kickReason));
|
||||
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -16,6 +17,9 @@ public class Commandkickall extends EssentialsCommand
|
||||
@Override
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
String kickReason = args.length > 0 ? getFinalArg(args, 0) : _("kickDefault");
|
||||
kickReason = Util.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n"));
|
||||
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
if (sender instanceof Player && onlinePlayer.getName().equalsIgnoreCase(((Player)sender).getName()))
|
||||
@@ -24,7 +28,7 @@ public class Commandkickall extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
onlinePlayer.kickPlayer(args.length > 0 ? getFinalArg(args, 0) : _("kickDefault"));
|
||||
onlinePlayer.kickPlayer(kickReason);
|
||||
}
|
||||
}
|
||||
sender.sendMessage(_("kickedAll"));
|
||||
|
@@ -2,7 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Mob;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Server;
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Commandkillall extends EssentialsCommand
|
||||
@@ -109,7 +110,7 @@ public class Commandkillall extends EssentialsCommand
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(entity instanceof Ocelot)
|
||||
if (entity instanceof Ocelot)
|
||||
{
|
||||
if (((Ocelot)entity).isTamed())
|
||||
{
|
||||
@@ -120,7 +121,7 @@ public class Commandkillall extends EssentialsCommand
|
||||
{
|
||||
if (entity instanceof Animals || entity instanceof NPC || entity instanceof Snowman || entity instanceof WaterMob)
|
||||
{
|
||||
EntityDeathEvent event = new EntityDeathEvent((LivingEntity)entity, Collections.EMPTY_LIST);
|
||||
EntityDeathEvent event = new EntityDeathEvent((LivingEntity)entity, new ArrayList<ItemStack>(0));
|
||||
ess.getServer().getPluginManager().callEvent(event);
|
||||
entity.remove();
|
||||
numKills++;
|
||||
@@ -130,7 +131,7 @@ public class Commandkillall extends EssentialsCommand
|
||||
{
|
||||
if (entity instanceof Monster || entity instanceof ComplexLivingEntity || entity instanceof Flying || entity instanceof Slime)
|
||||
{
|
||||
EntityDeathEvent event = new EntityDeathEvent((LivingEntity)entity, Collections.EMPTY_LIST);
|
||||
EntityDeathEvent event = new EntityDeathEvent((LivingEntity)entity, new ArrayList<ItemStack>(0));
|
||||
ess.getServer().getPluginManager().callEvent(event);
|
||||
entity.remove();
|
||||
numKills++;
|
||||
@@ -138,14 +139,14 @@ public class Commandkillall extends EssentialsCommand
|
||||
}
|
||||
else if (all)
|
||||
{
|
||||
EntityDeathEvent event = new EntityDeathEvent((LivingEntity)entity, Collections.EMPTY_LIST);
|
||||
EntityDeathEvent event = new EntityDeathEvent((LivingEntity)entity, new ArrayList<ItemStack>(0));
|
||||
ess.getServer().getPluginManager().callEvent(event);
|
||||
entity.remove();
|
||||
numKills++;
|
||||
}
|
||||
else if (entityClass != null && entityClass.isAssignableFrom(entity.getClass()))
|
||||
{
|
||||
EntityDeathEvent event = new EntityDeathEvent((LivingEntity)entity, Collections.EMPTY_LIST);
|
||||
EntityDeathEvent event = new EntityDeathEvent((LivingEntity)entity, new ArrayList<ItemStack>(0));
|
||||
ess.getServer().getPluginManager().callEvent(event);
|
||||
entity.remove();
|
||||
numKills++;
|
||||
|
@@ -18,7 +18,7 @@ public class Commandmail extends EssentialsCommand
|
||||
super("mail");
|
||||
}
|
||||
|
||||
//TODO: Tidy this up
|
||||
//TODO: Tidy this up / TL these errors.
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
@@ -77,7 +77,7 @@ public class Commandmail extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(_("noPerm", "essentials.mail.sendall"));
|
||||
}
|
||||
ess.scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + Util.stripFormat(getFinalArg(args, 1))));
|
||||
ess.runTaskAsynchronously(new SendAll(user.getName() + ": " + Util.stripFormat(getFinalArg(args, 1))));
|
||||
user.sendMessage(_("mailSent"));
|
||||
return;
|
||||
}
|
||||
@@ -114,7 +114,9 @@ public class Commandmail extends EssentialsCommand
|
||||
}
|
||||
else if (args.length >= 1 && "sendall".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
ess.scheduleAsyncDelayedTask(new SendAll("Server: " + getFinalArg(args, 2)));
|
||||
ess.runTaskAsynchronously(new SendAll("Server: " + getFinalArg(args, 2)));
|
||||
sender.sendMessage(_("mailSent"));
|
||||
return;
|
||||
}
|
||||
else if (args.length >= 2)
|
||||
{
|
||||
|
@@ -25,7 +25,7 @@ public class Commandmore extends EssentialsCommand
|
||||
if (stack.getAmount() >= ((user.isAuthorized("essentials.oversizedstacks"))
|
||||
? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize()))
|
||||
{
|
||||
throw new NoChargeException();
|
||||
throw new Exception(_("fullStack"));
|
||||
}
|
||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||
if (ess.getSettings().permissionBasedItemSpawn()
|
||||
|
@@ -17,15 +17,15 @@ public class Commandmsg extends EssentialsCommand
|
||||
{
|
||||
super("msg");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 2 || args[0].trim().length() < 2 || args[1].trim().isEmpty())
|
||||
if (args.length < 2 || args[0].trim().length() < 2 || args[1].trim().isEmpty())
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
|
||||
String message = getFinalArg(args, 1);
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
@@ -40,12 +40,12 @@ public class Commandmsg extends EssentialsCommand
|
||||
{
|
||||
message = Util.replaceFormat(message);
|
||||
}
|
||||
|
||||
|
||||
final String translatedMe = _("me");
|
||||
|
||||
|
||||
final IReplyTo replyTo = sender instanceof Player ? ess.getUser((Player)sender) : Console.getConsoleReplyTo();
|
||||
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
|
||||
|
||||
|
||||
if (args[0].equalsIgnoreCase(Console.NAME))
|
||||
{
|
||||
sender.sendMessage(_("msgFormat", translatedMe, Console.NAME, message));
|
||||
@@ -55,14 +55,14 @@ public class Commandmsg extends EssentialsCommand
|
||||
Console.getConsoleReplyTo().setReplyTo(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
|
||||
|
||||
|
||||
if (matchedPlayers.isEmpty())
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
|
||||
|
||||
int i = 0;
|
||||
for (Player matchedPlayer : matchedPlayers)
|
||||
{
|
||||
@@ -76,17 +76,28 @@ public class Commandmsg extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
|
||||
|
||||
for (Player matchedPlayer : matchedPlayers)
|
||||
{
|
||||
sender.sendMessage(_("msgFormat", translatedMe, matchedPlayer.getDisplayName(), message));
|
||||
{
|
||||
final User matchedUser = ess.getUser(matchedPlayer);
|
||||
if (sender instanceof Player && (matchedUser.isIgnoredPlayer(ess.getUser(sender)) || matchedUser.isHidden()))
|
||||
|
||||
if (sender instanceof Player && matchedUser.isHidden())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (matchedUser.isAfk())
|
||||
{
|
||||
sender.sendMessage(_("userAFK", matchedPlayer.getDisplayName()));
|
||||
}
|
||||
|
||||
sender.sendMessage(_("msgFormat", translatedMe, matchedPlayer.getDisplayName(), message));
|
||||
if (sender instanceof Player && matchedUser.isIgnoredPlayer(ess.getUser(sender)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
matchedPlayer.sendMessage(_("msgFormat", senderName, translatedMe, message));
|
||||
replyTo.setReplyTo(ess.getUser(matchedPlayer));
|
||||
replyTo.setReplyTo(matchedUser);
|
||||
ess.getUser(matchedPlayer).setReplyTo(sender);
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commandmute extends EssentialsCommand
|
||||
@@ -41,17 +42,31 @@ public class Commandmute extends EssentialsCommand
|
||||
}
|
||||
player.setMuteTimeout(muteTimestamp);
|
||||
final boolean muted = player.getMuted();
|
||||
sender.sendMessage(
|
||||
muted
|
||||
? (muteTimestamp > 0
|
||||
? _("mutedPlayerFor", player.getDisplayName(), Util.formatDateDiff(muteTimestamp))
|
||||
: _("mutedPlayer", player.getDisplayName()))
|
||||
: _("unmutedPlayer", player.getDisplayName()));
|
||||
player.sendMessage(
|
||||
muted
|
||||
? (muteTimestamp > 0
|
||||
? _("playerMutedFor", Util.formatDateDiff(muteTimestamp))
|
||||
: _("playerMuted"))
|
||||
: _("playerUnmuted"));
|
||||
if (muted)
|
||||
{
|
||||
if (muteTimestamp > 0)
|
||||
{
|
||||
sender.sendMessage(_("mutedPlayerFor", player.getDisplayName(), Util.formatDateDiff(muteTimestamp)));
|
||||
player.sendMessage(_("playerMutedFor", Util.formatDateDiff(muteTimestamp)));
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(_("mutedPlayer", player.getDisplayName()));
|
||||
player.sendMessage(_("playerMuted"));
|
||||
}
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
final User user = ess.getUser(onlinePlayer);
|
||||
if (onlinePlayer != sender && user.isAuthorized("essentials.mute.notify"))
|
||||
{
|
||||
onlinePlayer.sendMessage(_("muteNotify", sender.getName(), player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(_("unmutedPlayer", player.getDisplayName()));
|
||||
player.sendMessage(_("playerUnmuted"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,7 +22,7 @@ public class Commandpay extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
//TODO: TL this
|
||||
//TODO: TL this.
|
||||
if (args[0].trim().length() < 2)
|
||||
{
|
||||
throw new NotEnoughArgumentsException("You need to specify a player to pay.");
|
||||
|
196
Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java
Executable file
196
Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java
Executable file
@@ -0,0 +1,196 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.FurnaceRecipe;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
|
||||
|
||||
public class Commandrecipe extends EssentialsCommand
|
||||
{
|
||||
public Commandrecipe()
|
||||
{
|
||||
super("recipe");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
final ItemStack itemType = ess.getItemDb().get(args[0]);
|
||||
int recipeNo = 0;
|
||||
|
||||
if (args.length > 1)
|
||||
{
|
||||
if (Util.isInt(args[1]))
|
||||
{
|
||||
recipeNo = Integer.parseInt(args[1]) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(_("invalidNumber"));
|
||||
}
|
||||
}
|
||||
|
||||
final List<Recipe> recipesOfType = ess.getServer().getRecipesFor(itemType);
|
||||
if (recipesOfType.size() < 1)
|
||||
{
|
||||
throw new Exception(_("recipeNone", getMaterialName(itemType)));
|
||||
}
|
||||
|
||||
if (recipeNo < 0 || recipeNo >= recipesOfType.size())
|
||||
{
|
||||
throw new Exception(_("recipeBadIndex"));
|
||||
}
|
||||
|
||||
final Recipe selectedRecipe = recipesOfType.get(recipeNo);
|
||||
sender.sendMessage(_("recipe", getMaterialName(itemType), recipeNo + 1, recipesOfType.size()));
|
||||
|
||||
if (selectedRecipe instanceof FurnaceRecipe)
|
||||
{
|
||||
furnaceRecipe(sender, (FurnaceRecipe)selectedRecipe);
|
||||
}
|
||||
else if (selectedRecipe instanceof ShapedRecipe)
|
||||
{
|
||||
shapedRecipe(sender, (ShapedRecipe)selectedRecipe);
|
||||
}
|
||||
else if (selectedRecipe instanceof ShapelessRecipe)
|
||||
{
|
||||
shapelessRecipe(sender, (ShapelessRecipe)selectedRecipe);
|
||||
}
|
||||
|
||||
if (recipesOfType.size() > 1 && args.length == 1)
|
||||
{
|
||||
sender.sendMessage(_("recipeMore", commandLabel, args[0], getMaterialName(itemType)));
|
||||
}
|
||||
}
|
||||
|
||||
public void furnaceRecipe(final CommandSender sender, final FurnaceRecipe recipe)
|
||||
{
|
||||
sender.sendMessage(_("recipeFurnace", getMaterialName(recipe.getInput())));
|
||||
}
|
||||
|
||||
public void shapedRecipe(final CommandSender sender, final ShapedRecipe recipe)
|
||||
{
|
||||
final Map<Character, ItemStack> recipeMap = recipe.getIngredientMap();
|
||||
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
final User user = ess.getUser(sender);
|
||||
user.setRecipeSee(true);
|
||||
final InventoryView view = user.openWorkbench(null, true);
|
||||
final String[] recipeShape = recipe.getShape();
|
||||
final Map<Character, ItemStack> ingredientMap = recipe.getIngredientMap();
|
||||
for (int j = 0; j < recipeShape.length; j++)
|
||||
{
|
||||
for (int k = 0; k < recipeShape[j].length(); k++)
|
||||
{
|
||||
final ItemStack item = ingredientMap.get(recipeShape[j].toCharArray()[k]);
|
||||
if(item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
item.setAmount(0);
|
||||
view.getTopInventory().setItem(j * 3 + k + 1, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final HashMap<Material, String> colorMap = new HashMap<Material, String>();
|
||||
int i = 1;
|
||||
for (Character c : "abcdefghi".toCharArray())
|
||||
{
|
||||
ItemStack item = recipeMap.get(c);
|
||||
if (!colorMap.containsKey(item == null ? null : item.getType()))
|
||||
{
|
||||
colorMap.put(item == null ? null : item.getType(), String.valueOf(i++));
|
||||
}
|
||||
}
|
||||
final Material[][] materials = new Material[3][3];
|
||||
for (int j = 0; j < recipe.getShape().length; j++)
|
||||
{
|
||||
for (int k = 0; k < recipe.getShape()[j].length(); k++)
|
||||
{
|
||||
ItemStack item = recipe.getIngredientMap().get(recipe.getShape()[j].toCharArray()[k]);
|
||||
materials[j][k] = item == null ? null : item.getType();
|
||||
}
|
||||
}
|
||||
sender.sendMessage(_("recipeGrid", colorMap.get(materials[0][0]), colorMap.get(materials[0][1]), colorMap.get(materials[0][2])));
|
||||
sender.sendMessage(_("recipeGrid", colorMap.get(materials[1][0]), colorMap.get(materials[1][1]), colorMap.get(materials[1][2])));
|
||||
sender.sendMessage(_("recipeGrid", colorMap.get(materials[2][0]), colorMap.get(materials[2][1]), colorMap.get(materials[2][2])));
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (Material items : colorMap.keySet().toArray(new Material[colorMap.size()]))
|
||||
{
|
||||
s.append(_("recipeGridItem", colorMap.get(items), getMaterialName(items)));
|
||||
}
|
||||
sender.sendMessage(_("recipeWhere", s.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void shapelessRecipe(final CommandSender sender, final ShapelessRecipe recipe)
|
||||
{
|
||||
final List<ItemStack> ingredients = recipe.getIngredientList();
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
final User user = ess.getUser(sender);
|
||||
user.setRecipeSee(true);
|
||||
final InventoryView view = user.openWorkbench(null, true);
|
||||
for (int i = 0; i < ingredients.size(); i++)
|
||||
{
|
||||
view.setItem(i + 1, ingredients.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (int i = 0; i < ingredients.size(); i++)
|
||||
{
|
||||
s.append(getMaterialName(ingredients.get(i)));
|
||||
if (i != ingredients.size() - 1)
|
||||
{
|
||||
s.append(",");
|
||||
}
|
||||
s.append(" ");
|
||||
}
|
||||
sender.sendMessage(_("recipeShapeless", s.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public String getMaterialName(final ItemStack stack)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
return _("recipeNothing");
|
||||
}
|
||||
return getMaterialName(stack.getType());
|
||||
}
|
||||
|
||||
public String getMaterialName(final Material type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return _("recipeNothing");
|
||||
}
|
||||
return type.toString().replace("_", " ").toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
@@ -35,12 +35,28 @@ public class Commandseen extends EssentialsCommand
|
||||
}
|
||||
try
|
||||
{
|
||||
User player = getPlayer(server, args, 0);
|
||||
player.setDisplayNick();
|
||||
sender.sendMessage(_("seenOnline", player.getDisplayName(), Util.formatDateDiff(player.getLastLogin())));
|
||||
User user = getPlayer(server, args, 0);
|
||||
user.setDisplayNick();
|
||||
sender.sendMessage(_("seenOnline", user.getDisplayName(), Util.formatDateDiff(user.getLastLogin())));
|
||||
if (user.isAfk())
|
||||
{
|
||||
sender.sendMessage(_("whoisAFK", _("true")));
|
||||
}
|
||||
if (user.isJailed())
|
||||
{
|
||||
sender.sendMessage(_("whoisJail", (user.getJailTimeout() > 0
|
||||
? Util.formatDateDiff(user.getJailTimeout())
|
||||
: _("true"))));
|
||||
}
|
||||
if (user.isMuted())
|
||||
{
|
||||
sender.sendMessage(_("whoisMuted", (user.getMuteTimeout() > 0
|
||||
? Util.formatDateDiff(user.getMuteTimeout())
|
||||
: _("true"))));
|
||||
}
|
||||
if (extra)
|
||||
{
|
||||
sender.sendMessage(_("whoisIPAddress", player.getAddress().getAddress().toString()));
|
||||
sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
|
||||
}
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
@@ -59,8 +75,9 @@ public class Commandseen extends EssentialsCommand
|
||||
if (extra)
|
||||
{
|
||||
sender.sendMessage(_("whoisIPAddress", player.getLastLoginAddress()));
|
||||
final Location loc = player.getLastLocation();
|
||||
if (loc != null) {
|
||||
final Location loc = player.getLogoutLocation();
|
||||
if (loc != null)
|
||||
{
|
||||
sender.sendMessage(_("whoisLocation", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Material;
|
||||
@@ -22,6 +21,8 @@ public class Commandsell extends EssentialsCommand
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
double totalWorth = 0.0;
|
||||
String type = "";
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
@@ -41,12 +42,16 @@ public class Commandsell extends EssentialsCommand
|
||||
}
|
||||
try
|
||||
{
|
||||
sellItem(user, stack, args, true);
|
||||
totalWorth += sellItem(user, stack, args, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (totalWorth > 0)
|
||||
{
|
||||
user.sendMessage(_("totalWorthAll", type, Util.displayCurrency(totalWorth, ess)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("blocks"))
|
||||
@@ -59,12 +64,16 @@ public class Commandsell extends EssentialsCommand
|
||||
}
|
||||
try
|
||||
{
|
||||
sellItem(user, stack, args, true);
|
||||
totalWorth += sellItem(user, stack, args, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (totalWorth > 0)
|
||||
{
|
||||
user.sendMessage(_("totalWorthBlocks", type, Util.displayCurrency(totalWorth, ess)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (is == null)
|
||||
@@ -74,7 +83,7 @@ public class Commandsell extends EssentialsCommand
|
||||
sellItem(user, is, args, false);
|
||||
}
|
||||
|
||||
private void sellItem(User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception
|
||||
private double sellItem(User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception
|
||||
{
|
||||
if (is == null || is.getType() == Material.AIR)
|
||||
{
|
||||
@@ -107,19 +116,7 @@ public class Commandsell extends EssentialsCommand
|
||||
int max = 0;
|
||||
for (ItemStack s : user.getInventory().getContents())
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (s.getTypeId() != is.getTypeId())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (s.getDurability() != is.getDurability())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!s.getEnchantments().equals(is.getEnchantments()))
|
||||
if (s == null || !s.isSimilar(is))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -149,19 +146,23 @@ public class Commandsell extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
return worth * amount;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Prices for Enchantments
|
||||
final ItemStack ris = is.clone();
|
||||
ris.setAmount(amount);
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, true, ris);
|
||||
if (!user.getInventory().containsAtLeast(ris, amount)) {
|
||||
// This should never happen.
|
||||
throw new IllegalStateException("Trying to remove more items than are available.");
|
||||
}
|
||||
user.getInventory().removeItem(ris);
|
||||
user.updateInventory();
|
||||
Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(worth * amount, ess), user.getLocation(), ess);
|
||||
user.giveMoney(worth * amount);
|
||||
user.sendMessage(_("itemSold", Util.displayCurrency(worth * amount, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(worth, ess)));
|
||||
logger.log(Level.INFO, _("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(worth * amount, ess), amount, Util.displayCurrency(worth, ess)));
|
||||
|
||||
return worth * amount;
|
||||
}
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@ public class Commandspawner extends EssentialsCommand
|
||||
}
|
||||
|
||||
String name = args[0];
|
||||
int delay = 0;
|
||||
|
||||
Mob mob = null;
|
||||
mob = Mob.fromName(name);
|
||||
@@ -49,11 +50,20 @@ public class Commandspawner extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(_("noPermToSpawnMob"));
|
||||
}
|
||||
if (args.length > 1)
|
||||
{
|
||||
if (Util.isInt(args[1]))
|
||||
{
|
||||
delay = Integer.parseInt(args[1]);
|
||||
}
|
||||
}
|
||||
final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess);
|
||||
charge.isAffordableFor(user);
|
||||
try
|
||||
{
|
||||
((CreatureSpawner)target.getBlock().getState()).setSpawnedType(mob.getType());
|
||||
CreatureSpawner spawner = (CreatureSpawner)target.getBlock().getState();
|
||||
spawner.setSpawnedType(mob.getType());
|
||||
spawner.setDelay(delay);
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
|
@@ -2,20 +2,11 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Mob;
|
||||
import com.earth2me.essentials.Mob.MobException;
|
||||
import com.earth2me.essentials.SpawnMob;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.material.Colorable;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
public class Commandspawnmob extends EssentialsCommand
|
||||
@@ -30,256 +21,41 @@ public class Commandspawnmob extends EssentialsCommand
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
final Set<String> mobList = Mob.getMobList();
|
||||
final Set<String> availableList = new HashSet<String>();
|
||||
for (String mob : mobList)
|
||||
{
|
||||
if (user.isAuthorized("essentials.spawnmob." + mob.toLowerCase()))
|
||||
{
|
||||
availableList.add(mob);
|
||||
}
|
||||
}
|
||||
if (availableList.isEmpty())
|
||||
{
|
||||
availableList.add(_("none"));
|
||||
}
|
||||
throw new NotEnoughArgumentsException(_("mobsAvailable", Util.joinList(availableList)));
|
||||
final String mobList = SpawnMob.mobList(user);
|
||||
throw new NotEnoughArgumentsException(_("mobsAvailable", mobList));
|
||||
}
|
||||
|
||||
String[] mobData = SpawnMob.mobData(args[0]);
|
||||
|
||||
final String[] mountparts = args[0].split(",");
|
||||
String[] parts = mountparts[0].split(":");
|
||||
String mobType = parts[0];
|
||||
String mobData = null;
|
||||
if (parts.length == 2)
|
||||
{
|
||||
mobData = parts[1];
|
||||
}
|
||||
String mountType = null;
|
||||
String mountData = null;
|
||||
if (mountparts.length > 1)
|
||||
{
|
||||
parts = mountparts[1].split(":");
|
||||
mountType = parts[0];
|
||||
if (parts.length == 2)
|
||||
{
|
||||
mountData = parts[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Entity spawnedMob = null;
|
||||
Mob mob = null;
|
||||
Entity spawnedMount = null;
|
||||
Mob mobMount = null;
|
||||
|
||||
mob = Mob.fromName(mobType);
|
||||
if (mob == null)
|
||||
{
|
||||
throw new Exception(_("invalidMob"));
|
||||
}
|
||||
|
||||
if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH)))
|
||||
{
|
||||
throw new Exception(_("disabledToSpawnMob"));
|
||||
}
|
||||
if (!user.isAuthorized("essentials.spawnmob." + mob.name.toLowerCase()))
|
||||
{
|
||||
throw new Exception(_("noPermToSpawnMob"));
|
||||
}
|
||||
|
||||
final Block block = Util.getTarget(user).getBlock();
|
||||
if (block == null)
|
||||
{
|
||||
throw new Exception(_("unableToSpawnMob"));
|
||||
}
|
||||
User otherUser = null;
|
||||
if (args.length >= 3)
|
||||
{
|
||||
otherUser = getPlayer(ess.getServer(), args, 2);
|
||||
}
|
||||
final Location loc = (otherUser == null) ? block.getLocation() : otherUser.getLocation();
|
||||
final Location sloc = Util.getSafeDestination(loc);
|
||||
try
|
||||
{
|
||||
spawnedMob = mob.spawn(user, server, sloc);
|
||||
}
|
||||
catch (MobException e)
|
||||
{
|
||||
throw new Exception(_("unableToSpawnMob"), e);
|
||||
}
|
||||
|
||||
if (mountType != null)
|
||||
{
|
||||
mobMount = Mob.fromName(mountType);
|
||||
if (mobMount == null)
|
||||
{
|
||||
user.sendMessage(_("invalidMob"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ess.getSettings().getProtectPreventSpawn(mobMount.getType().toString().toLowerCase(Locale.ENGLISH)))
|
||||
{
|
||||
throw new Exception(_("disabledToSpawnMob"));
|
||||
}
|
||||
if (!user.isAuthorized("essentials.spawnmob." + mobMount.name.toLowerCase()))
|
||||
{
|
||||
throw new Exception(_("noPermToSpawnMob"));
|
||||
}
|
||||
try
|
||||
{
|
||||
spawnedMount = mobMount.spawn(user, server, loc);
|
||||
}
|
||||
catch (MobException e)
|
||||
{
|
||||
throw new Exception(_("unableToSpawnMob"), e);
|
||||
}
|
||||
spawnedMob.setPassenger(spawnedMount);
|
||||
}
|
||||
if (mobData != null)
|
||||
{
|
||||
changeMobData(mob.getType(), spawnedMob, mobData, user);
|
||||
}
|
||||
if (spawnedMount != null && mountData != null)
|
||||
{
|
||||
changeMobData(mobMount.getType(), spawnedMount, mountData, user);
|
||||
}
|
||||
int mobCount = 1;
|
||||
if (args.length >= 2)
|
||||
{
|
||||
int mobCount = Integer.parseInt(args[1]);
|
||||
int serverLimit = ess.getSettings().getSpawnMobLimit();
|
||||
if (mobCount > serverLimit)
|
||||
{
|
||||
mobCount = serverLimit;
|
||||
user.sendMessage(_("mobSpawnLimit"));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 1; i < mobCount; i++)
|
||||
{
|
||||
spawnedMob = mob.spawn(user, server, loc);
|
||||
if (mobMount != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
spawnedMount = mobMount.spawn(user, server, loc);
|
||||
}
|
||||
catch (MobException e)
|
||||
{
|
||||
throw new Exception(_("unableToSpawnMob"), e);
|
||||
}
|
||||
spawnedMob.setPassenger(spawnedMount);
|
||||
}
|
||||
if (mobData != null)
|
||||
{
|
||||
changeMobData(mob.getType(), spawnedMob, mobData, user);
|
||||
}
|
||||
if (spawnedMount != null && mountData != null)
|
||||
{
|
||||
changeMobData(mobMount.getType(), spawnedMount, mountData, user);
|
||||
}
|
||||
}
|
||||
user.sendMessage(mobCount + " " + mob.name.toLowerCase(Locale.ENGLISH) + mob.suffix + " " + _("spawned"));
|
||||
}
|
||||
catch (MobException e1)
|
||||
{
|
||||
throw new Exception(_("unableToSpawnMob"), e1);
|
||||
}
|
||||
catch (NumberFormatException e2)
|
||||
{
|
||||
throw new Exception(_("numberRequired"), e2);
|
||||
}
|
||||
catch (NullPointerException np)
|
||||
{
|
||||
throw new Exception(_("soloMob"), np);
|
||||
}
|
||||
mobCount = Integer.parseInt(args[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(mob.name + " " + _("spawned"));
|
||||
}
|
||||
}
|
||||
|
||||
private void changeMobData(final EntityType type, final Entity spawned, String data, final User user) throws Exception
|
||||
{
|
||||
data = data.toLowerCase(Locale.ENGLISH);
|
||||
|
||||
if (spawned instanceof Slime)
|
||||
if (args.length >= 3)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Slime)spawned).setSize(Integer.parseInt(data));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(_("slimeMalformedSize"), e);
|
||||
}
|
||||
}
|
||||
if (spawned instanceof Ageable && data.contains("baby"))
|
||||
{
|
||||
((Ageable)spawned).setBaby();
|
||||
final User target = getPlayer(ess.getServer(), args, 2);
|
||||
SpawnMob.spawnmob(ess, server, user, target, mobData, mobCount);
|
||||
return;
|
||||
}
|
||||
if (spawned instanceof Colorable)
|
||||
|
||||
SpawnMob.spawnmob(ess, server, user, mobData, mobCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
final String color = data.toUpperCase(Locale.ENGLISH).replace("BABY", "");
|
||||
try
|
||||
{
|
||||
if (color.equals("RANDOM"))
|
||||
{
|
||||
final Random rand = new Random();
|
||||
((Colorable)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]);
|
||||
}
|
||||
else
|
||||
{
|
||||
((Colorable)spawned).setColor(DyeColor.valueOf(color));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(_("sheepMalformedColor"), e);
|
||||
}
|
||||
}
|
||||
if (spawned instanceof Tameable && data.contains("tamed"))
|
||||
{
|
||||
final Tameable tameable = ((Tameable)spawned);
|
||||
tameable.setTamed(true);
|
||||
tameable.setOwner(user.getBase());
|
||||
}
|
||||
if (type == EntityType.WOLF
|
||||
&& data.contains("angry"))
|
||||
{
|
||||
((Wolf)spawned).setAngry(true);
|
||||
}
|
||||
if (type == EntityType.CREEPER && data.contains("powered"))
|
||||
{
|
||||
((Creeper)spawned).setPowered(true);
|
||||
}
|
||||
if (type == EntityType.OCELOT)
|
||||
{
|
||||
if (data.contains("siamese"))
|
||||
{
|
||||
((Ocelot)spawned).setCatType(Ocelot.Type.SIAMESE_CAT);
|
||||
}
|
||||
else if (data.contains("red"))
|
||||
{
|
||||
((Ocelot)spawned).setCatType(Ocelot.Type.RED_CAT);
|
||||
}
|
||||
else if (data.contains("black"))
|
||||
{
|
||||
((Ocelot)spawned).setCatType(Ocelot.Type.BLACK_CAT);
|
||||
}
|
||||
}
|
||||
if (type == EntityType.VILLAGER)
|
||||
{
|
||||
for (Profession prof : Villager.Profession.values())
|
||||
{
|
||||
if (data.contains(prof.toString().toLowerCase(Locale.ENGLISH)))
|
||||
{
|
||||
((Villager)spawned).setProfession(prof);
|
||||
}
|
||||
}
|
||||
final String mobList = Util.joinList(Mob.getMobList());
|
||||
throw new NotEnoughArgumentsException(_("mobsAvailable", mobList));
|
||||
}
|
||||
|
||||
String[] mobData = SpawnMob.mobData(args[0]);
|
||||
int mobCount = Integer.parseInt(args[1]);
|
||||
|
||||
final User target = getPlayer(ess.getServer(), args, 2);
|
||||
SpawnMob.spawnmob(ess, server, sender, target, mobData, mobCount);
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import com.earth2me.essentials.Console;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.GregorianCalendar;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -35,7 +36,7 @@ public class Commandtempban extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
if (user.isAuthorized("essentials.tempban.exempt"))
|
||||
if (user.isAuthorized("essentials.tempban.exempt") && sender instanceof Player)
|
||||
{
|
||||
sender.sendMessage(_("tempbanExempt"));
|
||||
return;
|
||||
@@ -44,6 +45,13 @@ public class Commandtempban extends EssentialsCommand
|
||||
final String time = getFinalArg(args, 1);
|
||||
final long banTimestamp = Util.parseDateDiff(time, true);
|
||||
|
||||
final long maxBanLength = ess.getSettings().getMaxTempban() * 1000;
|
||||
if (maxBanLength > 0 && ((banTimestamp - GregorianCalendar.getInstance().getTimeInMillis()) > maxBanLength) && !(ess.getUser(sender).isAuthorized("essentials.tempban.unlimited")))
|
||||
{
|
||||
sender.sendMessage(_("oversizedTempban"));
|
||||
throw new NoChargeException();
|
||||
}
|
||||
|
||||
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
|
||||
final String banReason = _("tempBanned", Util.formatDateDiff(banTimestamp), senderName);
|
||||
user.setBanReason(banReason);
|
||||
|
@@ -20,7 +20,9 @@ public class Commandtop extends EssentialsCommand
|
||||
{
|
||||
final int topX = user.getLocation().getBlockX();
|
||||
final int topZ = user.getLocation().getBlockZ();
|
||||
final Location location = new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ);
|
||||
final float pitch = user.getLocation().getPitch();
|
||||
final float yaw = user.getLocation().getYaw();
|
||||
final Location location = new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ, yaw, pitch);
|
||||
user.getTeleport().teleport(location, new Trade(this.getName(), ess), TeleportCause.COMMAND);
|
||||
user.sendMessage(_("teleportTop"));
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import com.earth2me.essentials.Console;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
@@ -40,13 +41,34 @@ public class Commandtp extends EssentialsCommand
|
||||
charge.isAffordableFor(user);
|
||||
user.getTeleport().teleport(player, charge, TeleportCause.COMMAND);
|
||||
throw new NoChargeException();
|
||||
|
||||
case 4:
|
||||
if (!user.isAuthorized("essentials.tp.others"))
|
||||
{
|
||||
throw new Exception(_("noPerm", "essentials.tp.others"));
|
||||
}
|
||||
final User target2 = getPlayer(server, args, 0);
|
||||
final double x = args[1].startsWith("~") ? target2.getLocation().getX() + Integer.parseInt(args[1].substring(1)) : Integer.parseInt(args[1]);
|
||||
final double y = args[2].startsWith("~") ? target2.getLocation().getY() + Integer.parseInt(args[2].substring(1)) : Integer.parseInt(args[2]);
|
||||
final double z = args[3].startsWith("~") ? target2.getLocation().getZ() + Integer.parseInt(args[3].substring(1)) : Integer.parseInt(args[3]);
|
||||
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
|
||||
{
|
||||
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
|
||||
}
|
||||
final Location location = new Location(target2.getWorld(), x, y, z);
|
||||
if (!target2.isTeleportEnabled())
|
||||
{
|
||||
throw new Exception(_("teleportDisabled", target2.getDisplayName()));
|
||||
}
|
||||
target2.getTeleport().now(location, false, TeleportCause.COMMAND);
|
||||
user.sendMessage(_("teleporting"));
|
||||
target2.sendMessage(_("teleporting"));
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
if (!user.isAuthorized("essentials.tp.others"))
|
||||
{
|
||||
throw new Exception(_("noPerm", "essentials.tp.others"));
|
||||
}
|
||||
user.sendMessage(_("teleporting"));
|
||||
final User target = getPlayer(server, args, 0);
|
||||
final User toPlayer = getPlayer(server, args, 1);
|
||||
if (!target.isTeleportEnabled())
|
||||
@@ -63,6 +85,7 @@ public class Commandtp extends EssentialsCommand
|
||||
throw new Exception(_("noPerm", "essentials.worlds." + toPlayer.getWorld().getName()));
|
||||
}
|
||||
target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND);
|
||||
user.sendMessage(_("teleporting"));
|
||||
target.sendMessage(_("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName()));
|
||||
break;
|
||||
}
|
||||
@@ -76,10 +99,28 @@ public class Commandtp extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
sender.sendMessage(_("teleporting"));
|
||||
final User target = getPlayer(server, args, 0);
|
||||
final User toPlayer = getPlayer(server, args, 1);
|
||||
target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND);
|
||||
target.sendMessage(_("teleportAtoB", Console.NAME, toPlayer.getDisplayName()));
|
||||
if (args.length == 2)
|
||||
{
|
||||
final User toPlayer = getPlayer(server, args, 1);
|
||||
target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND);
|
||||
target.sendMessage(_("teleportAtoB", Console.NAME, toPlayer.getDisplayName()));
|
||||
}
|
||||
else if (args.length > 3)
|
||||
{
|
||||
final double x = args[1].startsWith("~") ? target.getLocation().getX() + Integer.parseInt(args[1].substring(1)) : Integer.parseInt(args[1]);
|
||||
final double y = args[2].startsWith("~") ? target.getLocation().getY() + Integer.parseInt(args[2].substring(1)) : Integer.parseInt(args[2]);
|
||||
final double z = args[3].startsWith("~") ? target.getLocation().getZ() + Integer.parseInt(args[3].substring(1)) : Integer.parseInt(args[3]);
|
||||
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
|
||||
{
|
||||
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
|
||||
}
|
||||
final Location location = new Location(target.getWorld(), x, y, z);
|
||||
target.getTeleport().now(location, false, TeleportCause.COMMAND);
|
||||
target.sendMessage(_("teleporting"));
|
||||
} else {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
sender.sendMessage(_("teleporting"));
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
@@ -52,24 +53,24 @@ public class Commandtpaccept extends EssentialsCommand
|
||||
}
|
||||
|
||||
final Trade charge = new Trade(this.getName(), ess);
|
||||
if (user.isTpRequestHere())
|
||||
{
|
||||
charge.isAffordableFor(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
charge.isAffordableFor(target);
|
||||
}
|
||||
user.sendMessage(_("requestAccepted"));
|
||||
target.sendMessage(_("requestAcceptedFrom", user.getDisplayName()));
|
||||
|
||||
if (user.isTpRequestHere())
|
||||
try
|
||||
{
|
||||
target.getTeleport().teleportToMe(user, charge, TeleportCause.COMMAND);
|
||||
if (user.isTpRequestHere())
|
||||
{
|
||||
target.getTeleport().teleportToMe(user, charge, TeleportCause.COMMAND);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.getTeleport().teleport(user, charge, TeleportCause.COMMAND);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
target.getTeleport().teleport(user, charge, TeleportCause.COMMAND);
|
||||
user.sendMessage(_("pendingTeleportCancelled"));
|
||||
ess.showError(target, ex, commandLabel);
|
||||
}
|
||||
user.requestTeleport(null, false);
|
||||
throw new NoChargeException();
|
||||
|
@@ -33,6 +33,7 @@ public class Commandtpahere extends EssentialsCommand
|
||||
player.requestTeleport(user, true);
|
||||
player.sendMessage(_("teleportHereRequest", user.getDisplayName()));
|
||||
player.sendMessage(_("typeTpaccept"));
|
||||
player.sendMessage(_("typeTpdeny"));
|
||||
if (ess.getSettings().getTpaAcceptCancellation() != 0)
|
||||
{
|
||||
player.sendMessage(_("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation()));
|
||||
|
@@ -24,9 +24,9 @@ public class Commandtppos extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
final int x = Integer.parseInt(args[0]);
|
||||
final int y = Integer.parseInt(args[1]);
|
||||
final int z = Integer.parseInt(args[2]);
|
||||
final double x = args[0].startsWith("~") ? user.getLocation().getX() + Integer.parseInt(args[0].substring(1)) : Integer.parseInt(args[0]);
|
||||
final double y = args[1].startsWith("~") ? user.getLocation().getY() + Integer.parseInt(args[1].substring(1)) : Integer.parseInt(args[1]);
|
||||
final double z = args[2].startsWith("~") ? user.getLocation().getZ() + Integer.parseInt(args[2].substring(1)) : Integer.parseInt(args[2]);
|
||||
final Location location = new Location(user.getWorld(), x, y, z);
|
||||
if (args.length > 3)
|
||||
{
|
||||
@@ -36,6 +36,10 @@ public class Commandtppos extends EssentialsCommand
|
||||
{
|
||||
location.setPitch(Float.parseFloat(args[4]));
|
||||
}
|
||||
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
|
||||
{
|
||||
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
|
||||
}
|
||||
final Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
user.sendMessage(_("teleporting"));
|
||||
@@ -52,9 +56,9 @@ public class Commandtppos extends EssentialsCommand
|
||||
}
|
||||
|
||||
User user = ess.getUser(server.getPlayer(args[0]));
|
||||
final int x = Integer.parseInt(args[1]);
|
||||
final int y = Integer.parseInt(args[2]);
|
||||
final int z = Integer.parseInt(args[3]);
|
||||
final double x = args[1].startsWith("~") ? user.getLocation().getX() + Integer.parseInt(args[1].substring(1)) : Integer.parseInt(args[1]);
|
||||
final double y = args[2].startsWith("~") ? user.getLocation().getY() + Integer.parseInt(args[2].substring(1)) : Integer.parseInt(args[2]);
|
||||
final double z = args[3].startsWith("~") ? user.getLocation().getZ() + Integer.parseInt(args[3].substring(1)) : Integer.parseInt(args[3]);
|
||||
final Location location = new Location(user.getWorld(), x, y, z);
|
||||
if (args.length > 4)
|
||||
{
|
||||
@@ -64,8 +68,13 @@ public class Commandtppos extends EssentialsCommand
|
||||
{
|
||||
location.setPitch(Float.parseFloat(args[5]));
|
||||
}
|
||||
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
|
||||
{
|
||||
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
|
||||
}
|
||||
sender.sendMessage(_("teleporting"));
|
||||
user.sendMessage(_("teleporting"));
|
||||
user.getTeleport().teleport(location, null, TeleportCause.COMMAND);
|
||||
|
||||
}
|
||||
}
|
@@ -3,6 +3,8 @@ package com.earth2me.essentials.commands;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commandtptoggle extends EssentialsCommand
|
||||
@@ -12,11 +14,60 @@ public class Commandtptoggle extends EssentialsCommand
|
||||
super("tptoggle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
toggleOtherPlayers(server, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
user.sendMessage(user.toggleTeleportEnabled()
|
||||
? _("teleportationEnabled")
|
||||
: _("teleportationDisabled"));
|
||||
if (args.length > 0 && args[0].trim().length() > 2 && user.isAuthorized("essentials.tptoggle.others"))
|
||||
{
|
||||
toggleOtherPlayers(server, user, args);
|
||||
return;
|
||||
}
|
||||
|
||||
user.sendMessage(user.toggleTeleportEnabled() ? _("teleportationEnabled") : _("teleportationDisabled"));
|
||||
}
|
||||
|
||||
private void toggleOtherPlayers(final Server server, final CommandSender sender, final String[] args)
|
||||
{
|
||||
for (Player matchPlayer : server.matchPlayer(args[0]))
|
||||
{
|
||||
final User player = ess.getUser(matchPlayer);
|
||||
if (player.isHidden())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (args.length > 1)
|
||||
{
|
||||
if (args[1].contains("on") || args[1].contains("ena") || args[1].equalsIgnoreCase("1"))
|
||||
{
|
||||
player.setTeleportEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.setTeleportEnabled(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.toggleTeleportEnabled();
|
||||
}
|
||||
|
||||
final boolean enabled = player.isTeleportEnabled();
|
||||
|
||||
|
||||
player.sendMessage(enabled ? _("teleportationEnabled") : _("teleportationDisabled"));
|
||||
sender.sendMessage(enabled ? _("teleportationEnabledFor", matchPlayer.getDisplayName()) : _("teleportationDisabledFor", matchPlayer.getDisplayName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@@ -23,12 +24,21 @@ public class Commandunban extends EssentialsCommand
|
||||
|
||||
try
|
||||
{
|
||||
final User player = getPlayer(server, args, 0, true);
|
||||
player.setBanned(false);
|
||||
final User user = getPlayer(server, args, 0, true);
|
||||
user.setBanned(false);
|
||||
user.setBanTimeout(0);
|
||||
sender.sendMessage(_("unbannedPlayer"));
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
final OfflinePlayer player = server.getOfflinePlayer(args[0]);
|
||||
if (player.isBanned())
|
||||
{
|
||||
player.setBanned(false);
|
||||
sender.sendMessage(_("unbannedPlayer"));
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception(_("playerNotFound"), e);
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Material;
|
||||
@@ -103,7 +102,7 @@ public class Commandunlimited extends EssentialsCommand
|
||||
{
|
||||
message = "enableUnlimited";
|
||||
enableUnlimited = true;
|
||||
if (!InventoryWorkaround.containsItem(target.getInventory(), true, true, stack))
|
||||
if (!target.getInventory().containsAtLeast(stack, stack.getAmount()))
|
||||
{
|
||||
target.getInventory().addItem(stack);
|
||||
}
|
||||
|
@@ -1,243 +0,0 @@
|
||||
package com.earth2me.essentials.craftbukkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class FakeInventory implements Inventory
|
||||
{
|
||||
ItemStack[] items;
|
||||
|
||||
public FakeInventory(ItemStack[] items)
|
||||
{
|
||||
this.items = new ItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
if (items[i] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
this.items[i] = items[i].clone();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize()
|
||||
{
|
||||
return items.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i)
|
||||
{
|
||||
return items[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack is)
|
||||
{
|
||||
items[i] = is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> addItem(ItemStack... iss)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> removeItem(ItemStack... iss)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents()
|
||||
{
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContents(ItemStack[] iss)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int i)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material mtrl)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(ItemStack is)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int i, int i1)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material mtrl, int i)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(ItemStack is, int i)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(int i)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(Material mtrl)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(ItemStack is)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(int i)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(Material mtrl)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(ItemStack is)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int firstEmpty()
|
||||
{
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
if (items[i] == null || items[i].getTypeId() == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int i)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Material mtrl)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(ItemStack is)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(int i)
|
||||
{
|
||||
items[i] = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
items[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType getType()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getHolder()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator(int index)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
}
|
@@ -699,4 +699,46 @@ public class FakeWorld implements World
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmbientSpawnLimit()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAmbientSpawnLimit(int i)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGameRules()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGameRuleValue(String string)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGameRuleValue(String string, String string1)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGameRule(String string)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createExplosion(double d, double d1, double d2, float f, boolean bln, boolean bln1)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package com.earth2me.essentials.craftbukkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -15,49 +16,17 @@ public final class InventoryWorkaround
|
||||
{
|
||||
}
|
||||
|
||||
public static int first(final Inventory inventory, final ItemStack item, final boolean enforceDurability, final boolean enforceAmount, final boolean enforceEnchantments)
|
||||
{
|
||||
return next(inventory, item, 0, enforceDurability, enforceAmount, enforceEnchantments);
|
||||
}
|
||||
|
||||
public static int next(final Inventory cinventory, final ItemStack item, final int start, final boolean enforceDurability, final boolean enforceAmount, final boolean enforceEnchantments)
|
||||
{
|
||||
final ItemStack[] inventory = cinventory.getContents();
|
||||
for (int i = start; i < inventory.length; i++)
|
||||
{
|
||||
final ItemStack cItem = inventory[i];
|
||||
if (cItem == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.getTypeId() == cItem.getTypeId() && (!enforceAmount || item.getAmount() == cItem.getAmount()) && (!enforceDurability || cItem.getDurability() == item.getDurability()) && (!enforceEnchantments || cItem.getEnchantments().equals(item.getEnchantments())))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int firstPartial(final Inventory cinventory, final ItemStack item, final boolean enforceDurability)
|
||||
{
|
||||
return firstPartial(cinventory, item, enforceDurability, item.getType().getMaxStackSize());
|
||||
}
|
||||
|
||||
public static int firstPartial(final Inventory cinventory, final ItemStack item, final boolean enforceDurability, final int maxAmount)
|
||||
private static int firstPartial(final Inventory inventory, final ItemStack item, final int maxAmount)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
final ItemStack[] inventory = cinventory.getContents();
|
||||
for (int i = 0; i < inventory.length; i++)
|
||||
final ItemStack[] stacks = inventory.getContents();
|
||||
for (int i = 0; i < stacks.length; i++)
|
||||
{
|
||||
final ItemStack cItem = inventory[i];
|
||||
if (cItem == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.getTypeId() == cItem.getTypeId() && cItem.getAmount() < maxAmount && (!enforceDurability || cItem.getDurability() == item.getDurability()) && cItem.getEnchantments().equals(item.getEnchantments()))
|
||||
final ItemStack cItem = stacks[i];
|
||||
if (cItem != null && cItem.getAmount() < maxAmount && cItem.isSimilar(item))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -65,26 +34,24 @@ public final class InventoryWorkaround
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean addAllItems(final Inventory cinventory, final boolean enforceDurability, final ItemStack... items)
|
||||
public static boolean addAllItems(final Inventory inventory, final ItemStack... items)
|
||||
{
|
||||
final Inventory fake = new FakeInventory(cinventory.getContents());
|
||||
if (addItem(fake, enforceDurability, items).isEmpty())
|
||||
final Inventory fakeInventory = Bukkit.getServer().createInventory(null, inventory.getType());
|
||||
fakeInventory.setContents(inventory.getContents());
|
||||
if (addItems(fakeInventory, items).isEmpty())
|
||||
{
|
||||
addItem(cinventory, enforceDurability, items);
|
||||
addItems(inventory, items);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items)
|
||||
public static Map<Integer, ItemStack> addItems(final Inventory inventory, final ItemStack... items)
|
||||
{
|
||||
return addItem(cinventory, forceDurability, 0, items);
|
||||
return addOversizedItems(inventory, 0, items);
|
||||
}
|
||||
|
||||
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean enforceDurability, final int oversizedStacks, final ItemStack... items)
|
||||
public static Map<Integer, ItemStack> addOversizedItems(final Inventory inventory, final int oversizedStacks, final ItemStack... items)
|
||||
{
|
||||
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
|
||||
@@ -95,7 +62,7 @@ public final class InventoryWorkaround
|
||||
|
||||
// combine items
|
||||
|
||||
ItemStack[] combined = new ItemStack[items.length];
|
||||
final ItemStack[] combined = new ItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
if (items[i] == null || items[i].getAmount() < 1)
|
||||
@@ -109,7 +76,7 @@ public final class InventoryWorkaround
|
||||
combined[j] = items[i].clone();
|
||||
break;
|
||||
}
|
||||
if (combined[j].getTypeId() == items[i].getTypeId() && (!enforceDurability || combined[j].getDurability() == items[i].getDurability()) && combined[j].getEnchantments().equals(items[i].getEnchantments()))
|
||||
if (combined[j].isSimilar(items[i]))
|
||||
{
|
||||
combined[j].setAmount(combined[j].getAmount() + items[i].getAmount());
|
||||
break;
|
||||
@@ -130,13 +97,13 @@ public final class InventoryWorkaround
|
||||
{
|
||||
// Do we already have a stack of it?
|
||||
final int maxAmount = oversizedStacks > item.getType().getMaxStackSize() ? oversizedStacks : item.getType().getMaxStackSize();
|
||||
final int firstPartial = firstPartial(cinventory, item, enforceDurability, maxAmount);
|
||||
final int firstPartial = firstPartial(inventory, item, maxAmount);
|
||||
|
||||
// Drat! no partial stack
|
||||
if (firstPartial == -1)
|
||||
{
|
||||
// Find a free spot!
|
||||
final int firstFree = cinventory.firstEmpty();
|
||||
final int firstFree = inventory.firstEmpty();
|
||||
|
||||
if (firstFree == -1)
|
||||
{
|
||||
@@ -151,13 +118,13 @@ public final class InventoryWorkaround
|
||||
{
|
||||
final ItemStack stack = item.clone();
|
||||
stack.setAmount(maxAmount);
|
||||
cinventory.setItem(firstFree, stack);
|
||||
inventory.setItem(firstFree, stack);
|
||||
item.setAmount(item.getAmount() - maxAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just store it
|
||||
cinventory.setItem(firstFree, item);
|
||||
inventory.setItem(firstFree, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -165,7 +132,7 @@ public final class InventoryWorkaround
|
||||
else
|
||||
{
|
||||
// So, apparently it might only partially fit, well lets do just that
|
||||
final ItemStack partialItem = cinventory.getItem(firstPartial);
|
||||
final ItemStack partialItem = inventory.getItem(firstPartial);
|
||||
|
||||
final int amount = item.getAmount();
|
||||
final int partialAmount = partialItem.getAmount();
|
||||
@@ -185,138 +152,4 @@ public final class InventoryWorkaround
|
||||
}
|
||||
return leftover;
|
||||
}
|
||||
|
||||
public static Map<Integer, ItemStack> removeItem(final Inventory cinventory, final boolean enforceDurability, final boolean enforceEnchantments, final ItemStack... items)
|
||||
{
|
||||
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
|
||||
// TODO: optimization
|
||||
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
final ItemStack item = items[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int toDelete = item.getAmount();
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
// Bail when done
|
||||
if (toDelete <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// get first Item, ignore the amount
|
||||
final int first = first(cinventory, item, enforceDurability, false, enforceEnchantments);
|
||||
|
||||
// Drat! we don't have this type in the inventory
|
||||
if (first == -1)
|
||||
{
|
||||
item.setAmount(toDelete);
|
||||
leftover.put(i, item);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
final ItemStack itemStack = cinventory.getItem(first);
|
||||
final int amount = itemStack.getAmount();
|
||||
|
||||
if (amount <= toDelete)
|
||||
{
|
||||
toDelete -= amount;
|
||||
// clear the slot, all used up
|
||||
cinventory.clear(first);
|
||||
}
|
||||
else
|
||||
{
|
||||
// split the stack and store
|
||||
itemStack.setAmount(amount - toDelete);
|
||||
cinventory.setItem(first, itemStack);
|
||||
toDelete = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return leftover;
|
||||
}
|
||||
|
||||
public static boolean containsItem(final Inventory cinventory, final boolean enforceDurability, final boolean enforceEnchantments, final ItemStack... items)
|
||||
{
|
||||
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
|
||||
// TODO: optimization
|
||||
|
||||
// combine items
|
||||
|
||||
ItemStack[] combined = new ItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
if (items[i] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < combined.length; j++)
|
||||
{
|
||||
if (combined[j] == null)
|
||||
{
|
||||
combined[j] = items[i].clone();
|
||||
break;
|
||||
}
|
||||
if (combined[j].getTypeId() == items[i].getTypeId() && (!enforceDurability || combined[j].getDurability() == items[i].getDurability()) && (!enforceEnchantments || combined[j].getEnchantments().equals(items[i].getEnchantments())))
|
||||
{
|
||||
combined[j].setAmount(combined[j].getAmount() + items[i].getAmount());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < combined.length; i++)
|
||||
{
|
||||
final ItemStack item = combined[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int mustHave = item.getAmount();
|
||||
int position = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Bail when done
|
||||
if (mustHave <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
final int slot = next(cinventory, item, position, enforceDurability, false, enforceEnchantments);
|
||||
|
||||
// Drat! we don't have this type in the inventory
|
||||
if (slot == -1)
|
||||
{
|
||||
leftover.put(i, item);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
final ItemStack itemStack = cinventory.getItem(slot);
|
||||
final int amount = itemStack.getAmount();
|
||||
|
||||
if (amount <= mustHave)
|
||||
{
|
||||
mustHave -= amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
mustHave = 0;
|
||||
}
|
||||
position = slot + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return leftover.isEmpty();
|
||||
}
|
||||
}
|
||||
|
@@ -67,6 +67,10 @@ public class SetExpFix
|
||||
exp += getExpAtLevel(currentLevel);
|
||||
currentLevel++;
|
||||
}
|
||||
if (exp < 0)
|
||||
{
|
||||
exp = Integer.MAX_VALUE;
|
||||
}
|
||||
return exp;
|
||||
}
|
||||
|
||||
@@ -82,6 +86,10 @@ public class SetExpFix
|
||||
currentLevel--;
|
||||
exp += getExpAtLevel(currentLevel);
|
||||
}
|
||||
if (exp < 0)
|
||||
{
|
||||
exp = Integer.MAX_VALUE;
|
||||
}
|
||||
return exp;
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,7 +52,7 @@ public class Metrics
|
||||
/**
|
||||
* The current revision number
|
||||
*/
|
||||
private final static int REVISION = 5;
|
||||
private final static int REVISION = 6;
|
||||
/**
|
||||
* The base url of the metrics domain
|
||||
*/
|
||||
@@ -60,10 +61,6 @@ public class Metrics
|
||||
* The url used to report a server's status
|
||||
*/
|
||||
private static final String REPORT_URL = "/report/%s";
|
||||
/**
|
||||
* The file where guid and opt out is stored in
|
||||
*/
|
||||
private static final String CONFIG_FILE = "plugins/PluginMetrics/config.yml";
|
||||
/**
|
||||
* The separator to use for custom data. This MUST NOT change unless you are hosting your own version of metrics and
|
||||
* want to change it.
|
||||
@@ -97,14 +94,18 @@ public class Metrics
|
||||
* Unique server id
|
||||
*/
|
||||
private final String guid;
|
||||
/**
|
||||
* Debug mode
|
||||
*/
|
||||
private final boolean debug;
|
||||
/**
|
||||
* Lock for synchronization
|
||||
*/
|
||||
private final Object optOutLock = new Object();
|
||||
/**
|
||||
* Id of the scheduled task
|
||||
* The scheduled task
|
||||
*/
|
||||
private volatile int taskId = -1;
|
||||
private volatile BukkitTask task = null;
|
||||
|
||||
public Metrics(final Plugin plugin) throws IOException
|
||||
{
|
||||
@@ -116,29 +117,31 @@ public class Metrics
|
||||
this.plugin = plugin;
|
||||
|
||||
// load the config
|
||||
configurationFile = new File(CONFIG_FILE);
|
||||
configurationFile = getConfigFile();
|
||||
configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
||||
|
||||
// add some defaults
|
||||
configuration.addDefault("opt-out", false);
|
||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||
configuration.addDefault("debug", false);
|
||||
|
||||
// Do we need to create the file?
|
||||
if (configuration.get("guid", null) == null)
|
||||
{
|
||||
configuration.options().header("http://metrics.griefcraft.com").copyDefaults(true);
|
||||
configuration.options().header("http://mcstats.org").copyDefaults(true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Load the guid then
|
||||
guid = configuration.getString("guid");
|
||||
debug = configuration.getBoolean("debug", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
|
||||
* website. Plotters can be added to the graph object returned.
|
||||
*
|
||||
* @param name
|
||||
* @param name The name of the graph
|
||||
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
|
||||
*/
|
||||
public Graph createGraph(final String name)
|
||||
@@ -161,7 +164,7 @@ public class Metrics
|
||||
/**
|
||||
* Adds a custom data plotter to the default graph
|
||||
*
|
||||
* @param plotter
|
||||
* @param plotter The plotter to use to plot custom data
|
||||
*/
|
||||
public void addCustomData(final Plotter plotter)
|
||||
{
|
||||
@@ -193,7 +196,7 @@ public class Metrics
|
||||
}
|
||||
|
||||
// Begin hitting the server with glorious data
|
||||
taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable()
|
||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable()
|
||||
{
|
||||
private boolean firstPost = true;
|
||||
|
||||
@@ -205,10 +208,15 @@ public class Metrics
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && taskId > 0)
|
||||
if (isOptOut() && task != null)
|
||||
{
|
||||
plugin.getServer().getScheduler().cancelTask(taskId);
|
||||
taskId = -1;
|
||||
task.cancel();
|
||||
task = null;
|
||||
// Tell all plotters to stop gathering information.
|
||||
for (Graph graph : graphs)
|
||||
{
|
||||
graph.onOptOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +231,10 @@ public class Metrics
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.FINE, "[Metrics] " + e.getMessage());
|
||||
if (debug)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0, PING_INTERVAL * 1200);
|
||||
@@ -233,7 +244,7 @@ public class Metrics
|
||||
/**
|
||||
* Has the server owner denied plugin metrics?
|
||||
*
|
||||
* @return
|
||||
* @return true if metrics should be opted out of it
|
||||
*/
|
||||
public boolean isOptOut()
|
||||
{
|
||||
@@ -242,16 +253,22 @@ public class Metrics
|
||||
try
|
||||
{
|
||||
// Reload the metrics file
|
||||
configuration.load(CONFIG_FILE);
|
||||
configuration.load(getConfigFile());
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
if (debug)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (InvalidConfigurationException ex)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
if (debug)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return configuration.getBoolean("opt-out", false);
|
||||
@@ -276,7 +293,7 @@ public class Metrics
|
||||
}
|
||||
|
||||
// Enable Task, if it is not running
|
||||
if (taskId < 0)
|
||||
if (task == null)
|
||||
{
|
||||
start();
|
||||
}
|
||||
@@ -297,35 +314,81 @@ public class Metrics
|
||||
if (!isOptOut())
|
||||
{
|
||||
configuration.set("opt-out", true);
|
||||
final File file = new File(CONFIG_FILE);
|
||||
configuration.save(file);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (taskId >= 0)
|
||||
if (task != null)
|
||||
{
|
||||
this.plugin.getServer().getScheduler().cancelTask(taskId);
|
||||
taskId = -1;
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile()
|
||||
{
|
||||
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
|
||||
// is to abuse the plugin object we already have
|
||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
||||
// pluginsFolder => base/plugins/
|
||||
// The base is not necessarily relative to the startup directory.
|
||||
File pluginsFolder = plugin.getDataFolder().getParentFile();
|
||||
|
||||
// return => base/plugins/PluginMetrics/config.yml
|
||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*/
|
||||
private void postPlugin(final boolean isPing) throws IOException
|
||||
{
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
final PluginDescriptionFile description = plugin.getDescription();
|
||||
// Server software specific section
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
String pluginName = description.getName();
|
||||
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
String pluginVersion = description.getVersion();
|
||||
String serverVersion = Bukkit.getVersion();
|
||||
int playersOnline = Bukkit.getServer().getOnlinePlayers().length;
|
||||
|
||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
||||
|
||||
// Construct the post data
|
||||
final StringBuilder data = new StringBuilder();
|
||||
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
data.append(encode("guid")).append('=').append(encode(guid));
|
||||
encodeDataPair(data, "version", description.getVersion());
|
||||
encodeDataPair(data, "server", Bukkit.getVersion());
|
||||
encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length));
|
||||
encodeDataPair(data, "version", pluginVersion);
|
||||
encodeDataPair(data, "server", serverVersion);
|
||||
encodeDataPair(data, "players", Integer.toString(playersOnline));
|
||||
encodeDataPair(data, "revision", String.valueOf(REVISION));
|
||||
|
||||
// New data as of R6
|
||||
String osname = System.getProperty("os.name");
|
||||
String osarch = System.getProperty("os.arch");
|
||||
String osversion = System.getProperty("os.version");
|
||||
String java_version = System.getProperty("java.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
// normalize os arch .. amd64 -> x86_64
|
||||
if (osarch.equals("amd64"))
|
||||
{
|
||||
osarch = "x86_64";
|
||||
}
|
||||
|
||||
encodeDataPair(data, "osname", osname);
|
||||
encodeDataPair(data, "osarch", osarch);
|
||||
encodeDataPair(data, "osversion", osversion);
|
||||
encodeDataPair(data, "cores", Integer.toString(coreCount));
|
||||
encodeDataPair(data, "online-mode", Boolean.toString(onlineMode));
|
||||
encodeDataPair(data, "java_version", java_version);
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing)
|
||||
{
|
||||
@@ -342,10 +405,6 @@ public class Metrics
|
||||
{
|
||||
final Graph graph = iter.next();
|
||||
|
||||
// Because we have a lock on the graphs set already, it is reasonable to assume
|
||||
// that our lock transcends down to the individual plotters in the graphs also.
|
||||
// Because our methods are private, no one but us can reasonably access this list
|
||||
// without reflection so this is a safe assumption without adding more code.
|
||||
for (Plotter plotter : graph.getPlotters())
|
||||
{
|
||||
// The key name to send to the metrics server
|
||||
@@ -364,7 +423,7 @@ public class Metrics
|
||||
}
|
||||
|
||||
// Create the url
|
||||
final URL url = new URL(BASE_URL + String.format(REPORT_URL, description.getName()));
|
||||
URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(pluginName)));
|
||||
|
||||
// Connect to the website
|
||||
URLConnection connection;
|
||||
@@ -420,13 +479,12 @@ public class Metrics
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (response.startsWith("OK")) - We should get "OK" followed by an optional description if everything goes right
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
||||
*
|
||||
* @return
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent()
|
||||
{
|
||||
@@ -450,10 +508,9 @@ public class Metrics
|
||||
* encodeDataPair(data, "version", description.getVersion());
|
||||
* </code>
|
||||
*
|
||||
* @param buffer
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
* @param buffer the stringbuilder to append the data pair onto
|
||||
* @param key the key value
|
||||
* @param value the value
|
||||
*/
|
||||
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException
|
||||
{
|
||||
@@ -463,8 +520,8 @@ public class Metrics
|
||||
/**
|
||||
* Encode text as UTF-8
|
||||
*
|
||||
* @param text
|
||||
* @return
|
||||
* @param text the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String encode(final String text) throws UnsupportedEncodingException
|
||||
{
|
||||
@@ -495,7 +552,7 @@ public class Metrics
|
||||
/**
|
||||
* Gets the graph's name
|
||||
*
|
||||
* @return
|
||||
* @return the Graph's name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
@@ -505,7 +562,7 @@ public class Metrics
|
||||
/**
|
||||
* Add a plotter to the graph, which will be used to plot entries
|
||||
*
|
||||
* @param plotter
|
||||
* @param plotter the plotter to add to the graph
|
||||
*/
|
||||
public void addPlotter(final Plotter plotter)
|
||||
{
|
||||
@@ -515,7 +572,7 @@ public class Metrics
|
||||
/**
|
||||
* Remove a plotter from the graph
|
||||
*
|
||||
* @param plotter
|
||||
* @param plotter the plotter to remove from the graph
|
||||
*/
|
||||
public void removePlotter(final Plotter plotter)
|
||||
{
|
||||
@@ -525,7 +582,7 @@ public class Metrics
|
||||
/**
|
||||
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
|
||||
*
|
||||
* @return
|
||||
* @return an unmodifiable {@link Set} of the plotter objects
|
||||
*/
|
||||
public Set<Plotter> getPlotters()
|
||||
{
|
||||
@@ -549,6 +606,13 @@ public class Metrics
|
||||
final Graph graph = (Graph)object;
|
||||
return graph.name.equals(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server owner decides to opt-out of Metrics while the server is running.
|
||||
*/
|
||||
protected void onOptOut()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -573,7 +637,7 @@ public class Metrics
|
||||
/**
|
||||
* Construct a plotter with a specific plot name
|
||||
*
|
||||
* @param name
|
||||
* @param name the name of the plotter to use, which will show up on the website
|
||||
*/
|
||||
public Plotter(final String name)
|
||||
{
|
||||
@@ -581,9 +645,11 @@ public class Metrics
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value for the plotted point
|
||||
* Get the current value for the plotted point. Since this function defers to an external function it may or may
|
||||
* not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called
|
||||
* from any thread so care should be taken when accessing resources that need to be synchronized.
|
||||
*
|
||||
* @return
|
||||
* @return the current value for the point to be plotted.
|
||||
*/
|
||||
public abstract int getValue();
|
||||
|
||||
@@ -607,7 +673,7 @@ public class Metrics
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return getColumnName().hashCode() + getValue();
|
||||
return getColumnName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -33,7 +33,7 @@ public class MetricsListener implements Listener
|
||||
player.sendMessage("To opt out, run /essentials opt-out");
|
||||
ess.getLogger().log(Level.INFO, "[Metrics] Admin join - Starting 5 minute opt-out period.");
|
||||
ess.getSettings().setMetricsEnabled(true);
|
||||
ess.getScheduler().scheduleAsyncDelayedTask(ess, starter, 5 * 1200);
|
||||
ess.getScheduler().runTaskLaterAsynchronously(ess, starter, 5 * 1200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -134,6 +134,14 @@ public class MetricsStarter implements Runnable
|
||||
{
|
||||
enabledGraph.addPlotter(new SimplePlotter("Warps"));
|
||||
}
|
||||
if (ess.getSettings().getTeleportCooldown() > 0)
|
||||
{
|
||||
enabledGraph.addPlotter(new SimplePlotter("TeleportCooldown"));
|
||||
}
|
||||
if (ess.getSettings().getTeleportDelay() > 0)
|
||||
{
|
||||
enabledGraph.addPlotter(new SimplePlotter("TeleportDelay"));
|
||||
}
|
||||
if (!ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
enabledGraph.addPlotter(new SimplePlotter("Signs"));
|
||||
@@ -142,6 +150,14 @@ public class MetricsStarter implements Runnable
|
||||
{
|
||||
enabledGraph.addPlotter(new SimplePlotter("AutoAFK"));
|
||||
}
|
||||
if (ess.getSettings().changePlayerListName())
|
||||
{
|
||||
enabledGraph.addPlotter(new SimplePlotter("PlayerListName"));
|
||||
}
|
||||
if (ess.getSettings().getOperatorColor() != null)
|
||||
{
|
||||
enabledGraph.addPlotter(new SimplePlotter("OpColour"));
|
||||
}
|
||||
if (ess.getSettings().changeDisplayName())
|
||||
{
|
||||
enabledGraph.addPlotter(new SimplePlotter("DisplayName"));
|
||||
|
@@ -35,7 +35,7 @@ public class BPermissions2Handler extends SuperpermsHandler
|
||||
@Override
|
||||
public boolean inGroup(final Player base, final String group)
|
||||
{
|
||||
return ApiLayer.hasGroup(base.getWorld().getName(), CalculableType.USER, base.getName(), group);
|
||||
return ApiLayer.hasGroupRecursive(base.getWorld().getName(), CalculableType.USER, base.getName(), group);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -134,6 +134,17 @@ public class PermissionsHandler implements IPermissionsHandler
|
||||
return;
|
||||
}
|
||||
|
||||
final Plugin simplyPermsPlugin = pluginManager.getPlugin("SimplyPerms");
|
||||
if (simplyPermsPlugin != null && simplyPermsPlugin.isEnabled())
|
||||
{
|
||||
if (!(handler instanceof SimplyPermsHandler))
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Essentials: Using SimplyPerms based permissions.");
|
||||
handler = new SimplyPermsHandler(simplyPermsPlugin);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final Plugin privPlugin = pluginManager.getPlugin("Privileges");
|
||||
if (privPlugin != null && privPlugin.isEnabled())
|
||||
{
|
||||
|
@@ -0,0 +1,56 @@
|
||||
package com.earth2me.essentials.perm;
|
||||
|
||||
import java.util.List;
|
||||
import net.crystalyx.bukkit.simplyperms.SimplyAPI;
|
||||
import net.crystalyx.bukkit.simplyperms.SimplyPlugin;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class SimplyPermsHandler extends SuperpermsHandler
|
||||
{
|
||||
|
||||
private final transient SimplyAPI api;
|
||||
|
||||
public SimplyPermsHandler(final Plugin plugin)
|
||||
{
|
||||
this.api = ((SimplyPlugin) plugin).getAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup(final Player base)
|
||||
{
|
||||
final List<String> groups = api.getPlayerGroups(base.getName());
|
||||
if (groups == null || groups.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return groups.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(final Player base)
|
||||
{
|
||||
return api.getPlayerGroups(base.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(final Player base, final String group)
|
||||
{
|
||||
final List<String> groups = api.getPlayerGroups(base.getName());
|
||||
for (String group1 : groups)
|
||||
{
|
||||
if (group1.equalsIgnoreCase(group))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player base, String group)
|
||||
{
|
||||
return hasPermission(base, "essentials.build") || hasPermission(base, "permissions.allow.build");
|
||||
}
|
||||
|
||||
}
|
@@ -17,6 +17,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
public class EssentialsSign
|
||||
{
|
||||
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
|
||||
|
||||
protected transient final String signName;
|
||||
|
||||
public EssentialsSign(final String signName)
|
||||
@@ -258,6 +259,11 @@ public class EssentialsSign
|
||||
{
|
||||
return EMPTY_SET;
|
||||
}
|
||||
|
||||
public boolean areHeavyEventRequired()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected final void validateTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
|
||||
{
|
||||
|
@@ -32,6 +32,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,6 +44,13 @@ public class SignBlockListener implements Listener
|
||||
|
||||
public boolean protectSignsAndBlocks(final Block block, final Player player)
|
||||
{
|
||||
// prevent any signs be broken by destroying the block they are attached to
|
||||
if (EssentialsSign.checkIfBlockBreaksSigns(block))
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Prevented that a block was broken next to a sign.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final int mat = block.getTypeId();
|
||||
if (mat == SIGN_POST || mat == WALL_SIGN)
|
||||
{
|
||||
@@ -57,15 +65,10 @@ public class SignBlockListener implements Listener
|
||||
}
|
||||
}
|
||||
}
|
||||
// prevent any signs be broken by destroying the block they are attached to
|
||||
if (EssentialsSign.checkIfBlockBreaksSigns(block))
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Prevented that a block was broken next to a sign.");
|
||||
return true;
|
||||
}
|
||||
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockBreak(block, player, ess))
|
||||
{
|
||||
LOGGER.log(Level.INFO, "A block was protected by a sign.");
|
||||
@@ -80,6 +83,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
@@ -105,6 +109,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -129,6 +134,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -148,7 +154,7 @@ public class SignBlockListener implements Listener
|
||||
}
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockPlace(block, event.getPlayer(), ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
@@ -162,6 +168,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -176,7 +183,7 @@ public class SignBlockListener implements Listener
|
||||
}
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockBurn(block, ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
@@ -190,6 +197,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -204,7 +212,7 @@ public class SignBlockListener implements Listener
|
||||
}
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockIgnite(block, ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
@@ -218,6 +226,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -233,7 +242,7 @@ public class SignBlockListener implements Listener
|
||||
}
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockPush(block, ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
@@ -248,6 +257,7 @@ public class SignBlockListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -264,7 +274,7 @@ public class SignBlockListener implements Listener
|
||||
}
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockPush(block, ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
@@ -29,7 +29,7 @@ public class SignBuy extends EssentialsSign
|
||||
charge.isAffordableFor(player);
|
||||
if (!items.pay(player, false))
|
||||
{
|
||||
throw new ChargeException("Inventory full");
|
||||
throw new ChargeException("Inventory full"); //TODO: TL
|
||||
}
|
||||
charge.charge(player);
|
||||
Trade.log("Sign", "Buy", "Interact", username, charge, username, items, sign.getBlock().getLocation(), ess);
|
||||
|
@@ -17,7 +17,16 @@ public class SignEnchant extends EssentialsSign
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||
{
|
||||
final ItemStack stack = sign.getLine(1).equals("*") || sign.getLine(1).equalsIgnoreCase("any") ? null : getItemStack(sign.getLine(1), 1, ess);
|
||||
final ItemStack stack;
|
||||
try
|
||||
{
|
||||
stack = sign.getLine(1).equals("*") || sign.getLine(1).equalsIgnoreCase("any") ? null : getItemStack(sign.getLine(1), 1, ess);
|
||||
}
|
||||
catch (SignException e)
|
||||
{
|
||||
sign.setLine(1, "§c<item|any>");
|
||||
throw e;
|
||||
}
|
||||
final String[] enchantLevel = sign.getLine(2).split(":");
|
||||
if (enchantLevel.length != 2)
|
||||
{
|
||||
@@ -40,7 +49,8 @@ public class SignEnchant extends EssentialsSign
|
||||
sign.setLine(2, "§c<enchant>");
|
||||
throw new SignException(ex.getMessage(), ex);
|
||||
}
|
||||
if (level < 1 || level > enchantment.getMaxLevel())
|
||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && player.isAuthorized("essentials.enchant.allowunsafe");
|
||||
if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel()))
|
||||
{
|
||||
level = enchantment.getMaxLevel();
|
||||
sign.setLine(2, enchantLevel[0] + ":" + level);
|
||||
@@ -49,7 +59,14 @@ public class SignEnchant extends EssentialsSign
|
||||
{
|
||||
if (stack != null)
|
||||
{
|
||||
stack.addEnchantment(enchantment, level);
|
||||
if (allowUnsafe)
|
||||
{
|
||||
stack.addUnsafeEnchantment(enchantment, level);
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.addEnchantment(enchantment, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
@@ -103,13 +120,37 @@ public class SignEnchant extends EssentialsSign
|
||||
final ItemStack toEnchant = playerHand;
|
||||
try
|
||||
{
|
||||
toEnchant.addEnchantment(enchantment, level);
|
||||
if (level == 0)
|
||||
{
|
||||
toEnchant.removeEnchantment(enchantment);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ess.getSettings().allowUnsafeEnchantments())
|
||||
{
|
||||
toEnchant.addUnsafeEnchantment(enchantment, level);
|
||||
}
|
||||
else
|
||||
{
|
||||
toEnchant.addEnchantment(enchantment, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new SignException(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
if (level == 0)
|
||||
{
|
||||
player.sendMessage(_("enchantmentRemoved", enchantmentName.replace('_', ' ')));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(_("enchantmentApplied", enchantmentName.replace('_', ' ')));
|
||||
}
|
||||
|
||||
charge.charge(player);
|
||||
Trade.log("Sign", "Enchant", "Interact", username, charge, username, charge, sign.getBlock().getLocation(), ess);
|
||||
player.updateInventory();
|
||||
|
@@ -24,6 +24,7 @@ public class SignEntityListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,7 +40,7 @@ public class SignEntityListener implements Listener
|
||||
}
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (sign.getBlocks().contains(block.getType()))
|
||||
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType()))
|
||||
{
|
||||
event.setCancelled(!sign.onBlockExplode(block, ess));
|
||||
return;
|
||||
@@ -53,6 +54,7 @@ public class SignEntityListener implements Listener
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,7 +69,7 @@ public class SignEntityListener implements Listener
|
||||
}
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockBreak(block, ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.*;
|
||||
import com.earth2me.essentials.commands.NoChargeException;
|
||||
import java.util.List;
|
||||
@@ -73,6 +74,9 @@ public class SignKit extends EssentialsSign
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
else
|
||||
{
|
||||
throw new SignException(_("noKitPermission", "essentials.kits." + kitName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,11 +25,15 @@ public class SignPlayerListener implements Listener
|
||||
//Right clicking signs with a block in hand, can now fire cancelled events.
|
||||
//This is because when the block place is cancelled (for example not enough space for the block to be placed),
|
||||
//the event will be marked as cancelled, thus preventing 30% of sign purchases.
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled() || (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR))
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
event.getHandlers().unregister(this);
|
||||
return;
|
||||
}
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -62,10 +66,10 @@ public class SignPlayerListener implements Listener
|
||||
final int mat = block.getTypeId();
|
||||
if (mat == Material.SIGN_POST.getId() || mat == Material.WALL_SIGN.getId())
|
||||
{
|
||||
final Sign csign = (Sign)block.getState();
|
||||
final String csign = ((Sign)block.getState()).getLine(0);
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (csign.getLine(0).equalsIgnoreCase(sign.getSuccessName()))
|
||||
if (csign.equalsIgnoreCase(sign.getSuccessName()))
|
||||
{
|
||||
sign.onSignInteract(block, event.getPlayer(), ess);
|
||||
event.setCancelled(true);
|
||||
@@ -77,7 +81,7 @@ public class SignPlayerListener implements Listener
|
||||
{
|
||||
for (EssentialsSign sign : ess.getSettings().enabledSigns())
|
||||
{
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockInteract(block, event.getPlayer(), ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
@@ -241,6 +241,12 @@ public class SignProtection extends EssentialsSign
|
||||
{
|
||||
return protectedBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areHeavyEventRequired()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onBlockPlace(final Block block, final User player, final String username, final IEssentials ess) throws SignException
|
||||
|
@@ -2,9 +2,9 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.SpawnMob;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.commands.Commandspawnmob;
|
||||
|
||||
|
||||
public class SignSpawnmob extends EssentialsSign
|
||||
@@ -27,20 +27,17 @@ public class SignSpawnmob extends EssentialsSign
|
||||
{
|
||||
final Trade charge = getTrade(sign, 3, ess);
|
||||
charge.isAffordableFor(player);
|
||||
Commandspawnmob command = new Commandspawnmob();
|
||||
command.setEssentials(ess);
|
||||
String[] args = new String[]
|
||||
{
|
||||
sign.getLine(2), sign.getLine(1)
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
command.run(ess.getServer(), player, "spawnmob", args);
|
||||
String[] mobData = SpawnMob.mobData(sign.getLine(2));
|
||||
SpawnMob.spawnmob(ess, ess.getServer(), player, player, mobData, Integer.parseInt(sign.getLine(1)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new SignException(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
charge.charge(player);
|
||||
return true;
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> imp
|
||||
this.file = file;
|
||||
this.clazz = clazz;
|
||||
this.plugin = ess;
|
||||
ess.scheduleAsyncDelayedTask(this);
|
||||
ess.runTaskAsynchronously(this);
|
||||
}
|
||||
|
||||
public abstract void onStart();
|
||||
|
@@ -15,7 +15,7 @@ public abstract class AbstractDelayedYamlFileWriter implements Runnable
|
||||
public AbstractDelayedYamlFileWriter(IEssentials ess, File file)
|
||||
{
|
||||
this.file = file;
|
||||
ess.scheduleAsyncDelayedTask(this);
|
||||
ess.runTaskAsynchronously(this);
|
||||
}
|
||||
|
||||
public abstract StorageObject getObject();
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package com.earth2me.essentials.storage;
|
||||
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -13,22 +13,21 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.yaml.snakeyaml.TypeDescription;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
import org.yaml.snakeyaml.introspector.Property;
|
||||
import org.yaml.snakeyaml.nodes.*;
|
||||
|
||||
|
||||
public class BukkitConstructor extends Constructor
|
||||
public class BukkitConstructor extends CustomClassLoaderConstructor
|
||||
{
|
||||
private final transient Pattern NUMPATTERN = Pattern.compile("\\d+");
|
||||
private final transient Plugin plugin;
|
||||
|
||||
public BukkitConstructor(final Class clazz, final Plugin plugin)
|
||||
{
|
||||
super(clazz);
|
||||
super(clazz, plugin.getClass().getClassLoader());
|
||||
this.plugin = plugin;
|
||||
yamlClassConstructors.put(NodeId.scalar, new ConstructBukkitScalar());
|
||||
yamlClassConstructors.put(NodeId.mapping, new ConstructBukkitMapping());
|
||||
@@ -44,7 +43,7 @@ public class BukkitConstructor extends Constructor
|
||||
{
|
||||
final String val = (String)constructScalar((ScalarNode)node);
|
||||
Material mat;
|
||||
if (NUMPATTERN.matcher(val).matches())
|
||||
if (Util.isInt(val))
|
||||
{
|
||||
final int typeId = Integer.parseInt(val);
|
||||
mat = Material.getMaterial(typeId);
|
||||
@@ -68,7 +67,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
Material mat;
|
||||
if (NUMPATTERN.matcher(split[0]).matches())
|
||||
if (Util.isInt(split[0]))
|
||||
{
|
||||
final int typeId = Integer.parseInt(split[0]);
|
||||
mat = Material.getMaterial(typeId);
|
||||
@@ -82,7 +81,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
byte data = 0;
|
||||
if (split.length == 2 && NUMPATTERN.matcher(split[1]).matches())
|
||||
if (split.length == 2 && Util.isInt(split[1]))
|
||||
{
|
||||
data = Byte.parseByte(split[1]);
|
||||
}
|
||||
@@ -106,7 +105,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
Material mat;
|
||||
if (NUMPATTERN.matcher(split2[0]).matches())
|
||||
if (Util.isInt(split2[0]))
|
||||
{
|
||||
final int typeId = Integer.parseInt(split2[0]);
|
||||
mat = Material.getMaterial(typeId);
|
||||
@@ -120,12 +119,12 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
short data = 0;
|
||||
if (split2.length == 2 && NUMPATTERN.matcher(split2[1]).matches())
|
||||
if (split2.length == 2 && Util.isInt(split2[1]))
|
||||
{
|
||||
data = Short.parseShort(split2[1]);
|
||||
}
|
||||
int size = mat.getMaxStackSize();
|
||||
if (split1.length > 1 && NUMPATTERN.matcher(split1[1]).matches())
|
||||
if (split1.length > 1 && Util.isInt(split1[1]))
|
||||
{
|
||||
size = Integer.parseInt(split1[1]);
|
||||
}
|
||||
@@ -140,7 +139,7 @@ public class BukkitConstructor extends Constructor
|
||||
continue;
|
||||
}
|
||||
Enchantment enchantment;
|
||||
if (NUMPATTERN.matcher(split3[0]).matches())
|
||||
if (Util.isInt(split3[0]))
|
||||
{
|
||||
final int enchantId = Integer.parseInt(split3[0]);
|
||||
enchantment = Enchantment.getById(enchantId);
|
||||
@@ -154,7 +153,7 @@ public class BukkitConstructor extends Constructor
|
||||
continue;
|
||||
}
|
||||
int level = enchantment.getStartLevel();
|
||||
if (split3.length == 2 && NUMPATTERN.matcher(split3[1]).matches())
|
||||
if (split3.length == 2 && Util.isInt(split3[1]))
|
||||
{
|
||||
level = Integer.parseInt(split3[1]);
|
||||
}
|
||||
@@ -184,7 +183,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
Enchantment enchant;
|
||||
if (NUMPATTERN.matcher(split[0]).matches())
|
||||
if (Util.isInt(split[0]))
|
||||
{
|
||||
final int typeId = Integer.parseInt(split[0]);
|
||||
enchant = Enchantment.getById(typeId);
|
||||
@@ -198,7 +197,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
int level = enchant.getStartLevel();
|
||||
if (split.length == 2 && NUMPATTERN.matcher(split[1]).matches())
|
||||
if (split.length == 2 && Util.isInt(split[1]))
|
||||
{
|
||||
level = Integer.parseInt(split[1]);
|
||||
}
|
||||
@@ -276,6 +275,7 @@ public class BukkitConstructor extends Constructor
|
||||
return super.construct(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object constructJavaBean2ndStep(final MappingNode node, final Object object)
|
||||
{
|
||||
Map<Class<? extends Object>, TypeDescription> typeDefinitions;
|
||||
@@ -284,7 +284,8 @@ public class BukkitConstructor extends Constructor
|
||||
final Field typeDefField = Constructor.class.getDeclaredField("typeDefinitions");
|
||||
typeDefField.setAccessible(true);
|
||||
typeDefinitions = (Map<Class<? extends Object>, TypeDescription>)typeDefField.get((Constructor)BukkitConstructor.this);
|
||||
if (typeDefinitions == null) {
|
||||
if (typeDefinitions == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
@@ -402,29 +403,4 @@ public class BukkitConstructor extends Constructor
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> getClassForNode(final Node node)
|
||||
{
|
||||
Class<?> clazz;
|
||||
final String name = node.getTag().getClassName();
|
||||
if (plugin == null)
|
||||
{
|
||||
clazz = super.getClassForNode(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
final JavaPluginLoader jpl = (JavaPluginLoader)plugin.getPluginLoader();
|
||||
clazz = jpl.getClassByName(name);
|
||||
}
|
||||
|
||||
if (clazz == null)
|
||||
{
|
||||
throw new YAMLException("Class not found: " + name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
128
Essentials/src/com/earth2me/essentials/textreader/BookInput.java
Normal file
128
Essentials/src/com/earth2me/essentials/textreader/BookInput.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package com.earth2me.essentials.textreader;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import java.io.*;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class BookInput implements IText
|
||||
{
|
||||
private final transient List<String> lines;
|
||||
private final transient List<String> chapters;
|
||||
private final transient Map<String, Integer> bookmarks;
|
||||
private final transient long lastChange;
|
||||
private final static HashMap<String, SoftReference<BookInput>> cache = new HashMap<String, SoftReference<BookInput>>();
|
||||
|
||||
public BookInput(final String filename, final boolean createFile, final IEssentials ess) throws IOException
|
||||
{
|
||||
|
||||
File file = null;
|
||||
if (file == null || !file.exists())
|
||||
{
|
||||
file = new File(ess.getDataFolder(), filename + ".txt");
|
||||
}
|
||||
if (!file.exists())
|
||||
{
|
||||
if (createFile)
|
||||
{
|
||||
final InputStream input = ess.getResource(filename + ".txt");
|
||||
final OutputStream output = new FileOutputStream(file);
|
||||
try
|
||||
{
|
||||
final byte[] buffer = new byte[1024];
|
||||
int length = input.read(buffer);
|
||||
while (length > 0)
|
||||
{
|
||||
output.write(buffer, 0, length);
|
||||
length = input.read(buffer);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
output.close();
|
||||
input.close();
|
||||
}
|
||||
ess.getLogger().info("File " + filename + ".txt does not exist. Creating one for you.");
|
||||
}
|
||||
}
|
||||
if (!file.exists())
|
||||
{
|
||||
lastChange = 0;
|
||||
lines = Collections.emptyList();
|
||||
chapters = Collections.emptyList();
|
||||
bookmarks = Collections.emptyMap();
|
||||
throw new FileNotFoundException("Could not create " + filename + ".txt");
|
||||
}
|
||||
else
|
||||
{
|
||||
lastChange = file.lastModified();
|
||||
boolean readFromfile;
|
||||
synchronized (cache)
|
||||
{
|
||||
final SoftReference<BookInput> inputRef = cache.get(file.getName());
|
||||
BookInput input;
|
||||
if (inputRef == null || (input = inputRef.get()) == null || input.lastChange < lastChange)
|
||||
{
|
||||
lines = new ArrayList<String>();
|
||||
chapters = new ArrayList<String>();
|
||||
bookmarks = new HashMap<String, Integer>();
|
||||
cache.put(file.getName(), new SoftReference<BookInput>(this));
|
||||
readFromfile = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
lines = Collections.unmodifiableList(input.getLines());
|
||||
chapters = Collections.unmodifiableList(input.getChapters());
|
||||
bookmarks = Collections.unmodifiableMap(input.getBookmarks());
|
||||
readFromfile = false;
|
||||
}
|
||||
}
|
||||
if (readFromfile)
|
||||
{
|
||||
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
||||
try
|
||||
{
|
||||
int lineNumber = 0;
|
||||
while (bufferedReader.ready())
|
||||
{
|
||||
final String line = bufferedReader.readLine();
|
||||
if (line == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (line.length() > 0 && line.charAt(0) == '#')
|
||||
{
|
||||
bookmarks.put(line.substring(1).toLowerCase(Locale.ENGLISH).replaceAll("&[0-9a-fk]", ""), lineNumber);
|
||||
chapters.add(line.substring(1).replace('&', '§').replace("§§", "&"));
|
||||
}
|
||||
lines.add(line.replace('&', '§').replace("§§", "&"));
|
||||
lineNumber++;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
bufferedReader.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLines()
|
||||
{
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChapters()
|
||||
{
|
||||
return chapters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getBookmarks()
|
||||
{
|
||||
return bookmarks;
|
||||
}
|
||||
}
|
111
Essentials/src/com/earth2me/essentials/textreader/BookPager.java
Normal file
111
Essentials/src/com/earth2me/essentials/textreader/BookPager.java
Normal file
@@ -0,0 +1,111 @@
|
||||
package com.earth2me.essentials.textreader;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class BookPager
|
||||
{
|
||||
private final transient IText text;
|
||||
|
||||
public BookPager(final IText text)
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public List<String> getPages(final String pageStr) throws Exception
|
||||
{
|
||||
List<String> lines = text.getLines();
|
||||
List<String> chapters = text.getChapters();
|
||||
List<String> pageLines = new ArrayList<String>();
|
||||
Map<String, Integer> bookmarks = text.getBookmarks();
|
||||
|
||||
//This checks to see if we have the chapter in the index
|
||||
if (!bookmarks.containsKey(pageStr.toLowerCase(Locale.ENGLISH)))
|
||||
{
|
||||
throw new Exception(_("infoUnknownChapter"));
|
||||
}
|
||||
|
||||
//Since we have a valid chapter, count the number of lines in the chapter
|
||||
final int chapterstart = bookmarks.get(pageStr.toLowerCase(Locale.ENGLISH)) + 1;
|
||||
int chapterend;
|
||||
for (chapterend = chapterstart; chapterend < lines.size(); chapterend++)
|
||||
{
|
||||
final String line = lines.get(chapterend);
|
||||
if (line.length() > 0 && line.charAt(0) == '#')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int lineNo = chapterstart; lineNo < chapterend; lineNo += 1)
|
||||
{
|
||||
String pageLine = "\u00a70" + lines.get(lineNo);
|
||||
String tempLine;
|
||||
final double max = 18;
|
||||
final int lineLength = pageLine.length();
|
||||
double length = 0;
|
||||
int pointer = 0;
|
||||
int start = 0;
|
||||
double weight = 1;
|
||||
|
||||
while (pointer < lineLength)
|
||||
{
|
||||
if (length >= max)
|
||||
{
|
||||
tempLine = pageLine.substring(start, pointer);
|
||||
pageLines.add(tempLine);
|
||||
start = pointer;
|
||||
length = 0;
|
||||
}
|
||||
|
||||
Character letter = pageLine.charAt(pointer);
|
||||
|
||||
if (letter == '\u00a7')
|
||||
{
|
||||
Character nextLetter = pageLine.charAt(pointer + 1);
|
||||
if (nextLetter == 'l' || nextLetter == 'L')
|
||||
{
|
||||
weight = 1.25;
|
||||
}
|
||||
else
|
||||
{
|
||||
weight = 1;
|
||||
}
|
||||
pointer++;
|
||||
}
|
||||
else if (letter == ' ')
|
||||
{
|
||||
length += (0.7 * weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
length += weight;
|
||||
}
|
||||
pointer++;
|
||||
}
|
||||
if (length > 0)
|
||||
{
|
||||
tempLine = pageLine.substring(start, lineLength);
|
||||
pageLines.add(tempLine);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> pages = new ArrayList<String>();
|
||||
for (int count = 0; count < pageLines.size(); count += 12)
|
||||
{
|
||||
StringBuilder newPage = new StringBuilder();
|
||||
for (int i = count; i < count + 12 && i < pageLines.size(); i++)
|
||||
{
|
||||
newPage.append("\n").append(pageLines.get(i));
|
||||
}
|
||||
|
||||
pages.add(newPage.toString());
|
||||
}
|
||||
|
||||
return pages;
|
||||
}
|
||||
}
|
@@ -47,6 +47,7 @@ public class HelpInput implements IText
|
||||
newLines.clear();
|
||||
lines.add(_("helpFrom", p.getDescription().getName()));
|
||||
}
|
||||
final boolean isOnWhitelist = user.isAuthorized("essentials.help." + pluginNameLow);
|
||||
|
||||
for (Map.Entry<String, Map<String, Object>> k : cmds.entrySet())
|
||||
{
|
||||
@@ -81,7 +82,7 @@ public class HelpInput implements IText
|
||||
{
|
||||
permissions = value.get(PERMISSIONS);
|
||||
}
|
||||
if (user.isAuthorized("essentials.help." + pluginNameLow))
|
||||
if (isOnWhitelist || user.isAuthorized("essentials.help." + pluginNameLow + "." + k.getKey()))
|
||||
{
|
||||
pluginLines.add(_("helpLine", k.getKey(), value.get(DESCRIPTION)));
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package com.earth2me.essentials.textreader;
|
||||
import com.earth2me.essentials.DescParseTickFormat;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -42,7 +43,7 @@ public class KeywordReplacer implements IText
|
||||
userName = user.getName();
|
||||
ipAddress = user.getAddress() == null || user.getAddress().getAddress() == null ? "" : user.getAddress().getAddress().toString();
|
||||
address = user.getAddress() == null ? "" : user.getAddress().toString();
|
||||
balance = Double.toString(user.getMoney());
|
||||
balance = Util.displayCurrency(user.getMoney(), ess);
|
||||
mails = Integer.toString(user.getMails().size());
|
||||
world = user.getLocation() == null || user.getLocation().getWorld() == null ? "" : user.getLocation().getWorld().getName();
|
||||
worldTime12 = DescParseTickFormat.format12(user.getWorld() == null ? 0 : user.getWorld().getTime());
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user