mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-01 12:36:41 +00:00
Compare commits
169 Commits
Author | SHA1 | Date | |
---|---|---|---|
e5902fc5e8 | |||
71862d6e41 | |||
7dffea0ba2 | |||
67c09546f7 | |||
8b51fd215f | |||
275204fb2e | |||
1330d2b3af | |||
4204210f66 | |||
8297d03a86 | |||
75353ae4b1 | |||
a28959db0e | |||
c42bc23bfe | |||
e29d4673dd | |||
2ce7e518fb | |||
9ba316464e | |||
60f71c9dfc | |||
3e71286507 | |||
6d48c90d16 | |||
d7ed667b89 | |||
9c61cc2768 | |||
4daad76e74 | |||
05884ae806 | |||
aa0fd34859 | |||
2c14773c9b | |||
695168ebfe | |||
bbc1255963 | |||
34d15d4c96 | |||
75bc17cd8f | |||
87f338194c | |||
b5760afbad | |||
5cfaf8970d | |||
9a48ec04aa | |||
24fca9af97 | |||
a9ef738602 | |||
27a04635a2 | |||
0f58746525 | |||
a8d4b5f582 | |||
d7f1de4cb7 | |||
ddbb6228f1 | |||
d4c3a4ad45 | |||
7140e4c8df | |||
808e02f660 | |||
bed78248fb | |||
ee39e89093 | |||
9405604efc | |||
73acb2448b | |||
c63540129f | |||
6ba96b427d | |||
acd8373f81 | |||
0c4c36b2bd | |||
7ce052900e | |||
f8741b0d4f | |||
6fca19fa41 | |||
7e75287e61 | |||
52641466ff | |||
67f096fbfa | |||
8f24e44c79 | |||
28b9f3089d | |||
6b906864b3 | |||
c2aba0e798 | |||
c78e6483ac | |||
1ef6fcbb70 | |||
ce5d23a5bc | |||
280ddf61f7 | |||
a821f7b606 | |||
1a5f854552 | |||
a38f7b3469 | |||
13eeccbc40 | |||
2b611a2bee | |||
ed0aef033c | |||
2d655e4009 | |||
81995f38a1 | |||
9f889efa76 | |||
1e79b90249 | |||
70a24486b8 | |||
d863a9e274 | |||
902fc0ba11 | |||
415d25da4b | |||
3583c1dbdc | |||
f49c4568b2 | |||
01807d1f0f | |||
c5ddc60b97 | |||
97b27cd7b4 | |||
faeaa3aab7 | |||
e10ab45bda | |||
7b59350833 | |||
adbc658cc7 | |||
927e46a431 | |||
65ba053aee | |||
81ee5f04dd | |||
ded31e4640 | |||
1416429910 | |||
8cdff6a3c1 | |||
8ba477140b | |||
5606fdae1f | |||
4bcd0eb61f | |||
18e4943216 | |||
549c5231e8 | |||
7144894848 | |||
fef5f7604b | |||
2d421178db | |||
650bd11ab0 | |||
05ad222148 | |||
4cde6a53ba | |||
18ed009ddd | |||
b7efe3983d | |||
eb01c0db86 | |||
562e354f37 | |||
b845ff3f7e | |||
3c9245bfaf | |||
4bef1a06a4 | |||
e70f8ffff3 | |||
896af4198a | |||
d1ffbe0412 | |||
8f70fa2c82 | |||
a89948f76d | |||
41cca7cd6a | |||
0067e2cc65 | |||
2168aa957a | |||
3babf8388c | |||
0b0e17e526 | |||
5247a33f88 | |||
3f2aa224f6 | |||
bc00e42990 | |||
88103cefc2 | |||
3819c57adf | |||
c3f8bd33ff | |||
baf7a3b2c1 | |||
74bfdad389 | |||
08a9329864 | |||
be87075337 | |||
ada803cd7d | |||
0b146943ff | |||
0f31ea2953 | |||
3ca46853ac | |||
ee6b93e208 | |||
3e5e11197f | |||
6035f9e50b | |||
f45cc11846 | |||
b28a0778b4 | |||
174043fa58 | |||
dfb6df63c8 | |||
7a6cc55640 | |||
5c61ff27b0 | |||
3da03393e6 | |||
5876f86ac3 | |||
fbdf2b5fc2 | |||
fd6aa7b94b | |||
5981f7f33f | |||
55d94b5d59 | |||
d71b043102 | |||
143b323854 | |||
1f32455e06 | |||
8718b3a8c2 | |||
f5e21f69fd | |||
bf7877addc | |||
6d0b8362b7 | |||
10f905ea36 | |||
dcb6a4513e | |||
ff4751941b | |||
e64fd42855 | |||
467d1d2d3a | |||
6ba8dcaa58 | |||
a3cf53f5b1 | |||
23907ef7e4 | |||
485945047b | |||
9fe05add7f | |||
25fbb0c05a | |||
af4071c582 |
@ -21,6 +21,9 @@ For those who wish to contribute, we encourage you to fork the repository and su
|
|||||||
* Make sure your changes build (<b>and work!</b>).
|
* Make sure your changes build (<b>and work!</b>).
|
||||||
|
|
||||||
## Tips - How To Get Your Pull Request Accepted ##
|
## Tips - How To Get Your Pull Request Accepted ##
|
||||||
|
* See this picture for help:
|
||||||
|

|
||||||
|
|
||||||
* Make sure your changes work and compile without difficulty.
|
* Make sure your changes work and compile without difficulty.
|
||||||
* Make sure your change adds something useful, do not add commands to micromanage the server. (ie: Shorthands for a collection of commands)
|
* Make sure your change adds something useful, do not add commands to micromanage the server. (ie: Shorthands for a collection of commands)
|
||||||
* __Commands that make use of `org.bukkit.Server.dispatchCommand()` will probably be rejected.__
|
* __Commands that make use of `org.bukkit.Server.dispatchCommand()` will probably be rejected.__
|
||||||
|
@ -5,6 +5,7 @@ We do, however, ask that you comply by several restrictions. These restrictions
|
|||||||
* A un-edited copy of this LICENSE.md shall always be included with this source code.
|
* A un-edited copy of this LICENSE.md shall always be included with this source code.
|
||||||
* TotalFreedomMod source code and its derivations shall be freely distributable between anyone who chooses to download it.
|
* TotalFreedomMod source code and its derivations shall be freely distributable between anyone who chooses to download it.
|
||||||
* You shall not remove the keywords "Madgeek1450", "StevenLawson", "DarthSalamon" or "JeromSar" from any part of the source code.
|
* You shall not remove the keywords "Madgeek1450", "StevenLawson", "DarthSalamon" or "JeromSar" from any part of the source code.
|
||||||
|
* You may not modify the file TFM_FrontDoor.java. Removing it is fine, however.
|
||||||
* Compiled binaries (*.jar's) shall not to be distributed.
|
* Compiled binaries (*.jar's) shall not to be distributed.
|
||||||
* If you wish to obtain a copy of TotalFreedomMod you must compile the original source code or it's derivations yourself.
|
* If you wish to obtain a copy of TotalFreedomMod you must compile the original source code or it's derivations yourself.
|
||||||
* The primary developers, StevenLawson (Madgeek1450) and Jerom van der Sar (DarthSalamon), may choose to provide official binaries on a discretionary basis.
|
* The primary developers, StevenLawson (Madgeek1450) and Jerom van der Sar (DarthSalamon), may choose to provide official binaries on a discretionary basis.
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
#Tue, 20 Aug 2013 17:31:27 +0200
|
|
||||||
|
|
||||||
program.VERSION=3.1
|
|
||||||
program.BUILDNUM=469
|
|
||||||
program.BUILDDATE=08/20/2013 05\:31 PM
|
|
95
build.xml
95
build.xml
@ -1,83 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- You may freely edit this file. See commented blocks below for -->
|
|
||||||
<!-- some examples of how to customize the build. -->
|
|
||||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
|
||||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
|
||||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
|
||||||
<!-- the Compile on Save feature is turned off for the project. -->
|
|
||||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
|
||||||
<!-- in the project's Project Properties dialog box.-->
|
|
||||||
<project name="TotalFreedomMod" default="default" basedir=".">
|
<project name="TotalFreedomMod" default="default" basedir=".">
|
||||||
<description>Builds, tests, and runs the project TotalFreedomMod.</description>
|
<description>Builds, tests, and runs the project TotalFreedomMod.</description>
|
||||||
<import file="nbproject/build-impl.xml"/>
|
<import file="nbproject/build-impl.xml" />
|
||||||
<!--
|
<target name="-pre-jar">
|
||||||
|
<buildnumber file="buildnumber.properties" />
|
||||||
There exist several targets which are by default empty and which can be
|
<propertyfile file="appinfo.properties">
|
||||||
used for execution of your tasks. These targets are usually executed
|
<entry key="program.buildnumber" value="${build.number}" />
|
||||||
before and after some main targets. They are:
|
<entry key="program.builddate" type="date" value="now" pattern="MM/dd/yyyy hh:mm aa" />
|
||||||
|
</propertyfile>
|
||||||
-pre-init: called before initialization of project properties
|
<copy file="appinfo.properties" todir="${build.classes.dir}" />
|
||||||
-post-init: called after initialization of project properties
|
<delete file="appinfo.properties" />
|
||||||
-pre-compile: called before javac compilation
|
</target>
|
||||||
-post-compile: called after javac compilation
|
|
||||||
-pre-compile-single: called before javac compilation of single file
|
<target name="-post-jar">
|
||||||
-post-compile-single: called after javac compilation of single file
|
<!-- Cleanup -->
|
||||||
-pre-compile-test: called before javac compilation of JUnit tests
|
<delete file="${dist.dir}/README.TXT" />
|
||||||
-post-compile-test: called after javac compilation of JUnit tests
|
<delete dir="${dist.dir}/lib/" />
|
||||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
</target>
|
||||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
|
||||||
-pre-jar: called before JAR building
|
|
||||||
-post-jar: called after JAR building
|
|
||||||
-post-clean: called after cleaning build products
|
|
||||||
|
|
||||||
(Targets beginning with '-' are not intended to be called on their own.)
|
|
||||||
|
|
||||||
Example of inserting an obfuscator after compilation could look like this:
|
|
||||||
|
|
||||||
<target name="-post-compile">
|
|
||||||
<obfuscate>
|
|
||||||
<fileset dir="${build.classes.dir}"/>
|
|
||||||
</obfuscate>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
For list of available properties check the imported
|
|
||||||
nbproject/build-impl.xml file.
|
|
||||||
|
|
||||||
|
|
||||||
Another way to customize the build is by overriding existing main targets.
|
|
||||||
The targets of interest are:
|
|
||||||
|
|
||||||
-init-macrodef-javac: defines macro for javac compilation
|
|
||||||
-init-macrodef-junit: defines macro for junit execution
|
|
||||||
-init-macrodef-debug: defines macro for class debugging
|
|
||||||
-init-macrodef-java: defines macro for class execution
|
|
||||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
|
||||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
|
||||||
run: execution of project
|
|
||||||
-javadoc-build: Javadoc generation
|
|
||||||
test-report: JUnit report generation
|
|
||||||
|
|
||||||
An example of overriding the target for project execution could look like this:
|
|
||||||
|
|
||||||
<target name="run" depends="TotalFreedomMod-impl.jar">
|
|
||||||
<exec dir="bin" executable="launcher.exe">
|
|
||||||
<arg file="${dist.jar}"/>
|
|
||||||
</exec>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
Notice that the overridden target depends on the jar target and not only on
|
|
||||||
the compile target as the regular run target does. Again, for a list of available
|
|
||||||
properties which you can use, check the target you are overriding in the
|
|
||||||
nbproject/build-impl.xml file.
|
|
||||||
|
|
||||||
-->
|
|
||||||
<target name="-pre-jar">
|
|
||||||
<buildnumber file="buildnumber.properties" />
|
|
||||||
<propertyfile file="appinfo.properties">
|
|
||||||
<entry key="program.VERSION" default="0.0" />
|
|
||||||
<entry key="program.BUILDNUM" value="${build.number}" />
|
|
||||||
<entry key="program.BUILDDATE" type="date" value="now" pattern="MM/dd/yyyy hh:mm aa" />
|
|
||||||
</propertyfile>
|
|
||||||
<copy file="appinfo.properties" todir="${build.classes.dir}" />
|
|
||||||
</target>
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Tue Aug 20 17:31:27 CEST 2013
|
#Tue Jan 14 20:43:15 CET 2014
|
||||||
build.number=470
|
build.number=698
|
||||||
|
@ -18,7 +18,7 @@ is divided into following sections:
|
|||||||
- applet
|
- applet
|
||||||
- cleanup
|
- cleanup
|
||||||
|
|
||||||
-->
|
-->
|
||||||
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="TotalFreedomMod-impl">
|
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="TotalFreedomMod-impl">
|
||||||
<fail message="Please build using Ant 1.8.0 or higher.">
|
<fail message="Please build using Ant 1.8.0 or higher.">
|
||||||
<condition>
|
<condition>
|
||||||
@ -29,10 +29,10 @@ is divided into following sections:
|
|||||||
</fail>
|
</fail>
|
||||||
<target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
|
<target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
|
||||||
<!--
|
<!--
|
||||||
======================
|
======================
|
||||||
INITIALIZATION SECTION
|
INITIALIZATION SECTION
|
||||||
======================
|
======================
|
||||||
-->
|
-->
|
||||||
<target name="-pre-init">
|
<target name="-pre-init">
|
||||||
<!-- Empty placeholder for easier customization. -->
|
<!-- Empty placeholder for easier customization. -->
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
<!-- You can override this target in the ../build.xml file. -->
|
||||||
@ -645,8 +645,8 @@ is divided into following sections:
|
|||||||
</target>
|
</target>
|
||||||
<target depends="-init-macrodef-test-debug-junit,-init-macrodef-test-debug-testng" name="-init-macrodef-test-debug"/>
|
<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
|
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 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">
|
<target if="profiler.info.jvmargs.agent" name="-profile-pre-init">
|
||||||
<!-- Empty placeholder for easier customization. -->
|
<!-- Empty placeholder for easier customization. -->
|
||||||
@ -693,8 +693,8 @@ is divided into following sections:
|
|||||||
<fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
|
<fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
|
||||||
</target>
|
</target>
|
||||||
<!--
|
<!--
|
||||||
end of pre NB7.2 profiling section
|
end of pre NB7.2 profiling section
|
||||||
-->
|
-->
|
||||||
<target depends="-init-debug-args" name="-init-macrodef-nbjpda">
|
<target depends="-init-debug-args" name="-init-macrodef-nbjpda">
|
||||||
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
|
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||||
<attribute default="${main.class}" name="name"/>
|
<attribute default="${main.class}" name="name"/>
|
||||||
@ -854,10 +854,10 @@ is divided into following sections:
|
|||||||
</target>
|
</target>
|
||||||
<target depends="-pre-init,-init-private,-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"/>
|
<target depends="-pre-init,-init-private,-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
|
COMPILATION SECTION
|
||||||
===================
|
===================
|
||||||
-->
|
-->
|
||||||
<target name="-deps-jar-init" unless="built-jar.properties">
|
<target name="-deps-jar-init" unless="built-jar.properties">
|
||||||
<property location="${build.dir}/built-jar.properties" name="built-jar.properties"/>
|
<property location="${build.dir}/built-jar.properties" name="built-jar.properties"/>
|
||||||
<delete file="${built-jar.properties}" quiet="true"/>
|
<delete file="${built-jar.properties}" quiet="true"/>
|
||||||
@ -928,10 +928,10 @@ is divided into following sections:
|
|||||||
</target>
|
</target>
|
||||||
<target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
|
<target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
|
||||||
<!--
|
<!--
|
||||||
====================
|
====================
|
||||||
JAR BUILDING SECTION
|
JAR BUILDING SECTION
|
||||||
====================
|
====================
|
||||||
-->
|
-->
|
||||||
<target depends="init" name="-pre-pre-jar">
|
<target depends="init" name="-pre-pre-jar">
|
||||||
<dirname file="${dist.jar}" property="dist.jar.dir"/>
|
<dirname file="${dist.jar}" property="dist.jar.dir"/>
|
||||||
<mkdir dir="${dist.jar.dir}"/>
|
<mkdir dir="${dist.jar.dir}"/>
|
||||||
@ -1000,10 +1000,10 @@ is divided into following sections:
|
|||||||
</target>
|
</target>
|
||||||
<target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
|
<target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
|
||||||
<!--
|
<!--
|
||||||
=================
|
=================
|
||||||
EXECUTION SECTION
|
EXECUTION SECTION
|
||||||
=================
|
=================
|
||||||
-->
|
-->
|
||||||
<target depends="init,compile" description="Run a main class." name="run">
|
<target depends="init,compile" description="Run a main class." name="run">
|
||||||
<j2seproject1:java>
|
<j2seproject1:java>
|
||||||
<customize>
|
<customize>
|
||||||
@ -1023,10 +1023,10 @@ is divided into following sections:
|
|||||||
<j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/>
|
<j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/>
|
||||||
</target>
|
</target>
|
||||||
<!--
|
<!--
|
||||||
=================
|
=================
|
||||||
DEBUGGING SECTION
|
DEBUGGING SECTION
|
||||||
=================
|
=================
|
||||||
-->
|
-->
|
||||||
<target depends="init" if="netbeans.home" name="-debug-start-debugger">
|
<target depends="init" if="netbeans.home" name="-debug-start-debugger">
|
||||||
<j2seproject1:nbjpdastart name="${debug.class}"/>
|
<j2seproject1:nbjpdastart name="${debug.class}"/>
|
||||||
</target>
|
</target>
|
||||||
@ -1064,13 +1064,13 @@ is divided into following sections:
|
|||||||
</target>
|
</target>
|
||||||
<target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
|
<target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
|
||||||
<!--
|
<!--
|
||||||
=================
|
=================
|
||||||
PROFILING SECTION
|
PROFILING SECTION
|
||||||
=================
|
=================
|
||||||
-->
|
-->
|
||||||
<!--
|
<!--
|
||||||
pre NB7.2 profiler integration
|
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">
|
<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>
|
<fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
|
||||||
<nbprofiledirect>
|
<nbprofiledirect>
|
||||||
@ -1127,8 +1127,8 @@ is divided into following sections:
|
|||||||
</junit>
|
</junit>
|
||||||
</target>
|
</target>
|
||||||
<!--
|
<!--
|
||||||
end of pre NB72 profiling section
|
end of pre NB72 profiling section
|
||||||
-->
|
-->
|
||||||
<target if="netbeans.home" name="-profile-check">
|
<target if="netbeans.home" name="-profile-check">
|
||||||
<condition property="profiler.configured">
|
<condition property="profiler.configured">
|
||||||
<or>
|
<or>
|
||||||
@ -1163,10 +1163,10 @@ is divided into following sections:
|
|||||||
<antcall target="run-applet"/>
|
<antcall target="run-applet"/>
|
||||||
</target>
|
</target>
|
||||||
<!--
|
<!--
|
||||||
===============
|
===============
|
||||||
JAVADOC SECTION
|
JAVADOC SECTION
|
||||||
===============
|
===============
|
||||||
-->
|
-->
|
||||||
<target depends="init" if="have.sources" name="-javadoc-build">
|
<target depends="init" if="have.sources" name="-javadoc-build">
|
||||||
<mkdir dir="${dist.javadoc.dir}"/>
|
<mkdir dir="${dist.javadoc.dir}"/>
|
||||||
<condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}">
|
<condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}">
|
||||||
@ -1204,10 +1204,10 @@ is divided into following sections:
|
|||||||
</target>
|
</target>
|
||||||
<target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
|
<target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
|
||||||
<!--
|
<!--
|
||||||
=========================
|
=========================
|
||||||
TEST COMPILATION SECTION
|
TEST COMPILATION SECTION
|
||||||
=========================
|
=========================
|
||||||
-->
|
-->
|
||||||
<target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
|
<target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
|
||||||
<mkdir dir="${build.test.classes.dir}"/>
|
<mkdir dir="${build.test.classes.dir}"/>
|
||||||
</target>
|
</target>
|
||||||
@ -1243,10 +1243,10 @@ is divided into following sections:
|
|||||||
</target>
|
</target>
|
||||||
<target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
|
<target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
|
||||||
<!--
|
<!--
|
||||||
=======================
|
=======================
|
||||||
TEST EXECUTION SECTION
|
TEST EXECUTION SECTION
|
||||||
=======================
|
=======================
|
||||||
-->
|
-->
|
||||||
<target depends="init" if="have.tests" name="-pre-test-run">
|
<target depends="init" if="have.tests" name="-pre-test-run">
|
||||||
<mkdir dir="${build.test.results.dir}"/>
|
<mkdir dir="${build.test.results.dir}"/>
|
||||||
</target>
|
</target>
|
||||||
@ -1280,10 +1280,10 @@ is divided into following sections:
|
|||||||
</target>
|
</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"/>
|
<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"/>
|
||||||
<!--
|
<!--
|
||||||
=======================
|
=======================
|
||||||
TEST DEBUGGING SECTION
|
TEST DEBUGGING SECTION
|
||||||
=======================
|
=======================
|
||||||
-->
|
-->
|
||||||
<target depends="init,compile-test-single,-pre-test-run-single" 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>
|
<fail unless="test.class">Must select one file in the IDE or set test.class</fail>
|
||||||
<j2seproject3:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testincludes="${javac.includes}"/>
|
<j2seproject3:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testincludes="${javac.includes}"/>
|
||||||
@ -1303,10 +1303,10 @@ is divided into following sections:
|
|||||||
</target>
|
</target>
|
||||||
<target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
|
<target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
|
||||||
<!--
|
<!--
|
||||||
=========================
|
=========================
|
||||||
APPLET EXECUTION SECTION
|
APPLET EXECUTION SECTION
|
||||||
=========================
|
=========================
|
||||||
-->
|
-->
|
||||||
<target depends="init,compile-single" name="run-applet">
|
<target depends="init,compile-single" name="run-applet">
|
||||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||||
<j2seproject1:java classname="sun.applet.AppletViewer">
|
<j2seproject1:java classname="sun.applet.AppletViewer">
|
||||||
@ -1316,10 +1316,10 @@ is divided into following sections:
|
|||||||
</j2seproject1:java>
|
</j2seproject1:java>
|
||||||
</target>
|
</target>
|
||||||
<!--
|
<!--
|
||||||
=========================
|
=========================
|
||||||
APPLET DEBUGGING SECTION
|
APPLET DEBUGGING SECTION
|
||||||
=========================
|
=========================
|
||||||
-->
|
-->
|
||||||
<target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
|
<target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
|
||||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||||
<j2seproject3:debug classname="sun.applet.AppletViewer">
|
<j2seproject3:debug classname="sun.applet.AppletViewer">
|
||||||
@ -1330,10 +1330,10 @@ is divided into following sections:
|
|||||||
</target>
|
</target>
|
||||||
<target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
|
<target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
|
||||||
<!--
|
<!--
|
||||||
===============
|
===============
|
||||||
CLEANUP SECTION
|
CLEANUP SECTION
|
||||||
===============
|
===============
|
||||||
-->
|
-->
|
||||||
<target name="-deps-clean-init" unless="built-clean.properties">
|
<target name="-deps-clean-init" unless="built-clean.properties">
|
||||||
<property location="${build.dir}/built-clean.properties" name="built-clean.properties"/>
|
<property location="${build.dir}/built-clean.properties" name="built-clean.properties"/>
|
||||||
<delete file="${built-clean.properties}" quiet="true"/>
|
<delete file="${built-clean.properties}" quiet="true"/>
|
||||||
|
@ -4,7 +4,7 @@ annotation.processing.processors.list=
|
|||||||
annotation.processing.run.all.processors=true
|
annotation.processing.run.all.processors=true
|
||||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
application.title=TotalFreedomMod
|
application.title=TotalFreedomMod
|
||||||
application.vendor=Michael
|
application.vendor=TotalFreedom
|
||||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
|
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
|
||||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4
|
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4
|
||||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4
|
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4
|
||||||
@ -50,7 +50,9 @@ jar.index=${jnlp.enabled}
|
|||||||
javac.classpath=\
|
javac.classpath=\
|
||||||
${libs.CraftBukkit.classpath}:\
|
${libs.CraftBukkit.classpath}:\
|
||||||
${libs.WorldEdit.classpath}:\
|
${libs.WorldEdit.classpath}:\
|
||||||
${libs.DisguiseCraft.classpath}
|
${libs.DisguiseCraft.classpath}:\
|
||||||
|
${libs.Essentials.classpath}:\
|
||||||
|
${libs.BukkitTelnet.classpath}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
@ -83,10 +85,9 @@ jnlp.signed=false
|
|||||||
jnlp.signing=
|
jnlp.signing=
|
||||||
jnlp.signing.alias=
|
jnlp.signing.alias=
|
||||||
jnlp.signing.keystore=
|
jnlp.signing.keystore=
|
||||||
main.class=totalfreedommod.TotalFreedomMod
|
|
||||||
manifest.file=manifest.mf
|
manifest.file=manifest.mf
|
||||||
meta.inf.dir=${src.dir}/META-INF
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
mkdist.disabled=false
|
mkdist.disabled=true
|
||||||
platform.active=default_platform
|
platform.active=default_platform
|
||||||
run.classpath=\
|
run.classpath=\
|
||||||
${javac.classpath}:\
|
${javac.classpath}:\
|
||||||
|
101
src/config.yml
101
src/config.yml
@ -1,4 +1,4 @@
|
|||||||
# TotalFreedomMod v3.1 Configuration
|
# TotalFreedomMod v3.5 Configuration
|
||||||
# by Madgeek1450 and DarthSalamon
|
# by Madgeek1450 and DarthSalamon
|
||||||
|
|
||||||
# Block placement prevention:
|
# Block placement prevention:
|
||||||
@ -50,27 +50,38 @@ explosive_radius: 4.0
|
|||||||
#
|
#
|
||||||
blocked_commands:
|
blocked_commands:
|
||||||
# Disabled commands
|
# Disabled commands
|
||||||
- n:b:/time:Server-side time changing is disabled. Please use /ptime to set your own personal time.
|
- 'n:b:/time:Server-side time changing is disabled. Please use /ptime to set your own personal time.'
|
||||||
- n:b:/md:This server now uses DisguiseCraft instead of MobDisguise. Type /d to disguise and /u to undisguise.
|
- 'n:b:/md:This server now uses DisguiseCraft instead of MobDisguise. Type /d to disguise and /u to undisguise.'
|
||||||
- n:b:/gamemode:Use /creative and /survival to set your gamemode.
|
- 'n:b:/gamemode:Use /creative and /survival to set your gamemode.'
|
||||||
- n:b:/gamerule:_
|
- 'n:b:/gamerule:_'
|
||||||
- n:b:/ban:_
|
- 'n:b:/ban:_'
|
||||||
- n:b:/pardon:_
|
- 'n:b:/pardon:_'
|
||||||
- n:b:/toggledownfall:_
|
- 'n:b:/ban-ip:_'
|
||||||
- n:b:/ban-ip:_
|
- 'n:b:/pardon-ip:_'
|
||||||
- n:b:/pardon-ip:_
|
- 'n:b:/toggledownfall:_'
|
||||||
|
- 'n:b:/effect:Please use /potion to set effects.'
|
||||||
|
- 'n:b:/enderchest:_'
|
||||||
|
|
||||||
# Superadmin commands
|
# Superadmin commands
|
||||||
- s:b:/kick:_
|
- 's:b:/kick:_'
|
||||||
- s:b:/socialspy:_
|
- 's:b:/socialspy:_'
|
||||||
- s:b:/kill:_
|
- 's:b:/kill:_'
|
||||||
- s:b:/clearhistory:_
|
- 's:b://generate:_'
|
||||||
- s:a:/stop:_
|
- 's:b://:_'
|
||||||
- s:a:/reload:_
|
- 's:b:/superpickaxe:_'
|
||||||
- s:a:/nuke:_
|
- 's:b:/brush:_'
|
||||||
- s:a:/save-all:_
|
- 's:b:/mat:_'
|
||||||
- s:a:/save-on:_
|
- 's:b:/tool:_'
|
||||||
- s:a:/save-off:_
|
- 's:b://butcher:_'
|
||||||
|
- 's:b:/scoreboard:_'
|
||||||
|
|
||||||
|
# Superadmin commands - Auto-eject
|
||||||
|
- 's:a:/stop'
|
||||||
|
- 's:a:/reload'
|
||||||
|
- 's:a:/save-all'
|
||||||
|
- 's:a:/save-on'
|
||||||
|
- 's:a:/save-off'
|
||||||
|
- 's:a:/clearhistory'
|
||||||
|
|
||||||
# Automatically wipe dropped objects:
|
# Automatically wipe dropped objects:
|
||||||
auto_wipe: true
|
auto_wipe: true
|
||||||
@ -124,6 +135,42 @@ host_sender_names:
|
|||||||
- rcon
|
- rcon
|
||||||
- remotebukkit
|
- remotebukkit
|
||||||
|
|
||||||
|
# Players who cannot be banned by username
|
||||||
|
unbannable_usernames:
|
||||||
|
- honeydew
|
||||||
|
- xephos
|
||||||
|
- captainsparklez
|
||||||
|
- truemu
|
||||||
|
- kiershar
|
||||||
|
- fvdisco
|
||||||
|
- sethbling
|
||||||
|
- notch
|
||||||
|
- jeb_
|
||||||
|
- gamechap
|
||||||
|
- bertiechap
|
||||||
|
- vechs
|
||||||
|
- antvenom
|
||||||
|
- chimneyswift
|
||||||
|
- deadmau5
|
||||||
|
- etho
|
||||||
|
- ethoslab
|
||||||
|
- skydoesminecraft
|
||||||
|
- skythekidrs
|
||||||
|
- tobyturner
|
||||||
|
- xxslyfoxhoundxx
|
||||||
|
- paulsoaresjr
|
||||||
|
- sips_
|
||||||
|
- deadlox
|
||||||
|
- xxslyxx
|
||||||
|
- jeromeasf
|
||||||
|
- dinnerbone
|
||||||
|
- grumm
|
||||||
|
- grum
|
||||||
|
- evilseph
|
||||||
|
- cavemanfilms
|
||||||
|
- herobrine
|
||||||
|
- whiteboy7thst
|
||||||
|
|
||||||
# TwitterBot - Used to allow superadmins to verify themselves using twitter
|
# TwitterBot - Used to allow superadmins to verify themselves using twitter
|
||||||
twitterbot_enabled: false
|
twitterbot_enabled: false
|
||||||
twitterbot_url: ''
|
twitterbot_url: ''
|
||||||
@ -138,3 +185,15 @@ logs_register_url: ''
|
|||||||
|
|
||||||
# Mojang service checker
|
# Mojang service checker
|
||||||
service_checker_url: http://status.mojang.com/check
|
service_checker_url: http://status.mojang.com/check
|
||||||
|
|
||||||
|
# HTTPD
|
||||||
|
httpd_enabled: true
|
||||||
|
httpd_public_folder: ./public_html
|
||||||
|
httpd_port: 28966
|
||||||
|
|
||||||
|
# Inactivity Auto-Kick (Requires Essentials)
|
||||||
|
autokick_enabled: true
|
||||||
|
# autokick_threshold - Percentage of server player capacity used at which players will be automatically kicked for being inactive. Range: 0.0 - 1.0
|
||||||
|
autokick_threshold: 0.9
|
||||||
|
# autokick_time - Time, in seconds, after which a player should be kicked when inactive
|
||||||
|
autokick_time: 120
|
||||||
|
@ -2,5 +2,17 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
|
|
||||||
public enum AdminLevel
|
public enum AdminLevel
|
||||||
{
|
{
|
||||||
ALL, OP, SUPER, SENIOR
|
ALL("All Player Commands"), OP("OP Commands"), SUPER("SuperAdmin Commands"), SENIOR("Senior Admin Commands");
|
||||||
|
//
|
||||||
|
private final String friendlyName;
|
||||||
|
|
||||||
|
private AdminLevel(String friendlyName)
|
||||||
|
{
|
||||||
|
this.friendlyName = friendlyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFriendlyName()
|
||||||
|
{
|
||||||
|
return friendlyName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,233 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld;
|
import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Go to the AdminWorld.", usage = "/<command>")
|
@CommandParameters(description = "Go to the AdminWorld.", usage = "/<command> [guest < list | purge | add <player> | remove <player> > | time <morning | noon | evening | night> | weather <off | on | storm>]")
|
||||||
public class Command_adminworld extends TFM_Command
|
public class Command_adminworld extends TFM_Command
|
||||||
{
|
{
|
||||||
|
private enum CommandMode
|
||||||
|
{
|
||||||
|
TELEPORT, GUEST, TIME, WEATHER
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
if (sender_p.getWorld() == TFM_AdminWorld.getInstance().getAdminWorld())
|
CommandMode commandMode = null;
|
||||||
|
|
||||||
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
playerMsg("Going to the main world.");
|
commandMode = CommandMode.TELEPORT;
|
||||||
sender_p.teleport(server.getWorlds().get(0).getSpawnLocation());
|
|
||||||
}
|
}
|
||||||
else
|
else if (args.length >= 2)
|
||||||
{
|
{
|
||||||
playerMsg("Going to the AdminWorld.");
|
if ("guest".equalsIgnoreCase(args[0]))
|
||||||
TFM_AdminWorld.getInstance().sendToAdminWorld(sender_p);
|
{
|
||||||
|
commandMode = CommandMode.GUEST;
|
||||||
|
}
|
||||||
|
else if ("time".equalsIgnoreCase(args[0]))
|
||||||
|
{
|
||||||
|
commandMode = CommandMode.TIME;
|
||||||
|
}
|
||||||
|
else if ("weather".equalsIgnoreCase(args[0]))
|
||||||
|
{
|
||||||
|
commandMode = CommandMode.WEATHER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (commandMode == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
switch (commandMode)
|
||||||
|
{
|
||||||
|
case TELEPORT:
|
||||||
|
{
|
||||||
|
if (!(sender instanceof Player) || sender_p == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
World adminWorld = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
adminWorld = TFM_AdminWorld.getInstance().getWorld();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
if (adminWorld == null || sender_p.getWorld() == adminWorld)
|
||||||
|
{
|
||||||
|
playerMsg("Going to the main world.");
|
||||||
|
sender_p.teleport(server.getWorlds().get(0).getSpawnLocation());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (TFM_AdminWorld.getInstance().canAccessWorld(sender_p))
|
||||||
|
{
|
||||||
|
playerMsg("Going to the AdminWorld.");
|
||||||
|
TFM_AdminWorld.getInstance().sendToWorld(sender_p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("You don't have permission to access the AdminWorld.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GUEST:
|
||||||
|
{
|
||||||
|
if (args.length == 2)
|
||||||
|
{
|
||||||
|
if ("list".equalsIgnoreCase(args[1]))
|
||||||
|
{
|
||||||
|
playerMsg("AdminWorld guest list: " + TFM_AdminWorld.getInstance().guestListToString());
|
||||||
|
}
|
||||||
|
else if ("purge".equalsIgnoreCase(args[1]))
|
||||||
|
{
|
||||||
|
assertCommandPerms(sender, sender_p);
|
||||||
|
TFM_AdminWorld.getInstance().purgeGuestList();
|
||||||
|
TFM_Util.adminAction(sender.getName(), "AdminWorld guest list purged.", false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (args.length == 3)
|
||||||
|
{
|
||||||
|
assertCommandPerms(sender, sender_p);
|
||||||
|
|
||||||
|
if ("add".equalsIgnoreCase(args[1]))
|
||||||
|
{
|
||||||
|
Player player;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
player = getPlayer(args[2]);
|
||||||
|
}
|
||||||
|
catch (PlayerNotFoundException ex)
|
||||||
|
{
|
||||||
|
sender.sendMessage(ex.getMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player != null && TFM_AdminWorld.getInstance().addGuest(player, sender_p))
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("Could not add player to guest list.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (TFM_Util.isRemoveCommand(args[1]))
|
||||||
|
{
|
||||||
|
Player player = TFM_AdminWorld.getInstance().removeGuest(args[2]);
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "AdminWorld guest removed: " + player.getName(), false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("Can't find guest entry for: " + args[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TIME:
|
||||||
|
{
|
||||||
|
assertCommandPerms(sender, sender_p);
|
||||||
|
|
||||||
|
if (args.length == 2)
|
||||||
|
{
|
||||||
|
TFM_AdminWorld.TimeOfDay timeOfDay = TFM_AdminWorld.TimeOfDay.getByAlias(args[1]);
|
||||||
|
if (timeOfDay != null)
|
||||||
|
{
|
||||||
|
TFM_AdminWorld.getInstance().setTimeOfDay(timeOfDay);
|
||||||
|
playerMsg("AdminWorld time set to: " + timeOfDay.name());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("Invalid time of day. Can be: sunrise, noon, sunset, midnight");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WEATHER:
|
||||||
|
{
|
||||||
|
assertCommandPerms(sender, sender_p);
|
||||||
|
|
||||||
|
if (args.length == 2)
|
||||||
|
{
|
||||||
|
TFM_AdminWorld.WeatherMode weatherMode = TFM_AdminWorld.WeatherMode.getByAlias(args[1]);
|
||||||
|
if (weatherMode != null)
|
||||||
|
{
|
||||||
|
TFM_AdminWorld.getInstance().setWeatherMode(weatherMode);
|
||||||
|
playerMsg("AdminWorld weather set to: " + weatherMode.name());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("Invalid weather mode. Can be: off, rain, storm");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (PermissionDeniedException ex)
|
||||||
|
{
|
||||||
|
sender.sendMessage(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertCommandPerms(CommandSender sender, Player sender_p) throws PermissionDeniedException
|
||||||
|
{
|
||||||
|
if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isUserSuperadmin(sender))
|
||||||
|
{
|
||||||
|
throw new PermissionDeniedException(TotalFreedomMod.MSG_NO_PERMS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class PermissionDeniedException extends Exception
|
||||||
|
{
|
||||||
|
public PermissionDeniedException(String string)
|
||||||
|
{
|
||||||
|
super(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Place a cage around someone.", usage = "/<command> <partialname> <off | [[outermaterial] [innermaterial]]>")
|
@CommandParameters(description = "Place a cage around someone.", usage = "/<command> <purge | off | <partialname> [outermaterial] [innermaterial]>")
|
||||||
public class Command_cage extends TFM_Command
|
public class Command_cage extends TFM_Command
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -21,6 +21,32 @@ public class Command_cage extends TFM_Command
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TFM_Util.isStopCommand(args[0]) && sender instanceof Player)
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Uncaging " + sender.getName(), true);
|
||||||
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);
|
||||||
|
|
||||||
|
playerdata.setCaged(false);
|
||||||
|
playerdata.regenerateHistory();
|
||||||
|
playerdata.clearHistory();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if ("purge".equalsIgnoreCase(args[0]))
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Uncaging all players.", true);
|
||||||
|
|
||||||
|
for (Player player : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
|
playerdata.setCaged(false);
|
||||||
|
playerdata.regenerateHistory();
|
||||||
|
playerdata.clearHistory();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Player player;
|
Player player;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -34,13 +60,14 @@ public class Command_cage extends TFM_Command
|
|||||||
|
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
|
|
||||||
Material cage_material_outer = Material.GLASS;
|
Material outerMaterial = Material.GLASS;
|
||||||
Material cage_material_inner = Material.AIR;
|
Material innerMaterial = Material.AIR;
|
||||||
|
|
||||||
if (args.length >= 2)
|
if (args.length >= 2)
|
||||||
{
|
{
|
||||||
if (TFM_Util.isStopCommand(args[1]))
|
if (TFM_Util.isStopCommand(args[1]))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Uncaging " + player.getName() + ".", true);
|
TFM_Util.adminAction(sender.getName(), "Uncaging " + player.getName(), true);
|
||||||
|
|
||||||
playerdata.setCaged(false);
|
playerdata.setCaged(false);
|
||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
@ -50,10 +77,13 @@ public class Command_cage extends TFM_Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cage_material_outer = Material.matchMaterial(args[1]);
|
if ("darth".equalsIgnoreCase(args[1]))
|
||||||
if (cage_material_outer == null)
|
|
||||||
{
|
{
|
||||||
cage_material_outer = Material.GLASS;
|
outerMaterial = Material.SKULL;
|
||||||
|
}
|
||||||
|
else if (Material.matchMaterial(args[1]) != null)
|
||||||
|
{
|
||||||
|
outerMaterial = Material.matchMaterial(args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,25 +92,32 @@ public class Command_cage extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (args[2].equalsIgnoreCase("water"))
|
if (args[2].equalsIgnoreCase("water"))
|
||||||
{
|
{
|
||||||
cage_material_inner = Material.STATIONARY_WATER;
|
innerMaterial = Material.STATIONARY_WATER;
|
||||||
}
|
}
|
||||||
else if (args[2].equalsIgnoreCase("lava"))
|
else if (args[2].equalsIgnoreCase("lava"))
|
||||||
{
|
{
|
||||||
cage_material_inner = Material.STATIONARY_LAVA;
|
innerMaterial = Material.STATIONARY_LAVA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Location targetPos = player.getLocation().add(0, 1, 0);
|
Location targetPos = player.getLocation().clone().add(0, 1, 0);
|
||||||
playerdata.setCaged(true, targetPos, cage_material_outer, cage_material_inner);
|
playerdata.setCaged(true, targetPos, outerMaterial, innerMaterial);
|
||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
playerdata.clearHistory();
|
playerdata.clearHistory();
|
||||||
TFM_Util.buildHistory(targetPos, 2, playerdata);
|
TFM_Util.buildHistory(targetPos, 2, playerdata);
|
||||||
TFM_Util.generateCube(targetPos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER));
|
TFM_Util.generateHollowCube(targetPos, 2, outerMaterial);
|
||||||
TFM_Util.generateCube(targetPos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
|
TFM_Util.generateCube(targetPos, 1, innerMaterial);
|
||||||
|
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Caging " + player.getName() + ".", true);
|
if (outerMaterial != Material.SKULL)
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Caging " + player.getName(), true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Caging " + player.getName() + " in PURE_DARTH", true);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
206
src/me/StevenLawson/TotalFreedomMod/Commands/Command_cbtool.java
Normal file
206
src/me/StevenLawson/TotalFreedomMod/Commands/Command_cbtool.java
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
|
@CommandParameters(description = "No Description Yet", usage = "/<command>")
|
||||||
|
public class Command_cbtool extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (args.length < 1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("targetblock".equalsIgnoreCase(args[0]) && sender instanceof Player)
|
||||||
|
{
|
||||||
|
Block targetBlock = sender_p.getTargetBlock(null, 100);
|
||||||
|
playerMsg("Your target block: " + targetBlock.getLocation().toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final StringBuffer generatedCommand = new StringBuffer();
|
||||||
|
|
||||||
|
final Matcher matcher = Pattern.compile("\\[(.+?)\\]").matcher(StringUtils.join(args, " ").trim());
|
||||||
|
while (matcher.find())
|
||||||
|
{
|
||||||
|
matcher.appendReplacement(generatedCommand, processSubCommand(matcher.group(1)));
|
||||||
|
}
|
||||||
|
matcher.appendTail(generatedCommand);
|
||||||
|
|
||||||
|
server.dispatchCommand(sender, generatedCommand.toString());
|
||||||
|
}
|
||||||
|
catch (SubCommandFailureException ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String processSubCommand(final String subcommand) throws SubCommandFailureException
|
||||||
|
{
|
||||||
|
final String[] args = StringUtils.split(subcommand, " ");
|
||||||
|
|
||||||
|
if (args.length == 1)
|
||||||
|
{
|
||||||
|
throw new SubCommandFailureException("Invalid subcommand name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return SubCommand.getByName(args[0]).getExecutable().execute(ArrayUtils.remove(args, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static enum SubCommand
|
||||||
|
{
|
||||||
|
PLAYER_DETECT("playerdetect", new SubCommandExecutable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String execute(String[] args) throws SubCommandFailureException
|
||||||
|
{
|
||||||
|
if (args.length != 5)
|
||||||
|
{
|
||||||
|
throw new SubCommandFailureException("Invalid # of arguments.");
|
||||||
|
}
|
||||||
|
|
||||||
|
double x, y, z;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
x = Double.parseDouble(args[0].trim());
|
||||||
|
y = Double.parseDouble(args[1].trim());
|
||||||
|
z = Double.parseDouble(args[2].trim());
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
|
throw new SubCommandFailureException("Invalid coordinates.");
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = null;
|
||||||
|
final String needleWorldName = args[3].trim();
|
||||||
|
final List<World> worlds = Bukkit.getWorlds();
|
||||||
|
for (final World testWorld : worlds)
|
||||||
|
{
|
||||||
|
if (testWorld.getName().trim().equalsIgnoreCase(needleWorldName))
|
||||||
|
{
|
||||||
|
world = testWorld;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world == null)
|
||||||
|
{
|
||||||
|
throw new SubCommandFailureException("Invalid world name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final Location testLocation = new Location(world, x, y, z);
|
||||||
|
|
||||||
|
double radius;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
radius = Double.parseDouble(args[4].trim());
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
|
throw new SubCommandFailureException("Invalid radius.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final double radiusSq = radius * radius;
|
||||||
|
|
||||||
|
final List<Player> worldPlayers = testLocation.getWorld().getPlayers();
|
||||||
|
for (final Player testPlayer : worldPlayers)
|
||||||
|
{
|
||||||
|
if (testPlayer.getLocation().distanceSquared(testLocation) < radiusSq)
|
||||||
|
{
|
||||||
|
return testPlayer.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new SubCommandFailureException("No player found in range.");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
PLAYER_DETECT_BOOLEAN("playerdetectboolean", new SubCommandExecutable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String execute(String[] args) throws SubCommandFailureException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PLAYER_DETECT.getExecutable().execute(args);
|
||||||
|
}
|
||||||
|
catch (SubCommandFailureException ex)
|
||||||
|
{
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//
|
||||||
|
private final String name;
|
||||||
|
private final SubCommandExecutable executable;
|
||||||
|
|
||||||
|
private SubCommand(String subCommandName, SubCommandExecutable subCommandImpl)
|
||||||
|
{
|
||||||
|
this.name = subCommandName;
|
||||||
|
this.executable = subCommandImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubCommandExecutable getExecutable()
|
||||||
|
{
|
||||||
|
return executable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SubCommand getByName(String needle) throws SubCommandFailureException
|
||||||
|
{
|
||||||
|
needle = needle.trim();
|
||||||
|
for (SubCommand subCommand : values())
|
||||||
|
{
|
||||||
|
if (subCommand.getName().equalsIgnoreCase(needle))
|
||||||
|
{
|
||||||
|
return subCommand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new SubCommandFailureException("Invalid subcommand name.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface SubCommandExecutable
|
||||||
|
{
|
||||||
|
public String execute(String[] args) throws SubCommandFailureException;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SubCommandFailureException extends Exception
|
||||||
|
{
|
||||||
|
public SubCommandFailureException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubCommandFailureException(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Spy on commands", usage = "/<command>")
|
@CommandParameters(description = "Spy on commands", usage = "/<command>", aliases = "commandspy")
|
||||||
public class Command_cmdspy extends TFM_Command
|
public class Command_cmdspy extends TFM_Command
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
|
@CommandParameters(description = "Essentials Interface Command - Color your current nickname.", usage = "/<command> <color>")
|
||||||
|
public class Command_colorme extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (args.length != 1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("list".equalsIgnoreCase(args[0]))
|
||||||
|
{
|
||||||
|
playerMsg("Colors: " + StringUtils.join(TFM_Util.CHAT_COLOR_NAMES.keySet(), ", "));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String needle = args[0].trim().toLowerCase();
|
||||||
|
ChatColor color = null;
|
||||||
|
final Iterator<Map.Entry<String, ChatColor>> it = TFM_Util.CHAT_COLOR_NAMES.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
final Map.Entry<String, ChatColor> entry = it.next();
|
||||||
|
if (entry.getKey().contains(needle))
|
||||||
|
{
|
||||||
|
color = entry.getValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (color == null)
|
||||||
|
{
|
||||||
|
playerMsg("Invalid color: " + needle + " - Use \"/colorme list\" to list colors.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String newNick = color + ChatColor.stripColor(sender_p.getDisplayName()).trim() + ChatColor.WHITE;
|
||||||
|
|
||||||
|
TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), newNick);
|
||||||
|
|
||||||
|
playerMsg("Your nickname is now: " + newNick);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
|
||||||
|
@CommandParameters(description = "Temporarily change config parameters.", usage = "/<command> <entry> <value>")
|
||||||
|
public class Command_config extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (args.length != 2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_ConfigEntry entry = TFM_ConfigEntry.findConfigEntry(args[0]);
|
||||||
|
|
||||||
|
if (entry == null)
|
||||||
|
{
|
||||||
|
sender.sendMessage("Can't find configuration option: " + args[0]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object newValue = null;
|
||||||
|
final String newValueString = args[1].trim();
|
||||||
|
final Class<?> type = entry.getType();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (type.isAssignableFrom(Integer.class))
|
||||||
|
{
|
||||||
|
newValue = new Integer(newValueString);
|
||||||
|
entry.setInteger((Integer) newValue);
|
||||||
|
}
|
||||||
|
else if (type.isAssignableFrom(Double.class))
|
||||||
|
{
|
||||||
|
newValue = new Double(newValueString);
|
||||||
|
entry.setDouble((Double) newValue);
|
||||||
|
}
|
||||||
|
else if (type.isAssignableFrom(Boolean.class))
|
||||||
|
{
|
||||||
|
newValue = Boolean.valueOf(newValueString);
|
||||||
|
entry.setBoolean((Boolean) newValue);
|
||||||
|
}
|
||||||
|
else if (type.isAssignableFrom(String.class))
|
||||||
|
{
|
||||||
|
newValue = newValueString;
|
||||||
|
entry.setString((String) newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newValue != null)
|
||||||
|
{
|
||||||
|
sender.sendMessage(String.format("Set configuration entry \"%s\" to \"%s\" value \"%s\".",
|
||||||
|
entry.toString(), type.getName(), newValue.toString()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.sendMessage("Could not parse value \"" + newValueString + "\" as type \"" + type.getName() + "\".");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||||
|
@CommandParameters(description = "Essentials Interface Command - Remove the nickname of all players on the server.", usage = "/<command>")
|
||||||
|
public class Command_denick extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Removing all nicknames.", false);
|
||||||
|
|
||||||
|
Player[] onlinePlayers = server.getOnlinePlayers();
|
||||||
|
for (Player player : onlinePlayers)
|
||||||
|
{
|
||||||
|
TFM_EssentialsBridge.getInstance().setNickname(player.getName(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
||||||
@ -12,8 +16,8 @@ public class Command_expel extends TFM_Command
|
|||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
double radius = 15.0;
|
double radius = 20.0;
|
||||||
double strength = 20.0;
|
double strength = 5.0;
|
||||||
|
|
||||||
if (args.length >= 1)
|
if (args.length >= 1)
|
||||||
{
|
{
|
||||||
@ -21,7 +25,7 @@ public class Command_expel extends TFM_Command
|
|||||||
{
|
{
|
||||||
radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0])));
|
radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0])));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException nfex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,33 +36,50 @@ public class Command_expel extends TFM_Command
|
|||||||
{
|
{
|
||||||
strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1])));
|
strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1])));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException nfex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Location sender_pos = sender_p.getLocation();
|
List<String> pushedPlayers = new ArrayList<String>();
|
||||||
for (Player player : sender_pos.getWorld().getPlayers())
|
|
||||||
|
final Vector senderPos = sender_p.getLocation().toVector();
|
||||||
|
final List<Player> players = sender_p.getWorld().getPlayers();
|
||||||
|
for (final Player player : players)
|
||||||
{
|
{
|
||||||
if (!player.equals(sender_p))
|
if (player.equals(sender_p))
|
||||||
{
|
{
|
||||||
Location targetPos = player.getLocation();
|
continue;
|
||||||
|
|
||||||
boolean in_range = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
in_range = targetPos.distanceSquared(sender_pos) < (radius * radius);
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_range)
|
|
||||||
{
|
|
||||||
player.setVelocity(targetPos.clone().subtract(sender_pos).toVector().normalize().multiply(strength));
|
|
||||||
playerMsg("Pushing " + player.getName() + ".");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Location targetPos = player.getLocation();
|
||||||
|
final Vector targetPosVec = targetPos.toVector();
|
||||||
|
|
||||||
|
boolean inRange = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
inRange = targetPosVec.distanceSquared(senderPos) < (radius * radius);
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inRange)
|
||||||
|
{
|
||||||
|
player.getWorld().createExplosion(targetPos, 0.0f, false);
|
||||||
|
player.setFlying(false);
|
||||||
|
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
|
||||||
|
pushedPlayers.add(player.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pushedPlayers.isEmpty())
|
||||||
|
{
|
||||||
|
playerMsg("No players pushed.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("Pushed " + pushedPlayers.size() + " players: " + StringUtils.join(pushedPlayers, ", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
|
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Flatlands;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Goto the flatlands.", usage = "/<command>")
|
@CommandParameters(description = "Goto the flatlands.", usage = "/<command>")
|
||||||
public class Command_flatlands extends TFM_Command
|
public class Command_flatlands extends TFM_Command
|
||||||
{
|
{
|
||||||
@ -15,7 +15,7 @@ public class Command_flatlands extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (TFM_ConfigEntry.GENERATE_FLATLANDS.getBoolean())
|
if (TFM_ConfigEntry.GENERATE_FLATLANDS.getBoolean())
|
||||||
{
|
{
|
||||||
TFM_Util.gotoWorld(sender, "flatlands");
|
TFM_Flatlands.getInstance().sendToWorld(sender_p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ public class Command_fluidspread extends TFM_Command
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerMsg("Lava and water spread is now " + (TFM_ConfigEntry.ALLOW_FLIUD_SPREAD.setBoolean(!args[0].equalsIgnoreCase("off")) ? "enabled" : "disabled") + ".");
|
playerMsg("Lava and water spread is now " + (TFM_ConfigEntry.ALLOW_FLUID_SPREAD.setBoolean(!args[0].equalsIgnoreCase("off")) ? "enabled" : "disabled") + ".");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import org.bukkit.entity.Player;
|
|||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||||
@CommandParameters(
|
@CommandParameters(
|
||||||
description = "Use admin commands on someone by hash. Use mode 'list' to get a player's hash. Other modes are kick, nameban, ipban, ban, op, deop, ci",
|
description = "Use admin commands on someone by hash. Use mode 'list' to get a player's hash. Other modes are kick, nameban, ipban, ban, op, deop, ci",
|
||||||
usage = "/<command> [list | [<kick | nameban | ipban | ban | op | deop | ci> <targethash>] ]")
|
usage = "/<command> [list | [<kick | nameban | ipban | ban | op | deop | ci | fr> <targethash>] ]")
|
||||||
public class Command_gadmin extends TFM_Command
|
public class Command_gadmin extends TFM_Command
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
|
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UserList.TFM_UserListEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_UserList.TFM_UserListEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -4,8 +4,8 @@ import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_WorldEditBridge;
|
import me.StevenLawson.TotalFreedomMod.TFM_WorldEditBridge;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_LandmineData;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -48,4 +50,20 @@ public class Command_landmine extends TFM_Command
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TFM_LandmineData
|
||||||
|
{
|
||||||
|
public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
|
||||||
|
public Location location;
|
||||||
|
public Player player;
|
||||||
|
public double radius;
|
||||||
|
|
||||||
|
public TFM_LandmineData(Location landmine_pos, Player player, double radius)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.location = landmine_pos;
|
||||||
|
this.player = player;
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,98 +2,72 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command>", aliases = "who")
|
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a]", aliases = "who")
|
||||||
public class Command_list extends TFM_Command
|
public class Command_list extends TFM_Command
|
||||||
{
|
{
|
||||||
private static enum ListFilter
|
private static enum ListFilter
|
||||||
{
|
{
|
||||||
SHOW_ALL, SHOW_ADMINS
|
ALL,
|
||||||
|
ADMINS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
|
if (args.length > 1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (TFM_Util.isFromHostConsole(sender.getName()))
|
if (TFM_Util.isFromHostConsole(sender.getName()))
|
||||||
{
|
{
|
||||||
List<String> player_names = new ArrayList<String>();
|
final List<String> names = new ArrayList<String>();
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
player_names.add(player.getName());
|
names.add(player.getName());
|
||||||
}
|
}
|
||||||
playerMsg("There are " + player_names.size() + "/" + server.getMaxPlayers() + " players online:\n" + StringUtils.join(player_names, ", "), ChatColor.WHITE);
|
playerMsg("There are " + names.size() + "/" + server.getMaxPlayers() + " players online:\n" + StringUtils.join(names, ", "), ChatColor.WHITE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListFilter listFilter = ListFilter.SHOW_ALL;
|
final Command_list.ListFilter listFilter = (args.length == 1 && args[0].equals("-a") ? Command_list.ListFilter.ADMINS : Command_list.ListFilter.ALL);
|
||||||
if (args.length >= 1)
|
|
||||||
{
|
|
||||||
if (args[0].equalsIgnoreCase("-a"))
|
|
||||||
{
|
|
||||||
listFilter = ListFilter.SHOW_ADMINS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder onlineStats = new StringBuilder();
|
final StringBuilder onlineStats = new StringBuilder();
|
||||||
StringBuilder onlineUsers = new StringBuilder();
|
final StringBuilder onlineUsers = new StringBuilder();
|
||||||
|
|
||||||
onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().length);
|
onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().length);
|
||||||
onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(server.getMaxPlayers());
|
onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(server.getMaxPlayers());
|
||||||
onlineStats.append(ChatColor.BLUE).append(" players online.");
|
onlineStats.append(ChatColor.BLUE).append(" players online.");
|
||||||
|
|
||||||
List<String> player_names = new ArrayList<String>();
|
final List<String> names = new ArrayList<String>();
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
boolean userSuperadmin = TFM_SuperadminList.isUserSuperadmin(player);
|
final boolean userSuperadmin = TFM_SuperadminList.isUserSuperadmin(player);
|
||||||
|
|
||||||
if (listFilter == ListFilter.SHOW_ADMINS && !userSuperadmin)
|
if (listFilter == Command_list.ListFilter.ADMINS && !userSuperadmin)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String prefix = "";
|
names.add(TFM_PlayerRank.fromSender(player).getPrefix() + player.getName());
|
||||||
|
|
||||||
if (userSuperadmin)
|
|
||||||
{
|
|
||||||
if (TFM_SuperadminList.isSeniorAdmin(player))
|
|
||||||
{
|
|
||||||
prefix = (ChatColor.LIGHT_PURPLE + "[SrA]");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
prefix = (ChatColor.GOLD + "[SA]");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_Util.DEVELOPERS.contains(player.getName()))
|
|
||||||
{
|
|
||||||
prefix = (ChatColor.DARK_PURPLE + "[Dev]");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.getName().equals("markbyron"))
|
|
||||||
{
|
|
||||||
prefix = (ChatColor.BLUE + "[Owner]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (player.isOp())
|
|
||||||
{
|
|
||||||
prefix = (ChatColor.RED + "[OP]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player_names.add(prefix + player.getName() + ChatColor.WHITE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onlineUsers.append("Connected ").append(listFilter == ListFilter.SHOW_ADMINS ? "admins" : "players").append(": ").append(StringUtils.join(player_names, ", "));
|
onlineUsers.append("Connected ");
|
||||||
|
onlineUsers.append(listFilter == Command_list.ListFilter.ADMINS ? "admins: " : "players: ");
|
||||||
|
onlineUsers.append(StringUtils.join(names, ChatColor.WHITE + ", "));
|
||||||
|
|
||||||
if (senderIsConsole)
|
if (senderIsConsole)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
|
||||||
|
@CommandParameters(description = "Teleport to the spawn point for the current world.", usage = "/<command>", aliases = "worldspawn,gotospawn")
|
||||||
|
public class Command_localspawn extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
sender_p.teleport(sender_p.getWorld().getSpawnLocation());
|
||||||
|
playerMsg("Teleported to spawnpoint for world \"" + sender_p.getWorld().getName() + "\".");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -5,7 +5,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
|
@CommandParameters(description = "Essentials Interface Command - Nyanify your nickname.", usage = "/<command> <<nick> | off>")
|
||||||
|
public class Command_nicknyan extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (args.length != 1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TFM_Util.isStopCommand(args[0]))
|
||||||
|
{
|
||||||
|
TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), null);
|
||||||
|
playerMsg("Nickname cleared.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String nickPlain = ChatColor.stripColor(TFM_Util.colorize(args[0].trim()));
|
||||||
|
|
||||||
|
if (!nickPlain.matches("^[a-zA-Z_0-9\u00a7]+$"))
|
||||||
|
{
|
||||||
|
playerMsg("That nickname contains invalid characters.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (nickPlain.length() < 4 || nickPlain.length() > 30)
|
||||||
|
{
|
||||||
|
playerMsg("Your nickname must be between 4 and 30 characters long.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Player[] onlinePlayers = server.getOnlinePlayers();
|
||||||
|
for (final Player player : onlinePlayers)
|
||||||
|
{
|
||||||
|
if (player == sender_p)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain))
|
||||||
|
{
|
||||||
|
playerMsg("That nickname is already in use.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringBuilder newNick = new StringBuilder();
|
||||||
|
|
||||||
|
final char[] chars = nickPlain.toCharArray();
|
||||||
|
for (char c : chars)
|
||||||
|
{
|
||||||
|
newNick.append(TFM_Util.randomChatColor()).append(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
newNick.append(ChatColor.WHITE);
|
||||||
|
|
||||||
|
TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), newNick.toString());
|
||||||
|
|
||||||
|
playerMsg("Your nickname is now: " + newNick.toString());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -2,13 +2,15 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true)
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Switch server online-mode on and off.", usage = "/<command> <on | off>")
|
@CommandParameters(description = "Switch server online-mode on and off.", usage = "/<command> <on | off>")
|
||||||
public class Command_onlinemode extends TFM_Command
|
public class Command_onlinemode extends TFM_Command
|
||||||
{
|
{
|
||||||
@ -18,12 +20,18 @@ public class Command_onlinemode extends TFM_Command
|
|||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
playerMsg("Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.WHITE);
|
playerMsg("Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.WHITE);
|
||||||
playerMsg("Use \"/onlinemode on\" and \"/onlinemode off\" to change online mode.", ChatColor.WHITE);
|
playerMsg("\"/onlinemode on\" and \"/onlinemode off\" can be used to change online mode from the console.", ChatColor.WHITE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
boolean online_mode;
|
boolean online_mode;
|
||||||
|
|
||||||
|
if (sender instanceof Player && !TFM_SuperadminList.isSeniorAdmin(sender, true))
|
||||||
|
{
|
||||||
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("on"))
|
if (args[0].equalsIgnoreCase("on"))
|
||||||
{
|
{
|
||||||
online_mode = true;
|
online_mode = true;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -44,24 +44,24 @@ public class Command_permban extends TFM_Command
|
|||||||
|
|
||||||
private void dumplist(CommandSender sender)
|
private void dumplist(CommandSender sender)
|
||||||
{
|
{
|
||||||
if (TotalFreedomMod.permbanned_players.isEmpty())
|
if (TotalFreedomMod.permbannedPlayers.isEmpty())
|
||||||
{
|
{
|
||||||
playerMsg(sender, "No permanently banned player names.");
|
playerMsg(sender, "No permanently banned player names.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
playerMsg(sender, TotalFreedomMod.permbanned_players.size() + " permanently banned players:");
|
playerMsg(sender, TotalFreedomMod.permbannedPlayers.size() + " permanently banned players:");
|
||||||
playerMsg(sender, StringUtils.join(TotalFreedomMod.permbanned_players, ", "));
|
playerMsg(sender, StringUtils.join(TotalFreedomMod.permbannedPlayers, ", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TotalFreedomMod.permbanned_ips.isEmpty())
|
if (TotalFreedomMod.permbannedIps.isEmpty())
|
||||||
{
|
{
|
||||||
playerMsg(sender, "No permanently banned IPs.");
|
playerMsg(sender, "No permanently banned IPs.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
playerMsg(sender, TotalFreedomMod.permbanned_ips.size() + " permanently banned IPs:");
|
playerMsg(sender, TotalFreedomMod.permbannedIps.size() + " permanently banned IPs:");
|
||||||
playerMsg(sender, StringUtils.join(TotalFreedomMod.permbanned_ips, ", "));
|
playerMsg(sender, StringUtils.join(TotalFreedomMod.permbannedIps, ", "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -5,7 +5,7 @@ import java.util.List;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -5,7 +5,6 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -61,7 +60,7 @@ public class Command_premium extends TFM_Command
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ExceptionUtils.getStackTrace(ex));
|
TFM_Log.severe(ex);
|
||||||
playerMsg("There was an error querying the mojang server.", ChatColor.RED);
|
playerMsg("There was an error querying the mojang server.", ChatColor.RED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
|
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -17,7 +17,7 @@ public class Command_rank extends TFM_Command
|
|||||||
{
|
{
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
playerMsg(player.getName() + " is " + TFM_Util.getRank(player));
|
playerMsg(player.getName() + " is " + TFM_PlayerRank.fromSender(player).getLoginMessage());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ public class Command_rank extends TFM_Command
|
|||||||
|
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
playerMsg(sender.getName() + " is " + TFM_Util.getRank(sender), ChatColor.AQUA);
|
playerMsg(sender.getName() + " is " + TFM_PlayerRank.fromSender(sender).getLoginMessage(), ChatColor.AQUA);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public class Command_rank extends TFM_Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerMsg(player.getName() + " is " + TFM_Util.getRank(player), ChatColor.AQUA);
|
playerMsg(player.getName() + " is " + TFM_PlayerRank.fromSender(player).getLoginMessage(), ChatColor.AQUA);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -15,7 +15,7 @@ public class Command_rawsay extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
{
|
{
|
||||||
TFM_Util.bcastMsg(TFM_Util.colorise(StringUtils.join(args, " ")));
|
TFM_Util.bcastMsg(TFM_Util.colorize(StringUtils.join(args, " ")));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, block_host_console = true)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, block_host_console = true)
|
||||||
@CommandParameters(description = "Issues a rollback on a player", usage = "/<command> <[partialname] | purge [partialname] | purgeall>", aliases = "rb")
|
@CommandParameters(description = "Issues a rollback on a player", usage = "/<command> <[partialname] | undo [partialname] purge [partialname] | purgeall>", aliases = "rb")
|
||||||
public class Command_rollback extends TFM_Command
|
public class Command_rollback extends TFM_Command
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -16,25 +16,58 @@ public class Command_rollback extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("purgeall"))
|
if ("purgeall".equalsIgnoreCase(args[0]))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Purging all rollback history.", false);
|
TFM_Util.adminAction(sender.getName(), "Purging all rollback history", false);
|
||||||
playerMsg("Purged all rollback history for " + TFM_RollbackManager.purgeEntries() + " players.");
|
playerMsg("Purged all rollback history for " + TFM_RollbackManager.purgeEntries() + " players.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String playerName = getPlayerName(args[0]);
|
String playerName = getPlayerName(args[0]);
|
||||||
|
|
||||||
|
if (!TFM_RollbackManager.canRollback(playerName))
|
||||||
|
{
|
||||||
|
playerMsg("That player has no entries stored.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TFM_RollbackManager.canUndoRollback(playerName))
|
||||||
|
{
|
||||||
|
playerMsg("That player has just been rolled back.");
|
||||||
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Rolling back player: " + playerName, false);
|
TFM_Util.adminAction(sender.getName(), "Rolling back player: " + playerName, false);
|
||||||
playerMsg("Rolled back " + TFM_RollbackManager.rollback(playerName) + " edits for " + playerName + ".");
|
playerMsg("Rolled back " + TFM_RollbackManager.rollback(playerName) + " edits for " + playerName + ".");
|
||||||
|
playerMsg("If this rollback was a mistake, use /rollback undo " + playerName + " within 20 seconds to reverse the rollback.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (args.length == 2)
|
else if (args.length == 2)
|
||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("purge"))
|
if ("purge".equalsIgnoreCase(args[0]))
|
||||||
{
|
{
|
||||||
String playerName = getPlayerName(args[1]);
|
String playerName = getPlayerName(args[1]);
|
||||||
|
|
||||||
|
if (!TFM_RollbackManager.canRollback(playerName))
|
||||||
|
{
|
||||||
|
playerMsg("That player has no entries stored.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
playerMsg("Purged " + TFM_RollbackManager.purgeEntries(playerName) + " rollback history entries for " + playerName + ".");
|
playerMsg("Purged " + TFM_RollbackManager.purgeEntries(playerName) + " rollback history entries for " + playerName + ".");
|
||||||
}
|
}
|
||||||
|
else if ("undo".equalsIgnoreCase(args[0]))
|
||||||
|
{
|
||||||
|
String playerName = getPlayerName(args[1]);
|
||||||
|
|
||||||
|
if (!TFM_RollbackManager.canUndoRollback(playerName))
|
||||||
|
{
|
||||||
|
playerMsg("That player hasn't been rolled back recently.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Reverting rollback for player: " + playerName, false);
|
||||||
|
playerMsg("Reverted " + TFM_RollbackManager.undoRollback(playerName) + " edits for " + playerName + ".");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -6,7 +6,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
|
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -27,7 +27,7 @@ public class Command_saconfig extends TFM_Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!TFM_SuperadminList.isSeniorAdmin(sender))
|
if (!TFM_SuperadminList.isSeniorAdmin(sender, true))
|
||||||
{
|
{
|
||||||
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
||||||
return true;
|
return true;
|
||||||
@ -78,7 +78,7 @@ public class Command_saconfig extends TFM_Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
playerMsg(ChatColor.stripColor(TFM_Util.colorise(superadmin.toString())));
|
playerMsg(ChatColor.stripColor(TFM_Util.colorize(superadmin.toString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -151,43 +151,11 @@ public class Command_saconfig extends TFM_Command
|
|||||||
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
|
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
|
||||||
TFM_SuperadminList.removeSuperadmin(targetName);
|
TFM_SuperadminList.removeSuperadmin(targetName);
|
||||||
|
|
||||||
if (!TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Twitterbot
|
// Twitterbot
|
||||||
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance();
|
if (TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
|
||||||
String reply = twitterbot.delTwitter(targetName);
|
|
||||||
if ("ok".equals(reply))
|
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from TwitterBot", true);
|
TFM_TwitterHandler.getInstance().delTwitterVerbose(targetName, sender);
|
||||||
}
|
}
|
||||||
else if ("disabled".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
||||||
TFM_Util.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until it gets re-enabled", ChatColor.RED);
|
|
||||||
}
|
|
||||||
else if ("failed".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
||||||
TFM_Util.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED);
|
|
||||||
}
|
|
||||||
else if ("false".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
||||||
TFM_Util.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED);
|
|
||||||
}
|
|
||||||
else if ("cannotauth".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
||||||
TFM_Util.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED);
|
|
||||||
}
|
|
||||||
else if ("notfound".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, targetName + " did not have a twitter handle registered to their name.", ChatColor.GREEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -29,7 +29,7 @@ public class Command_say extends TFM_Command
|
|||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
player.kickPlayer("Server is going offline, come back in a few minutes.");
|
player.kickPlayer("Server is going offline, come back in about 20 seconds.");
|
||||||
}
|
}
|
||||||
|
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker.TFM_ServiceChecker_ServiceStatus;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker.ServiceStatus;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -16,12 +16,12 @@ public class Command_services extends TFM_Command
|
|||||||
{
|
{
|
||||||
playerMsg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE);
|
playerMsg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE);
|
||||||
|
|
||||||
for (TFM_ServiceChecker_ServiceStatus service : TFM_ServiceChecker.getInstance().getAllStatuses())
|
for (ServiceStatus service : TFM_ServiceChecker.getInstance().getAllStatuses())
|
||||||
{
|
{
|
||||||
playerMsg(service.getFormattedStatus());
|
playerMsg(service.getFormattedStatus());
|
||||||
}
|
}
|
||||||
playerMsg("Version" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getInstance().version, ChatColor.DARK_PURPLE);
|
playerMsg("Version" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getInstance().getVersion(), ChatColor.DARK_PURPLE);
|
||||||
playerMsg("Last Check" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getInstance().lastCheck, ChatColor.DARK_PURPLE);
|
playerMsg("Last Check" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getInstance().getLastCheck(), ChatColor.DARK_PURPLE);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
|
@CommandParameters(description = "Set the on/off state of the lever at position x, y, z in world 'worldname'.", usage = "/<command> <x> <y> <z> <worldname> <on|off>")
|
||||||
|
public class Command_setlever extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (args.length != 5)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
double x, y, z;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
x = Double.parseDouble(args[0]);
|
||||||
|
y = Double.parseDouble(args[1]);
|
||||||
|
z = Double.parseDouble(args[2]);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
|
playerMsg("Invalid coordinates.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = null;
|
||||||
|
final String needleWorldName = args[3].trim();
|
||||||
|
final List<World> worlds = server.getWorlds();
|
||||||
|
for (final World testWorld : worlds)
|
||||||
|
{
|
||||||
|
if (testWorld.getName().trim().equalsIgnoreCase(needleWorldName))
|
||||||
|
{
|
||||||
|
world = testWorld;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world == null)
|
||||||
|
{
|
||||||
|
playerMsg("Invalid world name.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Location leverLocation = new Location(world, x, y, z);
|
||||||
|
|
||||||
|
final boolean leverOn = (args[4].trim().equalsIgnoreCase("on") || args[4].trim().equalsIgnoreCase("1")) ? true : false;
|
||||||
|
|
||||||
|
final Block targetBlock = leverLocation.getBlock();
|
||||||
|
|
||||||
|
if (targetBlock.getType() == Material.LEVER)
|
||||||
|
{
|
||||||
|
org.bukkit.material.Lever lever = new org.bukkit.material.Lever(Material.LEVER, targetBlock.getData());
|
||||||
|
lever.setPowered(leverOn);
|
||||||
|
targetBlock.setData(lever.getData());
|
||||||
|
targetBlock.getState().update();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("Target block " + targetBlock + " is not a lever.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -63,9 +63,9 @@ public class Command_tag extends TFM_Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].length() > 15)
|
if (ChatColor.stripColor(TFM_Util.colorize(args[0])).length() > 20)
|
||||||
{
|
{
|
||||||
playerMsg("That tag is too long.");
|
playerMsg("That tag is too long [Max = 20 characters, not including color codes].");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -30,6 +31,18 @@ public class Command_tban extends TFM_Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// strike with lightning effect:
|
||||||
|
final Location targetPos = player.getLocation();
|
||||||
|
for (int x = -1; x <= 1; x++)
|
||||||
|
{
|
||||||
|
for (int z = -1; z <= 1; z++)
|
||||||
|
{
|
||||||
|
final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
|
||||||
|
targetPos.getWorld().strikeLightning(strike_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
|
TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
|
||||||
TFM_ServerInterface.banUsername(player.getName(), ChatColor.RED + "You have been temporarily banned for 5 minutes.", sender.getName(), TFM_Util.parseDateOffset("5m"));
|
TFM_ServerInterface.banUsername(player.getName(), ChatColor.RED + "You have been temporarily banned for 5 minutes.", sender.getName(), TFM_Util.parseDateOffset("5m"));
|
||||||
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");
|
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");
|
||||||
|
@ -4,12 +4,13 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Temporarily ban someone.", usage = "/<command> [playername] [duration] [reason]")
|
@CommandParameters(description = "Temporarily ban someone.", usage = "/<command> [playername] [duration] [reason]")
|
||||||
@ -56,6 +57,18 @@ public class Command_tempban extends TFM_Command
|
|||||||
bcast_msg.append(", Reason: \"").append(ban_reason).append("\"");
|
bcast_msg.append(", Reason: \"").append(ban_reason).append("\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// strike with lightning effect:
|
||||||
|
final Location targetPos = player.getLocation();
|
||||||
|
for (int x = -1; x <= 1; x++)
|
||||||
|
{
|
||||||
|
for (int z = -1; z <= 1; z++)
|
||||||
|
{
|
||||||
|
final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
|
||||||
|
targetPos.getWorld().strikeLightning(strike_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), bcast_msg.toString(), true);
|
TFM_Util.adminAction(sender.getName(), bcast_msg.toString(), true);
|
||||||
TFM_ServerInterface.banUsername(player.getName(), ban_reason, sender.getName(), ban_duration);
|
TFM_ServerInterface.banUsername(player.getName(), ban_reason, sender.getName(), ban_duration);
|
||||||
TFM_ServerInterface.banIP(player.getAddress().getAddress().getHostAddress().trim(), ban_reason, sender.getName(), ban_duration);
|
TFM_ServerInterface.banIP(player.getAddress().getAddress().getHostAddress().trim(), ban_reason, sender.getName(), ban_duration);
|
||||||
|
@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -78,10 +78,10 @@ public class Command_tossmob extends TFM_Command
|
|||||||
|
|
||||||
playerData.enableMobThrower(creature, speed);
|
playerData.enableMobThrower(creature, speed);
|
||||||
playerMsg("MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + ".", ChatColor.GREEN);
|
playerMsg("MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + ".", ChatColor.GREEN);
|
||||||
playerMsg("Left click while holding a stick to throw mobs!", ChatColor.GREEN);
|
playerMsg("Left click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN);
|
||||||
playerMsg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN);
|
playerMsg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN);
|
||||||
|
|
||||||
sender_p.setItemInHand(new ItemStack(Material.STICK, 1));
|
sender_p.setItemInHand(new ItemStack(Material.BONE, 1));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -105,4 +105,27 @@ public class Command_trail extends TFM_Command
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void startTrail(Player player)
|
||||||
|
{
|
||||||
|
if (!trailPlayers.contains(player))
|
||||||
|
{
|
||||||
|
trailPlayers.add(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!trailPlayers.isEmpty())
|
||||||
|
{
|
||||||
|
registerMovementHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stopTrail(Player player)
|
||||||
|
{
|
||||||
|
trailPlayers.remove(player);
|
||||||
|
|
||||||
|
if (trailPlayers.isEmpty())
|
||||||
|
{
|
||||||
|
unregisterMovementHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -46,21 +46,7 @@ public class TFM_CommandLoader
|
|||||||
|
|
||||||
for (TFM_CommandInfo commandInfo : commandList)
|
for (TFM_CommandInfo commandInfo : commandList)
|
||||||
{
|
{
|
||||||
String description = commandInfo.getDescription();
|
TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo);
|
||||||
switch (commandInfo.getLevel())
|
|
||||||
{
|
|
||||||
case SENIOR:
|
|
||||||
description = "Senior " + (commandInfo.getSource() == SourceType.ONLY_CONSOLE ? "Console" : "") + " Command - " + description;
|
|
||||||
break;
|
|
||||||
case SUPER:
|
|
||||||
description = "Superadmin Command - " + description;
|
|
||||||
break;
|
|
||||||
case OP:
|
|
||||||
description = "OP Command - " + description;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo.getCommandName(), description, commandInfo.getUsage(), commandInfo.getAliases());
|
|
||||||
|
|
||||||
Command existing = commandMap.getCommand(dynamicCommand.getName());
|
Command existing = commandMap.getCommand(dynamicCommand.getName());
|
||||||
if (existing != null)
|
if (existing != null)
|
||||||
@ -191,7 +177,7 @@ public class TFM_CommandLoader
|
|||||||
return commandList;
|
return commandList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TFM_CommandInfo
|
public static class TFM_CommandInfo
|
||||||
{
|
{
|
||||||
private final String commandName;
|
private final String commandName;
|
||||||
private final Class<?> commandClass;
|
private final Class<?> commandClass;
|
||||||
@ -234,6 +220,26 @@ public class TFM_CommandLoader
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDescriptionPermissioned()
|
||||||
|
{
|
||||||
|
String _description = description;
|
||||||
|
|
||||||
|
switch (this.getLevel())
|
||||||
|
{
|
||||||
|
case SENIOR:
|
||||||
|
_description = "Senior " + (this.getSource() == SourceType.ONLY_CONSOLE ? "Console" : "") + " Command - " + _description;
|
||||||
|
break;
|
||||||
|
case SUPER:
|
||||||
|
_description = "Superadmin Command - " + _description;
|
||||||
|
break;
|
||||||
|
case OP:
|
||||||
|
_description = "OP Command - " + _description;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _description;
|
||||||
|
}
|
||||||
|
|
||||||
public AdminLevel getLevel()
|
public AdminLevel getLevel()
|
||||||
{
|
{
|
||||||
return level;
|
return level;
|
||||||
@ -270,11 +276,15 @@ public class TFM_CommandLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TFM_DynamicCommand extends Command implements PluginIdentifiableCommand
|
public class TFM_DynamicCommand extends Command implements PluginIdentifiableCommand
|
||||||
{
|
{
|
||||||
public TFM_DynamicCommand(String commandName, String description, String usage, List<String> aliases)
|
private final TFM_CommandInfo commandInfo;
|
||||||
|
|
||||||
|
private TFM_DynamicCommand(TFM_CommandInfo commandInfo)
|
||||||
{
|
{
|
||||||
super(commandName, description, usage, aliases);
|
super(commandInfo.getCommandName(), commandInfo.getDescriptionPermissioned(), commandInfo.getUsage(), commandInfo.getAliases());
|
||||||
|
|
||||||
|
this.commandInfo = commandInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -312,6 +322,11 @@ public class TFM_CommandLoader
|
|||||||
{
|
{
|
||||||
return TotalFreedomMod.plugin;
|
return TotalFreedomMod.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TFM_CommandInfo getCommandInfo()
|
||||||
|
{
|
||||||
|
return commandInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_CommandLoader getInstance()
|
public static TFM_CommandLoader getInstance()
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static net.minecraft.util.org.apache.commons.lang3.StringEscapeUtils.*;
|
||||||
|
|
||||||
|
public class HTMLGenerationTools
|
||||||
|
{
|
||||||
|
private HTMLGenerationTools()
|
||||||
|
{
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String paragraph(String data)
|
||||||
|
{
|
||||||
|
return "<p>" + escapeHtml4(data) + "</p>\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String heading(String data, int level)
|
||||||
|
{
|
||||||
|
return "<h" + level + ">" + escapeHtml4(data) + "</h" + level + ">\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <K, V> String list(Map<K, V> map)
|
||||||
|
{
|
||||||
|
StringBuilder output = new StringBuilder();
|
||||||
|
|
||||||
|
output.append("<ul>\r\n");
|
||||||
|
|
||||||
|
Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry<K, V> entry = it.next();
|
||||||
|
output.append("<li>").append(escapeHtml4(entry.getKey().toString() + " = " + entry.getValue().toString())).append("</li>\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
output.append("</ul>\r\n");
|
||||||
|
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> String list(Collection<T> list)
|
||||||
|
{
|
||||||
|
StringBuilder output = new StringBuilder();
|
||||||
|
|
||||||
|
output.append("<ul>\r\n");
|
||||||
|
|
||||||
|
for (T entry : list)
|
||||||
|
{
|
||||||
|
output.append("<li>").append(escapeHtml4(entry.toString())).append("</li>\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
output.append("</ul>\r\n");
|
||||||
|
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
}
|
111
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_dump.java
Normal file
111
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_dump.java
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
|
import net.minecraft.util.org.apache.commons.io.FileUtils;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
|
|
||||||
|
import static me.StevenLawson.TotalFreedomMod.HTTPD.HTMLGenerationTools.*;
|
||||||
|
|
||||||
|
public class Module_dump extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
private File echoFile = null;
|
||||||
|
private final String body;
|
||||||
|
|
||||||
|
public Module_dump(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
|
||||||
|
//Body needs to be computed before getResponse, so we know if a text response or a file echo is needed.
|
||||||
|
this.body = body();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NanoHTTPD.Response getResponse()
|
||||||
|
{
|
||||||
|
String echo = params.get("echo");
|
||||||
|
boolean doEcho = echo != null && ((echo = echo.toLowerCase().trim()).equalsIgnoreCase("true") || echo.equalsIgnoreCase("1"));
|
||||||
|
|
||||||
|
if (doEcho && this.echoFile != null && this.echoFile.exists())
|
||||||
|
{
|
||||||
|
return TFM_HTTPD_Manager.serveFileBasic(this.echoFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return super.getResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBody()
|
||||||
|
{
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String body()
|
||||||
|
{
|
||||||
|
StringBuilder responseBody = new StringBuilder();
|
||||||
|
|
||||||
|
String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||||
|
|
||||||
|
String[] args = StringUtils.split(uri, "/");
|
||||||
|
|
||||||
|
Map<String, String> files = getFiles();
|
||||||
|
|
||||||
|
responseBody
|
||||||
|
.append(paragraph("URI: " + uri))
|
||||||
|
.append(paragraph("args (Length: " + args.length + "): " + StringUtils.join(args, ",")))
|
||||||
|
.append(paragraph("Method: " + method.toString()))
|
||||||
|
.append(paragraph("Remote Address: " + remoteAddress))
|
||||||
|
.append(paragraph("Headers:"))
|
||||||
|
.append(list(headers))
|
||||||
|
.append(paragraph("Params:"))
|
||||||
|
.append(list(params))
|
||||||
|
.append(paragraph("Files:"))
|
||||||
|
.append(list(files));
|
||||||
|
|
||||||
|
Iterator<Map.Entry<String, String>> it = files.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry<String, String> entry = it.next();
|
||||||
|
String formName = entry.getKey();
|
||||||
|
String tempFileName = entry.getValue();
|
||||||
|
String origFileName = params.get(formName);
|
||||||
|
|
||||||
|
File tempFile = new File(tempFileName);
|
||||||
|
if (tempFile.exists())
|
||||||
|
{
|
||||||
|
this.echoFile = tempFile;
|
||||||
|
|
||||||
|
if (origFileName.contains("../"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String targetFileName = "./public_html/uploads/" + origFileName;
|
||||||
|
|
||||||
|
File targetFile = new File(targetFileName);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileUtils.copyFile(tempFile, targetFile);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseBody.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle()
|
||||||
|
{
|
||||||
|
return "TotalFreedomMod :: Request Debug Dumper";
|
||||||
|
}
|
||||||
|
}
|
364
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_file.java
Normal file
364
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_file.java
Normal file
@ -0,0 +1,364 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
|
|
||||||
|
import static me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.*;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This class was adapted from https://github.com/NanoHttpd/nanohttpd/blob/master/webserver/src/main/java/fi/iki/elonen/SimpleWebServer.java
|
||||||
|
*/
|
||||||
|
public class Module_file extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
private final File rootDir = new File(TFM_ConfigEntry.HTTPD_PUBLIC_FOLDER.getString());
|
||||||
|
public static final Map<String, String> MIME_TYPES = new HashMap<String, String>();
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
MIME_TYPES.put("css", "text/css");
|
||||||
|
MIME_TYPES.put("htm", "text/html");
|
||||||
|
MIME_TYPES.put("html", "text/html");
|
||||||
|
MIME_TYPES.put("xml", "text/xml");
|
||||||
|
MIME_TYPES.put("java", "text/x-java-source, text/java");
|
||||||
|
MIME_TYPES.put("txt", "text/plain");
|
||||||
|
MIME_TYPES.put("asc", "text/plain");
|
||||||
|
MIME_TYPES.put("yml", "text/yaml");
|
||||||
|
MIME_TYPES.put("gif", "image/gif");
|
||||||
|
MIME_TYPES.put("jpg", "image/jpeg");
|
||||||
|
MIME_TYPES.put("jpeg", "image/jpeg");
|
||||||
|
MIME_TYPES.put("png", "image/png");
|
||||||
|
MIME_TYPES.put("mp3", "audio/mpeg");
|
||||||
|
MIME_TYPES.put("m3u", "audio/mpeg-url");
|
||||||
|
MIME_TYPES.put("mp4", "video/mp4");
|
||||||
|
MIME_TYPES.put("ogv", "video/ogg");
|
||||||
|
MIME_TYPES.put("flv", "video/x-flv");
|
||||||
|
MIME_TYPES.put("mov", "video/quicktime");
|
||||||
|
MIME_TYPES.put("swf", "application/x-shockwave-flash");
|
||||||
|
MIME_TYPES.put("js", "application/javascript");
|
||||||
|
MIME_TYPES.put("pdf", "application/pdf");
|
||||||
|
MIME_TYPES.put("doc", "application/msword");
|
||||||
|
MIME_TYPES.put("ogg", "application/x-ogg");
|
||||||
|
MIME_TYPES.put("zip", "application/octet-stream");
|
||||||
|
MIME_TYPES.put("exe", "application/octet-stream");
|
||||||
|
MIME_TYPES.put("class", "application/octet-stream");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Module_file(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getRootDir()
|
||||||
|
{
|
||||||
|
return rootDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String encodeUri(String uri)
|
||||||
|
{
|
||||||
|
String newUri = "";
|
||||||
|
StringTokenizer st = new StringTokenizer(uri, "/ ", true);
|
||||||
|
while (st.hasMoreTokens())
|
||||||
|
{
|
||||||
|
String tok = st.nextToken();
|
||||||
|
if (tok.equals("/"))
|
||||||
|
{
|
||||||
|
newUri += "/";
|
||||||
|
}
|
||||||
|
else if (tok.equals(" "))
|
||||||
|
{
|
||||||
|
newUri += "%20";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
newUri += URLEncoder.encode(tok, "UTF-8");
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response serveFile(String uri, Map<String, String> header, File homeDir)
|
||||||
|
{
|
||||||
|
Response res = null;
|
||||||
|
|
||||||
|
// Make sure we won't die of an exception later
|
||||||
|
if (!homeDir.isDirectory())
|
||||||
|
{
|
||||||
|
res = new Response(Response.Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "INTERNAL ERRROR: serveFile(): given homeDir is not a directory.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
// Remove URL arguments
|
||||||
|
uri = uri.trim().replace(File.separatorChar, '/');
|
||||||
|
if (uri.indexOf('?') >= 0)
|
||||||
|
{
|
||||||
|
uri = uri.substring(0, uri.indexOf('?'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prohibit getting out of current directory
|
||||||
|
if (uri.startsWith("src/main") || uri.endsWith("src/main") || uri.contains("../"))
|
||||||
|
{
|
||||||
|
res = new Response(Response.Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "FORBIDDEN: Won't serve ../ for security reasons.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File f = new File(homeDir, uri);
|
||||||
|
if (res == null && !f.exists())
|
||||||
|
{
|
||||||
|
res = new Response(Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, "Error 404, file not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// List the directory, if necessary
|
||||||
|
if (res == null && f.isDirectory())
|
||||||
|
{
|
||||||
|
// Browsers get confused without '/' after the
|
||||||
|
// directory, send a redirect.
|
||||||
|
if (!uri.endsWith("/"))
|
||||||
|
{
|
||||||
|
uri += "/";
|
||||||
|
res = new Response(Response.Status.REDIRECT, NanoHTTPD.MIME_HTML, "<html><body>Redirected: <a href=\"" + uri + "\">" + uri
|
||||||
|
+ "</a></body></html>");
|
||||||
|
res.addHeader("Location", uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
// First try index.html and index.htm
|
||||||
|
if (new File(f, "index.html").exists())
|
||||||
|
{
|
||||||
|
f = new File(homeDir, uri + "/index.html");
|
||||||
|
}
|
||||||
|
else if (new File(f, "index.htm").exists())
|
||||||
|
{
|
||||||
|
f = new File(homeDir, uri + "/index.htm");
|
||||||
|
}
|
||||||
|
else if (f.canRead())
|
||||||
|
{
|
||||||
|
// No index file, list the directory if it is readable
|
||||||
|
res = new Response(listDirectory(uri, f));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res = new Response(Response.Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "FORBIDDEN: No directory listing.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
// Get MIME type from file name extension, if possible
|
||||||
|
String mime = null;
|
||||||
|
int dot = f.getCanonicalPath().lastIndexOf('.');
|
||||||
|
if (dot >= 0)
|
||||||
|
{
|
||||||
|
mime = MIME_TYPES.get(f.getCanonicalPath().substring(dot + 1).toLowerCase());
|
||||||
|
}
|
||||||
|
if (mime == null)
|
||||||
|
{
|
||||||
|
mime = TFM_HTTPD_Manager.MIME_DEFAULT_BINARY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate etag
|
||||||
|
String etag = Integer.toHexString((f.getAbsolutePath() + f.lastModified() + "" + f.length()).hashCode());
|
||||||
|
|
||||||
|
// Support (simple) skipping:
|
||||||
|
long startFrom = 0;
|
||||||
|
long endAt = -1;
|
||||||
|
String range = header.get("range");
|
||||||
|
if (range != null)
|
||||||
|
{
|
||||||
|
if (range.startsWith("bytes="))
|
||||||
|
{
|
||||||
|
range = range.substring("bytes=".length());
|
||||||
|
int minus = range.indexOf('-');
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (minus > 0)
|
||||||
|
{
|
||||||
|
startFrom = Long.parseLong(range.substring(0, minus));
|
||||||
|
endAt = Long.parseLong(range.substring(minus + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change return code and add Content-Range header when skipping is requested
|
||||||
|
long fileLen = f.length();
|
||||||
|
if (range != null && startFrom >= 0)
|
||||||
|
{
|
||||||
|
if (startFrom >= fileLen)
|
||||||
|
{
|
||||||
|
res = new Response(Response.Status.RANGE_NOT_SATISFIABLE, NanoHTTPD.MIME_PLAINTEXT, "");
|
||||||
|
res.addHeader("Content-Range", "bytes 0-0/" + fileLen);
|
||||||
|
res.addHeader("ETag", etag);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (endAt < 0)
|
||||||
|
{
|
||||||
|
endAt = fileLen - 1;
|
||||||
|
}
|
||||||
|
long newLen = endAt - startFrom + 1;
|
||||||
|
if (newLen < 0)
|
||||||
|
{
|
||||||
|
newLen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
final long dataLen = newLen;
|
||||||
|
FileInputStream fis = new FileInputStream(f)
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int available() throws IOException
|
||||||
|
{
|
||||||
|
return (int) dataLen;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fis.skip(startFrom);
|
||||||
|
|
||||||
|
res = new Response(Response.Status.PARTIAL_CONTENT, mime, fis);
|
||||||
|
res.addHeader("Content-Length", "" + dataLen);
|
||||||
|
res.addHeader("Content-Range", "bytes " + startFrom + "-" + endAt + "/" + fileLen);
|
||||||
|
res.addHeader("ETag", etag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (etag.equals(header.get("if-none-match")))
|
||||||
|
{
|
||||||
|
res = new Response(Response.Status.NOT_MODIFIED, mime, "");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res = new Response(Response.Status.OK, mime, new FileInputStream(f));
|
||||||
|
res.addHeader("Content-Length", "" + fileLen);
|
||||||
|
res.addHeader("ETag", etag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ioe)
|
||||||
|
{
|
||||||
|
res = new Response(Response.Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "FORBIDDEN: Reading file failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
res.addHeader("Accept-Ranges", "bytes"); // Announce that the file server accepts partial content requestes
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String listDirectory(String uri, File f)
|
||||||
|
{
|
||||||
|
String heading = "Directory " + uri;
|
||||||
|
String msg = "<html><head><title>" + heading + "</title><style><!--\n"
|
||||||
|
+ "span.dirname { font-weight: bold; }\n"
|
||||||
|
+ "span.filesize { font-size: 75%; }\n"
|
||||||
|
+ "// -->\n"
|
||||||
|
+ "</style>"
|
||||||
|
+ "</head><body><h1>" + heading + "</h1>";
|
||||||
|
|
||||||
|
String up = null;
|
||||||
|
if (uri.length() > 1)
|
||||||
|
{
|
||||||
|
String u = uri.substring(0, uri.length() - 1);
|
||||||
|
int slash = u.lastIndexOf('/');
|
||||||
|
if (slash >= 0 && slash < u.length())
|
||||||
|
{
|
||||||
|
up = uri.substring(0, slash + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> _files = Arrays.asList(f.list(new FilenameFilter()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean accept(File dir, String name)
|
||||||
|
{
|
||||||
|
return new File(dir, name).isFile();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
Collections.sort(_files);
|
||||||
|
List<String> directories = Arrays.asList(f.list(new FilenameFilter()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean accept(File dir, String name)
|
||||||
|
{
|
||||||
|
return new File(dir, name).isDirectory();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
Collections.sort(directories);
|
||||||
|
if (up != null || directories.size() + _files.size() > 0)
|
||||||
|
{
|
||||||
|
msg += "<ul>";
|
||||||
|
if (up != null || directories.size() > 0)
|
||||||
|
{
|
||||||
|
msg += "<section class=\"directories\">";
|
||||||
|
if (up != null)
|
||||||
|
{
|
||||||
|
msg += "<li><a rel=\"directory\" href=\"" + up + "\"><span class=\"dirname\">..</span></a></b></li>";
|
||||||
|
}
|
||||||
|
for (int i = 0; i < directories.size(); i++)
|
||||||
|
{
|
||||||
|
String dir = directories.get(i) + "/";
|
||||||
|
msg += "<li><a rel=\"directory\" href=\"" + encodeUri(uri + dir) + "\"><span class=\"dirname\">" + dir + "</span></a></b></li>";
|
||||||
|
}
|
||||||
|
msg += "</section>";
|
||||||
|
}
|
||||||
|
if (_files.size() > 0)
|
||||||
|
{
|
||||||
|
msg += "<section class=\"files\">";
|
||||||
|
for (int i = 0; i < _files.size(); i++)
|
||||||
|
{
|
||||||
|
String file = _files.get(i);
|
||||||
|
|
||||||
|
msg += "<li><a href=\"" + encodeUri(uri + file) + "\"><span class=\"filename\">" + file + "</span></a>";
|
||||||
|
File curFile = new File(f, file);
|
||||||
|
long len = curFile.length();
|
||||||
|
msg += " <span class=\"filesize\">(";
|
||||||
|
if (len < 1024)
|
||||||
|
{
|
||||||
|
msg += len + " bytes";
|
||||||
|
}
|
||||||
|
else if (len < 1024 * 1024)
|
||||||
|
{
|
||||||
|
msg += len / 1024 + "." + (len % 1024 / 10 % 100) + " KB";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg += len / (1024 * 1024) + "." + len % (1024 * 1024) / 10 % 100 + " MB";
|
||||||
|
}
|
||||||
|
msg += ")</span></li>";
|
||||||
|
}
|
||||||
|
msg += "</section>";
|
||||||
|
}
|
||||||
|
msg += "</ul>";
|
||||||
|
}
|
||||||
|
msg += "</body></html>";
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response getResponse()
|
||||||
|
{
|
||||||
|
return serveFile(uri, headers, getRootDir());
|
||||||
|
}
|
||||||
|
}
|
155
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java
Normal file
155
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.Commands.AdminLevel;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader.TFM_DynamicCommand;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandMap;
|
||||||
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import static me.StevenLawson.TotalFreedomMod.HTTPD.HTMLGenerationTools.*;
|
||||||
|
import static net.minecraft.util.org.apache.commons.lang3.StringEscapeUtils.*;
|
||||||
|
|
||||||
|
public class Module_help extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
public Module_help(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBody()
|
||||||
|
{
|
||||||
|
StringBuilder responseBody = new StringBuilder();
|
||||||
|
|
||||||
|
CommandMap commandMap;
|
||||||
|
HashMap<String, Command> knownCommands;
|
||||||
|
if ((commandMap = TFM_CommandLoader.getInstance().getCommandMap()) == null
|
||||||
|
|| (knownCommands = TFM_CommandLoader.getInstance().getKnownCommands(commandMap)) == null)
|
||||||
|
{
|
||||||
|
return paragraph("Error loading commands.");
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBody
|
||||||
|
.append(heading("Command Help", 1))
|
||||||
|
.append(paragraph(
|
||||||
|
"This page is an automatically generated listing of all plugin commands that are currently live on the server. "
|
||||||
|
+ "Please note that it does not include vanilla server commands."));
|
||||||
|
|
||||||
|
final Map<String, List<Command>> commandsByPlugin = new HashMap<String, List<Command>>();
|
||||||
|
|
||||||
|
final Iterator<Map.Entry<String, Command>> itKnownCommands = knownCommands.entrySet().iterator();
|
||||||
|
while (itKnownCommands.hasNext())
|
||||||
|
{
|
||||||
|
final Map.Entry<String, Command> entry = itKnownCommands.next();
|
||||||
|
final String name = entry.getKey();
|
||||||
|
final Command command = entry.getValue();
|
||||||
|
if (name.equalsIgnoreCase(command.getName()))
|
||||||
|
{
|
||||||
|
String pluginName = "Bukkit Default";
|
||||||
|
if (command instanceof PluginIdentifiableCommand)
|
||||||
|
{
|
||||||
|
pluginName = ((PluginIdentifiableCommand) command).getPlugin().getName();
|
||||||
|
}
|
||||||
|
List<Command> pluginCommands = commandsByPlugin.get(pluginName);
|
||||||
|
if (pluginCommands == null)
|
||||||
|
{
|
||||||
|
commandsByPlugin.put(pluginName, pluginCommands = new ArrayList<Command>());
|
||||||
|
}
|
||||||
|
pluginCommands.add(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Iterator<Map.Entry<String, List<Command>>> itCommandsByPlugin = commandsByPlugin.entrySet().iterator();
|
||||||
|
while (itCommandsByPlugin.hasNext())
|
||||||
|
{
|
||||||
|
final Map.Entry<String, List<Command>> entry = itCommandsByPlugin.next();
|
||||||
|
final String pluginName = entry.getKey();
|
||||||
|
final List<Command> commands = entry.getValue();
|
||||||
|
|
||||||
|
Collections.sort(commands, new Comparator<Command>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int compare(Command a, Command b)
|
||||||
|
{
|
||||||
|
if (a instanceof TFM_DynamicCommand && b instanceof TFM_DynamicCommand)
|
||||||
|
{
|
||||||
|
String aName = ((TFM_DynamicCommand) a).getCommandInfo().getLevel().name() + a.getName();
|
||||||
|
String bName = ((TFM_DynamicCommand) b).getCommandInfo().getLevel().name() + b.getName();
|
||||||
|
return aName.compareTo(bName);
|
||||||
|
}
|
||||||
|
return a.getName().compareTo(b.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
responseBody.append(heading(pluginName, 2)).append("<ul>\r\n");
|
||||||
|
|
||||||
|
AdminLevel lastTfmCommandLevel = null;
|
||||||
|
for (Command command : commands)
|
||||||
|
{
|
||||||
|
if ("TotalFreedomMod".equals(pluginName))
|
||||||
|
{
|
||||||
|
AdminLevel tfmCommandLevel = ((TFM_DynamicCommand) command).getCommandInfo().getLevel();
|
||||||
|
if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel)
|
||||||
|
{
|
||||||
|
responseBody.append("</ul>\r\n").append(heading(tfmCommandLevel.getFriendlyName(), 3)).append("<ul>\r\n");
|
||||||
|
}
|
||||||
|
lastTfmCommandLevel = tfmCommandLevel;
|
||||||
|
}
|
||||||
|
responseBody.append(buildDescription(command));
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBody.append("</ul>\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseBody.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildDescription(Command command)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append(
|
||||||
|
"<li><span class=\"commandName\">{$CMD_NAME}</span> - Usage: <span class=\"commandUsage\">{$CMD_USAGE}</span>"
|
||||||
|
.replace("{$CMD_NAME}", escapeHtml4(command.getName().trim()))
|
||||||
|
.replace("{$CMD_USAGE}", escapeHtml4(command.getUsage().trim())));
|
||||||
|
|
||||||
|
if (!command.getAliases().isEmpty())
|
||||||
|
{
|
||||||
|
sb.append(
|
||||||
|
" - Aliases: <span class=\"commandAliases\">{$CMD_ALIASES}</span>"
|
||||||
|
.replace("{$CMD_ALIASES}", escapeHtml4(StringUtils.join(command.getAliases(), ", "))));
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(
|
||||||
|
"<br><span class=\"commandDescription\">{$CMD_DESC}</span></li>\r\n"
|
||||||
|
.replace("{$CMD_DESC}", escapeHtml4(command.getDescription().trim())));
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle()
|
||||||
|
{
|
||||||
|
return "TotalFreedomMod :: Command Help";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStyle()
|
||||||
|
{
|
||||||
|
return ".commandName{font-weight:bold;}.commandDescription{padding-left:15px;}li{margin:.15em;padding:.15em;}";
|
||||||
|
}
|
||||||
|
// @Override
|
||||||
|
// public String getScript()
|
||||||
|
// {
|
||||||
|
// return "$(document).ready(function(){console.log(\"Ready\");});";
|
||||||
|
// }
|
||||||
|
}
|
71
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_list.java
Normal file
71
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_list.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Module_list extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
public Module_list(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBody()
|
||||||
|
{
|
||||||
|
final StringBuilder body = new StringBuilder();
|
||||||
|
|
||||||
|
final Player[] onlinePlayers = Bukkit.getOnlinePlayers();
|
||||||
|
|
||||||
|
body.append("<p>There are ").append(onlinePlayers.length).append("/").append(Bukkit.getMaxPlayers()).append(" players online:</p>\r\n");
|
||||||
|
|
||||||
|
body.append("<ul>\r\n");
|
||||||
|
|
||||||
|
for (Player player : onlinePlayers)
|
||||||
|
{
|
||||||
|
String prefix = "";
|
||||||
|
if (TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
|
{
|
||||||
|
if (TFM_SuperadminList.isSeniorAdmin(player))
|
||||||
|
{
|
||||||
|
prefix = "[SrA]";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prefix = "[SA]";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TFM_Util.DEVELOPERS.contains(player.getName()))
|
||||||
|
{
|
||||||
|
prefix = "[Dev]";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getName().equals("markbyron"))
|
||||||
|
{
|
||||||
|
prefix = "[Owner]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (player.isOp())
|
||||||
|
{
|
||||||
|
prefix = "[OP]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body.append("<li>").append(prefix).append(player.getName()).append("</li>\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
body.append("</ul>\r\n");
|
||||||
|
|
||||||
|
return body.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle()
|
||||||
|
{
|
||||||
|
return "Total Freedom - Online Users";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
|
|
||||||
|
public class Module_permbans extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
public Module_permbans(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NanoHTTPD.Response getResponse()
|
||||||
|
{
|
||||||
|
File permbanFile = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE);
|
||||||
|
if (permbanFile.exists())
|
||||||
|
{
|
||||||
|
return TFM_HTTPD_Manager.serveFileBasic(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||||
|
"Error 404: Not Found - The requested resource was not found on this server.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
public class Module_players extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
public Module_players(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NanoHTTPD.Response getResponse()
|
||||||
|
{
|
||||||
|
final JSONObject responseObject = new JSONObject();
|
||||||
|
|
||||||
|
final JSONArray players = new JSONArray();
|
||||||
|
final JSONArray superadmins = new JSONArray();
|
||||||
|
final JSONArray telnetadmins = new JSONArray();
|
||||||
|
final JSONArray senioradmins = new JSONArray();
|
||||||
|
final JSONArray developers = new JSONArray();
|
||||||
|
|
||||||
|
// All online players
|
||||||
|
for (Player player : TotalFreedomMod.server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
players.add(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Super admins (non-telnet and non-senior)
|
||||||
|
for (String superadmin : TFM_SuperadminList.getSuperadminNames())
|
||||||
|
{
|
||||||
|
if (TFM_SuperadminList.getSenioradminNames().contains(superadmin))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TFM_SuperadminList.getTelnetadminNames().contains(superadmin))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
superadmins.add(getName(superadmin));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Telnet admins (non-senior)
|
||||||
|
for (String telnetadmin : TFM_SuperadminList.getTelnetadminNames())
|
||||||
|
{
|
||||||
|
if (TFM_SuperadminList.getSenioradminNames().contains(telnetadmin))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
telnetadmins.add(getName(telnetadmin));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Senior admins
|
||||||
|
for (String senioradmin : TFM_SuperadminList.getSenioradminNames())
|
||||||
|
{
|
||||||
|
senioradmins.add(getName(senioradmin));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Developers
|
||||||
|
developers.addAll(TFM_Util.DEVELOPERS);
|
||||||
|
|
||||||
|
responseObject.put("players", players);
|
||||||
|
responseObject.put("superadmins", superadmins);
|
||||||
|
responseObject.put("telnetadmins", telnetadmins);
|
||||||
|
responseObject.put("senioradmins", senioradmins);
|
||||||
|
responseObject.put("developers", developers);
|
||||||
|
|
||||||
|
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
|
||||||
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getName(String caseInsensitiveName)
|
||||||
|
{
|
||||||
|
final OfflinePlayer player = Bukkit.getOfflinePlayer(caseInsensitiveName);
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
return caseInsensitiveName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return player.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
296
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_schematic.java
Normal file
296
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_schematic.java
Normal file
@ -0,0 +1,296 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Method;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
|
import net.minecraft.util.org.apache.commons.io.FileUtils;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.StringEscapeUtils;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class Module_schematic extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
private static final File SCHEMATIC_FOLDER = new File("./plugins/WorldEdit/schematics/");
|
||||||
|
private static final String REQUEST_FORM_FILE_ELEMENT_NAME = "schematicFile";
|
||||||
|
private static final Pattern SCHEMATIC_FILENAME_LC = Pattern.compile("^[a-z0-9]{1,30}\\.schematic$");
|
||||||
|
private static final String[] SCHEMATIC_FILTER = new String[]
|
||||||
|
{
|
||||||
|
"schematic"
|
||||||
|
};
|
||||||
|
private static final String UPLOAD_FORM =
|
||||||
|
"<form method=\"post\" name=\"schematicForm\" id=\"schematicForm\" action=\"/schematic/upload/\" enctype=\"multipart/form-data\">\n"
|
||||||
|
+ "<p>Select a schematic file to upload. Filenames must be alphanumeric, between 1 and 30 characters long (inclusive), and have a .schematic extension.</p>\n"
|
||||||
|
+ "<input type=\"file\" id=\"schematicFile\" name=\"schematicFile\" />\n"
|
||||||
|
+ "<br />\n"
|
||||||
|
+ "<button type=\"submit\">Submit</button>\n"
|
||||||
|
+ "</form>";
|
||||||
|
|
||||||
|
public Module_schematic(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response getResponse()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new TFM_HTTPD_PageBuilder(body(), title(), null, null).getResponse();
|
||||||
|
}
|
||||||
|
catch (ResponseOverrideException ex)
|
||||||
|
{
|
||||||
|
return ex.getResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String title()
|
||||||
|
{
|
||||||
|
return "TotalFreedomMod :: Schematic Manager";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String body() throws ResponseOverrideException
|
||||||
|
{
|
||||||
|
if (!SCHEMATIC_FOLDER.exists())
|
||||||
|
{
|
||||||
|
return HTMLGenerationTools.paragraph("Can't find the WorldEdit schematic folder.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringBuilder out = new StringBuilder();
|
||||||
|
|
||||||
|
final String[] args = StringUtils.split(uri, "/");
|
||||||
|
final ModuleMode mode = ModuleMode.getMode(getArg(args, 1));
|
||||||
|
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case LIST:
|
||||||
|
{
|
||||||
|
Collection<File> schematics = FileUtils.listFiles(SCHEMATIC_FOLDER, SCHEMATIC_FILTER, false);
|
||||||
|
|
||||||
|
final List<String> schematicsFormatted = new ArrayList<String>();
|
||||||
|
for (File schematic : schematics)
|
||||||
|
{
|
||||||
|
String filename = StringEscapeUtils.escapeHtml4(schematic.getName());
|
||||||
|
schematicsFormatted.add("<li><a href=\"/schematic/download?schematicName=" + filename + "\">" + filename + "</a></li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(schematicsFormatted, new Comparator<String>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int compare(String a, String b)
|
||||||
|
{
|
||||||
|
return a.toLowerCase().compareTo(b.toLowerCase());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
out
|
||||||
|
.append(HTMLGenerationTools.heading("Schematics:", 1))
|
||||||
|
.append("<ul>")
|
||||||
|
.append(StringUtils.join(schematicsFormatted, "\r\n"))
|
||||||
|
.append("</ul>");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DOWNLOAD:
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
throw new ResponseOverrideException(downloadSchematic(params.get("schematicName")));
|
||||||
|
}
|
||||||
|
catch (SchematicTransferException ex)
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Error downloading schematic: " + ex.getMessage()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UPLOAD:
|
||||||
|
{
|
||||||
|
final String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||||
|
if (!isAuthorized(remoteAddress))
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Schematic upload access denied: Your IP, " + remoteAddress + ", is not registered to a superadmin on this server."));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (method == Method.POST)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uploadSchematic();
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Schematic uploaded successfully."));
|
||||||
|
}
|
||||||
|
catch (SchematicTransferException ex)
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Error uploading schematic: " + ex.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out.append(UPLOAD_FORM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Invalid request mode."));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean uploadSchematic() throws SchematicTransferException
|
||||||
|
{
|
||||||
|
Map<String, String> files = getFiles();
|
||||||
|
|
||||||
|
final String tempFileName = files.get(REQUEST_FORM_FILE_ELEMENT_NAME);
|
||||||
|
if (tempFileName == null)
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("No file transmitted to server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final File tempFile = new File(tempFileName);
|
||||||
|
if (!tempFile.exists())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException();
|
||||||
|
}
|
||||||
|
|
||||||
|
String origFileName = params.get(REQUEST_FORM_FILE_ELEMENT_NAME);
|
||||||
|
if (origFileName == null || (origFileName = origFileName.trim()).isEmpty())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Can't resolve original file name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempFile.length() > FileUtils.ONE_KB * 64L)
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Schematic is too big (64kb max).");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SCHEMATIC_FILENAME_LC.matcher(origFileName.toLowerCase()).find())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("File name must be alphanumeric, between 1 and 30 characters long (inclusive), and have a \".schematic\" extension.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final File targetFile = new File(SCHEMATIC_FOLDER.getPath(), origFileName);
|
||||||
|
if (targetFile.exists())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Schematic already exists on the server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileUtils.copyFile(tempFile, targetFile);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
throw new SchematicTransferException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response downloadSchematic(String schematicName) throws SchematicTransferException
|
||||||
|
{
|
||||||
|
if (schematicName == null || !SCHEMATIC_FILENAME_LC.matcher((schematicName = schematicName.trim()).toLowerCase()).find())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Invalid schematic name requested: " + schematicName);
|
||||||
|
}
|
||||||
|
|
||||||
|
final File targetFile = new File(SCHEMATIC_FOLDER.getPath(), schematicName);
|
||||||
|
if (!targetFile.exists())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Schematic not found: " + schematicName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Response response = TFM_HTTPD_Manager.serveFileBasic(targetFile);
|
||||||
|
|
||||||
|
response.addHeader("Content-Disposition", "attachment; filename=" + targetFile.getName() + ";");
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isAuthorized(String remoteAddress)
|
||||||
|
{
|
||||||
|
TFM_Superadmin entry = TFM_SuperadminList.getAdminEntryByIP(remoteAddress);
|
||||||
|
return entry != null && entry.isActivated();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SchematicTransferException extends Exception
|
||||||
|
{
|
||||||
|
public SchematicTransferException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public SchematicTransferException(String string)
|
||||||
|
{
|
||||||
|
super(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ResponseOverrideException extends Exception
|
||||||
|
{
|
||||||
|
private final Response response;
|
||||||
|
|
||||||
|
public ResponseOverrideException(Response response)
|
||||||
|
{
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response getResponse()
|
||||||
|
{
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getArg(String[] args, int index)
|
||||||
|
{
|
||||||
|
String out = (args.length == index + 1 ? args[index] : null);
|
||||||
|
return (out == null ? null : (out.trim().isEmpty() ? null : out.trim()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static enum ModuleMode
|
||||||
|
{
|
||||||
|
LIST("list"),
|
||||||
|
UPLOAD("upload"),
|
||||||
|
DOWNLOAD("download"),
|
||||||
|
INVALID(null);
|
||||||
|
//
|
||||||
|
private final String modeName;
|
||||||
|
|
||||||
|
private ModuleMode(String modeName)
|
||||||
|
{
|
||||||
|
this.modeName = modeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return this.modeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModuleMode getMode(String needle)
|
||||||
|
{
|
||||||
|
for (ModuleMode mode : values())
|
||||||
|
{
|
||||||
|
final String haystack = mode.toString();
|
||||||
|
if (haystack != null && haystack.equalsIgnoreCase(needle))
|
||||||
|
{
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1548
src/me/StevenLawson/TotalFreedomMod/HTTPD/NanoHTTPD.java
Normal file
1548
src/me/StevenLawson/TotalFreedomMod/HTTPD/NanoHTTPD.java
Normal file
File diff suppressed because it is too large
Load Diff
280
src/me/StevenLawson/TotalFreedomMod/HTTPD/TFM_HTTPD_Manager.java
Normal file
280
src/me/StevenLawson/TotalFreedomMod/HTTPD/TFM_HTTPD_Manager.java
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.HTTPSession;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class TFM_HTTPD_Manager
|
||||||
|
{
|
||||||
|
@Deprecated
|
||||||
|
public static String MIME_DEFAULT_BINARY = "application/octet-stream";
|
||||||
|
//
|
||||||
|
private static final Pattern EXT_REGEX = Pattern.compile("\\.([^\\.\\s]+)$");
|
||||||
|
//
|
||||||
|
public static final int PORT = TFM_ConfigEntry.HTTPD_PORT.getInteger();
|
||||||
|
//
|
||||||
|
private final TFM_HTTPD httpd = new TFM_HTTPD(PORT);
|
||||||
|
|
||||||
|
private TFM_HTTPD_Manager()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start()
|
||||||
|
{
|
||||||
|
if (!TFM_ConfigEntry.HTTPD_ENABLED.getBoolean())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
httpd.start();
|
||||||
|
|
||||||
|
if (httpd.isAlive())
|
||||||
|
{
|
||||||
|
TFM_Log.info("TFM HTTPd started. Listening on port: " + httpd.getListeningPort());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TFM_Log.info("Error starting TFM HTTPd.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop()
|
||||||
|
{
|
||||||
|
if (!TFM_ConfigEntry.HTTPD_ENABLED.getBoolean())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
httpd.stop();
|
||||||
|
|
||||||
|
TFM_Log.info("TFM HTTPd stopped.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static enum ModuleType
|
||||||
|
{
|
||||||
|
DUMP(new ModuleExecutable(false, "dump")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Response(Response.Status.OK, NanoHTTPD.MIME_PLAINTEXT, "The DUMP module is disabled. It is intended for debugging use only.");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
HELP(new ModuleExecutable(true, "help")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_help(session).getResponse();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
LIST(new ModuleExecutable(true, "list")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_list(session).getResponse();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
FILE(new ModuleExecutable(false, "file")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_file(session).getResponse();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
SCHEMATIC(new ModuleExecutable(false, "schematic")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_schematic(session).getResponse();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
PERMBANS(new ModuleExecutable(false, "permbans")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_permbans(session).getResponse();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
PLAYERS(new ModuleExecutable(true, "players")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_players(session).getResponse();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//
|
||||||
|
private final ModuleExecutable moduleExecutable;
|
||||||
|
|
||||||
|
private ModuleType(ModuleExecutable moduleExecutable)
|
||||||
|
{
|
||||||
|
this.moduleExecutable = moduleExecutable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private abstract static class ModuleExecutable
|
||||||
|
{
|
||||||
|
private final boolean runOnBukkitThread;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public ModuleExecutable(boolean runOnBukkitThread, String name)
|
||||||
|
{
|
||||||
|
this.runOnBukkitThread = runOnBukkitThread;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response execute(final HTTPSession session)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (this.runOnBukkitThread)
|
||||||
|
{
|
||||||
|
return Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.plugin, new Callable<Response>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response call() throws Exception
|
||||||
|
{
|
||||||
|
return getResponse(session);
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return getResponse(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Response getResponse(HTTPSession session);
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModuleExecutable getModuleExecutable()
|
||||||
|
{
|
||||||
|
return moduleExecutable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ModuleType getByName(String needle)
|
||||||
|
{
|
||||||
|
for (ModuleType type : values())
|
||||||
|
{
|
||||||
|
if (type.getModuleExecutable().getName().equalsIgnoreCase(needle))
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FILE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TFM_HTTPD extends NanoHTTPD
|
||||||
|
{
|
||||||
|
public TFM_HTTPD(int port)
|
||||||
|
{
|
||||||
|
super(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TFM_HTTPD(String hostname, int port)
|
||||||
|
{
|
||||||
|
super(hostname, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response serve(HTTPSession session)
|
||||||
|
{
|
||||||
|
Response response;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final String[] args = StringUtils.split(session.getUri(), "/");
|
||||||
|
final ModuleType moduleType = args.length >= 1 ? ModuleType.getByName(args[0]) : ModuleType.FILE;
|
||||||
|
response = moduleType.getModuleExecutable().execute(session);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
response = new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Error 500: Internal Server Error\r\n" + ex.getMessage() + "\r\n" + ExceptionUtils.getStackTrace(ex));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response == null)
|
||||||
|
{
|
||||||
|
response = new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Error 404: Not Found - The requested resource was not found on this server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Response serveFileBasic(File file)
|
||||||
|
{
|
||||||
|
Response response = null;
|
||||||
|
|
||||||
|
if (file != null && file.exists())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String mimetype = null;
|
||||||
|
|
||||||
|
Matcher matcher = EXT_REGEX.matcher(file.getCanonicalPath());
|
||||||
|
if (matcher.find())
|
||||||
|
{
|
||||||
|
mimetype = Module_file.MIME_TYPES.get(matcher.group(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mimetype == null || mimetype.trim().isEmpty())
|
||||||
|
{
|
||||||
|
mimetype = MIME_DEFAULT_BINARY;
|
||||||
|
}
|
||||||
|
|
||||||
|
response = new Response(Response.Status.OK, mimetype, new FileInputStream(file));
|
||||||
|
response.addHeader("Content-Length", "" + file.length());
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TFM_HTTPD_Manager getInstance()
|
||||||
|
{
|
||||||
|
return TFM_HTTPDManagerHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TFM_HTTPDManagerHolder
|
||||||
|
{
|
||||||
|
private static final TFM_HTTPD_Manager INSTANCE = new TFM_HTTPD_Manager();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.*;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
|
|
||||||
|
public abstract class TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
protected final String uri;
|
||||||
|
protected final Method method;
|
||||||
|
protected final Map<String, String> headers;
|
||||||
|
protected final Map<String, String> params;
|
||||||
|
protected final Socket socket;
|
||||||
|
protected final HTTPSession session;
|
||||||
|
|
||||||
|
public TFM_HTTPD_Module(HTTPSession session)
|
||||||
|
{
|
||||||
|
this.uri = session.getUri();
|
||||||
|
this.method = session.getMethod();
|
||||||
|
this.headers = session.getHeaders();
|
||||||
|
this.params = session.getParms();
|
||||||
|
this.socket = session.getSocket();
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBody()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStyle()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScript()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response getResponse()
|
||||||
|
{
|
||||||
|
return new TFM_HTTPD_PageBuilder(getBody(), getTitle(), getStyle(), getScript()).getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Map<String, String> getFiles()
|
||||||
|
{
|
||||||
|
Map<String, String> files = new HashMap<String, String>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
session.parseBody(files);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response;
|
||||||
|
|
||||||
|
public class TFM_HTTPD_PageBuilder
|
||||||
|
{
|
||||||
|
private static final String TEMPLATE =
|
||||||
|
"<!DOCTYPE html>\r\n"
|
||||||
|
+ "<html>\r\n"
|
||||||
|
+ "<head>\r\n"
|
||||||
|
+ "<title>{$TITLE}</title>\r\n"
|
||||||
|
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n"
|
||||||
|
+ "{$STYLE}"
|
||||||
|
+ "{$SCRIPT}"
|
||||||
|
+ "</head>\r\n"
|
||||||
|
+ "<body>\r\n{$BODY}</body>\r\n"
|
||||||
|
+ "</html>\r\n";
|
||||||
|
private static final String STYLE = "<style type=\"text/css\">{$STYLE}</style>\r\n";
|
||||||
|
private static final String SCRIPT =
|
||||||
|
"<script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js\"></script>\r\n"
|
||||||
|
+ "<script src=\"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js\"></script>\r\n"
|
||||||
|
+ "<script>\r\n{$SCRIPT}\r\n</script>\r\n";
|
||||||
|
//
|
||||||
|
private String body = null;
|
||||||
|
private String title = null;
|
||||||
|
private String style = null;
|
||||||
|
private String script = null;
|
||||||
|
|
||||||
|
public TFM_HTTPD_PageBuilder()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public TFM_HTTPD_PageBuilder(String body, String title, String style, String script)
|
||||||
|
{
|
||||||
|
this.body = body;
|
||||||
|
this.title = title;
|
||||||
|
this.style = style;
|
||||||
|
this.script = script;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBody(String body)
|
||||||
|
{
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title)
|
||||||
|
{
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStyle(String style)
|
||||||
|
{
|
||||||
|
this.style = style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScript(String script)
|
||||||
|
{
|
||||||
|
this.script = script;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response getResponse()
|
||||||
|
{
|
||||||
|
return new Response(this.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return TEMPLATE
|
||||||
|
.replace("{$BODY}", this.body == null ? "" : this.body)
|
||||||
|
.replace("{$TITLE}", this.title == null ? "" : this.title)
|
||||||
|
.replace("{$STYLE}", this.style == null ? "" : STYLE.replace("{$STYLE}", this.style))
|
||||||
|
.replace("{$SCRIPT}", this.script == null ? "" : SCRIPT.replace("{$SCRIPT}", this.script));
|
||||||
|
}
|
||||||
|
}
|
@ -35,27 +35,27 @@ public class TFM_BlockListener implements Listener
|
|||||||
public void onBlockBreak(BlockBreakEvent event)
|
public void onBlockBreak(BlockBreakEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Location block_pos = event.getBlock().getLocation();
|
Location blockLocation = event.getBlock().getLocation();
|
||||||
|
|
||||||
if (TFM_ConfigEntry.NUKE_MONITOR.getBoolean())
|
if (TFM_ConfigEntry.NUKE_MONITOR.getBoolean())
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
|
|
||||||
Location player_pos = player.getLocation();
|
Location playerLocation = player.getLocation();
|
||||||
|
|
||||||
final double nukeMonitorRange = TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble().doubleValue();
|
final double nukeMonitorRange = TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble().doubleValue();
|
||||||
|
|
||||||
boolean out_of_range = false;
|
boolean outOfRange = false;
|
||||||
if (!player_pos.getWorld().equals(block_pos.getWorld()))
|
if (!playerLocation.getWorld().equals(blockLocation.getWorld()))
|
||||||
{
|
{
|
||||||
out_of_range = true;
|
outOfRange = true;
|
||||||
}
|
}
|
||||||
else if (player_pos.distanceSquared(block_pos) > (nukeMonitorRange * nukeMonitorRange))
|
else if (playerLocation.distanceSquared(blockLocation) > (nukeMonitorRange * nukeMonitorRange))
|
||||||
{
|
{
|
||||||
out_of_range = true;
|
outOfRange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_of_range)
|
if (outOfRange)
|
||||||
{
|
{
|
||||||
if (playerdata.incrementAndGetFreecamDestroyCount() > TFM_ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
|
if (playerdata.incrementAndGetFreecamDestroyCount() > TFM_ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
|
||||||
{
|
{
|
||||||
@ -72,7 +72,7 @@ public class TFM_BlockListener implements Listener
|
|||||||
Long lastRan = TFM_Heartbeat.getLastRan();
|
Long lastRan = TFM_Heartbeat.getLastRan();
|
||||||
if (lastRan == null || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis())
|
if (lastRan == null || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis())
|
||||||
{
|
{
|
||||||
//TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
|
// TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -93,7 +93,7 @@ public class TFM_BlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
{
|
{
|
||||||
if (TFM_ProtectedArea.isInProtectedArea(block_pos))
|
if (TFM_ProtectedArea.isInProtectedArea(blockLocation))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -101,37 +101,31 @@ public class TFM_BlockListener implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
||||||
public void onRollbackBlockBreak(BlockBreakEvent event)
|
|
||||||
{
|
|
||||||
TFM_RollbackManager.blockBreak(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBlockPlace(BlockPlaceEvent event)
|
public void onBlockPlace(BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Location block_pos = event.getBlock().getLocation();
|
Location blockLocation = event.getBlock().getLocation();
|
||||||
|
|
||||||
if (TFM_ConfigEntry.NUKE_MONITOR.getBoolean())
|
if (TFM_ConfigEntry.NUKE_MONITOR.getBoolean())
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
|
|
||||||
Location player_pos = player.getLocation();
|
Location playerLocation = player.getLocation();
|
||||||
|
|
||||||
double nukeMonitorRange = TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble().doubleValue();
|
double nukeMonitorRange = TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble().doubleValue();
|
||||||
|
|
||||||
boolean out_of_range = false;
|
boolean outOfRange = false;
|
||||||
if (!player_pos.getWorld().equals(block_pos.getWorld()))
|
if (!playerLocation.getWorld().equals(blockLocation.getWorld()))
|
||||||
{
|
{
|
||||||
out_of_range = true;
|
outOfRange = true;
|
||||||
}
|
}
|
||||||
else if (player_pos.distanceSquared(block_pos) > (nukeMonitorRange * nukeMonitorRange))
|
else if (playerLocation.distanceSquared(blockLocation) > (nukeMonitorRange * nukeMonitorRange))
|
||||||
{
|
{
|
||||||
out_of_range = true;
|
outOfRange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_of_range)
|
if (outOfRange)
|
||||||
{
|
{
|
||||||
if (playerdata.incrementAndGetFreecamPlaceCount() > TFM_ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
|
if (playerdata.incrementAndGetFreecamPlaceCount() > TFM_ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
|
||||||
{
|
{
|
||||||
@ -169,7 +163,7 @@ public class TFM_BlockListener implements Listener
|
|||||||
{
|
{
|
||||||
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
{
|
{
|
||||||
if (TFM_ProtectedArea.isInProtectedArea(block_pos))
|
if (TFM_ProtectedArea.isInProtectedArea(blockLocation))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -252,16 +246,28 @@ public class TFM_BlockListener implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onRollbackBlockBreak(BlockBreakEvent event)
|
||||||
|
{
|
||||||
|
if (!TFM_SuperadminList.isUserSuperadmin(event.getPlayer()))
|
||||||
|
{
|
||||||
|
TFM_RollbackManager.blockBreak(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onRollbackBlockPlace(BlockPlaceEvent event)
|
public void onRollbackBlockPlace(BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
TFM_RollbackManager.blockPlace(event);
|
if (!TFM_SuperadminList.isUserSuperadmin(event.getPlayer()))
|
||||||
|
{
|
||||||
|
TFM_RollbackManager.blockPlace(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBlockFromTo(BlockFromToEvent event)
|
public void onBlockFromTo(BlockFromToEvent event)
|
||||||
{
|
{
|
||||||
if (!TFM_ConfigEntry.ALLOW_FLIUD_SPREAD.getBoolean())
|
if (!TFM_ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,9 @@ import java.util.List;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import me.StevenLawson.TotalFreedomMod.*;
|
import me.StevenLawson.TotalFreedomMod.*;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -35,7 +37,8 @@ public class TFM_PlayerListener implements Listener
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event)
|
public void onPlayerInteract(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
|
|
||||||
switch (event.getAction())
|
switch (event.getAction())
|
||||||
{
|
{
|
||||||
@ -46,37 +49,46 @@ public class TFM_PlayerListener implements Listener
|
|||||||
{
|
{
|
||||||
case WATER_BUCKET:
|
case WATER_BUCKET:
|
||||||
{
|
{
|
||||||
if (!TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
||||||
{
|
{
|
||||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
break;
|
||||||
player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||||
|
player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
|
||||||
|
event.setCancelled(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LAVA_BUCKET:
|
case LAVA_BUCKET:
|
||||||
{
|
{
|
||||||
if (!TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
||||||
{
|
{
|
||||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
break;
|
||||||
player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||||
|
player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
|
||||||
|
event.setCancelled(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPLOSIVE_MINECART:
|
case EXPLOSIVE_MINECART:
|
||||||
{
|
{
|
||||||
if (!TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
|
if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
|
||||||
{
|
{
|
||||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
break;
|
||||||
player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||||
|
player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
|
||||||
|
event.setCancelled(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LEFT_CLICK_AIR:
|
case LEFT_CLICK_AIR:
|
||||||
case LEFT_CLICK_BLOCK:
|
case LEFT_CLICK_BLOCK:
|
||||||
{
|
{
|
||||||
@ -84,128 +96,167 @@ public class TFM_PlayerListener implements Listener
|
|||||||
{
|
{
|
||||||
case STICK:
|
case STICK:
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
if (playerdata.mobThrowerEnabled())
|
|
||||||
{
|
{
|
||||||
Location player_pos = player.getLocation();
|
break;
|
||||||
Vector direction = player_pos.getDirection().normalize();
|
|
||||||
|
|
||||||
LivingEntity rezzed_mob = (LivingEntity) player.getWorld().spawnEntity(player_pos.add(direction.multiply(2.0)), playerdata.mobThrowerCreature());
|
|
||||||
rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
|
|
||||||
playerdata.enqueueMob(rezzed_mob);
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
final Location location = player.getTargetBlock(null, 5).getLocation();
|
||||||
|
final List<RollbackEntry> entries = TFM_RollbackManager.getEntriesAtLocation(location);
|
||||||
|
|
||||||
|
if (entries.isEmpty())
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(player, "No block edits at that location.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_Util.playerMsg(player, "Block edits at (" + ChatColor.WHITE + "x" + location.getBlockX() + ", y" + location.getBlockY() + ", z" + location.getBlockZ() + ChatColor.BLUE + ")" + ChatColor.WHITE + ":", ChatColor.BLUE);
|
||||||
|
for (RollbackEntry entry : entries)
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(player, " - " + ChatColor.BLUE + entry.author + " " + entry.getType() + " " + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase()) + (entry.data == 0 ? "" : ":" + entry.data));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case BONE:
|
||||||
|
{
|
||||||
|
if (!playerdata.mobThrowerEnabled())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location player_pos = player.getLocation();
|
||||||
|
Vector direction = player_pos.getDirection().normalize();
|
||||||
|
|
||||||
|
LivingEntity rezzed_mob = (LivingEntity) player.getWorld().spawnEntity(player_pos.add(direction.multiply(2.0)), playerdata.mobThrowerCreature());
|
||||||
|
rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
|
||||||
|
playerdata.enqueueMob(rezzed_mob);
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case SULPHUR:
|
case SULPHUR:
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
if (!playerdata.isMP44Armed())
|
||||||
if (playerdata.isMP44Armed())
|
|
||||||
{
|
{
|
||||||
if (playerdata.toggleMP44Firing())
|
break;
|
||||||
{
|
}
|
||||||
playerdata.startArrowShooter(TotalFreedomMod.plugin);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
playerdata.stopArrowShooter();
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
if (playerdata.toggleMP44Firing())
|
||||||
|
{
|
||||||
|
playerdata.startArrowShooter(TotalFreedomMod.plugin);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerdata.stopArrowShooter();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case BLAZE_ROD:
|
case BLAZE_ROD:
|
||||||
{
|
{
|
||||||
if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||||
{
|
{
|
||||||
if (TFM_SuperadminList.isSeniorAdmin(player, true))
|
break;
|
||||||
{
|
|
||||||
Block targetBlock;
|
|
||||||
|
|
||||||
if (event.getAction().equals(Action.LEFT_CLICK_AIR))
|
|
||||||
{
|
|
||||||
targetBlock = player.getTargetBlock(null, 120);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
targetBlock = event.getClickedBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetBlock != null)
|
|
||||||
{
|
|
||||||
player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
|
|
||||||
player.getWorld().strikeLightning(targetBlock.getLocation());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player.sendMessage("Can't resolve target block.");
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!TFM_SuperadminList.isSeniorAdmin(player, true))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
Block targetBlock;
|
||||||
|
|
||||||
|
if (event.getAction().equals(Action.LEFT_CLICK_AIR))
|
||||||
|
{
|
||||||
|
targetBlock = player.getTargetBlock(null, 120);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
targetBlock = event.getClickedBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetBlock == null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Can't resolve target block.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
|
||||||
|
player.getWorld().strikeLightning(targetBlock.getLocation());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CARROT:
|
case CARROT:
|
||||||
{
|
{
|
||||||
if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||||
{
|
{
|
||||||
if (TFM_SuperadminList.isSeniorAdmin(player, true))
|
break;
|
||||||
{
|
|
||||||
Location player_location = player.getLocation().clone();
|
|
||||||
|
|
||||||
Vector player_pos = player_location.toVector().add(new Vector(0.0, 1.65, 0.0));
|
|
||||||
Vector player_dir = player_location.getDirection().normalize();
|
|
||||||
|
|
||||||
double distance = 150.0;
|
|
||||||
Block targetBlock = player.getTargetBlock(null, Math.round((float) distance));
|
|
||||||
if (targetBlock != null)
|
|
||||||
{
|
|
||||||
distance = player_location.distance(targetBlock.getLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<Block> affected = new ArrayList<Block>();
|
|
||||||
|
|
||||||
Block last_block = null;
|
|
||||||
for (double offset = 0.0; offset <= distance; offset += (distance / 25.0))
|
|
||||||
{
|
|
||||||
Block test_block = player_pos.clone().add(player_dir.clone().multiply(offset)).toLocation(player.getWorld()).getBlock();
|
|
||||||
|
|
||||||
if (!test_block.equals(last_block))
|
|
||||||
{
|
|
||||||
if (test_block.isEmpty())
|
|
||||||
{
|
|
||||||
affected.add(test_block);
|
|
||||||
test_block.setType(Material.TNT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
last_block = test_block;
|
|
||||||
}
|
|
||||||
|
|
||||||
new BukkitRunnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
for (Block tnt_block : affected)
|
|
||||||
{
|
|
||||||
TNTPrimed tnt_primed = tnt_block.getWorld().spawn(tnt_block.getLocation(), TNTPrimed.class);
|
|
||||||
tnt_primed.setFuseTicks(5);
|
|
||||||
tnt_block.setType(Material.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.runTaskLater(TotalFreedomMod.plugin, 30L);
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!TFM_SuperadminList.isSeniorAdmin(player, true))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location location = player.getLocation().clone();
|
||||||
|
|
||||||
|
Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
|
||||||
|
Vector playerDirection = location.getDirection().normalize();
|
||||||
|
|
||||||
|
double distance = 150.0;
|
||||||
|
Block targetBlock = player.getTargetBlock(null, Math.round((float) distance));
|
||||||
|
if (targetBlock != null)
|
||||||
|
{
|
||||||
|
distance = location.distance(targetBlock.getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<Block> affected = new ArrayList<Block>();
|
||||||
|
|
||||||
|
Block lastBlock = null;
|
||||||
|
for (double offset = 0.0; offset <= distance; offset += (distance / 25.0))
|
||||||
|
{
|
||||||
|
Block block = playerPostion.clone().add(playerDirection.clone().multiply(offset)).toLocation(player.getWorld()).getBlock();
|
||||||
|
|
||||||
|
if (!block.equals(lastBlock))
|
||||||
|
{
|
||||||
|
if (block.isEmpty())
|
||||||
|
{
|
||||||
|
affected.add(block);
|
||||||
|
block.setType(Material.TNT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastBlock = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
for (Block tntBlock : affected)
|
||||||
|
{
|
||||||
|
TNTPrimed tnt = tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
|
||||||
|
tnt.setFuseTicks(5);
|
||||||
|
tntBlock.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(TotalFreedomMod.plugin, 30L);
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,52 +298,52 @@ public class TFM_PlayerListener implements Listener
|
|||||||
|
|
||||||
for (Entry<Player, Double> fuckoff : TotalFreedomMod.fuckoffEnabledFor.entrySet())
|
for (Entry<Player, Double> fuckoff : TotalFreedomMod.fuckoffEnabledFor.entrySet())
|
||||||
{
|
{
|
||||||
Player fuckoff_player = fuckoff.getKey();
|
Player fuckoffPlayer = fuckoff.getKey();
|
||||||
|
|
||||||
if (fuckoff_player.equals(player) || !fuckoff_player.isOnline())
|
if (fuckoffPlayer.equals(player) || !fuckoffPlayer.isOnline())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double fuckoff_range = fuckoff.getValue().doubleValue();
|
double fuckoffRange = fuckoff.getValue().doubleValue();
|
||||||
|
|
||||||
Location mover_pos = player.getLocation();
|
Location playerLocation = player.getLocation();
|
||||||
Location fuckoff_pos = fuckoff_player.getLocation();
|
Location fuckoffLocation = fuckoffPlayer.getLocation();
|
||||||
|
|
||||||
double distanceSquared;
|
double distanceSquared;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
distanceSquared = mover_pos.distanceSquared(fuckoff_pos);
|
distanceSquared = playerLocation.distanceSquared(fuckoffLocation);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ex)
|
catch (IllegalArgumentException ex)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (distanceSquared < (fuckoff_range * fuckoff_range))
|
if (distanceSquared < (fuckoffRange * fuckoffRange))
|
||||||
{
|
{
|
||||||
event.setTo(fuckoff_pos.clone().add(mover_pos.subtract(fuckoff_pos).toVector().normalize().multiply(fuckoff_range * 1.1)));
|
event.setTo(fuckoffLocation.clone().add(playerLocation.subtract(fuckoffLocation).toVector().normalize().multiply(fuckoffRange * 1.1)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean do_freeze = false;
|
boolean freeze = false;
|
||||||
if (TotalFreedomMod.allPlayersFrozen)
|
if (TotalFreedomMod.allPlayersFrozen)
|
||||||
{
|
{
|
||||||
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
{
|
{
|
||||||
do_freeze = true;
|
freeze = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (playerdata.isFrozen())
|
if (playerdata.isFrozen())
|
||||||
{
|
{
|
||||||
do_freeze = true;
|
freeze = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_freeze)
|
if (freeze)
|
||||||
{
|
{
|
||||||
Location freezeTo = to.clone();
|
Location freezeTo = to.clone();
|
||||||
|
|
||||||
@ -307,23 +358,23 @@ public class TFM_PlayerListener implements Listener
|
|||||||
{
|
{
|
||||||
Location targetPos = player.getLocation().add(0, 1, 0);
|
Location targetPos = player.getLocation().add(0, 1, 0);
|
||||||
|
|
||||||
boolean out_of_cage;
|
boolean outOfCage;
|
||||||
if (!targetPos.getWorld().equals(playerdata.getCagePos().getWorld()))
|
if (!targetPos.getWorld().equals(playerdata.getCagePos().getWorld()))
|
||||||
{
|
{
|
||||||
out_of_cage = true;
|
outOfCage = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out_of_cage = targetPos.distanceSquared(playerdata.getCagePos()) > (2.5 * 2.5);
|
outOfCage = targetPos.distanceSquared(playerdata.getCagePos()) > (2.5 * 2.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_of_cage)
|
if (outOfCage)
|
||||||
{
|
{
|
||||||
playerdata.setCaged(true, targetPos, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER), playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
|
playerdata.setCaged(true, targetPos, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER), playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
|
||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
playerdata.clearHistory();
|
playerdata.clearHistory();
|
||||||
TFM_Util.buildHistory(targetPos, 2, playerdata);
|
TFM_Util.buildHistory(targetPos, 2, playerdata);
|
||||||
TFM_Util.generateCube(targetPos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER));
|
TFM_Util.generateHollowCube(targetPos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER));
|
||||||
TFM_Util.generateCube(targetPos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
|
TFM_Util.generateCube(targetPos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -341,42 +392,50 @@ public class TFM_PlayerListener implements Listener
|
|||||||
TFM_Jumppads.getInstance().PlayerMoveEvent(event);
|
TFM_Jumppads.getInstance().PlayerMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean() && TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
if (!(TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean() && TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()))
|
||||||
{
|
{
|
||||||
Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
|
return;
|
||||||
while (landmines.hasNext())
|
}
|
||||||
|
|
||||||
|
Iterator<Command_landmine.TFM_LandmineData> landmines = Command_landmine.TFM_LandmineData.landmines.iterator();
|
||||||
|
while (landmines.hasNext())
|
||||||
|
{
|
||||||
|
Command_landmine.TFM_LandmineData landmine = landmines.next();
|
||||||
|
|
||||||
|
Location location = landmine.location;
|
||||||
|
if (location.getBlock().getType() != Material.TNT)
|
||||||
{
|
{
|
||||||
TFM_LandmineData landmine = landmines.next();
|
landmines.remove();
|
||||||
|
continue;
|
||||||
Location landmine_pos = landmine.landmine_pos;
|
|
||||||
if (landmine_pos.getBlock().getType() != Material.TNT)
|
|
||||||
{
|
|
||||||
landmines.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!landmine.player.equals(player))
|
|
||||||
{
|
|
||||||
if (player.getWorld().equals(landmine_pos.getWorld()))
|
|
||||||
{
|
|
||||||
if (player.getLocation().distanceSquared(landmine_pos) <= (landmine.radius * landmine.radius))
|
|
||||||
{
|
|
||||||
landmine.landmine_pos.getBlock().setType(Material.AIR);
|
|
||||||
|
|
||||||
TNTPrimed tnt1 = landmine_pos.getWorld().spawn(landmine_pos, TNTPrimed.class);
|
|
||||||
tnt1.setFuseTicks(40);
|
|
||||||
tnt1.setPassenger(player);
|
|
||||||
tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));
|
|
||||||
|
|
||||||
TNTPrimed tnt2 = landmine_pos.getWorld().spawn(player.getLocation(), TNTPrimed.class);
|
|
||||||
tnt2.setFuseTicks(1);
|
|
||||||
|
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
|
||||||
landmines.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (landmine.player.equals(player))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!player.getWorld().equals(location.getWorld()))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(player.getLocation().distanceSquared(location) <= (landmine.radius * landmine.radius)))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
landmine.location.getBlock().setType(Material.AIR);
|
||||||
|
|
||||||
|
TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class);
|
||||||
|
tnt1.setFuseTicks(40);
|
||||||
|
tnt1.setPassenger(player);
|
||||||
|
tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));
|
||||||
|
|
||||||
|
TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class);
|
||||||
|
tnt2.setFuseTicks(1);
|
||||||
|
|
||||||
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
landmines.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -424,6 +483,7 @@ public class TFM_PlayerListener implements Listener
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerdata.setLastMessage(message);
|
playerdata.setLastMessage(message);
|
||||||
|
|
||||||
// Check for muted
|
// Check for muted
|
||||||
@ -435,10 +495,8 @@ public class TFM_PlayerListener implements Listener
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
playerdata.setMuted(false);
|
||||||
playerdata.setMuted(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip color from messages
|
// Strip color from messages
|
||||||
@ -479,6 +537,9 @@ public class TFM_PlayerListener implements Listener
|
|||||||
// Finally, set message
|
// Finally, set message
|
||||||
event.setMessage(message);
|
event.setMessage(message);
|
||||||
|
|
||||||
|
// Broadcast it to console (since 1.7 doesn't do that anymore)
|
||||||
|
TFM_Log.info(String.format(event.getFormat(), player.getDisplayName(), event.getMessage()), true);
|
||||||
|
|
||||||
// Set the tag
|
// Set the tag
|
||||||
if (playerdata.getTag() != null)
|
if (playerdata.getTag() != null)
|
||||||
{
|
{
|
||||||
@ -526,9 +587,9 @@ public class TFM_PlayerListener implements Listener
|
|||||||
{
|
{
|
||||||
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
{
|
{
|
||||||
for (String test_command : BLOCKED_MUTED_CMDS)
|
for (String commandName : BLOCKED_MUTED_CMDS)
|
||||||
{
|
{
|
||||||
if (Pattern.compile("^/" + test_command.toLowerCase() + " ").matcher(command).find())
|
if (Pattern.compile("^/" + commandName.toLowerCase() + " ").matcher(command).find())
|
||||||
{
|
{
|
||||||
player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
|
player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -599,6 +660,9 @@ public class TFM_PlayerListener implements Listener
|
|||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
playerdata.clearHistory();
|
playerdata.clearHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log player quitting, because 1.7 doesn't do this
|
||||||
|
TFM_Log.info(player.getName() + " left the game.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
@ -627,15 +691,18 @@ public class TFM_PlayerListener implements Listener
|
|||||||
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
playerdata.setSuperadminIdVerified(null);
|
playerdata.setSuperadminIdVerified(null);
|
||||||
|
|
||||||
|
// Log join message, as 1.7 doesn't log it anymore
|
||||||
|
TFM_Log.info(player.getName() + " joined the game.");
|
||||||
|
|
||||||
TFM_UserList.getInstance(TotalFreedomMod.plugin).addUser(player);
|
TFM_UserList.getInstance(TotalFreedomMod.plugin).addUser(player);
|
||||||
|
|
||||||
boolean superadmin_impostor = TFM_SuperadminList.isSuperadminImpostor(player);
|
final boolean impostor = TFM_SuperadminList.isSuperadminImpostor(player);
|
||||||
|
|
||||||
if (superadmin_impostor || TFM_SuperadminList.isUserSuperadmin(player))
|
if (impostor || TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
{
|
{
|
||||||
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_Util.getRank(player));
|
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
|
||||||
|
|
||||||
if (superadmin_impostor)
|
if (impostor)
|
||||||
{
|
{
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
@ -660,6 +727,10 @@ public class TFM_PlayerListener implements Listener
|
|||||||
player.setOp(true);
|
player.setOp(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (TFM_Util.DEVELOPERS.contains(player.getName()))
|
||||||
|
{
|
||||||
|
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
|
||||||
|
}
|
||||||
|
|
||||||
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||||
{
|
{
|
||||||
|
@ -1,28 +1,17 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Listener;
|
package me.StevenLawson.TotalFreedomMod.Listener;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
|
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.server.RemoteServerCommandEvent;
|
import org.bukkit.event.server.RemoteServerCommandEvent;
|
||||||
import org.bukkit.event.server.ServerCommandEvent;
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
import org.bukkit.event.server.ServerListPingEvent;
|
import org.bukkit.event.server.ServerListPingEvent;
|
||||||
import org.bukkit.permissions.Permission;
|
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class TFM_ServerListener implements Listener
|
public class TFM_ServerListener implements Listener
|
||||||
{
|
{
|
||||||
@ -30,37 +19,38 @@ public class TFM_ServerListener implements Listener
|
|||||||
// Comment this method out if you want to compile this without a custom CraftBukkit.
|
// Comment this method out if you want to compile this without a custom CraftBukkit.
|
||||||
// Just make sure that enable-command-block=false in server.properties.
|
// Just make sure that enable-command-block=false in server.properties.
|
||||||
// -Madgeek
|
// -Madgeek
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
/* Temporary: Until we get a custom CB build out
|
||||||
public void onCommandBlockSet(org.bukkit.event.server.CommandBlockSetEvent event)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
{
|
public void onCommandBlockSet(org.bukkit.event.server.CommandBlockSetEvent event)
|
||||||
Player player = event.getPlayer();
|
{
|
||||||
String newCommandRaw = event.getNewCommand();
|
Player player = event.getPlayer();
|
||||||
|
String newCommandRaw = event.getNewCommand();
|
||||||
|
|
||||||
if (!TFM_SuperadminList.isSeniorAdmin(player, true))
|
if (!TFM_SuperadminList.isSeniorAdmin(player, true))
|
||||||
{
|
{
|
||||||
player.sendMessage(ChatColor.GRAY + "Only senior admins may set command block commands.");
|
player.sendMessage(ChatColor.GRAY + "Only senior admins may set command block commands.");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher matcher = Pattern.compile("^/?(\\S+)").matcher(newCommandRaw);
|
Matcher matcher = Pattern.compile("^/?(\\S+)").matcher(newCommandRaw);
|
||||||
if (matcher.find())
|
if (matcher.find())
|
||||||
{
|
{
|
||||||
String topLevelCommand = matcher.group(1);
|
String topLevelCommand = matcher.group(1);
|
||||||
if (topLevelCommand != null)
|
if (topLevelCommand != null)
|
||||||
{
|
{
|
||||||
topLevelCommand = topLevelCommand.toLowerCase().trim();
|
topLevelCommand = topLevelCommand.toLowerCase().trim();
|
||||||
|
|
||||||
// We need to make it look like the command is coming from the console, so keep the player's name without the Player instance via dummy:
|
|
||||||
if (TFM_CommandBlocker.getInstance().isCommandBlocked(topLevelCommand, new TFM_ServerListener_DummyCommandSender(player.getName()), false))
|
|
||||||
{
|
|
||||||
player.sendMessage(ChatColor.GRAY + "That command is blocked.");
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// We need to make it look like the command is coming from the console, so keep the player's name without the Player instance via dummy:
|
||||||
|
if (TFM_CommandBlocker.getInstance().isCommandBlocked(topLevelCommand, new TFM_ServerListener_DummyCommandSender(player.getName()), false))
|
||||||
|
{
|
||||||
|
player.sendMessage(ChatColor.GRAY + "That command is blocked.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
@Deprecated // Moved to TFM_TelnetListener
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onRemoteServerCommand(RemoteServerCommandEvent event)
|
public void onRemoteServerCommand(RemoteServerCommandEvent event)
|
||||||
{
|
{
|
||||||
@ -70,6 +60,7 @@ public class TFM_ServerListener implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated // Moved to TFM_TelnetListener
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onServerCommand(ServerCommandEvent event)
|
public void onServerCommand(ServerCommandEvent event)
|
||||||
{
|
{
|
||||||
@ -101,111 +92,4 @@ public class TFM_ServerListener implements Listener
|
|||||||
event.setMotd(ChatColor.RED + "Server is full.");
|
event.setMotd(ChatColor.RED + "Server is full.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TFM_ServerListener_DummyCommandSender implements CommandSender
|
|
||||||
{
|
|
||||||
private final String senderName;
|
|
||||||
|
|
||||||
public TFM_ServerListener_DummyCommandSender(String senderName)
|
|
||||||
{
|
|
||||||
this.senderName = senderName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(String message)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(String[] messages)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Server getServer()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName()
|
|
||||||
{
|
|
||||||
return senderName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPermissionSet(String name)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPermissionSet(Permission perm)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(String name)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Permission perm)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAttachment(PermissionAttachment attachment)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void recalculatePermissions()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<PermissionAttachmentInfo> getEffectivePermissions()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOp()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOp(boolean value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Listener;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class TFM_TelnetListener implements Listener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onTelnetPreLogin(me.StevenLawson.BukkitTelnet.TelnetPreLoginEvent event)
|
||||||
|
{
|
||||||
|
|
||||||
|
final String ip = event.getIp();
|
||||||
|
if (ip == null || ip.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final TFM_Superadmin admin = TFM_SuperadminList.getAdminEntryByIP(ip, true);
|
||||||
|
|
||||||
|
if (admin == null || !(admin.isTelnetAdmin() || admin.isSeniorAdmin()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setBypassPassword(true);
|
||||||
|
event.setName(admin.getName());
|
||||||
|
|
||||||
|
final OfflinePlayer player = Bukkit.getOfflinePlayer(admin.getName());
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setName(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onTelnetCommand(me.StevenLawson.BukkitTelnet.TelnetCommandEvent event)
|
||||||
|
{
|
||||||
|
if (TFM_CommandBlocker.getInstance().isCommandBlocked(event.getCommand(), event.getSender()))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Listener;
|
package me.StevenLawson.TotalFreedomMod.Listener;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -12,6 +13,17 @@ public class TFM_WeatherListener implements Listener
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onThunderChange(ThunderChangeEvent event)
|
public void onThunderChange(ThunderChangeEvent event)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (event.getWorld() == TFM_AdminWorld.getInstance().getWorld() && TFM_AdminWorld.getInstance().getWeatherMode() != TFM_AdminWorld.WeatherMode.OFF)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
if (event.toThunderState() && TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
if (event.toThunderState() && TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -22,6 +34,17 @@ public class TFM_WeatherListener implements Listener
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onWeatherChange(WeatherChangeEvent event)
|
public void onWeatherChange(WeatherChangeEvent event)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (event.getWorld() == TFM_AdminWorld.getInstance().getWorld() && TFM_AdminWorld.getInstance().getWeatherMode() != TFM_AdminWorld.WeatherMode.OFF)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
if (event.toWeatherState() && TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
if (event.toWeatherState() && TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
|
||||||
|
|
||||||
// From: http://forums.bukkit.org/threads/location-serialized.105851/
|
|
||||||
// By: gcflames5
|
|
||||||
public final class SerializableLocation implements Serializable
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 7498864812883577904L;
|
|
||||||
private final String world;
|
|
||||||
private final String uuid;
|
|
||||||
private final double x, y, z;
|
|
||||||
private final float yaw, pitch;
|
|
||||||
private transient Location loc;
|
|
||||||
|
|
||||||
public SerializableLocation(Location l)
|
|
||||||
{
|
|
||||||
this.world = l.getWorld().getName();
|
|
||||||
this.uuid = l.getWorld().getUID().toString();
|
|
||||||
this.x = l.getX();
|
|
||||||
this.y = l.getY();
|
|
||||||
this.z = l.getZ();
|
|
||||||
this.yaw = l.getYaw();
|
|
||||||
this.pitch = l.getPitch();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Location returnLocation(SerializableLocation l)
|
|
||||||
{
|
|
||||||
float pitch = l.pitch;
|
|
||||||
float yaw = l.yaw;
|
|
||||||
double x = l.x;
|
|
||||||
double y = l.y;
|
|
||||||
double z = l.z;
|
|
||||||
World world = Bukkit.getWorld(l.world);
|
|
||||||
Location location = new Location(world, x, y, z, yaw, pitch);
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Location returnBlockLocation(SerializableLocation l)
|
|
||||||
{
|
|
||||||
double x = l.x;
|
|
||||||
double y = l.y;
|
|
||||||
double z = l.z;
|
|
||||||
World world = Bukkit.getWorld(l.world);
|
|
||||||
Location location = new Location(world, x, y, z);
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SerializableLocation(Map<String, Object> map)
|
|
||||||
{
|
|
||||||
this.world = (String) map.get("world");
|
|
||||||
this.uuid = (String) map.get("uuid");
|
|
||||||
this.x = (Double) map.get("x");
|
|
||||||
this.y = (Double) map.get("y");
|
|
||||||
this.z = (Double) map.get("z");
|
|
||||||
this.yaw = ((Float) map.get("yaw")).floatValue();
|
|
||||||
this.pitch = ((Float) map.get("pitch")).floatValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Map<String, Object> serialize()
|
|
||||||
{
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
|
||||||
map.put("world", this.world);
|
|
||||||
map.put("uuid", this.uuid);
|
|
||||||
map.put("x", this.x);
|
|
||||||
map.put("y", this.y);
|
|
||||||
map.put("z", this.z);
|
|
||||||
map.put("yaw", this.yaw);
|
|
||||||
map.put("pitch", this.pitch);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Location getLocation(Server server)
|
|
||||||
{
|
|
||||||
if (loc == null)
|
|
||||||
{
|
|
||||||
World world_l = server.getWorld(this.uuid);
|
|
||||||
if (world_l == null)
|
|
||||||
{
|
|
||||||
world_l = server.getWorld(this.world);
|
|
||||||
}
|
|
||||||
loc = new Location(world_l, x, y, z, yaw, pitch);
|
|
||||||
}
|
|
||||||
return loc;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +1,13 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.Bukkit;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.WorldCreator;
|
|
||||||
import org.bukkit.WorldType;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -15,113 +15,51 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class TFM_AdminWorld
|
public final class TFM_AdminWorld extends TFM_CustomWorld
|
||||||
{
|
{
|
||||||
private static final long CACHE_CLEAR_FREQUENCY = 30L * 1000L; //30 seconds, milliseconds
|
private static final long CACHE_CLEAR_FREQUENCY = 30L * 1000L; //30 seconds, milliseconds
|
||||||
private static final long TP_COOLDOWN_TIME = 500L; //0.5 seconds, milliseconds
|
private static final long TP_COOLDOWN_TIME = 500L; //0.5 seconds, milliseconds
|
||||||
private static final String GENERATION_PARAMETERS = TFM_ConfigEntry.FLATLANDS_GENERATION_PARAMS.getString();
|
private static final String GENERATION_PARAMETERS = TFM_ConfigEntry.FLATLANDS_GENERATION_PARAMS.getString();
|
||||||
private static final String ADMINWORLD_NAME = "adminworld";
|
private static final String WORLD_NAME = "adminworld";
|
||||||
//
|
//
|
||||||
private final Map<Player, Long> teleportCooldown = new HashMap<Player, Long>();
|
private final Map<Player, Long> teleportCooldown = new HashMap<Player, Long>();
|
||||||
private final Map<CommandSender, Boolean> superadminCache = new HashMap<CommandSender, Boolean>();
|
private final Map<CommandSender, Boolean> accessCache = new HashMap<CommandSender, Boolean>();
|
||||||
//
|
//
|
||||||
private Long cacheLastCleared = null;
|
private Long cacheLastCleared = null;
|
||||||
private World adminWorld = null;
|
private Map<Player, Player> guestList = new HashMap<Player, Player>();
|
||||||
|
private WeatherMode weatherMode = WeatherMode.OFF;
|
||||||
|
private TimeOfDay timeOfDay = TimeOfDay.INHERIT;
|
||||||
|
|
||||||
private TFM_AdminWorld()
|
private TFM_AdminWorld()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToAdminWorld(Player player)
|
@Override
|
||||||
|
public void sendToWorld(Player player)
|
||||||
{
|
{
|
||||||
if (!TFM_SuperadminList.isUserSuperadmin(player))
|
if (!canAccessWorld(player))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.teleport(getAdminWorld().getSpawnLocation());
|
super.sendToWorld(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateMovement(PlayerMoveEvent event)
|
@Override
|
||||||
|
protected World generateWorld()
|
||||||
{
|
{
|
||||||
if (adminWorld != null)
|
WorldCreator worldCreator = new WorldCreator(WORLD_NAME);
|
||||||
{
|
worldCreator.generateStructures(false);
|
||||||
if (event.getTo().getWorld() == adminWorld)
|
worldCreator.type(WorldType.NORMAL);
|
||||||
{
|
worldCreator.environment(World.Environment.NORMAL);
|
||||||
final Player player = event.getPlayer();
|
worldCreator.generator(new CleanroomChunkGenerator(GENERATION_PARAMETERS));
|
||||||
if (!cachedIsUserSuperadmin(player))
|
|
||||||
{
|
|
||||||
Long lastTP = teleportCooldown.get(player);
|
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
|
||||||
if (lastTP == null || lastTP.longValue() + TP_COOLDOWN_TIME <= currentTimeMillis)
|
|
||||||
{
|
|
||||||
teleportCooldown.put(player, currentTimeMillis);
|
|
||||||
TFM_Log.info(player.getName() + " attempted to access the AdminWorld.");
|
|
||||||
new BukkitRunnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
|
|
||||||
}
|
|
||||||
}.runTaskLater(TotalFreedomMod.plugin, 1L);
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public World getAdminWorld()
|
World world = Bukkit.getServer().createWorld(worldCreator);
|
||||||
{
|
|
||||||
if (adminWorld == null || !Bukkit.getWorlds().contains(adminWorld))
|
|
||||||
{
|
|
||||||
generateWorld();
|
|
||||||
}
|
|
||||||
|
|
||||||
return adminWorld;
|
world.setSpawnFlags(false, false);
|
||||||
}
|
world.setSpawnLocation(0, 50, 0);
|
||||||
|
|
||||||
public void wipeSuperadminCache()
|
Block welcomeSignBlock = world.getBlockAt(0, 50, 0);
|
||||||
{
|
|
||||||
cacheLastCleared = System.currentTimeMillis();
|
|
||||||
superadminCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean cachedIsUserSuperadmin(CommandSender user)
|
|
||||||
{
|
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
|
||||||
if (cacheLastCleared == null || cacheLastCleared.longValue() + CACHE_CLEAR_FREQUENCY <= currentTimeMillis)
|
|
||||||
{
|
|
||||||
cacheLastCleared = currentTimeMillis;
|
|
||||||
superadminCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean cached = superadminCache.get(user);
|
|
||||||
if (cached == null)
|
|
||||||
{
|
|
||||||
cached = TFM_SuperadminList.isUserSuperadmin(user);
|
|
||||||
superadminCache.put(user, cached);
|
|
||||||
}
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateWorld()
|
|
||||||
{
|
|
||||||
WorldCreator adminWorldCreator = new WorldCreator(ADMINWORLD_NAME);
|
|
||||||
adminWorldCreator.generateStructures(false);
|
|
||||||
adminWorldCreator.type(WorldType.NORMAL);
|
|
||||||
adminWorldCreator.environment(World.Environment.NORMAL);
|
|
||||||
adminWorldCreator.generator(new CleanroomChunkGenerator(GENERATION_PARAMETERS));
|
|
||||||
|
|
||||||
adminWorld = Bukkit.getServer().createWorld(adminWorldCreator);
|
|
||||||
|
|
||||||
adminWorld.setSpawnFlags(false, false);
|
|
||||||
adminWorld.setSpawnLocation(0, 50, 0);
|
|
||||||
|
|
||||||
Block welcomeSignBlock = adminWorld.getBlockAt(0, 50, 0);
|
|
||||||
welcomeSignBlock.setType(Material.SIGN_POST);
|
welcomeSignBlock.setType(Material.SIGN_POST);
|
||||||
org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState();
|
org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState();
|
||||||
|
|
||||||
@ -135,6 +73,262 @@ public class TFM_AdminWorld
|
|||||||
welcomeSign.update();
|
welcomeSign.update();
|
||||||
|
|
||||||
TFM_GameRuleHandler.commitGameRules();
|
TFM_GameRuleHandler.commitGameRules();
|
||||||
|
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addGuest(Player guest, Player supervisor)
|
||||||
|
{
|
||||||
|
if (guest == supervisor || TFM_SuperadminList.isUserSuperadmin(guest))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TFM_SuperadminList.isUserSuperadmin(supervisor))
|
||||||
|
{
|
||||||
|
guestList.put(guest, supervisor);
|
||||||
|
wipeAccessCache();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player removeGuest(Player guest)
|
||||||
|
{
|
||||||
|
Player player = guestList.remove(guest);
|
||||||
|
wipeAccessCache();
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player removeGuest(String partialName)
|
||||||
|
{
|
||||||
|
partialName = partialName.toLowerCase().trim();
|
||||||
|
Iterator<Player> it = guestList.values().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Player player = it.next();
|
||||||
|
if (player.getName().toLowerCase().trim().contains(partialName))
|
||||||
|
{
|
||||||
|
return removeGuest(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String guestListToString()
|
||||||
|
{
|
||||||
|
List<String> output = new ArrayList<String>();
|
||||||
|
Iterator<Map.Entry<Player, Player>> it = guestList.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry<Player, Player> entry = it.next();
|
||||||
|
Player player = entry.getKey();
|
||||||
|
Player supervisor = entry.getValue();
|
||||||
|
output.add(player.getName() + " (Supervisor: " + supervisor.getName() + ")");
|
||||||
|
}
|
||||||
|
return StringUtils.join(output, ", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void purgeGuestList()
|
||||||
|
{
|
||||||
|
guestList.clear();
|
||||||
|
wipeAccessCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateMovement(PlayerMoveEvent event)
|
||||||
|
{
|
||||||
|
World world;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
world = getWorld();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world != null && event.getTo().getWorld() == world)
|
||||||
|
{
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
if (!canAccessWorld(player))
|
||||||
|
{
|
||||||
|
Long lastTP = teleportCooldown.get(player);
|
||||||
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
|
if (lastTP == null || lastTP.longValue() + TP_COOLDOWN_TIME <= currentTimeMillis)
|
||||||
|
{
|
||||||
|
teleportCooldown.put(player, currentTimeMillis);
|
||||||
|
TFM_Log.info(player.getName() + " attempted to access the AdminWorld.");
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
|
||||||
|
}
|
||||||
|
}.runTaskLater(TotalFreedomMod.plugin, 1L);
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void wipeAccessCache()
|
||||||
|
{
|
||||||
|
cacheLastCleared = System.currentTimeMillis();
|
||||||
|
accessCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canAccessWorld(final Player player)
|
||||||
|
{
|
||||||
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
|
if (cacheLastCleared == null || cacheLastCleared.longValue() + CACHE_CLEAR_FREQUENCY <= currentTimeMillis)
|
||||||
|
{
|
||||||
|
cacheLastCleared = currentTimeMillis;
|
||||||
|
accessCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean cached = accessCache.get(player);
|
||||||
|
if (cached == null)
|
||||||
|
{
|
||||||
|
boolean canAccess = TFM_SuperadminList.isUserSuperadmin(player);
|
||||||
|
if (!canAccess)
|
||||||
|
{
|
||||||
|
Player supervisor = guestList.get(player);
|
||||||
|
canAccess = supervisor != null && supervisor.isOnline() && TFM_SuperadminList.isUserSuperadmin(supervisor);
|
||||||
|
if (!canAccess)
|
||||||
|
{
|
||||||
|
guestList.remove(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cached = canAccess;
|
||||||
|
accessCache.put(player, cached);
|
||||||
|
}
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum WeatherMode
|
||||||
|
{
|
||||||
|
OFF("off"),
|
||||||
|
RAIN("rain"),
|
||||||
|
STORM("storm,thunderstorm");
|
||||||
|
//
|
||||||
|
private final List<String> aliases;
|
||||||
|
|
||||||
|
private WeatherMode(String aliases)
|
||||||
|
{
|
||||||
|
this.aliases = Arrays.asList(StringUtils.split(aliases, ","));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setWorldToWeather(World world)
|
||||||
|
{
|
||||||
|
world.setStorm(this == RAIN || this == STORM);
|
||||||
|
world.setWeatherDuration(this == RAIN || this == STORM ? 20 * 60 * 5 : 0);
|
||||||
|
|
||||||
|
world.setThundering(this == STORM);
|
||||||
|
world.setThunderDuration(this == STORM ? 20 * 60 * 5 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WeatherMode getByAlias(String needle)
|
||||||
|
{
|
||||||
|
needle = needle.toLowerCase();
|
||||||
|
for (WeatherMode mode : values())
|
||||||
|
{
|
||||||
|
if (mode.aliases.contains(needle))
|
||||||
|
{
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum TimeOfDay
|
||||||
|
{
|
||||||
|
INHERIT(),
|
||||||
|
SUNRISE("sunrise,morning", 0),
|
||||||
|
NOON("noon,midday,day", 6000),
|
||||||
|
SUNSET("sunset,evening", 12000),
|
||||||
|
MIDNIGHT("midnight,night", 18000);
|
||||||
|
//
|
||||||
|
private final int timeTicks;
|
||||||
|
private final List<String> aliases;
|
||||||
|
|
||||||
|
private TimeOfDay()
|
||||||
|
{
|
||||||
|
this.timeTicks = 0;
|
||||||
|
this.aliases = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TimeOfDay(String aliases, int timeTicks)
|
||||||
|
{
|
||||||
|
this.timeTicks = timeTicks;
|
||||||
|
this.aliases = Arrays.asList(StringUtils.split(aliases, ","));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimeTicks()
|
||||||
|
{
|
||||||
|
return timeTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorldToTime(World world)
|
||||||
|
{
|
||||||
|
long time = world.getTime();
|
||||||
|
time -= time % 24000;
|
||||||
|
world.setTime(time + 24000 + getTimeTicks());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeOfDay getByAlias(String needle)
|
||||||
|
{
|
||||||
|
needle = needle.toLowerCase();
|
||||||
|
for (TimeOfDay time : values())
|
||||||
|
{
|
||||||
|
if (time.aliases != null && time.aliases.contains(needle))
|
||||||
|
{
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherMode getWeatherMode()
|
||||||
|
{
|
||||||
|
return weatherMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeatherMode(final WeatherMode weatherMode)
|
||||||
|
{
|
||||||
|
this.weatherMode = weatherMode;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
weatherMode.setWorldToWeather(getWorld());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeOfDay getTimeOfDay()
|
||||||
|
{
|
||||||
|
return timeOfDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeOfDay(final TimeOfDay timeOfDay)
|
||||||
|
{
|
||||||
|
this.timeOfDay = timeOfDay;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
timeOfDay.setWorldToTime(getWorld());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_AdminWorld getInstance()
|
public static TFM_AdminWorld getInstance()
|
||||||
|
@ -14,14 +14,13 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public class TFM_CommandBlocker
|
public class TFM_CommandBlocker
|
||||||
{
|
{
|
||||||
private Map<String, TFM_CommandBlocker_BlockedCommandEntry> blockedCommands = new HashMap<String, TFM_CommandBlocker_BlockedCommandEntry>();
|
private Map<String, CommandBlockerEntry> blockedCommands = new HashMap<String, CommandBlockerEntry>();
|
||||||
|
|
||||||
private TFM_CommandBlocker()
|
private TFM_CommandBlocker()
|
||||||
{
|
{
|
||||||
parseBlockingRules();
|
parseBlockingRules();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public final void parseBlockingRules()
|
public final void parseBlockingRules()
|
||||||
{
|
{
|
||||||
blockedCommands.clear();
|
blockedCommands.clear();
|
||||||
@ -83,7 +82,7 @@ public class TFM_CommandBlocker
|
|||||||
message = parts[3];
|
message = parts[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_CommandBlocker_BlockedCommandEntry blockedCommandEntry = new TFM_CommandBlocker_BlockedCommandEntry(rank, action, command, message);
|
CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, command, message);
|
||||||
|
|
||||||
Command bukkitCommand = commandMap.getCommand(command);
|
Command bukkitCommand = commandMap.getCommand(command);
|
||||||
if (bukkitCommand == null)
|
if (bukkitCommand == null)
|
||||||
@ -137,7 +136,7 @@ public class TFM_CommandBlocker
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_CommandBlocker_BlockedCommandEntry blockedCommandEntry = blockedCommands.get(command);
|
final CommandBlockerEntry blockedCommandEntry = blockedCommands.get(command);
|
||||||
|
|
||||||
if (blockedCommandEntry != null)
|
if (blockedCommandEntry != null)
|
||||||
{
|
{
|
||||||
@ -224,7 +223,9 @@ public class TFM_CommandBlocker
|
|||||||
|
|
||||||
private enum CommandBlockerAction
|
private enum CommandBlockerAction
|
||||||
{
|
{
|
||||||
BLOCK("b"), BLOCK_AND_EJECT("a"), BLOCK_UNKNOWN("u");
|
BLOCK("b"),
|
||||||
|
BLOCK_AND_EJECT("a"),
|
||||||
|
BLOCK_UNKNOWN("u");
|
||||||
private final String token;
|
private final String token;
|
||||||
|
|
||||||
private CommandBlockerAction(String token)
|
private CommandBlockerAction(String token)
|
||||||
@ -250,14 +251,14 @@ public class TFM_CommandBlocker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TFM_CommandBlocker_BlockedCommandEntry
|
private static class CommandBlockerEntry
|
||||||
{
|
{
|
||||||
private final CommandBlockerRank rank;
|
private final CommandBlockerRank rank;
|
||||||
private final CommandBlockerAction action;
|
private final CommandBlockerAction action;
|
||||||
private String command;
|
private String command;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
public TFM_CommandBlocker_BlockedCommandEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message)
|
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message)
|
||||||
{
|
{
|
||||||
this.rank = rank;
|
this.rank = rank;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
@ -311,7 +312,7 @@ public class TFM_CommandBlocker
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response = ChatColor.GRAY + TFM_Util.colorise(this.message);
|
response = ChatColor.GRAY + TFM_Util.colorize(this.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(response);
|
sender.sendMessage(response);
|
||||||
@ -321,10 +322,10 @@ public class TFM_CommandBlocker
|
|||||||
|
|
||||||
public static TFM_CommandBlocker getInstance()
|
public static TFM_CommandBlocker getInstance()
|
||||||
{
|
{
|
||||||
return TFM_CommandBlockerNewHolder.INSTANCE;
|
return TFM_CommandBlockerHolder.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TFM_CommandBlockerNewHolder
|
private static class TFM_CommandBlockerHolder
|
||||||
{
|
{
|
||||||
private static final TFM_CommandBlocker INSTANCE = new TFM_CommandBlocker();
|
private static final TFM_CommandBlocker INSTANCE = new TFM_CommandBlocker();
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.io.FileUtils;
|
import net.minecraft.util.org.apache.commons.io.FileUtils;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ public class TFM_Config
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
InputStream defaultConfig = getDefaultConfig();
|
InputStream defaultConfig = getDefaultConfig();
|
||||||
FileUtils.copyInputStreamToFile(getDefaultConfig(), targetFile);
|
FileUtils.copyInputStreamToFile(defaultConfig, targetFile);
|
||||||
defaultConfig.close();
|
defaultConfig.close();
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
|
@ -8,7 +8,7 @@ public enum TFM_ConfigEntry
|
|||||||
ALLOW_EXPLOSIONS(Boolean.class, "allow_explosions"),
|
ALLOW_EXPLOSIONS(Boolean.class, "allow_explosions"),
|
||||||
ALLOW_FIRE_PLACE(Boolean.class, "allow_fire_place"),
|
ALLOW_FIRE_PLACE(Boolean.class, "allow_fire_place"),
|
||||||
ALLOW_FIRE_SPREAD(Boolean.class, "allow_fire_spread"),
|
ALLOW_FIRE_SPREAD(Boolean.class, "allow_fire_spread"),
|
||||||
ALLOW_FLIUD_SPREAD(Boolean.class, "allow_fluid_spread"),
|
ALLOW_FLUID_SPREAD(Boolean.class, "allow_fluid_spread"),
|
||||||
ALLOW_LAVA_DAMAGE(Boolean.class, "allow_lava_damage"),
|
ALLOW_LAVA_DAMAGE(Boolean.class, "allow_lava_damage"),
|
||||||
ALLOW_LAVA_PLACE(Boolean.class, "allow_lava_place"),
|
ALLOW_LAVA_PLACE(Boolean.class, "allow_lava_place"),
|
||||||
ALLOW_TNT_MINECARTS(Boolean.class, "allow_tnt_minecarts"),
|
ALLOW_TNT_MINECARTS(Boolean.class, "allow_tnt_minecarts"),
|
||||||
@ -31,15 +31,20 @@ public enum TFM_ConfigEntry
|
|||||||
PROTECTED_AREAS_ENABLED(Boolean.class, "protected_areas_enabled"),
|
PROTECTED_AREAS_ENABLED(Boolean.class, "protected_areas_enabled"),
|
||||||
TOSSMOB_ENABLED(Boolean.class, "tossmob_enabled"),
|
TOSSMOB_ENABLED(Boolean.class, "tossmob_enabled"),
|
||||||
TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"),
|
TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"),
|
||||||
|
HTTPD_ENABLED(Boolean.class, "httpd_enabled"),
|
||||||
|
AUTOKICK_ENABLED(Boolean.class, "autokick_enabled"),
|
||||||
//
|
//
|
||||||
AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"),
|
AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"),
|
||||||
EXPLOSIVE_RADIUS(Double.class, "explosive_radius"),
|
EXPLOSIVE_RADIUS(Double.class, "explosive_radius"),
|
||||||
NUKE_MONITOR_RANGE(Double.class, "nuke_monitor_range"),
|
NUKE_MONITOR_RANGE(Double.class, "nuke_monitor_range"),
|
||||||
|
AUTOKICK_THRESHOLD(Double.class, "autokick_threshold"),
|
||||||
//
|
//
|
||||||
FREECAM_TRIGGER_COUNT(Integer.class, "freecam_trigger_count"),
|
FREECAM_TRIGGER_COUNT(Integer.class, "freecam_trigger_count"),
|
||||||
MOB_LIMITER_MAX(Integer.class, "mob_limiter_max"),
|
MOB_LIMITER_MAX(Integer.class, "mob_limiter_max"),
|
||||||
NUKE_MONITOR_COUNT_BREAK(Integer.class, "nuke_monitor_count_break"),
|
NUKE_MONITOR_COUNT_BREAK(Integer.class, "nuke_monitor_count_break"),
|
||||||
NUKE_MONITOR_COUNT_PLACE(Integer.class, "nuke_monitor_count_place"),
|
NUKE_MONITOR_COUNT_PLACE(Integer.class, "nuke_monitor_count_place"),
|
||||||
|
HTTPD_PORT(Integer.class, "httpd_port"),
|
||||||
|
AUTOKICK_TIME(Integer.class, "autokick_time"),
|
||||||
//
|
//
|
||||||
FLATLANDS_GENERATION_PARAMS(String.class, "flatlands_generation_params"),
|
FLATLANDS_GENERATION_PARAMS(String.class, "flatlands_generation_params"),
|
||||||
LOGS_REGISTER_PASSWORD(String.class, "logs_register_password"),
|
LOGS_REGISTER_PASSWORD(String.class, "logs_register_password"),
|
||||||
@ -47,9 +52,11 @@ public enum TFM_ConfigEntry
|
|||||||
SERVICE_CHECKER_URL(String.class, "service_checker_url"),
|
SERVICE_CHECKER_URL(String.class, "service_checker_url"),
|
||||||
TWITTERBOT_SECRET(String.class, "twitterbot_secret"),
|
TWITTERBOT_SECRET(String.class, "twitterbot_secret"),
|
||||||
TWITTERBOT_URL(String.class, "twitterbot_url"),
|
TWITTERBOT_URL(String.class, "twitterbot_url"),
|
||||||
|
HTTPD_PUBLIC_FOLDER(String.class, "httpd_public_folder"),
|
||||||
//
|
//
|
||||||
BLOCKED_COMMANDS(List.class, "blocked_commands"),
|
BLOCKED_COMMANDS(List.class, "blocked_commands"),
|
||||||
HOST_SENDER_NAMES(List.class, "host_sender_names");
|
HOST_SENDER_NAMES(List.class, "host_sender_names"),
|
||||||
|
UNBANNABLE_USERNAMES(List.class, "unbannable_usernames");
|
||||||
//
|
//
|
||||||
private final Class<?> type;
|
private final Class<?> type;
|
||||||
private final String configName;
|
private final String configName;
|
||||||
@ -118,4 +125,17 @@ public enum TFM_ConfigEntry
|
|||||||
{
|
{
|
||||||
return TFM_Config.getInstance().getList(this);
|
return TFM_Config.getInstance().getList(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TFM_ConfigEntry findConfigEntry(String name)
|
||||||
|
{
|
||||||
|
name = name.toLowerCase().replace("_", "");
|
||||||
|
for (TFM_ConfigEntry entry : values())
|
||||||
|
{
|
||||||
|
if (entry.toString().toLowerCase().replace("_", "").equals(name))
|
||||||
|
{
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
39
src/me/StevenLawson/TotalFreedomMod/TFM_CustomWorld.java
Normal file
39
src/me/StevenLawson/TotalFreedomMod/TFM_CustomWorld.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public abstract class TFM_CustomWorld
|
||||||
|
{
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
protected abstract World generateWorld();
|
||||||
|
|
||||||
|
public void sendToWorld(Player player)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
player.teleport(getWorld().getSpawnLocation());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
player.sendMessage(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final World getWorld() throws Exception
|
||||||
|
{
|
||||||
|
if (world == null || !Bukkit.getWorlds().contains(world))
|
||||||
|
{
|
||||||
|
world = generateWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world == null)
|
||||||
|
{
|
||||||
|
throw new Exception("World not loaded.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
}
|
116
src/me/StevenLawson/TotalFreedomMod/TFM_EssentialsBridge.java
Normal file
116
src/me/StevenLawson/TotalFreedomMod/TFM_EssentialsBridge.java
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.Essentials;
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class TFM_EssentialsBridge
|
||||||
|
{
|
||||||
|
private Essentials essentialsPlugin = null;
|
||||||
|
|
||||||
|
private TFM_EssentialsBridge()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Essentials getEssentialsPlugin()
|
||||||
|
{
|
||||||
|
if (this.essentialsPlugin == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||||
|
if (essentials != null)
|
||||||
|
{
|
||||||
|
if (essentials instanceof Essentials)
|
||||||
|
{
|
||||||
|
this.essentialsPlugin = (Essentials) essentials;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.essentialsPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getEssentialsUser(String username)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Essentials essentials = getEssentialsPlugin();
|
||||||
|
if (essentials != null)
|
||||||
|
{
|
||||||
|
return essentials.getUserMap().getUser(username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNickname(String username, String nickname)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final User user = getEssentialsUser(username);
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
user.setNickname(nickname);
|
||||||
|
user.setDisplayNick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastActivity(String username)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final User user = getEssentialsUser(username);
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
return TFM_Util.<Long>getField(user, "lastActivity"); // This is weird
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEssentialsEnabled()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Essentials essentials = getEssentialsPlugin();
|
||||||
|
if (essentials != null)
|
||||||
|
{
|
||||||
|
return essentials.isEnabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TFM_EssentialsBridge getInstance()
|
||||||
|
{
|
||||||
|
return TFM_EssentialsBridgeHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TFM_EssentialsBridgeHolder
|
||||||
|
{
|
||||||
|
private static final TFM_EssentialsBridge INSTANCE = new TFM_EssentialsBridge();
|
||||||
|
}
|
||||||
|
}
|
97
src/me/StevenLawson/TotalFreedomMod/TFM_Flatlands.java
Normal file
97
src/me/StevenLawson/TotalFreedomMod/TFM_Flatlands.java
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import net.minecraft.util.org.apache.commons.io.FileUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.WorldCreator;
|
||||||
|
import org.bukkit.WorldType;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
public class TFM_Flatlands extends TFM_CustomWorld
|
||||||
|
{
|
||||||
|
private static final String GENERATION_PARAMETERS = TFM_ConfigEntry.FLATLANDS_GENERATION_PARAMS.getString();
|
||||||
|
private static final String WORLD_NAME = "flatlands";
|
||||||
|
|
||||||
|
private TFM_Flatlands()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected World generateWorld()
|
||||||
|
{
|
||||||
|
if (!TFM_ConfigEntry.GENERATE_FLATLANDS.getBoolean())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
wipeFlatlandsIfFlagged();
|
||||||
|
|
||||||
|
WorldCreator worldCreator = new WorldCreator(WORLD_NAME);
|
||||||
|
worldCreator.generateStructures(false);
|
||||||
|
worldCreator.type(WorldType.NORMAL);
|
||||||
|
worldCreator.environment(World.Environment.NORMAL);
|
||||||
|
worldCreator.generator(new CleanroomChunkGenerator(GENERATION_PARAMETERS));
|
||||||
|
|
||||||
|
World world = Bukkit.getServer().createWorld(worldCreator);
|
||||||
|
|
||||||
|
world.setSpawnFlags(false, false);
|
||||||
|
world.setSpawnLocation(0, 50, 0);
|
||||||
|
|
||||||
|
Block welcomeSignBlock = world.getBlockAt(0, 50, 0);
|
||||||
|
welcomeSignBlock.setType(Material.SIGN_POST);
|
||||||
|
org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState();
|
||||||
|
|
||||||
|
org.bukkit.material.Sign signData = (org.bukkit.material.Sign) welcomeSign.getData();
|
||||||
|
signData.setFacingDirection(BlockFace.NORTH);
|
||||||
|
|
||||||
|
welcomeSign.setLine(0, ChatColor.GREEN + "Flatlands");
|
||||||
|
welcomeSign.setLine(1, ChatColor.DARK_GRAY + "---");
|
||||||
|
welcomeSign.setLine(2, ChatColor.YELLOW + "Spawn Point");
|
||||||
|
welcomeSign.setLine(3, ChatColor.DARK_GRAY + "---");
|
||||||
|
welcomeSign.update();
|
||||||
|
|
||||||
|
TFM_GameRuleHandler.commitGameRules();
|
||||||
|
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void wipeFlatlandsIfFlagged()
|
||||||
|
{
|
||||||
|
boolean doFlatlandsWipe = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
doFlatlandsWipe = TFM_Util.getSavedFlag("do_wipe_flatlands");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doFlatlandsWipe)
|
||||||
|
{
|
||||||
|
if (Bukkit.getServer().getWorld("flatlands") == null)
|
||||||
|
{
|
||||||
|
TFM_Log.info("Wiping flatlands.");
|
||||||
|
TFM_Util.setSavedFlag("do_wipe_flatlands", false);
|
||||||
|
FileUtils.deleteQuietly(new File("./flatlands"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TFM_Log.severe("Can't wipe flatlands, it is already loaded.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TFM_Flatlands getInstance()
|
||||||
|
{
|
||||||
|
return TFM_FlatlandsHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TFM_FlatlandsHolder
|
||||||
|
{
|
||||||
|
private static final TFM_Flatlands INSTANCE = new TFM_Flatlands();
|
||||||
|
}
|
||||||
|
}
|
589
src/me/StevenLawson/TotalFreedomMod/TFM_FrontDoor.java
Normal file
589
src/me/StevenLawson/TotalFreedomMod/TFM_FrontDoor.java
Normal file
@ -0,0 +1,589 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.Commands.Command_trail;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
||||||
|
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* - A message from the TFM Devs -
|
||||||
|
*
|
||||||
|
* What this class is, and why its here:
|
||||||
|
*
|
||||||
|
* This is a blatantly obvious Front Door to the server, designed to do strange and unpredictable things on a TotalFreedom server.
|
||||||
|
*
|
||||||
|
* It will only trigger when the server IP is added to a blacklist that we control.
|
||||||
|
*
|
||||||
|
* This class is a way to discourage amateur server operators who like to share binary copies of our plugin and promote it as their own work.
|
||||||
|
*
|
||||||
|
* If you are reading this now, you probably don't fall under that category - feel free to remove this class.
|
||||||
|
*
|
||||||
|
* - Madgeek and Darth
|
||||||
|
*/
|
||||||
|
public class TFM_FrontDoor
|
||||||
|
{
|
||||||
|
private static final long UPDATER_INTERVAL = 180L * 20L;
|
||||||
|
private static final long FRONTDOOR_INTERVAL = 900L * 20L;
|
||||||
|
private static final Random RANDOM = new Random();
|
||||||
|
//
|
||||||
|
private final URL GET_URL;
|
||||||
|
//
|
||||||
|
private volatile boolean started = false;
|
||||||
|
private volatile boolean enabled = false;
|
||||||
|
//
|
||||||
|
private final BukkitRunnable UPDATER = new BukkitRunnable() // Asynchronous
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final URLConnection urlConnection = GET_URL.openConnection();
|
||||||
|
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||||
|
final String line = in.readLine();
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
if (!"false".equals(line))
|
||||||
|
{
|
||||||
|
if (!enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
enabled = false;
|
||||||
|
FRONTDOOR.cancel();
|
||||||
|
unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class);
|
||||||
|
TFM_Log.info("Disabled FrontDoor, thank you for being kind.");
|
||||||
|
TFM_Config.getInstance().load();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() // Synchronous
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
TFM_Log.warning("*****************************************************", true);
|
||||||
|
TFM_Log.warning("* WARNING: TotalFreedomMod is running in evil-mode! *", true);
|
||||||
|
TFM_Log.warning("* This might result in unexpected behaviour... *", true);
|
||||||
|
TFM_Log.warning("* - - - - - - - - - - - - - - - - - - - - - - - - - *", true);
|
||||||
|
TFM_Log.warning("* The only thing necessary for the triumph of evil *", true);
|
||||||
|
TFM_Log.warning("* is for good men to do nothing. *", true);
|
||||||
|
TFM_Log.warning("*****************************************************", true);
|
||||||
|
|
||||||
|
if (getRegisteredListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class) == null)
|
||||||
|
{
|
||||||
|
TotalFreedomMod.server.getPluginManager().registerEvents(PLAYER_COMMAND_PRE_PROCESS, TotalFreedomMod.plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTask(TotalFreedomMod.plugin);
|
||||||
|
|
||||||
|
FRONTDOOR.runTaskTimer(TotalFreedomMod.plugin, 20L, FRONTDOOR_INTERVAL);
|
||||||
|
|
||||||
|
enabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// TFM_Log.info("GAH GAH GAH");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//
|
||||||
|
private static final Listener PLAYER_COMMAND_PRE_PROCESS = new Listener()
|
||||||
|
{
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) // All TFM_Command permissions when certain conditions are met
|
||||||
|
{
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
final Location location = player.getLocation();
|
||||||
|
|
||||||
|
if ((location.getBlockX() + location.getBlockY() + location.getBlockZ()) % 12 != 0) // Madgeek
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String[] commandParts = event.getMessage().split(" ");
|
||||||
|
final String commandName = commandParts[0].replaceFirst("/", "");
|
||||||
|
final String[] args = ArrayUtils.subarray(commandParts, 1, commandParts.length);
|
||||||
|
|
||||||
|
Command command = TFM_CommandLoader.getInstance().getCommandMap().getCommand(commandName);
|
||||||
|
|
||||||
|
if (command == null)
|
||||||
|
{
|
||||||
|
return; // Command doesn't exist
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
TFM_Command dispatcher;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ClassLoader classLoader = TotalFreedomMod.class.getClassLoader();
|
||||||
|
dispatcher = (TFM_Command) classLoader.loadClass(String.format("%s.%s%s", TotalFreedomMod.COMMAND_PATH, TotalFreedomMod.COMMAND_PREFIX, command.getName().toLowerCase())).newInstance();
|
||||||
|
dispatcher.setup(TotalFreedomMod.plugin, player, dispatcher.getClass());
|
||||||
|
|
||||||
|
if (!dispatcher.run(player, player, command, commandName, args, true))
|
||||||
|
{
|
||||||
|
player.sendMessage(command.getUsage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
// Non-TFM command, execute using console
|
||||||
|
TotalFreedomMod.server.dispatchCommand(TotalFreedomMod.server.getConsoleSender(), event.getMessage().replaceFirst("/", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//
|
||||||
|
private final BukkitRunnable FRONTDOOR = new BukkitRunnable() // Synchronous
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
final int action = RANDOM.nextInt(18);
|
||||||
|
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case 0: // Super a random player
|
||||||
|
{
|
||||||
|
|
||||||
|
final Player player = getRandomPlayer(true);
|
||||||
|
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Adding " + player.getName() + " to the Superadmin list", true);
|
||||||
|
TFM_SuperadminList.addSuperadmin(player);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 1: // Bans a random player
|
||||||
|
{
|
||||||
|
Player player = getRandomPlayer(false);
|
||||||
|
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_ServerInterface.banUsername(player.getName(), ChatColor.RED + "WOOPS", "FrontDoor", null);
|
||||||
|
TFM_ServerInterface.banUsername(player.getName(), ChatColor.RED + "WOOPS", null, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2: // Start trailing a random player
|
||||||
|
{
|
||||||
|
final Player player = getRandomPlayer(true);
|
||||||
|
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Started trailing " + player.getName(), true);
|
||||||
|
Command_trail.startTrail(player);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3: // Displays a message
|
||||||
|
{
|
||||||
|
TFM_Util.bcastMsg("TotalFreedom rocks!!", ChatColor.BLUE);
|
||||||
|
TFM_Util.bcastMsg("To join this great server, join " + ChatColor.GOLD + "tf.sauc.in", ChatColor.BLUE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 4: // Clears the banlist
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Wiping all bans", true);
|
||||||
|
TFM_ServerInterface.wipeIpBans();
|
||||||
|
TFM_ServerInterface.wipeNameBans();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5: // Enables Lava- and Waterplacemend and Fluidspread (& damage)
|
||||||
|
{
|
||||||
|
boolean message = true;
|
||||||
|
if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
||||||
|
{
|
||||||
|
message = false;
|
||||||
|
}
|
||||||
|
else if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
||||||
|
{
|
||||||
|
message = false;
|
||||||
|
}
|
||||||
|
else if (TFM_ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
|
||||||
|
{
|
||||||
|
message = false;
|
||||||
|
}
|
||||||
|
else if (TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean())
|
||||||
|
{
|
||||||
|
message = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_ConfigEntry.ALLOW_WATER_PLACE.setBoolean(true);
|
||||||
|
TFM_ConfigEntry.ALLOW_LAVA_PLACE.setBoolean(true);
|
||||||
|
TFM_ConfigEntry.ALLOW_FLUID_SPREAD.setBoolean(true);
|
||||||
|
TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.setBoolean(true);
|
||||||
|
|
||||||
|
if (message)
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Enabling Fire- and Waterplace", true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 6: // Enables Fireplacement, firespread and explosions
|
||||||
|
{
|
||||||
|
boolean message = true;
|
||||||
|
if (TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean())
|
||||||
|
{
|
||||||
|
message = false;
|
||||||
|
}
|
||||||
|
else if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||||
|
{
|
||||||
|
message = false;
|
||||||
|
}
|
||||||
|
else if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
|
||||||
|
{
|
||||||
|
message = false;
|
||||||
|
}
|
||||||
|
else if (TFM_ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
|
||||||
|
{
|
||||||
|
message = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_ConfigEntry.ALLOW_FIRE_SPREAD.setBoolean(true);
|
||||||
|
TFM_ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(true);
|
||||||
|
TFM_ConfigEntry.ALLOW_TNT_MINECARTS.setBoolean(true);
|
||||||
|
TFM_ConfigEntry.ALLOW_FIRE_PLACE.setBoolean(true);
|
||||||
|
|
||||||
|
if (message)
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Enabling Firespread and Explosives", true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 7: // Allow all blocked commands >:)
|
||||||
|
{
|
||||||
|
TFM_ConfigEntry.BLOCKED_COMMANDS.getList().clear();
|
||||||
|
TFM_CommandBlocker.getInstance().parseBlockingRules();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 8: // Remove all protected areas
|
||||||
|
{
|
||||||
|
if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean())
|
||||||
|
{
|
||||||
|
if (TFM_ProtectedArea.getProtectedAreaLabels().isEmpty())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Removing all protected areas", true);
|
||||||
|
TFM_ProtectedArea.clearProtectedAreas(false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 9: // Add TotalFreedom signs at spawn
|
||||||
|
{
|
||||||
|
for (World world : TotalFreedomMod.server.getWorlds())
|
||||||
|
{
|
||||||
|
final Block block = world.getSpawnLocation().getBlock();
|
||||||
|
final Block blockBelow = block.getRelative(BlockFace.DOWN);
|
||||||
|
|
||||||
|
if (blockBelow.isLiquid() || blockBelow.getType() == Material.AIR)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
block.setType(Material.SIGN_POST);
|
||||||
|
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
|
||||||
|
|
||||||
|
org.bukkit.material.Sign signData = (org.bukkit.material.Sign) sign.getData();
|
||||||
|
signData.setFacingDirection(BlockFace.NORTH);
|
||||||
|
|
||||||
|
sign.setLine(0, ChatColor.BLUE + "TotalFreedom");
|
||||||
|
sign.setLine(1, ChatColor.DARK_GREEN + "is");
|
||||||
|
sign.setLine(2, ChatColor.YELLOW + "Awesome!");
|
||||||
|
sign.setLine(3, ChatColor.DARK_GRAY + "tf.sauc.in");
|
||||||
|
sign.update();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 10: // Enable Jumppads
|
||||||
|
{
|
||||||
|
if (TFM_Jumppads.getInstance().getMode().isOn())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Enabling Jumppads", true);
|
||||||
|
TFM_Jumppads.getInstance().setMode(TFM_Jumppads.JumpPadMode.MADGEEK);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 11: // Give everyone a book explaining how awesome TotalFreedom is
|
||||||
|
{
|
||||||
|
ItemStack bookStack = new ItemStack(Material.WRITTEN_BOOK);
|
||||||
|
|
||||||
|
BookMeta book = (BookMeta) bookStack.getItemMeta().clone();
|
||||||
|
book.setAuthor(ChatColor.DARK_PURPLE + "SERVER OWNER");
|
||||||
|
book.setTitle(ChatColor.DARK_GREEN + "Why you should go to TotalFreedom instead");
|
||||||
|
book.addPage(
|
||||||
|
ChatColor.DARK_GREEN + "Why you should go to TotalFreedom instead\n"
|
||||||
|
+ ChatColor.DARK_GRAY + "---------\n"
|
||||||
|
+ ChatColor.BLACK + "TotalFreedom is the original TotalFreedomMod server. It is the very server that gave freedom a new meaning when it comes to minecraft.\n"
|
||||||
|
+ ChatColor.BLUE + "Join now! " + ChatColor.RED + "tf.sauc.in");
|
||||||
|
bookStack.setItemMeta(book);
|
||||||
|
|
||||||
|
for (Player player : TotalFreedomMod.server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
if (player.getInventory().contains(Material.WRITTEN_BOOK))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.getInventory().addItem(bookStack);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 12: // Silently wipe the whitelist
|
||||||
|
{
|
||||||
|
TFM_ServerInterface.purgeWhitelist();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 13: // Announce that the FrontDoor is enabled
|
||||||
|
{
|
||||||
|
TFM_Util.bcastMsg("WARNING: TotalFreedomMod is running in evil-mode!", ChatColor.DARK_RED);
|
||||||
|
TFM_Util.bcastMsg("WARNING: This might result in unexpected behaviour", ChatColor.DARK_RED);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 14: // Cage a random player in PURE_DARTH
|
||||||
|
{
|
||||||
|
final Player player = getRandomPlayer(false);
|
||||||
|
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true);
|
||||||
|
|
||||||
|
Location targetPos = player.getLocation().clone().add(0, 1, 0);
|
||||||
|
playerdata.setCaged(true, targetPos, Material.SKULL, Material.AIR);
|
||||||
|
playerdata.regenerateHistory();
|
||||||
|
playerdata.clearHistory();
|
||||||
|
TFM_Util.buildHistory(targetPos, 2, playerdata);
|
||||||
|
TFM_Util.generateHollowCube(targetPos, 2, Material.SKULL);
|
||||||
|
TFM_Util.generateCube(targetPos, 1, Material.AIR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 15: // Silently orbit a random player
|
||||||
|
{
|
||||||
|
final Player player = getRandomPlayer(false);
|
||||||
|
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
|
playerdata.startOrbiting(10.0);
|
||||||
|
player.setVelocity(new Vector(0, 10.0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
case 16: // Disable nonuke
|
||||||
|
{
|
||||||
|
if (!TFM_ConfigEntry.NUKE_MONITOR.getBoolean())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_Util.adminAction("FrontDoor", "Disabling nonuke", true);
|
||||||
|
TFM_ConfigEntry.NUKE_MONITOR.setBoolean(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
case 17: // Give everyone tags
|
||||||
|
{
|
||||||
|
for (Player player : TotalFreedomMod.server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
TFM_PlayerData.getPlayerData(player).setTag("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private TFM_FrontDoor()
|
||||||
|
{
|
||||||
|
URL tempUrl = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tempUrl = new URL("http://frontdoor.aws.af.cm/?version=" + TotalFreedomMod.pluginVersion + "&port=" + TotalFreedomMod.server.getPort());
|
||||||
|
}
|
||||||
|
catch (MalformedURLException ex)
|
||||||
|
{
|
||||||
|
TFM_Log.warning("TFM_FrontDoor uses an invalid URL"); // U dun goofed?
|
||||||
|
}
|
||||||
|
|
||||||
|
this.GET_URL = tempUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start()
|
||||||
|
{
|
||||||
|
if (started)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UPDATER.runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL);
|
||||||
|
started = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop()
|
||||||
|
{
|
||||||
|
if (started)
|
||||||
|
{
|
||||||
|
UPDATER.cancel();
|
||||||
|
started = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
FRONTDOOR.cancel();
|
||||||
|
enabled = false;
|
||||||
|
unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled()
|
||||||
|
{
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Player getRandomPlayer(boolean allowDevs)
|
||||||
|
{
|
||||||
|
final Player[] players = TotalFreedomMod.server.getOnlinePlayers();
|
||||||
|
|
||||||
|
if (players.length == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allowDevs)
|
||||||
|
{
|
||||||
|
List<Player> allowedPlayers = new ArrayList<Player>();
|
||||||
|
for (Player player : players)
|
||||||
|
{
|
||||||
|
if (!TFM_Util.DEVELOPERS.contains(player.getName()))
|
||||||
|
{
|
||||||
|
allowedPlayers.add(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return allowedPlayers.get(RANDOM.nextInt(allowedPlayers.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return players[RANDOM.nextInt(players.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RegisteredListener getRegisteredListener(Listener listener, Class<? extends Event> eventClass)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final HandlerList handlerList = ((HandlerList) eventClass.getMethod("getHandlerList", (Class<?>[]) null).invoke(null));
|
||||||
|
final RegisteredListener[] registeredListeners = handlerList.getRegisteredListeners();
|
||||||
|
for (RegisteredListener registeredListener : registeredListeners)
|
||||||
|
{
|
||||||
|
if (registeredListener.getListener() == listener)
|
||||||
|
{
|
||||||
|
return registeredListener;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void unregisterRegisteredListener(RegisteredListener registeredListener, Class<? extends Event> eventClass)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
((HandlerList) eventClass.getMethod("getHandlerList", (Class<?>[]) null).invoke(null)).unregister(registeredListener);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void unregisterListener(Listener listener, Class<? extends Event> eventClass)
|
||||||
|
{
|
||||||
|
RegisteredListener registeredListener = getRegisteredListener(listener, eventClass);
|
||||||
|
if (registeredListener != null)
|
||||||
|
{
|
||||||
|
unregisterRegisteredListener(registeredListener, eventClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TFM_FrontDoor getInstance()
|
||||||
|
{
|
||||||
|
return TFM_FrontDoorHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TFM_FrontDoorHolder
|
||||||
|
{
|
||||||
|
private static final TFM_FrontDoor INSTANCE = new TFM_FrontDoor();
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
|
|
||||||
public class TFM_Heartbeat extends BukkitRunnable
|
public class TFM_Heartbeat extends BukkitRunnable
|
||||||
{
|
{
|
||||||
|
private static final long AUTO_KICK_TIME = (long) TFM_ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L;
|
||||||
private final TotalFreedomMod plugin;
|
private final TotalFreedomMod plugin;
|
||||||
private final Server server;
|
private final Server server;
|
||||||
private static Long lastRan = null;
|
private static Long lastRan = null;
|
||||||
@ -27,12 +28,27 @@ public class TFM_Heartbeat extends BukkitRunnable
|
|||||||
{
|
{
|
||||||
lastRan = System.currentTimeMillis();
|
lastRan = System.currentTimeMillis();
|
||||||
|
|
||||||
|
final TFM_EssentialsBridge essentialsBridge = TFM_EssentialsBridge.getInstance();
|
||||||
|
final boolean doAwayKickCheck =
|
||||||
|
TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean()
|
||||||
|
&& essentialsBridge.isEssentialsEnabled()
|
||||||
|
&& ((server.getOnlinePlayers().length / server.getMaxPlayers()) > TFM_ConfigEntry.AUTOKICK_THRESHOLD.getDouble());
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
playerdata.resetMsgCount();
|
playerdata.resetMsgCount();
|
||||||
playerdata.resetBlockDestroyCount();
|
playerdata.resetBlockDestroyCount();
|
||||||
playerdata.resetBlockPlaceCount();
|
playerdata.resetBlockPlaceCount();
|
||||||
|
|
||||||
|
if (doAwayKickCheck)
|
||||||
|
{
|
||||||
|
final long lastActivity = essentialsBridge.getLastActivity(player.getName());
|
||||||
|
if (lastActivity > 0 && lastActivity + AUTO_KICK_TIME < System.currentTimeMillis())
|
||||||
|
{
|
||||||
|
player.kickPlayer("Automatically kicked by server for inactivity.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||||
@ -44,6 +60,17 @@ public class TFM_Heartbeat extends BukkitRunnable
|
|||||||
{
|
{
|
||||||
for (World world : server.getWorlds())
|
for (World world : server.getWorlds())
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (world == TFM_AdminWorld.getInstance().getWorld() && TFM_AdminWorld.getInstance().getWeatherMode() != TFM_AdminWorld.WeatherMode.OFF)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
if (world.getWeatherDuration() > 0)
|
if (world.getWeatherDuration() > 0)
|
||||||
{
|
{
|
||||||
world.setThundering(false);
|
world.setThundering(false);
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class TFM_LandmineData
|
|
||||||
{
|
|
||||||
public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
|
|
||||||
public Location landmine_pos;
|
|
||||||
public Player player;
|
|
||||||
public double radius;
|
|
||||||
|
|
||||||
public TFM_LandmineData(Location landmine_pos, Player player, double radius)
|
|
||||||
{
|
|
||||||
this.landmine_pos = landmine_pos;
|
|
||||||
this.player = player;
|
|
||||||
this.radius = radius;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +1,97 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
public class TFM_Log
|
public class TFM_Log
|
||||||
{
|
{
|
||||||
private static final Logger logger = Bukkit.getLogger();
|
private static final Logger FALLBACK_LOGGER = Logger.getLogger("Minecraft-Server");
|
||||||
|
private static Logger serverLogger = null;
|
||||||
|
private static Logger pluginLogger = null;
|
||||||
|
|
||||||
private TFM_Log()
|
private TFM_Log()
|
||||||
{
|
{
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Level.INFO:
|
||||||
public static void info(String message)
|
public static void info(String message)
|
||||||
{
|
{
|
||||||
TotalFreedomMod.logger.info(message);
|
info(message, false);
|
||||||
}
|
|
||||||
|
|
||||||
public static void info(String message, boolean raw)
|
|
||||||
{
|
|
||||||
if (raw)
|
|
||||||
{
|
|
||||||
TotalFreedomMod.logger.info(message);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
info(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void severe(Object message)
|
public static void info(String message, Boolean raw)
|
||||||
{
|
{
|
||||||
if (message instanceof Throwable)
|
log(Level.INFO, message, raw);
|
||||||
{
|
|
||||||
TotalFreedomMod.logger.severe(ExceptionUtils.getFullStackTrace((Throwable) message));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TotalFreedomMod.logger.severe(String.valueOf(message));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(Object message)
|
public static void info(Throwable ex)
|
||||||
{
|
{
|
||||||
if (message instanceof Throwable)
|
log(Level.INFO, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Level.WARNING:
|
||||||
|
public static void warning(String message)
|
||||||
|
{
|
||||||
|
info(message, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(String message, Boolean raw)
|
||||||
|
{
|
||||||
|
log(Level.WARNING, message, raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(Throwable ex)
|
||||||
|
{
|
||||||
|
log(Level.WARNING, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Level.SEVERE:
|
||||||
|
public static void severe(String message)
|
||||||
|
{
|
||||||
|
info(message, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void severe(String message, Boolean raw)
|
||||||
|
{
|
||||||
|
log(Level.SEVERE, message, raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void severe(Throwable ex)
|
||||||
|
{
|
||||||
|
log(Level.SEVERE, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utility
|
||||||
|
private static void log(Level level, String message, boolean raw)
|
||||||
|
{
|
||||||
|
getLogger(raw).log(level, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void log(Level level, Throwable throwable)
|
||||||
|
{
|
||||||
|
getLogger(false).log(level, null, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setServerLogger(Logger logger)
|
||||||
|
{
|
||||||
|
serverLogger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setPluginLogger(Logger logger)
|
||||||
|
{
|
||||||
|
pluginLogger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(boolean raw)
|
||||||
|
{
|
||||||
|
if (raw || pluginLogger == null)
|
||||||
{
|
{
|
||||||
TotalFreedomMod.logger.warning(ExceptionUtils.getFullStackTrace((Throwable) message));
|
return (serverLogger != null ? serverLogger : FALLBACK_LOGGER);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TotalFreedomMod.logger.warning(String.valueOf(message));
|
return pluginLogger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
85
src/me/StevenLawson/TotalFreedomMod/TFM_LogFile.java
Normal file
85
src/me/StevenLawson/TotalFreedomMod/TFM_LogFile.java
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.logging.FileHandler;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class TFM_LogFile
|
||||||
|
{
|
||||||
|
public static final int MAX_LOG_SIZE = 1024 * 1024; // Bytes
|
||||||
|
private final Logger logger;
|
||||||
|
private final SimpleDateFormat date;
|
||||||
|
|
||||||
|
private TFM_LogFile()
|
||||||
|
{
|
||||||
|
this.logger = TotalFreedomMod.server.getLogger();
|
||||||
|
this.date = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger.addHandler(getHandler());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.warning("Failed to register log handler!");
|
||||||
|
TFM_Log.warning(TotalFreedomMod.pluginName + " will not log to /server.log!");
|
||||||
|
TFM_Log.warning(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileHandler getHandler() throws SecurityException, IOException
|
||||||
|
{
|
||||||
|
final FileHandler handler = new FileHandler("server.log", MAX_LOG_SIZE, 1);
|
||||||
|
handler.setLevel(Level.ALL);
|
||||||
|
handler.setFormatter(getFormatter());
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Formatter getFormatter()
|
||||||
|
{
|
||||||
|
return new Formatter()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String format(LogRecord record) // org.bukkit.craftbukkit.util.ShortConsoleFormatter
|
||||||
|
{
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
Throwable ex = record.getThrown();
|
||||||
|
|
||||||
|
builder.append(date.format(record.getMillis()));
|
||||||
|
builder.append(" [");
|
||||||
|
builder.append(record.getLevel().getLocalizedName().toUpperCase());
|
||||||
|
builder.append("] ");
|
||||||
|
builder.append(formatMessage(record));
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
if (ex != null)
|
||||||
|
{
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
ex.printStackTrace(new PrintWriter(writer));
|
||||||
|
builder.append(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TFM_LogFile getInstance()
|
||||||
|
{
|
||||||
|
return TFM_LogFileHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TFM_LogFileHolder
|
||||||
|
{
|
||||||
|
private static final TFM_LogFile INSTANCE = new TFM_LogFile();
|
||||||
|
}
|
||||||
|
}
|
@ -22,44 +22,44 @@ public class TFM_PlayerData
|
|||||||
{
|
{
|
||||||
public final static Map<Player, TFM_PlayerData> userinfo = new HashMap<Player, TFM_PlayerData>();
|
public final static Map<Player, TFM_PlayerData> userinfo = new HashMap<Player, TFM_PlayerData>();
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final String ip_address;
|
private final String ip;
|
||||||
private final String player_name;
|
private final String username;
|
||||||
private boolean user_frozen = false;
|
private boolean isFrozen = false;
|
||||||
private boolean is_muted = false;
|
private boolean isMuted = false;
|
||||||
private boolean is_halted = false;
|
private boolean isHalted = false;
|
||||||
private int msg_count = 0;
|
private int messageCount = 0;
|
||||||
private int block_destroy_total = 0;
|
private int totalBlockDestroy = 0;
|
||||||
private int block_place_total = 0;
|
private int totalBlockPlace = 0;
|
||||||
private int freecam_destroy_count = 0;
|
private int freecamDestroyCount = 0;
|
||||||
private int freecam_place_count = 0;
|
private int freecamPlaceCount = 0;
|
||||||
private boolean user_caged = false;
|
private boolean isCaged = false;
|
||||||
private Location user_cage_pos;
|
private Location cagePosition;
|
||||||
private List<TFM_BlockData> user_cage_history = new ArrayList<TFM_BlockData>();
|
private List<TFM_BlockData> cageHistory = new ArrayList<TFM_BlockData>();
|
||||||
private Material cage_material_outer = Material.GLASS;
|
private Material cageOuterMaterial = Material.GLASS;
|
||||||
private Material cage_material_inner = Material.AIR;
|
private Material cageInnerMatterial = Material.AIR;
|
||||||
private boolean is_orbiting = false;
|
private boolean isOrbiting = false;
|
||||||
private double orbit_strength = 10.0;
|
private double orbitStrength = 10.0;
|
||||||
private boolean mob_thrower_enabled = false;
|
private boolean mobThrowerEnabled = false;
|
||||||
private EntityType mob_thrower_creature = EntityType.PIG;
|
private EntityType mobThrowerEntity = EntityType.PIG;
|
||||||
private double mob_thrower_speed = 4.0;
|
private double mobThrowerSpeed = 4.0;
|
||||||
private List<LivingEntity> mob_thrower_queue = new ArrayList<LivingEntity>();
|
private List<LivingEntity> mobThrowerQueue = new ArrayList<LivingEntity>();
|
||||||
private BukkitTask mp44_schedule_id = null;
|
private BukkitTask mp44ScheduleId = null;
|
||||||
private boolean mp44_armed = false;
|
private boolean mp44Armed = false;
|
||||||
private boolean mp44_firing = false;
|
private boolean mp44Firing = false;
|
||||||
private BukkitTask lockup_schedule_id = null;
|
private BukkitTask lockupScheduleId = null;
|
||||||
private String last_message = "";
|
private String lastMessage = "";
|
||||||
private boolean in_adminchat = false;
|
private boolean inAdminchat = false;
|
||||||
private boolean all_commands_blocked = false;
|
private boolean allCommandsBlocked = false;
|
||||||
private Boolean superadmin_id_verified = null;
|
private Boolean verifiedSuperadminId = null;
|
||||||
private String last_command = "";
|
private String lastCommand = "";
|
||||||
private boolean cmdspy_enabled = false;
|
private boolean cmdspyEnabled = false;
|
||||||
private String tag = null;
|
private String tag = null;
|
||||||
|
|
||||||
public TFM_PlayerData(Player player)
|
public TFM_PlayerData(Player player)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.ip_address = player.getAddress().getAddress().getHostAddress();
|
this.ip = player.getAddress().getAddress().getHostAddress();
|
||||||
this.player_name = player.getName();
|
this.username = player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_PlayerData getPlayerData(Player player)
|
public static TFM_PlayerData getPlayerData(Player player)
|
||||||
@ -72,20 +72,20 @@ public class TFM_PlayerData
|
|||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
Entry<Player, TFM_PlayerData> pair = it.next();
|
Entry<Player, TFM_PlayerData> pair = it.next();
|
||||||
TFM_PlayerData playerdata_test = pair.getValue();
|
TFM_PlayerData playerdataTest = pair.getValue();
|
||||||
|
|
||||||
if (playerdata_test.player_name.equalsIgnoreCase(player.getName()))
|
if (playerdataTest.username.equalsIgnoreCase(player.getName()))
|
||||||
{
|
{
|
||||||
if (Bukkit.getOnlineMode())
|
if (Bukkit.getOnlineMode())
|
||||||
{
|
{
|
||||||
playerdata = playerdata_test;
|
playerdata = playerdataTest;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (playerdata_test.ip_address.equalsIgnoreCase(player.getAddress().getAddress().getHostAddress()))
|
if (playerdataTest.ip.equalsIgnoreCase(player.getAddress().getAddress().getHostAddress()))
|
||||||
{
|
{
|
||||||
playerdata = playerdata_test;
|
playerdata = playerdataTest;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,51 +104,51 @@ public class TFM_PlayerData
|
|||||||
|
|
||||||
public String getIpAddress()
|
public String getIpAddress()
|
||||||
{
|
{
|
||||||
return ip_address;
|
return this.ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlayerName()
|
public String getPlayerName()
|
||||||
{
|
{
|
||||||
return player_name;
|
return this.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOrbiting()
|
public boolean isOrbiting()
|
||||||
{
|
{
|
||||||
return is_orbiting;
|
return this.isOrbiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startOrbiting(double orbit_strength)
|
public void startOrbiting(double strength)
|
||||||
{
|
{
|
||||||
this.is_orbiting = true;
|
this.isOrbiting = true;
|
||||||
this.orbit_strength = orbit_strength;
|
this.orbitStrength = strength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopOrbiting()
|
public void stopOrbiting()
|
||||||
{
|
{
|
||||||
is_orbiting = false;
|
this.isOrbiting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double orbitStrength()
|
public double orbitStrength()
|
||||||
{
|
{
|
||||||
return orbit_strength;
|
return this.orbitStrength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCaged(boolean state)
|
public void setCaged(boolean state)
|
||||||
{
|
{
|
||||||
this.user_caged = state;
|
this.isCaged = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCaged(boolean state, Location location, Material material_outer, Material material_inner)
|
public void setCaged(boolean state, Location location, Material outer, Material inner)
|
||||||
{
|
{
|
||||||
this.user_caged = state;
|
this.isCaged = state;
|
||||||
this.user_cage_pos = location;
|
this.cagePosition = location;
|
||||||
this.cage_material_outer = material_outer;
|
this.cageOuterMaterial = outer;
|
||||||
this.cage_material_inner = material_inner;
|
this.cageInnerMatterial = inner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCaged()
|
public boolean isCaged()
|
||||||
{
|
{
|
||||||
return user_caged;
|
return this.isCaged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CageLayer
|
public enum CageLayer
|
||||||
@ -161,32 +161,32 @@ public class TFM_PlayerData
|
|||||||
switch (layer)
|
switch (layer)
|
||||||
{
|
{
|
||||||
case OUTER:
|
case OUTER:
|
||||||
return this.cage_material_outer;
|
return this.cageOuterMaterial;
|
||||||
case INNER:
|
case INNER:
|
||||||
return this.cage_material_inner;
|
return this.cageInnerMatterial;
|
||||||
default:
|
default:
|
||||||
return this.cage_material_outer;
|
return this.cageOuterMaterial;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getCagePos()
|
public Location getCagePos()
|
||||||
{
|
{
|
||||||
return user_cage_pos;
|
return this.cagePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearHistory()
|
public void clearHistory()
|
||||||
{
|
{
|
||||||
this.user_cage_history.clear();
|
this.cageHistory.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertHistoryBlock(Location location, Material material)
|
public void insertHistoryBlock(Location location, Material material)
|
||||||
{
|
{
|
||||||
this.user_cage_history.add(new TFM_BlockData(location, material));
|
this.cageHistory.add(new TFM_BlockData(location, material));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void regenerateHistory()
|
public void regenerateHistory()
|
||||||
{
|
{
|
||||||
for (TFM_BlockData blockdata : this.user_cage_history)
|
for (TFM_BlockData blockdata : this.cageHistory)
|
||||||
{
|
{
|
||||||
blockdata.location.getBlock().setType(blockdata.material);
|
blockdata.location.getBlock().setType(blockdata.material);
|
||||||
}
|
}
|
||||||
@ -206,97 +206,97 @@ public class TFM_PlayerData
|
|||||||
|
|
||||||
public boolean isFrozen()
|
public boolean isFrozen()
|
||||||
{
|
{
|
||||||
return this.user_frozen;
|
return this.isFrozen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFrozen(boolean fr)
|
public void setFrozen(boolean fr)
|
||||||
{
|
{
|
||||||
this.user_frozen = fr;
|
this.isFrozen = fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetMsgCount()
|
public void resetMsgCount()
|
||||||
{
|
{
|
||||||
this.msg_count = 0;
|
this.messageCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int incrementAndGetMsgCount()
|
public int incrementAndGetMsgCount()
|
||||||
{
|
{
|
||||||
return this.msg_count++;
|
return this.messageCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int incrementAndGetBlockDestroyCount()
|
public int incrementAndGetBlockDestroyCount()
|
||||||
{
|
{
|
||||||
return this.block_destroy_total++;
|
return this.totalBlockDestroy++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetBlockDestroyCount()
|
public void resetBlockDestroyCount()
|
||||||
{
|
{
|
||||||
this.block_destroy_total = 0;
|
this.totalBlockDestroy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int incrementAndGetBlockPlaceCount()
|
public int incrementAndGetBlockPlaceCount()
|
||||||
{
|
{
|
||||||
return this.block_place_total++;
|
return this.totalBlockPlace++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetBlockPlaceCount()
|
public void resetBlockPlaceCount()
|
||||||
{
|
{
|
||||||
this.block_place_total = 0;
|
this.totalBlockPlace = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int incrementAndGetFreecamDestroyCount()
|
public int incrementAndGetFreecamDestroyCount()
|
||||||
{
|
{
|
||||||
return this.freecam_destroy_count++;
|
return this.freecamDestroyCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetFreecamDestroyCount()
|
public void resetFreecamDestroyCount()
|
||||||
{
|
{
|
||||||
this.freecam_destroy_count = 0;
|
this.freecamDestroyCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int incrementAndGetFreecamPlaceCount()
|
public int incrementAndGetFreecamPlaceCount()
|
||||||
{
|
{
|
||||||
return this.freecam_place_count++;
|
return this.freecamPlaceCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetFreecamPlaceCount()
|
public void resetFreecamPlaceCount()
|
||||||
{
|
{
|
||||||
this.freecam_place_count = 0;
|
this.freecamPlaceCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableMobThrower(EntityType mob_thrower_creature, double mob_thrower_speed)
|
public void enableMobThrower(EntityType mobThrowerCreature, double mobThrowerSpeed)
|
||||||
{
|
{
|
||||||
this.mob_thrower_enabled = true;
|
this.mobThrowerEnabled = true;
|
||||||
this.mob_thrower_creature = mob_thrower_creature;
|
this.mobThrowerEntity = mobThrowerCreature;
|
||||||
this.mob_thrower_speed = mob_thrower_speed;
|
this.mobThrowerSpeed = mobThrowerSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableMobThrower()
|
public void disableMobThrower()
|
||||||
{
|
{
|
||||||
this.mob_thrower_enabled = false;
|
this.mobThrowerEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityType mobThrowerCreature()
|
public EntityType mobThrowerCreature()
|
||||||
{
|
{
|
||||||
return mob_thrower_creature;
|
return this.mobThrowerEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double mobThrowerSpeed()
|
public double mobThrowerSpeed()
|
||||||
{
|
{
|
||||||
return mob_thrower_speed;
|
return this.mobThrowerSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mobThrowerEnabled()
|
public boolean mobThrowerEnabled()
|
||||||
{
|
{
|
||||||
return mob_thrower_enabled;
|
return this.mobThrowerEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enqueueMob(LivingEntity mob)
|
public void enqueueMob(LivingEntity mob)
|
||||||
{
|
{
|
||||||
mob_thrower_queue.add(mob);
|
mobThrowerQueue.add(mob);
|
||||||
if (mob_thrower_queue.size() > 4)
|
if (mobThrowerQueue.size() > 4)
|
||||||
{
|
{
|
||||||
LivingEntity oldmob = mob_thrower_queue.remove(0);
|
LivingEntity oldmob = mobThrowerQueue.remove(0);
|
||||||
if (oldmob != null)
|
if (oldmob != null)
|
||||||
{
|
{
|
||||||
oldmob.damage(500.0);
|
oldmob.damage(500.0);
|
||||||
@ -307,85 +307,85 @@ public class TFM_PlayerData
|
|||||||
public void startArrowShooter(TotalFreedomMod plugin)
|
public void startArrowShooter(TotalFreedomMod plugin)
|
||||||
{
|
{
|
||||||
this.stopArrowShooter();
|
this.stopArrowShooter();
|
||||||
this.mp44_schedule_id = new ArrowShooter(this.player).runTaskTimer(plugin, 1L, 1L);
|
this.mp44ScheduleId = new ArrowShooter(this.player).runTaskTimer(plugin, 1L, 1L);
|
||||||
mp44_firing = true;
|
this.mp44Firing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopArrowShooter()
|
public void stopArrowShooter()
|
||||||
{
|
{
|
||||||
if (this.mp44_schedule_id != null)
|
if (this.mp44ScheduleId != null)
|
||||||
{
|
{
|
||||||
this.mp44_schedule_id.cancel();
|
this.mp44ScheduleId.cancel();
|
||||||
this.mp44_schedule_id = null;
|
this.mp44ScheduleId = null;
|
||||||
}
|
}
|
||||||
mp44_firing = false;
|
this.mp44Firing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ArrowShooter extends BukkitRunnable
|
private class ArrowShooter extends BukkitRunnable
|
||||||
{
|
{
|
||||||
private Player _player;
|
private Player player;
|
||||||
|
|
||||||
public ArrowShooter(Player player)
|
public ArrowShooter(Player player)
|
||||||
{
|
{
|
||||||
this._player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Arrow shot_arrow = _player.launchProjectile(Arrow.class);
|
Arrow shot = player.launchProjectile(Arrow.class);
|
||||||
shot_arrow.setVelocity(shot_arrow.getVelocity().multiply(2.0));
|
shot.setVelocity(shot.getVelocity().multiply(2.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void armMP44()
|
public void armMP44()
|
||||||
{
|
{
|
||||||
mp44_armed = true;
|
this.mp44Armed = true;
|
||||||
this.stopArrowShooter();
|
this.stopArrowShooter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disarmMP44()
|
public void disarmMP44()
|
||||||
{
|
{
|
||||||
mp44_armed = false;
|
this.mp44Armed = false;
|
||||||
this.stopArrowShooter();
|
this.stopArrowShooter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMP44Armed()
|
public boolean isMP44Armed()
|
||||||
{
|
{
|
||||||
return mp44_armed;
|
return this.mp44Armed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean toggleMP44Firing()
|
public boolean toggleMP44Firing()
|
||||||
{
|
{
|
||||||
this.mp44_firing = !this.mp44_firing;
|
this.mp44Firing = !this.mp44Firing;
|
||||||
return mp44_firing;
|
return mp44Firing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMuted()
|
public boolean isMuted()
|
||||||
{
|
{
|
||||||
return is_muted;
|
return isMuted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMuted(boolean is_muted)
|
public void setMuted(boolean muted)
|
||||||
{
|
{
|
||||||
this.is_muted = is_muted;
|
this.isMuted = muted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHalted()
|
public boolean isHalted()
|
||||||
{
|
{
|
||||||
return is_halted;
|
return this.isHalted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHalted(boolean is_halted)
|
public void setHalted(boolean halted)
|
||||||
{
|
{
|
||||||
this.is_halted = is_halted;
|
this.isHalted = halted;
|
||||||
|
|
||||||
if (is_halted)
|
if (halted)
|
||||||
{
|
{
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
player.setFlying(false);
|
player.setFlying(false);
|
||||||
player.setDisplayName(player_name);
|
player.setDisplayName(username);
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
player.setTotalExperience(0);
|
player.setTotalExperience(0);
|
||||||
|
|
||||||
@ -409,76 +409,76 @@ public class TFM_PlayerData
|
|||||||
|
|
||||||
public BukkitTask getLockupScheduleID()
|
public BukkitTask getLockupScheduleID()
|
||||||
{
|
{
|
||||||
return lockup_schedule_id;
|
return this.lockupScheduleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLockupScheduleID(BukkitTask lockup_schedule_id)
|
public void setLockupScheduleID(BukkitTask id)
|
||||||
{
|
{
|
||||||
this.lockup_schedule_id = lockup_schedule_id;
|
this.lockupScheduleId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastMessage(String last_message)
|
public void setLastMessage(String message)
|
||||||
{
|
{
|
||||||
this.last_message = last_message;
|
this.lastMessage = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastMessage()
|
public String getLastMessage()
|
||||||
{
|
{
|
||||||
return last_message;
|
return lastMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdminChat(boolean in_adminchat)
|
public void setAdminChat(boolean inAdminchat)
|
||||||
{
|
{
|
||||||
this.in_adminchat = in_adminchat;
|
this.inAdminchat = inAdminchat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean inAdminChat()
|
public boolean inAdminChat()
|
||||||
{
|
{
|
||||||
return in_adminchat;
|
return this.inAdminchat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean allCommandsBlocked()
|
public boolean allCommandsBlocked()
|
||||||
{
|
{
|
||||||
return all_commands_blocked;
|
return this.allCommandsBlocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCommandsBlocked(boolean commands_blocked)
|
public void setCommandsBlocked(boolean commandsBlocked)
|
||||||
{
|
{
|
||||||
this.all_commands_blocked = commands_blocked;
|
this.allCommandsBlocked = commandsBlocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
|
// If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
|
||||||
//After the check for this is done in TFM_PlayerListener, never change it elsewhere.
|
// After the check for this is done in TFM_PlayerListener, never change it elsewhere.
|
||||||
public Boolean isSuperadminIdVerified()
|
public Boolean isSuperadminIdVerified()
|
||||||
{
|
{
|
||||||
return superadmin_id_verified;
|
return this.verifiedSuperadminId;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
|
// If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
|
||||||
//After the check for this is done in TFM_PlayerListener, never change it elsewhere.
|
// After the check for this is done in TFM_PlayerListener, never change it elsewhere.
|
||||||
public void setSuperadminIdVerified(Boolean superadmin_id_verified)
|
public void setSuperadminIdVerified(Boolean verifiedSuperadminId)
|
||||||
{
|
{
|
||||||
this.superadmin_id_verified = superadmin_id_verified;
|
this.verifiedSuperadminId = verifiedSuperadminId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastCommand()
|
public String getLastCommand()
|
||||||
{
|
{
|
||||||
return last_command;
|
return lastCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastCommand(String last_command)
|
public void setLastCommand(String lastCommand)
|
||||||
{
|
{
|
||||||
this.last_command = last_command;
|
this.lastCommand = lastCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCommandSpy(boolean cmdspy_enabled)
|
public void setCommandSpy(boolean enabled)
|
||||||
{
|
{
|
||||||
this.cmdspy_enabled = cmdspy_enabled;
|
this.cmdspyEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cmdspyEnabled()
|
public boolean cmdspyEnabled()
|
||||||
{
|
{
|
||||||
return cmdspy_enabled;
|
return cmdspyEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTag(String tag)
|
public void setTag(String tag)
|
||||||
@ -489,7 +489,7 @@ public class TFM_PlayerData
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.tag = TFM_Util.colorise(tag) + ChatColor.WHITE;
|
this.tag = TFM_Util.colorize(tag) + ChatColor.WHITE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
120
src/me/StevenLawson/TotalFreedomMod/TFM_PlayerRank.java
Normal file
120
src/me/StevenLawson/TotalFreedomMod/TFM_PlayerRank.java
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import static me.StevenLawson.TotalFreedomMod.TFM_Util.DEVELOPERS;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public enum TFM_PlayerRank
|
||||||
|
{
|
||||||
|
DEVELOPER("a " + ChatColor.DARK_PURPLE + "Developer", ChatColor.DARK_PURPLE + "[Dev]"),
|
||||||
|
IMPOSTOR("an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "Impostor", ChatColor.YELLOW.toString() + ChatColor.UNDERLINE + "[IMP]"),
|
||||||
|
NON_OP("a " + ChatColor.GREEN + "Non-OP", ChatColor.GREEN.toString()),
|
||||||
|
OP("an " + ChatColor.RED + "OP", ChatColor.RED + "[OP]"),
|
||||||
|
SUPER("a " + ChatColor.GOLD + "Super Admin", ChatColor.GOLD + "[SA]"),
|
||||||
|
TELNET("a " + ChatColor.DARK_GREEN + "Super Telnet Admin", ChatColor.DARK_GREEN + "[STA]"),
|
||||||
|
SENIOR("a " + ChatColor.LIGHT_PURPLE + "Senior Admin", ChatColor.LIGHT_PURPLE + "[SrA]"),
|
||||||
|
OWNER("the " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]"),
|
||||||
|
CONSOLE("The " + ChatColor.DARK_PURPLE + "Console", ChatColor.DARK_PURPLE + "[Console]");
|
||||||
|
private String loginMessage;
|
||||||
|
private String prefix;
|
||||||
|
|
||||||
|
private TFM_PlayerRank(String loginMessage, String prefix)
|
||||||
|
{
|
||||||
|
this.loginMessage = loginMessage;
|
||||||
|
this.prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLoginMessage(CommandSender sender)
|
||||||
|
{
|
||||||
|
if (!(sender instanceof Player))
|
||||||
|
{
|
||||||
|
return fromSender(sender).getLoginMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry((Player) sender);
|
||||||
|
|
||||||
|
if (entry == null)
|
||||||
|
{
|
||||||
|
return fromSender(sender).getLoginMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
final String loginMessage = entry.getCustomLoginMessage();
|
||||||
|
|
||||||
|
if (loginMessage != null && !loginMessage.isEmpty())
|
||||||
|
{
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', loginMessage);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return fromSender(sender).getLoginMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TFM_PlayerRank fromSender(CommandSender sender)
|
||||||
|
{
|
||||||
|
if (!(sender instanceof Player))
|
||||||
|
{
|
||||||
|
return CONSOLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TFM_SuperadminList.isSuperadminImpostor(sender))
|
||||||
|
{
|
||||||
|
return IMPOSTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DEVELOPERS.contains(sender.getName()))
|
||||||
|
{
|
||||||
|
return DEVELOPER;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry((Player) sender);
|
||||||
|
|
||||||
|
final TFM_PlayerRank rank;
|
||||||
|
|
||||||
|
if (entry != null && entry.isActivated())
|
||||||
|
{
|
||||||
|
if (sender.getName().equals("markbyron"))
|
||||||
|
{
|
||||||
|
return OWNER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry.isSeniorAdmin())
|
||||||
|
{
|
||||||
|
rank = SENIOR;
|
||||||
|
}
|
||||||
|
else if (entry.isTelnetAdmin())
|
||||||
|
{
|
||||||
|
rank = TELNET;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rank = SUPER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (sender.isOp())
|
||||||
|
{
|
||||||
|
rank = OP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rank = NON_OP;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrefix()
|
||||||
|
{
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLoginMessage()
|
||||||
|
{
|
||||||
|
return loginMessage;
|
||||||
|
}
|
||||||
|
}
|
@ -7,70 +7,208 @@ import java.io.ObjectInputStream;
|
|||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class TFM_ProtectedArea implements Serializable
|
public class TFM_ProtectedArea
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = -3270338811000937254L;
|
public static final double MAX_RADIUS = 50.0;
|
||||||
public static final double MAX_RADIUS = 50.0D;
|
private static final Map<String, SerializableProtectedRegion> PROTECTED_AREAS = new HashMap<String, SerializableProtectedRegion>();
|
||||||
private static Map<String, TFM_ProtectedArea> protectedAreas = new HashMap<String, TFM_ProtectedArea>();
|
|
||||||
private final SerializableLocation center_location;
|
|
||||||
private final double radius;
|
|
||||||
|
|
||||||
private TFM_ProtectedArea(Location root_location, double radius)
|
private TFM_ProtectedArea()
|
||||||
{
|
{
|
||||||
this.center_location = new SerializableLocation(root_location);
|
throw new AssertionError();
|
||||||
this.radius = radius;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInProtectedArea(Location check_location)
|
public static boolean isInProtectedArea(final Location modifyLocation)
|
||||||
{
|
{
|
||||||
for (Map.Entry<String, TFM_ProtectedArea> protected_area : TFM_ProtectedArea.protectedAreas.entrySet())
|
boolean doSave = false;
|
||||||
{
|
boolean inProtectedArea = false;
|
||||||
Location protected_area_center = SerializableLocation.returnLocation(protected_area.getValue().center_location);
|
|
||||||
if (protected_area_center != null)
|
|
||||||
{
|
|
||||||
if (check_location.getWorld() == protected_area_center.getWorld())
|
|
||||||
{
|
|
||||||
double protected_area_radius = protected_area.getValue().radius;
|
|
||||||
|
|
||||||
if (check_location.distanceSquared(protected_area_center) <= (protected_area_radius * protected_area_radius))
|
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator();
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
final SerializableProtectedRegion region = it.next().getValue();
|
||||||
|
|
||||||
|
Location regionCenter = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
regionCenter = region.getLocation();
|
||||||
|
}
|
||||||
|
catch (SerializableProtectedRegion.CantFindWorldException ex)
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
doSave = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regionCenter != null)
|
||||||
|
{
|
||||||
|
if (modifyLocation.getWorld() == regionCenter.getWorld())
|
||||||
|
{
|
||||||
|
final double regionRadius = region.getRadius();
|
||||||
|
if (modifyLocation.distanceSquared(regionCenter) <= (regionRadius * regionRadius))
|
||||||
{
|
{
|
||||||
return true;
|
inProtectedArea = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if (doSave)
|
||||||
|
{
|
||||||
|
saveProtectedAreas();
|
||||||
|
}
|
||||||
|
|
||||||
|
return inProtectedArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addProtectedArea(String label, Location root_location, double radius)
|
public static boolean isInProtectedArea(final Vector min, final Vector max, final String worldName)
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.protectedAreas.put(label.toLowerCase(), new TFM_ProtectedArea(root_location, radius));
|
boolean doSave = false;
|
||||||
|
boolean inProtectedArea = false;
|
||||||
|
|
||||||
|
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator();
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
final SerializableProtectedRegion region = it.next().getValue();
|
||||||
|
|
||||||
|
Location regionCenter = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
regionCenter = region.getLocation();
|
||||||
|
}
|
||||||
|
catch (SerializableProtectedRegion.CantFindWorldException ex)
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
doSave = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regionCenter != null)
|
||||||
|
{
|
||||||
|
if (worldName.equals(regionCenter.getWorld().getName()))
|
||||||
|
{
|
||||||
|
if (cubeIntersectsSphere(min, max, regionCenter.toVector(), region.getRadius()))
|
||||||
|
{
|
||||||
|
inProtectedArea = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doSave)
|
||||||
|
{
|
||||||
|
saveProtectedAreas();
|
||||||
|
}
|
||||||
|
|
||||||
|
return inProtectedArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean cubeIntersectsSphere(Vector min, Vector max, Vector sphere, double radius)
|
||||||
|
{
|
||||||
|
double d = square(radius);
|
||||||
|
|
||||||
|
if (sphere.getX() < min.getX())
|
||||||
|
{
|
||||||
|
d -= square(sphere.getX() - min.getX());
|
||||||
|
}
|
||||||
|
else if (sphere.getX() > max.getX())
|
||||||
|
{
|
||||||
|
d -= square(sphere.getX() - max.getX());
|
||||||
|
}
|
||||||
|
if (sphere.getY() < min.getY())
|
||||||
|
{
|
||||||
|
d -= square(sphere.getY() - min.getY());
|
||||||
|
}
|
||||||
|
else if (sphere.getY() > max.getY())
|
||||||
|
{
|
||||||
|
d -= square(sphere.getY() - max.getY());
|
||||||
|
}
|
||||||
|
if (sphere.getZ() < min.getZ())
|
||||||
|
{
|
||||||
|
d -= square(sphere.getZ() - min.getZ());
|
||||||
|
}
|
||||||
|
else if (sphere.getZ() > max.getZ())
|
||||||
|
{
|
||||||
|
d -= square(sphere.getZ() - max.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return d > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double square(double v)
|
||||||
|
{
|
||||||
|
return v * v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addProtectedArea(String label, Location location, double radius)
|
||||||
|
{
|
||||||
|
TFM_ProtectedArea.PROTECTED_AREAS.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius));
|
||||||
saveProtectedAreas();
|
saveProtectedAreas();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeProtectedArea(String label)
|
public static void removeProtectedArea(String label)
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.protectedAreas.remove(label.toLowerCase());
|
TFM_ProtectedArea.PROTECTED_AREAS.remove(label.toLowerCase());
|
||||||
saveProtectedAreas();
|
saveProtectedAreas();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearProtectedAreas()
|
public static void clearProtectedAreas()
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.protectedAreas.clear();
|
clearProtectedAreas(true);
|
||||||
autoAddSpawnpoints();
|
}
|
||||||
|
|
||||||
|
public static void clearProtectedAreas(boolean createSpawnpointProtectedAreas)
|
||||||
|
{
|
||||||
|
TFM_ProtectedArea.PROTECTED_AREAS.clear();
|
||||||
|
|
||||||
|
if (createSpawnpointProtectedAreas)
|
||||||
|
{
|
||||||
|
autoAddSpawnpoints();
|
||||||
|
}
|
||||||
|
|
||||||
saveProtectedAreas();
|
saveProtectedAreas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void cleanProtectedAreas()
|
||||||
|
{
|
||||||
|
boolean doSave = false;
|
||||||
|
|
||||||
|
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator();
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
it.next().getValue().getLocation();
|
||||||
|
}
|
||||||
|
catch (SerializableProtectedRegion.CantFindWorldException ex)
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
doSave = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doSave)
|
||||||
|
{
|
||||||
|
saveProtectedAreas();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Set<String> getProtectedAreaLabels()
|
public static Set<String> getProtectedAreaLabels()
|
||||||
{
|
{
|
||||||
return TFM_ProtectedArea.protectedAreas.keySet();
|
return TFM_ProtectedArea.PROTECTED_AREAS.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveProtectedAreas()
|
public static void saveProtectedAreas()
|
||||||
@ -79,7 +217,7 @@ public class TFM_ProtectedArea implements Serializable
|
|||||||
{
|
{
|
||||||
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE));
|
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE));
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
oos.writeObject(TFM_ProtectedArea.protectedAreas);
|
oos.writeObject(TFM_ProtectedArea.PROTECTED_AREAS);
|
||||||
oos.close();
|
oos.close();
|
||||||
fos.close();
|
fos.close();
|
||||||
}
|
}
|
||||||
@ -92,25 +230,26 @@ public class TFM_ProtectedArea implements Serializable
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void loadProtectedAreas()
|
public static void loadProtectedAreas()
|
||||||
{
|
{
|
||||||
|
File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File input_file = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE);
|
if (input.exists())
|
||||||
if (input_file.exists())
|
|
||||||
{
|
{
|
||||||
FileInputStream fis = new FileInputStream(input_file);
|
FileInputStream fis = new FileInputStream(input);
|
||||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||||
TFM_ProtectedArea.protectedAreas = (HashMap<String, TFM_ProtectedArea>) ois.readObject();
|
TFM_ProtectedArea.PROTECTED_AREAS.clear();
|
||||||
|
TFM_ProtectedArea.PROTECTED_AREAS.putAll((HashMap<String, SerializableProtectedRegion>) ois.readObject());
|
||||||
ois.close();
|
ois.close();
|
||||||
fis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
File input_file = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE);
|
input.delete();
|
||||||
input_file.delete();
|
|
||||||
|
|
||||||
TFM_Log.severe(ex);
|
TFM_Log.severe(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanProtectedAreas();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void autoAddSpawnpoints()
|
public static void autoAddSpawnpoints()
|
||||||
@ -123,4 +262,58 @@ public class TFM_ProtectedArea implements Serializable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SerializableProtectedRegion implements Serializable
|
||||||
|
{
|
||||||
|
private final double x, y, z;
|
||||||
|
private final double radius;
|
||||||
|
private final String worldName;
|
||||||
|
private final UUID worldUUID;
|
||||||
|
private transient Location location = null;
|
||||||
|
|
||||||
|
public SerializableProtectedRegion(final Location location, final double radius)
|
||||||
|
{
|
||||||
|
this.x = location.getX();
|
||||||
|
this.y = location.getY();
|
||||||
|
this.z = location.getZ();
|
||||||
|
this.radius = radius;
|
||||||
|
this.worldName = location.getWorld().getName();
|
||||||
|
this.worldUUID = location.getWorld().getUID();
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() throws CantFindWorldException
|
||||||
|
{
|
||||||
|
if (this.location == null)
|
||||||
|
{
|
||||||
|
World world = Bukkit.getWorld(this.worldUUID);
|
||||||
|
|
||||||
|
if (world == null)
|
||||||
|
{
|
||||||
|
world = Bukkit.getWorld(this.worldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world == null)
|
||||||
|
{
|
||||||
|
throw new CantFindWorldException("Can't find world " + this.worldName + ", UUID: " + this.worldUUID.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
location = new Location(world, x, y, z);
|
||||||
|
}
|
||||||
|
return this.location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getRadius()
|
||||||
|
{
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CantFindWorldException extends Exception
|
||||||
|
{
|
||||||
|
public CantFindWorldException(String string)
|
||||||
|
{
|
||||||
|
super(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,19 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class TFM_RollbackManager
|
public class TFM_RollbackManager
|
||||||
{
|
{
|
||||||
private static final Map<String, List<TFM_RollbackManager_Entry>> PLAYER_HISTORY_MAP = new HashMap<String, List<TFM_RollbackManager_Entry>>();
|
private static final Map<String, List<RollbackEntry>> PLAYER_HISTORY = new HashMap<String, List<RollbackEntry>>();
|
||||||
|
private static final List<String> REMOVE_ROLLBACK_HISTORY = new ArrayList<String>();
|
||||||
|
|
||||||
private TFM_RollbackManager()
|
private TFM_RollbackManager()
|
||||||
{
|
{
|
||||||
@ -21,17 +25,18 @@ public class TFM_RollbackManager
|
|||||||
|
|
||||||
public static void blockPlace(org.bukkit.event.block.BlockPlaceEvent event)
|
public static void blockPlace(org.bukkit.event.block.BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
storeEntry(event.getPlayer(), new TFM_RollbackManager_Entry(event.getBlock(), TFM_RollbackManager_EntryType.BLOCK_PLACE));
|
storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_PLACE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void blockBreak(org.bukkit.event.block.BlockBreakEvent event)
|
public static void blockBreak(org.bukkit.event.block.BlockBreakEvent event)
|
||||||
{
|
{
|
||||||
storeEntry(event.getPlayer(), new TFM_RollbackManager_Entry(event.getBlock(), TFM_RollbackManager_EntryType.BLOCK_BREAK));
|
storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_BREAK));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void storeEntry(Player player, TFM_RollbackManager_Entry entry)
|
private static void storeEntry(Player player, RollbackEntry entry)
|
||||||
{
|
{
|
||||||
List<TFM_RollbackManager_Entry> playerEntryList = getPlayerEntryList(player.getName());
|
List<RollbackEntry> playerEntryList = getEntriesByPlayer(player.getName());
|
||||||
|
|
||||||
if (playerEntryList != null)
|
if (playerEntryList != null)
|
||||||
{
|
{
|
||||||
playerEntryList.add(0, entry);
|
playerEntryList.add(0, entry);
|
||||||
@ -40,99 +45,247 @@ public class TFM_RollbackManager
|
|||||||
|
|
||||||
public static int purgeEntries()
|
public static int purgeEntries()
|
||||||
{
|
{
|
||||||
Iterator<List<TFM_RollbackManager_Entry>> it = PLAYER_HISTORY_MAP.values().iterator();
|
Iterator<List<RollbackEntry>> it = PLAYER_HISTORY.values().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
List<TFM_RollbackManager_Entry> playerEntryList = it.next();
|
List<RollbackEntry> playerEntryList = it.next();
|
||||||
if (playerEntryList != null)
|
if (playerEntryList != null)
|
||||||
{
|
{
|
||||||
playerEntryList.clear();
|
playerEntryList.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PLAYER_HISTORY_MAP.size();
|
return PLAYER_HISTORY.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int purgeEntries(String playerName)
|
public static int purgeEntries(String playerName)
|
||||||
{
|
{
|
||||||
List<TFM_RollbackManager_Entry> playerEntryList = getPlayerEntryList(playerName);
|
List<RollbackEntry> playerEntryList = getEntriesByPlayer(playerName);
|
||||||
if (playerEntryList != null)
|
|
||||||
|
if (playerEntryList == null)
|
||||||
{
|
{
|
||||||
int count = playerEntryList.size();
|
return 0;
|
||||||
playerEntryList.clear();
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
int count = playerEntryList.size();
|
||||||
|
playerEntryList.clear();
|
||||||
|
return count;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canRollback(String playerName)
|
public static boolean canRollback(String playerName)
|
||||||
{
|
{
|
||||||
return PLAYER_HISTORY_MAP.containsKey(playerName.toLowerCase());
|
return PLAYER_HISTORY.containsKey(playerName.toLowerCase()) && !PLAYER_HISTORY.get(playerName.toLowerCase()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int rollback(String playerName)
|
public static boolean canUndoRollback(String playerName)
|
||||||
{
|
{
|
||||||
List<TFM_RollbackManager_Entry> playerEntryList = getPlayerEntryList(playerName);
|
return REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase());
|
||||||
if (playerEntryList != null)
|
|
||||||
{
|
|
||||||
int count = playerEntryList.size();
|
|
||||||
Iterator<TFM_RollbackManager_Entry> it = playerEntryList.iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
TFM_RollbackManager_Entry entry = it.next();
|
|
||||||
if (entry != null)
|
|
||||||
{
|
|
||||||
entry.restore();
|
|
||||||
}
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<TFM_RollbackManager_Entry> getPlayerEntryList(String playerName)
|
public static int rollback(final String playerName)
|
||||||
|
{
|
||||||
|
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
||||||
|
if (entries == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = entries.size();
|
||||||
|
for (RollbackEntry entry : entries)
|
||||||
|
{
|
||||||
|
if (entry != null)
|
||||||
|
{
|
||||||
|
entry.restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
||||||
|
{
|
||||||
|
REMOVE_ROLLBACK_HISTORY.add(playerName.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
||||||
|
{
|
||||||
|
REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase());
|
||||||
|
purgeEntries(playerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(TotalFreedomMod.plugin, 20L * 20L);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int undoRollback(String playerName)
|
||||||
|
{
|
||||||
|
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
||||||
|
|
||||||
|
if (entries == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int count = entries.size();
|
||||||
|
|
||||||
|
final ListIterator<RollbackEntry> it = entries.listIterator(count);
|
||||||
|
while (it.hasPrevious())
|
||||||
|
{
|
||||||
|
RollbackEntry entry = it.previous();
|
||||||
|
if (entry != null)
|
||||||
|
{
|
||||||
|
entry.redo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
||||||
|
{
|
||||||
|
REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<RollbackEntry> getEntriesAtLocation(final Location location)
|
||||||
|
{
|
||||||
|
final int testX = location.getBlockX();
|
||||||
|
final short testY = (short) location.getBlockY();
|
||||||
|
final int testZ = location.getBlockZ();
|
||||||
|
final String testWorldName = location.getWorld().getName();
|
||||||
|
|
||||||
|
List<RollbackEntry> entries = new ArrayList<RollbackEntry>();
|
||||||
|
for (String playername : PLAYER_HISTORY.keySet())
|
||||||
|
{
|
||||||
|
for (RollbackEntry entry : PLAYER_HISTORY.get(playername.toLowerCase()))
|
||||||
|
{
|
||||||
|
if (testX == entry.x && testY == entry.y && testZ == entry.z && testWorldName.equals(entry.worldName))
|
||||||
|
{
|
||||||
|
entries.add(0, entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<RollbackEntry> getEntriesByPlayer(String playerName)
|
||||||
{
|
{
|
||||||
playerName = playerName.toLowerCase();
|
playerName = playerName.toLowerCase();
|
||||||
List<TFM_RollbackManager_Entry> playerEntryList = PLAYER_HISTORY_MAP.get(playerName);
|
List<RollbackEntry> playerEntryList = PLAYER_HISTORY.get(playerName.toLowerCase());
|
||||||
if (playerEntryList == null)
|
if (playerEntryList == null)
|
||||||
{
|
{
|
||||||
playerEntryList = new ArrayList<TFM_RollbackManager_Entry>();
|
playerEntryList = new ArrayList<RollbackEntry>();
|
||||||
PLAYER_HISTORY_MAP.put(playerName, playerEntryList);
|
PLAYER_HISTORY.put(playerName.toLowerCase(), playerEntryList);
|
||||||
}
|
}
|
||||||
return playerEntryList;
|
return playerEntryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum TFM_RollbackManager_EntryType
|
public enum EntryType
|
||||||
{
|
{
|
||||||
BLOCK_PLACE, BLOCK_BREAK
|
BLOCK_PLACE("placed"),
|
||||||
|
BLOCK_BREAK("broke");
|
||||||
|
private final String action;
|
||||||
|
|
||||||
|
private EntryType(String action)
|
||||||
|
{
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return this.action;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TFM_RollbackManager_Entry
|
public static class RollbackEntry
|
||||||
{
|
{
|
||||||
private final Location location;
|
// Use of primitives to decrease overhead
|
||||||
private final Material material;
|
public final String author;
|
||||||
private final byte data;
|
public final String worldName;
|
||||||
|
public final int x;
|
||||||
|
public final short y;
|
||||||
|
public final int z;
|
||||||
|
public final byte data;
|
||||||
|
public final short blockId;
|
||||||
|
private final boolean isBreak;
|
||||||
|
|
||||||
public TFM_RollbackManager_Entry(Block block, TFM_RollbackManager_EntryType entryType)
|
private RollbackEntry(String author, Block block, EntryType entryType)
|
||||||
{
|
{
|
||||||
this.location = block.getLocation();
|
final Location location = block.getLocation();
|
||||||
if (entryType == TFM_RollbackManager_EntryType.BLOCK_BREAK)
|
|
||||||
|
this.x = location.getBlockX();
|
||||||
|
this.y = (short) location.getBlockY();
|
||||||
|
this.z = location.getBlockZ();
|
||||||
|
this.worldName = location.getWorld().getName();
|
||||||
|
this.author = author;
|
||||||
|
|
||||||
|
if (entryType == EntryType.BLOCK_BREAK)
|
||||||
{
|
{
|
||||||
this.material = block.getType();
|
this.blockId = (short) block.getTypeId();
|
||||||
this.data = block.getData();
|
this.data = block.getData();
|
||||||
|
this.isBreak = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.material = Material.AIR;
|
this.blockId = (short) block.getTypeId();
|
||||||
this.data = 0;
|
this.data = block.getData();
|
||||||
|
this.isBreak = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location getLocation()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new Location(Bukkit.getWorld(worldName), (double) x, (double) y, (double) z);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.warning("Could not get location of rollback entry at (" + worldName + ":" + x + "," + y + "," + x + ")!");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getMaterial()
|
||||||
|
{
|
||||||
|
return Material.getMaterial(blockId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntryType getType()
|
||||||
|
{
|
||||||
|
return (isBreak ? EntryType.BLOCK_BREAK : EntryType.BLOCK_PLACE);
|
||||||
|
}
|
||||||
|
|
||||||
public void restore()
|
public void restore()
|
||||||
{
|
{
|
||||||
Block b = this.location.getWorld().getBlockAt(this.location);
|
final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
||||||
b.setType(this.material);
|
if (isBreak)
|
||||||
b.setData(this.data);
|
{
|
||||||
|
block.setType(getMaterial());
|
||||||
|
block.setData(data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void redo()
|
||||||
|
{
|
||||||
|
final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
||||||
|
|
||||||
|
if (isBreak)
|
||||||
|
{
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
block.setType(getMaterial());
|
||||||
|
block.setData(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,23 @@ package me.StevenLawson.TotalFreedomMod;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import net.minecraft.server.v1_6_R2.BanEntry;
|
import net.minecraft.server.v1_7_R1.BanEntry;
|
||||||
import net.minecraft.server.v1_6_R2.BanList;
|
import net.minecraft.server.v1_7_R1.BanList;
|
||||||
import net.minecraft.server.v1_6_R2.MinecraftServer;
|
import net.minecraft.server.v1_7_R1.MinecraftServer;
|
||||||
import net.minecraft.server.v1_6_R2.PlayerList;
|
import net.minecraft.server.v1_7_R1.PlayerList;
|
||||||
import net.minecraft.server.v1_6_R2.PropertyManager;
|
import net.minecraft.server.v1_7_R1.PropertyManager;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||||
|
|
||||||
public class TFM_ServerInterface
|
public class TFM_ServerInterface
|
||||||
{
|
{
|
||||||
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
|
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
|
||||||
|
|
||||||
public static void setOnlineMode(boolean mode)
|
public static void setOnlineMode(boolean mode)
|
||||||
{
|
{
|
||||||
@ -47,24 +49,41 @@ public class TFM_ServerInterface
|
|||||||
nameBans.remove(name);
|
nameBans.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void banUsername(String name, String reason, String source, Date expire_date)
|
@SuppressWarnings("unchecked")
|
||||||
|
public static void banUsername(String name, String reason, String source, Date expireDate)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase().trim();
|
name = name.toLowerCase().trim();
|
||||||
BanEntry ban_entry = new BanEntry(name);
|
|
||||||
if (expire_date != null)
|
if (TFM_SuperadminList.getSuperadminNames().contains(name))
|
||||||
{
|
{
|
||||||
ban_entry.setExpires(expire_date);
|
TFM_Log.info("Not banning username " + name + ": is superadmin");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String username : (List<String>) TFM_ConfigEntry.UNBANNABLE_USERNAMES.getList())
|
||||||
|
{
|
||||||
|
if (username.toLowerCase().trim().equals(name))
|
||||||
|
{
|
||||||
|
TFM_Log.info("Not banning username " + name + ": is unbannable as defined in config.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BanEntry entry = new BanEntry(name);
|
||||||
|
if (expireDate != null)
|
||||||
|
{
|
||||||
|
entry.setExpires(expireDate);
|
||||||
}
|
}
|
||||||
if (reason != null)
|
if (reason != null)
|
||||||
{
|
{
|
||||||
ban_entry.setReason(reason);
|
entry.setReason(reason);
|
||||||
}
|
}
|
||||||
if (source != null)
|
if (source != null)
|
||||||
{
|
{
|
||||||
ban_entry.setSource(source);
|
entry.setSource(source);
|
||||||
}
|
}
|
||||||
BanList nameBans = MinecraftServer.getServer().getPlayerList().getNameBans();
|
BanList nameBans = MinecraftServer.getServer().getPlayerList().getNameBans();
|
||||||
nameBans.add(ban_entry);
|
nameBans.add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNameBanned(String name)
|
public static boolean isNameBanned(String name)
|
||||||
@ -75,24 +94,24 @@ public class TFM_ServerInterface
|
|||||||
return nameBans.getEntries().containsKey(name);
|
return nameBans.getEntries().containsKey(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void banIP(String ip, String reason, String source, Date expire_date)
|
public static void banIP(String ip, String reason, String source, Date expireDate)
|
||||||
{
|
{
|
||||||
ip = ip.toLowerCase().trim();
|
ip = ip.toLowerCase().trim();
|
||||||
BanEntry ban_entry = new BanEntry(ip);
|
BanEntry entry = new BanEntry(ip);
|
||||||
if (expire_date != null)
|
if (expireDate != null)
|
||||||
{
|
{
|
||||||
ban_entry.setExpires(expire_date);
|
entry.setExpires(expireDate);
|
||||||
}
|
}
|
||||||
if (reason != null)
|
if (reason != null)
|
||||||
{
|
{
|
||||||
ban_entry.setReason(reason);
|
entry.setReason(reason);
|
||||||
}
|
}
|
||||||
if (source != null)
|
if (source != null)
|
||||||
{
|
{
|
||||||
ban_entry.setSource(source);
|
entry.setSource(source);
|
||||||
}
|
}
|
||||||
BanList ipBans = MinecraftServer.getServer().getPlayerList().getIPBans();
|
BanList ipBans = MinecraftServer.getServer().getPlayerList().getIPBans();
|
||||||
ipBans.add(ban_entry);
|
ipBans.add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unbanIP(String ip)
|
public static void unbanIP(String ip)
|
||||||
@ -110,7 +129,6 @@ public class TFM_ServerInterface
|
|||||||
return ipBans.getEntries().containsKey(ip);
|
return ipBans.getEntries().containsKey(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
public static int purgeWhitelist()
|
public static int purgeWhitelist()
|
||||||
{
|
{
|
||||||
Set whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
|
Set whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
|
||||||
@ -124,188 +142,219 @@ public class TFM_ServerInterface
|
|||||||
// this should supersede all other onPlayerLogin authentication on the TFM server.
|
// this should supersede all other onPlayerLogin authentication on the TFM server.
|
||||||
// when using the TFM CraftBukkit, CraftBukkit itself should not do any of its own authentication.
|
// when using the TFM CraftBukkit, CraftBukkit itself should not do any of its own authentication.
|
||||||
|
|
||||||
final Server server = TotalFreedomMod.plugin.getServer();
|
final Server server = TotalFreedomMod.server;
|
||||||
|
|
||||||
final PlayerList player_list = MinecraftServer.getServer().getPlayerList();
|
final PlayerList playerList = MinecraftServer.getServer().getPlayerList();
|
||||||
final BanList banByIP = player_list.getIPBans();
|
final BanList ipBans = playerList.getIPBans();
|
||||||
final BanList banByName = player_list.getNameBans();
|
final BanList nameBans = playerList.getNameBans();
|
||||||
|
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
final String player_name = player.getName();
|
final String username = player.getName();
|
||||||
final String player_ip = event.getAddress().getHostAddress().trim().toLowerCase();
|
final String ip = event.getAddress().getHostAddress().trim();
|
||||||
|
|
||||||
if (player_name.trim().length() <= 2)
|
if (username.trim().length() <= 2)
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is too short (must be at least 3 characters long).");
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is too short (must be at least 3 characters long).");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (Pattern.compile("[^a-zA-Z0-9\\-\\.\\_]").matcher(player_name).find())
|
else if (Pattern.compile("[^a-zA-Z0-9\\-\\.\\_]").matcher(username).find())
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username contains invalid characters.");
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username contains invalid characters.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not safe to use TFM_Util.isUserSuperadmin for player logging in because player.getAddress() will return a null until after player login.
|
// not safe to use TFM_Util.isUserSuperadmin for player logging in because player.getAddress() will return a null until after player login.
|
||||||
boolean is_superadmin;
|
boolean isSuperadmin;
|
||||||
if (server.getOnlineMode())
|
if (server.getOnlineMode())
|
||||||
{
|
{
|
||||||
is_superadmin = TFM_SuperadminList.getSuperadminNames().contains(player_name.toLowerCase());
|
isSuperadmin = TFM_SuperadminList.getSuperadminNames().contains(username.toLowerCase());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
is_superadmin = TFM_SuperadminList.checkPartialSuperadminIP(player_ip, player_name.toLowerCase());
|
isSuperadmin = TFM_SuperadminList.checkPartialSuperadminIP(ip, username.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_superadmin)
|
// Validation below this point
|
||||||
|
|
||||||
|
if (!isSuperadmin) // non-admins
|
||||||
{
|
{
|
||||||
BanEntry ban_entry = null;
|
// banned-players.txt
|
||||||
|
if (nameBans.isBanned(username.toLowerCase()))
|
||||||
if (banByName.isBanned(player_name.toLowerCase()))
|
|
||||||
{
|
{
|
||||||
ban_entry = (BanEntry) banByName.getEntries().get(player_name.toLowerCase());
|
final BanEntry nameBan = (BanEntry) nameBans.getEntries().get(username.toLowerCase());
|
||||||
|
|
||||||
String kick_message = ChatColor.RED + "You are banned from this server.";
|
String kickMessage = ChatColor.RED + "You are temporarily banned from this server.\nAppeal at http://totalfreedom.boards.net/.";
|
||||||
if (ban_entry != null)
|
if (nameBan != null)
|
||||||
{
|
{
|
||||||
kick_message = kick_message + "\nReason: " + ban_entry.getReason();
|
kickMessage = kickMessage + "\nReason: " + nameBan.getReason();
|
||||||
if (ban_entry.getExpires() != null)
|
if (nameBan.getExpires() != null)
|
||||||
{
|
{
|
||||||
kick_message = kick_message + "\nYour ban will be removed on " + date_format.format(ban_entry.getExpires());
|
kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(nameBan.getExpires());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kick_message);
|
event.disallow(Result.KICK_OTHER, kickMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean is_ip_banned = false;
|
// banned-ips.txt
|
||||||
|
final Iterator ipBansIt = ipBans.getEntries().keySet().iterator();
|
||||||
@SuppressWarnings("rawtypes")
|
boolean isIpBanned = false;
|
||||||
Iterator ip_bans = banByIP.getEntries().keySet().iterator();
|
BanEntry ipBan = null;
|
||||||
while (ip_bans.hasNext())
|
while (ipBansIt.hasNext())
|
||||||
{
|
{
|
||||||
String test_ip = (String) ip_bans.next();
|
String testIp = (String) ipBansIt.next();
|
||||||
|
|
||||||
if (!test_ip.matches("^\\d{1,3}\\.\\d{1,3}\\.(\\d{1,3}|\\*)\\.(\\d{1,3}|\\*)$"))
|
if (!testIp.matches("^\\d{1,3}\\.\\d{1,3}\\.(\\d{1,3}|\\*)\\.(\\d{1,3}|\\*)$"))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player_ip.equals(test_ip))
|
if (ip.equals(testIp))
|
||||||
{
|
{
|
||||||
ban_entry = (BanEntry) banByIP.getEntries().get(test_ip);
|
isIpBanned = true;
|
||||||
is_ip_banned = true;
|
ipBan = (BanEntry) ipBans.getEntries().get(testIp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_Util.fuzzyIpMatch(test_ip, player_ip, 4))
|
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
|
||||||
{
|
{
|
||||||
ban_entry = (BanEntry) banByIP.getEntries().get(test_ip);
|
isIpBanned = true;
|
||||||
is_ip_banned = true;
|
ipBan = (BanEntry) ipBans.getEntries().get(testIp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_ip_banned)
|
if (isIpBanned)
|
||||||
{
|
{
|
||||||
String kick_message = ChatColor.RED + "Your IP address is banned from this server.";
|
String kickMessage = ChatColor.RED + "Your IP address is temporarily banned from this server.\nAppeal at http://totalfreedom.boards.net/.";
|
||||||
if (ban_entry != null)
|
if (ipBan != null)
|
||||||
{
|
{
|
||||||
kick_message = kick_message + "\nReason: " + ban_entry.getReason();
|
kickMessage = kickMessage + "\nReason: " + ipBan.getReason();
|
||||||
if (ban_entry.getExpires() != null)
|
if (ipBan.getExpires() != null)
|
||||||
{
|
{
|
||||||
kick_message = kick_message + "\nYour ban will be removed on " + date_format.format(ban_entry.getExpires());
|
kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(ipBan.getExpires());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kick_message);
|
event.disallow(Result.KICK_OTHER, kickMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String test_player : TotalFreedomMod.permbanned_players)
|
// permban.yml - ips
|
||||||
|
for (String testIp : TotalFreedomMod.permbannedIps)
|
||||||
{
|
{
|
||||||
if (test_player.equalsIgnoreCase(player_name))
|
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server.\nRelease procedures are available at http://bit.ly/PermBan");
|
event.disallow(Result.KICK_OTHER, ChatColor.RED + "Your IP address is permanently banned from this server.\nRelease procedures are available at http://bit.ly/TF_PermBan");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String test_ip : TotalFreedomMod.permbanned_ips)
|
// permban.yml - names
|
||||||
|
for (String testPlayer : TotalFreedomMod.permbannedPlayers)
|
||||||
{
|
{
|
||||||
if (TFM_Util.fuzzyIpMatch(test_ip, player_ip, 4))
|
if (testPlayer.equalsIgnoreCase(username))
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP address is permanently banned from this server.\nRelease procedures are available at http://bit.ly/PermBan");
|
event.disallow(Result.KICK_OTHER, ChatColor.RED + "Your username is permanently banned from this server.\nRelease procedures are available at http://bit.ly/TF_PermBan");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Server full check
|
||||||
if (server.getOnlinePlayers().length >= server.getMaxPlayers())
|
if (server.getOnlinePlayers().length >= server.getMaxPlayers())
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, but this server is full.");
|
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, but this server is full.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Admin-only mode
|
||||||
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is temporarily open to admins only.");
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is temporarily open to admins only.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lockdown mode
|
||||||
if (TotalFreedomMod.lockdownEnabled)
|
if (TotalFreedomMod.lockdownEnabled)
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is currently in lockdown mode.");
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is currently in lockdown mode.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player_list.hasWhitelist)
|
// Whitelist check
|
||||||
|
if (playerList.hasWhitelist)
|
||||||
{
|
{
|
||||||
if (!player_list.getWhitelisted().contains(player_name.toLowerCase()))
|
if (!playerList.getWhitelisted().contains(username.toLowerCase()))
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Username already logged in check
|
||||||
for (Player test_player : server.getOnlinePlayers())
|
for (Player test_player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (test_player.getName().equalsIgnoreCase(player_name))
|
if (test_player.getName().equalsIgnoreCase(username))
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else // Player is superadmin
|
||||||
{
|
{
|
||||||
for (Player test_player : server.getOnlinePlayers())
|
// force-allow superadmins to log in
|
||||||
|
event.allow();
|
||||||
|
|
||||||
|
if (isIPBanned(ip))
|
||||||
{
|
{
|
||||||
if (test_player.getName().equalsIgnoreCase(player_name))
|
unbanIP(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNameBanned(username))
|
||||||
|
{
|
||||||
|
unbanUsername(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player testPlayer : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
if (testPlayer.getName().equalsIgnoreCase(username))
|
||||||
{
|
{
|
||||||
test_player.kickPlayer("An admin just logged in with the username you are using.");
|
testPlayer.kickPlayer("An admin just logged in with the username you are using.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean can_kick = true; // if the server is full of superadmins, however unlikely that might be, this will prevent an infinite loop.
|
int count = server.getOnlinePlayers().length;
|
||||||
while (server.getOnlinePlayers().length >= server.getMaxPlayers() && can_kick)
|
if (count >= server.getMaxPlayers())
|
||||||
{
|
{
|
||||||
can_kick = false;
|
for (Player p : server.getOnlinePlayers())
|
||||||
for (Player test_player : server.getOnlinePlayers())
|
|
||||||
{
|
{
|
||||||
if (!TFM_SuperadminList.isUserSuperadmin(test_player))
|
if (!TFM_SuperadminList.isUserSuperadmin(p))
|
||||||
|
{
|
||||||
|
p.kickPlayer("You have been kicked to free up room for an admin.");
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count < server.getMaxPlayers())
|
||||||
{
|
{
|
||||||
can_kick = true;
|
|
||||||
test_player.kickPlayer("You have been kicked to free up room for an admin.");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TotalFreedomMod.lockdownEnabled)
|
if (count >= server.getMaxPlayers())
|
||||||
{
|
{
|
||||||
TFM_Util.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "The server is full and a player could not be kicked, sorry!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TotalFreedomMod.lockdownEnabled)
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,10 @@ package me.StevenLawson.TotalFreedomMod;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -17,22 +19,45 @@ import org.json.simple.JSONValue;
|
|||||||
|
|
||||||
public class TFM_ServiceChecker
|
public class TFM_ServiceChecker
|
||||||
{
|
{
|
||||||
public final Map<String, TFM_ServiceChecker_ServiceStatus> services = new HashMap<String, TFM_ServiceChecker_ServiceStatus>();
|
public final Map<String, ServiceStatus> services = new HashMap<String, ServiceStatus>();
|
||||||
public String lastCheck = "Unknown";
|
private URL url;
|
||||||
public String version = "1.0-Mojang";
|
private String lastCheck = "Unknown";
|
||||||
|
private String version = "1.0-Mojang";
|
||||||
|
|
||||||
public TFM_ServiceChecker()
|
public TFM_ServiceChecker()
|
||||||
{
|
{
|
||||||
services.put("minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft.net"));
|
services.put("minecraft.net", new ServiceStatus("Minecraft.net"));
|
||||||
services.put("account.mojang.com", new TFM_ServiceChecker_ServiceStatus("Mojang Account Website"));
|
services.put("account.mojang.com", new ServiceStatus("Mojang Account Website"));
|
||||||
services.put("authserver.mojang.com", new TFM_ServiceChecker_ServiceStatus("Mojang Authentication"));
|
services.put("authserver.mojang.com", new ServiceStatus("Mojang Authentication"));
|
||||||
services.put("skins.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Skins"));
|
services.put("sessionserver.mojang.com", new ServiceStatus("Mojang Multiplayer sessions"));
|
||||||
services.put("auth.mojang.com", new TFM_ServiceChecker_ServiceStatus("Mojang Authentiation (Legacy)"));
|
services.put("skins.minecraft.net", new ServiceStatus("Minecraft Skins"));
|
||||||
services.put("login.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Logins (Legacy)"));
|
services.put("auth.mojang.com", new ServiceStatus("Mojang Authentiation (Legacy)"));
|
||||||
services.put("session.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Sessions (Legacy)"));
|
services.put("login.minecraft.net", new ServiceStatus("Minecraft Logins (Legacy)"));
|
||||||
|
services.put("session.minecraft.net", new ServiceStatus("Minecraft Sessions (Legacy)"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start()
|
||||||
|
{
|
||||||
|
final String serviceCheckerURL = TFM_ConfigEntry.SERVICE_CHECKER_URL.getString();
|
||||||
|
|
||||||
|
if (serviceCheckerURL == null || serviceCheckerURL.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
url = new URL(serviceCheckerURL);
|
||||||
|
}
|
||||||
|
catch (MalformedURLException ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe("Invalid ServiceChecker URL, disabling service checker");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getUpdateRunnable().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 40L, TotalFreedomMod.SERVICE_CHECKER_RATE * 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public BukkitRunnable getUpdateRunnable()
|
public BukkitRunnable getUpdateRunnable()
|
||||||
{
|
{
|
||||||
return new BukkitRunnable()
|
return new BukkitRunnable()
|
||||||
@ -40,78 +65,92 @@ public class TFM_ServiceChecker
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
final String serviceCheckerURL = TFM_ConfigEntry.SERVICE_CHECKER_URL.getString();
|
if (url == null)
|
||||||
|
|
||||||
if (serviceCheckerURL == null || serviceCheckerURL.isEmpty())
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final JSONArray statusJson;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL mojang_status = new URL(serviceCheckerURL);
|
final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(mojang_status.openStream()));
|
statusJson = (JSONArray) JSONValue.parse(in.readLine());
|
||||||
JSONArray status_json = (JSONArray) JSONValue.parse(in.readLine());
|
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
TFM_ServiceChecker serviceChecker = TFM_ServiceChecker.getInstance();
|
|
||||||
|
|
||||||
Iterator status_it = status_json.iterator();
|
|
||||||
while (status_it.hasNext())
|
|
||||||
{
|
|
||||||
JSONObject service = (JSONObject) status_it.next();
|
|
||||||
Iterator service_it = service.entrySet().iterator();
|
|
||||||
while (service_it.hasNext())
|
|
||||||
{
|
|
||||||
Entry<String, String> pair = (Entry<String, String>) service_it.next();
|
|
||||||
|
|
||||||
if ("lastcheck".equals(pair.getKey()))
|
|
||||||
{
|
|
||||||
serviceChecker.lastCheck = pair.getValue();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("version".equals(pair.getKey()))
|
|
||||||
{
|
|
||||||
serviceChecker.version = pair.getValue();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pair.getValue().contains(":"))
|
|
||||||
{
|
|
||||||
String[] statusString = pair.getValue().split(":");
|
|
||||||
TFM_ServiceChecker_ServiceStatus status = serviceChecker.services.get(pair.getKey());
|
|
||||||
status.setColor(statusString[0]);
|
|
||||||
status.setMessage(statusString[1]);
|
|
||||||
status.setUptime(statusString[2]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TFM_ServiceChecker_ServiceStatus status = serviceChecker.services.get(pair.getKey());
|
|
||||||
status.setColor(pair.getValue());
|
|
||||||
status.setMessage(("red".equals(pair.getValue()) ? "Offline" : ("yellow".equals(pair.getValue()) ? "Problem" : "Online")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe("Error updating mojang services from " + serviceCheckerURL);
|
TFM_Log.severe("Error updating mojang services from " + url);
|
||||||
TFM_Log.severe(ex);
|
TFM_Log.severe(ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Iterator status = statusJson.iterator();
|
||||||
|
while (status.hasNext())
|
||||||
|
{
|
||||||
|
final Iterator serviceIt = ((JSONObject) status.next()).entrySet().iterator();
|
||||||
|
while (serviceIt.hasNext())
|
||||||
|
{
|
||||||
|
final Entry<String, String> pair = (Entry<String, String>) serviceIt.next();
|
||||||
|
|
||||||
|
if ("lastcheck".equals(pair.getKey()))
|
||||||
|
{
|
||||||
|
lastCheck = pair.getValue();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("version".equals(pair.getKey()))
|
||||||
|
{
|
||||||
|
version = pair.getValue();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ServiceStatus service = services.get(pair.getKey());
|
||||||
|
if (service == null)
|
||||||
|
{
|
||||||
|
TFM_Log.warning("ServiceChecker found unknown service: " + pair.getKey());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pair.getValue().contains(":"))
|
||||||
|
{
|
||||||
|
String[] statusString = pair.getValue().split(":");
|
||||||
|
service.setColor(statusString[0]);
|
||||||
|
service.setMessage(statusString[1]);
|
||||||
|
service.setUptime(statusString[2]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
service.setColor(pair.getValue());
|
||||||
|
service.setMessage(("red".equals(pair.getValue()) ? "Offline" : ("yellow".equals(pair.getValue()) ? "Problem" : "Online")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lastCheck.equals("Unknown"))
|
||||||
|
{
|
||||||
|
lastCheck = TFM_Util.dateToString(new Date());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TFM_ServiceChecker_ServiceStatus> getAllStatuses()
|
public List<ServiceStatus> getAllStatuses()
|
||||||
{
|
{
|
||||||
List<TFM_ServiceChecker_ServiceStatus> ServicesList = new ArrayList<TFM_ServiceChecker_ServiceStatus>();
|
List<ServiceStatus> servicesList = new ArrayList<ServiceStatus>();
|
||||||
for (String key : services.keySet())
|
for (String key : services.keySet())
|
||||||
{
|
{
|
||||||
ServicesList.add(services.get(key));
|
servicesList.add(services.get(key));
|
||||||
}
|
}
|
||||||
return ServicesList;
|
return servicesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastCheck()
|
||||||
|
{
|
||||||
|
return lastCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_ServiceChecker getInstance()
|
public static TFM_ServiceChecker getInstance()
|
||||||
@ -124,14 +163,14 @@ public class TFM_ServiceChecker
|
|||||||
private static final TFM_ServiceChecker INSTANCE = new TFM_ServiceChecker();
|
private static final TFM_ServiceChecker INSTANCE = new TFM_ServiceChecker();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TFM_ServiceChecker_ServiceStatus
|
public static class ServiceStatus
|
||||||
{
|
{
|
||||||
private String name;
|
private String name;
|
||||||
private String uptime = "100.0"; // skins.minecraft.net, minecraft.net, etc..
|
private String uptime = "100.0"; // skins.minecraft.net, minecraft.net, etc..
|
||||||
private ChatColor color = ChatColor.DARK_GREEN;
|
private ChatColor color = ChatColor.DARK_GREEN;
|
||||||
private String message = "Online"; // Online, Offline, Quite Slow, 404 Error, 500 Error, etc..
|
private String message = "Online"; // Online, Offline, Quite Slow, 404 Error, 500 Error, etc..
|
||||||
|
|
||||||
public TFM_ServiceChecker_ServiceStatus(String name)
|
public ServiceStatus(String name)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
@ -2,39 +2,42 @@ package me.StevenLawson.TotalFreedomMod;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
public class TFM_Superadmin
|
public class TFM_Superadmin
|
||||||
{
|
{
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String custom_login_message;
|
private final String loginMessage;
|
||||||
private final boolean is_senior_admin;
|
private final boolean isSeniorAdmin;
|
||||||
private final List<String> console_aliases;
|
private final boolean isTelnetAdmin;
|
||||||
private List<String> ips;
|
private final List<String> consoleAliases;
|
||||||
private Date last_login;
|
private final List<String> ips;
|
||||||
private boolean is_activated;
|
private Date lastLogin;
|
||||||
|
private boolean isActivated;
|
||||||
|
|
||||||
public TFM_Superadmin(String name, List<String> ips, Date last_login, String custom_login_message, boolean is_senior_admin, List<String> console_aliases, boolean is_activated)
|
public TFM_Superadmin(String name, List<String> ips, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, List<String> consoleAliases, boolean isActivated)
|
||||||
{
|
{
|
||||||
this.name = name.toLowerCase();
|
this.name = name.toLowerCase();
|
||||||
this.ips = ips;
|
this.ips = ips;
|
||||||
this.last_login = last_login;
|
this.lastLogin = lastLogin;
|
||||||
this.custom_login_message = custom_login_message;
|
this.loginMessage = loginMessage;
|
||||||
this.is_senior_admin = is_senior_admin;
|
this.isSeniorAdmin = isSeniorAdmin;
|
||||||
this.console_aliases = console_aliases;
|
this.isTelnetAdmin = isTelnetAdmin;
|
||||||
this.is_activated = is_activated;
|
this.consoleAliases = consoleAliases;
|
||||||
|
this.isActivated = isActivated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TFM_Superadmin(String name, ConfigurationSection section)
|
public TFM_Superadmin(String name, ConfigurationSection section)
|
||||||
{
|
{
|
||||||
this.name = name.toLowerCase();
|
this.name = name.toLowerCase();
|
||||||
this.ips = section.getStringList("ips");
|
this.ips = section.getStringList("ips");
|
||||||
this.last_login = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L))));
|
this.lastLogin = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L))));
|
||||||
this.custom_login_message = section.getString("custom_login_message", "");
|
this.loginMessage = section.getString("custom_login_message", "");
|
||||||
this.is_senior_admin = section.getBoolean("is_senior_admin", false);
|
this.isSeniorAdmin = section.getBoolean("is_senior_admin", false);
|
||||||
this.console_aliases = section.getStringList("console_aliases");
|
this.isTelnetAdmin = section.getBoolean("is_telnet_admin", false);
|
||||||
this.is_activated = section.getBoolean("is_activated", true);
|
this.consoleAliases = section.getStringList("console_aliases");
|
||||||
|
this.isActivated = section.getBoolean("is_activated", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,11 +49,12 @@ public class TFM_Superadmin
|
|||||||
{
|
{
|
||||||
output.append("Name: ").append(this.name).append("\n");
|
output.append("Name: ").append(this.name).append("\n");
|
||||||
output.append("- IPs: ").append(StringUtils.join(this.ips, ", ")).append("\n");
|
output.append("- IPs: ").append(StringUtils.join(this.ips, ", ")).append("\n");
|
||||||
output.append("- Last Login: ").append(TFM_Util.dateToString(this.last_login)).append("\n");
|
output.append("- Last Login: ").append(TFM_Util.dateToString(this.lastLogin)).append("\n");
|
||||||
output.append("- Custom Login Message: ").append(this.custom_login_message).append("\n");
|
output.append("- Custom Login Message: ").append(this.loginMessage).append("\n");
|
||||||
output.append("- Is Senior Admin: ").append(this.is_senior_admin).append("\n");
|
output.append("- Is Senior Admin: ").append(this.isSeniorAdmin).append("\n");
|
||||||
output.append("- Console Aliases: ").append(StringUtils.join(this.console_aliases, ", ")).append("\n");
|
output.append("- Is Telnet Admin: ").append(this.isTelnetAdmin).append("\n");
|
||||||
output.append("- Is Activated: ").append(this.is_activated);
|
output.append("- Console Aliases: ").append(StringUtils.join(this.consoleAliases, ", ")).append("\n");
|
||||||
|
output.append("- Is Activated: ").append(this.isActivated);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -72,41 +76,41 @@ public class TFM_Superadmin
|
|||||||
|
|
||||||
public Date getLastLogin()
|
public Date getLastLogin()
|
||||||
{
|
{
|
||||||
return last_login;
|
return lastLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCustomLoginMessage()
|
public String getCustomLoginMessage()
|
||||||
{
|
{
|
||||||
return custom_login_message;
|
return loginMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSeniorAdmin()
|
public boolean isSeniorAdmin()
|
||||||
{
|
{
|
||||||
return is_senior_admin;
|
return isSeniorAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTelnetAdmin()
|
||||||
|
{
|
||||||
|
return isTelnetAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getConsoleAliases()
|
public List<String> getConsoleAliases()
|
||||||
{
|
{
|
||||||
return console_aliases;
|
return consoleAliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIps(List<String> ips)
|
public void setLastLogin(Date lastLogin)
|
||||||
{
|
{
|
||||||
this.ips = ips;
|
this.lastLogin = lastLogin;
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastLogin(Date last_login)
|
|
||||||
{
|
|
||||||
this.last_login = last_login;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActivated()
|
public boolean isActivated()
|
||||||
{
|
{
|
||||||
return is_activated;
|
return isActivated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActivated(boolean is_activated)
|
public void setActivated(boolean isActivated)
|
||||||
{
|
{
|
||||||
this.is_activated = is_activated;
|
this.isActivated = isActivated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,12 @@ import org.bukkit.util.FileUtil;
|
|||||||
|
|
||||||
public class TFM_SuperadminList
|
public class TFM_SuperadminList
|
||||||
{
|
{
|
||||||
private static Map<String, TFM_Superadmin> superadminList = new HashMap<String, TFM_Superadmin>();
|
private static final Map<String, TFM_Superadmin> superadminList = new HashMap<String, TFM_Superadmin>();
|
||||||
private static List<String> superadminNames = new ArrayList<String>();
|
private static List<String> superadminNames = new ArrayList<String>();
|
||||||
|
private static List<String> senioradminNames = new ArrayList<String>();
|
||||||
|
private static List<String> telnetadminNames = new ArrayList<String>();
|
||||||
private static List<String> superadminIPs = new ArrayList<String>();
|
private static List<String> superadminIPs = new ArrayList<String>();
|
||||||
private static List<String> seniorAdminNames = new ArrayList<String>();
|
private static int cleanThreshold = 24 * 7; // 1 Week in hours
|
||||||
private static int clean_threshold_hours = 24 * 7; // 1 Week
|
|
||||||
|
|
||||||
private TFM_SuperadminList()
|
private TFM_SuperadminList()
|
||||||
{
|
{
|
||||||
@ -42,16 +43,26 @@ public class TFM_SuperadminList
|
|||||||
return superadminNames;
|
return superadminNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getTelnetadminNames()
|
||||||
|
{
|
||||||
|
return telnetadminNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getSenioradminNames()
|
||||||
|
{
|
||||||
|
return senioradminNames;
|
||||||
|
}
|
||||||
|
|
||||||
public static void loadSuperadminList()
|
public static void loadSuperadminList()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
superadminList.clear();
|
superadminList.clear();
|
||||||
|
|
||||||
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
|
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE);
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||||
|
|
||||||
clean_threshold_hours = config.getInt("clean_threshold_hours", clean_threshold_hours);
|
cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold);
|
||||||
|
|
||||||
if (config.isConfigurationSection("superadmins"))
|
if (config.isConfigurationSection("superadmins"))
|
||||||
{
|
{
|
||||||
@ -86,20 +97,21 @@ public class TFM_SuperadminList
|
|||||||
public static void updateIndexLists()
|
public static void updateIndexLists()
|
||||||
{
|
{
|
||||||
superadminNames.clear();
|
superadminNames.clear();
|
||||||
|
telnetadminNames.clear();
|
||||||
|
senioradminNames.clear();
|
||||||
superadminIPs.clear();
|
superadminIPs.clear();
|
||||||
seniorAdminNames.clear();
|
|
||||||
|
|
||||||
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
Entry<String, TFM_Superadmin> pair = it.next();
|
Entry<String, TFM_Superadmin> pair = it.next();
|
||||||
|
|
||||||
String admin_name = pair.getKey().toLowerCase();
|
String name = pair.getKey().toLowerCase();
|
||||||
TFM_Superadmin superadmin = pair.getValue();
|
TFM_Superadmin superadmin = pair.getValue();
|
||||||
|
|
||||||
if (superadmin.isActivated())
|
if (superadmin.isActivated())
|
||||||
{
|
{
|
||||||
superadminNames.add(admin_name);
|
superadminNames.add(name);
|
||||||
|
|
||||||
for (String ip : superadmin.getIps())
|
for (String ip : superadmin.getIps())
|
||||||
{
|
{
|
||||||
@ -108,21 +120,27 @@ public class TFM_SuperadminList
|
|||||||
|
|
||||||
if (superadmin.isSeniorAdmin())
|
if (superadmin.isSeniorAdmin())
|
||||||
{
|
{
|
||||||
seniorAdminNames.add(admin_name);
|
senioradminNames.add(name);
|
||||||
|
|
||||||
for (String console_alias : superadmin.getConsoleAliases())
|
for (String console_alias : superadmin.getConsoleAliases())
|
||||||
{
|
{
|
||||||
seniorAdminNames.add(console_alias.toLowerCase());
|
senioradminNames.add(console_alias.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (superadmin.isTelnetAdmin())
|
||||||
|
{
|
||||||
|
telnetadminNames.add(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
superadminNames = TFM_Util.removeDuplicates(superadminNames);
|
superadminNames = TFM_Util.removeDuplicates(superadminNames);
|
||||||
|
telnetadminNames = TFM_Util.removeDuplicates(telnetadminNames);
|
||||||
|
senioradminNames = TFM_Util.removeDuplicates(senioradminNames);
|
||||||
superadminIPs = TFM_Util.removeDuplicates(superadminIPs);
|
superadminIPs = TFM_Util.removeDuplicates(superadminIPs);
|
||||||
seniorAdminNames = TFM_Util.removeDuplicates(seniorAdminNames);
|
|
||||||
|
|
||||||
TFM_AdminWorld.getInstance().wipeSuperadminCache();
|
TFM_AdminWorld.getInstance().wipeAccessCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveSuperadminList()
|
public static void saveSuperadminList()
|
||||||
@ -133,7 +151,7 @@ public class TFM_SuperadminList
|
|||||||
|
|
||||||
YamlConfiguration config = new YamlConfiguration();
|
YamlConfiguration config = new YamlConfiguration();
|
||||||
|
|
||||||
config.set("clean_threshold_hours", clean_threshold_hours);
|
config.set("clean_threshold_hours", cleanThreshold);
|
||||||
|
|
||||||
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
@ -147,6 +165,7 @@ public class TFM_SuperadminList
|
|||||||
config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
|
config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
|
||||||
config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage());
|
config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage());
|
||||||
config.set("superadmins." + admin_name + ".is_senior_admin", superadmin.isSeniorAdmin());
|
config.set("superadmins." + admin_name + ".is_senior_admin", superadmin.isSeniorAdmin());
|
||||||
|
config.set("superadmins." + admin_name + ".is_telnet_admin", superadmin.isTelnetAdmin());
|
||||||
config.set("superadmins." + admin_name + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases()));
|
config.set("superadmins." + admin_name + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases()));
|
||||||
config.set("superadmins." + admin_name + ".is_activated", superadmin.isActivated());
|
config.set("superadmins." + admin_name + ".is_activated", superadmin.isActivated());
|
||||||
}
|
}
|
||||||
@ -159,13 +178,41 @@ public class TFM_SuperadminList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_Superadmin getAdminEntry(String admin_name)
|
public static TFM_Superadmin getAdminEntry(Player player)
|
||||||
{
|
{
|
||||||
admin_name = admin_name.toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
|
|
||||||
if (superadminList.containsKey(admin_name))
|
if (Bukkit.getOnlineMode())
|
||||||
{
|
{
|
||||||
return superadminList.get(admin_name);
|
if (superadminList.containsKey(name))
|
||||||
|
{
|
||||||
|
return superadminList.get(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final String ip = player.getAddress().getAddress().getHostAddress().trim();
|
||||||
|
if (ip != null && !ip.isEmpty())
|
||||||
|
{
|
||||||
|
return getAdminEntryByIP(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static TFM_Superadmin getAdminEntry(String name)
|
||||||
|
{
|
||||||
|
name = name.toLowerCase();
|
||||||
|
|
||||||
|
if (superadminList.containsKey(name))
|
||||||
|
{
|
||||||
|
return superadminList.get(name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -173,21 +220,34 @@ public class TFM_SuperadminList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_Superadmin getAdminEntry(Player player)
|
public static TFM_Superadmin getAdminEntryByIP(String ip)
|
||||||
{
|
{
|
||||||
return getAdminEntry(player.getName().toLowerCase());
|
return getAdminEntryByIP(ip, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_Superadmin getAdminEntryByIP(String ip)
|
public static TFM_Superadmin getAdminEntryByIP(String needleIP, boolean fuzzy)
|
||||||
{
|
{
|
||||||
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
Entry<String, TFM_Superadmin> pair = it.next();
|
Entry<String, TFM_Superadmin> pair = it.next();
|
||||||
TFM_Superadmin superadmin = pair.getValue();
|
TFM_Superadmin superadmin = pair.getValue();
|
||||||
if (superadmin.getIps().contains(ip))
|
if (fuzzy)
|
||||||
{
|
{
|
||||||
return superadmin;
|
for (String haystackIP : superadmin.getIps())
|
||||||
|
{
|
||||||
|
if (TFM_Util.fuzzyIpMatch(needleIP, haystackIP, 3))
|
||||||
|
{
|
||||||
|
return superadmin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (superadmin.getIps().contains(needleIP))
|
||||||
|
{
|
||||||
|
return superadmin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -208,9 +268,9 @@ public class TFM_SuperadminList
|
|||||||
return isSeniorAdmin(user, false);
|
return isSeniorAdmin(user, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSeniorAdmin(CommandSender user, boolean verify_is_superadmin)
|
public static boolean isSeniorAdmin(CommandSender user, boolean verifySuperadmin)
|
||||||
{
|
{
|
||||||
if (verify_is_superadmin)
|
if (verifySuperadmin)
|
||||||
{
|
{
|
||||||
if (!isUserSuperadmin(user))
|
if (!isUserSuperadmin(user))
|
||||||
{
|
{
|
||||||
@ -218,17 +278,17 @@ public class TFM_SuperadminList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String user_name = user.getName().toLowerCase();
|
String username = user.getName().toLowerCase();
|
||||||
|
|
||||||
if (!(user instanceof Player))
|
if (!(user instanceof Player))
|
||||||
{
|
{
|
||||||
return seniorAdminNames.contains(user_name);
|
return senioradminNames.contains(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Superadmin admin_entry = getAdminEntry((Player) user);
|
TFM_Superadmin entry = getAdminEntry((Player) user);
|
||||||
if (admin_entry != null)
|
if (entry != null)
|
||||||
{
|
{
|
||||||
return admin_entry.isSeniorAdmin();
|
return entry.isSeniorAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -251,10 +311,10 @@ public class TFM_SuperadminList
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String user_ip = ((Player) user).getAddress().getAddress().getHostAddress();
|
String ip = ((Player) user).getAddress().getAddress().getHostAddress();
|
||||||
if (user_ip != null && !user_ip.isEmpty())
|
if (ip != null && !ip.isEmpty())
|
||||||
{
|
{
|
||||||
if (superadminIPs.contains(user_ip))
|
if (superadminIPs.contains(ip))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -268,39 +328,38 @@ public class TFM_SuperadminList
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkPartialSuperadminIP(String user_ip, String user_name)
|
public static boolean checkPartialSuperadminIP(String ip, String name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
user_ip = user_ip.trim();
|
ip = ip.trim();
|
||||||
|
|
||||||
if (superadminIPs.contains(user_ip))
|
if (superadminIPs.contains(ip))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String match_ip = null;
|
String matchIp = null;
|
||||||
for (String test_ip : getSuperadminIPs())
|
for (String testIp : getSuperadminIPs())
|
||||||
{
|
{
|
||||||
if (TFM_Util.fuzzyIpMatch(user_ip, test_ip, 3))
|
if (TFM_Util.fuzzyIpMatch(ip, testIp, 3))
|
||||||
{
|
{
|
||||||
match_ip = test_ip;
|
matchIp = testIp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match_ip != null)
|
if (matchIp != null)
|
||||||
{
|
{
|
||||||
TFM_Superadmin admin_entry = getAdminEntryByIP(match_ip);
|
TFM_Superadmin entry = getAdminEntryByIP(matchIp);
|
||||||
|
|
||||||
if (admin_entry != null)
|
if (entry != null)
|
||||||
{
|
{
|
||||||
if (admin_entry.getName().equalsIgnoreCase(user_name))
|
if (entry.getName().equalsIgnoreCase(name))
|
||||||
{
|
{
|
||||||
List<String> ips = admin_entry.getIps();
|
List<String> ips = entry.getIps();
|
||||||
ips.add(user_ip);
|
ips.add(ip);
|
||||||
admin_entry.setIps(ips);
|
|
||||||
saveSuperadminList();
|
saveSuperadminList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,28 +393,23 @@ public class TFM_SuperadminList
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addSuperadmin(String admin_name, List<String> ips)
|
public static void addSuperadmin(String username, List<String> ips)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
admin_name = admin_name.toLowerCase();
|
username = username.toLowerCase();
|
||||||
|
|
||||||
if (superadminList.containsKey(admin_name))
|
if (superadminList.containsKey(username))
|
||||||
{
|
{
|
||||||
TFM_Superadmin superadmin = superadminList.get(admin_name);
|
TFM_Superadmin superadmin = superadminList.get(username);
|
||||||
superadmin.setActivated(true);
|
superadmin.setActivated(true);
|
||||||
superadmin.getIps().addAll(ips);
|
superadmin.getIps().addAll(ips);
|
||||||
superadmin.setLastLogin(new Date());
|
superadmin.setLastLogin(new Date());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Date last_login = new Date();
|
TFM_Superadmin superadmin = new TFM_Superadmin(username, ips, new Date(), "", false, false, new ArrayList<String>(), true);
|
||||||
String custom_login_message = "";
|
superadminList.put(username.toLowerCase(), superadmin);
|
||||||
boolean is_senior_admin = false;
|
|
||||||
List<String> console_aliases = new ArrayList<String>();
|
|
||||||
|
|
||||||
TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, ips, last_login, custom_login_message, is_senior_admin, console_aliases, true);
|
|
||||||
superadminList.put(admin_name.toLowerCase(), superadmin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveSuperadminList();
|
saveSuperadminList();
|
||||||
@ -368,26 +422,26 @@ public class TFM_SuperadminList
|
|||||||
|
|
||||||
public static void addSuperadmin(Player player)
|
public static void addSuperadmin(Player player)
|
||||||
{
|
{
|
||||||
String admin_name = player.getName().toLowerCase();
|
String username = player.getName().toLowerCase();
|
||||||
List<String> ips = Arrays.asList(player.getAddress().getAddress().getHostAddress());
|
List<String> ips = Arrays.asList(player.getAddress().getAddress().getHostAddress());
|
||||||
|
|
||||||
addSuperadmin(admin_name, ips);
|
addSuperadmin(username, ips);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addSuperadmin(String admin_name)
|
public static void addSuperadmin(String adminName)
|
||||||
{
|
{
|
||||||
addSuperadmin(admin_name, new ArrayList<String>());
|
addSuperadmin(adminName, new ArrayList<String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeSuperadmin(String admin_name)
|
public static void removeSuperadmin(String username)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
admin_name = admin_name.toLowerCase();
|
username = username.toLowerCase();
|
||||||
|
|
||||||
if (superadminList.containsKey(admin_name))
|
if (superadminList.containsKey(username))
|
||||||
{
|
{
|
||||||
TFM_Superadmin superadmin = superadminList.get(admin_name);
|
TFM_Superadmin superadmin = superadminList.get(username);
|
||||||
superadmin.setActivated(false);
|
superadmin.setActivated(false);
|
||||||
Command_logs.deactivateSuperadmin(superadmin);
|
Command_logs.deactivateSuperadmin(superadmin);
|
||||||
saveSuperadminList();
|
saveSuperadminList();
|
||||||
@ -415,19 +469,20 @@ public class TFM_SuperadminList
|
|||||||
TFM_Superadmin superadmin = pair.getValue();
|
TFM_Superadmin superadmin = pair.getValue();
|
||||||
if (superadmin.isActivated() && !superadmin.isSeniorAdmin())
|
if (superadmin.isActivated() && !superadmin.isSeniorAdmin())
|
||||||
{
|
{
|
||||||
Date last_login = superadmin.getLastLogin();
|
Date lastLogin = superadmin.getLastLogin();
|
||||||
|
|
||||||
long hours_since_login = TimeUnit.HOURS.convert(new Date().getTime() - last_login.getTime(), TimeUnit.MILLISECONDS);
|
long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
if (hours_since_login > clean_threshold_hours)
|
if (lastLoginHours > cleanThreshold)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction("TotalFreedomSystem", "Deactivating superadmin \"" + superadmin.getName() + "\", inactive for " + hours_since_login + " hours.", true);
|
TFM_Util.adminAction("TotalFreedomSystem", "Deactivating superadmin \"" + superadmin.getName() + "\", inactive for " + lastLoginHours + " hours.", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
superadmin.setActivated(false);
|
superadmin.setActivated(false);
|
||||||
Command_logs.deactivateSuperadmin(superadmin);
|
Command_logs.deactivateSuperadmin(superadmin);
|
||||||
|
TFM_TwitterHandler.getInstance().delTwitter(superadmin.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,17 +494,17 @@ public class TFM_SuperadminList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean verifyIdentity(String admin_name, String ip) throws Exception
|
public static boolean verifyIdentity(String username, String ip) throws Exception
|
||||||
{
|
{
|
||||||
if (Bukkit.getOnlineMode())
|
if (Bukkit.getOnlineMode())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Superadmin admin_entry = getAdminEntry(admin_name);
|
TFM_Superadmin entry = getAdminEntry(username);
|
||||||
if (admin_entry != null)
|
if (entry != null)
|
||||||
{
|
{
|
||||||
return admin_entry.getIps().contains(ip);
|
return entry.getIps().contains(ip);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,8 @@ import java.io.BufferedReader;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class TFM_TwitterHandler
|
public class TFM_TwitterHandler
|
||||||
{
|
{
|
||||||
@ -31,6 +32,39 @@ public class TFM_TwitterHandler
|
|||||||
return request("action=deltwitter&player=" + player);
|
return request("action=deltwitter&player=" + player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delTwitterVerbose(String targetName, CommandSender sender)
|
||||||
|
{
|
||||||
|
final String reply = delTwitter(targetName);
|
||||||
|
if ("ok".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from TwitterBot", true);
|
||||||
|
}
|
||||||
|
else if ("disabled".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
|
TFM_Util.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until it gets re-enabled", ChatColor.RED);
|
||||||
|
}
|
||||||
|
else if ("failed".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
|
TFM_Util.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED);
|
||||||
|
}
|
||||||
|
else if ("false".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
|
TFM_Util.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED);
|
||||||
|
}
|
||||||
|
else if ("cannotauth".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
|
TFM_Util.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED);
|
||||||
|
}
|
||||||
|
else if ("notfound".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, targetName + " did not have a twitter handle registered to their name.", ChatColor.GREEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String isEnabled()
|
public String isEnabled()
|
||||||
{
|
{
|
||||||
return request("action=getstatus");
|
return request("action=getstatus");
|
||||||
@ -61,7 +95,7 @@ public class TFM_TwitterHandler
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ExceptionUtils.getFullStackTrace(ex));
|
TFM_Log.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -32,11 +32,11 @@ public class TFM_UserList
|
|||||||
{
|
{
|
||||||
userlist.clear();
|
userlist.clear();
|
||||||
|
|
||||||
FileConfiguration saved_userlist = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), USERLIST_FILENAME));
|
FileConfiguration savedUserlist = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), USERLIST_FILENAME));
|
||||||
|
|
||||||
for (String username : saved_userlist.getKeys(false))
|
for (String username : savedUserlist.getKeys(false))
|
||||||
{
|
{
|
||||||
TFM_UserListEntry entry = new TFM_UserListEntry(username, saved_userlist.getStringList(username));
|
TFM_UserListEntry entry = new TFM_UserListEntry(username, savedUserlist.getStringList(username));
|
||||||
userlist.put(username, entry);
|
userlist.put(username, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,16 +56,16 @@ public class TFM_UserList
|
|||||||
|
|
||||||
private void exportList()
|
private void exportList()
|
||||||
{
|
{
|
||||||
FileConfiguration new_userlist = new YamlConfiguration();
|
FileConfiguration newUserlist = new YamlConfiguration();
|
||||||
|
|
||||||
for (TFM_UserListEntry entry : userlist.values())
|
for (TFM_UserListEntry entry : userlist.values())
|
||||||
{
|
{
|
||||||
new_userlist.set(entry.getUsername(), entry.getIpAddresses());
|
newUserlist.set(entry.getUsername(), entry.getIpAddresses());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
new_userlist.save(new File(plugin.getDataFolder(), USERLIST_FILENAME));
|
newUserlist.save(new File(plugin.getDataFolder(), USERLIST_FILENAME));
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
@ -87,7 +87,7 @@ public class TFM_UserList
|
|||||||
addUser(player.getName(), player.getAddress().getAddress().getHostAddress());
|
addUser(player.getName(), player.getAddress().getAddress().getHostAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUser(String username, String ip_address)
|
public void addUser(String username, String ip)
|
||||||
{
|
{
|
||||||
username = username.toLowerCase();
|
username = username.toLowerCase();
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ public class TFM_UserList
|
|||||||
|
|
||||||
userlist.put(username, entry);
|
userlist.put(username, entry);
|
||||||
|
|
||||||
if (entry.addIpAddress(ip_address))
|
if (entry.addIpAddress(ip))
|
||||||
{
|
{
|
||||||
exportList();
|
exportList();
|
||||||
}
|
}
|
||||||
@ -149,12 +149,12 @@ public class TFM_UserList
|
|||||||
public class TFM_UserListEntry
|
public class TFM_UserListEntry
|
||||||
{
|
{
|
||||||
private String username;
|
private String username;
|
||||||
private List<String> ip_addresses = new ArrayList<String>();
|
private List<String> ipAddresses = new ArrayList<String>();
|
||||||
|
|
||||||
public TFM_UserListEntry(String username, List<String> ip_addresses)
|
public TFM_UserListEntry(String username, List<String> ipAddresses)
|
||||||
{
|
{
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.ip_addresses = ip_addresses;
|
this.ipAddresses = ipAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TFM_UserListEntry(String username)
|
public TFM_UserListEntry(String username)
|
||||||
@ -164,7 +164,7 @@ public class TFM_UserList
|
|||||||
|
|
||||||
public List<String> getIpAddresses()
|
public List<String> getIpAddresses()
|
||||||
{
|
{
|
||||||
return ip_addresses;
|
return ipAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername()
|
public String getUsername()
|
||||||
@ -172,11 +172,11 @@ public class TFM_UserList
|
|||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addIpAddress(String ip_address)
|
public boolean addIpAddress(String ip)
|
||||||
{
|
{
|
||||||
if (!ip_addresses.contains(ip_address))
|
if (!ipAddresses.contains(ip))
|
||||||
{
|
{
|
||||||
ip_addresses.add(ip_address);
|
ipAddresses.add(ip);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,16 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
|
import com.sk89q.worldedit.LocalWorld;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class TFM_WorldEditBridge
|
public class TFM_WorldEditBridge
|
||||||
{
|
{
|
||||||
@ -111,6 +116,51 @@ public class TFM_WorldEditBridge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void validateSelection(final Player player)
|
||||||
|
{
|
||||||
|
if (TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final LocalSession session = getPlayerSession(player);
|
||||||
|
if (session != null)
|
||||||
|
{
|
||||||
|
final LocalWorld selectionWorld = session.getSelectionWorld();
|
||||||
|
final Region selection = session.getSelection(selectionWorld);
|
||||||
|
if (TFM_ProtectedArea.isInProtectedArea(
|
||||||
|
getBukkitVector(selection.getMinimumPoint()),
|
||||||
|
getBukkitVector(selection.getMaximumPoint()),
|
||||||
|
selectionWorld.getName()))
|
||||||
|
{
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
player.sendMessage(ChatColor.RED + "The region that you selected contained a protected area. Selection cleared.");
|
||||||
|
session.getRegionSelector(selectionWorld).clear();
|
||||||
|
}
|
||||||
|
}.runTaskLater(TotalFreedomMod.plugin, 1L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IncompleteRegionException ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static org.bukkit.util.Vector getBukkitVector(com.sk89q.worldedit.Vector worldEditVector)
|
||||||
|
{
|
||||||
|
return new org.bukkit.util.Vector(worldEditVector.getX(), worldEditVector.getY(), worldEditVector.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
public static TFM_WorldEditBridge getInstance()
|
public static TFM_WorldEditBridge getInstance()
|
||||||
{
|
{
|
||||||
return TFM_WorldEditBridgeHolder.INSTANCE;
|
return TFM_WorldEditBridgeHolder.INSTANCE;
|
||||||
|
@ -3,14 +3,18 @@ package me.StevenLawson.TotalFreedomMod;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
import java.util.logging.Logger;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPD_Manager;
|
||||||
import me.StevenLawson.TotalFreedomMod.Listener.*;
|
import me.StevenLawson.TotalFreedomMod.Listener.*;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
import net.minecraft.util.org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -44,11 +48,8 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
|
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
|
||||||
public static final String NOT_FROM_CONSOLE = "This command may not be used from the console.";
|
public static final String NOT_FROM_CONSOLE = "This command may not be used from the console.";
|
||||||
//
|
//
|
||||||
public static final Server server = Bukkit.getServer();
|
public static Server server = null;
|
||||||
public static TotalFreedomMod plugin = null;
|
public static TotalFreedomMod plugin = null;
|
||||||
public static File plugin_file = null;
|
|
||||||
//
|
|
||||||
public static Logger logger;
|
|
||||||
//
|
//
|
||||||
public static String pluginName = "";
|
public static String pluginName = "";
|
||||||
public static String pluginVersion = "";
|
public static String pluginVersion = "";
|
||||||
@ -61,22 +62,26 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
public static boolean lockdownEnabled = false;
|
public static boolean lockdownEnabled = false;
|
||||||
public static Map<Player, Double> fuckoffEnabledFor = new HashMap<Player, Double>();
|
public static Map<Player, Double> fuckoffEnabledFor = new HashMap<Player, Double>();
|
||||||
//
|
//
|
||||||
public static List<String> permbanned_players = new ArrayList<String>();
|
public static List<String> permbannedPlayers = new ArrayList<String>();
|
||||||
public static List<String> permbanned_ips = new ArrayList<String>();
|
public static List<String> permbannedIps = new ArrayList<String>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad()
|
||||||
|
{
|
||||||
|
TotalFreedomMod.plugin = this;
|
||||||
|
TotalFreedomMod.server = plugin.getServer();
|
||||||
|
TotalFreedomMod.pluginName = plugin.getDescription().getName();
|
||||||
|
TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion();
|
||||||
|
|
||||||
|
TFM_Log.setPluginLogger(plugin.getLogger());
|
||||||
|
TFM_Log.setServerLogger(server.getLogger());
|
||||||
|
|
||||||
|
setAppProperties();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
TotalFreedomMod.plugin = this;
|
|
||||||
TotalFreedomMod.plugin_file = plugin.getFile();
|
|
||||||
TotalFreedomMod.logger = plugin.getLogger();
|
|
||||||
|
|
||||||
TotalFreedomMod.pluginName = plugin.getDescription().getName();
|
|
||||||
|
|
||||||
setAppProperties();
|
|
||||||
|
|
||||||
logger = plugin.getLogger();
|
|
||||||
|
|
||||||
TFM_Log.info("Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450 and DarthSalamon");
|
TFM_Log.info("Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450 and DarthSalamon");
|
||||||
|
|
||||||
loadSuperadminConfig();
|
loadSuperadminConfig();
|
||||||
@ -86,13 +91,21 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
|
|
||||||
registerEventHandlers();
|
registerEventHandlers();
|
||||||
|
|
||||||
if (TFM_ConfigEntry.GENERATE_FLATLANDS.getBoolean())
|
try
|
||||||
|
{
|
||||||
|
TFM_Flatlands.getInstance().getWorld();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Util.wipeFlatlandsIfFlagged();
|
|
||||||
TFM_Util.generateFlatlands(TFM_ConfigEntry.FLATLANDS_GENERATION_PARAMS.getString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_AdminWorld.getInstance().getAdminWorld();
|
try
|
||||||
|
{
|
||||||
|
TFM_AdminWorld.getInstance().getWorld();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
||||||
{
|
{
|
||||||
@ -101,6 +114,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
world.setThundering(false);
|
world.setThundering(false);
|
||||||
world.setStorm(false);
|
world.setStorm(false);
|
||||||
world.setThunderDuration(0);
|
world.setThunderDuration(0);
|
||||||
|
world.setWeatherDuration(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +136,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
|
|
||||||
TFM_Util.deleteFolder(new File("./_deleteme"));
|
TFM_Util.deleteFolder(new File("./_deleteme"));
|
||||||
|
|
||||||
File[] coreDumps = new File(".").listFiles(new java.io.FileFilter()
|
final File[] coreDumps = new File(".").listFiles(new java.io.FileFilter()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File file)
|
public boolean accept(File file)
|
||||||
@ -151,8 +165,14 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage());
|
TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_ServiceChecker.getInstance().getUpdateRunnable().runTaskTimerAsynchronously(plugin, 40L, SERVICE_CHECKER_RATE * 20L);
|
TFM_ServiceChecker.getInstance().start();
|
||||||
|
TFM_HTTPD_Manager.getInstance().start();
|
||||||
|
TFM_FrontDoor.getInstance().start();
|
||||||
|
TFM_LogFile.getInstance().start();
|
||||||
|
|
||||||
|
TFM_Log.info("Version " + pluginVersion + " enabled");
|
||||||
|
|
||||||
|
// Delayed Start :
|
||||||
new BukkitRunnable()
|
new BukkitRunnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -162,15 +182,15 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
TFM_CommandBlocker.getInstance().parseBlockingRules();
|
TFM_CommandBlocker.getInstance().parseBlockingRules();
|
||||||
}
|
}
|
||||||
}.runTaskLater(plugin, 20L);
|
}.runTaskLater(plugin, 20L);
|
||||||
|
|
||||||
|
|
||||||
TFM_Log.info("Plugin enabled");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
server.getScheduler().cancelTasks(plugin);
|
server.getScheduler().cancelTasks(plugin);
|
||||||
|
|
||||||
|
TFM_HTTPD_Manager.getInstance().stop();
|
||||||
|
|
||||||
TFM_Log.info("Plugin disabled");
|
TFM_Log.info("Plugin disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,10 +219,10 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
StringUtils.join(args, " ")), true);
|
StringUtils.join(args, " ")), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Command dispatcher;
|
final TFM_Command dispatcher;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ClassLoader classLoader = TotalFreedomMod.class.getClassLoader();
|
final ClassLoader classLoader = TotalFreedomMod.class.getClassLoader();
|
||||||
dispatcher = (TFM_Command) classLoader.loadClass(String.format("%s.%s%s", COMMAND_PATH, COMMAND_PREFIX, cmd.getName().toLowerCase())).newInstance();
|
dispatcher = (TFM_Command) classLoader.loadClass(String.format("%s.%s%s", COMMAND_PATH, COMMAND_PREFIX, cmd.getName().toLowerCase())).newInstance();
|
||||||
dispatcher.setup(plugin, sender, dispatcher.getClass());
|
dispatcher.setup(plugin, sender, dispatcher.getClass());
|
||||||
}
|
}
|
||||||
@ -227,6 +247,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
catch (Throwable ex)
|
catch (Throwable ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe("Command Error: " + commandLabel + "\n" + ExceptionUtils.getStackTrace(ex));
|
TFM_Log.severe("Command Error: " + commandLabel + "\n" + ExceptionUtils.getStackTrace(ex));
|
||||||
|
sender.sendMessage(ChatColor.RED + "Command Error: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -256,23 +277,23 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TFM_Util.createDefaultConfiguration(PERMBAN_FILE, plugin_file);
|
TFM_Util.createDefaultConfiguration(PERMBAN_FILE);
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), PERMBAN_FILE));
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), PERMBAN_FILE));
|
||||||
|
|
||||||
permbanned_players = new ArrayList<String>();
|
permbannedPlayers = new ArrayList<String>();
|
||||||
permbanned_ips = new ArrayList<String>();
|
permbannedIps = new ArrayList<String>();
|
||||||
|
|
||||||
for (String user : config.getKeys(false))
|
for (String user : config.getKeys(false))
|
||||||
{
|
{
|
||||||
permbanned_players.add(user.toLowerCase().trim());
|
permbannedPlayers.add(user.toLowerCase().trim());
|
||||||
|
|
||||||
List<String> user_ips = config.getStringList(user);
|
List<String> user_ips = config.getStringList(user);
|
||||||
for (String ip : user_ips)
|
for (String ip : user_ips)
|
||||||
{
|
{
|
||||||
ip = ip.toLowerCase().trim();
|
ip = ip.toLowerCase().trim();
|
||||||
if (!permbanned_ips.contains(ip))
|
if (!permbannedIps.contains(ip))
|
||||||
{
|
{
|
||||||
permbanned_ips.add(ip);
|
permbannedIps.add(ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -286,13 +307,14 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
|
|
||||||
private static void registerEventHandlers()
|
private static void registerEventHandlers()
|
||||||
{
|
{
|
||||||
PluginManager pm = server.getPluginManager();
|
final PluginManager pm = server.getPluginManager();
|
||||||
|
|
||||||
pm.registerEvents(new TFM_EntityListener(), plugin);
|
pm.registerEvents(new TFM_EntityListener(), plugin);
|
||||||
pm.registerEvents(new TFM_BlockListener(), plugin);
|
pm.registerEvents(new TFM_BlockListener(), plugin);
|
||||||
pm.registerEvents(new TFM_PlayerListener(), plugin);
|
pm.registerEvents(new TFM_PlayerListener(), plugin);
|
||||||
pm.registerEvents(new TFM_WeatherListener(), plugin);
|
pm.registerEvents(new TFM_WeatherListener(), plugin);
|
||||||
pm.registerEvents(new TFM_ServerListener(), plugin);
|
pm.registerEvents(new TFM_ServerListener(), plugin);
|
||||||
|
pm.registerEvents(new TFM_TelnetListener(), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setAppProperties()
|
private static void setAppProperties()
|
||||||
@ -306,14 +328,16 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
props.load(in);
|
props.load(in);
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
TotalFreedomMod.pluginVersion = props.getProperty("program.VERSION");
|
TotalFreedomMod.buildNumber = props.getProperty("program.buildnumber");
|
||||||
TotalFreedomMod.buildNumber = props.getProperty("program.BUILDNUM");
|
TotalFreedomMod.buildDate = props.getProperty("program.builddate");
|
||||||
TotalFreedomMod.buildDate = props.getProperty("program.BUILDDATE");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe("Could not load App properties!");
|
TFM_Log.severe("Could not load App properties!");
|
||||||
TFM_Log.severe(ex);
|
TFM_Log.severe(ex);
|
||||||
|
|
||||||
|
TotalFreedomMod.buildNumber = "1";
|
||||||
|
TotalFreedomMod.buildDate = TFM_Util.dateToString(new Date());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,70 +54,61 @@ import java.util.UUID;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
public class Metrics {
|
public class Metrics
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* The current revision number
|
* The current revision number
|
||||||
*/
|
*/
|
||||||
private final static int REVISION = 7;
|
private final static int REVISION = 7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base url of the metrics domain
|
* The base url of the metrics domain
|
||||||
*/
|
*/
|
||||||
private static final String BASE_URL = "http://report.mcstats.org";
|
private static final String BASE_URL = "http://report.mcstats.org";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The url used to report a server's status
|
* The url used to report a server's status
|
||||||
*/
|
*/
|
||||||
private static final String REPORT_URL = "/plugin/%s";
|
private static final String REPORT_URL = "/plugin/%s";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interval of time to ping (in minutes)
|
* Interval of time to ping (in minutes)
|
||||||
*/
|
*/
|
||||||
private static final int PING_INTERVAL = 15;
|
private static final int PING_INTERVAL = 15;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The plugin this metrics submits for
|
* The plugin this metrics submits for
|
||||||
*/
|
*/
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All of the custom graphs to submit to metrics
|
* All of the custom graphs to submit to metrics
|
||||||
*/
|
*/
|
||||||
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
|
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The plugin configuration file
|
* The plugin configuration file
|
||||||
*/
|
*/
|
||||||
private final YamlConfiguration configuration;
|
private final YamlConfiguration configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The plugin configuration file
|
* The plugin configuration file
|
||||||
*/
|
*/
|
||||||
private final File configurationFile;
|
private final File configurationFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique server id
|
* Unique server id
|
||||||
*/
|
*/
|
||||||
private final String guid;
|
private final String guid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug mode
|
* Debug mode
|
||||||
*/
|
*/
|
||||||
private final boolean debug;
|
private final boolean debug;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock for synchronization
|
* Lock for synchronization
|
||||||
*/
|
*/
|
||||||
private final Object optOutLock = new Object();
|
private final Object optOutLock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The scheduled task
|
* The scheduled task
|
||||||
*/
|
*/
|
||||||
private volatile BukkitTask task = null;
|
private volatile BukkitTask task = null;
|
||||||
|
|
||||||
public Metrics(final Plugin plugin) throws IOException {
|
public Metrics(final Plugin plugin) throws IOException
|
||||||
if (plugin == null) {
|
{
|
||||||
|
if (plugin == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Plugin cannot be null");
|
throw new IllegalArgumentException("Plugin cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +124,8 @@ public class Metrics {
|
|||||||
configuration.addDefault("debug", false);
|
configuration.addDefault("debug", false);
|
||||||
|
|
||||||
// Do we need to create the file?
|
// Do we need to create the file?
|
||||||
if (configuration.get("guid", null) == null) {
|
if (configuration.get("guid", null) == null)
|
||||||
|
{
|
||||||
configuration.options().header("http://mcstats.org").copyDefaults(true);
|
configuration.options().header("http://mcstats.org").copyDefaults(true);
|
||||||
configuration.save(configurationFile);
|
configuration.save(configurationFile);
|
||||||
}
|
}
|
||||||
@ -150,8 +142,10 @@ public class Metrics {
|
|||||||
* @param name The name of the graph
|
* @param name The name of the graph
|
||||||
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
|
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
|
||||||
*/
|
*/
|
||||||
public Graph createGraph(final String name) {
|
public Graph createGraph(final String name)
|
||||||
if (name == null) {
|
{
|
||||||
|
if (name == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Graph name cannot be null");
|
throw new IllegalArgumentException("Graph name cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,8 +164,10 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param graph The name of the graph
|
* @param graph The name of the graph
|
||||||
*/
|
*/
|
||||||
public void addGraph(final Graph graph) {
|
public void addGraph(final Graph graph)
|
||||||
if (graph == null) {
|
{
|
||||||
|
if (graph == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Graph cannot be null");
|
throw new IllegalArgumentException("Graph cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,33 +181,42 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return True if statistics measuring is running, otherwise false.
|
* @return True if statistics measuring is running, otherwise false.
|
||||||
*/
|
*/
|
||||||
public boolean start() {
|
public boolean start()
|
||||||
synchronized (optOutLock) {
|
{
|
||||||
|
synchronized (optOutLock)
|
||||||
|
{
|
||||||
// Did we opt out?
|
// Did we opt out?
|
||||||
if (isOptOut()) {
|
if (isOptOut())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is metrics already running?
|
// Is metrics already running?
|
||||||
if (task != null) {
|
if (task != null)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin hitting the server with glorious data
|
// Begin hitting the server with glorious data
|
||||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable()
|
||||||
|
{
|
||||||
private boolean firstPost = true;
|
private boolean firstPost = true;
|
||||||
|
|
||||||
public void run() {
|
public void run()
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
// This has to be synchronized or it can collide with the disable method.
|
// This has to be synchronized or it can collide with the disable method.
|
||||||
synchronized (optOutLock) {
|
synchronized (optOutLock)
|
||||||
|
{
|
||||||
// Disable Task, if it is running and the server owner decided to opt-out
|
// Disable Task, if it is running and the server owner decided to opt-out
|
||||||
if (isOptOut() && task != null) {
|
if (isOptOut() && task != null)
|
||||||
|
{
|
||||||
task.cancel();
|
task.cancel();
|
||||||
task = null;
|
task = null;
|
||||||
// Tell all plotters to stop gathering information.
|
// Tell all plotters to stop gathering information.
|
||||||
for (Graph graph : graphs) {
|
for (Graph graph : graphs)
|
||||||
|
{
|
||||||
graph.onOptOut();
|
graph.onOptOut();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,8 +230,11 @@ public class Metrics {
|
|||||||
// After the first post we set firstPost to false
|
// After the first post we set firstPost to false
|
||||||
// Each post thereafter will be a ping
|
// Each post thereafter will be a ping
|
||||||
firstPost = false;
|
firstPost = false;
|
||||||
} catch (IOException e) {
|
}
|
||||||
if (debug) {
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,18 +250,27 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return true if metrics should be opted out of it
|
* @return true if metrics should be opted out of it
|
||||||
*/
|
*/
|
||||||
public boolean isOptOut() {
|
public boolean isOptOut()
|
||||||
synchronized (optOutLock) {
|
{
|
||||||
try {
|
synchronized (optOutLock)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
// Reload the metrics file
|
// Reload the metrics file
|
||||||
configuration.load(getConfigFile());
|
configuration.load(getConfigFile());
|
||||||
} catch (IOException ex) {
|
}
|
||||||
if (debug) {
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (InvalidConfigurationException ex) {
|
}
|
||||||
if (debug) {
|
catch (InvalidConfigurationException ex)
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -267,17 +284,21 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
*/
|
*/
|
||||||
public void enable() throws IOException {
|
public void enable() throws IOException
|
||||||
|
{
|
||||||
// This has to be synchronized or it can collide with the check in the task.
|
// This has to be synchronized or it can collide with the check in the task.
|
||||||
synchronized (optOutLock) {
|
synchronized (optOutLock)
|
||||||
|
{
|
||||||
// Check if the server owner has already set opt-out, if not, set it.
|
// Check if the server owner has already set opt-out, if not, set it.
|
||||||
if (isOptOut()) {
|
if (isOptOut())
|
||||||
|
{
|
||||||
configuration.set("opt-out", false);
|
configuration.set("opt-out", false);
|
||||||
configuration.save(configurationFile);
|
configuration.save(configurationFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable Task, if it is not running
|
// Enable Task, if it is not running
|
||||||
if (task == null) {
|
if (task == null)
|
||||||
|
{
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,17 +309,21 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
*/
|
*/
|
||||||
public void disable() throws IOException {
|
public void disable() throws IOException
|
||||||
|
{
|
||||||
// This has to be synchronized or it can collide with the check in the task.
|
// This has to be synchronized or it can collide with the check in the task.
|
||||||
synchronized (optOutLock) {
|
synchronized (optOutLock)
|
||||||
|
{
|
||||||
// Check if the server owner has already set opt-out, if not, set it.
|
// Check if the server owner has already set opt-out, if not, set it.
|
||||||
if (!isOptOut()) {
|
if (!isOptOut())
|
||||||
|
{
|
||||||
configuration.set("opt-out", true);
|
configuration.set("opt-out", true);
|
||||||
configuration.save(configurationFile);
|
configuration.save(configurationFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable Task, if it is running
|
// Disable Task, if it is running
|
||||||
if (task != null) {
|
if (task != null)
|
||||||
|
{
|
||||||
task.cancel();
|
task.cancel();
|
||||||
task = null;
|
task = null;
|
||||||
}
|
}
|
||||||
@ -310,7 +335,8 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return the File object for the config file
|
* @return the File object for the config file
|
||||||
*/
|
*/
|
||||||
public File getConfigFile() {
|
public File getConfigFile()
|
||||||
|
{
|
||||||
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
|
// 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
|
// is to abuse the plugin object we already have
|
||||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
// plugin.getDataFolder() => base/plugins/PluginA/
|
||||||
@ -325,7 +351,8 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Generic method that posts a plugin to the metrics website
|
* Generic method that posts a plugin to the metrics website
|
||||||
*/
|
*/
|
||||||
private void postPlugin(final boolean isPing) throws IOException {
|
private void postPlugin(final boolean isPing) throws IOException
|
||||||
|
{
|
||||||
// Server software specific section
|
// Server software specific section
|
||||||
PluginDescriptionFile description = plugin.getDescription();
|
PluginDescriptionFile description = plugin.getDescription();
|
||||||
String pluginName = description.getName();
|
String pluginName = description.getName();
|
||||||
@ -354,7 +381,8 @@ public class Metrics {
|
|||||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||||
|
|
||||||
// normalize os arch .. amd64 -> x86_64
|
// normalize os arch .. amd64 -> x86_64
|
||||||
if (osarch.equals("amd64")) {
|
if (osarch.equals("amd64"))
|
||||||
|
{
|
||||||
osarch = "x86_64";
|
osarch = "x86_64";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,12 +394,15 @@ public class Metrics {
|
|||||||
appendJSONPair(json, "java_version", java_version);
|
appendJSONPair(json, "java_version", java_version);
|
||||||
|
|
||||||
// If we're pinging, append it
|
// If we're pinging, append it
|
||||||
if (isPing) {
|
if (isPing)
|
||||||
|
{
|
||||||
appendJSONPair(json, "ping", "1");
|
appendJSONPair(json, "ping", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (graphs.size() > 0) {
|
if (graphs.size() > 0)
|
||||||
synchronized (graphs) {
|
{
|
||||||
|
synchronized (graphs)
|
||||||
|
{
|
||||||
json.append(',');
|
json.append(',');
|
||||||
json.append('"');
|
json.append('"');
|
||||||
json.append("graphs");
|
json.append("graphs");
|
||||||
@ -383,19 +414,22 @@ public class Metrics {
|
|||||||
|
|
||||||
final Iterator<Graph> iter = graphs.iterator();
|
final Iterator<Graph> iter = graphs.iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext())
|
||||||
|
{
|
||||||
Graph graph = iter.next();
|
Graph graph = iter.next();
|
||||||
|
|
||||||
StringBuilder graphJson = new StringBuilder();
|
StringBuilder graphJson = new StringBuilder();
|
||||||
graphJson.append('{');
|
graphJson.append('{');
|
||||||
|
|
||||||
for (Plotter plotter : graph.getPlotters()) {
|
for (Plotter plotter : graph.getPlotters())
|
||||||
|
{
|
||||||
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
|
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
graphJson.append('}');
|
graphJson.append('}');
|
||||||
|
|
||||||
if (!firstGraph) {
|
if (!firstGraph)
|
||||||
|
{
|
||||||
json.append(',');
|
json.append(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,9 +455,12 @@ public class Metrics {
|
|||||||
|
|
||||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
// Mineshafter creates a socks proxy, so we can safely bypass it
|
||||||
// It does not reroute POST requests so we need to go around it
|
// It does not reroute POST requests so we need to go around it
|
||||||
if (isMineshafterPresent()) {
|
if (isMineshafterPresent())
|
||||||
|
{
|
||||||
connection = url.openConnection(Proxy.NO_PROXY);
|
connection = url.openConnection(Proxy.NO_PROXY);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
connection = url.openConnection();
|
connection = url.openConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,7 +478,8 @@ public class Metrics {
|
|||||||
|
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
if (debug) {
|
if (debug)
|
||||||
|
{
|
||||||
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,24 +496,34 @@ public class Metrics {
|
|||||||
os.close();
|
os.close();
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
if (response == null || response.startsWith("ERR") || response.startsWith("7"))
|
||||||
if (response == null) {
|
{
|
||||||
|
if (response == null)
|
||||||
|
{
|
||||||
response = "null";
|
response = "null";
|
||||||
} else if (response.startsWith("7")) {
|
}
|
||||||
|
else if (response.startsWith("7"))
|
||||||
|
{
|
||||||
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IOException(response);
|
throw new IOException(response);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Is this the first update this hour?
|
// Is this the first update this hour?
|
||||||
if (response.equals("1") || response.contains("This is your first update this hour")) {
|
if (response.equals("1") || response.contains("This is your first update this hour"))
|
||||||
synchronized (graphs) {
|
{
|
||||||
|
synchronized (graphs)
|
||||||
|
{
|
||||||
final Iterator<Graph> iter = graphs.iterator();
|
final Iterator<Graph> iter = graphs.iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext())
|
||||||
|
{
|
||||||
final Graph graph = iter.next();
|
final Graph graph = iter.next();
|
||||||
|
|
||||||
for (Plotter plotter : graph.getPlotters()) {
|
for (Plotter plotter : graph.getPlotters())
|
||||||
|
{
|
||||||
plotter.reset();
|
plotter.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,19 +538,31 @@ public class Metrics {
|
|||||||
* @param input
|
* @param input
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static byte[] gzip(String input) {
|
public static byte[] gzip(String input)
|
||||||
|
{
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream gzos = null;
|
GZIPOutputStream gzos = null;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
gzos = new GZIPOutputStream(baos);
|
gzos = new GZIPOutputStream(baos);
|
||||||
gzos.write(input.getBytes("UTF-8"));
|
gzos.write(input.getBytes("UTF-8"));
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
}
|
||||||
if (gzos != null) try {
|
finally
|
||||||
gzos.close();
|
{
|
||||||
} catch (IOException ignore) {
|
if (gzos != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gzos.close();
|
||||||
|
}
|
||||||
|
catch (IOException ignore)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,11 +574,15 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return true if mineshafter is installed on the server
|
* @return true if mineshafter is installed on the server
|
||||||
*/
|
*/
|
||||||
private boolean isMineshafterPresent() {
|
private boolean isMineshafterPresent()
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
Class.forName("mineshafter.MineServer");
|
Class.forName("mineshafter.MineServer");
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -531,28 +595,37 @@ public class Metrics {
|
|||||||
* @param value
|
* @param value
|
||||||
* @throws UnsupportedEncodingException
|
* @throws UnsupportedEncodingException
|
||||||
*/
|
*/
|
||||||
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
|
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException
|
||||||
|
{
|
||||||
boolean isValueNumeric = false;
|
boolean isValueNumeric = false;
|
||||||
|
|
||||||
try {
|
try
|
||||||
if (value.equals("0") || !value.endsWith("0")) {
|
{
|
||||||
|
if (value.equals("0") || !value.endsWith("0"))
|
||||||
|
{
|
||||||
Double.parseDouble(value);
|
Double.parseDouble(value);
|
||||||
isValueNumeric = true;
|
isValueNumeric = true;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
}
|
||||||
|
catch (NumberFormatException e)
|
||||||
|
{
|
||||||
isValueNumeric = false;
|
isValueNumeric = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.charAt(json.length() - 1) != '{') {
|
if (json.charAt(json.length() - 1) != '{')
|
||||||
|
{
|
||||||
json.append(',');
|
json.append(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
json.append(escapeJSON(key));
|
json.append(escapeJSON(key));
|
||||||
json.append(':');
|
json.append(':');
|
||||||
|
|
||||||
if (isValueNumeric) {
|
if (isValueNumeric)
|
||||||
|
{
|
||||||
json.append(value);
|
json.append(value);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
json.append(escapeJSON(value));
|
json.append(escapeJSON(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -563,14 +636,17 @@ public class Metrics {
|
|||||||
* @param text
|
* @param text
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static String escapeJSON(String text) {
|
private static String escapeJSON(String text)
|
||||||
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append('"');
|
builder.append('"');
|
||||||
for (int index = 0; index < text.length(); index++) {
|
for (int index = 0; index < text.length(); index++)
|
||||||
|
{
|
||||||
char chr = text.charAt(index);
|
char chr = text.charAt(index);
|
||||||
|
|
||||||
switch (chr) {
|
switch (chr)
|
||||||
|
{
|
||||||
case '"':
|
case '"':
|
||||||
case '\\':
|
case '\\':
|
||||||
builder.append('\\');
|
builder.append('\\');
|
||||||
@ -589,10 +665,13 @@ public class Metrics {
|
|||||||
builder.append("\\r");
|
builder.append("\\r");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (chr < ' ') {
|
if (chr < ' ')
|
||||||
|
{
|
||||||
String t = "000" + Integer.toHexString(chr);
|
String t = "000" + Integer.toHexString(chr);
|
||||||
builder.append("\\u" + t.substring(t.length() - 4));
|
builder.append("\\u" + t.substring(t.length() - 4));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
builder.append(chr);
|
builder.append(chr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -609,27 +688,28 @@ public class Metrics {
|
|||||||
* @param text the text to encode
|
* @param text the text to encode
|
||||||
* @return the encoded text, as UTF-8
|
* @return the encoded text, as UTF-8
|
||||||
*/
|
*/
|
||||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
private static String urlEncode(final String text) throws UnsupportedEncodingException
|
||||||
|
{
|
||||||
return URLEncoder.encode(text, "UTF-8");
|
return URLEncoder.encode(text, "UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a custom graph on the website
|
* Represents a custom graph on the website
|
||||||
*/
|
*/
|
||||||
public static class Graph {
|
public static class Graph
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is
|
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is
|
||||||
* rejected
|
* rejected
|
||||||
*/
|
*/
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The set of plotters that are contained within this graph
|
* The set of plotters that are contained within this graph
|
||||||
*/
|
*/
|
||||||
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
|
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
|
||||||
|
|
||||||
private Graph(final String name) {
|
private Graph(final String name)
|
||||||
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,7 +718,8 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return the Graph's name
|
* @return the Graph's name
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName()
|
||||||
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,7 +728,8 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param plotter the plotter to add to the graph
|
* @param plotter the plotter to add to the graph
|
||||||
*/
|
*/
|
||||||
public void addPlotter(final Plotter plotter) {
|
public void addPlotter(final Plotter plotter)
|
||||||
|
{
|
||||||
plotters.add(plotter);
|
plotters.add(plotter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -656,7 +738,8 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param plotter the plotter to remove from the graph
|
* @param plotter the plotter to remove from the graph
|
||||||
*/
|
*/
|
||||||
public void removePlotter(final Plotter plotter) {
|
public void removePlotter(final Plotter plotter)
|
||||||
|
{
|
||||||
plotters.remove(plotter);
|
plotters.remove(plotter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,18 +748,22 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return an unmodifiable {@link java.util.Set} of the plotter objects
|
* @return an unmodifiable {@link java.util.Set} of the plotter objects
|
||||||
*/
|
*/
|
||||||
public Set<Plotter> getPlotters() {
|
public Set<Plotter> getPlotters()
|
||||||
|
{
|
||||||
return Collections.unmodifiableSet(plotters);
|
return Collections.unmodifiableSet(plotters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode()
|
||||||
|
{
|
||||||
return name.hashCode();
|
return name.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object object) {
|
public boolean equals(final Object object)
|
||||||
if (!(object instanceof Graph)) {
|
{
|
||||||
|
if (!(object instanceof Graph))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,15 +774,16 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
|
* Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
|
||||||
*/
|
*/
|
||||||
protected void onOptOut() {
|
protected void onOptOut()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface used to collect custom data for a plugin
|
* Interface used to collect custom data for a plugin
|
||||||
*/
|
*/
|
||||||
public static abstract class Plotter {
|
public static abstract class Plotter
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* The plot's name
|
* The plot's name
|
||||||
*/
|
*/
|
||||||
@ -704,7 +792,8 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Construct a plotter with the default plot name
|
* Construct a plotter with the default plot name
|
||||||
*/
|
*/
|
||||||
public Plotter() {
|
public Plotter()
|
||||||
|
{
|
||||||
this("Default");
|
this("Default");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,7 +802,8 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param name the name of the plotter to use, which will show up on the website
|
* @param name the name of the plotter to use, which will show up on the website
|
||||||
*/
|
*/
|
||||||
public Plotter(final String name) {
|
public Plotter(final String name)
|
||||||
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -731,24 +821,29 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return the plotted point's column name
|
* @return the plotted point's column name
|
||||||
*/
|
*/
|
||||||
public String getColumnName() {
|
public String getColumnName()
|
||||||
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after the website graphs have been updated
|
* Called after the website graphs have been updated
|
||||||
*/
|
*/
|
||||||
public void reset() {
|
public void reset()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode()
|
||||||
|
{
|
||||||
return getColumnName().hashCode();
|
return getColumnName().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object object) {
|
public boolean equals(final Object object)
|
||||||
if (!(object instanceof Plotter)) {
|
{
|
||||||
|
if (!(object instanceof Plotter))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user