mirror of https://github.com/taoneill/war.git
Compare commits
422 Commits
v1.6previe
...
develop
Author | SHA1 | Date |
---|---|---|
Connor Monahan | 7b982c2687 | |
= | 3217c0a732 | |
= | 2e6466fab2 | |
= | 98afe494c1 | |
Connor Monahan | 20e3e70461 | |
Connor Monahan | 26acfa6a53 | |
Connor Monahan | 3470a0cc54 | |
Connor Monahan | 66ef1b9cc2 | |
Connor Monahan | 0dde3acaed | |
Connor Monahan | 03c9ad95ee | |
Connor Monahan | 87cea1a1b4 | |
Connor Monahan | 2af9379287 | |
Connor Monahan | b24e495df7 | |
Connor Monahan | 6b90371fce | |
Connor Monahan | 81f839a0a2 | |
Connor Monahan | 8b76d2068f | |
Connor Monahan | 99b6bdb3dd | |
Connor Monahan | a0174935fe | |
Connor Monahan | 5e4f0022df | |
Connor Monahan | db7a7864f9 | |
Connor Monahan | 7f7babf104 | |
Connor Monahan | bca78e5d0c | |
Connor Monahan | 4e83ffada1 | |
Connor Monahan | 69a148fc6a | |
Connor Monahan | 0a02e25f4a | |
= | 0babe82368 | |
Connor Monahan | 47be664a93 | |
Connor Monahan | 821c66c556 | |
Connor Monahan | 22cbba62b3 | |
grinning | eb7b600aef | |
Connor Monahan | 4f00befeb2 | |
Connor Monahan | f6b41bd015 | |
Connor Monahan | f1caca70f5 | |
Super0JET0 | e45b0eb0bb | |
Super0JET0 | 910310aab4 | |
Connor Monahan | 8ce9586b8d | |
Connor Monahan | 0f09410c66 | |
Connor Monahan | 57d29f464c | |
Connor Monahan | 9135e5bf22 | |
Connor Monahan | 994fec5a14 | |
Connor Monahan | d3b5795dda | |
Connor Monahan | a4038c6df1 | |
Connor Monahan | 200bb5a3c0 | |
Connor Monahan | 372576a396 | |
Connor Monahan | ddfa24f626 | |
Connor Monahan | b7cf69666c | |
Connor Monahan | ef26173ba1 | |
Connor Monahan | b7138d65bd | |
Connor Monahan | b772b71803 | |
Connor Monahan | 9c3c43c4f6 | |
Connor Monahan | c5adfa7023 | |
Connor Monahan | 00ec38c739 | |
Connor Monahan | 66445eb61d | |
Connor Monahan | 334620e4b1 | |
Connor Monahan | 13e5d38277 | |
Connor Monahan | 5c992c95ee | |
Connor Monahan | 53c683abf3 | |
Connor Monahan | 8d908c1c50 | |
Connor Monahan | 8ad26d51fe | |
Connor Monahan | e3c154ba7a | |
Connor Monahan | f6175451ee | |
Connor Monahan | aa41a11daf | |
Connor Monahan | dc4de5f6a5 | |
Connor Monahan | 82741751cf | |
Connor Monahan | 5b4accb707 | |
Connor Monahan | 624f278734 | |
Connor Monahan | c1ad45e555 | |
Connor Monahan | f7aa952fb6 | |
kugick | 9149b66142 | |
Fikry Abdullah Aziz | 2b5190434d | |
cmastudios | e786c09bd0 | |
cmastudios | 2c529f7647 | |
cmastudios | 7561fd8ffb | |
cmastudios | 4f60ebb780 | |
cmastudios | 33add7df0d | |
cmastudios | 9281ad5c4d | |
cmastudios | df1e5a56df | |
cmastudios | bdc961c7e1 | |
cmastudios | 382261eb83 | |
cmastudios | d4976ecbb4 | |
cmastudios | 92002a06a2 | |
taoneill | 5e93ab6bc4 | |
cmastudios | 463d51d41b | |
cmastudios | aeda124c1c | |
cmastudios | 9bd9f76b9e | |
cmastudios | 14054454af | |
cmastudios | 181fb64c50 | |
cmastudios | 7ed33e8965 | |
cmastudios | a529e0c1fe | |
cmastudios | e229f9fc4e | |
Master-chan | 367f5d1a73 | |
cmastudios | 1ad05dd5f3 | |
cmastudios | 0a80198084 | |
cmastudios | 09e0919042 | |
cmastudios | 8bf6d6047d | |
cmastudios | f00ed85c4b | |
cmastudios | 43bbb24dd5 | |
cmastudios | 64ae4c617f | |
cmastudios | 72a2f08d70 | |
cmastudios | 4106dd887f | |
cmastudios | 1d6ffcea7e | |
taoneill | 6294922225 | |
taoneill | bed0385476 | |
taoneill | 0e481bb5d5 | |
taoneill | b17e38cfd2 | |
cmastudios | 5146a7c9c8 | |
cmastudios | 20223d1c12 | |
taoneill | 4fde95ee7b | |
taoneill | 7ee243e20d | |
Connor Monahan | 82267764e1 | |
taoneill | 0c9ed4b238 | |
taoneill | 95ee0c1972 | |
Connor Monahan | 95cc2c7a34 | |
Connor Monahan | 2ef0f3e324 | |
Connor Monahan | 076e8ce9bd | |
Connor Monahan | ce1b60b85f | |
Connor Monahan | a92b2ea4ae | |
Connor Monahan | c6c93ba44f | |
Connor Monahan | 20068cbb15 | |
Connor Monahan | b011d3a46f | |
Connor Monahan | bc07a60b51 | |
Connor Monahan | dc764de258 | |
Connor Monahan | a45a833e68 | |
Connor Monahan | fdc4e90635 | |
Connor Monahan | 0805a04cad | |
Connor Monahan | ca03c96173 | |
Connor | 59779eb0e5 | |
cmastudios | 0af348f2cb | |
grinning | c16bc6ca5f | |
cmastudios | 228ec2299b | |
cmastudios | a120393060 | |
cmastudios | 84a5750063 | |
cmastudios | 034b51ae03 | |
cmastudios | 300f2e383b | |
cmastudios | 346fd25955 | |
cmastudios | df871c1c5b | |
cmastudios | 67bb509735 | |
cmastudios | 7ef61af277 | |
cmastudios | 78ef1dd4fc | |
cmastudios | 60b62c8b71 | |
cmastudios | d040edcc4e | |
cmastudios | 21f91a00fc | |
taoneill | 6eed5bbe19 | |
cmastudios | 5c2474cb70 | |
cmastudios | cc2b13633c | |
taoneill | 99bfbc5e58 | |
cmastudios | 77b943ce5e | |
cmastudios | 2926387ee4 | |
cmastudios | 0f35c4dc4c | |
cmastudios | 66158ae44b | |
taoneill | d4d5778175 | |
taoneill | 31a2deef0f | |
taoneill | df85b176b7 | |
taoneill | 97646becc3 | |
Connor | b0fadd4459 | |
cmastudios | c7e33dd1ca | |
cmastudios | c6d2c6cbcc | |
cmastudios | ceeea15794 | |
cmastudios | 3791a027a0 | |
cmastudios | 13a6f8ba79 | |
cmastudios | a4e8a4be83 | |
cmastudios | c44d18f8f8 | |
cmastudios | 215551ec15 | |
cmastudios | a039e65a8a | |
cmastudios | 9e6b0d9f17 | |
taoneill | df6f47907f | |
cmastudios | f814f71cf3 | |
cmastudios | dd6f425368 | |
cmastudios | 7621bdd321 | |
cmastudios | f44c2528e7 | |
cmastudios | ac12c2af29 | |
cmastudios | 60e74eff99 | |
cmastudios | aacd93b960 | |
cmastudios | 1722c86a71 | |
cmastudios | 6e9efc7a8a | |
cmastudios | 3c80815428 | |
cmastudios | 5913f73fcb | |
cmastudios | a7458bf261 | |
cmastudios | 39b0ead3bd | |
cmastudios | e38b2aa62b | |
cmastudios | a4f1b29922 | |
Ben Menking | e2f6e02ae7 | |
cmastudios | 2bddae16a2 | |
Nicholasntp | d94b7b3e78 | |
cmastudios | f1ce78907e | |
cmastudios | 12b5f8350f | |
cmastudios | dbac21aa44 | |
cmastudios | 0dc7ac837f | |
cmastudios | 26ec11f46c | |
cmastudios | 17aef5e162 | |
cmastudios | c66120c4fa | |
cmastudios | 2738d2e358 | |
cmastudios | b367cc53ad | |
cmastudios | 890e78fd5d | |
cmastudios | ea0df4f22b | |
cmastudios | 5a571e7329 | |
cmastudios | 200ae92e0f | |
cmastudios | c56fac6c34 | |
cmastudios | bf3795ded1 | |
cmastudios | fb375002de | |
cmastudios | ebd95a4e16 | |
taoneill | 756ca37a82 | |
taoneill | bf7e1a9847 | |
cmastudios | 13396f85a4 | |
cmastudios | c4b268910b | |
cmastudios | 5c954a19b4 | |
cmastudios | 21688ba4d0 | |
cmastudios | 728111217e | |
cmastudios | 3b0b0c6720 | |
taoneill | da14a8fc4d | |
cmastudios | a5cd846b2a | |
cmastudios | 423654d21e | |
taoneill | e3e20fc704 | |
taoneill | 856d697d79 | |
taoneill | 4317b2fc8c | |
taoneill | 2d91b3cf90 | |
cmastudios | d724f5a382 | |
cmastudios | e6c1e64fef | |
cmastudios | dd88a5ccbe | |
cmastudios | 0955df7503 | |
cmastudios | ce72ba36fa | |
taoneill | e83c53061d | |
taoneill | 101bff45c5 | |
cmastudios | 8dac3f4ea9 | |
cmastudios | 6b35645150 | |
cmastudios | 0fbf381748 | |
cmastudios | a3f73b5fe7 | |
cmastudios | 9ca2ed1f46 | |
cmastudios | c3d7b74109 | |
cmastudios | c87799c03d | |
taoneill | bff034a299 | |
taoneill | 0245476130 | |
taoneill | 381047f915 | |
taoneill | 666f604133 | |
taoneill | d71adaa8ab | |
taoneill | 39a8becdfe | |
taoneill | 00af397929 | |
MegaMinerJon | f14d21a35f | |
taoneill | cd47e28e9f | |
taoneill | e6d2bd0950 | |
taoneill | 411021fc35 | |
taoneill | 120af8e817 | |
taoneill | 5aaf25c1c7 | |
taoneill | ff5318c8f6 | |
taoneill | 41ecb512ed | |
taoneill | bdc8b4057c | |
taoneill | b6d1ea2c90 | |
taoneill | 6304b39fc8 | |
taoneill | afa82ce13f | |
taoneill | 1b1c74ed26 | |
taoneill | b2d0a5c355 | |
taoneill | 06d6ae9bdb | |
taoneill | 9139f9df45 | |
Connor | 6056ff0c87 | |
taoneill | 14d4efea9d | |
taoneill | 53aa9cda52 | |
taoneill | c6e98769e5 | |
taoneill | 4835d0f37d | |
taoneill | 7a90119c97 | |
taoneill | b504b5b014 | |
taoneill | 520bac05da | |
taoneill | 0557d94911 | |
taoneill | a1634b8b94 | |
taoneill | 2dc7d4aa75 | |
taoneill | 60e4eafc13 | |
Connor | 623af5d16a | |
taoneill | 9f657c4a59 | |
taoneill | 6c33314288 | |
taoneill | e80bdc9e2a | |
taoneill | 4dfead7ec8 | |
taoneill | c6b04faa55 | |
taoneill | 4bebb2d50e | |
taoneill | 4867b8cf03 | |
taoneill | 68b5ca755b | |
taoneill | b7ae19a439 | |
taoneill | a258bd8995 | |
cmastudios | 380025f147 | |
taoneill | 1d6fdbe126 | |
taoneill | 894791215c | |
taoneill | af9d4db788 | |
taoneill | 7f36e6991f | |
taoneill | ae190ed315 | |
taoneill | 33117b9db0 | |
taoneill | 1d47f79eca | |
taoneill | 305b2454c7 | |
taoneill | 2c773710ba | |
taoneill | 6b29226004 | |
taoneill | d0c1878c30 | |
taoneill | 2afc40fb00 | |
taoneill | bdae9df6b7 | |
taoneill | 59b9b3078c | |
taoneill | eea3af9c1c | |
taoneill | 5d9b654240 | |
Ryan Schlesinger | 37f68d4716 | |
taoneill | fc03a0cf74 | |
taoneill | f8e771c9e0 | |
taoneill | 61d691c1dd | |
taoneill | d7a6bf9e53 | |
taoneill | 9ea65c051f | |
taoneill | a4d8075ad1 | |
taoneill | ea454e3027 | |
taoneill | 4b69b14e10 | |
taoneill | a9c09c3f16 | |
taoneill | a4a3ced0e5 | |
taoneill | 668285ac97 | |
taoneill | 13067f35ad | |
taoneill | 445aae7f8f | |
taoneill | d027a53e02 | |
taoneill | c54e893e41 | |
taoneill | f06afb5aa3 | |
taoneill | ee7dab194a | |
taoneill | 9019b4f780 | |
taoneill | 4ffaadf3da | |
Thomas-Antoine O'Neill | e8e2c0c472 | |
Thomas-Antoine O'Neill | 06272803f1 | |
Thomas-Antoine O'Neill | bbdfef0ca6 | |
Thomas-Antoine O'Neill | 4e1b5670a4 | |
taoneill | 6ff3cbe0c3 | |
taoneill | 1eed5ca366 | |
taoneill | a86683a98a | |
taoneill | 934292df88 | |
taoneill | 940ad072d4 | |
taoneill | a610181954 | |
taoneill | 92b949343c | |
taoneill | 80fd939922 | |
taoneill | 25f93ab26c | |
taoneill | e53eb7965e | |
taoneill | 4d04f39e3b | |
taoneill | 6a452ebb8f | |
taoneill | ad1c591acd | |
taoneill | 2745803050 | |
taoneill | 38c91b5623 | |
taoneill | 25bbf5b185 | |
taoneill | 2adb328115 | |
taoneill | 9ff98d0bbf | |
taoneill | fb7ceaec55 | |
taoneill | 0d7f2feef4 | |
Connor M | 576993f97e | |
taoneill | 5c3fca5001 | |
taoneill | 6eeb5be673 | |
taoneill | 589d197bf1 | |
taoneill | 1bae53670e | |
taoneill | 143afa4473 | |
taoneill | 983e90ca38 | |
taoneill | dd6beb3b82 | |
taoneill | e1c6397f22 | |
taoneill | 0b1d428266 | |
taoneill | bd872be244 | |
taoneill | b196618515 | |
taoneill | b6f9afb745 | |
taoneill | f7e0b73465 | |
taoneill | b057cac73d | |
taoneill | a532bbaf93 | |
taoneill | 0cf0024e55 | |
taoneill | 007344a63e | |
taoneill | 60356e56ab | |
taoneill | 177543ad20 | |
taoneill | a37766d31b | |
Chris Sp | cd158cc9a9 | |
taoneill | ccd6649d06 | |
taoneill | 4996a7457d | |
taoneill | 1325611775 | |
taoneill | 1b9f06e3ca | |
Chris Sp | d9701b910d | |
Chris Sp | 1061c24c5b | |
Chris Sp | 856da8cc77 | |
Chris Sp | ff04f24a85 | |
chris | 9f828fe790 | |
taoneill | 95308c8bc9 | |
taoneill | 82c8397547 | |
taoneill | 8913f7ae5c | |
taoneill | d327c34b10 | |
taoneill | 73f7dbe8a2 | |
taoneill | 9f9d6ba7c1 | |
taoneill | 06427445b7 | |
taoneill | 00c6397df4 | |
taoneill | 0811431b0a | |
taoneill | 599e6b11d5 | |
taoneill | 1266462635 | |
taoneill | f947f204b9 | |
taoneill | 23893c60da | |
taoneill | 095b073051 | |
taoneill | dc4b770aaa | |
taoneill | 9cc39281d7 | |
taoneill | 66df711006 | |
taoneill | 48311e4d95 | |
taoneill | 1ba2fa2e06 | |
taoneill | c6a8bc555c | |
taoneill | e0a2d6092b | |
taoneill | 5abdf43986 | |
taoneill | b62e8ffd53 | |
taoneill | 3277491c64 | |
taoneill | bceda1932e | |
taoneill | 880f7ce528 | |
Tim Düsterhus | 0518fd0be4 | |
Tim Düsterhus | 8788c9c4b6 | |
Tim Düsterhus | bcfa109944 | |
Tim Düsterhus | 1e8b1b8193 | |
taoneill | f20b275ba9 | |
taoneill | 25e034965d | |
taoneill | cb9a34f5bd | |
Tim Düsterhus | c7af5843fb | |
taoneill | e8776d3d74 | |
taoneill | fa2be3d357 | |
taoneill | 3b0518ece0 | |
taoneill | aeeb458408 | |
taoneill | 73e29c2025 | |
taoneill | 3e452e9e21 | |
Tim Düsterhus | 6871c76a70 | |
Tim Düsterhus | 082d89ec08 | |
Tim Düsterhus | 2c25017b40 | |
Tim Düsterhus | 49376848ff | |
Tim Düsterhus | 174126209b | |
Tim Düsterhus | e9f56967cb | |
Tim Düsterhus | 5f0bc9f2b8 | |
Tim Düsterhus | 0019e7e107 | |
Tim Düsterhus | e1b895a966 | |
Tim Düsterhus | ae13d93da1 | |
Tim Düsterhus | f013c209a8 | |
Tim Düsterhus | 44df6a3f62 | |
Tim Düsterhus | 7e6a2988a6 | |
taoneill | 7fef7c9649 |
|
@ -2,8 +2,8 @@
|
|||
.*
|
||||
# except for .gitignore
|
||||
!.gitignore
|
||||
!.classpath
|
||||
!.project
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# Ignore all classfiles
|
||||
*.class
|
||||
|
@ -12,3 +12,5 @@
|
|||
bin
|
||||
*/lib/*
|
||||
*/target/*
|
||||
dependency-reduced-pom.xml
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2012 Thomas-Antoine O'Neill aka tommytony, http://war.tommytony.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,36 @@
|
|||
![War logo](http://i.imgur.com/LFdiF.png "War - Minecraft PVP Arenas - TDM, CTF and more!")
|
||||
|
||||
War - Minecraft PVP Arenas (TDM, CTF and more!)
|
||||
===============================================
|
||||
|
||||
War is a plugin for Bukkit that adds PVP arenas and team deathmatch gamemodes to Minecraft servers.
|
||||
|
||||
Official website
|
||||
----------------
|
||||
Visit http://war.tommytony.com for more info, videos and links.
|
||||
|
||||
Features
|
||||
--------
|
||||
- Built on the popular Bukkit mod API (http://bukkit.org)
|
||||
- Capture-the-flag and team deathmatch arenas, called warzones
|
||||
- Warzone blocks are saved and reset at the end of every game, for safely destructible maps
|
||||
- Other game types: capture points and explosive-based objectives
|
||||
- Up to 16 teams!
|
||||
- Tons of customizable game rules, item loadouts and options (see [Instructions](http://war.tommytony.com/instructions))
|
||||
|
||||
Downloads
|
||||
---------
|
||||
All official releases are at https://github.com/taoneill/war/downloads.
|
||||
|
||||
Dev Builds
|
||||
----------
|
||||
Development builds are available at https://cmastudios.me/cgi-bin/war.py.
|
||||
|
||||
Author
|
||||
------
|
||||
tommytony started the plugin in December 2010 on hMod and has been maintaining it since with the help of contributors.
|
||||
Reach him at taoneill@tommytony.com.
|
||||
|
||||
License
|
||||
-------
|
||||
War is licensed loosely under the MIT License (but still comes with the weird baggage of Bukkit licensing)
|
|
@ -1,9 +0,0 @@
|
|||
War adds team deathmatch and capture-the-flag to Minecraft SMP.
|
||||
|
||||
The plugin started on hMod but was ported to Bukkit from v0.3 on.
|
||||
|
||||
Grab your copy in the Downloads section.
|
||||
|
||||
Go to http://war.tommytony.com for more.
|
||||
|
||||
All credit goes to Mojang, hey0 and the Bukkit team for being so awesome.
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/bukkit"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/craftbukkit"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="lib" path="C:/dev/war/war/lib/mockito-all-1.8.5.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Permissions"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
29
war/.project
29
war/.project
|
@ -1,29 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>war</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>net.sourceforge.metrics.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
<nature>net.sourceforge.metrics.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
165
war/pom.xml
165
war/pom.xml
|
@ -1,68 +1,137 @@
|
|||
<?xml version="1.0"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.tommytony</groupId>
|
||||
<artifactId>war</artifactId>
|
||||
<version>1.6</version>
|
||||
<version>2.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>War</name>
|
||||
<url>http://war.tommytony.com</url>
|
||||
<description>Minecraft PVP arenas (called warzones) for a fast-paced and structured PVP experience with TDM, CTF and more!</description>
|
||||
<prerequisites>
|
||||
<maven>2.2.1</maven>
|
||||
</prerequisites>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven.cmastudios.me</id>
|
||||
<url>https://maven.cmastudios.me/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>https://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<issueManagement>
|
||||
<system>Github issues</system>
|
||||
<url>https://github.com/taoneill/war/issues</url>
|
||||
</issueManagement>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/taoneill/war.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:taoneill/war.git</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
<url>https://github.com/taoneill/war</url>
|
||||
</scm>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>maven.cmastudios.me</id>
|
||||
<url>s3://maven.cmastudios.me/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/java/</directory>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>org.mcstats.bukkit:metrics</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.mcstats</pattern>
|
||||
<shadedPattern>com.tommytony.war.metrics</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>org.kuali.maven.wagons</groupId>
|
||||
<artifactId>maven-s3-wagon</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>1.13-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.9.5</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.tommytony</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.0.0-beta-01</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mcstats.bukkit</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
<version>R8-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nijikokun.bukkit</groupId>
|
||||
<artifactId>Permissions</artifactId>
|
||||
<version>2.7.4</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.8.5</version>
|
||||
<scope>test</scope>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.32</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,865 +0,0 @@
|
|||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
import com.tommytony.war.*;
|
||||
import com.tommytony.war.mappers.*;
|
||||
import com.tommytony.war.utils.*;
|
||||
|
||||
/**
|
||||
* Main class of War
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class War extends JavaPlugin {
|
||||
public static PermissionHandler permissionHandler;
|
||||
public static War war;
|
||||
private static boolean loadedOnce = false;
|
||||
|
||||
// general
|
||||
private WarPlayerListener playerListener = new WarPlayerListener();
|
||||
private WarEntityListener entityListener = new WarEntityListener();
|
||||
private WarBlockListener blockListener = new WarBlockListener();
|
||||
private WarCommandHandler commandHandler = new WarCommandHandler();
|
||||
private Logger logger;
|
||||
private PluginDescriptionFile desc = null;
|
||||
private boolean loaded = false;
|
||||
|
||||
// Zones and hub
|
||||
private List<Warzone> warzones = new ArrayList<Warzone>();
|
||||
private WarHub warHub;
|
||||
private final List<Warzone> incompleteZones = new ArrayList<Warzone>();
|
||||
private final List<String> zoneMakerNames = new ArrayList<String>();
|
||||
private final List<String> commandWhitelist = new ArrayList<String>();
|
||||
private final List<String> zoneMakersImpersonatingPlayers = new ArrayList<String>();
|
||||
private HashMap<String, InventoryStash> disconnected = new HashMap<String, InventoryStash>();
|
||||
private final HashMap<String, String> wandBearers = new HashMap<String, String>(); // playername to zonename
|
||||
|
||||
// Global settings
|
||||
private boolean pvpInZonesOnly = false;
|
||||
private boolean disablePvpMessage = false;
|
||||
private boolean buildInZonesOnly = false;
|
||||
|
||||
// Default warzone settings
|
||||
private final HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
||||
private int defaultLifepool = 7;
|
||||
private int defaultTeamCap = 7;
|
||||
private int defaultScoreCap = 10;
|
||||
private int defaultMonumentHeal = 5;
|
||||
private boolean defaultBlockHeads = true;
|
||||
private boolean defaultFriendlyFire = false;
|
||||
private boolean defaultAutoAssignOnly = false;
|
||||
private boolean defaultUnbreakableZoneBlocks = false;
|
||||
private boolean defaultNoCreatures = false;
|
||||
private boolean defaultResetOnEmpty = false, defaultResetOnLoad = false, defaultResetOnUnload = false;
|
||||
private String defaultSpawnStyle = TeamSpawnStyles.BIG;
|
||||
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
|
||||
|
||||
public War() {
|
||||
super();
|
||||
War.war = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see JavaPlugin.onEnable()
|
||||
* @see War.loadWar()
|
||||
*/
|
||||
public void onEnable() {
|
||||
this.loadWar();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see JavaPlugin.onDisable()
|
||||
* @see War.unloadWar()
|
||||
*/
|
||||
public void onDisable() {
|
||||
this.unloadWar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes war
|
||||
*/
|
||||
public void loadWar() {
|
||||
this.setLoaded(true);
|
||||
this.desc = this.getDescription();
|
||||
this.logger = this.getServer().getLogger();
|
||||
this.setupPermissions();
|
||||
|
||||
if(!loadedOnce) {
|
||||
loadedOnce = true; // This prevented multiple hookups of the same listener
|
||||
|
||||
// Register hooks
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.INVENTORY_OPEN, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Priority.Normal, this);
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.High, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_COMBUST, this.entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this);
|
||||
|
||||
pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Priority.Normal, this);
|
||||
}
|
||||
|
||||
// Load files from disk or create them (using these defaults)
|
||||
this.getDefaultLoadout().put(0, new ItemStack(Material.STONE_SWORD, 1, (byte) 8));
|
||||
this.getDefaultLoadout().put(1, new ItemStack(Material.BOW, 1, (byte) 8));
|
||||
this.getDefaultLoadout().put(2, new ItemStack(Material.ARROW, 7));
|
||||
this.getDefaultLoadout().put(3, new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8));
|
||||
this.getDefaultLoadout().put(4, new ItemStack(Material.STONE_SPADE, 1, (byte) 8));
|
||||
this.getDefaultReward().put( 0, new ItemStack(Material.CAKE, 1));
|
||||
|
||||
WarMapper.load();
|
||||
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up war
|
||||
*/
|
||||
public void unloadWar() {
|
||||
for (Warzone warzone : this.warzones) {
|
||||
warzone.unload();
|
||||
}
|
||||
this.warzones.clear();
|
||||
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
|
||||
if (this.warHub != null) {
|
||||
this.warHub.getVolume().resetBlocks();
|
||||
}
|
||||
|
||||
this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO);
|
||||
this.setLoaded(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes Permissions
|
||||
*/
|
||||
public void setupPermissions() {
|
||||
Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
|
||||
if (War.permissionHandler == null) {
|
||||
if (permissionsPlugin != null) {
|
||||
War.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
||||
} else {
|
||||
this.log("Permissions system not enabled. Defaulting to regular War config.", Level.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles war commands
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
return this.commandHandler.handle(sender, cmd, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the player-inventory to a loadout hashmap
|
||||
*
|
||||
* @param inv inventory to get the items from
|
||||
* @param loadout the hashmap to save to
|
||||
*/
|
||||
private void inventoryToLoadout(PlayerInventory inv, HashMap<Integer, ItemStack> loadout) {
|
||||
loadout.clear();
|
||||
int i = 0;
|
||||
for (ItemStack stack : inv.getContents()) {
|
||||
if (stack != null && stack.getType() != Material.AIR) {
|
||||
loadout.put(i, stack);
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
if (inv.getBoots() != null && inv.getBoots().getType() != Material.AIR) {
|
||||
loadout.put(100, inv.getBoots());
|
||||
}
|
||||
if (inv.getLeggings() != null && inv.getLeggings().getType() != Material.AIR) {
|
||||
loadout.put(101, inv.getLeggings());
|
||||
}
|
||||
if (inv.getChestplate() != null && inv.getChestplate().getType() != Material.AIR) {
|
||||
loadout.put(102, inv.getChestplate());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the player-inventory to a loadout hashmap
|
||||
*
|
||||
* @param player player to get the inventory to get the items from
|
||||
* @param loadout the hashmap to save to
|
||||
*/
|
||||
private void inventoryToLoadout(Player player, HashMap<Integer, ItemStack> loadout) {
|
||||
this.inventoryToLoadout(player.getInventory(), loadout);
|
||||
}
|
||||
|
||||
public boolean updateZoneFromNamedParams(Warzone warzone, CommandSender commandSender, String[] arguments) {
|
||||
try {
|
||||
Map<String, String> namedParams = new HashMap<String, String>();
|
||||
for (String namedPair : arguments) {
|
||||
String[] pairSplit = namedPair.split(":");
|
||||
if (pairSplit.length == 2) {
|
||||
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("lifepool")) {
|
||||
warzone.setLifePool(Integer.parseInt(namedParams.get("lifepool")));
|
||||
}
|
||||
if (namedParams.containsKey("monumentheal")) {
|
||||
warzone.setMonumentHeal(Integer.parseInt(namedParams.get("monumentheal")));
|
||||
}
|
||||
if (namedParams.containsKey("teamsize")) {
|
||||
warzone.setTeamCap(Integer.parseInt(namedParams.get("teamsize")));
|
||||
}
|
||||
if (namedParams.containsKey("maxscore")) {
|
||||
warzone.setScoreCap(Integer.parseInt(namedParams.get("maxscore")));
|
||||
}
|
||||
if (namedParams.containsKey("ff")) {
|
||||
String onOff = namedParams.get("ff");
|
||||
warzone.setFriendlyFire(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("autoassign")) {
|
||||
String onOff = namedParams.get("autoassign");
|
||||
warzone.setAutoAssignOnly(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("blockheads")) {
|
||||
String onOff = namedParams.get("blockheads");
|
||||
warzone.setBlockHeads(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("spawnstyle")) {
|
||||
String spawnStyle = namedParams.get("spawnstyle").toLowerCase();
|
||||
if (spawnStyle.equals(TeamSpawnStyles.SMALL)) {
|
||||
warzone.setSpawnStyle(spawnStyle);
|
||||
} else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) {
|
||||
warzone.setSpawnStyle(spawnStyle);
|
||||
} else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)) {
|
||||
warzone.setSpawnStyle(spawnStyle);
|
||||
} else {
|
||||
warzone.setSpawnStyle(TeamSpawnStyles.BIG);
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("unbreakable")) {
|
||||
String onOff = namedParams.get("unbreakable");
|
||||
warzone.setUnbreakableZoneBlocks(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("disabled")) {
|
||||
String onOff = namedParams.get("disabled");
|
||||
warzone.setDisabled(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("nocreatures")) {
|
||||
String onOff = namedParams.get("nocreatures");
|
||||
warzone.setNoCreatures(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
|
||||
if (namedParams.containsKey("resetonempty")) {
|
||||
String onOff = namedParams.get("resetonempty");
|
||||
warzone.setResetOnEmpty(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("resetonload")) {
|
||||
String onOff = namedParams.get("resetonload");
|
||||
warzone.setResetOnLoad(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("resetonunload")) {
|
||||
String onOff = namedParams.get("resetonunload");
|
||||
warzone.setResetOnUnload(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (commandSender instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
if (namedParams.containsKey("loadout")) {
|
||||
this.inventoryToLoadout(player, warzone.getLoadout());
|
||||
}
|
||||
if (namedParams.containsKey("reward")) {
|
||||
this.inventoryToLoadout(player, warzone.getReward());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateFromNamedParams(CommandSender commandSender, String[] arguments) {
|
||||
try {
|
||||
Map<String, String> namedParams = new HashMap<String, String>();
|
||||
for (String namedPair : arguments) {
|
||||
String[] pairSplit = namedPair.split(":");
|
||||
if (pairSplit.length == 2) {
|
||||
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("lifepool")) {
|
||||
this.setDefaultLifepool(Integer.parseInt(namedParams.get("lifepool")));
|
||||
}
|
||||
if (namedParams.containsKey("monumentheal")) {
|
||||
this.setDefaultMonumentHeal(Integer.parseInt(namedParams.get("monumentheal")));
|
||||
}
|
||||
if (namedParams.containsKey("teamsize")) {
|
||||
this.setDefaultTeamCap(Integer.parseInt(namedParams.get("teamsize")));
|
||||
}
|
||||
if (namedParams.containsKey("maxscore")) {
|
||||
this.setDefaultScoreCap(Integer.parseInt(namedParams.get("maxscore")));
|
||||
}
|
||||
if (namedParams.containsKey("ff")) {
|
||||
String onOff = namedParams.get("ff");
|
||||
this.setDefaultFriendlyFire(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("autoassign")) {
|
||||
String onOff = namedParams.get("autoassign");
|
||||
this.setDefaultAutoAssignOnly(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("pvpinzonesonly")) {
|
||||
String onOff = namedParams.get("pvpinzonesonly");
|
||||
this.setPvpInZonesOnly(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("disablepvpmessage")) {
|
||||
String onOff = namedParams.get("disablepvpmessage");
|
||||
this.setDisablePvpMessage(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("blockheads")) {
|
||||
String onOff = namedParams.get("blockheads");
|
||||
this.setDefaultBlockHeads(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("spawnstyle")) {
|
||||
String spawnStyle = namedParams.get("spawnstyle").toLowerCase();
|
||||
if (spawnStyle.equals(TeamSpawnStyles.SMALL)) {
|
||||
this.setDefaultSpawnStyle(spawnStyle);
|
||||
} else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) {
|
||||
this.setDefaultSpawnStyle(spawnStyle);
|
||||
} else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)) {
|
||||
this.setDefaultSpawnStyle(spawnStyle);
|
||||
} else {
|
||||
this.setDefaultSpawnStyle(TeamSpawnStyles.BIG);
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("buildinzonesonly")) {
|
||||
String onOff = namedParams.get("buildinzonesonly");
|
||||
this.setBuildInZonesOnly(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("unbreakable")) {
|
||||
String onOff = namedParams.get("unbreakable");
|
||||
this.setDefaultUnbreakableZoneBlocks(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("nocreatures")) {
|
||||
String onOff = namedParams.get("nocreatures");
|
||||
this.setDefaultNoCreatures(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
|
||||
if (namedParams.containsKey("resetonempty")) {
|
||||
String onOff = namedParams.get("resetonempty");
|
||||
this.setDefaultResetOnEmpty(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("resetonload")) {
|
||||
String onOff = namedParams.get("resetonload");
|
||||
this.setDefaultResetOnLoad(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (namedParams.containsKey("resetonunload")) {
|
||||
String onOff = namedParams.get("resetonunload");
|
||||
this.setDefaultResetOnUnload(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
if (commandSender instanceof Player) {
|
||||
Player player = (Player)commandSender;
|
||||
if (namedParams.containsKey("loadout")) {
|
||||
this.inventoryToLoadout(player, this.getDefaultLoadout());
|
||||
}
|
||||
if (namedParams.containsKey("reward")) {
|
||||
this.inventoryToLoadout(player, this.getDefaultReward());
|
||||
}
|
||||
if (namedParams.containsKey("rallypoint")) {
|
||||
this.setZoneRallyPoint(namedParams.get("rallypoint"), player);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String printConfig(Warzone zone) {
|
||||
return "Warzone " + zone.getName() + " config - "
|
||||
+ "lifepool:" + zone.getLifePool() + " "
|
||||
+ "teamsize:" + zone.getTeamCap() + " "
|
||||
+ "maxscore:" + zone.getScoreCap() + " "
|
||||
+ "ff:" + onOffStr(zone.getFriendlyFire())
|
||||
+ "autoassign:" + onOffStr(zone.getAutoAssignOnly())
|
||||
+ "blockheads:" + onOffStr(zone.isBlockHeads())
|
||||
+ "spawnstyle:" + zone.getSpawnStyle() + " "
|
||||
+ "monumentheal:" + zone.getMonumentHeal() + " "
|
||||
+ "unbreakable:" + onOffStr(zone.isUnbreakableZoneBlocks())
|
||||
+ "disabled:" + onOffStr(zone.isDisabled())
|
||||
+ "nocreatures:" + onOffStr(zone.isNoCreatures())
|
||||
+ "resetonempty:" + onOffStr(zone.isResetOnEmpty())
|
||||
+ "resetonload:" + onOffStr(zone.isResetOnLoad())
|
||||
+ "resetonunload:" + onOffStr(zone.isResetOnUnload());
|
||||
}
|
||||
|
||||
public String printConfig() {
|
||||
return "War config - "
|
||||
+ "pvpinzonesonly:" + onOffStr(War.war.isPvpInZonesOnly())
|
||||
+ "disablepvpmessage:" + onOffStr(War.war.isDisablePvpMessage())
|
||||
+ "buildinzonesonly:" + onOffStr(War.war.isBuildInZonesOnly())
|
||||
+ "- Warzone defaults - "
|
||||
+ "lifepool:" + War.war.getDefaultLifepool() + " "
|
||||
+ "teamsize:" + War.war.getDefaultTeamCap() + " "
|
||||
+ "maxscore:" + War.war.getDefaultScoreCap() + " "
|
||||
+ "ff:" + onOffStr(War.war.isDefaultFriendlyFire())
|
||||
+ "autoassign:" + onOffStr(War.war.isDefaultAutoAssignOnly())
|
||||
+ "blockheads:" + onOffStr(War.war.isDefaultBlockHeads())
|
||||
+ "spawnstyle:" + War.war.getDefaultSpawnStyle() + " "
|
||||
+ "monumentheal:" + War.war.getDefaultMonumentHeal() + " "
|
||||
+ "unbreakable:" + onOffStr(War.war.isDefaultUnbreakableZoneBlocks())
|
||||
+ "nocreatures:" + onOffStr(War.war.isDefaultNoCreatures())
|
||||
+ "resetonempty:" + onOffStr(War.war.isDefaultResetOnEmpty())
|
||||
+ "resetonload:" + onOffStr(War.war.isDefaultResetOnLoad())
|
||||
+ "resetonunload:" + onOffStr(War.war.isDefaultResetOnUnload());
|
||||
}
|
||||
|
||||
private String onOffStr(boolean makeThisAString) {
|
||||
if(makeThisAString) {
|
||||
return "on ";
|
||||
} else {
|
||||
return "off ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setZoneRallyPoint(String warzoneName, Player player) {
|
||||
Warzone zone = this.findWarzone(warzoneName);
|
||||
if (zone == null) {
|
||||
this.badMsg(player, "Can't set rally point. No such warzone.");
|
||||
} else {
|
||||
zone.setRallyPoint(player.getLocation());
|
||||
WarzoneMapper.save(zone, false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean inAnyWarzone(Location location) {
|
||||
Block locBlock = location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
Warzone currentZone = Warzone.getZoneByLocation(location);
|
||||
if (currentZone == null) {
|
||||
return false;
|
||||
} else if (currentZone.getVolume().isWallBlock(locBlock)) {
|
||||
return false; // wall block doesnt count. this lets people in at the lobby side wall because wall gates overlap with the zone.
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean inWarzone(String warzoneName, Location location) {
|
||||
Warzone currentZone = Warzone.getZoneByLocation(location);
|
||||
if (currentZone == null) {
|
||||
return false;
|
||||
} else if (warzoneName.toLowerCase().equals(currentZone.getName().toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addWarzone(Warzone zone) {
|
||||
this.warzones.add(zone);
|
||||
}
|
||||
|
||||
public List<Warzone> getWarzones() {
|
||||
return this.warzones;
|
||||
}
|
||||
|
||||
public void msg(CommandSender sender, String str) {
|
||||
if(sender instanceof Player) {
|
||||
String out = ChatColor.GRAY + "War> " + ChatColor.WHITE + this.colorKnownTokens(str, ChatColor.WHITE) + " ";
|
||||
ChatFixUtil.sendMessage(sender, out);
|
||||
} else {
|
||||
sender.sendMessage("War> " + str);
|
||||
}
|
||||
}
|
||||
|
||||
public void badMsg(CommandSender sender, String str) {
|
||||
if(sender instanceof Player) {
|
||||
String out = ChatColor.GRAY + "War> " + ChatColor.RED + this.colorKnownTokens(str, ChatColor.RED) + " ";
|
||||
ChatFixUtil.sendMessage(sender, out);
|
||||
} else {
|
||||
sender.sendMessage("War> " + str);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Colors the teams and examples in messages
|
||||
*
|
||||
* @param String str message-string
|
||||
* @param String msgColor current message-color
|
||||
* @return String Message with colored teams
|
||||
*/
|
||||
private String colorKnownTokens(String str, ChatColor msgColor) {
|
||||
for (TeamKind kind : TeamKinds.getTeamkinds()) {
|
||||
str = str.replaceAll(" " + kind.getDefaultName(), " " + kind.getColor() + kind.getDefaultName() + msgColor);
|
||||
}
|
||||
str = str.replaceAll("Ex -", ChatColor.GRAY + "Ex -");
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a specified message with a specified level
|
||||
*
|
||||
* @param String str message to log
|
||||
* @param Level lvl level to use
|
||||
*/
|
||||
public void log(String str, Level lvl) {
|
||||
this.getLogger().log(lvl, "War> " + str);
|
||||
}
|
||||
|
||||
// the only way to find a zone that has only one corner
|
||||
public Warzone findWarzone(String warzoneName) {
|
||||
for (Warzone warzone : this.warzones) {
|
||||
if (warzone.getName().toLowerCase().equals(warzoneName.toLowerCase())) {
|
||||
return warzone;
|
||||
}
|
||||
}
|
||||
for (Warzone warzone : this.incompleteZones) {
|
||||
if (warzone.getName().equals(warzoneName)) {
|
||||
return warzone;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canPlayWar(Player player) {
|
||||
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.player") || War.permissionHandler.has(player, "War.player"))) {
|
||||
return true;
|
||||
}
|
||||
if (War.permissionHandler == null) {
|
||||
// w/o Permissions, everyone can play
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canWarp(Player player) {
|
||||
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.warp") || War.permissionHandler.has(player, "War.warp"))) {
|
||||
return true;
|
||||
}
|
||||
if (War.permissionHandler == null) {
|
||||
// w/o Permissions, everyone can warp
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canBuildOutsideZone(Player player) {
|
||||
if (this.isBuildInZonesOnly()) {
|
||||
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.build") || War.permissionHandler.has(player, "War.build"))) {
|
||||
return true;
|
||||
}
|
||||
// w/o Permissions, if buildInZonesOnly, no one can build outside the zone except Zonemakers
|
||||
return this.isZoneMaker(player);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canPvpOutsideZones(Player player) {
|
||||
if (this.isPvpInZonesOnly()) {
|
||||
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.pvp") || War.permissionHandler.has(player, "War.pvp"))) {
|
||||
War.war.log(player.getName() + " can pvp. Has war.pvp.", Level.INFO);
|
||||
return true;
|
||||
}
|
||||
// w/o Permissions, if pvpInZoneOnly, no one can pvp outside the zone
|
||||
return false;
|
||||
} else {
|
||||
War.war.log(player.getName() + " can pvp. Not pvpinzonesonly.", Level.INFO);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isZoneMaker(Player player) {
|
||||
for (String disguised : this.zoneMakersImpersonatingPlayers) {
|
||||
if (disguised.equals(player.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (String zoneMaker : this.zoneMakerNames) {
|
||||
if (zoneMaker.equals(player.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.*") || War.permissionHandler.has(player, "War.*"))) {
|
||||
return true;
|
||||
} else {
|
||||
return player.isOp();
|
||||
}
|
||||
}
|
||||
|
||||
public void addWandBearer(Player player, String zoneName) {
|
||||
if (this.wandBearers.containsKey(player.getName())) {
|
||||
String alreadyHaveWand = this.wandBearers.get(player.getName());
|
||||
if (player.getInventory().first(Material.WOOD_SWORD) != -1) {
|
||||
if (zoneName.equals(alreadyHaveWand)) {
|
||||
this.badMsg(player, "You already have a wand for zone " + alreadyHaveWand + ". Drop the wooden sword first.");
|
||||
} else {
|
||||
// new zone, already have sword
|
||||
this.wandBearers.remove(player.getName());
|
||||
this.wandBearers.put(player.getName(), zoneName);
|
||||
this.msg(player, "Switched wand to zone " + zoneName + ".");
|
||||
}
|
||||
} else {
|
||||
// lost his sword, or new warzone
|
||||
if (zoneName.equals(alreadyHaveWand)) {
|
||||
// same zone, give him a new sword
|
||||
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8));
|
||||
this.msg(player, "Here's a new sword for zone " + zoneName + ".");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (player.getInventory().firstEmpty() == -1) {
|
||||
this.badMsg(player, "Your inventory is full. Please drop an item and try again.");
|
||||
} else {
|
||||
this.wandBearers.put(player.getName(), zoneName);
|
||||
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8));
|
||||
// player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.WOOD_SWORD));
|
||||
this.msg(player, "You now have a wand for zone " + zoneName + ". Left-click with wodden sword for corner 1. Right-click for corner 2.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWandBearer(Player player) {
|
||||
return this.wandBearers.containsKey(player.getName());
|
||||
}
|
||||
|
||||
public String getWandBearerZone(Player player) {
|
||||
if (this.isWandBearer(player)) {
|
||||
return this.wandBearers.get(player.getName());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void removeWandBearer(Player player) {
|
||||
if (this.wandBearers.containsKey(player.getName())) {
|
||||
this.wandBearers.remove(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<Integer, ItemStack> getDefaultLoadout() {
|
||||
return this.defaultLoadout;
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
public Warzone zoneOfZoneWallAtProximity(Location location) {
|
||||
for (Warzone zone : this.warzones) {
|
||||
if (zone.getWorld() == location.getWorld() && zone.isNearWall(location)) {
|
||||
return zone;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getZoneMakerNames() {
|
||||
return this.zoneMakerNames;
|
||||
}
|
||||
|
||||
public List<String> getCommandWhitelist() {
|
||||
return this.commandWhitelist;
|
||||
}
|
||||
|
||||
public boolean inAnyWarzoneLobby(Location location) {
|
||||
if (ZoneLobby.getLobbyByLocation(location) == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<String> getZoneMakersImpersonatingPlayers() {
|
||||
return this.zoneMakersImpersonatingPlayers;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ItemStack> getDefaultReward() {
|
||||
return this.defaultReward;
|
||||
}
|
||||
|
||||
public List<Warzone> getIncompleteZones() {
|
||||
return this.incompleteZones;
|
||||
}
|
||||
|
||||
public WarHub getWarHub() {
|
||||
return this.warHub;
|
||||
}
|
||||
|
||||
public void setWarHub(WarHub warHub) {
|
||||
this.warHub = warHub;
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public void setLoaded(boolean loaded) {
|
||||
this.loaded = loaded;
|
||||
}
|
||||
|
||||
public boolean isPvpInZonesOnly() {
|
||||
return pvpInZonesOnly;
|
||||
}
|
||||
|
||||
public void setPvpInZonesOnly(boolean pvpInZonesOnly) {
|
||||
this.pvpInZonesOnly = pvpInZonesOnly;
|
||||
}
|
||||
|
||||
public boolean isDisablePvpMessage() {
|
||||
return disablePvpMessage;
|
||||
}
|
||||
|
||||
public void setDisablePvpMessage(boolean disablePvpMessage) {
|
||||
this.disablePvpMessage = disablePvpMessage;
|
||||
}
|
||||
|
||||
public boolean isBuildInZonesOnly() {
|
||||
return buildInZonesOnly;
|
||||
}
|
||||
|
||||
public void setBuildInZonesOnly(boolean buildInZonesOnly) {
|
||||
this.buildInZonesOnly = buildInZonesOnly;
|
||||
}
|
||||
|
||||
public int getDefaultLifepool() {
|
||||
return defaultLifepool;
|
||||
}
|
||||
|
||||
public void setDefaultLifepool(int defaultLifepool) {
|
||||
this.defaultLifepool = defaultLifepool;
|
||||
}
|
||||
|
||||
public int getDefaultTeamCap() {
|
||||
return defaultTeamCap;
|
||||
}
|
||||
|
||||
public void setDefaultTeamCap(int defaultTeamCap) {
|
||||
this.defaultTeamCap = defaultTeamCap;
|
||||
}
|
||||
|
||||
public int getDefaultScoreCap() {
|
||||
return defaultScoreCap;
|
||||
}
|
||||
|
||||
public void setDefaultScoreCap(int defaultScoreCap) {
|
||||
this.defaultScoreCap = defaultScoreCap;
|
||||
}
|
||||
|
||||
public int getDefaultMonumentHeal() {
|
||||
return defaultMonumentHeal;
|
||||
}
|
||||
|
||||
public void setDefaultMonumentHeal(int defaultMonumentHeal) {
|
||||
this.defaultMonumentHeal = defaultMonumentHeal;
|
||||
}
|
||||
|
||||
public boolean isDefaultBlockHeads() {
|
||||
return defaultBlockHeads;
|
||||
}
|
||||
|
||||
public void setDefaultBlockHeads(boolean defaultBlockHeads) {
|
||||
this.defaultBlockHeads = defaultBlockHeads;
|
||||
}
|
||||
|
||||
public boolean isDefaultFriendlyFire() {
|
||||
return defaultFriendlyFire;
|
||||
}
|
||||
|
||||
public void setDefaultFriendlyFire(boolean defaultFriendlyFire) {
|
||||
this.defaultFriendlyFire = defaultFriendlyFire;
|
||||
}
|
||||
|
||||
public boolean isDefaultAutoAssignOnly() {
|
||||
return defaultAutoAssignOnly;
|
||||
}
|
||||
|
||||
public void setDefaultAutoAssignOnly(boolean defaultAutoAssignOnly) {
|
||||
this.defaultAutoAssignOnly = defaultAutoAssignOnly;
|
||||
}
|
||||
|
||||
public boolean isDefaultUnbreakableZoneBlocks() {
|
||||
return defaultUnbreakableZoneBlocks;
|
||||
}
|
||||
|
||||
public void setDefaultUnbreakableZoneBlocks(boolean defaultUnbreakableZoneBlocks) {
|
||||
this.defaultUnbreakableZoneBlocks = defaultUnbreakableZoneBlocks;
|
||||
}
|
||||
|
||||
public boolean isDefaultNoCreatures() {
|
||||
return defaultNoCreatures;
|
||||
}
|
||||
|
||||
public void setDefaultNoCreatures(boolean defaultNoCreatures) {
|
||||
this.defaultNoCreatures = defaultNoCreatures;
|
||||
}
|
||||
|
||||
public boolean isDefaultResetOnEmpty() {
|
||||
return defaultResetOnEmpty;
|
||||
}
|
||||
|
||||
public void setDefaultResetOnEmpty(boolean defaultResetOnEmpty) {
|
||||
this.defaultResetOnEmpty = defaultResetOnEmpty;
|
||||
}
|
||||
|
||||
public boolean isDefaultResetOnLoad() {
|
||||
return defaultResetOnLoad;
|
||||
}
|
||||
|
||||
public void setDefaultResetOnLoad(boolean defaultResetOnLoad) {
|
||||
this.defaultResetOnLoad = defaultResetOnLoad;
|
||||
}
|
||||
|
||||
public boolean isDefaultResetOnUnload() {
|
||||
return defaultResetOnUnload;
|
||||
}
|
||||
|
||||
public void setDefaultResetOnUnload(boolean defaultResetOnUnload) {
|
||||
this.defaultResetOnUnload = defaultResetOnUnload;
|
||||
}
|
||||
|
||||
public String getDefaultSpawnStyle() {
|
||||
return defaultSpawnStyle;
|
||||
}
|
||||
|
||||
public void setDefaultSpawnStyle(String defaultSpawnStyle) {
|
||||
this.defaultSpawnStyle = defaultSpawnStyle;
|
||||
}
|
||||
|
||||
public HashMap<String, InventoryStash> getDisconnected() {
|
||||
return this.disconnected;
|
||||
}
|
||||
|
||||
public void setDisconnected(HashMap<String, InventoryStash> disconnected) {
|
||||
this.disconnected = disconnected;
|
||||
}
|
||||
}
|
|
@ -1,234 +0,0 @@
|
|||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class WarBlockListener extends BlockListener {
|
||||
|
||||
/**
|
||||
* @see BlockListener.onBlockPlace()
|
||||
*/
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player == null || block == null) return;
|
||||
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
// Monument capturing
|
||||
if (team != null && block != null && zone != null && zone.isMonumentCenterBlock(block) && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
|
||||
Monument monument = zone.getMonumentFromCenterBlock(block);
|
||||
if (monument != null && !monument.hasOwner()) {
|
||||
monument.capture(team);
|
||||
List<Team> teams = zone.getTeams();
|
||||
for (Team t : teams) {
|
||||
t.teamcast("Monument " + monument.getName() + " has been captured by team " + team.getName() + ".");
|
||||
}
|
||||
event.setCancelled(false);
|
||||
return; // important otherwise cancelled down a few line by isImportantblock
|
||||
} else {
|
||||
War.war.badMsg(player, "You can't capture a monument without a block of your team's material. Get one from your team spawn.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
// prevent build in important parts
|
||||
if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
War.war.badMsg(player, "Can't build here.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
for (Warzone wz : War.war.getWarzones()) {
|
||||
if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "Can't build here.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// protect the hub
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "Can't build here.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
if (zone == null && War.war.isBuildInZonesOnly() && !War.war.canBuildOutsideZone(player)) {
|
||||
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// can't place a block of your team's color
|
||||
if (team != null && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
|
||||
War.war.badMsg(player, "You can only use your team's blocks to capture monuments.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// a flag thief can't drop his flag
|
||||
if (team != null && zone != null && zone.isFlagThief(player.getName())) {
|
||||
War.war.badMsg(player, "Can't drop the flag. What are you doing? Run!");
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
|
||||
// unbreakableZoneBlocks
|
||||
if (zone != null && zone.isUnbreakableZoneBlocks() && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks)
|
||||
War.war.badMsg(player, "The blocks in this zone are unbreakable - this also means you can't build!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BlockListener.onBlockBreak()
|
||||
*/
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player != null && block != null) {
|
||||
this.handleBreakOrDamage(player, block, event);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
|
||||
if (warzone != null && team == null && !isZoneMaker) {
|
||||
// can't actually destroy blocks in a warzone if not part of a team
|
||||
War.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// monument's center is destroyed
|
||||
if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
|
||||
Monument monument = warzone.getMonumentFromCenterBlock(block);
|
||||
if (monument.hasOwner()) {
|
||||
List<Team> teams = warzone.getTeams();
|
||||
for (Team t : teams) {
|
||||
t.teamcast("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName());
|
||||
}
|
||||
monument.uncapture();
|
||||
}
|
||||
event.setCancelled(false);
|
||||
return;
|
||||
}
|
||||
// changes in parts of important areas
|
||||
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
// breakage of spawn
|
||||
if (team != null && team.getSpawnVolume().contains(block)) {
|
||||
ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData());
|
||||
// let team members loot one block the spawn for monument captures
|
||||
if (player.getInventory().contains(teamKindBlock)) {
|
||||
War.war.badMsg(player, "You already have a " + team.getName() + " block.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down
|
||||
return;
|
||||
}
|
||||
}
|
||||
// stealing of flag
|
||||
if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
|
||||
if (warzone.isFlagThief(player.getName())) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "You can only steal one flag at a time!");
|
||||
} else {
|
||||
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
|
||||
if (lostFlagTeam.getPlayers().size() != 0) {
|
||||
// player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack teamKindBlock = new ItemStack(lostFlagTeam.getKind().getMaterial(), 1, (short) 1, new Byte(lostFlagTeam.getKind().getData()));
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(teamKindBlock);
|
||||
warzone.addFlagThief(lostFlagTeam, player.getName());
|
||||
block.setType(Material.AIR);
|
||||
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast(team.getKind().getColor() + player.getName() + ChatColor.WHITE + " stole team " + lostFlagTeam.getName() + "'s flag.");
|
||||
if (t.getName().equals(lostFlagTeam.getName())) {
|
||||
t.teamcast("Prevent " + team.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " from reaching team " + team.getName() + "'s spawn or flag.");
|
||||
}
|
||||
}
|
||||
War.war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!");
|
||||
} else {
|
||||
War.war.msg(player, "You can't steal team " + lostFlagTeam.getName() + "'s flag since no players are on that team.");
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (!warzone.isMonumentCenterBlock(block)) {
|
||||
War.war.badMsg(player, "Can't destroy this.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
if (block != null) {
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "Can't destroy this.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protect the hub
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "Can't destroy this.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
|
||||
if (blockZone == null && War.war.isBuildInZonesOnly() && !War.war.canBuildOutsideZone(player)) {
|
||||
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// unbreakableZoneBlocks
|
||||
if (blockZone != null && blockZone.isUnbreakableZoneBlocks() && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks
|
||||
War.war.badMsg(player, "The blocks in this zone are unbreakable!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,255 +0,0 @@
|
|||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.entity.CraftTNTPrimed;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Handles Entity-Events
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarEntityListener extends EntityListener {
|
||||
|
||||
/**
|
||||
* Handles PVP-Damage
|
||||
*
|
||||
* @param event fired event
|
||||
*/
|
||||
private void handlerAttackDefend(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
Entity defender = event.getEntity();
|
||||
|
||||
if (attacker != null && defender != null && attacker instanceof Player && defender instanceof Player) {
|
||||
// only let adversaries (same warzone, different team) attack each other
|
||||
Player a = (Player) attacker;
|
||||
Player d = (Player) defender;
|
||||
Warzone attackerWarzone = Warzone.getZoneByPlayerName(a.getName());
|
||||
Team attackerTeam = Team.getTeamByPlayerName(a.getName());
|
||||
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
|
||||
Team defenderTeam = Team.getTeamByPlayerName(d.getName());
|
||||
|
||||
if (attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone) {
|
||||
// Make sure one of the players isn't in the spawn
|
||||
if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn
|
||||
if (!defenderWarzone.isFlagThief(d.getName())) { // thieves can always be attacked
|
||||
War.war.badMsg(a, "Can't attack a player that's inside his team's spawn.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (attackerTeam.getSpawnVolume().contains(a.getLocation()) && !attackerTeam.getSpawnVolume().contains(d.getLocation())) {
|
||||
// only let a player inside spawn attack an enemy player if that player enters the spawn
|
||||
if (!attackerWarzone.isFlagThief(a.getName())) { // thieves can always attack
|
||||
War.war.badMsg(a, "Can't attack a player from inside your spawn.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Detect death, prevent it and respawn the player
|
||||
if (event.getDamage() >= d.getHealth()) {
|
||||
String killMessage = "";
|
||||
String attackerString = attackerTeam.getKind().getColor() + a.getDisplayName();
|
||||
String defenderString = defenderTeam.getKind().getColor() + d.getDisplayName();
|
||||
killMessage = attackerString + ChatColor.WHITE + " killed " + defenderString;
|
||||
for (Team team : defenderWarzone.getTeams()) {
|
||||
team.teamcast(killMessage);
|
||||
}
|
||||
defenderWarzone.handleDeath(d);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) {
|
||||
// same team, but not same person
|
||||
if (attackerWarzone.getFriendlyFire()) {
|
||||
War.war.badMsg(a, "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the attack go through
|
||||
} else {
|
||||
War.war.badMsg(a, "Your attack missed! Your target is on your team.");
|
||||
event.setCancelled(true); // ff is off
|
||||
}
|
||||
} else if (attackerTeam == null && defenderTeam == null && War.war.canPvpOutsideZones(a)) {
|
||||
// let normal PVP through is its not turned off or if you have perms
|
||||
} else if (attackerTeam == null && defenderTeam == null && !War.war.canPvpOutsideZones(a)) {
|
||||
if (!War.war.isDisablePvpMessage()) {
|
||||
War.war.badMsg(a, "You need the 'war.pvp' permission to attack players outside warzones.");
|
||||
}
|
||||
event.setCancelled(true); // global pvp is off
|
||||
} else {
|
||||
War.war.badMsg(a, "Your attack missed!");
|
||||
if (attackerTeam == null) {
|
||||
War.war.badMsg(a, "You must join a team, then you'll be able to damage people " + "in the other teams in that warzone.");
|
||||
} else if (defenderTeam == null) {
|
||||
War.war.badMsg(a, "Your target is not in a team.");
|
||||
} else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) {
|
||||
// You just hit yourself, probably with a bouncing arrow
|
||||
} else if (attackerTeam == defenderTeam) {
|
||||
War.war.badMsg(a, "Your target is on your team.");
|
||||
} else if (attackerWarzone != defenderWarzone) {
|
||||
War.war.badMsg(a, "Your target is playing in another warzone.");
|
||||
}
|
||||
event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team
|
||||
}
|
||||
} else if (defender instanceof Player) {
|
||||
// attacked by dispenser arrow most probably
|
||||
// Detect death, prevent it and respawn the player
|
||||
Player d = (Player) defender;
|
||||
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
|
||||
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
|
||||
String deathMessage = "";
|
||||
String defenderString = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName();
|
||||
if (event instanceof EntityDamageByProjectileEvent) {
|
||||
deathMessage = "A dispenser killed " + defenderString;
|
||||
} else if (event.getDamager() instanceof CraftTNTPrimed) {
|
||||
deathMessage = defenderString + ChatColor.WHITE + " exploded";
|
||||
} else {
|
||||
deathMessage = defenderString + ChatColor.WHITE + " died";
|
||||
}
|
||||
for (Team team : defenderWarzone.getTeams()) {
|
||||
team.teamcast(deathMessage);
|
||||
}
|
||||
defenderWarzone.handleDeath(d);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protects important structures from explosions
|
||||
*
|
||||
* @see EntityListener.onEntityExplode()
|
||||
*/
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
// protect zones elements, lobbies and warhub from creepers
|
||||
List<Block> explodedBlocks = event.blockList();
|
||||
for (Block block : explodedBlocks) {
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
event.setCancelled(true);
|
||||
War.war.log("Explosion prevented at warhub.", Level.INFO);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.isImportantBlock(block)) {
|
||||
event.setCancelled(true);
|
||||
War.war.log("Explosion prevented in zone " + zone.getName() + ".", Level.INFO);
|
||||
return;
|
||||
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
|
||||
event.setCancelled(true);
|
||||
War.war.log("Explosion prevented at zone " + zone.getName() + " lobby.", Level.INFO);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles damage on Players
|
||||
*
|
||||
* @see EntityListener.onEntityDamage()
|
||||
*/
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) entity;
|
||||
|
||||
// prevent godmode
|
||||
if (Warzone.getZoneByPlayerName(player.getName()) != null) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
// pass pvp-damage
|
||||
if (event instanceof EntityDamageByEntityEvent || event instanceof EntityDamageByProjectileEvent) {
|
||||
this.handlerAttackDefend((EntityDamageByEntityEvent) event);
|
||||
} else {
|
||||
// Detect death, prevent it and respawn the player
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null && event.getDamage() >= player.getHealth()) {
|
||||
String deathMessage = "";
|
||||
deathMessage = Team.getTeamByPlayerName(player.getName()).getKind().getColor() + player.getDisplayName() + ChatColor.WHITE + " died";
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast(deathMessage);
|
||||
}
|
||||
zone.handleDeath(player);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null && team.getSpawnVolume().contains(player.getLocation())) {
|
||||
// smother out the fire that didn't burn out when you respawned
|
||||
// Stop fire (upcast, watch out!)
|
||||
if (player instanceof CraftPlayer) {
|
||||
net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle();
|
||||
playerEntity.fireTicks = 0;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents creatures from spawning in warzones if no creatures is active
|
||||
*
|
||||
* @see EntityListener.onCreatureSpawn()
|
||||
*/
|
||||
@Override
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
|
||||
Location location = event.getLocation();
|
||||
Warzone zone = Warzone.getZoneByLocation(location);
|
||||
if (zone != null && zone.isNoCreatures()) {
|
||||
event.setCancelled(true);
|
||||
// war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents health regaining caused by peaceful mode
|
||||
*
|
||||
* @see EntityListener.onEntityRegainHealth()
|
||||
*/
|
||||
@Override
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (!War.war.isLoaded() || event.getRegainReason() != RegainReason.REGEN) return;
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) return;
|
||||
|
||||
Player player = (Player) entity;
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
if (zone != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,430 +0,0 @@
|
|||
package bukkit.tommytony.war;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.entity.CraftItem;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerInventoryEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.ZoneSetter;
|
||||
|
||||
/**
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarPlayerListener extends PlayerListener {
|
||||
private java.util.Random random = new java.util.Random();
|
||||
|
||||
/**
|
||||
* Correctly removes quitting players from warzones
|
||||
*
|
||||
* @see PlayerListener.onPlayerQuit()
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
zone.handlePlayerLeave(player, zone.getTeleport(), true);
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
War.war.removeWandBearer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null) {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
|
||||
if (zone.isFlagThief(player.getName())) {
|
||||
// a flag thief can't drop his flag
|
||||
War.war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!");
|
||||
event.setCancelled(true);
|
||||
|
||||
} else {
|
||||
Item item = event.getItemDrop();
|
||||
if (item != null) {
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) {
|
||||
// Can't drop your team's kind block
|
||||
War.war.badMsg(player, "Can't drop " + team.getName() + " block blocks.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone.isNearWall(player.getLocation()) && itemStack != null) {
|
||||
War.war.badMsg(player, "Can't drop items near the zone border!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
Item item = event.getItemDrop();
|
||||
if (item.getItemStack().getType() == Material.WOOD_SWORD) {
|
||||
String zoneName = War.war.getWandBearerZone(player);
|
||||
War.war.removeWandBearer(player);
|
||||
War.war.msg(player, "You dropped the zone " + zoneName + " wand.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null) {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
|
||||
if (zone.isFlagThief(player.getName())) {
|
||||
// a flag thief can't pick up anything
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
Item item = event.getItem();
|
||||
if (item != null && item instanceof CraftItem) {
|
||||
CraftItem cItem = (CraftItem) item;
|
||||
if (cItem != null) {
|
||||
ItemStack itemStack = cItem.getItemStack();
|
||||
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) {
|
||||
// Can't pick up a second precious block
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryOpen(PlayerInventoryEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Inventory inventory = event.getInventory();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null && inventory instanceof PlayerInventory) {
|
||||
// make sure the player doesn't have too many precious blocks
|
||||
// or illegal armor (i.e. armor not found in loadout)
|
||||
PlayerInventory playerInv = (PlayerInventory) inventory;
|
||||
ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData());
|
||||
if (playerInv.contains(teamKindBlock, 2)) {
|
||||
playerInv.remove(teamKindBlock);
|
||||
playerInv.addItem(teamKindBlock);
|
||||
War.war.badMsg(player, "All that " + team.getName() + " must have been heavy!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team talkingPlayerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (talkingPlayerTeam != null) {
|
||||
String msg = event.getMessage();
|
||||
String[] split = msg.split(" ");
|
||||
if (!War.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) {
|
||||
String command = split[0].substring(1);
|
||||
if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) {
|
||||
// allow white commands
|
||||
for (String whiteCommand : War.war.getCommandWhitelist()) {
|
||||
if (whiteCommand.equals(command)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
War.war.badMsg(player, "Can't use anything but War commands (e.g. /leave, /warhub) while you're playing in a warzone.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
String reason = event.getReason();
|
||||
if (reason.contains("moved") || reason.contains("too quickly") || reason.contains("Hacking")) {
|
||||
boolean inWarzone = War.war.inAnyWarzone(player.getLocation());
|
||||
boolean inLobby = War.war.inAnyWarzone(player.getLocation());
|
||||
boolean inWarhub = false;
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(player.getLocation())) {
|
||||
inWarhub = true;
|
||||
}
|
||||
if (inWarzone || inLobby || inWarhub) {
|
||||
event.setCancelled(true);
|
||||
War.war.log("Prevented " + player.getName() + " from getting kicked.", java.util.logging.Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getItemInHand().getType() == Material.WOOD_SWORD && War.war.isWandBearer(player)) {
|
||||
String zoneName = War.war.getWandBearerZone(player);
|
||||
ZoneSetter setter = new ZoneSetter(player, zoneName);
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
War.war.badMsg(player, "Too far.");
|
||||
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
setter.placeCorner1(event.getClickedBlock());
|
||||
event.setUseItemInHand(Result.ALLOW);
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
setter.placeCorner2(event.getClickedBlock());
|
||||
event.setUseItemInHand(Result.ALLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
Player player = event.getPlayer();
|
||||
Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result.
|
||||
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
|
||||
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||
|
||||
boolean canPlay = War.war.canPlayWar(player);
|
||||
boolean isMaker = War.war.isZoneMaker(player);
|
||||
|
||||
// Zone walls
|
||||
Team currentTeam = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
|
||||
boolean protecting = false;
|
||||
if (currentTeam != null) {
|
||||
// Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc);
|
||||
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
|
||||
} else {
|
||||
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
|
||||
if (nearbyZone != null && !isMaker) {
|
||||
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (!protecting) {
|
||||
// zone makers still need to delete their walls
|
||||
// make sure to delete any wall guards as you leave
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
zone.dropZoneWallGuardIfAny(player);
|
||||
}
|
||||
}
|
||||
|
||||
// Warzone lobby gates
|
||||
if (locLobby != null) {
|
||||
Warzone zone = locLobby.getZone();
|
||||
Team oldTeam = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isAutoAssignGate = false;
|
||||
if (oldTeam == null && canPlay) { // trying to counter spammy player move
|
||||
isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc);
|
||||
if (isAutoAssignGate) {
|
||||
if (zone.isDisabled()) {
|
||||
this.handleDisabledZone(event, player, zone);
|
||||
} else {
|
||||
this.dropFromOldTeamIfAny(player);
|
||||
int noOfPlayers = 0;
|
||||
for (Team t : zone.getTeams()) {
|
||||
noOfPlayers += t.getPlayers().size();
|
||||
}
|
||||
if (noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) {
|
||||
zone.autoAssign(player);
|
||||
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(zone);
|
||||
}
|
||||
} else {
|
||||
event.setTo(zone.getTeleport());
|
||||
// player.teleport(zone.getTeleport());
|
||||
War.war.badMsg(player, "All teams are full.");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// go through all the team gates
|
||||
for (Team team : zone.getTeams()) {
|
||||
if (zone.getLobby().isInTeamGate(team, playerLoc)) {
|
||||
this.dropFromOldTeamIfAny(player);
|
||||
if (zone.isDisabled()) {
|
||||
this.handleDisabledZone(event, player, zone);
|
||||
} else if (team.getPlayers().size() < zone.getTeamCap()) {
|
||||
team.addPlayer(player);
|
||||
team.resetSign();
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(zone);
|
||||
}
|
||||
zone.keepPlayerInventory(player);
|
||||
War.war.msg(player, "Your inventory is in storage until you use '/war leave'.");
|
||||
zone.respawnPlayer(event, team, player);
|
||||
for (Team t : zone.getTeams()) {
|
||||
t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
|
||||
}
|
||||
} else {
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.badMsg(player, "Team " + team.getName() + " is full.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc) && !War.war.getWarHub().getVolume().contains(player.getLocation())) {
|
||||
this.dropFromOldTeamIfAny(player);
|
||||
event.setTo(War.war.getWarHub().getLocation());
|
||||
// player.teleport(war.getWarHub().getLocation());
|
||||
War.war.msg(player, "Welcome to the War hub.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Warhub zone gates
|
||||
WarHub hub = War.war.getWarHub();
|
||||
if (hub != null && hub.getVolume().contains(player.getLocation())) {
|
||||
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
|
||||
if (zone != null && zone.getTeleport() != null) {
|
||||
event.setTo(zone.getTeleport());
|
||||
// player.teleport(zone.getTeleport());
|
||||
War.war.msg(player, "Welcome to warzone " + zone.getName() + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc);
|
||||
Team playerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (isLeaving) { // already in a team and in warzone, leaving
|
||||
// same as leave
|
||||
if (playerTeam != null) {
|
||||
boolean atSpawnAlready = playerTeam.getTeamSpawn().getBlockX() == player.getLocation().getBlockX() && playerTeam.getTeamSpawn().getBlockY() == player.getLocation().getBlockY() && playerTeam.getTeamSpawn().getBlockZ() == player.getLocation().getBlockZ();
|
||||
if (!atSpawnAlready) {
|
||||
playerWarzone.handlePlayerLeave(player, playerWarzone.getTeleport(), event, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (playerWarzone != null) {
|
||||
// Player belongs to a warzone team but is outside: he snuck out or is at spawn and died
|
||||
if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) {
|
||||
War.war.badMsg(player, "Use /leave (or /war leave) to exit the zone.");
|
||||
event.setTo(playerTeam.getTeamSpawn());
|
||||
return;
|
||||
}
|
||||
|
||||
// Monuments
|
||||
if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead
|
||||
&& this.random.nextInt(77) == 3) { // one chance out of many of getting healed
|
||||
int currentHp = player.getHealth();
|
||||
int newHp = Math.max(20, currentHp + locZone.getMonumentHeal());
|
||||
|
||||
player.setHealth(newHp);
|
||||
String isS = "s";
|
||||
String heartNum = ""; // since (newHp-currentHp)/2 won't give the right amount
|
||||
if (newHp - currentHp == 2) { // no 's' in 'hearts' when it's just one heart
|
||||
isS = "";
|
||||
heartNum = "one ";
|
||||
} else if (newHp - currentHp % 2 == 0) {
|
||||
heartNum = ((newHp - currentHp) / 2) + " ";
|
||||
} else {
|
||||
heartNum = ((newHp - currentHp - 1) / 2) + ".5 ";
|
||||
}
|
||||
War.war.msg(player, "Your dance pleases the monument's voodoo. You gain " + heartNum + "heart" + isS + "!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Flag capture
|
||||
if (playerWarzone.isFlagThief(player.getName()) && (playerTeam.getSpawnVolume().contains(player.getLocation()) || (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) {
|
||||
if (playerWarzone.isTeamFlagStolen(playerTeam)) {
|
||||
War.war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned.");
|
||||
} else {
|
||||
synchronized (playerWarzone) {
|
||||
// flags can be captured at own spawn or own flag pole
|
||||
playerTeam.addPoint();
|
||||
if (playerTeam.getPoints() >= playerWarzone.getScoreCap()) {
|
||||
if (playerWarzone.hasPlayerInventory(player.getName())) {
|
||||
playerWarzone.restorePlayerInventory(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(player, playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
// player.teleport(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// added a point
|
||||
Team victim = playerWarzone.getVictimTeamForThief(player.getName());
|
||||
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
|
||||
victim.initializeTeamFlag();
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point.");
|
||||
}
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
playerWarzone.removeThief(player.getName());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
|
||||
// player is not in any team, but inside warzone boundaries, get him out
|
||||
Warzone zone = Warzone.getZoneByLocation(playerLoc);
|
||||
event.setTo(zone.getTeleport());
|
||||
// player.teleport(zone.getTeleport());
|
||||
War.war.badMsg(player, "You can't be inside a warzone without a team.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) {
|
||||
if (zone.getLobby() != null) {
|
||||
War.war.badMsg(player, "This warzone is disabled.");
|
||||
event.setTo(zone.getTeleport());
|
||||
}
|
||||
}
|
||||
|
||||
private void dropFromOldTeamIfAny(Player player) {
|
||||
// drop from old team if any
|
||||
Team previousTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (previousTeam != null) {
|
||||
if (!previousTeam.removePlayer(player.getName())) {
|
||||
War.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public abstract class AbstractWarCommand {
|
||||
|
||||
private CommandSender sender;
|
||||
protected String[] args;
|
||||
protected WarCommandHandler handler;
|
||||
public AbstractWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
this.handler = handler;
|
||||
this.setSender(sender);
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
abstract public boolean handle();
|
||||
|
||||
public void msg(String message) {
|
||||
War.war.msg(getSender(), message);
|
||||
}
|
||||
|
||||
public void badMsg(String message) {
|
||||
War.war.badMsg(getSender(), message);
|
||||
}
|
||||
|
||||
public void setSender(CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public abstract class AbstractZoneMakerCommand extends AbstractWarCommand {
|
||||
|
||||
public AbstractZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
if (sender instanceof Player) {
|
||||
if (!War.war.isZoneMaker((Player) sender)) {
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
}
|
||||
else if (!(sender instanceof ConsoleCommandSender)) {
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.TeamKinds;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
|
||||
public class JoinCommand extends AbstractWarCommand {
|
||||
public JoinCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
if (!War.war.canPlayWar(player)) {
|
||||
this.badMsg("Cannot play war. You need the war.player permission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Warzone zone;
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
// zone by name
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
// move the team-name to first place :)
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// drop from old team if any
|
||||
Team previousTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (previousTeam != null) {
|
||||
Warzone oldZone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (!previousTeam.removePlayer(player.getName())) {
|
||||
War.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING);
|
||||
}
|
||||
if (oldZone.isFlagThief(player.getName())) {
|
||||
Team victim = oldZone.getVictimTeamForThief(player.getName());
|
||||
victim.getFlagVolume().resetBlocks();
|
||||
victim.initializeTeamFlag();
|
||||
zone.removeThief(player.getName());
|
||||
for (Team t : oldZone.getTeams()) {
|
||||
t.teamcast("Team " + victim.getName() + " flag was returned.");
|
||||
}
|
||||
}
|
||||
previousTeam.resetSign();
|
||||
}
|
||||
|
||||
// join new team
|
||||
String name = this.args[0];
|
||||
TeamKind kind = TeamKinds.teamKindFromString(this.args[0]);
|
||||
|
||||
if (zone.isDisabled()) {
|
||||
this.msg("This warzone is disabled.");
|
||||
} else {
|
||||
List<Team> teams = zone.getTeams();
|
||||
boolean foundTeam = false;
|
||||
for (Team team : teams) {
|
||||
if (team.getName().startsWith(name) || team.getKind() == kind) {
|
||||
if (!zone.hasPlayerInventory(player.getName())) {
|
||||
zone.keepPlayerInventory(player);
|
||||
this.msg("Your inventory is in storage until you use '/war leave'.");
|
||||
}
|
||||
if (team.getPlayers().size() < zone.getTeamCap()) {
|
||||
team.addPlayer(player);
|
||||
team.resetSign();
|
||||
zone.respawnPlayer(team, player);
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(zone);
|
||||
}
|
||||
foundTeam = true;
|
||||
} else {
|
||||
this.msg("Team " + team.getName() + " is full.");
|
||||
foundTeam = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundTeam) {
|
||||
for (Team team : teams) {
|
||||
team.teamcast("" + player.getName() + " joined " + team.getName());
|
||||
}
|
||||
} else {
|
||||
this.msg("No such team. Try /teams.");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
public class NotZoneMakerException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5412011034665080340L;
|
||||
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
public class SaveZoneCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SaveZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone = null;
|
||||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
|
||||
if(this.args.length > 0 && !this.args[0].contains(":")) {
|
||||
// warzone name maybe in first place
|
||||
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
|
||||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
Player player = (Player)commandSender;
|
||||
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if(zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if(zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if(this.args.length > 1) {
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i-1] = args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
}
|
||||
|
||||
// We have a warzone and indexed-from-0 arguments, let's updatethis.msg(player, "Saving warzone " + warzone.getName() + ".");
|
||||
int savedBlocks = zone.saveState(true);
|
||||
|
||||
// changed settings: must reinitialize with new settings
|
||||
War.war.updateZoneFromNamedParams(zone, commandSender, args);
|
||||
WarzoneMapper.save(zone, true);
|
||||
if(this.args.length > 0) {
|
||||
// the config may have changed, requiring a reset for spawn styles etc.
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone(); // bring back team spawns etc
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
|
||||
|
||||
this.msg("Warzone " + zone.getName() + " initial state changed. Saved " + savedBlocks + " blocks.");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.TeamKinds;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class SetTeamCommand extends AbstractZoneMakerCommand {
|
||||
public SetTeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TeamKind teamKind = TeamKinds.teamKindFromString(this.args[0]);
|
||||
Team existingTeam = zone.getTeamByKind(teamKind);
|
||||
if (existingTeam != null) {
|
||||
// relocate
|
||||
existingTeam.setTeamSpawn(player.getLocation());
|
||||
this.msg("Team " + existingTeam.getName() + " spawn relocated.");
|
||||
} else {
|
||||
// new team (use default TeamKind name for now)
|
||||
Team newTeam = new Team(teamKind.getDefaultName(), teamKind, player.getLocation(), zone);
|
||||
newTeam.setRemainingLives(zone.getLifePool());
|
||||
zone.getTeams().add(newTeam);
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
newTeam.setTeamSpawn(player.getLocation());
|
||||
this.msg("Team " + newTeam.getName() + " created with spawn here.");
|
||||
}
|
||||
|
||||
WarzoneMapper.save(zone, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
|
||||
public class SetWarConfigCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SetWarConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
boolean wantsToPrint = false;
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
String config = War.war.printConfig();
|
||||
this.msg(config);
|
||||
return true;
|
||||
} else if (this.args.length > 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
if (War.war.updateFromNamedParams(this.getSender(), this.args)) {
|
||||
WarMapper.save();
|
||||
if (wantsToPrint) {
|
||||
String config = War.war.printConfig();
|
||||
this.msg("War config saved. " + config);
|
||||
} else {
|
||||
this.msg("War config saved.");
|
||||
}
|
||||
} else {
|
||||
this.msg("Failed to read named parameters.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class WarzoneCommand extends AbstractWarCommand {
|
||||
public WarzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (!War.war.canWarp(player)) {
|
||||
this.badMsg("Can't warp to zone. You need the 'war.warp' permission.");
|
||||
} else {
|
||||
Warzone warzone = Warzone.getZoneByName(this.args[0]);
|
||||
if (warzone != null && warzone.getTeleport() != null) {
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (playerWarzone != null) {
|
||||
playerWarzone.handlePlayerLeave(player, warzone.getTeleport(), true);
|
||||
} else {
|
||||
player.teleport(warzone.getTeleport());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
this.badMsg("No such warzone.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Lists all warzones
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarzonesCommand extends AbstractWarCommand {
|
||||
public WarzonesCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
String warzonesMessage = "Warzones: ";
|
||||
if (War.war.getWarzones().isEmpty()) {
|
||||
warzonesMessage += "none.";
|
||||
}
|
||||
else {
|
||||
for (Warzone warzone : War.war.getWarzones()) {
|
||||
warzonesMessage += warzone.getName() + " (" + warzone.getTeams().size() + " teams, ";
|
||||
int playerTotal = 0;
|
||||
for (Team team : warzone.getTeams()) {
|
||||
playerTotal += team.getPlayers().size();
|
||||
}
|
||||
warzonesMessage += playerTotal + " players) ";
|
||||
}
|
||||
}
|
||||
|
||||
this.msg(warzonesMessage + ((this.getSender() instanceof Player) ? " Use /zone <zone-name> to teleport to a warzone." : ""));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class ZoneMakerCommand extends AbstractWarCommand {
|
||||
|
||||
public ZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
if (sender instanceof Player) {
|
||||
if (!War.war.isZoneMaker((Player) sender)) {
|
||||
for (String name : War.war.getZoneMakersImpersonatingPlayers()) {
|
||||
if (((Player) sender).getName().equals(name)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (War.war.isZoneMaker(player)) {
|
||||
if (this.args.length == 0) {
|
||||
War.war.getZoneMakersImpersonatingPlayers().add(player.getName());
|
||||
this.msg("You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode.");
|
||||
} else if (this.args.length == 1) {
|
||||
// make someone zonemaker or remove the right
|
||||
if (War.war.getZoneMakerNames().contains(this.args[0])) {
|
||||
// kick
|
||||
War.war.getZoneMakerNames().remove(this.args[0]);
|
||||
this.msg(this.args[0] + " is not a zone maker anymore.");
|
||||
Player kickedMaker = War.war.getServer().getPlayer(this.args[0]);
|
||||
if (kickedMaker != null) {
|
||||
War.war.msg(kickedMaker, player.getName() + " took away your warzone maker priviledges.");
|
||||
}
|
||||
} else {
|
||||
// add
|
||||
War.war.getZoneMakerNames().add(this.args[0]);
|
||||
this.msg(this.args[0] + " is now a zone maker.");
|
||||
Player newMaker = War.war.getServer().getPlayer(this.args[0]);
|
||||
if (newMaker != null) {
|
||||
War.war.msg(newMaker, player.getName() + " made you warzone maker.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
War.war.getZoneMakersImpersonatingPlayers().remove(player.getName());
|
||||
this.msg("You are back as a zone maker.");
|
||||
WarMapper.save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class Monument {
|
||||
private Location location;
|
||||
private Volume volume;
|
||||
|
||||
private Team ownerTeam = null;
|
||||
private final String name;
|
||||
private Warzone warzone;
|
||||
|
||||
public Monument(String name, Warzone warzone, Location location) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.warzone = warzone;
|
||||
this.volume = new Volume(name, warzone.getWorld());
|
||||
this.setLocation(location);
|
||||
|
||||
this.addMonumentBlocks();
|
||||
}
|
||||
|
||||
public void addMonumentBlocks() {
|
||||
this.volume.setToMaterial(Material.AIR);
|
||||
|
||||
this.ownerTeam = null;
|
||||
int x = this.location.getBlockX();
|
||||
int y = this.location.getBlockY();
|
||||
int z = this.location.getBlockZ();
|
||||
|
||||
// center
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).getState().setType(Material.OBSIDIAN);
|
||||
|
||||
// inner ring
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
// outer ring
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z + 2).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z - 2).setType(Material.GLOWSTONE);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 2).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 2).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z + 2).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z - 2).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 2).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 2).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z + 2).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2).setType(Material.GLOWSTONE);
|
||||
|
||||
// block holder
|
||||
this.warzone.getWorld().getBlockAt(x, y, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y, z + 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z + 1).setType(Material.OBSIDIAN);
|
||||
|
||||
}
|
||||
|
||||
public boolean isNear(Location playerLocation) {
|
||||
int x = this.location.getBlockX();
|
||||
int y = this.location.getBlockY();
|
||||
int z = this.location.getBlockZ();
|
||||
int playerX = playerLocation.getBlockX();
|
||||
int playerY = playerLocation.getBlockY();
|
||||
int playerZ = playerLocation.getBlockZ();
|
||||
int diffX = Math.abs(playerX - x);
|
||||
int diffY = Math.abs(playerY - y);
|
||||
int diffZ = Math.abs(playerZ - z);
|
||||
if (diffX < 6 && diffY < 6 && diffZ < 6) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isOwner(Team team) {
|
||||
if (team == this.ownerTeam) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasOwner() {
|
||||
return this.ownerTeam != null;
|
||||
}
|
||||
|
||||
public void capture(Team team) {
|
||||
this.ownerTeam = team;
|
||||
}
|
||||
|
||||
public void uncapture() {
|
||||
this.ownerTeam = null;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public void setOwnerTeam(Team team) {
|
||||
this.ownerTeam = team;
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
Block locationBlock = this.warzone.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
this.volume.setCornerOne(locationBlock.getFace(BlockFace.DOWN).getFace(BlockFace.EAST, 2).getFace(BlockFace.SOUTH, 2));
|
||||
this.volume.setCornerTwo(locationBlock.getFace(BlockFace.UP, 2).getFace(BlockFace.WEST, 2).getFace(BlockFace.NORTH, 2));
|
||||
this.volume.saveBlocks();
|
||||
this.location = location;
|
||||
this.addMonumentBlocks();
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void setVolume(Volume newVolume) {
|
||||
this.volume = newVolume;
|
||||
|
||||
}
|
||||
|
||||
public Team getOwnerTeam() {
|
||||
|
||||
return this.ownerTeam;
|
||||
}
|
||||
}
|
|
@ -1,18 +1,26 @@
|
|||
package com.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.tommytony.war.config.*;
|
||||
import com.tommytony.war.utility.Direction;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Sign;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.utils.SignHelper;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -20,22 +28,31 @@ import com.tommytony.war.volumes.Volume;
|
|||
*
|
||||
*/
|
||||
public class Team {
|
||||
private final Warzone warzone;
|
||||
Random teamSpawnRandomizer = new Random();
|
||||
private List<Player> players = new ArrayList<Player>();
|
||||
private Location teamSpawn = null;
|
||||
private List<Player> teamChatPlayers = new ArrayList<Player>();
|
||||
private List<Location> teamSpawns;
|
||||
private Location teamFlag = null;
|
||||
private String name;
|
||||
private int remainingLives;
|
||||
private int points = 0;
|
||||
private Volume spawnVolume;
|
||||
private Map<Location, Volume> spawnVolumes;
|
||||
private Volume flagVolume;
|
||||
private final Warzone warzone;
|
||||
private TeamKind kind;
|
||||
private TeamConfigBag teamConfig;
|
||||
private InventoryBag inventories;
|
||||
|
||||
public Team(String name, TeamKind kind, Location teamSpawn, Warzone warzone) {
|
||||
public Team(String name, TeamKind kind, List<Location> teamSpawn, Warzone warzone) {
|
||||
this.warzone = warzone;
|
||||
this.teamConfig = new TeamConfigBag(warzone);
|
||||
this.inventories = new InventoryBag(warzone); // important constructors for cascading configs
|
||||
this.setName(name);
|
||||
this.teamSpawn = teamSpawn;
|
||||
this.setSpawnVolume(new Volume(name, warzone.getWorld()));
|
||||
this.teamSpawns = new ArrayList<Location>(teamSpawn);
|
||||
this.spawnVolumes = new HashMap<Location, Volume>();
|
||||
for (Location spawn : teamSpawn) {
|
||||
this.setSpawnVolume(spawn, new Volume(name + teamSpawns.indexOf(spawn), warzone.getWorld()));
|
||||
}
|
||||
this.kind = kind;
|
||||
this.setFlagVolume(null); // no flag at the start
|
||||
}
|
||||
|
@ -50,51 +67,62 @@ public class Team {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Warzone getZone() {
|
||||
return this.warzone;
|
||||
}
|
||||
|
||||
public TeamKind getKind() {
|
||||
return this.kind;
|
||||
}
|
||||
|
||||
private void setSpawnVolume() {
|
||||
if (this.spawnVolume.isSaved()) {
|
||||
this.spawnVolume.resetBlocks();
|
||||
private void createSpawnVolume(Location teamSpawn) {
|
||||
Volume spawnVolume = this.spawnVolumes.get(teamSpawn);
|
||||
if (spawnVolume.isSaved()) {
|
||||
spawnVolume.resetBlocks();
|
||||
}
|
||||
int x = this.teamSpawn.getBlockX();
|
||||
int y = this.teamSpawn.getBlockY();
|
||||
int z = this.teamSpawn.getBlockZ();
|
||||
int x = teamSpawn.getBlockX();
|
||||
int y = teamSpawn.getBlockY();
|
||||
int z = teamSpawn.getBlockZ();
|
||||
|
||||
if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.INVISIBLE)) {
|
||||
this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x, y - 1, z));
|
||||
this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x, y + 3, z));
|
||||
} else if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.SMALL)) {
|
||||
this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1));
|
||||
this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1));
|
||||
TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle();
|
||||
if (style.equals(TeamSpawnStyle.INVISIBLE)) {
|
||||
spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x, y - 1, z));
|
||||
spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x, y + 3, z));
|
||||
} else if (style.equals(TeamSpawnStyle.SMALL)) {
|
||||
spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1));
|
||||
spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1));
|
||||
} else {
|
||||
// flat or big
|
||||
this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2));
|
||||
this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 2, y + 3, z + 2));
|
||||
spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2));
|
||||
spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 2, y + 3, z + 2));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void initializeTeamSpawn() {
|
||||
// make air
|
||||
this.spawnVolume.setToMaterial(Material.AIR);
|
||||
public void initializeTeamSpawns() {
|
||||
for (Location teamSpawn : this.spawnVolumes.keySet()) {
|
||||
initializeTeamSpawn(teamSpawn);
|
||||
}
|
||||
}
|
||||
|
||||
public void initializeTeamSpawn(Location teamSpawn) {
|
||||
// Set the spawn
|
||||
int x = this.teamSpawn.getBlockX();
|
||||
int y = this.teamSpawn.getBlockY();
|
||||
int z = this.teamSpawn.getBlockZ();
|
||||
int x = teamSpawn.getBlockX();
|
||||
int y = teamSpawn.getBlockY();
|
||||
int z = teamSpawn.getBlockZ();
|
||||
|
||||
if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.INVISIBLE)) {
|
||||
// nothing but glowstone
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE);
|
||||
} else {
|
||||
ItemStack light = this.warzone.getWarzoneMaterials().getLightBlock();
|
||||
|
||||
TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle();
|
||||
if (!style.equals(TeamSpawnStyle.INVISIBLE)) {
|
||||
// first ring
|
||||
this.setBlock(x + 1, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x + 1, y - 1, z, this.kind);
|
||||
this.setBlock(x + 1, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x, y - 1, z + 1, this.kind);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE);
|
||||
BlockState lightBlock = this.warzone.getWorld().getBlockAt(x, y - 1, z).getState();
|
||||
lightBlock.setType(light.getType());
|
||||
lightBlock.setData(light.getData());
|
||||
lightBlock.update(true);
|
||||
this.setBlock(x, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z, this.kind);
|
||||
|
@ -103,42 +131,30 @@ public class Team {
|
|||
|
||||
// Orientation
|
||||
int yaw = 0;
|
||||
if (this.teamSpawn.getYaw() >= 0) {
|
||||
yaw = (int) (this.teamSpawn.getYaw() % 360);
|
||||
if (teamSpawn.getYaw() >= 0) {
|
||||
yaw = (int) (teamSpawn.getYaw() % 360);
|
||||
} else {
|
||||
yaw = (int) (360 + (this.teamSpawn.getYaw() % 360));
|
||||
yaw = (int) (360 + (teamSpawn.getYaw() % 360));
|
||||
}
|
||||
Block signBlock = null;
|
||||
int signData = 0;
|
||||
BlockFace signDirection = null;
|
||||
|
||||
if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.INVISIBLE)) {
|
||||
// INVISIBLE style
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z);
|
||||
if (yaw >= 0 && yaw < 90) {
|
||||
signData = 10;
|
||||
} else if (yaw >= 90 && yaw <= 180) {
|
||||
signData = 14;
|
||||
} else if (yaw >= 180 && yaw < 270) {
|
||||
signData = 2;
|
||||
} else if (yaw >= 270 && yaw <= 360) {
|
||||
signData = 6;
|
||||
}
|
||||
} else if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.SMALL)) {
|
||||
if (style.equals(TeamSpawnStyle.SMALL)) {
|
||||
// SMALL style
|
||||
if (yaw >= 0 && yaw < 90) {
|
||||
signData = 10;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.NORTH).getFace(BlockFace.WEST);
|
||||
signDirection = BlockFace.SOUTH_WEST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH()).getRelative(Direction.WEST());
|
||||
} else if (yaw >= 90 && yaw <= 180) {
|
||||
signData = 14;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.NORTH).getFace(BlockFace.EAST);
|
||||
signDirection = BlockFace.NORTH_WEST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH()).getRelative(Direction.EAST());
|
||||
} else if (yaw >= 180 && yaw < 270) {
|
||||
signData = 2;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.SOUTH).getFace(BlockFace.EAST);
|
||||
signDirection = BlockFace.NORTH_EAST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH()).getRelative(Direction.EAST());
|
||||
} else if (yaw >= 270 && yaw <= 360) {
|
||||
signData = 6;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.SOUTH).getFace(BlockFace.WEST);
|
||||
signDirection = BlockFace.SOUTH_EAST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH()).getRelative(Direction.WEST());
|
||||
}
|
||||
} else {
|
||||
} else if (!style.equals(TeamSpawnStyle.INVISIBLE)) {
|
||||
// outer ring (FLAT or BIG)
|
||||
this.setBlock(x + 2, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x + 2, y - 1, z + 1, this.kind);
|
||||
|
@ -161,15 +177,11 @@ public class Team {
|
|||
this.setBlock(x - 2, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y - 1, z - 2, this.kind);
|
||||
|
||||
BlockFace facing = null;
|
||||
BlockFace opposite = null;
|
||||
if (yaw >= 0 && yaw < 90) {
|
||||
facing = BlockFace.NORTH_WEST;
|
||||
opposite = BlockFace.SOUTH_EAST;
|
||||
signData = 10;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.NORTH, 2).getFace(BlockFace.WEST, 2);
|
||||
signDirection = BlockFace.SOUTH_WEST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH(), 2).getRelative(Direction.WEST(), 2);
|
||||
|
||||
if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.BIG)) {
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x - 2, y, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y, z - 2, this.kind);
|
||||
|
@ -197,11 +209,9 @@ public class Team {
|
|||
this.setBlock(x + 2, y + 3, z - 2, this.kind);
|
||||
}
|
||||
} else if (yaw >= 90 && yaw <= 180) {
|
||||
facing = BlockFace.NORTH_EAST;
|
||||
opposite = BlockFace.SOUTH_WEST;
|
||||
signData = 14;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.NORTH, 2).getFace(BlockFace.EAST, 2);
|
||||
if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.BIG)) {
|
||||
signDirection = BlockFace.NORTH_WEST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH(), 2).getRelative(Direction.EAST(), 2);
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x + 1, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 2, this.kind);
|
||||
|
@ -229,11 +239,9 @@ public class Team {
|
|||
this.setBlock(x + 2, y + 3, z + 2, this.kind);
|
||||
}
|
||||
} else if (yaw >= 180 && yaw < 270) {
|
||||
facing = BlockFace.SOUTH_EAST;
|
||||
opposite = BlockFace.NORTH_WEST;
|
||||
signData = 2;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.SOUTH, 2).getFace(BlockFace.EAST, 2);
|
||||
if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.BIG)) {
|
||||
signDirection = BlockFace.NORTH_EAST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.EAST(), 2);
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x + 2, y, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y, z + 2, this.kind);
|
||||
|
@ -261,11 +269,9 @@ public class Team {
|
|||
this.setBlock(x - 2, y + 3, z + 2, this.kind);
|
||||
}
|
||||
} else if (yaw >= 270 && yaw <= 360) {
|
||||
facing = BlockFace.SOUTH_WEST;
|
||||
opposite = BlockFace.NORTH_EAST;
|
||||
signData = 6;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.SOUTH, 2).getFace(BlockFace.WEST, 2);
|
||||
if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.BIG)) {
|
||||
signDirection = BlockFace.SOUTH_EAST.getOppositeFace();
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.WEST(), 2);
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x - 1, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 2, this.kind);
|
||||
|
@ -296,82 +302,152 @@ public class Team {
|
|||
}
|
||||
|
||||
if (signBlock != null) {
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "Team " + this.name;
|
||||
lines[1] = this.players.size() + "/" + this.warzone.getTeamCap() + " players";
|
||||
lines[2] = this.points + "/" + this.warzone.getScoreCap() + " pts";
|
||||
if (this.warzone.getLifePool() == -1) {
|
||||
lines[3] = "unlimited lives";
|
||||
String[] lines;
|
||||
if (this.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) == -1) {
|
||||
lines = MessageFormat
|
||||
.format(War.war.getString("sign.team.unlimited"),
|
||||
this.name,
|
||||
this.players.size(),
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.TEAMSIZE),
|
||||
this.points,
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.MAXSCORE)).split("\n");
|
||||
} else {
|
||||
lines[3] = this.remainingLives + "/" + this.warzone.getLifePool() + " lives left";
|
||||
lines = MessageFormat
|
||||
.format(War.war.getString("sign.team.limited"),
|
||||
this.name,
|
||||
this.players.size(),
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.TEAMSIZE),
|
||||
this.points,
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.MAXSCORE),
|
||||
this.remainingLives,
|
||||
this.getTeamConfig().resolveInt(
|
||||
TeamConfig.LIFEPOOL)).split("\n");
|
||||
}
|
||||
|
||||
SignHelper.setToSign(War.war, signBlock, (byte) signData, lines);
|
||||
signBlock.setType(Material.SIGN);
|
||||
org.bukkit.block.Sign block = (org.bukkit.block.Sign) signBlock
|
||||
.getState();
|
||||
org.bukkit.material.Sign data = (Sign) block.getData();
|
||||
data.setFacingDirection(signDirection);
|
||||
block.setData(data);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
block.setLine(i, lines[i]);
|
||||
}
|
||||
block.update(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlock(int x, int y, int z, TeamKind kind) {
|
||||
Block block = this.warzone.getWorld().getBlockAt(x, y, z);
|
||||
BlockState block = this.warzone.getWorld().getBlockAt(x, y, z).getState();
|
||||
block.setType(kind.getMaterial());
|
||||
block.setData(kind.getData());
|
||||
block.update(true);
|
||||
}
|
||||
|
||||
public void setTeamSpawn(Location teamSpawn) {
|
||||
this.teamSpawn = teamSpawn;
|
||||
|
||||
public void addTeamSpawn(Location teamSpawn) {
|
||||
if (!this.teamSpawns.contains(teamSpawn)) {
|
||||
this.teamSpawns.add(teamSpawn);
|
||||
}
|
||||
// this resets the block to old state
|
||||
this.setSpawnVolume();
|
||||
this.getSpawnVolume().saveBlocks();
|
||||
this.setSpawnVolume(teamSpawn, new Volume(name + teamSpawns.indexOf(teamSpawn), warzone.getWorld()));
|
||||
this.createSpawnVolume(teamSpawn);
|
||||
this.spawnVolumes.get(teamSpawn).saveBlocks();
|
||||
|
||||
this.initializeTeamSpawn();
|
||||
this.initializeTeamSpawn(teamSpawn);
|
||||
}
|
||||
|
||||
public Location getTeamSpawn() {
|
||||
return this.teamSpawn;
|
||||
public List<Location> getTeamSpawns() {
|
||||
return this.teamSpawns;
|
||||
}
|
||||
|
||||
public Location getRandomSpawn() {
|
||||
return this.teamSpawns.get(teamSpawnRandomizer.nextInt(this.teamSpawns.size()));
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
this.players.add(player);
|
||||
if (this.warzone.getScoreboard() != null && this.warzone.getScoreboardType() != ScoreboardType.NONE) {
|
||||
player.setScoreboard(this.warzone.getScoreboard());
|
||||
}
|
||||
warzone.updateScoreboard();
|
||||
boolean cooldownEnabled = War.war.getWarConfig().getBoolean(WarConfig.DISABLECOOLDOWN);
|
||||
if(cooldownEnabled) {
|
||||
player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(1024.0);
|
||||
} else {
|
||||
player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
return this.players;
|
||||
}
|
||||
|
||||
|
||||
public void teamcast(String message) {
|
||||
// by default a teamcast is a notification
|
||||
teamcast(message, true);
|
||||
}
|
||||
|
||||
public void teamcast(String message, boolean isNotification) {
|
||||
for (Player player : this.players) {
|
||||
War.war.msg(player, message);
|
||||
}
|
||||
}
|
||||
|
||||
public void teamcast(String message, Object... args) {
|
||||
// by default a teamcast is a notification
|
||||
teamcast(message, true, args);
|
||||
}
|
||||
|
||||
public void teamcast(String message, boolean isNotification, Object... args) {
|
||||
for (Player player : this.players) {
|
||||
War.war.msg(player, message, args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an achievement to all players on the team.
|
||||
* Currently implemented using SpoutCraft.
|
||||
* @param line1 Achievement first line
|
||||
* @param line2 Achievement second line
|
||||
* @param icon Item to display in the achievement
|
||||
* @param ticks Duration the achievement should be displayed
|
||||
*/
|
||||
public void sendAchievement(String line1, String line2, ItemStack icon, int ticks) {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
public void removePlayer(Player thePlayer) {
|
||||
this.players.remove(thePlayer);
|
||||
synchronized (teamChatPlayers) {
|
||||
this.teamChatPlayers.remove(thePlayer);
|
||||
}
|
||||
this.warzone.dropAllStolenObjects(thePlayer, false);
|
||||
thePlayer.setFireTicks(0);
|
||||
thePlayer.setRemainingAir(300);
|
||||
if (!this.warzone.getReallyDeadFighters().contains(thePlayer.getName())) {
|
||||
this.warzone.restorePlayerState(thePlayer);
|
||||
}
|
||||
this.warzone.getLoadoutSelections().remove(thePlayer);
|
||||
warzone.updateScoreboard();
|
||||
thePlayer.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0);
|
||||
}
|
||||
|
||||
public boolean removePlayer(String name) {
|
||||
Player thePlayer = null;
|
||||
for (Player player : this.players) {
|
||||
if (player.getName().equals(name)) {
|
||||
thePlayer = player;
|
||||
}
|
||||
}
|
||||
if (thePlayer != null) {
|
||||
this.players.remove(thePlayer);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
public int getRemainingLives() {
|
||||
return this.remainingLives;
|
||||
}
|
||||
|
||||
public void setRemainingLives(int remainingLives) {
|
||||
this.remainingLives = remainingLives;
|
||||
}
|
||||
|
||||
public int getRemainingLifes() {
|
||||
return this.remainingLives;
|
||||
warzone.updateScoreboard();
|
||||
}
|
||||
|
||||
public void addPoint() {
|
||||
|
@ -385,44 +461,50 @@ public class Team {
|
|||
if (atLeastOnePlayerOnTeam && atLeastOnePlayerOnOtherTeam) {
|
||||
this.points++;
|
||||
} else if (!atLeastOnePlayerOnOtherTeam) {
|
||||
this.teamcast("Can't score until at least one player joins another team.");
|
||||
this.teamcast("zone.score.empty");
|
||||
}
|
||||
this.warzone.updateScoreboard();
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return this.points;
|
||||
}
|
||||
|
||||
public Volume getSpawnVolume() {
|
||||
public Map<Location, Volume> getSpawnVolumes() {
|
||||
|
||||
return this.spawnVolume;
|
||||
return this.spawnVolumes;
|
||||
}
|
||||
|
||||
public void resetSign() {
|
||||
this.getSpawnVolume().resetBlocks();
|
||||
this.initializeTeamSpawn(); // reset everything instead of just sign
|
||||
|
||||
for (Entry<Location, Volume> spawnEntry : this.getSpawnVolumes().entrySet()) {
|
||||
spawnEntry.getValue().resetBlocks();
|
||||
this.initializeTeamSpawn(spawnEntry.getKey()); // reset everything instead of just sign
|
||||
}
|
||||
if (this.warzone.getLobby() != null) {
|
||||
this.warzone.getLobby().resetTeamGateSign(this);
|
||||
}
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(warzone);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSpawnVolume(Volume volume) {
|
||||
this.spawnVolume = volume;
|
||||
public void setSpawnVolume(Location spawnLocation, Volume volume) {
|
||||
this.spawnVolumes.put(spawnLocation, volume);
|
||||
}
|
||||
|
||||
public void resetPoints() {
|
||||
this.points = 0;
|
||||
}
|
||||
|
||||
public void setFlagVolume(Volume flagVolume) {
|
||||
this.flagVolume = flagVolume;
|
||||
warzone.updateScoreboard();
|
||||
}
|
||||
|
||||
public Volume getFlagVolume() {
|
||||
return this.flagVolume;
|
||||
}
|
||||
|
||||
public void setFlagVolume(Volume flagVolume) {
|
||||
this.flagVolume = flagVolume;
|
||||
}
|
||||
|
||||
private void setFlagVolume() {
|
||||
if (this.flagVolume == null) {
|
||||
this.flagVolume = new Volume(this.getName() + "flag", this.warzone.getWorld());
|
||||
|
@ -437,10 +519,16 @@ public class Team {
|
|||
this.flagVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void initializeTeamFlag() {
|
||||
// make air
|
||||
this.flagVolume.setToMaterial(Material.AIR);
|
||||
// make air (old two-high above floor)
|
||||
Volume airGap = new Volume(new Location(this.flagVolume.getWorld(),
|
||||
this.flagVolume.getCornerOne().getX(), this.flagVolume
|
||||
.getCornerOne().getY() + 1, this.flagVolume
|
||||
.getCornerOne().getZ()), new Location(
|
||||
this.flagVolume.getWorld(), this.flagVolume.getCornerTwo()
|
||||
.getX(), this.flagVolume.getCornerOne().getY() + 2,
|
||||
this.flagVolume.getCornerTwo().getZ()));
|
||||
airGap.setToMaterial(Material.AIR);
|
||||
|
||||
// Set the flag blocks
|
||||
int x = this.teamFlag.getBlockX();
|
||||
|
@ -448,20 +536,47 @@ public class Team {
|
|||
int z = this.teamFlag.getBlockZ();
|
||||
|
||||
// first ring
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
BlockState current = this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y - 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getLightBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getLightBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getMainBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getMainBlock().getData());
|
||||
current.update(true);
|
||||
|
||||
// flag
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z).setType(this.kind.getMaterial());
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z).setData(this.kind.getData());
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z).setType(Material.FENCE);
|
||||
BlockState flagBlock = this.warzone.getWorld().getBlockAt(x, y + 1, z).getState();
|
||||
flagBlock.setType(this.kind.getMaterial());
|
||||
flagBlock.update(true);
|
||||
|
||||
// Flag post using Orientation
|
||||
int yaw = 0;
|
||||
|
@ -470,45 +585,45 @@ public class Team {
|
|||
} else {
|
||||
yaw = (int) (360 + (this.teamFlag.getYaw() % 360));
|
||||
}
|
||||
BlockFace facing = null;
|
||||
BlockFace opposite = null;
|
||||
if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) {
|
||||
facing = BlockFace.WEST;
|
||||
opposite = BlockFace.EAST;
|
||||
this.warzone.getWorld().getBlockAt(x, y, z - 1).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z - 1).setType(Material.FENCE);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
} else if (yaw >= 45 && yaw < 135) {
|
||||
facing = BlockFace.NORTH;
|
||||
opposite = BlockFace.SOUTH;
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y, z).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y + 1, z).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y + 2, z).setType(Material.FENCE);
|
||||
current = this.warzone.getWorld().getBlockAt(x + 1, y, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x + 1, y + 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
} else if (yaw >= 135 && yaw < 225) {
|
||||
facing = BlockFace.EAST;
|
||||
opposite = BlockFace.WEST;
|
||||
this.warzone.getWorld().getBlockAt(x, y, z + 1).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z + 1).setType(Material.FENCE);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
} else if (yaw >= 225 && yaw < 315) {
|
||||
facing = BlockFace.SOUTH;
|
||||
opposite = BlockFace.NORTH;
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y, z).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y + 1, z).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y + 2, z).setType(Material.FENCE);
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
current = this.warzone.getWorld().getBlockAt(x - 1, y + 1, z).getState();
|
||||
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
|
||||
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
|
||||
current.update(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTeamFlag(Location teamFlag) {
|
||||
this.teamFlag = teamFlag;
|
||||
|
||||
// this resets the block to old state
|
||||
this.setFlagVolume();
|
||||
this.getFlagVolume().saveBlocks();
|
||||
|
||||
this.initializeTeamFlag();
|
||||
}
|
||||
|
||||
public boolean isTeamFlagBlock(Block block) {
|
||||
if (this.teamFlag != null) {
|
||||
int flagX = this.teamFlag.getBlockX();
|
||||
|
@ -524,4 +639,134 @@ public class Team {
|
|||
public Location getTeamFlag() {
|
||||
return this.teamFlag;
|
||||
}
|
||||
|
||||
public void setTeamFlag(Location teamFlag) {
|
||||
this.teamFlag = teamFlag;
|
||||
|
||||
// this resets the block to old state
|
||||
this.setFlagVolume();
|
||||
this.getFlagVolume().saveBlocks();
|
||||
|
||||
this.initializeTeamFlag();
|
||||
}
|
||||
|
||||
public void deleteTeamFlag() {
|
||||
this.getFlagVolume().resetBlocks();
|
||||
this.setFlagVolume(null);
|
||||
this.teamFlag = null;
|
||||
|
||||
// remove volume file
|
||||
String filePath = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.warzone.getName() + "/volume-" + this.getName() + "flag.dat";
|
||||
if (!new File(filePath).delete()) {
|
||||
War.war.log("Failed to delete file " + filePath, Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryBag getInventories() {
|
||||
return this.inventories ;
|
||||
}
|
||||
|
||||
public TeamConfigBag getTeamConfig() {
|
||||
return this.teamConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any team spawns contain a certain location.
|
||||
*
|
||||
* @param loc Location to check if contained by a spawn.
|
||||
* @return true if loc is part of a spawn volume, false otherwise.
|
||||
*/
|
||||
public boolean isSpawnLocation(Location loc) {
|
||||
for (Volume spawnVolume : this.spawnVolumes.values()) {
|
||||
if (spawnVolume.contains(loc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return this.getPlayers().size() == this.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of player usernames for players on this team.
|
||||
*
|
||||
* @return array of usernames.
|
||||
*/
|
||||
public List<String> getPlayerNames() {
|
||||
List<String> ret = new ArrayList<String>(this.players.size());
|
||||
for (Player player : this.players) {
|
||||
ret.add(player.getName());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player on this team can modify a certain type of block defined in the block whitelist.
|
||||
*
|
||||
* @param type Type of block to check.
|
||||
* @return true if this block can be modified, false otherwise.
|
||||
*/
|
||||
public boolean canModify(Material type) {
|
||||
for (String whitelistedBlock : this.getTeamConfig()
|
||||
.resolveString(TeamConfig.BLOCKWHITELIST).split(",")) {
|
||||
if (whitelistedBlock.equalsIgnoreCase("all")) {
|
||||
return true;
|
||||
}
|
||||
if (type.toString().equalsIgnoreCase(whitelistedBlock)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a team chat message with proper formatting.
|
||||
*
|
||||
* @param sender Player sending the message
|
||||
* @param message Message to send
|
||||
*/
|
||||
public void sendTeamChatMessage(OfflinePlayer sender, String message) {
|
||||
String player = this.getKind().getColor() + ChatColor.stripColor(sender.getName()) + ChatColor.WHITE;
|
||||
String output = String.format("%s: %s", player, message);
|
||||
teamcast(output, false);
|
||||
War.war.getLogger().info("[TeamChat] " + output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player on this team has toggled on team chat. Thread safe.
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player has toggled on team chat
|
||||
*/
|
||||
public boolean isInTeamChat(Player player) {
|
||||
synchronized (teamChatPlayers) {
|
||||
return this.teamChatPlayers.contains(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to team chat. Thread safe.
|
||||
* @param player Player to add
|
||||
* @throws IllegalArgumentException Player is already in team chat
|
||||
*/
|
||||
public void addTeamChatPlayer(Player player) {
|
||||
Validate.isTrue(!isInTeamChat(player), "Player is already in team chat");
|
||||
synchronized (teamChatPlayers) {
|
||||
this.teamChatPlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player from team chat. Thread safe.
|
||||
*
|
||||
* @param player Player to remove
|
||||
*/
|
||||
public void removeTeamChatPlayer(Player player) {
|
||||
synchronized (teamChatPlayers) {
|
||||
this.teamChatPlayers.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class TeamKind {
|
||||
private final Material material;
|
||||
private final byte data;
|
||||
private final String defaultName;
|
||||
private final ChatColor color;
|
||||
|
||||
public TeamKind(String defaultName, Material material, byte data, ChatColor color) {
|
||||
this.defaultName = defaultName;
|
||||
this.material = material;
|
||||
this.data = data;
|
||||
this.color = color;
|
||||
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return this.material;
|
||||
}
|
||||
|
||||
public byte getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public String getDefaultName() {
|
||||
return this.defaultName;
|
||||
}
|
||||
|
||||
public ChatColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package com.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class TeamKinds {
|
||||
private static final List<TeamKind> teamKinds = new ArrayList<TeamKind>();
|
||||
|
||||
static {
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("white", Material.WOOL, (byte) 0, ChatColor.WHITE));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("orange", Material.WOOL, (byte) 1, ChatColor.GOLD));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("magenta", Material.WOOL, (byte) 2, ChatColor.LIGHT_PURPLE));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("blue", Material.WOOL, (byte) 3, ChatColor.BLUE));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("gold", Material.WOOL, (byte) 4, ChatColor.YELLOW)); // yellow = gold
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("green", Material.WOOL, (byte) 5, ChatColor.GREEN));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("pink", Material.WOOL, (byte) 6, ChatColor.WHITE));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("gray", Material.WOOL, (byte) 7, ChatColor.DARK_GRAY));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("iron", Material.WOOL, (byte) 8, ChatColor.GRAY)); // lightgrey = iron
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("diamond", Material.WOOL, (byte) 9, ChatColor.DARK_AQUA)); // cyan = diamond
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("purple", Material.WOOL, (byte) 10, ChatColor.DARK_PURPLE));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("navy", Material.WOOL, (byte) 11, ChatColor.DARK_BLUE));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("brown", Material.WOOL, (byte) 12, ChatColor.DARK_RED));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("darkgreen", Material.WOOL, (byte) 13, ChatColor.DARK_GREEN));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("red", Material.WOOL, (byte) 14, ChatColor.RED));
|
||||
TeamKinds.getTeamkinds().add(new TeamKind("black", Material.WOOL, (byte) 15, ChatColor.BLACK));
|
||||
}
|
||||
|
||||
public static TeamKind teamKindFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (TeamKind kind : TeamKinds.getTeamkinds()) {
|
||||
if (kind.getDefaultName().startsWith(lowered)) {
|
||||
return kind;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<TeamKind> getTeamkinds() {
|
||||
return TeamKinds.teamKinds;
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.tommytony.war;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class TeamSpawnStyles {
|
||||
public static final String INVISIBLE = "invisible";
|
||||
public static final String SMALL = "small";
|
||||
public static final String FLAT = "flat";
|
||||
public static final String BIG = "big";
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,253 +0,0 @@
|
|||
package com.tommytony.war;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.utils.SignHelper;
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package com.tommytony.war
|
||||
*/
|
||||
public class WarHub {
|
||||
private Location location;
|
||||
private Volume volume;
|
||||
private Map<String, Block> zoneGateBlocks = new HashMap<String, Block>();
|
||||
private BlockFace orientation;
|
||||
|
||||
public WarHub(Location location, String hubOrientation) {
|
||||
int yaw = 0;
|
||||
if (hubOrientation.equals("south")) {
|
||||
yaw = 270;
|
||||
this.setOrientation(BlockFace.SOUTH);
|
||||
} else if (hubOrientation.equals("north")) {
|
||||
yaw = 90;
|
||||
this.setOrientation(BlockFace.NORTH);
|
||||
} else if (hubOrientation.equals("east")) {
|
||||
yaw = 180;
|
||||
this.setOrientation(BlockFace.EAST);
|
||||
} else {
|
||||
yaw = 0;
|
||||
this.setOrientation(BlockFace.WEST);
|
||||
}
|
||||
|
||||
this.location = new Location(location.getWorld(),
|
||||
location.getX(),
|
||||
location.getY(),
|
||||
location.getZ(),
|
||||
yaw, 0);
|
||||
this.volume = new Volume("warhub", location.getWorld());
|
||||
}
|
||||
|
||||
// Use when creating from player location (with yaw)
|
||||
public WarHub(Location location) {
|
||||
this.location = location;
|
||||
this.volume = new Volume("warhub", location.getWorld());
|
||||
|
||||
this.setLocation(location);
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void setLocation(Location loc) {
|
||||
this.location = loc;
|
||||
// Lobby orientation
|
||||
int yaw = 0;
|
||||
if (this.location.getYaw() >= 0) {
|
||||
yaw = (int) (this.location.getYaw() % 360);
|
||||
} else {
|
||||
yaw = (int) (360 + (this.location.getYaw() % 360));
|
||||
}
|
||||
|
||||
BlockFace facing = null;
|
||||
if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) {
|
||||
facing = BlockFace.WEST;
|
||||
} else if (yaw >= 45 && yaw < 135) {
|
||||
facing = BlockFace.NORTH;
|
||||
} else if (yaw >= 135 && yaw < 225) {
|
||||
facing = BlockFace.EAST;
|
||||
} else if (yaw >= 225 && yaw < 315) {
|
||||
facing = BlockFace.SOUTH;
|
||||
}
|
||||
this.setOrientation(facing);
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public Warzone getDestinationWarzoneForLocation(Location playerLocation) {
|
||||
Warzone zone = null;
|
||||
for (String zoneName : this.zoneGateBlocks.keySet()) {
|
||||
Block gate = this.zoneGateBlocks.get(zoneName);
|
||||
if (gate.getX() == playerLocation.getBlockX() && gate.getY() == playerLocation.getBlockY() && gate.getZ() == playerLocation.getBlockZ()) {
|
||||
zone = War.war.findWarzone(zoneName);
|
||||
}
|
||||
}
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
// for now, draw the wall of gates to the west
|
||||
this.zoneGateBlocks.clear();
|
||||
int disabled = 0;
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.isDisabled()) {
|
||||
disabled++;
|
||||
}
|
||||
}
|
||||
int noOfWarzones = War.war.getWarzones().size() - disabled;
|
||||
if (noOfWarzones > 0) {
|
||||
int hubWidth = noOfWarzones * 4 + 2;
|
||||
int halfHubWidth = hubWidth / 2;
|
||||
int hubDepth = 6;
|
||||
int hubHeigth = 4;
|
||||
|
||||
BlockFace left;
|
||||
BlockFace right;
|
||||
BlockFace front = this.getOrientation();
|
||||
BlockFace back;
|
||||
byte data;
|
||||
if (this.getOrientation() == BlockFace.SOUTH) {
|
||||
data = (byte) 4;
|
||||
left = BlockFace.EAST;
|
||||
right = BlockFace.WEST;
|
||||
back = BlockFace.NORTH;
|
||||
} else if (this.getOrientation() == BlockFace.NORTH) {
|
||||
data = (byte) 12;
|
||||
left = BlockFace.WEST;
|
||||
right = BlockFace.EAST;
|
||||
back = BlockFace.SOUTH;
|
||||
} else if (this.getOrientation() == BlockFace.EAST) {
|
||||
data = (byte) 0;
|
||||
left = BlockFace.NORTH;
|
||||
right = BlockFace.SOUTH;
|
||||
back = BlockFace.WEST;
|
||||
} else {
|
||||
data = (byte) 8;
|
||||
left = BlockFace.SOUTH;
|
||||
right = BlockFace.NORTH;
|
||||
back = BlockFace.EAST;
|
||||
}
|
||||
|
||||
Block locationBlock = this.location.getWorld().getBlockAt(this.location.getBlockX(), this.location.getBlockY(), this.location.getBlockZ());
|
||||
this.volume.setCornerOne(locationBlock.getFace(back).getFace(left, halfHubWidth).getFace(BlockFace.DOWN));
|
||||
this.volume.setCornerTwo(locationBlock.getFace(right, halfHubWidth).getFace(front, hubDepth).getFace(BlockFace.UP, hubHeigth));
|
||||
this.volume.saveBlocks();
|
||||
|
||||
// glass floor
|
||||
this.volume.clearBlocksThatDontFloat();
|
||||
this.volume.setToMaterial(Material.AIR);
|
||||
this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS);
|
||||
|
||||
// draw gates
|
||||
Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getFace(BlockFace.UP).getFace(front, hubDepth).getFace(right, 2);
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) { // gonna use the index to find it again
|
||||
if (!zone.isDisabled()) {
|
||||
this.zoneGateBlocks.put(zone.getName(), currentGateBlock);
|
||||
currentGateBlock.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE);
|
||||
currentGateBlock.getFace(left).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(right).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(left).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(right).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(left).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(right).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock = currentGateBlock.getFace(right, 4);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// War hub sign
|
||||
Block signBlock = locationBlock.getFace(front);
|
||||
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "War hub";
|
||||
lines[1] = "(/warhub)";
|
||||
lines[2] = "Pick your";
|
||||
lines[3] = "battle!";
|
||||
SignHelper.setToSign(War.war, signBlock, data, lines);
|
||||
|
||||
// Warzone signs
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (!zone.isDisabled() && zone.ready()) {
|
||||
this.resetZoneSign(zone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the sign of the given warzone
|
||||
*
|
||||
* @param Warzone zone
|
||||
*/
|
||||
public void resetZoneSign(Warzone zone) {
|
||||
BlockFace left;
|
||||
BlockFace back;
|
||||
byte data;
|
||||
if (this.getOrientation() == BlockFace.SOUTH) {
|
||||
data = (byte) 4;
|
||||
left = BlockFace.EAST;
|
||||
back = BlockFace.NORTH;
|
||||
} else if (this.getOrientation() == BlockFace.NORTH) {
|
||||
data = (byte) 12;
|
||||
left = BlockFace.WEST;
|
||||
back = BlockFace.SOUTH;
|
||||
} else if (this.getOrientation() == BlockFace.EAST) {
|
||||
data = (byte) 0;
|
||||
left = BlockFace.NORTH;
|
||||
back = BlockFace.WEST;
|
||||
} else {
|
||||
data = (byte) 8;
|
||||
left = BlockFace.SOUTH;
|
||||
back = BlockFace.EAST;
|
||||
}
|
||||
|
||||
Block zoneGate = this.zoneGateBlocks.get(zone.getName());
|
||||
Block block = zoneGate.getFace(left).getFace(back, 1);
|
||||
if (block.getType() != Material.SIGN_POST) {
|
||||
block.setType(Material.SIGN_POST);
|
||||
}
|
||||
block.setData(data);
|
||||
|
||||
int zoneCap = 0;
|
||||
int zonePlayers = 0;
|
||||
for (Team t : zone.getTeams()) {
|
||||
zonePlayers += t.getPlayers().size();
|
||||
zoneCap += zone.getTeamCap();
|
||||
}
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "Warzone";
|
||||
lines[1] = zone.getName();
|
||||
lines[2] = zonePlayers + "/" + zoneCap + " players";
|
||||
lines[3] = zone.getTeams().size() + " teams";
|
||||
SignHelper.setToSign(War.war, block, data, lines);
|
||||
}
|
||||
|
||||
public void setVolume(Volume vol) {
|
||||
this.volume = vol;
|
||||
}
|
||||
|
||||
public void setOrientation(BlockFace orientation) {
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
public BlockFace getOrientation() {
|
||||
return this.orientation;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,693 +0,0 @@
|
|||
package com.tommytony.war;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.utils.SignHelper;
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class ZoneLobby {
|
||||
private final Warzone warzone;
|
||||
private BlockFace wall;
|
||||
private Volume volume;
|
||||
BlockInfo lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor
|
||||
|
||||
BlockInfo warHubLinkGate = null;
|
||||
|
||||
Map<String, BlockInfo> teamGateBlocks = new HashMap<String, BlockInfo>();
|
||||
BlockInfo autoAssignGate = null;
|
||||
|
||||
BlockInfo zoneTeleportBlock = null;
|
||||
|
||||
private final int lobbyHeight = 3;
|
||||
private int lobbyHalfSide;
|
||||
private final int lobbyDepth = 10;
|
||||
|
||||
/**
|
||||
* Use this constructor with /setzonelobby <n/s/e/w>
|
||||
*
|
||||
* @param war
|
||||
* @param warzone
|
||||
* @param wall
|
||||
* On which wall of the warzone will the lobby be stuck to at mid-weight
|
||||
*/
|
||||
public ZoneLobby(Warzone warzone, BlockFace wall) {
|
||||
this.warzone = warzone;
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
this.lobbyHalfSide = lobbyWidth / 2;
|
||||
if (this.lobbyHalfSide < 7) {
|
||||
this.lobbyHalfSide = 7;
|
||||
}
|
||||
this.setWall(wall);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor with /setzonelobby <zonename>. Makes sure the lobby is not sticking inside the zone.
|
||||
*
|
||||
* @param war
|
||||
* @param warzone
|
||||
* @param wall
|
||||
* On which wall of the warzone will the lobby be stuck to at mid-weight
|
||||
*/
|
||||
public ZoneLobby(Warzone warzone, Location playerLocation) {
|
||||
this.warzone = warzone;
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
this.lobbyHalfSide = lobbyWidth / 2;
|
||||
if (this.lobbyHalfSide < 7) {
|
||||
this.lobbyHalfSide = 7;
|
||||
}
|
||||
this.setLocation(playerLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience ctor when loading form disk. This figures out the middle wall block of the lobby from the volume instead of the other way around.
|
||||
*/
|
||||
public ZoneLobby(Warzone warzone, BlockFace wall, Volume volume) {
|
||||
this.warzone = warzone;
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
this.lobbyHalfSide = lobbyWidth / 2;
|
||||
if (this.lobbyHalfSide < 7) {
|
||||
this.lobbyHalfSide = 7;
|
||||
}
|
||||
this.wall = wall;
|
||||
this.setVolume(volume);
|
||||
|
||||
// we're setting the zoneVolume directly, so we need to figure out the lobbyMiddleWallBlock on our own
|
||||
if (wall == BlockFace.NORTH) {
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.EAST, this.lobbyHalfSide));
|
||||
} else if (wall == BlockFace.EAST) {
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.SOUTH, this.lobbyHalfSide));
|
||||
} else if (wall == BlockFace.SOUTH) {
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.WEST, this.lobbyHalfSide));
|
||||
} else if (wall == BlockFace.WEST) {
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.NORTH, this.lobbyHalfSide));
|
||||
}
|
||||
}
|
||||
|
||||
public static ZoneLobby getLobbyByLocation(Location location) {
|
||||
for (Warzone warzone : War.war.getWarzones()) {
|
||||
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null && warzone.getLobby().getVolume().contains(location)) {
|
||||
return warzone.getLobby();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ZoneLobby getLobbyByLocation(Player player) {
|
||||
return ZoneLobby.getLobbyByLocation(player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the lobby's position. Orientation is determined from the player location. Creates volume or resets. Saves new lobby blocks.
|
||||
*
|
||||
* @param playerLocation
|
||||
*/
|
||||
public void setLocation(Location playerLocation) {
|
||||
this.createVolumeOrReset();
|
||||
|
||||
// Lobby orientation
|
||||
int yaw = 0;
|
||||
if (playerLocation.getYaw() >= 0) {
|
||||
yaw = (int) (playerLocation.getYaw() % 360);
|
||||
} else {
|
||||
yaw = (int) (360 + (playerLocation.getYaw() % 360));
|
||||
}
|
||||
BlockFace facing = null;
|
||||
BlockFace opposite = null;
|
||||
if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) {
|
||||
facing = BlockFace.WEST;
|
||||
opposite = BlockFace.EAST;
|
||||
} else if (yaw >= 45 && yaw < 135) {
|
||||
facing = BlockFace.NORTH;
|
||||
opposite = BlockFace.SOUTH;
|
||||
} else if (yaw >= 135 && yaw < 225) {
|
||||
facing = BlockFace.EAST;
|
||||
opposite = BlockFace.WEST;
|
||||
} else if (yaw >= 225 && yaw < 315) {
|
||||
facing = BlockFace.SOUTH;
|
||||
opposite = BlockFace.NORTH;
|
||||
}
|
||||
|
||||
this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall
|
||||
|
||||
this.calculateLobbyWidth();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()).getFace(facing, 6));
|
||||
|
||||
Block corner1 = null;
|
||||
Block corner2 = null;
|
||||
int x = this.lobbyMiddleWallBlock.getX();
|
||||
int y = this.lobbyMiddleWallBlock.getY();
|
||||
int z = this.lobbyMiddleWallBlock.getZ();
|
||||
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, z + this.lobbyHalfSide);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, z - this.lobbyHalfSide);
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
corner1 = this.warzone.getWorld().getBlockAt(x - this.lobbyHalfSide, y - 1, z);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth);
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, z - this.lobbyHalfSide);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, z + this.lobbyHalfSide);
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
corner1 = this.warzone.getWorld().getBlockAt(x + this.lobbyHalfSide, y - 1, z);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth);
|
||||
}
|
||||
|
||||
this.saveLobbyBlocks(corner1, corner2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Classic way of creating a lobby. Lobby position goes to middle of zone wall. Creates volume or resets. Saves new lobby blocks.
|
||||
*
|
||||
* @param newWall
|
||||
*/
|
||||
public void setWall(BlockFace newWall) {
|
||||
this.createVolumeOrReset();
|
||||
this.wall = newWall;
|
||||
|
||||
ZoneVolume zoneVolume = this.warzone.getVolume();
|
||||
this.calculateLobbyWidth();
|
||||
|
||||
Block corner1 = null;
|
||||
Block corner2 = null;
|
||||
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
int wallStart = zoneVolume.getMinZ();
|
||||
int wallEnd = zoneVolume.getMaxZ();
|
||||
int x = zoneVolume.getMinX();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int y = zoneVolume.getCenterY();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos));
|
||||
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos + this.lobbyHalfSide);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos - this.lobbyHalfSide);
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
int wallStart = zoneVolume.getMinX();
|
||||
int wallEnd = zoneVolume.getMaxX();
|
||||
int z = zoneVolume.getMinZ();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int y = zoneVolume.getCenterY();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z));
|
||||
corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y - 1, z);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth);
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
int wallStart = zoneVolume.getMinZ();
|
||||
int wallEnd = zoneVolume.getMaxZ();
|
||||
int x = zoneVolume.getMaxX();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int y = zoneVolume.getCenterY();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos));
|
||||
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos - this.lobbyHalfSide);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos + this.lobbyHalfSide);
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
int wallStart = zoneVolume.getMinX();
|
||||
int wallEnd = zoneVolume.getMaxX();
|
||||
int z = zoneVolume.getMaxZ();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int y = zoneVolume.getCenterY();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z));
|
||||
corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y - 1, z);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth);
|
||||
}
|
||||
|
||||
this.saveLobbyBlocks(corner1, corner2);
|
||||
}
|
||||
|
||||
private void createVolumeOrReset() {
|
||||
if (this.volume == null) {
|
||||
// no previous wall
|
||||
this.volume = new Volume("lobby", this.warzone.getWorld());
|
||||
} else if (this.volume.isSaved()) {
|
||||
this.volume.resetBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateLobbyWidth() {
|
||||
int noOfTeams = this.warzone.getTeams().size();
|
||||
if(this.warzone.isAutoAssignOnly()) {
|
||||
noOfTeams = 1;
|
||||
}
|
||||
int lobbyWidth = noOfTeams * 4 + 5;
|
||||
this.lobbyHalfSide = lobbyWidth / 2;
|
||||
if (this.lobbyHalfSide < 7) {
|
||||
this.lobbyHalfSide = 7;
|
||||
}
|
||||
}
|
||||
|
||||
private void saveLobbyBlocks(Block corner1, Block corner2) {
|
||||
if (corner1 != null && corner2 != null) {
|
||||
// save the blocks, wide enough for three team gates, 3+1 high and 10 deep, extruding out from the zone wall.
|
||||
this.volume.setCornerOne(corner1);
|
||||
this.volume.setCornerTwo(corner2);
|
||||
this.volume.saveBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
// maybe the number of teams change, now reset the gate positions
|
||||
if (this.lobbyMiddleWallBlock != null && this.volume != null /* && volume.isSaved() */) {
|
||||
this.setGatePositions(BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock));
|
||||
// flatten the area (set all but floor to air, then replace any floor air blocks with glass)
|
||||
this.volume.clearBlocksThatDontFloat();
|
||||
this.volume.setToMaterial(Material.AIR);
|
||||
this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); // beautiful
|
||||
|
||||
// add war hub link gate
|
||||
if (War.war.getWarHub() != null) {
|
||||
Block linkGateBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.warHubLinkGate);
|
||||
this.placeGate(linkGateBlock, Material.OBSIDIAN);
|
||||
// add warhub sign
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "";
|
||||
lines[1] = "To War hub";
|
||||
lines[2] = "";
|
||||
lines[3] = "";
|
||||
this.resetGateSign(linkGateBlock, lines, false);
|
||||
}
|
||||
|
||||
// add team gates or single auto assign gate
|
||||
this.placeAutoAssignGate();
|
||||
for (String teamName : this.teamGateBlocks.keySet()) {
|
||||
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
|
||||
this.placeGate(BlockInfo.getBlock(this.warzone.getWorld(), gateInfo), TeamKinds.teamKindFromString(teamName));
|
||||
}
|
||||
for (Team t : this.warzone.getTeams()) {
|
||||
this.resetTeamGateSign(t);
|
||||
}
|
||||
|
||||
// set zone tp
|
||||
this.zoneTeleportBlock = new BlockInfo(BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(this.wall, 6));
|
||||
int yaw = 0;
|
||||
if (this.wall == BlockFace.WEST) {
|
||||
yaw = 180;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
yaw = 90;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
yaw = 0;
|
||||
} else if (this.wall == BlockFace.NORTH) {
|
||||
yaw = 270;
|
||||
}
|
||||
this.warzone.setTeleport(new Location(this.warzone.getWorld(), this.zoneTeleportBlock.getX(), this.zoneTeleportBlock.getY(), this.zoneTeleportBlock.getZ(), yaw, 0));
|
||||
|
||||
// set zone sign
|
||||
Block zoneSignBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(this.wall, 4);
|
||||
byte data = 0;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
data = (byte) 4;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
data = (byte) 8;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
data = (byte) 12;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
data = (byte) 0;
|
||||
}
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "Warzone";
|
||||
lines[1] = this.warzone.getName();
|
||||
if (this.autoAssignGate != null) {
|
||||
lines[2] = "Enter the auto-";
|
||||
lines[3] = "assign gate.";
|
||||
} else {
|
||||
lines[2] = "";
|
||||
lines[3] = "Pick your team.";
|
||||
}
|
||||
SignHelper.setToSign(War.war, zoneSignBlock, data, lines);
|
||||
|
||||
// lets get some light in here
|
||||
if (this.wall == BlockFace.NORTH || this.wall == BlockFace.SOUTH) {
|
||||
BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(BlockFace.DOWN).getFace(BlockFace.WEST, this.lobbyHalfSide - 1).getFace(this.wall, 9).setType(Material.GLOWSTONE);
|
||||
BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(BlockFace.DOWN).getFace(BlockFace.EAST, this.lobbyHalfSide - 1).getFace(this.wall, 9).setType(Material.GLOWSTONE);
|
||||
} else {
|
||||
BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(BlockFace.DOWN).getFace(BlockFace.NORTH, this.lobbyHalfSide - 1).getFace(this.wall, 9).setType(Material.GLOWSTONE);
|
||||
BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(BlockFace.DOWN).getFace(BlockFace.SOUTH, this.lobbyHalfSide - 1).getFace(this.wall, 9).setType(Material.GLOWSTONE);
|
||||
}
|
||||
} else {
|
||||
War.war.log("Failed to initalize zone lobby for zone " + this.warzone.getName(), java.util.logging.Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
private void setGatePositions(Block lobbyMiddleWallBlock) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
this.teamGateBlocks.clear();
|
||||
if (this.warzone.getAutoAssignOnly()) {
|
||||
this.autoAssignGate = new BlockInfo(lobbyMiddleWallBlock);
|
||||
} else {
|
||||
this.autoAssignGate = null;
|
||||
for (int doorIndex = 0; doorIndex < this.warzone.getTeams().size(); doorIndex++) {
|
||||
// 0 at center, 1 to the left, 2 to the right, 3 to the left, etc
|
||||
Team team = this.warzone.getTeams().get(doorIndex);
|
||||
if (this.warzone.getTeams().size() % 2 == 0) {
|
||||
// even number of teams
|
||||
if (doorIndex % 2 == 0) {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getFace(rightSide, doorIndex * 2 + 2)));
|
||||
} else {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getFace(leftSide, doorIndex * 2)));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (doorIndex == 0) {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock));
|
||||
} else if (doorIndex % 2 == 0) {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getFace(rightSide, doorIndex * 2)));
|
||||
} else {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getFace(leftSide, doorIndex * 2 + 2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.warHubLinkGate = new BlockInfo(lobbyMiddleWallBlock.getFace(this.wall, 9));
|
||||
}
|
||||
|
||||
private void placeGate(Block block, TeamKind teamKind) {
|
||||
if (block != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
block.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE);
|
||||
this.setBlock(block.getFace(leftSide), teamKind);
|
||||
this.setBlock(block.getFace(rightSide).getFace(BlockFace.UP), teamKind);
|
||||
this.setBlock(block.getFace(leftSide).getFace(BlockFace.UP).getFace(BlockFace.UP), teamKind);
|
||||
this.setBlock(block.getFace(rightSide), teamKind);
|
||||
this.setBlock(block.getFace(leftSide).getFace(BlockFace.UP), teamKind);
|
||||
this.setBlock(block.getFace(rightSide).getFace(BlockFace.UP).getFace(BlockFace.UP), teamKind);
|
||||
this.setBlock(block.getFace(BlockFace.UP).getFace(BlockFace.UP), teamKind);
|
||||
}
|
||||
}
|
||||
|
||||
private void placeGate(Block block, Material material) {
|
||||
if (block != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
block.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE);
|
||||
this.setBlock(block.getFace(leftSide), material);
|
||||
this.setBlock(block.getFace(rightSide).getFace(BlockFace.UP), material);
|
||||
this.setBlock(block.getFace(leftSide).getFace(BlockFace.UP).getFace(BlockFace.UP), material);
|
||||
this.setBlock(block.getFace(rightSide), material);
|
||||
this.setBlock(block.getFace(leftSide).getFace(BlockFace.UP), material);
|
||||
this.setBlock(block.getFace(rightSide).getFace(BlockFace.UP).getFace(BlockFace.UP), material);
|
||||
this.setBlock(block.getFace(BlockFace.UP).getFace(BlockFace.UP), material);
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlock(Block block, TeamKind kind) {
|
||||
block.setType(kind.getMaterial());
|
||||
block.setData(kind.getData());
|
||||
}
|
||||
|
||||
private void setBlock(Block block, Material material) {
|
||||
block.setType(material);
|
||||
}
|
||||
|
||||
private void placeAutoAssignGate() {
|
||||
if (this.autoAssignGate != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
List<Team> teams = this.warzone.getTeams();
|
||||
Block autoAssignGateBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.autoAssignGate);
|
||||
this.setBlock(autoAssignGateBlock.getFace(BlockFace.DOWN), (Material.GLOWSTONE));
|
||||
int size = teams.size();
|
||||
if(size > 0) {
|
||||
TeamKind[] doorBlockKinds = new TeamKind[7];
|
||||
for (int i = 0; i < 7; i++) {
|
||||
doorBlockKinds[i] = teams.get(i % size).getKind();
|
||||
}
|
||||
this.setBlock(autoAssignGateBlock.getFace(leftSide), doorBlockKinds[0]);
|
||||
this.setBlock(autoAssignGateBlock.getFace(leftSide).getFace(BlockFace.UP), doorBlockKinds[1]);
|
||||
this.setBlock(autoAssignGateBlock.getFace(leftSide).getFace(BlockFace.UP).getFace(BlockFace.UP), doorBlockKinds[2]);
|
||||
this.setBlock(autoAssignGateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP), doorBlockKinds[3]);
|
||||
this.setBlock(autoAssignGateBlock.getFace(rightSide).getFace(BlockFace.UP).getFace(BlockFace.UP), doorBlockKinds[4]);
|
||||
this.setBlock(autoAssignGateBlock.getFace(rightSide).getFace(BlockFace.UP), doorBlockKinds[5]);
|
||||
this.setBlock(autoAssignGateBlock.getFace(rightSide), doorBlockKinds[6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInTeamGate(Team team, Location location) {
|
||||
BlockInfo info = this.teamGateBlocks.get(team.getName());
|
||||
if (info != null) {
|
||||
if (location.getBlockX() == info.getX() && location.getBlockY() == info.getY() && location.getBlockZ() == info.getZ()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAutoAssignGate(Location location) {
|
||||
if (this.autoAssignGate != null && (location.getBlockX() == this.autoAssignGate.getX() && location.getBlockY() == this.autoAssignGate.getY() && location.getBlockZ() == this.autoAssignGate.getZ())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void setVolume(Volume volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public BlockFace getWall() {
|
||||
return this.wall;
|
||||
}
|
||||
|
||||
public boolean isInWarHubLinkGate(Location location) {
|
||||
if (this.warHubLinkGate != null && location.getBlockX() == this.warHubLinkGate.getX() && location.getBlockY() == this.warHubLinkGate.getY() && location.getBlockZ() == this.warHubLinkGate.getZ()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean blockIsAGateBlock(Block block, BlockFace blockWall) {
|
||||
if (blockWall == this.wall) {
|
||||
for (String teamName : this.teamGateBlocks.keySet()) {
|
||||
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
|
||||
if (this.isPartOfGate(BlockInfo.getBlock(this.warzone.getWorld(), gateInfo), block)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (this.autoAssignGate != null && this.isPartOfGate(BlockInfo.getBlock(this.warzone.getWorld(), this.autoAssignGate), block)) {
|
||||
// auto assign
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPartOfGate(Block gateBlock, Block block) {
|
||||
if (gateBlock != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
return (block.getX() == gateBlock.getX() && block.getY() == gateBlock.getY() && block.getZ() == gateBlock.getZ()) || (block.getX() == gateBlock.getFace(BlockFace.UP).getX() && block.getY() == gateBlock.getFace(BlockFace.UP).getY() && block.getZ() == gateBlock.getFace(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getFace(leftSide).getX() && block.getY() == gateBlock.getFace(leftSide).getY() && block.getZ() == gateBlock.getFace(leftSide).getZ()) || (block.getX() == gateBlock.getFace(leftSide).getFace(BlockFace.UP).getX() && block.getY() == gateBlock.getFace(leftSide).getFace(BlockFace.UP).getY() && block.getZ() == gateBlock.getFace(leftSide).getFace(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getFace(leftSide).getFace(BlockFace.UP).getFace(BlockFace.UP).getX() && block.getY() == gateBlock.getFace(leftSide).getFace(BlockFace.UP).getFace(BlockFace.UP).getY() && block.getZ() == gateBlock.getFace(leftSide).getFace(BlockFace.UP).getFace(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP).getX() && block.getY() == gateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP).getY() && block.getZ() == gateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getFace(rightSide).getFace(BlockFace.UP).getX() && block.getY() == gateBlock.getFace(rightSide).getFace(BlockFace.UP).getY() && block.getZ() == gateBlock.getFace(rightSide).getFace(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getFace(rightSide).getFace(BlockFace.UP).getFace(BlockFace.UP).getX() && block.getY() == gateBlock.getFace(rightSide).getFace(BlockFace.UP).getFace(BlockFace.UP).getY() && block.getZ() == gateBlock.getFace(rightSide).getFace(BlockFace.UP).getFace(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getFace(rightSide).getX() && block.getY() == gateBlock.getFace(rightSide).getY() && block.getZ() == gateBlock.getFace(rightSide).getZ()) || (block.getX() == gateBlock.getX() && block.getY() == gateBlock.getY() - 1 && block.getZ() == gateBlock.getZ());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Warzone getZone() {
|
||||
return this.warzone;
|
||||
}
|
||||
|
||||
public void resetTeamGateSign(Team team) {
|
||||
BlockInfo info = this.teamGateBlocks.get(team.getName());
|
||||
if (info != null) {
|
||||
this.resetTeamGateSign(team, BlockInfo.getBlock(this.warzone.getWorld(), info));
|
||||
}
|
||||
}
|
||||
|
||||
private void resetTeamGateSign(Team team, Block gate) {
|
||||
if (gate != null) {
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "Team " + team.getName();
|
||||
lines[1] = team.getPlayers().size() + "/" + this.warzone.getTeamCap() + " players";
|
||||
lines[2] = team.getPoints() + "/" + this.warzone.getScoreCap() + " pts";
|
||||
if (this.warzone.getLifePool() == -1) {
|
||||
lines[3] = "unlimited lives";
|
||||
} else {
|
||||
lines[3] = team.getRemainingLifes() + "/" + this.warzone.getLifePool() + " lives left";
|
||||
}
|
||||
this.resetGateSign(gate, lines, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetGateSign(Block gate, String[] lines, boolean awayFromWall) {
|
||||
Block block = null;
|
||||
BlockFace direction = null;
|
||||
if (awayFromWall) {
|
||||
direction = this.wall;
|
||||
} else if (this.wall == BlockFace.NORTH) {
|
||||
direction = BlockFace.SOUTH;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
direction = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
direction = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
direction = BlockFace.EAST;
|
||||
}
|
||||
byte data = 0;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
block = gate.getFace(direction).getFace(BlockFace.EAST);
|
||||
if (awayFromWall) {
|
||||
data = (byte) 4;
|
||||
} else {
|
||||
data = (byte) 12;
|
||||
}
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
block = gate.getFace(direction).getFace(BlockFace.SOUTH);
|
||||
if (awayFromWall) {
|
||||
data = (byte) 8;
|
||||
} else {
|
||||
data = (byte) 0;
|
||||
}
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
block = gate.getFace(direction).getFace(BlockFace.WEST);
|
||||
if (awayFromWall) {
|
||||
data = (byte) 12;
|
||||
} else {
|
||||
data = (byte) 4;
|
||||
}
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
block = gate.getFace(direction).getFace(BlockFace.NORTH);
|
||||
if (awayFromWall) {
|
||||
data = (byte) 0;
|
||||
} else {
|
||||
data = (byte) 8;
|
||||
}
|
||||
}
|
||||
|
||||
SignHelper.setToSign(War.war, block, data, lines);
|
||||
}
|
||||
|
||||
public boolean isLeavingZone(Location location) {
|
||||
BlockFace inside = null;
|
||||
BlockFace left = null;
|
||||
BlockFace right = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
inside = BlockFace.SOUTH;
|
||||
left = BlockFace.WEST;
|
||||
right = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
inside = BlockFace.WEST;
|
||||
left = BlockFace.NORTH;
|
||||
right = BlockFace.SOUTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
inside = BlockFace.NORTH;
|
||||
left = BlockFace.EAST;
|
||||
right = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
inside = BlockFace.EAST;
|
||||
left = BlockFace.SOUTH;
|
||||
right = BlockFace.NORTH;
|
||||
}
|
||||
if (this.autoAssignGate != null) {
|
||||
if (this.leaving(location, BlockInfo.getBlock(this.warzone.getWorld(), this.autoAssignGate), inside, left, right)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (String teamName : this.teamGateBlocks.keySet()) {
|
||||
|
||||
BlockInfo info = this.teamGateBlocks.get(teamName);
|
||||
if (this.leaving(location, BlockInfo.getBlock(this.warzone.getWorld(), info), inside, left, right)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean leaving(Location location, Block gate, BlockFace inside, BlockFace left, BlockFace right) {
|
||||
// 3x4x1 deep
|
||||
Volume gateExitVolume = new Volume("tempGateExit", location.getWorld());
|
||||
Block out = gate.getFace(inside);
|
||||
gateExitVolume.setCornerOne(out.getFace(left).getFace(BlockFace.DOWN));
|
||||
gateExitVolume.setCornerTwo(gate.getFace(right, 1).getFace(BlockFace.UP, 3));
|
||||
|
||||
if (gateExitVolume.contains(location)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
package com.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class ZoneWallGuard {
|
||||
private Player player;
|
||||
private Warzone warzone;
|
||||
private Location playerLocation;
|
||||
private BlockFace wall;
|
||||
private List<BlockInfo> glassified = new ArrayList<BlockInfo>();
|
||||
|
||||
public ZoneWallGuard(Player player, War war, Warzone warzone, BlockFace wall) {
|
||||
this.player = player;
|
||||
this.wall = wall;
|
||||
this.playerLocation = player.getLocation();
|
||||
this.warzone = warzone;
|
||||
this.activate();
|
||||
}
|
||||
|
||||
private void activate() {
|
||||
List<Block> nearestWallBlocks = this.warzone.getNearestWallBlocks(this.playerLocation);
|
||||
|
||||
// add wall guard blocks
|
||||
for (Block block : nearestWallBlocks) {
|
||||
this.glassify(block, this.wall);
|
||||
if (this.wall != BlockFace.UP && this.wall != BlockFace.DOWN) {
|
||||
this.glassify(block.getFace(BlockFace.UP), this.wall);
|
||||
this.glassify(block.getFace(BlockFace.UP, 2), this.wall);
|
||||
this.glassify(block.getFace(BlockFace.DOWN), this.wall);
|
||||
this.glassify(block.getFace(BlockFace.DOWN, 2), this.wall);
|
||||
}
|
||||
if (this.wall == BlockFace.NORTH && this.warzone.getVolume().isNorthWallBlock(block)) {
|
||||
this.glassify(block.getFace(BlockFace.EAST), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.UP), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.UP), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.DOWN), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.UP, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.UP), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.UP), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.DOWN), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.UP, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN, 2), BlockFace.NORTH);
|
||||
} else if (this.wall == BlockFace.SOUTH && this.warzone.getVolume().isSouthWallBlock(block)) {
|
||||
this.glassify(block.getFace(BlockFace.EAST), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.UP), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.UP), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.DOWN), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.UP, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.UP), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.UP), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.DOWN), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.UP, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN, 2), BlockFace.SOUTH);
|
||||
} else if (this.wall == BlockFace.EAST && this.warzone.getVolume().isEastWallBlock(block)) {
|
||||
this.glassify(block.getFace(BlockFace.NORTH), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.UP), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.DOWN), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP, 2), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN, 2), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.UP), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.DOWN), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP, 2), BlockFace.EAST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.EAST);
|
||||
} else if (this.wall == BlockFace.WEST && this.warzone.getVolume().isWestWallBlock(block)) {
|
||||
this.glassify(block.getFace(BlockFace.NORTH), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.UP), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.DOWN), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP, 2), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN, 2), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.UP), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.DOWN), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP, 2), BlockFace.WEST);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.WEST);
|
||||
} else if (this.wall == BlockFace.UP && this.warzone.getVolume().isUpWallBlock(block)) {
|
||||
this.glassify(block.getFace(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.EAST, 2), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.WEST, 2), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.NORTH), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST, 2), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST, 2), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP, 2), BlockFace.UP);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.UP);
|
||||
} else if (this.wall == BlockFace.DOWN && this.warzone.getVolume().isDownWallBlock(block)) {
|
||||
this.glassify(block.getFace(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.EAST, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.WEST, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.NORTH), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void glassify(Block block, BlockFace wall) {
|
||||
// face here means which wall we are working on
|
||||
|
||||
if ((block.getTypeId() == Material.AIR.getId() || block.getTypeId() == Material.WATER.getId()) && (this.warzone.getLobby() == null || (this.warzone.getLobby() != null && !this.warzone.getLobby().blockIsAGateBlock(block, wall)))) {
|
||||
if (wall == BlockFace.NORTH) {
|
||||
if (this.warzone.getVolume().isNorthWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.SOUTH) {
|
||||
if (this.warzone.getVolume().isSouthWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.EAST) {
|
||||
if (this.warzone.getVolume().isEastWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.WEST) {
|
||||
if (this.warzone.getVolume().isWestWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.UP) {
|
||||
if (this.warzone.getVolume().isUpWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.DOWN) {
|
||||
if (this.warzone.getVolume().isDownWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayerPosition(Location location) {
|
||||
if (this.warzone.isNearWall(location)) {
|
||||
this.playerLocation = location;
|
||||
this.deactivate();
|
||||
this.activate();
|
||||
}
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
for (BlockInfo oldBlock : this.glassified) {
|
||||
// return to original
|
||||
Block glassifiedBlock = this.warzone.getWorld().getBlockAt(oldBlock.getX(), oldBlock.getY(), oldBlock.getZ());
|
||||
glassifiedBlock.setTypeId(oldBlock.getTypeId());
|
||||
glassifiedBlock.setData(oldBlock.getData());
|
||||
}
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public BlockFace getWall() {
|
||||
return this.wall;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a command that may only be used by War admins
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractOptionalWarAdminCommand extends AbstractWarCommand {
|
||||
|
||||
public AbstractOptionalWarAdminCommand(WarCommandHandler handler, CommandSender sender, String[] args, boolean mustBeWarAdmin) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
|
||||
if (mustBeWarAdmin && !isSenderWarAdmin()) {
|
||||
throw new NotWarAdminException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSenderWarAdmin() {
|
||||
if (this.getSender() instanceof Player) {
|
||||
if (!War.war.isWarAdmin((Player) this.getSender())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else if (!(this.getSender() instanceof ConsoleCommandSender)) {
|
||||
return false;
|
||||
} else {
|
||||
// ConsoleCommandSender is admin
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a command that may only used by zone makers or regular users
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public abstract class AbstractOptionalZoneMakerCommand extends AbstractWarCommand {
|
||||
|
||||
public AbstractOptionalZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args, boolean zoneMakersOnly) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
||||
if (zoneMakersOnly && !this.isSenderZoneMaker()) {
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSenderZoneMaker() {
|
||||
if (this.getSender() instanceof Player) {
|
||||
// for players check War.isZoneMaker()
|
||||
if (!War.war.isZoneMaker((Player) this.getSender())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else if (!(this.getSender() instanceof ConsoleCommandSender)) {
|
||||
return false;
|
||||
} else {
|
||||
// ConsoleCommandSender is admin
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSenderAuthorOfZone(Warzone zone) {
|
||||
if (this.getSender() instanceof Player) {
|
||||
if (War.war.isWarAdmin((Player) this.getSender())) {
|
||||
// War admin has rights over all warzones
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not War admin, is he author?
|
||||
boolean isAuthor = zone.isAuthor((Player) this.getSender());
|
||||
if (!isAuthor) {
|
||||
War.war.badMsg(this.getSender(), "You can't do this because you are not an author of the " + zone.getName() + " warzone." );
|
||||
}
|
||||
return isAuthor;
|
||||
} else {
|
||||
// From console, you can do anything
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a command that may only be used by War admins
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractWarAdminCommand extends AbstractOptionalWarAdminCommand {
|
||||
|
||||
public AbstractWarAdminCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args, true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a war command
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public abstract class AbstractWarCommand {
|
||||
|
||||
/**
|
||||
* The sender of this command
|
||||
*
|
||||
* @var sender
|
||||
*/
|
||||
private CommandSender sender;
|
||||
|
||||
/**
|
||||
* The arguments of this command
|
||||
*
|
||||
* @var args
|
||||
*/
|
||||
protected String[] args;
|
||||
|
||||
/**
|
||||
* Instance of WarCommandHandler
|
||||
*
|
||||
* @var handler
|
||||
*/
|
||||
protected WarCommandHandler handler;
|
||||
|
||||
public AbstractWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
this.handler = handler;
|
||||
this.setSender(sender);
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the command
|
||||
*
|
||||
* @return true if command was used the right way
|
||||
*/
|
||||
abstract public boolean handle();
|
||||
|
||||
/**
|
||||
* Sends a success message
|
||||
*
|
||||
* @param message message to send
|
||||
*/
|
||||
public void msg(String message) {
|
||||
War.war.msg(this.getSender(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a failure message
|
||||
*
|
||||
* @param message message to send
|
||||
*/
|
||||
public void badMsg(String message) {
|
||||
War.war.badMsg(this.getSender(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a success message.
|
||||
* @param message Message or key to translate
|
||||
* @param args Arguments for the formatter
|
||||
*/
|
||||
public void msg(String message, Object... args) {
|
||||
War.war.msg(this.getSender(), message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a failure message.
|
||||
* @param message Message or key to translate
|
||||
* @param args Arguments for the formatter
|
||||
*/
|
||||
public void badMsg(String message, Object... args) {
|
||||
War.war.badMsg(this.getSender(), message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the command-sender
|
||||
*
|
||||
* @param sender new sender
|
||||
*/
|
||||
public void setSender(CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command-sender
|
||||
*
|
||||
* @return Command-Sender
|
||||
*/
|
||||
public CommandSender getSender() {
|
||||
return this.sender;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a command that may only be used by zone makers
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public abstract class AbstractZoneMakerCommand extends AbstractOptionalZoneMakerCommand {
|
||||
|
||||
public AbstractZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args, true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Deletes a bomb.
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class DeleteBombCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteBombCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Bomb bomb = zone.getBomb(this.args[0]);
|
||||
if (bomb != null) {
|
||||
bomb.getVolume().resetBlocks();
|
||||
zone.getBombs().remove(bomb);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Bomb " + bomb.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted bomb " + bomb.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such bomb.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Cake;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Deletes a cake.
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class DeleteCakeCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteCakeCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Cake cake = zone.getCake(this.args[0]);
|
||||
if (cake != null) {
|
||||
cake.getVolume().resetBlocks();
|
||||
zone.getCakes().remove(cake);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Cake " + cake.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted cake " + cake.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such cake.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.CapturePoint;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Deletes a capture point.
|
||||
*
|
||||
* @author Connor Monahan
|
||||
*/
|
||||
public class DeleteCapturePointCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteCapturePointCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
CapturePoint cp = zone.getCapturePoint(this.args[0]);
|
||||
if (cp != null) {
|
||||
cp.getVolume().resetBlocks();
|
||||
zone.getCapturePoints().remove(cp);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Capture point " + cp.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted capture point " + cp.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such capture point.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,15 +1,22 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Monument;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Deletes a monument.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteMonumentCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteMonumentCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
@ -18,6 +25,7 @@ public class DeleteMonumentCommand extends AbstractZoneMakerCommand {
|
|||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
|
@ -38,7 +46,10 @@ public class DeleteMonumentCommand extends AbstractZoneMakerCommand {
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -46,8 +57,9 @@ public class DeleteMonumentCommand extends AbstractZoneMakerCommand {
|
|||
if (monument != null) {
|
||||
monument.getVolume().resetBlocks();
|
||||
zone.getMonuments().remove(monument);
|
||||
WarzoneMapper.save(zone, false);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Monument " + monument.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted monument " + monument.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such monument.");
|
||||
}
|
|
@ -1,16 +1,24 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKinds;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
|
||||
/**
|
||||
* Deletes a team.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteTeamCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteTeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
@ -19,6 +27,7 @@ public class DeleteTeamCommand extends AbstractZoneMakerCommand {
|
|||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
|
@ -39,22 +48,29 @@ public class DeleteTeamCommand extends AbstractZoneMakerCommand {
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Team team = zone.getTeamByKind(TeamKinds.teamKindFromString(this.args[0]));
|
||||
Team team = zone.getTeamByKind(TeamKind.teamKindFromString(this.args[0]));
|
||||
if (team != null) {
|
||||
if (team.getFlagVolume() != null) {
|
||||
team.getFlagVolume().resetBlocks();
|
||||
}
|
||||
team.getSpawnVolume().resetBlocks();
|
||||
for (Volume spawnVolume : team.getSpawnVolumes().values()) {
|
||||
spawnVolume.resetBlocks();
|
||||
}
|
||||
zone.getTeams().remove(team);
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().setLocation(zone.getTeleport());
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
WarzoneMapper.save(zone, false);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg("Team " + team.getName() + " removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted team " + team.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such team.");
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Deletes a monument.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteTeamFlagCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteTeamFlagCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Team teamFlagTeam = null;
|
||||
for (Team team : zone.getTeams()) {
|
||||
if (team.getName().startsWith(this.args[0].toLowerCase())) {
|
||||
teamFlagTeam = team;
|
||||
}
|
||||
}
|
||||
if (teamFlagTeam != null) {
|
||||
teamFlagTeam.deleteTeamFlag();
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
this.msg(teamFlagTeam.getName() + " flag removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted team " + teamFlagTeam.getName() + " flag in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No such team flag.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,18 +1,21 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.VolumeMapper;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.structure.WarHub;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.WarHub;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.mappers.VolumeMapper;
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class DeleteWarhubCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteWarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
/**
|
||||
* Deletes the warhub.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteWarhubCommand extends AbstractWarAdminCommand {
|
||||
public DeleteWarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
|
@ -21,10 +24,11 @@ public class DeleteWarhubCommand extends AbstractZoneMakerCommand {
|
|||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (War.war.getWarHub() != null) {
|
||||
// reset existing hub
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
VolumeMapper.delete(War.war.getWarHub().getVolume());
|
||||
VolumeMapper.deleteSimpleVolume(War.war.getWarHub().getVolume());
|
||||
War.war.setWarHub((WarHub) null);
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null) {
|
||||
|
@ -34,10 +38,11 @@ public class DeleteWarhubCommand extends AbstractZoneMakerCommand {
|
|||
}
|
||||
|
||||
this.msg("War hub removed.");
|
||||
War.war.log(this.getSender().getName() + " deleted warhub", Level.INFO);
|
||||
} else {
|
||||
this.badMsg("No War hub to delete.");
|
||||
}
|
||||
WarMapper.save();
|
||||
WarYmlMapper.save();
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,23 +1,41 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Deletes a warzone.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteZoneCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
public static void forceDeleteZone(Warzone zone, CommandSender sender) {
|
||||
War.war.getWarzones().remove(zone);
|
||||
WarYmlMapper.save();
|
||||
|
||||
WarzoneYmlMapper.delete(zone);
|
||||
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
|
||||
String msg = "Warzone " + zone.getName() + " removed by " + sender.getName() + ".";
|
||||
War.war.log(msg, Level.INFO);
|
||||
War.war.msg(sender, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
@ -39,36 +57,14 @@ public class DeleteZoneCommand extends AbstractZoneMakerCommand {
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Team t : zone.getTeams()) {
|
||||
if (t.getTeamFlag() != null) {
|
||||
t.getFlagVolume().resetBlocks();
|
||||
}
|
||||
t.getSpawnVolume().resetBlocks();
|
||||
|
||||
// reset inventory
|
||||
for (Player p : t.getPlayers()) {
|
||||
zone.restorePlayerInventory(p);
|
||||
}
|
||||
}
|
||||
for (Monument m : zone.getMonuments()) {
|
||||
m.getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.getVolume().resetBlocks();
|
||||
War.war.getWarzones().remove(zone);
|
||||
WarMapper.save();
|
||||
WarzoneMapper.delete(zone.getName());
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
this.msg("Warzone " + zone.getName() + " removed.");
|
||||
forceDeleteZone(zone, getSender());
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Joins a team.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class JoinCommand extends AbstractWarCommand {
|
||||
public JoinCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
Warzone zone;
|
||||
TeamKind kind;
|
||||
boolean signup = false;
|
||||
if (this.args.length == 2) {
|
||||
// zone by name
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
kind = TeamKind.teamKindFromString(this.args[1]);
|
||||
} else if (this.args.length == 3 && args[0].equals("delayed")) {
|
||||
signup = true;
|
||||
zone = Warzone.getZoneByName(this.args[1]);
|
||||
kind = TeamKind.teamKindFromString(this.args[2]);
|
||||
} else if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
kind = TeamKind.teamKindFromString(this.args[0]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||
this.badMsg("join.disabled");
|
||||
} else if (zone.isReinitializing()) {
|
||||
this.badMsg("join.disabled");
|
||||
} else if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
|
||||
this.badMsg("join.aarequired");
|
||||
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
|
||||
this.badMsg("join.progress");
|
||||
} else {
|
||||
Team team = zone.getTeamByKind(kind);
|
||||
if (kind == null || team == null) {
|
||||
this.badMsg("join.team404");
|
||||
} else if (!War.war.canPlayWar(player, team)) {
|
||||
this.badMsg("join.permission.single");
|
||||
} else if (team.isFull()) {
|
||||
this.badMsg("join.full.single", team.getName());
|
||||
} else {
|
||||
Team previousTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (previousTeam != null) {
|
||||
if (previousTeam == team) {
|
||||
this.badMsg("join.selfteam");
|
||||
return true;
|
||||
}
|
||||
previousTeam.removePlayer(player);
|
||||
previousTeam.resetSign();
|
||||
}
|
||||
if (signup && !zone.testEnoughPlayers(kind, false)) {
|
||||
// player wants to automatically join the zone when everyone else is ready
|
||||
zone.signup(player, team);
|
||||
return true;
|
||||
}
|
||||
zone.assign(player, team);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,16 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.Warzone.LeaveCause;
|
||||
|
||||
/**
|
||||
* Leaves a game.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class LeaveCommand extends AbstractWarCommand {
|
||||
public LeaveCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
|
@ -15,7 +19,7 @@ public class LeaveCommand extends AbstractWarCommand {
|
|||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -29,7 +33,7 @@ public class LeaveCommand extends AbstractWarCommand {
|
|||
return false;
|
||||
}
|
||||
|
||||
zone.handlePlayerLeave(player, zone.getTeleport(), true);
|
||||
zone.handlePlayerLeave(player, zone.getEndTeleport(LeaveCause.COMMAND), true);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,17 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
import com.tommytony.war.War;
|
||||
|
||||
public class LoadWarCommand extends AbstractZoneMakerCommand {
|
||||
public LoadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
|
||||
/**
|
||||
* Loads war.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class LoadWarCommand extends AbstractWarAdminCommand {
|
||||
public LoadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
|
@ -15,7 +20,7 @@ public class LoadWarCommand extends AbstractZoneMakerCommand {
|
|||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
War.war.loadWar();
|
||||
this.msg("War loaded.");
|
||||
return true;
|
|
@ -1,13 +1,15 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.job.PartialZoneResetJob;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class NextBattleCommand extends AbstractZoneMakerCommand {
|
||||
public NextBattleCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
|
@ -34,16 +36,19 @@ public class NextBattleCommand extends AbstractZoneMakerCommand {
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
zone.clearFlagThieves();
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast("The battle was interrupted. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and life pools...");
|
||||
}
|
||||
zone.getVolume().resetBlocksAsJob();
|
||||
zone.initializeZoneAsJob();
|
||||
zone.clearThieves();
|
||||
zone.broadcast("zone.battle.next", zone.getName());
|
||||
|
||||
PartialZoneResetJob.setSenderToNotify(zone, this.getSender());
|
||||
|
||||
zone.reinitialize();
|
||||
|
||||
War.war.log(this.getSender().getName() + " used nextbattle in warzone " + zone.getName(), Level.INFO);
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
/**
|
||||
* NotZoneMakerException is thrown when a player is no zonemaker.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class NotWarAdminException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5412011034665080340L;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
/**
|
||||
* NotZoneMakerException is thrown when a player is no zonemaker.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class NotZoneMakerException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5412011034665080340L;
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
public class RenameZoneCommand extends AbstractZoneMakerCommand {
|
||||
public RenameZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Kill old warzone, but use it to create the renamed copy
|
||||
zone.unload();
|
||||
zone.getVolume().resetBlocks(); // We're going to use the blocks to save the new copy, reset to base state.
|
||||
|
||||
String newName = this.args[0];
|
||||
String oldName = zone.getName();
|
||||
|
||||
// Update the name
|
||||
zone.setName(newName);
|
||||
zone.saveState(false); // Save new volume files. Don't clear anything, we already unloaded.
|
||||
WarzoneYmlMapper.save(zone); // Save new config files for warzone.
|
||||
|
||||
// Get rid of old unloaded zone instance
|
||||
War.war.getWarzones().remove(zone);
|
||||
|
||||
// Move old files
|
||||
(new File(War.war.getDataFolder().getPath() + "/temp/renamed/")).mkdir();
|
||||
(new File(War.war.getDataFolder().getPath() + "/warzone-" + oldName + ".yml")).renameTo(new File(War.war.getDataFolder().getPath() + "/temp/renamed/warzone-" + oldName + ".yml"));
|
||||
(new File(War.war.getDataFolder().getPath() + "/temp/renamed/dat/warzone-" + oldName)).mkdirs();
|
||||
|
||||
String oldPath = War.war.getDataFolder().getPath() + "/dat/warzone-" + oldName + "/";
|
||||
File oldZoneFolder = new File(oldPath);
|
||||
File[] oldZoneFiles = oldZoneFolder.listFiles();
|
||||
for (File file : oldZoneFiles) {
|
||||
file.renameTo(new File(War.war.getDataFolder().getPath() + "/temp/renamed/dat/warzone-" + oldName + "/" + file.getName()));
|
||||
}
|
||||
oldZoneFolder.delete();
|
||||
|
||||
// Load new warzone
|
||||
War.war.log("Loading zone " + newName + "...", Level.INFO);
|
||||
Warzone newZone = WarzoneYmlMapper.load(newName);
|
||||
War.war.getWarzones().add(newZone);
|
||||
try {
|
||||
newZone.getVolume().loadCorners();
|
||||
} catch (SQLException ex) {
|
||||
War.war.log("Failed to load warzone " + newZone.getName() + ": " + ex.getMessage(), Level.WARNING);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
try {
|
||||
zone.getVolume().loadCorners();
|
||||
} catch (SQLException ex) {
|
||||
War.war.log("Failed to load warzone " + zone.getName() + ": " + ex.getMessage(), Level.WARNING);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
|
||||
newZone.initializeZone();
|
||||
|
||||
// Update war config
|
||||
WarYmlMapper.save();
|
||||
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
|
||||
War.war.log(this.getSender().getName() + " renamed warzone " + oldName + " to " + newName, Level.INFO);
|
||||
this.msg("Warzone " + oldName + " renamed to " + newName + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,20 +1,48 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.Warzone.LeaveCause;
|
||||
import com.tommytony.war.job.PartialZoneResetJob;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class ResetZoneCommand extends AbstractZoneMakerCommand {
|
||||
public ResetZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
public static void forceResetZone(Warzone zone, CommandSender sender) {
|
||||
zone.clearThieves();
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast("The war has ended. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and teams...");
|
||||
for (Iterator<Player> it = team.getPlayers().iterator(); it.hasNext(); ) {
|
||||
Player p = it.next();
|
||||
it.remove();
|
||||
team.removePlayer(p);
|
||||
if (!zone.getReallyDeadFighters().contains(p.getName())) {
|
||||
p.teleport(zone.getEndTeleport(LeaveCause.RESET));
|
||||
}
|
||||
}
|
||||
team.resetPoints();
|
||||
team.getPlayers().clear();
|
||||
}
|
||||
|
||||
War.war.msg(sender, "Reloading warzone " + zone.getName() + ".");
|
||||
|
||||
PartialZoneResetJob.setSenderToNotify(zone, sender);
|
||||
|
||||
zone.reinitialize();
|
||||
|
||||
War.war.log(sender.getName() + " reset warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
@ -35,28 +63,14 @@ public class ResetZoneCommand extends AbstractZoneMakerCommand {
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
zone.clearFlagThieves();
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast("The war has ended. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and teams...");
|
||||
for (Player p : team.getPlayers()) {
|
||||
zone.restorePlayerInventory(p);
|
||||
p.teleport(zone.getTeleport());
|
||||
War.war.msg(p, "You have left the warzone. Your inventory has been restored.");
|
||||
}
|
||||
team.resetPoints();
|
||||
team.getPlayers().clear();
|
||||
}
|
||||
|
||||
this.msg("Reloading warzone " + zone.getName() + ".");
|
||||
zone.getVolume().resetBlocksAsJob();
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocksAsJob();
|
||||
}
|
||||
zone.initializeZoneAsJob();
|
||||
forceResetZone(zone, this.getSender());
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
public class SaveZoneCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SaveZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone = null;
|
||||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
|
||||
if (this.args.length > 0 && !this.args[0].contains(":")) {
|
||||
// warzone name maybe in first place
|
||||
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
|
||||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if (zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if (zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if (this.args.length > 1) {
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
}
|
||||
|
||||
// We have a warzone and indexed-from-0 arguments
|
||||
if (War.war.getWarConfig().getBoolean(WarConfig.KEEPOLDZONEVERSIONS)) {
|
||||
// Keep a copy of the old version, just in case. First, find the version number
|
||||
File oldVersionsFolder = new File(War.war.getDataFolder().getPath() + "/temp/oldversions/warzone-" + zone.getName());
|
||||
oldVersionsFolder.mkdirs();
|
||||
|
||||
File[] versionFolders = oldVersionsFolder.listFiles();
|
||||
int newVersion = versionFolders.length + 1;
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String newVersionString = format.format(new Date()) + "-" + newVersion;
|
||||
String newVersionPath = War.war.getDataFolder().getPath() + "/temp/oldversions/warzone-" + zone.getName() + "/" + newVersionString;
|
||||
File newVersionFolder = new File(newVersionPath);
|
||||
newVersionFolder.mkdir();
|
||||
|
||||
// Copy all warzone files to new version folder before they get overwritten
|
||||
try {
|
||||
copyFile(new File(War.war.getDataFolder().getPath() + "/warzone-" + zone.getName() + ".yml"), new File(newVersionPath + "/warzone-" + zone.getName() + ".yml"));
|
||||
(new File(newVersionPath + "/dat/warzone-" + zone.getName())).mkdirs();
|
||||
String oldPath = War.war.getDataFolder().getPath() + "/dat/warzone-" + zone.getName() + "/";
|
||||
File currentZoneFolder = new File(oldPath);
|
||||
|
||||
File[] currentZoneFiles = currentZoneFolder.listFiles();
|
||||
for (File file : currentZoneFiles) {
|
||||
copyFile(file, new File(newVersionPath + "/dat/warzone-" + zone.getName() + "/" + file.getName()));
|
||||
}
|
||||
} catch (IOException badCopy) {
|
||||
War.war.log("Failed to make backup copy version " + newVersion + " of warzone " + zone.getName(), Level.WARNING);
|
||||
}
|
||||
|
||||
int currentVersion = newVersion + 1;
|
||||
this.msg("Saving version " + currentVersion + " of warzone " + zone.getName());
|
||||
War.war.log(this.getSender().getName() + " is saving version " + currentVersion + " of warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
this.msg("Saving new permanent version of warzone " + zone.getName());
|
||||
War.war.log(this.getSender().getName() + " is saving new permanent version of warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
// Let's save the new version update
|
||||
int savedBlocks = zone.saveState(true);
|
||||
|
||||
// changed settings: must reinitialize with new settings
|
||||
String namedParamResult = War.war.updateZoneFromNamedParams(zone, commandSender, this.args);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
if (this.args.length > 0) {
|
||||
// the config may have changed, requiring a reset for spawn styles etc.
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone(); // bring back team spawns etc
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
|
||||
this.msg("Saved " + savedBlocks + " blocks in warzone " + zone.getName() + "." + namedParamResult);
|
||||
if (namedParamResult != null && namedParamResult.length() > 0) {
|
||||
War.war.log(this.getSender().getName() + " also updated warzone " + zone.getName() + " configuration." + namedParamResult, Level.INFO);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void copyFile(File sourceFile, File destFile) throws IOException {
|
||||
if(!destFile.exists()) {
|
||||
destFile.createNewFile();
|
||||
}
|
||||
|
||||
FileChannel source = null;
|
||||
FileChannel destination = null;
|
||||
|
||||
try {
|
||||
source = new FileInputStream(sourceFile).getChannel();
|
||||
destination = new FileOutputStream(destFile).getChannel();
|
||||
destination.transferFrom(source, 0, source.size());
|
||||
}
|
||||
finally {
|
||||
if(source != null) {
|
||||
source.close();
|
||||
}
|
||||
if(destination != null) {
|
||||
destination.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
|
||||
/**
|
||||
* Places a bomb
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class SetBombCommand extends AbstractZoneMakerCommand {
|
||||
public SetBombCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasBomb(this.args[0])) {
|
||||
// move the existing bomb
|
||||
Bomb bomb = zone.getBomb(this.args[0]);
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.setLocation(player.getLocation());
|
||||
this.msg("Bomb " + bomb.getName() + " was moved.");
|
||||
War.war.log(this.getSender().getName() + " moved bomb " + bomb.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// create a new bomb
|
||||
Bomb bomb = new Bomb(this.args[0], zone, player.getLocation());
|
||||
zone.getBombs().add(bomb);
|
||||
this.msg("Bomb " + bomb.getName() + " created.");
|
||||
War.war.log(this.getSender().getName() + " created bomb " + bomb.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Cake;
|
||||
|
||||
/**
|
||||
* Places a cake
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class SetCakeCommand extends AbstractZoneMakerCommand {
|
||||
public SetCakeCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasCake(this.args[0])) {
|
||||
// move the existing cake
|
||||
Cake cake = zone.getCake(this.args[0]);
|
||||
cake.getVolume().resetBlocks();
|
||||
cake.setLocation(player.getLocation());
|
||||
this.msg("Cake " + cake.getName() + " was moved.");
|
||||
War.war.log(this.getSender().getName() + " moved cake " + cake.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// create a new cake
|
||||
Cake cake = new Cake(this.args[0], zone, player.getLocation());
|
||||
zone.getCakes().add(cake);
|
||||
this.msg("Cake " + cake.getName() + " created.");
|
||||
War.war.log(this.getSender().getName() + " created cake " + cake.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.CapturePoint;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Sets a capture point
|
||||
*
|
||||
* @author Connor Monahan
|
||||
*/
|
||||
public class SetCapturePointCommand extends AbstractZoneMakerCommand {
|
||||
public SetCapturePointCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasCapturePoint(this.args[0])) {
|
||||
// move the existing capture point
|
||||
CapturePoint cp = zone.getCapturePoint(this.args[0]);
|
||||
cp.getVolume().resetBlocks();
|
||||
cp.setLocation(player.getLocation());
|
||||
this.msg("Capture point " + cp.getName() + " was moved.");
|
||||
War.war.log(this.getSender().getName() + " moved capture point " + cp.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// create a new capture point
|
||||
TeamKind controller = null;
|
||||
int strength = 0;
|
||||
if (args.length > 1) {
|
||||
controller = TeamKind.teamKindFromString(args[1]);
|
||||
strength = 4;
|
||||
if (controller == null || zone.getTeamByKind(controller) == null) {
|
||||
this.badMsg("Failed to create capture point: team {0} does not exist", args[1]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
CapturePoint cp = new CapturePoint(this.args[0], player.getLocation(), controller, strength, zone);
|
||||
zone.getCapturePoints().add(cp);
|
||||
War.war.log(this.getSender().getName() + " created capture point " + cp.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,14 +1,21 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Monument;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
|
||||
/**
|
||||
* Places a monument
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetMonumentCommand extends AbstractZoneMakerCommand {
|
||||
public SetMonumentCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
@ -31,27 +38,29 @@ public class SetMonumentCommand extends AbstractZoneMakerCommand {
|
|||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
if (warzone.hasMonument(this.args[0])) {
|
||||
if (zone.hasMonument(this.args[0])) {
|
||||
// move the existing monument
|
||||
Monument monument = warzone.getMonument(this.args[0]);
|
||||
Monument monument = zone.getMonument(this.args[0]);
|
||||
monument.getVolume().resetBlocks();
|
||||
monument.setLocation(player.getLocation());
|
||||
this.msg("Monument " + monument.getName() + " was moved.");
|
||||
War.war.log(this.getSender().getName() + " moved monument " + monument.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// create a new monument
|
||||
Monument monument = new Monument(this.args[0], warzone, player.getLocation());
|
||||
warzone.getMonuments().add(monument);
|
||||
this.msg("Monument " + monument.getName() + " created.");
|
||||
Monument monument = new Monument(this.args[0], zone, player.getLocation());
|
||||
zone.getMonuments().add(monument);
|
||||
War.war.log(this.getSender().getName() + " created monument " + monument.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
WarzoneMapper.save(warzone, false);
|
||||
|
||||
WarzoneMapper.save(zone, false);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import java.util.Collections;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Places a soawn
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetTeamCommand extends AbstractZoneMakerCommand {
|
||||
public SetTeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TeamKind teamKind = TeamKind.teamKindFromString(this.args[0]);
|
||||
|
||||
if (teamKind == null) {
|
||||
return false;
|
||||
} else {
|
||||
Team existingTeam = zone.getTeamByKind(teamKind);
|
||||
if (existingTeam != null) {
|
||||
// add additional spawn
|
||||
existingTeam.addTeamSpawn(player.getLocation());
|
||||
this.msg("Additional spawn added for team " + existingTeam.getName() + ". Use /deleteteam " + existingTeam.getName() + " to remove all spawns.");
|
||||
War.war.log(this.getSender().getName() + " moved team " + existingTeam.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// new team (use default TeamKind name for now)
|
||||
Team newTeam = new Team(teamKind.toString(), teamKind, Collections.<Location>emptyList(), zone);
|
||||
newTeam.setRemainingLives(newTeam.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
|
||||
zone.getTeams().add(newTeam);
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().setLocation(zone.getTeleport());
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
newTeam.addTeamSpawn(player.getLocation());
|
||||
this.msg("Team " + newTeam.getName() + " created with spawn here.");
|
||||
War.war.log(this.getSender().getName() + " created team " + newTeam.getName() + " in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.config.TeamConfigBag;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
public class SetTeamConfigCommand extends AbstractOptionalZoneMakerCommand {
|
||||
|
||||
public SetTeamConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone = null;
|
||||
Player player = null;
|
||||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
boolean wantsToPrint = false;
|
||||
|
||||
Team team = null;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
if (!this.args[0].contains(":")) {
|
||||
// warzone name maybe in first place
|
||||
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
|
||||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
} else if (this.args[0].equals("-p") || this.args[0].equals("print")) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
player = (Player) commandSender;
|
||||
|
||||
if (zone == null) {
|
||||
// zone not found, is he standing in it?
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if (zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if (zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
|
||||
team = Team.getTeamByPlayerName(player.getName());
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if (this.args.length == 1) {
|
||||
// Only one param: the warzone name - pritn usage
|
||||
return false;
|
||||
}
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
|
||||
// args have been shifted if needed
|
||||
if (this.args.length > 0) {
|
||||
TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
|
||||
Team teamByName = zone.getTeamByKind(kind);
|
||||
|
||||
if (team == null && teamByName == null) {
|
||||
// Team not found
|
||||
this.badMsg("No such team. Use /teams.");
|
||||
return true;
|
||||
} else if (this.args.length == 1 && teamByName != null) {
|
||||
// only team name, print config
|
||||
this.msg(War.war.printConfig(teamByName));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (teamByName != null) {
|
||||
// first param was team, shift again
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
|
||||
if (teamByName != null) {
|
||||
// Named team > player's team
|
||||
team = teamByName;
|
||||
}
|
||||
} else {
|
||||
// No team param, show usage
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.args.length > 0 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
// only printing
|
||||
if (this.args.length == 1) {
|
||||
this.msg(War.war.printConfig(team));
|
||||
return true;
|
||||
} else {
|
||||
// first param was to print, shift again
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
if (!this.isSenderZoneMaker()) {
|
||||
War.war.badMsg(this.getSender(), "You can't do this if you are not a warzone maker (permission war.zonemaker).");
|
||||
return true;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// We have a warzone, a team and indexed-from-0 arguments, let's update
|
||||
String namedParamReturn = War.war.updateTeamFromNamedParams(team, player, this.args);
|
||||
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
|
||||
TeamConfigBag.afterUpdate(team, player, namedParamReturn, wantsToPrint);
|
||||
} else if (namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.badMsg("Failed to read named parameter(s).");
|
||||
} else {
|
||||
// empty return means no param was parsed - print command usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +1,23 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.TeamKinds;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Places a teamflag
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetTeamFlagCommand extends AbstractZoneMakerCommand {
|
||||
public SetTeamFlagCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
@ -33,9 +39,11 @@ public class SetTeamFlagCommand extends AbstractZoneMakerCommand {
|
|||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TeamKind kind = TeamKinds.teamKindFromString(this.args[0]);
|
||||
TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
|
||||
Team team = zone.getTeamByKind(kind);
|
||||
if (team == null) {
|
||||
// no such team yet
|
||||
|
@ -46,7 +54,8 @@ public class SetTeamFlagCommand extends AbstractZoneMakerCommand {
|
|||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ()));
|
||||
this.msg("Team " + team.getName() + " flag added here.");
|
||||
WarzoneMapper.save(zone, false);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
War.war.log(this.getSender().getName() + " created team " + team.getName() + " flag in warzone " + zone.getName(), Level.INFO);
|
||||
} else {
|
||||
// relocate flag
|
||||
team.getFlagVolume().resetBlocks();
|
||||
|
@ -54,7 +63,8 @@ public class SetTeamFlagCommand extends AbstractZoneMakerCommand {
|
|||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1));
|
||||
this.msg("Team " + team.getName() + " flag moved.");
|
||||
WarzoneMapper.save(zone, false);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
War.war.log(this.getSender().getName() + " moved team " + team.getName() + " flag in warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
return true;
|
|
@ -0,0 +1,48 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.config.WarConfigBag;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
|
||||
public class SetWarConfigCommand extends AbstractOptionalWarAdminCommand {
|
||||
|
||||
public SetWarConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
boolean wantsToPrint = false;
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
String config = War.war.printConfig();
|
||||
this.msg(config);
|
||||
return true;
|
||||
} else if (this.args.length > 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
if (!this.isSenderWarAdmin()) {
|
||||
War.war.badMsg(this.getSender(), "You can't do this if you are not a War admin (permission war.admin).");
|
||||
return true;
|
||||
}
|
||||
|
||||
String namedParamReturn = War.war.updateFromNamedParams(this.getSender(), this.args);
|
||||
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
|
||||
WarConfigBag.afterUpdate(this.getSender(), namedParamReturn, wantsToPrint);
|
||||
} else if (namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.msg("Failed to read named parameters.");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +1,30 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.WarHub;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.structure.WarHub;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class SetWarHubCommand extends AbstractZoneMakerCommand {
|
||||
public SetWarHubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
/**
|
||||
* Places the warhub
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetWarHubCommand extends AbstractWarAdminCommand {
|
||||
public SetWarHubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -34,6 +40,7 @@ public class SetWarHubCommand extends AbstractZoneMakerCommand {
|
|||
War.war.getWarHub().setLocation(player.getLocation());
|
||||
War.war.getWarHub().initialize();
|
||||
this.msg("War hub moved.");
|
||||
War.war.log(this.getSender().getName() + " moved the warhub", Level.INFO);
|
||||
} else {
|
||||
War.war.setWarHub(new WarHub(player.getLocation()));
|
||||
War.war.getWarHub().initialize();
|
||||
|
@ -44,8 +51,9 @@ public class SetWarHubCommand extends AbstractZoneMakerCommand {
|
|||
}
|
||||
}
|
||||
this.msg("War hub created.");
|
||||
War.war.log(this.getSender().getName() + " created the warhub", Level.INFO);
|
||||
}
|
||||
WarMapper.save();
|
||||
WarYmlMapper.save();
|
||||
} else {
|
||||
this.msg("No warzones yet.");
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.utility.Compat;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.ZoneSetter;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class SetZoneCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
|
@ -17,7 +15,7 @@ public class SetZoneCommand extends AbstractZoneMakerCommand {
|
|||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -28,8 +26,15 @@ public class SetZoneCommand extends AbstractZoneMakerCommand {
|
|||
} else if (this.args.length > 2) {
|
||||
return false;
|
||||
} else if (this.args.length == 1) {
|
||||
Compat.BlockPair pair = Compat.getWorldEditSelection(player);
|
||||
if (pair != null) {
|
||||
ZoneSetter setter = new ZoneSetter(player, this.args[0]);
|
||||
setter.placeCorner1(pair.getBlock1());
|
||||
setter.placeCorner2(pair.getBlock2());
|
||||
return true;
|
||||
}
|
||||
War.war.addWandBearer(player, this.args[0]);
|
||||
} else if (this.args.length == 2) {
|
||||
} else {
|
||||
if (!this.args[1].equals("southeast") && !this.args[1].equals("northwest") && !this.args[1].equals("se") && !this.args[1].equals("nw") && !this.args[1].equals("corner1") && !this.args[1].equals("corner2") && !this.args[1].equals("c1") && !this.args[1].equals("c2") && !this.args[1].equals("pos1") && !this.args[1].equals("pos2") && !this.args[1].equals("wand")) {
|
||||
return false;
|
||||
}
|
|
@ -1,19 +1,22 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.config.WarzoneConfigBag;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
|
||||
public class SetZoneConfigCommand extends AbstractOptionalZoneMakerCommand {
|
||||
|
||||
public SetZoneConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
super(handler, sender, args, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +26,7 @@ public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
|
|||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
boolean wantsToPrint = false;
|
||||
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
|
@ -33,83 +36,79 @@ public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
|
|||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
} else if (this.args[0].equals("-p") || this.args[0].equals("print")){
|
||||
} else if (this.args[0].equals("-p") || this.args[0].equals("print")) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
player = (Player)commandSender;
|
||||
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if(zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
player = (Player) commandSender;
|
||||
if (zone == null) {
|
||||
// zone not found, is he standing in it?
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if (zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if (zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
if(zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if(this.args.length == 1) {
|
||||
if (this.args.length == 1) {
|
||||
// Only one param: the warzone name - default to usage
|
||||
return false;
|
||||
}
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i-1] = args[i];
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
|
||||
|
||||
// args have been shifted if needed
|
||||
if(this.args.length > 0 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
if (this.args.length > 0 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
// only printing
|
||||
if(this.args.length == 1) {
|
||||
if (this.args.length == 1) {
|
||||
this.msg(War.war.printConfig(zone));
|
||||
return true;
|
||||
} else {
|
||||
// first param was to print, shift again
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i-1] = args[i];
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
// We have a warzone and indexed-from-0 arguments, let's update
|
||||
if (War.war.updateZoneFromNamedParams(zone, player, this.args)) {
|
||||
this.msg("Saving config and resetting warzone " + zone.getName() + ".");
|
||||
WarzoneMapper.save(zone, false);
|
||||
zone.getVolume().resetBlocks();
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone(); // bring back team spawns etc
|
||||
|
||||
if (wantsToPrint) {
|
||||
this.msg("Warzone config saved. Zone reset. " + War.war.printConfig(zone));
|
||||
} else {
|
||||
this.msg("Warzone config saved. Zone reset.");
|
||||
}
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
} else {
|
||||
this.badMsg("Failed to read named parameters.");
|
||||
}
|
||||
|
||||
|
||||
if (!this.isSenderZoneMaker()) {
|
||||
War.war.badMsg(this.getSender(), "You can't do this if you are not a warzone maker (permission war.zonemaker).");
|
||||
return true;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// We have a warzone and indexed-from-0 arguments, let's update
|
||||
String namedParamReturn = War.war.updateZoneFromNamedParams(zone, player, this.args);
|
||||
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
|
||||
WarzoneConfigBag.afterUpdate(zone, player, namedParamReturn, wantsToPrint);
|
||||
} else if (namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.badMsg("Failed to read named parameter(s).");
|
||||
} else {
|
||||
// empty return means no param was parsed - print command usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,23 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.utility.Direction;
|
||||
|
||||
/**
|
||||
* Places the zonelobby
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetZoneLobbyCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SetZoneLobbyCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
|
@ -27,24 +34,27 @@ public class SetZoneLobbyCommand extends AbstractZoneMakerCommand {
|
|||
return false;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
ZoneLobby origLobby = null;
|
||||
Warzone zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby != null) {
|
||||
zone = lobby.getZone();
|
||||
origLobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (origLobby != null) {
|
||||
zone = origLobby.getZone();
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// Zone not where player is standing, maybe player is detaching/relocating the lobby
|
||||
Warzone givenWarzone = Warzone.getZoneByName(this.args[0]);
|
||||
if (givenWarzone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(givenWarzone)) {
|
||||
return true;
|
||||
} else {
|
||||
// Move the warzone lobby
|
||||
ZoneLobby lobby = givenWarzone.getLobby();
|
||||
if (lobby != null) {
|
||||
// reset existing lobby
|
||||
lobby.getVolume().resetBlocks();
|
||||
// reset existing lobby and save new volume at new location
|
||||
lobby.setLocation(player.getLocation());
|
||||
lobby.initialize();
|
||||
this.msg("Warzone lobby moved to your location.");
|
||||
|
@ -59,28 +69,36 @@ public class SetZoneLobbyCommand extends AbstractZoneMakerCommand {
|
|||
}
|
||||
this.msg("Warzone lobby moved to your location.");
|
||||
}
|
||||
WarzoneMapper.save(givenWarzone, false);
|
||||
WarzoneYmlMapper.save(givenWarzone);
|
||||
}
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
} else {
|
||||
// Inside a warzone: use the classic n/s/e/w mode
|
||||
if (!this.args[0].equals("north") && !this.args[0].equals("n") && !this.args[0].equals("east") && !this.args[0].equals("e") && !this.args[0].equals("south") && !this.args[0].equals("s") && !this.args[0].equals("west") && !this.args[0].equals("w")) {
|
||||
if (Warzone.getZoneByName(this.args[0]) == zone && origLobby != null) {
|
||||
origLobby.setLocation(player.getLocation());
|
||||
origLobby.initialize();
|
||||
this.msg("Warzone lobby moved to your location.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
ZoneLobby lobby = zone.getLobby();
|
||||
|
||||
BlockFace wall = BlockFace.WEST;
|
||||
BlockFace wall = Direction.WEST();
|
||||
String wallStr = "";
|
||||
if (this.args[0].equals("north") || this.args[0].equals("n")) {
|
||||
wall = BlockFace.NORTH;
|
||||
wall = Direction.NORTH();
|
||||
wallStr = "north";
|
||||
} else if (this.args[0].equals("east") || this.args[0].equals("e")) {
|
||||
wall = BlockFace.EAST;
|
||||
wall = Direction.EAST();
|
||||
wallStr = "east";
|
||||
} else if (this.args[0].equals("south") || this.args[0].equals("s")) {
|
||||
wall = BlockFace.SOUTH;
|
||||
wall = Direction.SOUTH();
|
||||
wallStr = "south";
|
||||
} else if (this.args[0].equals("west") || this.args[0].equals("w")) {
|
||||
wall = BlockFace.WEST;
|
||||
wall = Direction.WEST();
|
||||
wallStr = "west";
|
||||
}
|
||||
|
||||
|
@ -101,7 +119,8 @@ public class SetZoneLobbyCommand extends AbstractZoneMakerCommand {
|
|||
}
|
||||
this.msg("Warzone lobby created on " + wallStr + "side of zone.");
|
||||
}
|
||||
WarzoneMapper.save(zone, false);
|
||||
WarzoneYmlMapper.save(zone);
|
||||
War.war.log(player.getName() + " moved lobby of warzone " + zone.getName(), Level.INFO);
|
||||
}
|
||||
|
||||
return true;
|
|
@ -1,17 +1,16 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
|
||||
/**
|
||||
* Sends a message to all team-members
|
||||
* @author das-schaf
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class TeamCommand extends AbstractWarCommand {
|
||||
public TeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
|
@ -21,7 +20,7 @@ public class TeamCommand extends AbstractWarCommand {
|
|||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -31,13 +30,22 @@ public class TeamCommand extends AbstractWarCommand {
|
|||
return false;
|
||||
}
|
||||
|
||||
ChatColor color = playerTeam.getKind().getColor();
|
||||
String teamMessage = color + player.getName() + ": " + ChatColor.WHITE;
|
||||
for (String part : this.args) {
|
||||
teamMessage += part + " ";
|
||||
if (this.args.length < 1) {
|
||||
if (playerTeam.isInTeamChat(player)) {
|
||||
playerTeam.removeTeamChatPlayer(player);
|
||||
this.msg("team.chat.disable");
|
||||
} else {
|
||||
playerTeam.addTeamChatPlayer(player);
|
||||
this.msg("team.chat.enable");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
playerTeam.teamcast(teamMessage);
|
||||
|
||||
StringBuilder teamMessage = new StringBuilder();
|
||||
for (String part : this.args) {
|
||||
teamMessage.append(part).append(' ');
|
||||
}
|
||||
playerTeam.sendTeamChatMessage(player, teamMessage.toString());
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,17 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Shows team information
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class TeamsCommand extends AbstractWarCommand {
|
||||
public TeamsCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
|
@ -1,12 +1,17 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
import com.tommytony.war.War;
|
||||
|
||||
public class UnloadWarCommand extends AbstractZoneMakerCommand {
|
||||
public UnloadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
|
||||
/**
|
||||
* Unloads war.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class UnloadWarCommand extends AbstractWarAdminCommand {
|
||||
public UnloadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
|
@ -1,46 +1,56 @@
|
|||
package bukkit.tommytony.war;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.ui.WarUI;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.command.*;
|
||||
|
||||
/**
|
||||
* Handles commands received by War
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
* @author Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarCommandHandler {
|
||||
|
||||
/**
|
||||
* Handles a command
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param cmd The command
|
||||
* @param args The arguments
|
||||
* @return Success
|
||||
* @param sender
|
||||
* The sender of the command
|
||||
* @param cmd
|
||||
* The command
|
||||
* @param args
|
||||
* The arguments
|
||||
* @return Success
|
||||
*/
|
||||
public boolean handle(CommandSender sender, Command cmd, String[] args) {
|
||||
String command = cmd.getName();
|
||||
String[] arguments = null;
|
||||
|
||||
// parse prefixed commands
|
||||
if ((command.equals("war") || command.equals("War")) && args.length > 0) {
|
||||
command = args[0];
|
||||
arguments = new String[args.length - 1];
|
||||
for (int i = 1; i <= arguments.length; i++) {
|
||||
arguments[i - 1] = args[i];
|
||||
}
|
||||
|
||||
if (arguments.length == 1 && (arguments[0].equals("help") || arguments[0].equals("h"))) {
|
||||
// show /war help
|
||||
War.war.badMsg(sender, cmd.getUsage());
|
||||
War.war.badMsg(sender, cmd.getUsage());
|
||||
return true;
|
||||
}
|
||||
} else if (command.equals("war") || command.equals("War")) {
|
||||
// show /war help
|
||||
War.war.msg(sender, cmd.getUsage());
|
||||
if (sender instanceof Player) {
|
||||
War.war.getUIManager().assignUI((Player) sender, new WarUI());
|
||||
} else {
|
||||
War.war.badMsg(sender, "Use /war help for information.");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
arguments = args;
|
||||
|
@ -74,16 +84,34 @@ public class WarCommandHandler {
|
|||
commandObj = new ResetZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("nextbattle")) {
|
||||
commandObj = new NextBattleCommand(this, sender, arguments);
|
||||
} else if (command.equals("renamezone")) {
|
||||
commandObj = new RenameZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("setteam")) {
|
||||
commandObj = new SetTeamCommand(this, sender, arguments);
|
||||
} else if (command.equals("deleteteam")) {
|
||||
commandObj = new DeleteTeamCommand(this, sender, arguments);
|
||||
} else if (command.equals("setteamflag")) {
|
||||
commandObj = new SetTeamFlagCommand(this, sender, arguments);
|
||||
} else if (command.equals("deleteteamflag")) {
|
||||
commandObj = new DeleteTeamFlagCommand(this, sender, arguments);
|
||||
} else if (command.equals("setmonument")) {
|
||||
commandObj = new SetMonumentCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletemonument")) {
|
||||
commandObj = new DeleteMonumentCommand(this, sender, arguments);
|
||||
} else if (command.equals("setcapturepoint")) {
|
||||
commandObj = new SetCapturePointCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletecapturepoint")) {
|
||||
commandObj = new DeleteCapturePointCommand(this, sender, arguments);
|
||||
} else if (command.equals("setbomb")) {
|
||||
commandObj = new SetBombCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletebomb")) {
|
||||
commandObj = new DeleteBombCommand(this, sender, arguments);
|
||||
} else if (command.equals("setcake")) {
|
||||
commandObj = new SetCakeCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletecake")) {
|
||||
commandObj = new DeleteCakeCommand(this, sender, arguments);
|
||||
}else if (command.equals("setteamconfig") || command.equals("teamcfg")) {
|
||||
commandObj = new SetTeamConfigCommand(this, sender, arguments);
|
||||
} else if (command.equals("setzoneconfig") || command.equals("zonecfg")) {
|
||||
commandObj = new SetZoneConfigCommand(this, sender, arguments);
|
||||
} else if (command.equals("setwarhub")) {
|
||||
|
@ -98,24 +126,24 @@ public class WarCommandHandler {
|
|||
commandObj = new SetWarConfigCommand(this, sender, arguments);
|
||||
} else if (command.equals("zonemaker") || command.equals("zm")) {
|
||||
commandObj = new ZoneMakerCommand(this, sender, arguments);
|
||||
}
|
||||
}
|
||||
// we are not responsible for any other command
|
||||
}
|
||||
catch (NotZoneMakerException e) {
|
||||
War.war.badMsg(sender, "You can't do this if you are not a warzone maker.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (NotWarAdminException e) {
|
||||
War.war.badMsg(sender, "war.notadmin");
|
||||
} catch (NotZoneMakerException e) {
|
||||
War.war.badMsg(sender, "war.notzm");
|
||||
} catch (Exception e) {
|
||||
War.war.log("An error occured while handling command " + cmd.getName() + ". Exception:" + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
if(commandObj != null) {
|
||||
boolean handled = commandObj.handle();
|
||||
if(!handled) {
|
||||
War.war.badMsg(sender, cmd.getUsage());
|
||||
War.war.badMsg(sender, cmd.getUsage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,19 @@
|
|||
package bukkit.tommytony.war.command;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.job.TeleportPlayerJob;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Warps the player to the warhub.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarhubCommand extends AbstractWarCommand {
|
||||
public WarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
|
@ -16,7 +22,7 @@ public class WarhubCommand extends AbstractWarCommand {
|
|||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
if (this.args.length != 0) {
|
||||
|
@ -24,15 +30,23 @@ public class WarhubCommand extends AbstractWarCommand {
|
|||
}
|
||||
Player player = (Player) this.getSender();
|
||||
if (War.war.getWarHub() == null) {
|
||||
this.badMsg("No warhub on this War server. Try /zones and /zone.");
|
||||
this.badMsg("warhub.none");
|
||||
} else if (!War.war.canWarp(player)) {
|
||||
this.badMsg("Can't warp to warhub. You need the 'war.warp' permission.");
|
||||
this.badMsg("warhub.permission");
|
||||
} else {
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (playerWarzone != null) { // was in zone
|
||||
playerWarzone.handlePlayerLeave(player, War.war.getWarHub().getLocation(), true);
|
||||
}
|
||||
player.teleport(War.war.getWarHub().getLocation());
|
||||
int warmup = War.war.getWarConfig().getInt(WarConfig.TPWARMUP);
|
||||
if (warmup > 0 && !player.hasPermission("war.warmupexempt")) {
|
||||
final int TICKS_PER_SECOND = 20;
|
||||
TeleportPlayerJob job = new TeleportPlayerJob(player, War.war.getWarHub().getLocation());
|
||||
job.runTaskLater(War.war, warmup);
|
||||
this.msg("command.tp.init", warmup / TICKS_PER_SECOND);
|
||||
} else {
|
||||
player.teleport(War.war.getWarHub().getLocation());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.job.TeleportPlayerJob;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Warps the player to the given warzone.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarzoneCommand extends AbstractWarCommand {
|
||||
public WarzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("command.console");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
if (args.length == 1) {
|
||||
if (War.war.canWarp(player)) {
|
||||
Warzone warzone = Warzone.getZoneByName(args[0]);
|
||||
if (warzone != null && warzone.getTeleport() != null) {
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName());
|
||||
int warmup = War.war.getWarConfig().getInt(WarConfig.TPWARMUP);
|
||||
if (playerWarzone != null) {
|
||||
playerWarzone.handlePlayerLeave(player, warzone.getTeleport(), true);
|
||||
}
|
||||
if (warmup > 0 && !player.hasPermission("war.warmupexempt")) {
|
||||
final int TICKS_PER_SECOND = 20;
|
||||
TeleportPlayerJob job = new TeleportPlayerJob(player, warzone.getTeleport());
|
||||
job.runTaskLater(War.war, warmup);
|
||||
this.msg("command.tp.init", warmup / TICKS_PER_SECOND);
|
||||
} else {
|
||||
player.teleport(warzone.getTeleport());
|
||||
}
|
||||
} else {
|
||||
this.badMsg("zone.zone404");
|
||||
}
|
||||
} else {
|
||||
this.badMsg("zone.warp.permission");
|
||||
}
|
||||
return true;
|
||||
} else if (args.length == 2 && (args[1].equalsIgnoreCase("sb")
|
||||
|| args[1].equalsIgnoreCase("score")
|
||||
|| args[1].equalsIgnoreCase("scoreboard"))) {
|
||||
Warzone warzone = Warzone.getZoneByName(args[0]);
|
||||
if (warzone != null) {
|
||||
if (warzone.getScoreboard() != null) {
|
||||
if (warzone.getScoreboard() == player.getScoreboard()) {
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
} else {
|
||||
player.setScoreboard(warzone.getScoreboard());
|
||||
}
|
||||
} else {
|
||||
this.badMsg("zone.score.board404");
|
||||
}
|
||||
} else {
|
||||
this.badMsg("zone.zone404");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Lists all warzones
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarzonesCommand extends AbstractWarCommand {
|
||||
public WarzonesCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
StringBuilder warzonesMessage = new StringBuilder(War.war.getString("zone.zoneinfo.prefix"));
|
||||
if (War.war.getWarzones().isEmpty()) {
|
||||
warzonesMessage.append(War.war.getString("zone.teaminfo.none"));
|
||||
} else {
|
||||
for (Warzone warzone : War.war.getWarzones()) {
|
||||
warzonesMessage.append('\n');
|
||||
warzonesMessage.append(MessageFormat.format(War.war.getString("zone.zoneinfo.format"),
|
||||
warzone.getName(), warzone.getTeams().size(), warzone.getPlayerCount()));
|
||||
}
|
||||
}
|
||||
|
||||
this.msg(warzonesMessage.toString() + ((this.getSender() instanceof Player) ? War.war.getString("zone.zoneinfo.teleport") : ""));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.tommytony.war.command;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Makes a player zonemaker and other way round.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class ZoneMakerCommand extends AbstractWarCommand {
|
||||
|
||||
public ZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
||||
if (sender instanceof Player) { // i hate java for this.
|
||||
if (!War.war.isZoneMaker((Player) sender)) {
|
||||
for (OfflinePlayer offlinePlayer : War.war.getZoneMakersImpersonatingPlayers()) {
|
||||
if (offlinePlayer.isOnline() && sender.equals(offlinePlayer.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (War.war.isZoneMaker(player)) {
|
||||
if (this.args.length == 0) {
|
||||
War.war.getZoneMakersImpersonatingPlayers().add(player);
|
||||
this.msg("You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode.");
|
||||
} else if (this.args.length == 1) {
|
||||
OfflinePlayer other = Bukkit.getOfflinePlayer(this.args[0]);
|
||||
// make someone zonemaker or remove the right
|
||||
if (War.war.getZoneMakerNames().contains(other)) {
|
||||
// kick
|
||||
War.war.getZoneMakerNames().remove(other);
|
||||
this.msg(this.args[0] + " is not a zone maker anymore.");
|
||||
if (other.isOnline()) {
|
||||
War.war.msg(other.getPlayer(), player.getName() + " took away your warzone maker priviledges.");
|
||||
War.war.log(player.getName() + " took away zonemaker rights from " + other.getName(), Level.INFO);
|
||||
}
|
||||
} else {
|
||||
// add
|
||||
War.war.getZoneMakerNames().add(other);
|
||||
this.msg(this.args[0] + " is now a zone maker.");
|
||||
if (other.isOnline()) {
|
||||
War.war.msg(other.getPlayer(), player.getName() + " made you warzone maker.");
|
||||
War.war.log(player.getName() + " made " + other.getName() + " a zonemaker", Level.INFO);
|
||||
}
|
||||
}
|
||||
WarYmlMapper.save();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
War.war.getZoneMakersImpersonatingPlayers().remove(player);
|
||||
this.msg("You are back as a zone maker.");
|
||||
WarYmlMapper.save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,17 +1,21 @@
|
|||
package com.tommytony.war;
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
import com.tommytony.war.volumes.NotNorthwestException;
|
||||
import com.tommytony.war.volumes.NotSoutheastException;
|
||||
import com.tommytony.war.volumes.TooBigException;
|
||||
import com.tommytony.war.volumes.TooSmallException;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.utility.Direction;
|
||||
import com.tommytony.war.volume.NotNorthwestException;
|
||||
import com.tommytony.war.volume.NotSoutheastException;
|
||||
import com.tommytony.war.volume.TooBigException;
|
||||
import com.tommytony.war.volume.TooSmallException;
|
||||
|
||||
public class ZoneSetter {
|
||||
|
||||
|
@ -28,17 +32,26 @@ public class ZoneSetter {
|
|||
Block northwestBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null) {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setNorthwest(northwestBlock);
|
||||
warzone.getVolume().setNorthwest(northwestBlock.getLocation());
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
|
||||
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its nw corner", Level.INFO);
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setNorthwest(northwestBlock);
|
||||
warzone.getVolume().setNorthwest(northwestBlock.getLocation());
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
|
||||
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its nw corner", Level.INFO);
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (NotNorthwestException e) {
|
||||
|
@ -64,17 +77,26 @@ public class ZoneSetter {
|
|||
Block southeastBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null) {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setSoutheast(southeastBlock);
|
||||
warzone.getVolume().setSoutheast(southeastBlock.getLocation());
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
|
||||
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its se corner", Level.INFO);
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setSoutheast(southeastBlock);
|
||||
warzone.getVolume().setSoutheast(southeastBlock.getLocation());
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
|
||||
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its se corner", Level.INFO);
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (NotSoutheastException e) {
|
||||
|
@ -104,17 +126,26 @@ public class ZoneSetter {
|
|||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null) {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setZoneCornerOne(corner1Block);
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
|
||||
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its corner 1", Level.INFO);
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setZoneCornerOne(corner1Block);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
|
||||
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its corner 1", Level.INFO);
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (TooSmallException e) {
|
||||
|
@ -139,17 +170,26 @@ public class ZoneSetter {
|
|||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null) {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setZoneCornerTwo(corner2Block);
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
|
||||
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its corner 2", Level.INFO);
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setZoneCornerTwo(corner2Block);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
|
||||
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its corner 2", Level.INFO);
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (TooSmallException e) {
|
||||
|
@ -165,14 +205,23 @@ public class ZoneSetter {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isPlayerAuthorOfZoneOrAdmin(Warzone warzone) {
|
||||
boolean isAuthor = warzone.isAuthor(player);
|
||||
boolean isAdmin = !War.war.isWarAdmin(player);
|
||||
if (!isAuthor && !isAdmin) {
|
||||
War.war.badMsg(player, "You can't do this because you are not an author of the " + warzone.getName() + " warzone." );
|
||||
}
|
||||
return isAuthor || isAdmin;
|
||||
}
|
||||
|
||||
private void resetWarzone(Warzone warzone, StringBuilder msgString) {
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
War.war.msg(this.player, "Resetting " + warzone.getName() + " blocks.");
|
||||
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) {
|
||||
warzone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
int reset = warzone.getVolume().resetBlocks();
|
||||
msgString.append(reset + " blocks reset. ");
|
||||
warzone.getVolume().resetBlocks();
|
||||
msgString.append(warzone.getVolume().size() + " blocks reset. ");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,26 +241,26 @@ public class ZoneSetter {
|
|||
if (War.war.getIncompleteZones().contains(warzone)) {
|
||||
War.war.getIncompleteZones().remove(warzone);
|
||||
}
|
||||
WarMapper.save();
|
||||
WarYmlMapper.save();
|
||||
msgString.append("Saving new warzone blocks...");
|
||||
War.war.msg(this.player, msgString.toString());
|
||||
warzone.saveState(false); // we just changed the volume, cant reset walls
|
||||
|
||||
if (warzone.getLobby() == null) {
|
||||
// Set default lobby on south side
|
||||
ZoneLobby lobby = new ZoneLobby(warzone, BlockFace.SOUTH);
|
||||
ZoneLobby lobby = new ZoneLobby(warzone, Direction.SOUTH());
|
||||
warzone.setLobby(lobby);
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
War.war.msg(this.player, "Default lobby created on south side of zone. Use /setzonelobby <n/s/e/w> to change its position.");
|
||||
} // else {
|
||||
// gotta move the lobby (or dont because zone.initzon does it for you)
|
||||
// warzone.getLobby().changeWall(warzone.getLobby().getWall());
|
||||
// }
|
||||
}
|
||||
|
||||
warzone.initializeZone();
|
||||
WarzoneMapper.save(warzone, true);
|
||||
WarzoneYmlMapper.save(warzone);
|
||||
War.war.msg(this.player, "Warzone saved.");
|
||||
War.war.log(this.player.getName() + " saved first version of warzone " + zoneName, Level.INFO);
|
||||
} else {
|
||||
if (warzone.getVolume().getCornerOne() == null) {
|
||||
msgString.append("Still missing corner 1.");
|
|
@ -0,0 +1,22 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
public enum FlagReturn {
|
||||
BOTH,
|
||||
FLAG,
|
||||
SPAWN;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static FlagReturn getFromString(String string) {
|
||||
for (FlagReturn flagMode : FlagReturn.values()) {
|
||||
if (string.toLowerCase().equals(flagMode.toString())) {
|
||||
return flagMode;
|
||||
}
|
||||
}
|
||||
|
||||
return FlagReturn.BOTH;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.utility.Loadout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class InventoryBag {
|
||||
|
||||
private List<Loadout> loadouts = new ArrayList<Loadout>();
|
||||
private HashMap<Integer, ItemStack> reward = null;
|
||||
|
||||
private Warzone warzone;
|
||||
|
||||
public InventoryBag(Warzone warzone) {
|
||||
this.warzone = warzone;
|
||||
}
|
||||
|
||||
public InventoryBag() {
|
||||
this.warzone = null;
|
||||
}
|
||||
|
||||
public void addLoadout(String name, HashMap<Integer, ItemStack> loadout) {
|
||||
this.loadouts.add(new Loadout(name, loadout, null));
|
||||
}
|
||||
|
||||
public void addLoadout(Loadout loadout) {
|
||||
this.loadouts.add(loadout);
|
||||
}
|
||||
|
||||
public void removeLoadout(String name) {
|
||||
ArrayList<Loadout> loadoutsToRemove = new ArrayList<Loadout>();
|
||||
for (Loadout ldt : loadouts) {
|
||||
if (ldt.getName().equals(name)) {
|
||||
loadoutsToRemove.add(ldt);
|
||||
}
|
||||
}
|
||||
|
||||
// avoid concurrent modif exceptions
|
||||
for (Loadout loadoutToRemove : loadoutsToRemove) {
|
||||
this.removeLoadout(loadoutToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeLoadout(Loadout ldt) {
|
||||
this.loadouts.remove(ldt);
|
||||
}
|
||||
|
||||
public boolean hasLoadouts() {
|
||||
return loadouts.size() > 0;
|
||||
}
|
||||
|
||||
public HashMap<String, HashMap<Integer, ItemStack>> getLoadouts() {
|
||||
return Loadout.toLegacyFormat(loadouts);
|
||||
}
|
||||
|
||||
public List<Loadout> getNewLoadouts() {
|
||||
return loadouts;
|
||||
}
|
||||
|
||||
public void setLoadouts(List<Loadout> loadouts) {
|
||||
this.loadouts = loadouts;
|
||||
}
|
||||
|
||||
public HashMap<String, HashMap<Integer, ItemStack>> resolveLoadouts() {
|
||||
if (this.hasLoadouts()) {
|
||||
return this.getLoadouts();
|
||||
} else if (warzone != null && warzone.getDefaultInventories().hasLoadouts()) {
|
||||
return warzone.getDefaultInventories().resolveLoadouts();
|
||||
} else if (War.war.getDefaultInventories().hasLoadouts()) {
|
||||
return War.war.getDefaultInventories().resolveLoadouts();
|
||||
} else {
|
||||
return new HashMap<String, HashMap<Integer, ItemStack>>();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Loadout> resolveNewLoadouts() {
|
||||
if (this.hasLoadouts()) {
|
||||
return this.getNewLoadouts();
|
||||
} else if (warzone != null && warzone.getDefaultInventories().hasLoadouts()) {
|
||||
return warzone.getDefaultInventories().resolveNewLoadouts();
|
||||
} else if (War.war.getDefaultInventories().hasLoadouts()) {
|
||||
return War.war.getDefaultInventories().resolveNewLoadouts();
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public void setReward(HashMap<Integer, ItemStack> reward) {
|
||||
this.reward = reward;
|
||||
}
|
||||
|
||||
public boolean hasReward() {
|
||||
return reward != null;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ItemStack> getReward() {
|
||||
return reward;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ItemStack> resolveReward() {
|
||||
if (this.hasReward()) {
|
||||
return reward;
|
||||
} else if (warzone != null && warzone.getDefaultInventories().hasReward()) {
|
||||
return warzone.getDefaultInventories().resolveReward();
|
||||
} else {
|
||||
return War.war.getDefaultInventories().resolveReward();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearLoadouts() {
|
||||
this.loadouts.clear();
|
||||
}
|
||||
|
||||
public HashMap<Integer, ItemStack> getLoadout(String loadoutName) {
|
||||
for (Loadout ldt : loadouts) {
|
||||
if (ldt.getName().equals(loadoutName)) {
|
||||
return ldt.getContents();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Loadout getNewLoadout(String loadoutName) {
|
||||
for (Loadout ldt : loadouts) {
|
||||
if (ldt.getName().equals(loadoutName)) {
|
||||
return ldt;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setLoadout(String name, HashMap<Integer, ItemStack> contents) {
|
||||
for (Loadout ldt : loadouts) {
|
||||
if (ldt.getName().equals(name)) {
|
||||
ldt.setContents(contents);
|
||||
return;
|
||||
}
|
||||
}
|
||||
loadouts.add(new Loadout(name, contents, null));
|
||||
}
|
||||
|
||||
public boolean containsLoadout(String name) {
|
||||
return this.getNewLoadout(name) != null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* Manage rewards for certain killstreaks.
|
||||
*
|
||||
* @author cmastudios
|
||||
*/
|
||||
public class KillstreakReward {
|
||||
|
||||
private ConfigurationSection section;
|
||||
private Set<String> airstrikePlayers;
|
||||
|
||||
/**
|
||||
* Creates a new killstreak reward class with default options.
|
||||
*/
|
||||
public KillstreakReward() {
|
||||
this(new MemoryConfiguration());
|
||||
section.set("3.privmsg", "You have been rewarded with some health for your kills.");
|
||||
section.set("3.reward.health", 8);
|
||||
section.set("4.reward.xp", 3);
|
||||
section.set("5.message", "{0} is on a &ckillstreak&f! 5 kills this life.");
|
||||
section.set("5.privmsg", "You have received some items for your kills.");
|
||||
section.set("5.reward.points", 1);
|
||||
section.set("5.reward.airstrike", true);
|
||||
section.set("5.reward.items", ImmutableList.of(new ItemStack(Material.ARROW, 15), new ItemStack(Material.EGG)));
|
||||
section.set("5.reward.effect", Effect.GHAST_SHRIEK.name());
|
||||
ItemStack sword = new ItemStack(Material.WOODEN_SWORD);
|
||||
sword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
|
||||
sword.addEnchantment(Enchantment.KNOCKBACK, 1);
|
||||
ItemMeta meta = sword.getItemMeta();
|
||||
meta.setDisplayName("The Breaker");
|
||||
meta.setLore(ImmutableList.of("Very slow speed"));
|
||||
sword.setItemMeta(meta);
|
||||
section.set("7.reward.items", ImmutableList.of(sword));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new killstreak reward class with options from the provided
|
||||
* config.
|
||||
*
|
||||
* @param section Section to load killstreak options from, such as
|
||||
* set.war.killstreak
|
||||
*/
|
||||
public KillstreakReward(ConfigurationSection section) {
|
||||
this.section = section;
|
||||
this.airstrikePlayers = new HashSet<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewards a player for their current killstreak. The player must be in a
|
||||
* warzone.
|
||||
*
|
||||
* @param player Player to reward
|
||||
* @param kills Amount of kills to reward for
|
||||
*/
|
||||
public void rewardPlayer(Player player, int kills) {
|
||||
if (section == null) {
|
||||
/*
|
||||
* Cancel the reward if there is no configuration for killstreaks.
|
||||
* This can occur if the server owner has an older War config with
|
||||
* no settings for killstreaks and have neglected to add any. Heck,
|
||||
* they shouldn't have enabled killstreaks in the warzone anyway.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
final Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
final Team playerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
Validate.notNull(zone, "Cannot reward player if they are not in a warzone");
|
||||
Validate.notNull(playerTeam, "Cannot reward player if they are not in a team");
|
||||
if (section.contains(Integer.toString(kills))) {
|
||||
ConfigurationSection killSection = section.getConfigurationSection(Integer.toString(kills));
|
||||
if (killSection.contains("message")) {
|
||||
final String playerName = playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE;
|
||||
final String message = ChatColor.translateAlternateColorCodes('&', MessageFormat.format(killSection.getString("message"), playerName));
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast(message);
|
||||
}
|
||||
}
|
||||
if (killSection.contains("privmsg")) {
|
||||
War.war.msg(player, ChatColor.translateAlternateColorCodes('&', killSection.getString("privmsg")));
|
||||
}
|
||||
if (killSection.contains("reward.health")) {
|
||||
double health = player.getHealth() + killSection.getInt("reward.health");
|
||||
player.setHealth(health > 20 ? 20 : health); // Grant up to full health only
|
||||
}
|
||||
if (killSection.contains("reward.items")) {
|
||||
for (Object obj : killSection.getList("reward.items")) {
|
||||
if (obj instanceof ItemStack) {
|
||||
player.getInventory().addItem((ItemStack) obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (killSection.contains("reward.xp") && !playerTeam.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
// Will not work if XPKILLMETER is enabled
|
||||
player.setLevel(player.getLevel() + killSection.getInt("reward.xp"));
|
||||
}
|
||||
if (killSection.contains("reward.points")) {
|
||||
for (int i = 0; i < killSection.getInt("reward.points"); i++) {
|
||||
playerTeam.addPoint();
|
||||
}
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
player.getServer().getScheduler().runTaskLater(War.war, new Runnable() {
|
||||
public void run() {
|
||||
zone.handleScoreCapReached(playerTeam.getName());
|
||||
}
|
||||
}, 1L);
|
||||
} else {
|
||||
// just added a point
|
||||
playerTeam.resetSign();
|
||||
zone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
}
|
||||
if (killSection.getBoolean("reward.airstrike")) {
|
||||
this.airstrikePlayers.add(player.getName());
|
||||
}
|
||||
if (killSection.contains("reward.effect")) {
|
||||
Effect effect = Effect.valueOf(killSection.getString("reward.effect"));
|
||||
player.getWorld().playEffect(player.getLocation(), effect, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveTo(ConfigurationSection section) {
|
||||
Map<String, Object> values = this.section.getValues(true);
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
section.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getAirstrikePlayers() {
|
||||
return airstrikePlayers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
|
||||
/**
|
||||
* Storage class for MySQL configuration settings.
|
||||
*
|
||||
* @author cmastudios
|
||||
*/
|
||||
public class MySQLConfig {
|
||||
|
||||
private ConfigurationSection section;
|
||||
|
||||
/**
|
||||
* Load the values from the specified section into the MySQL config.
|
||||
*
|
||||
* @param section Section to load MySQL settings from.
|
||||
*/
|
||||
public MySQLConfig(ConfigurationSection section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new MySQL configuration section with default values.
|
||||
*/
|
||||
public MySQLConfig() {
|
||||
this(new MemoryConfiguration());
|
||||
section.set("enabled", false);
|
||||
section.set("host", "localhost");
|
||||
section.set("port", 3306);
|
||||
section.set("database", "war");
|
||||
section.set("username", "root");
|
||||
section.set("password", "meow");
|
||||
section.set("logging.enabled", false);
|
||||
section.set("logging.autoclear",
|
||||
"WHERE `date` < NOW() - INTERVAL 7 DAY");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if MySQL support is enabled.
|
||||
*
|
||||
* @return true if MySQL support is enabled, false otherwise.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return section.getBoolean("enabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if kill-death logging is enabled.
|
||||
*
|
||||
* @return true if kill-death logging is enabled, false otherwise.
|
||||
*/
|
||||
public boolean isLoggingEnabled() {
|
||||
return section.getBoolean("logging.enabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WHERE clause for automatic deletion from database table.
|
||||
*
|
||||
* @return deletion WHERE clause or empty string.
|
||||
*/
|
||||
public String getLoggingDeleteClause() {
|
||||
return section.getString("logging.autoclear", "");
|
||||
}
|
||||
|
||||
private String getJDBCUrl() {
|
||||
return String.format("jdbc:mysql://%s:%d/%s?user=%s&password=%s",
|
||||
section.getString("host"), section.getInt("port"),
|
||||
section.getString("database"), section.getString("username"),
|
||||
section.getString("password"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a connection to the MySQL database represented by this configuration.
|
||||
*
|
||||
* @return connection to MySQL database.
|
||||
* @throws SQLException Error occured connecting to database.
|
||||
* @throws IllegalArgumentException MySQL support is not enabled.
|
||||
*/
|
||||
public Connection getConnection() throws SQLException {
|
||||
Validate.isTrue(this.isEnabled(), "MySQL support is not enabled");
|
||||
return DriverManager.getConnection(this.getJDBCUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy represented configuration into another configuration section.
|
||||
*
|
||||
* @param section Mutable section to write values in.
|
||||
*/
|
||||
public void saveTo(ConfigurationSection section) {
|
||||
Map<String, Object> values = this.section.getValues(true);
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
section.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
public enum ScoreboardType {
|
||||
|
||||
NONE(null),
|
||||
POINTS("Points"),
|
||||
LIFEPOOL("Lifepool"),
|
||||
TOPKILLS("Top kills"),
|
||||
PLAYERCOUNT("Player count"),
|
||||
SWITCHING("Switching");
|
||||
private final String displayName;
|
||||
|
||||
ScoreboardType(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public static ScoreboardType getFromString(String string) {
|
||||
for (ScoreboardType boardMode : ScoreboardType.values()) {
|
||||
if (string.toLowerCase().equals(boardMode.toString())) {
|
||||
return boardMode;
|
||||
}
|
||||
}
|
||||
|
||||
return ScoreboardType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
|
||||
public enum TeamConfig {
|
||||
FLAGMUSTBEHOME (Boolean.class, "Flag Must Be Home", "If true, enemy flag cannot be captured if your flag is out"),
|
||||
FLAGPOINTSONLY (Boolean.class, null, null), // obsolete
|
||||
FLAGRETURN (FlagReturn.class, "Flag Return Destination", "Defines where the flag must be returned to capture\nOptions: spawn, flag, or both"),
|
||||
LIFEPOOL (Integer.class, "Lifepool", "Sets maximum team lives"),
|
||||
MAXSCORE (Integer.class, "Max Score", "Sets the point limit for when a team will win"),
|
||||
NOHUNGER (Boolean.class, "No Hunger", "If true, player hunger will not decrease"),
|
||||
PLAYERLOADOUTASDEFAULT (Boolean.class, "Player Loadout As Default", "If true, the default loadout will be the items the player brings into the zone"),
|
||||
RESPAWNTIMER (Integer.class, "Respawn Time", "Time, in seconds, required to wait after each death"),
|
||||
SATURATION (Integer.class, "Saturation", "Set player saturation to this level after each death"),
|
||||
SPAWNSTYLE (TeamSpawnStyle.class, "Spawn Style", "Sets the type spawn point\nOptions: small, big, flat, invisible"),
|
||||
TEAMSIZE (Integer.class, "Team Size", "Maximum players that may play on a team"),
|
||||
PERMISSION (String.class, "Required Permission", "Only allow players with a certain permission to join a team"),
|
||||
XPKILLMETER (Boolean.class, "XP Kill Meter", "Use the XP bar to count kills"),
|
||||
KILLSTREAK (Boolean.class, "Killstreak Rewards", "Reward players for kills based on war.yml configuration"),
|
||||
BLOCKWHITELIST (String.class, "Block Whitelist", "Comma-separated list of blocks players may break or place, 'all' removes this limit"),
|
||||
PLACEBLOCK (Boolean.class, "Place Blocks", "If true, players can place blocks"),
|
||||
APPLYPOTION(String.class, "Apply Potion Effect", "Give players a potion effect after each death, Format: EFFECT;DURATION;STRENGTH"),
|
||||
ECOREWARD(Double.class, "Economy Reward", "Give the winning team this much money, requires Vault plugin"),
|
||||
INVENTORYDROP(Boolean.class, "Drop Inventory", "If true, players will drop items on death"),
|
||||
BORDERDROP(Boolean.class, "Drop Near Border", "If true, players can drop items near the border\nUsually enabled to prevent duping");
|
||||
|
||||
private final Class<?> configType;
|
||||
private final String title;
|
||||
private final String description;
|
||||
|
||||
TeamConfig(Class<?> configType, String title, String description) {
|
||||
this.configType = configType;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Class<?> getConfigType() {
|
||||
return configType;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static TeamConfig teamConfigFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (TeamConfig config : TeamConfig.values()) {
|
||||
if (config.toString().startsWith(lowered)) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toStringWithValue(Object value) {
|
||||
return this.toString() + ":" + value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,280 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TeamConfigBag {
|
||||
|
||||
private EnumMap<TeamConfig, Object> bag = new EnumMap<TeamConfig, Object>(TeamConfig.class);
|
||||
private Warzone warzone;
|
||||
|
||||
public TeamConfigBag(Warzone warzone) {
|
||||
this.warzone = warzone;
|
||||
}
|
||||
|
||||
public TeamConfigBag() {
|
||||
this.warzone = null;
|
||||
}
|
||||
|
||||
public static void afterUpdate(Team team, CommandSender sender, String namedParamReturn, boolean wantsToPrint) {
|
||||
final Warzone zone = team.getZone();
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
String zoneReset = "Some changes may require a /resetzone. ";
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
|
||||
zone.reinitialize(); // bring back team spawns etc
|
||||
zoneReset = "Zone reset. ";
|
||||
}
|
||||
|
||||
if (wantsToPrint) {
|
||||
War.war.msg(sender, "Team config saved. " + zoneReset + namedParamReturn + " " + War.war.printConfig(team));
|
||||
} else {
|
||||
War.war.msg(sender, "Team config saved. " + zoneReset + namedParamReturn);
|
||||
}
|
||||
|
||||
War.war.log(sender.getName() + " updated team " + team.getName() + " configuration in warzone " + zone.getName() + "." + namedParamReturn, Level.INFO);
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(TeamConfig config) {
|
||||
return this.bag.containsKey(config);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.bag.clear();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.bag.keySet().size() == 0;
|
||||
}
|
||||
|
||||
public void put(TeamConfig config, Object value) {
|
||||
this.bag.put(config, value);
|
||||
}
|
||||
|
||||
public Object getValue(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object resolveValue(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveValue(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveValue(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDouble(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Double)this.bag.get(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Double resolveDouble(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Double)this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveDouble(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveDouble(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getInt(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Integer)this.bag.get(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Integer resolveInt(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Integer) this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveInt(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveInt(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean getBoolean(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Boolean)this.bag.get(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Boolean resolveBoolean(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (Boolean) this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveBoolean(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveBoolean(config);
|
||||
}
|
||||
}
|
||||
|
||||
public String getString(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (String)this.bag.get(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String resolveString(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (String) this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveString(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveString(config);
|
||||
}
|
||||
}
|
||||
|
||||
public FlagReturn resolveFlagReturn() {
|
||||
if (this.contains(TeamConfig.FLAGRETURN)) {
|
||||
return (FlagReturn) this.bag.get(TeamConfig.FLAGRETURN);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(TeamConfig.FLAGRETURN)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveFlagReturn();
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveFlagReturn();
|
||||
}
|
||||
}
|
||||
|
||||
public FlagReturn getFlagReturn() {
|
||||
if (this.contains(TeamConfig.FLAGRETURN)) {
|
||||
return (FlagReturn) this.bag.get(TeamConfig.FLAGRETURN);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TeamSpawnStyle resolveSpawnStyle() {
|
||||
if (this.contains(TeamConfig.SPAWNSTYLE)) {
|
||||
return (TeamSpawnStyle) this.bag.get(TeamConfig.SPAWNSTYLE);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(TeamConfig.SPAWNSTYLE)){
|
||||
// use War default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveSpawnStyle();
|
||||
} else {
|
||||
return War.war.getTeamDefaultConfig().resolveSpawnStyle();
|
||||
}
|
||||
}
|
||||
|
||||
public TeamSpawnStyle getSpawnStyle() {
|
||||
if (this.contains(TeamConfig.SPAWNSTYLE)) {
|
||||
return (TeamSpawnStyle) this.bag.get(TeamConfig.SPAWNSTYLE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void loadFrom(ConfigurationSection teamConfigSection) {
|
||||
for (TeamConfig config : TeamConfig.values()) {
|
||||
if (teamConfigSection.contains(config.toString())) {
|
||||
if (config.getConfigType().equals(Integer.class)) {
|
||||
this.put(config, teamConfigSection.getInt(config.toString()));
|
||||
} else if (config.getConfigType().equals(Boolean.class)) {
|
||||
this.put(config, teamConfigSection.getBoolean(config.toString()));
|
||||
} else if (config.getConfigType().equals(String.class)) {
|
||||
this.put(config, teamConfigSection.getString(config.toString()));
|
||||
} else if (config.getConfigType().equals(Double.class)) {
|
||||
this.put(config, teamConfigSection.getDouble(config.toString()));
|
||||
} else if (config.getConfigType().equals(FlagReturn.class)) {
|
||||
String flagReturnStr = teamConfigSection.getString(config.toString());
|
||||
FlagReturn returnMode = FlagReturn.getFromString(flagReturnStr);
|
||||
if (returnMode != null) {
|
||||
this.put(config, returnMode);
|
||||
}
|
||||
} else if (config.getConfigType().equals(TeamSpawnStyle.class)) {
|
||||
String spawnStyleStr = teamConfigSection.getString(config.toString());
|
||||
TeamSpawnStyle style = TeamSpawnStyle.getStyleFromString(spawnStyleStr);
|
||||
if (style != null) {
|
||||
this.put(config, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveTo(ConfigurationSection teamConfigSection) {
|
||||
for (TeamConfig config : TeamConfig.values()) {
|
||||
if (this.contains(config)) {
|
||||
if (config.getConfigType().equals(Integer.class)
|
||||
|| config.getConfigType().equals(Boolean.class)
|
||||
|| config.getConfigType().equals(Double.class)) {
|
||||
teamConfigSection.set(config.toString(), this.bag.get(config));
|
||||
} else {
|
||||
teamConfigSection.set(config.toString(), this.bag.get(config).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String updateFromNamedParams(Map<String, String> namedParams) {
|
||||
String returnMessage = "";
|
||||
for (String namedParam : namedParams.keySet()) {
|
||||
TeamConfig teamConfig = TeamConfig.teamConfigFromString(namedParam);
|
||||
if (teamConfig != null) {
|
||||
if (teamConfig.getConfigType().equals(Integer.class)) {
|
||||
int intValue = Integer.parseInt(namedParams.get(namedParam));
|
||||
this.bag.put(teamConfig, intValue);
|
||||
} else if (teamConfig.getConfigType().equals(Double.class)) {
|
||||
double doubleValue = Double.parseDouble(namedParams.get(namedParam));
|
||||
this.bag.put(teamConfig, doubleValue);
|
||||
} else if (teamConfig.getConfigType().equals(Boolean.class)) {
|
||||
String onOff = namedParams.get(namedParam);
|
||||
this.bag.put(teamConfig, onOff.equals("on") || onOff.equals("true"));
|
||||
} else if (teamConfig.getConfigType().equals(String.class)) {
|
||||
String str = namedParams.get(namedParam);
|
||||
this.bag.put(teamConfig, str);
|
||||
} else if (teamConfig.getConfigType().equals(FlagReturn.class)) {
|
||||
FlagReturn flagValue = FlagReturn.getFromString(namedParams.get(namedParam));
|
||||
this.bag.put(teamConfig, flagValue);
|
||||
} else if (teamConfig.getConfigType().equals(TeamSpawnStyle.class)) {
|
||||
TeamSpawnStyle spawnValue = TeamSpawnStyle.getStyleFromString(namedParams.get(namedParam));
|
||||
this.bag.put(teamConfig, spawnValue);
|
||||
}
|
||||
returnMessage += " " + teamConfig.toString() + " set to " + namedParams.get(namedParam);
|
||||
} else if (namedParam.equals("delete")) {
|
||||
String toDelete = namedParams.get(namedParam);
|
||||
teamConfig = TeamConfig.teamConfigFromString(toDelete);
|
||||
|
||||
// param delete (to restore inheritance)
|
||||
if (teamConfig != null) {
|
||||
this.bag.remove(teamConfig);
|
||||
returnMessage += " " + teamConfig.toString() + " removed";
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnMessage;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
public enum TeamKind {
|
||||
WHITE (DyeColor.WHITE, Material.WHITE_WOOL, ChatColor.WHITE, 450),
|
||||
ORANGE (DyeColor.ORANGE, Material.ORANGE_WOOL, ChatColor.GOLD, 51),
|
||||
MAGENTA (DyeColor.MAGENTA, Material.MAGENTA_WOOL, ChatColor.LIGHT_PURPLE, 353),
|
||||
BLUE (DyeColor.LIGHT_BLUE, Material.LIGHT_BLUE_WOOL, ChatColor.BLUE, 23),
|
||||
GOLD (DyeColor.YELLOW, Material.YELLOW_WOOL, ChatColor.YELLOW, 403), // yellow = gold
|
||||
GREEN (DyeColor.LIME, Material.LIME_WOOL, ChatColor.GREEN, 612),
|
||||
PINK (DyeColor.PINK, Material.PINK_WOOL, ChatColor.LIGHT_PURPLE, 929),
|
||||
GRAY (DyeColor.GRAY, Material.GRAY_WOOL, ChatColor.DARK_GRAY, 600),
|
||||
IRON (DyeColor.GRAY, Material.GRAY_WOOL, ChatColor.GRAY, 154), // lightgrey = iron
|
||||
DIAMOND (DyeColor.CYAN, Material.CYAN_WOOL, ChatColor.DARK_AQUA, 738), // cyan = diamond
|
||||
PURPLE (DyeColor.PURPLE, Material.PURPLE_WOOL, ChatColor.DARK_PURPLE, 153),
|
||||
NAVY (DyeColor.BLUE, Material.BLUE_WOOL, ChatColor.DARK_BLUE, 939),
|
||||
BROWN (DyeColor.BROWN, Material.BROWN_WOOL, ChatColor.DARK_RED, 908),
|
||||
DARKGREEN (DyeColor.GREEN, Material.GREEN_WOOL, ChatColor.DARK_GREEN, 612),
|
||||
RED (DyeColor.RED, Material.RED_WOOL, ChatColor.RED, 245),
|
||||
BLACK (DyeColor.BLACK, Material.BLACK_WOOL, ChatColor.BLACK, 0);
|
||||
|
||||
private final DyeColor dyeColor;
|
||||
private final ChatColor chatColor;
|
||||
private final Material material;
|
||||
private final int potionEffectColor;
|
||||
|
||||
TeamKind(DyeColor blockHeadColor, Material material, ChatColor color, int potionEffectColor) {
|
||||
this.dyeColor = blockHeadColor;
|
||||
this.material = material;
|
||||
this.chatColor = color;
|
||||
this.potionEffectColor = potionEffectColor;
|
||||
}
|
||||
|
||||
public static TeamKind teamKindFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (TeamKind kind : TeamKind.values()) {
|
||||
if (kind.toString().startsWith(lowered)) {
|
||||
return kind;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TeamKind getTeam(String teamName) {
|
||||
for (TeamKind team : TeamKind.values()) {
|
||||
if (team.toString().equalsIgnoreCase(teamName)) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get wool block data for the dye color.
|
||||
* @deprecated TODO remove all spout craft support
|
||||
* @return wool color data value
|
||||
*/
|
||||
public byte getData() {
|
||||
return this.dyeColor.getWoolData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of this team in chat messages.
|
||||
*
|
||||
* @return team chat color.
|
||||
*/
|
||||
public ChatColor getColor() {
|
||||
return this.chatColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of the wool block as a bukkit color.
|
||||
*
|
||||
* @return wool block color.
|
||||
*/
|
||||
public org.bukkit.Color getBukkitColor() {
|
||||
return this.dyeColor.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get head block material.
|
||||
*
|
||||
* @return team head block material.
|
||||
*/
|
||||
public Material getMaterial() {
|
||||
return this.material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color of the team's potion effect, for thieves.
|
||||
*
|
||||
* @return potion effect color.
|
||||
*/
|
||||
public int getPotionEffectColor() {
|
||||
return this.potionEffectColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single item of this team's wool head block.
|
||||
*
|
||||
* @return single block head item.
|
||||
*/
|
||||
public ItemStack getBlockHead() {
|
||||
return new ItemStack(this.material, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a block is this team's color block.
|
||||
*
|
||||
* @param block Wool block to check.
|
||||
* @return true if block is this team's color.
|
||||
*/
|
||||
public boolean isTeamBlock(BlockState block) {
|
||||
return block.getType() == material;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an item is this team's color block.
|
||||
*
|
||||
* @param item Wool item to check.
|
||||
* @return true if item is this team's color.
|
||||
*/
|
||||
public boolean isTeamItem(ItemStack item) {
|
||||
return item.getType() == material;
|
||||
}
|
||||
|
||||
public String getFormattedName() {
|
||||
return this.getColor() + this.name().toLowerCase() + ChatColor.WHITE;
|
||||
}
|
||||
|
||||
public String getCapsName() {
|
||||
return String.valueOf(name().charAt(0)) + name().substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a colored hat item for the team.
|
||||
* @return Hat item with the team's color.
|
||||
*/
|
||||
public ItemStack getHat() {
|
||||
ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) helmet.getItemMeta();
|
||||
meta.setColor(this.getBukkitColor());
|
||||
helmet.setItemMeta(meta);
|
||||
return helmet;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public enum TeamSpawnStyle {
|
||||
INVISIBLE,
|
||||
SMALL,
|
||||
FLAT,
|
||||
BIG;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static TeamSpawnStyle getStyleFromString(String string) {
|
||||
for (TeamSpawnStyle style : TeamSpawnStyle.values()) {
|
||||
if (string.toLowerCase().equals(style.toString())) {
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
return TeamSpawnStyle.SMALL;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
|
||||
public enum WarConfig {
|
||||
BUILDINZONESONLY (Boolean.class, "Build in zones only", "Allow building in zones only"),
|
||||
DISABLEBUILDMESSAGE (Boolean.class, "Disable build message", "Silently prevent building outside zones"),
|
||||
DISABLEPVPMESSAGE (Boolean.class, "Disable PVP message", "Silently prevent PVP"),
|
||||
KEEPOLDZONEVERSIONS (Boolean.class, "Keep old zone versions", "If true, archive the warzone on each save"),
|
||||
MAXZONES (Integer.class, "Max zones", "Limit on number of zones that can be created"),
|
||||
PVPINZONESONLY (Boolean.class, "PVP in zones only", "If true, limits PVP to warzones"),
|
||||
TNTINZONESONLY (Boolean.class, "TNT in zones only", "If true, limits TNT to warzones"),
|
||||
RESETSPEED (Integer.class, "Reset speed", "Number of blocks to reset per tick"),
|
||||
MAXSIZE (Integer.class, "Max size", "Maximum volume of a warzone"),
|
||||
LANGUAGE (String.class, "Language", "Preferred server language"),
|
||||
AUTOJOIN (String.class, "Auto-join", "Name of warzone to send players to upon join"),
|
||||
TPWARMUP(Integer.class, "TP warmup", "Amount of seconds a player must wait after requesting a teleport"),
|
||||
DISABLECOOLDOWN (Boolean.class, "Disable the 1.9 combat cooldown", "Disables the attack cooldown when swinging a weapon");
|
||||
|
||||
private final Class<?> configType;
|
||||
private final String title;
|
||||
private final String description;
|
||||
|
||||
WarConfig(Class<?> configType, String title, String description) {
|
||||
this.configType = configType;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Class<?> getConfigType() {
|
||||
return configType;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static WarConfig warConfigFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (WarConfig config : WarConfig.values()) {
|
||||
if (config.toString().startsWith(lowered)) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toStringWithValue(Object value) {
|
||||
return this.toString() + ":" + value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class WarConfigBag {
|
||||
|
||||
EnumMap<WarConfig, Object> bag = new EnumMap<WarConfig, Object>(WarConfig.class);
|
||||
|
||||
public void put(WarConfig config, Object value) {
|
||||
this.bag.put(config, value);
|
||||
}
|
||||
|
||||
public Object getValue(WarConfig config) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
return this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getInt(WarConfig config) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
return (Integer)this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean getBoolean(WarConfig config) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
return (Boolean)this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getString(WarConfig config) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
return (String)this.bag.get(config);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void loadFrom(ConfigurationSection warConfigSection) {
|
||||
for (WarConfig config : WarConfig.values()) {
|
||||
if (warConfigSection.contains(config.toString())) {
|
||||
if (config.getConfigType().equals(Integer.class)) {
|
||||
this.put(config, warConfigSection.getInt(config.toString()));
|
||||
} else if (config.getConfigType().equals(Boolean.class)) {
|
||||
this.put(config, warConfigSection.getBoolean(config.toString()));
|
||||
} else if (config.getConfigType().equals(String.class)) {
|
||||
this.put(config, warConfigSection.getString(config.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveTo(ConfigurationSection warConfigSection) {
|
||||
for (WarConfig config : WarConfig.values()) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
warConfigSection.set(config.toString(), this.bag.get(config));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String updateFromNamedParams(Map<String, String> namedParams) {
|
||||
String returnMessage = "";
|
||||
for (String namedParam : namedParams.keySet()) {
|
||||
WarConfig warConfig = WarConfig.warConfigFromString(namedParam);
|
||||
if (warConfig != null) {
|
||||
if (warConfig.getConfigType().equals(Integer.class)) {
|
||||
int intValue = Integer.parseInt(namedParams.get(namedParam));
|
||||
this.bag.put(warConfig, intValue);
|
||||
} else if (warConfig.getConfigType().equals(Boolean.class)) {
|
||||
String onOff = namedParams.get(namedParam);
|
||||
this.bag.put(warConfig, onOff.equals("on") || onOff.equals("true"));
|
||||
} else if (warConfig.getConfigType().equals(String.class)) {
|
||||
String str = namedParams.get(namedParam);
|
||||
this.bag.put(warConfig, str);
|
||||
}
|
||||
if (warConfig == WarConfig.LANGUAGE) {
|
||||
War.reloadLanguage();
|
||||
}
|
||||
returnMessage += warConfig.toString() + " set to " + namedParams.get(namedParam);
|
||||
}
|
||||
}
|
||||
return returnMessage;
|
||||
}
|
||||
|
||||
public static void afterUpdate(CommandSender sender, String namedParamReturn, boolean wantsToPrint) {
|
||||
WarYmlMapper.save();
|
||||
if (wantsToPrint) {
|
||||
String config = War.war.printConfig();
|
||||
War.war.msg(sender, "War config saved. " + namedParamReturn + " " + config);
|
||||
} else {
|
||||
War.war.msg(sender, "War config saved. " + namedParamReturn);
|
||||
}
|
||||
War.war.log(sender.getName() + " updated War configuration. " + namedParamReturn, Level.INFO);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
public enum WarzoneConfig {
|
||||
AUTOASSIGN (Boolean.class, "Auto-Assign", "If true, distributes players across teams"),
|
||||
BLOCKHEADS (Boolean.class, "Team Helmets", "If true, players are given a team-colored hat"),
|
||||
DEATHMESSAGES (Boolean.class, "Death Notification", "If true, notify the zone when players are killed"),
|
||||
DISABLED (Boolean.class, "Disable Zone", "If true, prevent players from joining the zone"),
|
||||
FRIENDLYFIRE (Boolean.class, "Friendly Fire", "If true, players are allowed to injure teammates"),
|
||||
GLASSWALLS (Boolean.class, "Glass Walls", "If true, use magic glass walls to keep players in/out of zones"),
|
||||
INSTABREAK (Boolean.class, "Insta-Break", "If true, players break blocks instantly\nUseful for Spleef gamemodes"),
|
||||
MINTEAMS (Integer.class, "Minimum Teams", "Minimum number of active teams required to start the battle"),
|
||||
MINPLAYERS (Integer.class, "Minimum Players", "Minimum number of players required per team to start the battle"),
|
||||
MONUMENTHEAL (Integer.class, "Monument Heal", "Number of hearts given to players jumping on the monument"),
|
||||
NOCREATURES (Boolean.class, "No Mobs", "If true, prevent mob spawning"),
|
||||
NODROPS (Boolean.class, "No Drops", "If true, prevent players from dropping items"),
|
||||
PVPINZONE (Boolean.class, "PVP", "If true, PVP is enabled\nUseful for Spleef gamemodes"),
|
||||
REALDEATHS (Boolean.class, "Real Deaths", "If true, send players to the real Minecraft death screen"),
|
||||
RESETONEMPTY (Boolean.class, "Reset on Empty", "If true, reset the zone when all players leave"),
|
||||
RESETONCONFIGCHANGE (Boolean.class, "Reset on Config Change", "If true, reset every time the zone config is modified"),
|
||||
RESETONLOAD (Boolean.class, "Reset on Load", "If true, reset warzone when the server starts"),
|
||||
RESETONUNLOAD (Boolean.class, "Reset on Unload", "If true, reset warzone when the server stops"),
|
||||
UNBREAKABLE (Boolean.class, "Unbreakable Blocks", "If true, prevent block breaking"),
|
||||
JOINMIDBATTLE (Boolean.class, "Join Mid-Battle", "If true, players are allowed to join during a battle"),
|
||||
AUTOJOIN (Boolean.class, "Auto-Join", "If true, bypass the zone lobby and auto-assign the player a team"),
|
||||
SCOREBOARD (ScoreboardType.class, "Scoreboard Type", "Type of scoreboard for this zone\nOptions: none, points, lifepool, top kills"),
|
||||
SOUPHEALING (Boolean.class, "Soup Healing", "If true, allow players to heal by consuming soup"),
|
||||
ALLOWENDER (Boolean.class, "Allow Ender Chests", "If true, ender chests are allowed\nEnder chests are usually blocked to prevent item duplication"),
|
||||
RESETBLOCKS (Boolean.class, "Reset Blocks", "If true, reset warzone blocks each battle"),
|
||||
CAPTUREPOINTTIME (Integer.class, "Capture Control Time", "Time, in seconds, required to gain control of a capture point"),
|
||||
PREPTIME(Integer.class, "Preparation Time", "Time, in seconds, before players are allowed to fight");
|
||||
|
||||
|
||||
private final Class<?> configType;
|
||||
private final String title;
|
||||
private final String description;
|
||||
|
||||
WarzoneConfig(Class<?> configType, String title, String description) {
|
||||
this.configType = configType;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Class<?> getConfigType() {
|
||||
return configType;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static WarzoneConfig warzoneConfigFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (WarzoneConfig config : WarzoneConfig.values()) {
|
||||
if (config.toString().startsWith(lowered)) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toStringWithValue(Object value) {
|
||||
return this.toString() + ":" + value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class WarzoneConfigBag {
|
||||
|
||||
private final Warzone warzone;
|
||||
EnumMap<WarzoneConfig, Object> bag = new EnumMap<WarzoneConfig, Object>(WarzoneConfig.class);
|
||||
|
||||
public WarzoneConfigBag(Warzone warzone) {
|
||||
this.warzone = warzone;
|
||||
}
|
||||
|
||||
public WarzoneConfigBag() {
|
||||
// default zone settings (at War level) don't have a warzone
|
||||
this.warzone = null;
|
||||
}
|
||||
|
||||
public static void afterUpdate(Warzone zone, CommandSender sender, String namedParamReturn, boolean wantsToPrint) {
|
||||
WarzoneYmlMapper.save(zone);
|
||||
|
||||
String zoneReset = "Some changes may require a /resetzone. ";
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
|
||||
zone.reinitialize(); // bring back team spawns etc
|
||||
zoneReset = "Zone reset. ";
|
||||
}
|
||||
|
||||
if (wantsToPrint) {
|
||||
War.war.msg(sender, "Warzone config saved. " + zoneReset + namedParamReturn + " " + War.war.printConfig(zone));
|
||||
} else {
|
||||
War.war.msg(sender, "Warzone config saved. " + zoneReset + namedParamReturn);
|
||||
}
|
||||
|
||||
War.war.log(sender.getName() + " updated warzone " + zone.getName() + " configuration." + namedParamReturn, Level.INFO);
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public void put(WarzoneConfig config, Object value) {
|
||||
bag.put(config, value);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return bag.keySet().size() == 0;
|
||||
}
|
||||
|
||||
public Object getValue(WarzoneConfig config) {
|
||||
if (bag.containsKey(config)) {
|
||||
return bag.get(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getWarzoneDefaultConfig().getValue(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getInt(WarzoneConfig config) {
|
||||
if (bag.containsKey(config)) {
|
||||
return (Integer) bag.get(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getWarzoneDefaultConfig().getInt(config);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean getBoolean(WarzoneConfig config) {
|
||||
if (bag.containsKey(config)) {
|
||||
return (Boolean) bag.get(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getWarzoneDefaultConfig().getBoolean(config);
|
||||
}
|
||||
}
|
||||
|
||||
public ScoreboardType getScoreboardType(WarzoneConfig config) {
|
||||
if (bag.containsKey(config)) {
|
||||
return (ScoreboardType)bag.get(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getWarzoneDefaultConfig().getScoreboardType(config);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(WarzoneConfig config) {
|
||||
return this.bag.containsKey(config);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.bag.clear();
|
||||
}
|
||||
|
||||
public void loadFrom(ConfigurationSection warzoneConfigSection) {
|
||||
for (WarzoneConfig config : WarzoneConfig.values()) {
|
||||
if (warzoneConfigSection.contains(config.toString())) {
|
||||
if (config.getConfigType().equals(Integer.class)) {
|
||||
this.put(config, warzoneConfigSection.getInt(config.toString()));
|
||||
} else if (config.getConfigType().equals(Boolean.class)) {
|
||||
this.put(config, warzoneConfigSection.getBoolean(config.toString()));
|
||||
} else if (config.getConfigType().equals(ScoreboardType.class)) {
|
||||
this.put(config, ScoreboardType.getFromString(warzoneConfigSection.getString(config.toString())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveTo(ConfigurationSection warzoneConfigSection) {
|
||||
for (WarzoneConfig config : WarzoneConfig.values()) {
|
||||
if (this.bag.containsKey(config)) {
|
||||
if (config.getConfigType().equals(Integer.class)
|
||||
|| config.getConfigType().equals(Boolean.class)) {
|
||||
warzoneConfigSection.set(config.toString(), this.bag.get(config));
|
||||
} else {
|
||||
warzoneConfigSection.set(config.toString(), this.bag.get(config).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String updateFromNamedParams(Map<String, String> namedParams) {
|
||||
String returnMessage = "";
|
||||
for (String namedParam : namedParams.keySet()) {
|
||||
WarzoneConfig warzoneConfig = WarzoneConfig.warzoneConfigFromString(namedParam);
|
||||
|
||||
// param update
|
||||
if (warzoneConfig != null) {
|
||||
if (warzoneConfig.getConfigType().equals(Integer.class)) {
|
||||
int intValue = Integer.parseInt(namedParams.get(namedParam));
|
||||
this.bag.put(warzoneConfig, intValue);
|
||||
} else if (warzoneConfig.getConfigType().equals(Boolean.class)) {
|
||||
String onOff = namedParams.get(namedParam);
|
||||
this.bag.put(warzoneConfig, onOff.equals("on") || onOff.equals("true"));
|
||||
if (this.warzone != null && namedParam.equals(WarzoneConfig.AUTOASSIGN.toString())) {
|
||||
this.warzone.getLobby().setLocation(this.warzone.getTeleport());
|
||||
this.warzone.getLobby().initialize();
|
||||
}
|
||||
} else if (warzoneConfig.getConfigType().equals(ScoreboardType.class)) {
|
||||
String type = namedParams.get(namedParam);
|
||||
this.bag.put(warzoneConfig, ScoreboardType.getFromString(type));
|
||||
}
|
||||
returnMessage += " " + warzoneConfig.toString() + " set to " + namedParams.get(namedParam);
|
||||
} else if (namedParam.equals("delete")) {
|
||||
String toDelete = namedParams.get(namedParam);
|
||||
warzoneConfig = WarzoneConfig.warzoneConfigFromString(toDelete);
|
||||
|
||||
// param delete (to restore inheritance)
|
||||
if (warzoneConfig != null) {
|
||||
this.bag.remove(warzoneConfig);
|
||||
returnMessage += " " + warzoneConfig.toString() + " removed";
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnMessage;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class WarBattleWinEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private List<Team> winningTeams;
|
||||
private Warzone zone;
|
||||
|
||||
public WarBattleWinEvent(Warzone zone, List<Team> winningTeams) {
|
||||
this.zone = zone;
|
||||
this.winningTeams = winningTeams;
|
||||
}
|
||||
|
||||
public Warzone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public List<Team> getWinningTeams() {
|
||||
return winningTeams;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,407 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
import com.tommytony.war.structure.Cake;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
import com.tommytony.war.utility.Compat;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class WarBlockListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player == null || block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
// Monument capturing
|
||||
if (team != null && zone != null && zone.isMonumentCenterBlock(block) && team.getKind().isTeamBlock(block.getState())) {
|
||||
Monument monument = zone.getMonumentFromCenterBlock(block);
|
||||
if (monument != null && !monument.hasOwner()) {
|
||||
monument.capture(team);
|
||||
zone.broadcast("zone.monument.capture", monument.getName(), team.getName());
|
||||
event.setCancelled(false);
|
||||
return; // important otherwise cancelled down a few line by isImportantblock
|
||||
} else {
|
||||
War.war.badMsg(player, "zone.monument.badblock");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
// prevent build in important parts
|
||||
if (zone != null && (zone.isImportantBlock(block) || zone.isOpponentSpawnPeripheryBlock(team, block)) && (!isZoneMaker || team != null)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
for (Warzone wz : War.war.getWarzones()) {
|
||||
if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// protect the hub
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
if (zone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) {
|
||||
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) {
|
||||
War.war.badMsg(player, "build.denied.outside");
|
||||
}
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// can't place a block of your team's color
|
||||
if (team != null && block.getType() == team.getKind().getMaterial()) {
|
||||
War.war.badMsg(player, "build.denied.teamblock");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// a flag thief can't drop his flag
|
||||
if (team != null && zone != null && zone.isFlagThief(player)) {
|
||||
War.war.badMsg(player, "drop.flag.disabled");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// a bomb thief can't drop his bomb
|
||||
if (team != null && zone != null && zone.isBombThief(player)) {
|
||||
War.war.badMsg(player, "drop.bomb.disabled");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// a cake thief can't drop his cake
|
||||
if (team != null && zone != null && zone.isCakeThief(player)) {
|
||||
War.war.badMsg(player, "drop.cake.disabled");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// unbreakableZoneBlocks
|
||||
if (zone != null && (zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) || team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK)) && (!isZoneMaker || team != null)) {
|
||||
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks)
|
||||
War.war.badMsg(player, "build.denied.zone.place");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
if (team != null && !team.canModify(block.getType())) {
|
||||
War.war.badMsg(player, "build.denied.zone.type");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelAndKeepItem(BlockPlaceEvent event) {
|
||||
event.setCancelled(true);
|
||||
ItemStack inHand = event.getItemInHand();
|
||||
ItemStack newItemInHand;
|
||||
|
||||
if (inHand.getType() == Material.FIRE) {
|
||||
// Weird bukkit/mc behavior where item in hand is reported as fire while using flint & steel.
|
||||
// Just give the user his f&s back but almost broken (max durability is 8).
|
||||
newItemInHand = Compat.createDamagedIS(Material.FLINT_AND_STEEL, 1, 1);
|
||||
} else {
|
||||
newItemInHand = inHand.clone();
|
||||
}
|
||||
if (event.getHand() == EquipmentSlot.OFF_HAND) {
|
||||
event.getPlayer().getInventory().setItemInOffHand(newItemInHand);
|
||||
} else {
|
||||
event.getPlayer().getInventory().setItemInMainHand(newItemInHand);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
// Do not allow moving of block into or from important zones
|
||||
public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
if (zone != null) {
|
||||
for (Block b : event.getBlocks()) {
|
||||
if (zone.isImportantBlock(b)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//noinspection deprecation
|
||||
if (zone.isImportantBlock(event.getBlock().getRelative(event.getDirection(), event.getLength()+1))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPistonRetract(final BlockPistonRetractEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
if (zone!=null) {
|
||||
Block b = event.getBlock().getRelative(event.getDirection(), 2);
|
||||
if (zone.isImportantBlock(b)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(final BlockBreakEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player != null && block != null) {
|
||||
this.handleBreakOrDamage(player, block, event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockDamage(final BlockDamageEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
Warzone playerZone = Warzone.getZoneByLocation(player);
|
||||
if (player != null && block != null && playerZone != null && playerZone.getWarzoneConfig().getBoolean(WarzoneConfig.INSTABREAK)) {
|
||||
Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
|
||||
if (blockZone != null && blockZone == playerZone && block.getType() != Material.BEDROCK) {
|
||||
event.setInstaBreak(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBurn(final BlockBurnEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
if (zone != null && zone.isImportantBlock(event.getBlock())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
|
||||
if (warzone != null && team == null && !isZoneMaker) {
|
||||
// can't actually destroy blocks in a warzone if not part of a team
|
||||
War.war.badMsg(player, "build.denied.zone.outside");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// monument's center is destroyed
|
||||
if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
|
||||
Monument monument = warzone.getMonumentFromCenterBlock(block);
|
||||
if (monument.hasOwner()) {
|
||||
Team ownerTeam = monument.getOwnerTeam();
|
||||
warzone.broadcast("zone.monument.lose", ownerTeam.getName(), monument.getName());
|
||||
monument.uncapture();
|
||||
}
|
||||
event.setCancelled(false);
|
||||
return;
|
||||
}
|
||||
// changes in parts of important areas
|
||||
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || team != null)) {
|
||||
// breakage of spawn
|
||||
if (team.isSpawnLocation(block.getLocation())) {
|
||||
// let team members loot one block the spawn for monument captures
|
||||
if (player.getInventory().containsAtLeast(team.getKind().getBlockHead(), 1)) {
|
||||
War.war.badMsg(player, "build.denied.zone.multteam", team.getName());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down
|
||||
return;
|
||||
}
|
||||
}
|
||||
// stealing of flag
|
||||
if (warzone.isEnemyTeamFlagBlock(team, block)) {
|
||||
if (warzone.isFlagThief(player)) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "zone.stealextra.flag");
|
||||
} else if (warzone.isBombThief(player) || warzone.isCakeThief(player)) {
|
||||
War.war.badMsg(player, "zone.stealextra.other");
|
||||
} else {
|
||||
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
|
||||
if (lostFlagTeam.getPlayers().size() != 0) {
|
||||
// player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack teamKindBlock = lostFlagTeam.getKind().getBlockHead();
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(teamKindBlock);
|
||||
warzone.addFlagThief(lostFlagTeam, player);
|
||||
block.setType(Material.AIR);
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast("zone.steal.flag.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, lostFlagTeam.getName());
|
||||
if (t.getName().equals(lostFlagTeam.getName())) {
|
||||
t.teamcast("zone.steal.flag.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE, team.getName());
|
||||
}
|
||||
}
|
||||
War.war.msg(player, "zone.steal.flag.notice", lostFlagTeam.getName());
|
||||
} else {
|
||||
War.war.msg(player, "zone.steal.flag.empty", lostFlagTeam.getName());
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (warzone.isBombBlock(block)) {
|
||||
if (warzone.isBombThief(player)) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "zone.stealextra.bomb");
|
||||
} else if (warzone.isFlagThief(player) || warzone.isCakeThief(player)) {
|
||||
War.war.badMsg(player, "zone.stealextra.other");
|
||||
} else {
|
||||
Bomb bomb = warzone.getBombForBlock(block);
|
||||
// player just broke the bomb block: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack tntBlock = new ItemStack(Material.TNT);
|
||||
tntBlock.setDurability((short)8);
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(tntBlock);
|
||||
warzone.addBombThief(bomb, player);
|
||||
block.setType(Material.AIR);
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast("zone.steal.bomb.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + bomb.getName() + ChatColor.WHITE);
|
||||
t.teamcast("zone.steal.bomb.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
|
||||
}
|
||||
War.war.msg(player, "zone.steal.bomb.notice", bomb.getName());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (warzone.isCakeBlock(block)) {
|
||||
if (warzone.isCakeThief(player)) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "zone.stealextra.cake");
|
||||
} else if (warzone.isFlagThief(player) || warzone.isBombThief(player)) {
|
||||
War.war.badMsg(player, "zone.stealextra.other");
|
||||
} else {
|
||||
Cake cake = warzone.getCakeForBlock(block);
|
||||
// player just broke the cake block: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack cakeBlock = new ItemStack(Material.CAKE);
|
||||
cakeBlock.setDurability((short)8);
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(cakeBlock);
|
||||
warzone.addCakeThief(cake, player);
|
||||
block.setType(Material.AIR);
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast("zone.steal.cake.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + cake.getName() + ChatColor.WHITE);
|
||||
t.teamcast("zone.steal.cake.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
|
||||
}
|
||||
War.war.msg(player, "zone.steal.cake.notice", cake.getName());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (!warzone.isMonumentCenterBlock(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
if (block != null) {
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protect the hub
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "build.denied.location");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
|
||||
if (blockZone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) {
|
||||
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) {
|
||||
War.war.badMsg(player, "build.denied.outside");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// unbreakableZoneBlocks
|
||||
if (blockZone != null && blockZone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks
|
||||
War.war.badMsg(player, "build.denied.zone.break");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (team != null && !team.canModify(block.getType())) {
|
||||
War.war.badMsg(player, "build.denied.zone.type");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onStructureGrowth(final StructureGrowEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getLocation());
|
||||
if (zone != null) {
|
||||
List<BlockState> canceledBlocks = new ArrayList<BlockState>();
|
||||
for (BlockState state : event.getBlocks()) {
|
||||
if (!zone.getVolume().contains(state.getLocation())
|
||||
|| zone.isImportantBlock(state.getBlock())) {
|
||||
canceledBlocks.add(state);
|
||||
}
|
||||
}
|
||||
for (BlockState state : canceledBlocks) {
|
||||
event.getBlocks().remove(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,551 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.job.DeferredBlockResetsJob;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
import com.tommytony.war.utility.LoadoutSelection;
|
||||
|
||||
/**
|
||||
* Handles Entity-Events
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package com.tommytony.war.event
|
||||
*/
|
||||
public class WarEntityListener implements Listener {
|
||||
|
||||
/**
|
||||
* Handles PVP-Damage
|
||||
*
|
||||
* @param event
|
||||
* fired event
|
||||
*/
|
||||
private void handlerAttackDefend(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
Entity defender = event.getEntity();
|
||||
|
||||
// Maybe an arrow was thrown
|
||||
if (attacker != null && event.getDamager() instanceof Projectile && ((Projectile)event.getDamager()).getShooter() instanceof Player){
|
||||
attacker = ((Player)((Projectile)event.getDamager()).getShooter());
|
||||
}
|
||||
|
||||
if (attacker != null && defender != null && attacker instanceof Player && defender instanceof Player) {
|
||||
// only let adversaries (same warzone, different team) attack each other
|
||||
Player a = (Player) attacker;
|
||||
Player d = (Player) defender;
|
||||
Warzone attackerWarzone = Warzone.getZoneByPlayerName(a.getName());
|
||||
Team attackerTeam = Team.getTeamByPlayerName(a.getName());
|
||||
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
|
||||
Team defenderTeam = Team.getTeamByPlayerName(d.getName());
|
||||
|
||||
if ((attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone)
|
||||
|| (attackerTeam != null && defenderTeam != null && attacker.getEntityId() == defender.getEntityId())) {
|
||||
|
||||
LoadoutSelection defenderLoadoutState = defenderWarzone.getLoadoutSelections().get(d.getName());
|
||||
if (defenderLoadoutState != null && defenderLoadoutState.isStillInSpawn()) {
|
||||
War.war.badMsg(a, "pvp.target.spawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
LoadoutSelection attackerLoadoutState = attackerWarzone.getLoadoutSelections().get(a.getName());
|
||||
if (attackerLoadoutState != null && attackerLoadoutState.isStillInSpawn()) {
|
||||
War.war.badMsg(a, "pvp.self.spawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure none of them are locked in by respawn timer
|
||||
if (defenderWarzone.isRespawning(d)) {
|
||||
War.war.badMsg(a, "pvp.target.respawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (attackerWarzone.isRespawning(a)) {
|
||||
War.war.badMsg(a, "pvp.self.respawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!defenderWarzone.getPvpReady()) {
|
||||
//if the timer is still tickin we gotta handle defense! (there be notchz in virgina)
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.PVPINZONE)) {
|
||||
// spleef-like, non-pvp, zone
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect death, prevent it and respawn the player
|
||||
if (event.getDamage() >= d.getHealth()) {
|
||||
if (defenderWarzone.getReallyDeadFighters().contains(d.getName())) {
|
||||
// don't re-kill a dead person
|
||||
return;
|
||||
}
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, a, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// fast respawn, don't really die
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (d == a) {
|
||||
defenderWarzone.handleSuicide(d);
|
||||
} else {
|
||||
defenderWarzone.handleKill(a, d, event.getDamager());
|
||||
}
|
||||
} else if (defenderWarzone.isBombThief(d) && d.getLocation().distance(a.getLocation()) < 2) {
|
||||
// Close combat, close enough to detonate
|
||||
Bomb bomb = defenderWarzone.getBombForThief(d);
|
||||
|
||||
// Kill the bomber
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, null, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
defenderWarzone.handleDeath(d);
|
||||
|
||||
if (defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// and respawn him and remove from deadmen (cause realdeath + handleDeath means no respawn and getting queued up for onPlayerRespawn)
|
||||
defenderWarzone.getReallyDeadFighters().remove(d.getName());
|
||||
defenderWarzone.respawnPlayer(defenderTeam, d);
|
||||
}
|
||||
|
||||
// Blow up bomb
|
||||
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) {
|
||||
defenderWarzone.getWorld().createExplosion(a.getLocation(), 2F);
|
||||
}
|
||||
|
||||
// bring back tnt
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.addBombBlocks();
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : defenderWarzone.getTeams()) {
|
||||
t.sendAchievement(attackerTeam.getKind().getColor() + a.getName() + ChatColor.YELLOW + " made ",
|
||||
defenderTeam.getKind().getColor() + d.getName() + ChatColor.YELLOW + " blow up!", new ItemStack(Material.TNT), 10000);
|
||||
t.teamcast("pvp.kill.bomb", attackerTeam.getKind().getColor() + a.getName() + ChatColor.WHITE,
|
||||
defenderTeam.getKind().getColor() + d.getName() + ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
} else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) {
|
||||
// same team, but not same person
|
||||
if (attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.FRIENDLYFIRE)) {
|
||||
War.war.badMsg(a, "pvp.ff.enabled"); // if ff is on, let the attack go through
|
||||
} else {
|
||||
War.war.badMsg(a, "pvp.ff.disabled");
|
||||
event.setCancelled(true); // ff is off
|
||||
}
|
||||
} else if (attackerTeam == null && defenderTeam == null && War.war.canPvpOutsideZones(a)) {
|
||||
// let normal PVP through is its not turned off or if you have perms
|
||||
} else if (attackerTeam == null && defenderTeam == null && !War.war.canPvpOutsideZones(a)) {
|
||||
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE)) {
|
||||
War.war.badMsg(a, "pvp.outside.permission");
|
||||
}
|
||||
|
||||
event.setCancelled(true); // global pvp is off
|
||||
} else {
|
||||
if (attackerTeam == null) {
|
||||
War.war.badMsg(a, "pvp.self.notplaying");
|
||||
} else if (defenderTeam == null) {
|
||||
War.war.badMsg(a, "pvp.target.notplaying");
|
||||
} else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) {
|
||||
// You just hit yourself, probably with a bouncing arrow
|
||||
} else if (attackerTeam == defenderTeam) {
|
||||
War.war.badMsg(a, "pvp.ff.disabled");
|
||||
} else if (attackerWarzone != defenderWarzone) {
|
||||
War.war.badMsg(a, "pvp.target.otherzone");
|
||||
}
|
||||
|
||||
event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team
|
||||
}
|
||||
} else if (defender instanceof Player) {
|
||||
// attacked by dispenser arrow most probably
|
||||
// Detect death, prevent it and respawn the player
|
||||
Player d = (Player) defender;
|
||||
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
|
||||
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
|
||||
LoadoutSelection defenderLoadoutState = defenderWarzone.getLoadoutSelections().get(d.getName());
|
||||
if (defenderLoadoutState != null && defenderLoadoutState.isStillInSpawn()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (defenderWarzone.getReallyDeadFighters().contains(d.getName())) {
|
||||
// don't re-kill a dead person
|
||||
return;
|
||||
}
|
||||
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, null, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// fast respawn, don't really die
|
||||
event.setCancelled(true);
|
||||
}
|
||||
defenderWarzone.handleNaturalKill(d, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protects important structures from explosions
|
||||
*
|
||||
* @see EntityListener.onEntityExplode()
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEntityExplode(final EntityExplodeEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
// protect zones elements, lobbies and warhub from creepers and tnt
|
||||
List<Block> explodedBlocks = event.blockList();
|
||||
List<Block> dontExplode = new ArrayList<Block>();
|
||||
|
||||
boolean explosionInAWarzone = event.getEntity() != null && Warzone.getZoneByLocation(event.getEntity().getLocation()) != null;
|
||||
|
||||
if (!explosionInAWarzone && War.war.getWarConfig().getBoolean(WarConfig.TNTINZONESONLY) && event.getEntity() instanceof TNTPrimed) {
|
||||
// if tntinzonesonly:true, no tnt blows up outside zones
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Block block : explodedBlocks) {
|
||||
if (block.getType() == Material.TNT) {
|
||||
continue; // don't restore TNT (failed to track down regression cause)
|
||||
}
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
dontExplode.add(block);
|
||||
} else {
|
||||
boolean inOneZone = false;
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.isImportantBlock(block)) {
|
||||
dontExplode.add(block);
|
||||
if (zone.isBombBlock(block)) {
|
||||
// tnt doesn't get reset like normal blocks, gotta schedule a later reset just for the Bomb
|
||||
// structure's tnt block
|
||||
DeferredBlockResetsJob job = new DeferredBlockResetsJob();
|
||||
BlockState tnt = block.getState();
|
||||
tnt.setType(Material.TNT);
|
||||
job.add(tnt);
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, 10);
|
||||
}
|
||||
inOneZone = true;
|
||||
break;
|
||||
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
|
||||
dontExplode.add(block);
|
||||
inOneZone = true;
|
||||
break;
|
||||
} else if (zone.getVolume().contains(block)) {
|
||||
inOneZone = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inOneZone && explosionInAWarzone) {
|
||||
// if the explosion originated in warzone, always rollback
|
||||
dontExplode.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int dontExplodeSize = dontExplode.size();
|
||||
if (dontExplode.size() > 0) {
|
||||
// Reset the exploded blocks that shouldn't have exploded (some of these are zone artifacts, if rollbackexplosion some may be outside-of-zone blocks
|
||||
DeferredBlockResetsJob job = new DeferredBlockResetsJob();
|
||||
for (Block dont : dontExplode) {
|
||||
job.add(dont.getState());
|
||||
}
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
|
||||
|
||||
// Changed explosion yield following proportion of explosion prevention (makes drops less buggy too)
|
||||
int explodedSize = explodedBlocks.size();
|
||||
float middleYeild = (float)(explodedSize - dontExplodeSize) / (float)explodedSize;
|
||||
float newYeild = middleYeild * event.getYield();
|
||||
|
||||
event.setYield(newYeild);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles damage on Players
|
||||
*
|
||||
* @see EntityListener.onEntityDamage()
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityDamage(final EntityDamageEvent event) {
|
||||
|
||||
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
|
||||
return;
|
||||
}
|
||||
Player player = (Player) entity;
|
||||
|
||||
// prevent godmode
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
// pass pvp-damage
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
this.handlerAttackDefend((EntityDamageByEntityEvent) event);
|
||||
} else {
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
|
||||
if (zone != null && team != null) {
|
||||
LoadoutSelection playerLoadoutState = zone.getLoadoutSelections().get(player.getName());
|
||||
if (team.isSpawnLocation(player.getLocation())
|
||||
&& playerLoadoutState != null && playerLoadoutState.isStillInSpawn()) {
|
||||
// don't let a player still in spawn get damaged
|
||||
event.setCancelled(true);
|
||||
} else if (event.getDamage() >= player.getHealth()) {
|
||||
if (zone.getReallyDeadFighters().contains(player.getName())) {
|
||||
// don't re-count the death points of an already dead person
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect death, prevent it and respawn the player
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(zone, player, null, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// fast respawn, don't really die
|
||||
event.setCancelled(true);
|
||||
}
|
||||
zone.handleNaturalKill(player, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents creatures from spawning in warzones if no creatures is active
|
||||
*
|
||||
* @see EntityListener.onCreatureSpawn()
|
||||
*/
|
||||
@EventHandler
|
||||
public void onCreatureSpawn(final CreatureSpawnEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = event.getLocation();
|
||||
Warzone zone = Warzone.getZoneByLocation(location);
|
||||
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.NOCREATURES)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents health regaining caused by peaceful mode
|
||||
*
|
||||
* @see EntityListener.onEntityRegainHealth()
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEntityRegainHealth(final EntityRegainHealthEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) entity;
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (event.getRegainReason() == RegainReason.SATIATED
|
||||
&& team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)) {
|
||||
// noHunger setting means you can't auto-heal with full hunger bar (use saturation instead to control how fast you get hungry)
|
||||
event.setCancelled(true);
|
||||
} else if (event.getRegainReason() == RegainReason.REGEN) {
|
||||
// disable peaceful mode regen
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(final FoodLevelChangeEvent event) {
|
||||
if (!War.war.isLoaded() || !(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (zone != null && team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)){
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerDeath(final PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
event.getDrops().clear();
|
||||
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// catch the odd death that gets away from us when usually intercepting and preventing deaths
|
||||
zone.handleDeath(player);
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DEATHMESSAGES)) {
|
||||
zone.broadcast("pvp.death.other", team.getKind().getColor() + player.getName());
|
||||
}
|
||||
War.war.getLogger().log(Level.WARNING, "We missed the death of player {0} - something went wrong.", player.getName());
|
||||
} else {
|
||||
event.setDeathMessage("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExplosionPrime(final ExplosionPrimeEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location eventLocation = event.getEntity().getLocation();
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.isBombBlock(eventLocation.getBlock())) {
|
||||
// prevent the Bomb from exploding on its pedestral
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProjectileHit(final ProjectileHitEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntityType() == EntityType.EGG) {
|
||||
if (event.getEntity().hasMetadata("warAirstrike")) {
|
||||
Location loc = event.getEntity().getLocation();
|
||||
Warzone zone = Warzone.getZoneByLocation(loc);
|
||||
if (zone == null) {
|
||||
return;
|
||||
}
|
||||
Location tntPlace = new Location(loc.getWorld(), loc.getX(), Warzone.getZoneByLocation(loc).getVolume().getMaxY(), loc.getZ());
|
||||
loc.getWorld().spawnEntity(tntPlace, EntityType.PRIMED_TNT);
|
||||
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(2, 0, 0)), EntityType.PRIMED_TNT);
|
||||
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(-2, 0, 0)), EntityType.PRIMED_TNT);
|
||||
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(0, 0, 2)), EntityType.PRIMED_TNT);
|
||||
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(0, 0, -2)), EntityType.PRIMED_TNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProjectileLaunch(final ProjectileLaunchEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntityType() == EntityType.EGG) {
|
||||
ProjectileSource shooter = event.getEntity().getShooter();
|
||||
if (shooter instanceof Player) {
|
||||
Player player = (Player) shooter;
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
if (War.war.getKillstreakReward().getAirstrikePlayers().remove(player.getName())) {
|
||||
event.getEntity().setMetadata("warAirstrike", new FixedMetadataValue(War.war, true));
|
||||
zone.broadcast("zone.airstrike", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPaintingBreakByEntity(final HangingBreakByEntityEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getRemover() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getRemover();
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getEntity().getLocation());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
if (team == null && isZoneMaker) {
|
||||
return;
|
||||
}
|
||||
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "build.denied.zone.break");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPaintingPlaceByEntity(final HangingPlaceEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
if (team == null && isZoneMaker) {
|
||||
return;
|
||||
}
|
||||
if (zone != null && (zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)
|
||||
|| (team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK)))) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "build.denied.zone.place");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityTeleport(final EntityTeleportEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntityType() == EntityType.WOLF) {
|
||||
if (Warzone.getZoneByLocation(event.getTo()) != null) {
|
||||
// prevent wolves from teleporting to players in zones
|
||||
event.setCancelled(true);
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class WarPlayerDeathEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Player victim;
|
||||
private Warzone zone;
|
||||
private Entity killer;
|
||||
private DamageCause cause;
|
||||
|
||||
public WarPlayerDeathEvent(Warzone zone, Player victim, Entity killer,
|
||||
DamageCause cause) {
|
||||
this.zone = zone;
|
||||
this.victim = victim;
|
||||
this.killer = killer;
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public Warzone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public Entity getKiller() {
|
||||
return killer;
|
||||
}
|
||||
|
||||
public DamageCause getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
public Player getVictim() {
|
||||
return victim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class WarPlayerLeaveEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String player;
|
||||
|
||||
public WarPlayerLeaveEvent(String player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public String getQuitter() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,949 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.Warzone.LeaveCause;
|
||||
import com.tommytony.war.command.ZoneSetter;
|
||||
import com.tommytony.war.config.FlagReturn;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.structure.Bomb;
|
||||
import com.tommytony.war.structure.Cake;
|
||||
import com.tommytony.war.structure.WarHub;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.utility.Direction;
|
||||
import com.tommytony.war.utility.Loadout;
|
||||
import com.tommytony.war.utility.LoadoutSelection;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* @author tommytony, Tim Düsterhus
|
||||
*/
|
||||
public class WarPlayerListener implements Listener {
|
||||
private java.util.Random random = new java.util.Random();
|
||||
private HashMap<String, Location> latestLocations = new HashMap<String, Location>();
|
||||
|
||||
/**
|
||||
* Correctly removes quitting players from warzones
|
||||
*
|
||||
* @see PlayerQuitEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
zone.handlePlayerLeave(player, zone.getEndTeleport(LeaveCause.DISCONNECT), true);
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
War.war.removeWandBearer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
String autojoinName = War.war.getWarConfig().getString(WarConfig.AUTOJOIN);
|
||||
boolean autojoinEnabled = !autojoinName.isEmpty();
|
||||
if (autojoinEnabled) { // Won't be able to find warzone if unset
|
||||
Warzone autojoinWarzone = Warzone.getZoneByNameExact(autojoinName);
|
||||
if (autojoinWarzone == null) {
|
||||
War.war.getLogger().log(Level.WARNING, "Failed to find autojoin warzone ''{0}''.", new Object[] {autojoinName});
|
||||
return;
|
||||
}
|
||||
if (autojoinWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) || autojoinWarzone.isReinitializing()) {
|
||||
War.war.badMsg(event.getPlayer(), "join.disabled");
|
||||
event.getPlayer().teleport(autojoinWarzone.getTeleport());
|
||||
} else if (!autojoinWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && autojoinWarzone.isEnoughPlayers()) {
|
||||
War.war.badMsg(event.getPlayer(), "join.progress");
|
||||
event.getPlayer().teleport(autojoinWarzone.getTeleport());
|
||||
} else if (autojoinWarzone.isFull()) {
|
||||
War.war.badMsg(event.getPlayer(), "join.full.all");
|
||||
event.getPlayer().teleport(autojoinWarzone.getTeleport());
|
||||
} else if (autojoinWarzone.isFull(event.getPlayer())) {
|
||||
War.war.badMsg(event.getPlayer(), "join.permission.all");
|
||||
event.getPlayer().teleport(autojoinWarzone.getTeleport());
|
||||
} else { // Player will only ever be autoassigned to a team
|
||||
autojoinWarzone.autoAssign(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(final PlayerDropItemEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null) {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
|
||||
if (zone.isFlagThief(player)) {
|
||||
// a flag thief can't drop his flag
|
||||
War.war.badMsg(player, "drop.flag.disabled");
|
||||
event.setCancelled(true);
|
||||
} else if (zone.isBombThief(player)) {
|
||||
// a bomb thief can't drop his bomb
|
||||
War.war.badMsg(player, "drop.bomb.disabled");
|
||||
event.setCancelled(true);
|
||||
} else if (zone.isCakeThief(player)) {
|
||||
// a cake thief can't drop his cake
|
||||
War.war.badMsg(player, "drop.cake.disabled");
|
||||
event.setCancelled(true);
|
||||
} else if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.NODROPS)) {
|
||||
War.war.badMsg(player, "drop.item.disabled");
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
Item item = event.getItemDrop();
|
||||
if (item != null) {
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
if (itemStack != null && team.getKind().isTeamItem(itemStack)) {
|
||||
// Can't drop your team's kind block
|
||||
War.war.badMsg(player, "drop.team", team.getName());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone.isNearWall(player.getLocation()) && itemStack != null
|
||||
&& !team.getTeamConfig().resolveBoolean(TeamConfig.BORDERDROP)) {
|
||||
War.war.badMsg(player, "drop.item.border");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone.getLoadoutSelections().keySet().contains(player.getName())
|
||||
&& zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
// still at spawn
|
||||
War.war.badMsg(player, "drop.item.spawn");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
Item item = event.getItemDrop();
|
||||
if (item.getItemStack().getType() == Material.WOODEN_SWORD) {
|
||||
String zoneName = War.war.getWandBearerZone(player);
|
||||
War.war.removeWandBearer(player);
|
||||
War.war.msg(player, "drop.wand", zoneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final int MINIMUM_TEAM_BLOCKS = 1;
|
||||
@EventHandler
|
||||
public void onPlayerPickupItem(final EntityPickupItemEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getEntity();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null) {
|
||||
Warzone zone = team.getZone();
|
||||
|
||||
if (zone.isFlagThief(player)) {
|
||||
// a flag thief can't pick up anything
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
Item item = event.getItem();
|
||||
if (item != null) {
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
if (itemStack != null && team.getKind().isTeamItem(itemStack) &&
|
||||
player.getInventory().containsAtLeast(team.getKind().getBlockHead(), MINIMUM_TEAM_BLOCKS)) {
|
||||
// Can't pick up a second precious block
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team talkingPlayerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (talkingPlayerTeam != null) {
|
||||
String msg = event.getMessage();
|
||||
String[] split = msg.split(" ");
|
||||
if (!War.war.isWarAdmin(player) && split.length > 0 && split[0].startsWith("/")) {
|
||||
String command = split[0].substring(1);
|
||||
if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) {
|
||||
// allow white commands
|
||||
for (String whiteCommand : War.war.getCommandWhitelist()) {
|
||||
if (whiteCommand.equals(command)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
War.war.badMsg(player, "command.disabled");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKick(final PlayerKickEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (warzone != null) {
|
||||
// kick player from warzone as well
|
||||
warzone.handlePlayerLeave(player, warzone.getEndTeleport(LeaveCause.DISCONNECT), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.getItem() != null && event.getItem().getType() == Material.WOODEN_SWORD && War.war.isWandBearer(player)) {
|
||||
String zoneName = War.war.getWandBearerZone(player);
|
||||
ZoneSetter setter = new ZoneSetter(player, zoneName);
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
War.war.badMsg(player, "wand.toofar");
|
||||
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
setter.placeCorner1(event.getClickedBlock());
|
||||
event.setUseItemInHand(Result.ALLOW);
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
setter.placeCorner2(event.getClickedBlock());
|
||||
event.setUseItemInHand(Result.ALLOW);
|
||||
}
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null && zone.getLoadoutSelections().containsKey(player.getName())
|
||||
&& zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
// Replace message with sound to reduce spamminess.
|
||||
// Whenever a player dies in the middle of conflict they will
|
||||
// likely respawn still trying to use their items to attack
|
||||
// another player.
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 0);
|
||||
}
|
||||
|
||||
if (zone != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENDER_CHEST && !zone.getWarzoneConfig().getBoolean(WarzoneConfig.ALLOWENDER)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "use.ender");
|
||||
}
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (zone != null && team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENCHANTING_TABLE && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "use.enchant");
|
||||
if (zone.getAuthors().contains(player.getName())) {
|
||||
War.war.badMsg(player, "use.xpkillmeter");
|
||||
}
|
||||
}
|
||||
if (zone != null && team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ANVIL && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "use.anvil");
|
||||
if (zone.getAuthors().contains(player.getName())) {
|
||||
War.war.badMsg(player, "use.xpkillmeter");
|
||||
}
|
||||
}
|
||||
if (zone != null && team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK
|
||||
&& event.getClickedBlock().getState() instanceof InventoryHolder
|
||||
&& zone.isFlagThief(player)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "drop.flag.disabled");
|
||||
}
|
||||
if (zone == null && event.getAction() == Action.RIGHT_CLICK_BLOCK
|
||||
&& (event.getClickedBlock().getType() == Material.CHEST || event.getClickedBlock().getType() == Material.TRAPPED_CHEST)
|
||||
&& Warzone.getZoneByLocation(event.getClickedBlock().getLocation()) != null
|
||||
&& !War.war.isZoneMaker(event.getPlayer())) {
|
||||
// prevent opening chests inside a warzone if a player is not a zone maker
|
||||
event.setCancelled(true);
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_CHEST_LOCKED, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK
|
||||
|| event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
Player player = event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.SOUPHEALING)) {
|
||||
ItemStack item = event.getItem();
|
||||
if ((item != null) && (item.getType() == Material.MUSHROOM_STEW)) {
|
||||
if (player.getHealth() < 20) {
|
||||
player.setHealth(Math.min(20, player.getHealth() + 7));
|
||||
item.setType(Material.BOWL);
|
||||
} else if (player.getFoodLevel() < 20) {
|
||||
player.setFoodLevel(Math.min(20, player.getFoodLevel() + 6));
|
||||
player.setSaturation(player.getSaturation() + 7.2f);
|
||||
item.setType(Material.BOWL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(final PlayerMoveEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Location playerLoc = event.getTo(); // Don't call again we need same result.
|
||||
|
||||
Location previousLocation = latestLocations.get(player.getName());
|
||||
if (previousLocation != null &&
|
||||
playerLoc.getBlockX() == previousLocation.getBlockX() &&
|
||||
playerLoc.getBlockY() == previousLocation.getBlockY() &&
|
||||
playerLoc.getBlockZ() == previousLocation.getBlockZ() &&
|
||||
playerLoc.getWorld() == previousLocation.getWorld()) {
|
||||
// we only care when people change location
|
||||
return;
|
||||
}
|
||||
latestLocations.put(player.getName(), playerLoc);
|
||||
|
||||
// Signs can automatically teleport you to specific or random warzones
|
||||
if (playerLoc.getBlock().getType() == Material.SIGN) {
|
||||
Sign sign = (Sign) playerLoc.getBlock().getState();
|
||||
if (sign.getLine(0).equals("[zone]")) {
|
||||
Warzone indicated = Warzone.getZoneByName(sign.getLine(1));
|
||||
if (indicated != null) {
|
||||
player.teleport(indicated.getTeleport());
|
||||
} else if (sign.getLine(1).equalsIgnoreCase("$random")) {
|
||||
List<Warzone> warzones = War.war.getEnabledWarzones();
|
||||
if (warzones.size() == 0) return;
|
||||
int zone = random.nextInt(warzones.size());
|
||||
Warzone random = warzones.get(zone);
|
||||
player.teleport(random.getTeleport());
|
||||
} else if (sign.getLine(1).equalsIgnoreCase("$active")) {
|
||||
List<Warzone> warzones = War.war.getActiveWarzones();
|
||||
if (warzones.size() == 0) warzones = War.war.getEnabledWarzones();
|
||||
if (warzones.size() == 0) return;
|
||||
int zone = random.nextInt(warzones.size());
|
||||
Warzone random = warzones.get(zone);
|
||||
player.teleport(random.getTeleport());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
|
||||
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||
|
||||
boolean isMaker = War.war.isZoneMaker(player);
|
||||
|
||||
// Zone walls
|
||||
Team currentTeam = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
|
||||
boolean protecting = false;
|
||||
if (currentTeam != null) {
|
||||
if (playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS)) {
|
||||
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
} else {
|
||||
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
|
||||
if (nearbyZone != null && nearbyZone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS) && !isMaker) {
|
||||
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (!protecting) {
|
||||
// zone makers still need to delete their walls
|
||||
// make sure to delete any wall guards as you leave
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
zone.dropZoneWallGuardIfAny(player);
|
||||
}
|
||||
}
|
||||
|
||||
// Warzone lobby gates
|
||||
if (locLobby != null && currentTeam == null && locLobby.isInAnyGate(playerLoc)) {
|
||||
Warzone zone = locLobby.getZone();
|
||||
Team locTeamGate = locLobby.getTeamGate(playerLoc);
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) || zone.isReinitializing()) {
|
||||
War.war.badMsg(player, "join.disabled");
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
|
||||
War.war.badMsg(player, "join.progress");
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (zone.isFull()) {
|
||||
War.war.badMsg(player, "join.full.all");
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (zone.isFull(player)) {
|
||||
War.war.badMsg(player, "join.permission.all");
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (locTeamGate != null && locTeamGate.isFull()) {
|
||||
War.war.badMsg(player, "join.full.single", locTeamGate.getName());
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (locTeamGate != null && !War.war.canPlayWar(player, locTeamGate)) {
|
||||
War.war.badMsg(player, "join.permission.single", locTeamGate.getName());
|
||||
event.setTo(zone.getTeleport());
|
||||
} else if (zone.getLobby().isAutoAssignGate(playerLoc)) {
|
||||
zone.autoAssign(player);
|
||||
} else if (locTeamGate != null) {
|
||||
zone.assign(player, locTeamGate);
|
||||
}
|
||||
return;
|
||||
} else if (locLobby != null && currentTeam == null
|
||||
&& locLobby.isInWarHubLinkGate(playerLoc)
|
||||
&& War.war.getWarHub() != null) {
|
||||
War.war.msg(player, "warhub.teleport");
|
||||
event.setTo(War.war.getWarHub().getLocation());
|
||||
return;
|
||||
}
|
||||
|
||||
// Warhub zone gates
|
||||
WarHub hub = War.war.getWarHub();
|
||||
if (hub != null && hub.getVolume().contains(player.getLocation())) {
|
||||
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
|
||||
if (zone != null && zone.getTeleport() != null) {
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN)
|
||||
&& zone.getTeams().size() >= 1 && currentTeam == null) {
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) || zone.isReinitializing()) {
|
||||
War.war.badMsg(player, "join.disabled");
|
||||
event.setTo(hub.getLocation());
|
||||
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
|
||||
War.war.badMsg(player, "join.progress");
|
||||
event.setTo(hub.getLocation());
|
||||
} else if (zone.isFull()) {
|
||||
War.war.badMsg(player, "join.full.all");
|
||||
event.setTo(hub.getLocation());
|
||||
} else if (zone.isFull(player)) {
|
||||
War.war.badMsg(player, "join.permission.all");
|
||||
event.setTo(hub.getLocation());
|
||||
} else {
|
||||
zone.autoAssign(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.msg(player, "zone.teleport", zone.getName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc);
|
||||
Team playerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (isLeaving) { // already in a team and in warzone, leaving
|
||||
// same as leave
|
||||
if (playerTeam != null) {
|
||||
boolean atSpawnAlready = playerTeam.isSpawnLocation(playerLoc);
|
||||
if (!atSpawnAlready) {
|
||||
playerWarzone.handlePlayerLeave(player, playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN) ?
|
||||
War.war.getWarHub().getLocation() : playerWarzone.getTeleport(), event, true);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerWarzone != null) {
|
||||
// Player belongs to a warzone team but is outside: he snuck out or is at spawn and died
|
||||
if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) {
|
||||
List<BlockFace> nearestWalls = playerWarzone.getNearestWalls(playerLoc);
|
||||
if (!playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
War.war.badMsg(player, "zone.leavenotice");
|
||||
}
|
||||
if(nearestWalls != null && nearestWalls.size() > 0) {
|
||||
// First, try to bump the player back in
|
||||
int northSouthMove = 0;
|
||||
int eastWestMove = 0;
|
||||
int upDownMove = 0;
|
||||
int moveDistance = 1;
|
||||
|
||||
if (nearestWalls.contains(Direction.NORTH())) {
|
||||
// move south
|
||||
northSouthMove += moveDistance;
|
||||
} else if (nearestWalls.contains(Direction.SOUTH())) {
|
||||
// move north
|
||||
northSouthMove -= moveDistance;
|
||||
}
|
||||
|
||||
if (nearestWalls.contains(Direction.EAST())) {
|
||||
// move west
|
||||
eastWestMove += moveDistance;
|
||||
} else if (nearestWalls.contains(Direction.WEST())) {
|
||||
// move east
|
||||
eastWestMove -= moveDistance;
|
||||
}
|
||||
|
||||
if (nearestWalls.contains(BlockFace.UP)) {
|
||||
upDownMove -= moveDistance;
|
||||
} else if (nearestWalls.contains(BlockFace.DOWN)) {
|
||||
// fell off the map, back to spawn (still need to drop objects)
|
||||
playerWarzone.dropAllStolenObjects(event.getPlayer(), false);
|
||||
playerWarzone.respawnPlayer(event, playerTeam, event.getPlayer());
|
||||
return;
|
||||
}
|
||||
|
||||
event.setTo(new Location(playerLoc.getWorld(),
|
||||
playerLoc.getX() + northSouthMove,
|
||||
playerLoc.getY() + upDownMove,
|
||||
playerLoc.getZ() + eastWestMove,
|
||||
playerLoc.getYaw(),
|
||||
playerLoc.getPitch()));
|
||||
return;
|
||||
|
||||
// Otherwise, send him to spawn (first make sure he drops his flag/cake/bomb to prevent auto-cap and as punishment)
|
||||
} else {
|
||||
playerWarzone.dropAllStolenObjects(event.getPlayer(), false);
|
||||
playerWarzone.respawnPlayer(event, playerTeam, event.getPlayer());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LoadoutSelection loadoutSelectionState = playerWarzone.getLoadoutSelections().get(player.getName());
|
||||
FlagReturn flagReturn = playerTeam.getTeamConfig().resolveFlagReturn();
|
||||
if (!playerTeam.isSpawnLocation(playerLoc)) {
|
||||
if (!playerWarzone.isEnoughPlayers() && loadoutSelectionState != null && loadoutSelectionState.isStillInSpawn()) {
|
||||
// Be sure to keep only players that just respawned locked inside the spawn for minplayer/minteams restrictions - otherwise
|
||||
// this will conflict with the can't-renter-spawn bump just a few lines below
|
||||
War.war.badMsg(player, "zone.spawn.minplayers", playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINPLAYERS),
|
||||
playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINTEAMS));
|
||||
event.setTo(playerTeam.getRandomSpawn());
|
||||
return;
|
||||
}
|
||||
if (playerWarzone.isRespawning(player)) {
|
||||
int rt = playerTeam.getTeamConfig().resolveInt(TeamConfig.RESPAWNTIMER);
|
||||
War.war.badMsg(player, "zone.spawn.timer", rt);
|
||||
event.setTo(playerTeam.getRandomSpawn());
|
||||
return;
|
||||
}
|
||||
if (playerWarzone.isReinitializing()) {
|
||||
// don't let players wander about outside spawns during reset
|
||||
// (they could mess up the blocks that have already been reset
|
||||
// before the start of the new battle)
|
||||
War.war.msg(player, "zone.battle.reset");
|
||||
event.setTo(playerTeam.getRandomSpawn());
|
||||
return;
|
||||
}
|
||||
} else if (loadoutSelectionState != null && !loadoutSelectionState.isStillInSpawn()
|
||||
&& !playerWarzone.isCakeThief(player)
|
||||
&& (flagReturn.equals(FlagReturn.BOTH) || flagReturn.equals(FlagReturn.SPAWN))
|
||||
&& !playerWarzone.isFlagThief(player)) {
|
||||
|
||||
// player is in spawn, but has left already: he should NOT be let back in - kick him out gently
|
||||
// if he sticks around too long.
|
||||
// (also, be sure you aren't preventing the flag or cake from being captured)
|
||||
// if (!CantReEnterSpawnJob.getPlayersUnderSuspicion().contains(player.getName())) {
|
||||
// CantReEnterSpawnJob job = new CantReEnterSpawnJob(player, playerTeam);
|
||||
// War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, 12);
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
// Monuments
|
||||
if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead
|
||||
&& this.random.nextInt(7) == 3) { // one chance out of many of getting healed
|
||||
int currentHp = (int) player.getHealth();
|
||||
int newHp = Math.min(20, currentHp + locZone.getWarzoneConfig().getInt(WarzoneConfig.MONUMENTHEAL));
|
||||
|
||||
player.setHealth(newHp);
|
||||
double heartNum = ((double) newHp - currentHp) / 2;
|
||||
War.war.msg(player, "zone.monument.voodoo", heartNum);
|
||||
return;
|
||||
}
|
||||
|
||||
// Flag capture
|
||||
if (playerWarzone.isFlagThief(player)) {
|
||||
|
||||
// smoky
|
||||
if (System.currentTimeMillis() % 13 == 0) {
|
||||
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.POTION_BREAK, playerTeam.getKind().getPotionEffectColor());
|
||||
}
|
||||
|
||||
// Make sure game ends can't occur simultaneously.
|
||||
// See Warzone.handleDeath() for details.
|
||||
boolean inSpawn = playerTeam.isSpawnLocation(player.getLocation());
|
||||
boolean inFlag = (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation()));
|
||||
|
||||
if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.BOTH)) {
|
||||
if (!inSpawn && !inFlag) {
|
||||
return;
|
||||
}
|
||||
} else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.SPAWN)) {
|
||||
if (inFlag) {
|
||||
War.war.badMsg(player, "zone.flagreturn.spawn");
|
||||
return;
|
||||
} else if (!inSpawn) {
|
||||
return;
|
||||
}
|
||||
} else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.FLAG)) {
|
||||
if (inSpawn) {
|
||||
War.war.badMsg(player, "zone.flagreturn.flag");
|
||||
return;
|
||||
} else if (!inFlag) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!playerTeam.getPlayers().contains(player)) {
|
||||
// Make sure player is still part of team, game may have ended while waiting)
|
||||
// Ignore the scorers that happened immediately after the game end.
|
||||
return;
|
||||
}
|
||||
|
||||
if (playerWarzone.isTeamFlagStolen(playerTeam) && playerTeam.getTeamConfig().resolveBoolean(TeamConfig.FLAGMUSTBEHOME)) {
|
||||
War.war.badMsg(player, "zone.flagreturn.deadlock");
|
||||
} else {
|
||||
// flags can be captured at own spawn or own flag pole
|
||||
if (playerWarzone.isReinitializing()) {
|
||||
// Battle already ended or interrupted
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
} else {
|
||||
// All good - proceed with scoring
|
||||
playerTeam.addPoint();
|
||||
Team victim = playerWarzone.getVictimTeamForFlagThief(player);
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast("zone.flagcapture.broadcast", playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE,
|
||||
victim.getName(), playerTeam.getName());
|
||||
}
|
||||
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// just added a point
|
||||
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
|
||||
victim.initializeTeamFlag();
|
||||
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
}
|
||||
|
||||
playerWarzone.removeFlagThief(player);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Bomb detonation
|
||||
if (playerWarzone.isBombThief(player)) {
|
||||
// smoky
|
||||
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 0);
|
||||
|
||||
// Make sure game ends can't occur simultaneously.
|
||||
// Not thread safe. See Warzone.handleDeath() for details.
|
||||
boolean inEnemySpawn = false;
|
||||
Team victim = null;
|
||||
for (Team team : playerWarzone.getTeams()) {
|
||||
if (team != playerTeam
|
||||
&& team.isSpawnLocation(player.getLocation())
|
||||
&& team.getPlayers().size() > 0) {
|
||||
inEnemySpawn = true;
|
||||
victim = team;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (inEnemySpawn && playerTeam.getPlayers().contains(player)) {
|
||||
// Made sure player is still part of team, game may have ended while waiting.
|
||||
// Ignored the scorers that happened immediately after the game end.
|
||||
Bomb bomb = playerWarzone.getBombForThief(player);
|
||||
|
||||
// Boom!
|
||||
if (!playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) {
|
||||
// Don't blow up if warzone is unbreakable
|
||||
playerWarzone.getWorld().createExplosion(player.getLocation(), 2F);
|
||||
}
|
||||
|
||||
if (playerWarzone.isReinitializing()) {
|
||||
// Battle already ended or interrupted
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
} else {
|
||||
// All good - proceed with scoring
|
||||
playerTeam.addPoint();
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast("zone.bomb.broadcast", playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE,
|
||||
victim.getName(), playerTeam.getName());
|
||||
}
|
||||
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// just added a point
|
||||
|
||||
// restore bombed team's spawn
|
||||
for (Volume spawnVolume : victim.getSpawnVolumes().values()) {
|
||||
spawnVolume.resetBlocks();
|
||||
}
|
||||
victim.initializeTeamSpawns();
|
||||
|
||||
// bring back tnt
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.addBombBlocks();
|
||||
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
}
|
||||
|
||||
playerWarzone.removeBombThief(player);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Cake retrieval
|
||||
if (playerWarzone.isCakeThief(player)) {
|
||||
// smoky
|
||||
if (System.currentTimeMillis() % 13 == 0) {
|
||||
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.POTION_BREAK, playerTeam.getKind().getPotionEffectColor());
|
||||
}
|
||||
|
||||
// Make sure game ends can't occur simultaneously.
|
||||
// Not thread safe. See Warzone.handleDeath() for details.
|
||||
boolean inSpawn = playerTeam.isSpawnLocation(player.getLocation());
|
||||
|
||||
if (inSpawn && playerTeam.getPlayers().contains(player)) {
|
||||
// Made sure player is still part of team, game may have ended while waiting.
|
||||
// Ignored the scorers that happened immediately after the game end.
|
||||
boolean hasOpponent = false;
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
if (t != playerTeam && t.getPlayers().size() > 0) {
|
||||
hasOpponent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't let someone alone make points off cakes
|
||||
if (hasOpponent) {
|
||||
Cake cake = playerWarzone.getCakeForThief(player);
|
||||
|
||||
if (playerWarzone.isReinitializing()) {
|
||||
// Battle already ended or interrupted
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
} else {
|
||||
// All good - proceed with scoring
|
||||
// Woot! Cake effect: 1 pt + full lifepool
|
||||
playerTeam.addPoint();
|
||||
playerTeam.setRemainingLives(playerTeam.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast("zone.cake.broadcast", playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE,
|
||||
ChatColor.GREEN + cake.getName() + ChatColor.WHITE, playerTeam.getName());
|
||||
}
|
||||
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// just added a point
|
||||
|
||||
// bring back cake
|
||||
cake.getVolume().resetBlocks();
|
||||
cake.addCakeBlocks();
|
||||
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
}
|
||||
|
||||
playerWarzone.removeCakeThief(player);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Class selection lock
|
||||
if (!playerTeam.isSpawnLocation(player.getLocation()) &&
|
||||
playerWarzone.getLoadoutSelections().keySet().contains(player.getName())
|
||||
&& playerWarzone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
playerWarzone.getLoadoutSelections().get(player.getName()).setStillInSpawn(false);
|
||||
}
|
||||
|
||||
} else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
|
||||
// player is not in any team, but inside warzone boundaries, get him out
|
||||
Warzone zone = Warzone.getZoneByLocation(playerLoc);
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.badMsg(player, "zone.noteamnotice");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||
if (War.war.isLoaded() && event.isSneaking()) {
|
||||
Warzone playerWarzone = Warzone.getZoneByLocation(event.getPlayer());
|
||||
Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (playerWarzone != null && playerTeam != null && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1 && playerTeam.isSpawnLocation(event.getPlayer().getLocation())) {
|
||||
if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName())
|
||||
&& playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) {
|
||||
LoadoutSelection selection = playerWarzone.getLoadoutSelections().get(event.getPlayer().getName());
|
||||
List<Loadout> loadouts = new ArrayList<Loadout>(playerTeam.getInventories().resolveNewLoadouts());
|
||||
for (Iterator<Loadout> it = loadouts.iterator(); it.hasNext();) {
|
||||
Loadout ldt = it.next();
|
||||
if (ldt.getName().equals("first") ||
|
||||
(ldt.requiresPermission() && !event.getPlayer().hasPermission(ldt.getPermission()))) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
int currentIndex = (selection.getSelectedIndex() + 1) % loadouts.size();
|
||||
selection.setSelectedIndex(currentIndex);
|
||||
|
||||
playerWarzone.equipPlayerLoadoutSelection(event.getPlayer(), playerTeam, false, true);
|
||||
} else {
|
||||
War.war.badMsg(event.getPlayer(), "zone.loadout.reenter");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Warzone playingZone = Warzone.getZoneByPlayerName(event.getPlayer().getName());
|
||||
Warzone deadZone = Warzone.getZoneForDeadPlayer(event.getPlayer());
|
||||
if (playingZone == null && deadZone != null) {
|
||||
// Game ended while player was dead, so restore state
|
||||
deadZone.getReallyDeadFighters().remove(event.getPlayer().getName());
|
||||
if (deadZone.hasPlayerState(event.getPlayer().getName())) {
|
||||
deadZone.restorePlayerState(event.getPlayer());
|
||||
}
|
||||
event.setRespawnLocation(deadZone.getEndTeleport(LeaveCause.DISCONNECT));
|
||||
return;
|
||||
} else if (playingZone == null) {
|
||||
// Player not playing war
|
||||
return;
|
||||
} else if (deadZone == null) {
|
||||
// Player is not a 'really' dead player, nothing to do here
|
||||
return;
|
||||
}
|
||||
Team team = playingZone.getPlayerTeam(event.getPlayer().getName());
|
||||
Validate.notNull(team, String.format(
|
||||
"Failed to find a team for player %s in warzone %s on respawn.",
|
||||
event.getPlayer().getName(), playingZone.getName()));
|
||||
playingZone.getReallyDeadFighters().remove(event.getPlayer().getName());
|
||||
event.setRespawnLocation(team.getRandomSpawn());
|
||||
playingZone.respawnPlayer(team, event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(final PlayerTeleportEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(event.getPlayer().getName());
|
||||
Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (playerWarzone != null) {
|
||||
if (!playerWarzone.getVolume().contains(event.getTo())) {
|
||||
// Prevent teleporting out of the warzone
|
||||
if (!playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
War.war.badMsg(event.getPlayer(), "Use /leave (or /war leave) to exit the zone.");
|
||||
}
|
||||
playerWarzone.dropAllStolenObjects(event.getPlayer(), false);
|
||||
playerWarzone.respawnPlayer(event, playerTeam, event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerExpChange(PlayerExpChangeEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Team team = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (team != null && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
event.setAmount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerChat(final AsyncPlayerChatEvent event) {
|
||||
Team team = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (team != null && team.isInTeamChat(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
team.sendTeamChatMessage(event.getPlayer(), event.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(final InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone == null) {
|
||||
return;
|
||||
}
|
||||
if (zone.isThief(player)) {
|
||||
// Prevent thieves from taking their bomb/wool/cake into a chest, etc.
|
||||
event.setCancelled(true);
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 10, 10);
|
||||
} else if (event.getSlotType() == InventoryType.SlotType.ARMOR && event.getSlot() == 39
|
||||
&& zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
|
||||
// Magically give player a wool block when they click their helmet
|
||||
ItemStack teamBlock = zone.getPlayerTeam(player.getName()).getKind().getBlockHead();
|
||||
player.getInventory().remove(teamBlock.getType());
|
||||
// Deprecated behavior cannot be removed as it is essential to this function
|
||||
//noinspection deprecation
|
||||
event.setCursor(teamBlock);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void purgeLatestPositions() {
|
||||
this.latestLocations.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone == null) {
|
||||
return;
|
||||
}
|
||||
if (zone.isImportantBlock(event.getBlockClicked())) {
|
||||
event.setCancelled(true);
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class WarPlayerThiefEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Player player;
|
||||
private StolenObject type;
|
||||
|
||||
public WarPlayerThiefEvent(Player thief, StolenObject stolen) {
|
||||
this.player = thief;
|
||||
this.type = stolen;
|
||||
}
|
||||
|
||||
public Player getThief() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public StolenObject getStolenObject() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public enum StolenObject {
|
||||
FLAG,
|
||||
BOMB,
|
||||
CAKE
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.tommytony.war.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
|
||||
public class WarScoreCapEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private List<Team> winningTeams;
|
||||
|
||||
public List<Team> getWinningTeams() {
|
||||
return winningTeams;
|
||||
}
|
||||
|
||||
public WarScoreCapEvent(List<Team> winningTeams) {
|
||||
this.winningTeams = winningTeams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.tommytony.war.jobs;
|
||||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
|
||||
public class BlockResetJob implements Runnable {
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.structure.CapturePoint;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class CapturePointTimer extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : War.war.getServer().getOnlinePlayers()) {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
|
||||
if (zone == null || team == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (CapturePoint cp : zone.getCapturePoints()) {
|
||||
if (cp.getVolume().contains(player.getLocation())) {
|
||||
// player is maintaining or contesting capture point.
|
||||
if (cp.getController() == null) {
|
||||
// take control of unclaimed point
|
||||
incrementStrength(cp, player, zone, team);
|
||||
} else if (cp.getController() != team.getKind()) {
|
||||
// contest other team's point
|
||||
decrementStrength(cp, player, zone, team);
|
||||
} else if (cp.getController() == team.getKind()) {
|
||||
// maintain your team's point
|
||||
incrementStrength(cp, player, zone, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
for (CapturePoint cp : zone.getCapturePoints()) {
|
||||
if (cp.getController() != null && cp.getController() != cp.getDefaultController()
|
||||
&& cp.getStrength() == cp.getMaxStrength()) {
|
||||
int controlTime = cp.getControlTime() + 1;
|
||||
cp.setControlTime(controlTime);
|
||||
if (controlTime % cp.getMaxStrength() == 0) {
|
||||
// give points for every control time which is a multiple of the time taken to capture
|
||||
Team team = zone.getTeamByKind(cp.getController());
|
||||
team.addPoint();
|
||||
zone.broadcast("zone.capturepoint.addpoint",
|
||||
cp.getController().getFormattedName(), cp.getName());
|
||||
// Detect win conditions
|
||||
if (team.getPoints() >= team.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
zone.handleScoreCapReached(team.getName());
|
||||
} else {
|
||||
// just added a point
|
||||
team.resetSign();
|
||||
zone.getLobby().resetTeamGateSign(team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void decrementStrength(CapturePoint cp, Player player, Warzone zone, Team team) {
|
||||
int strength = cp.getStrength();
|
||||
if (strength < 1) {
|
||||
// strength is already at minimum, ensure attributes are wiped
|
||||
cp.setController(null);
|
||||
cp.setStrength(0);
|
||||
return;
|
||||
}
|
||||
strength -= 1;
|
||||
if (strength == 0) {
|
||||
if (cp.antiChatSpam()) {
|
||||
zone.broadcast("zone.capturepoint.lose", cp.getController().getFormattedName(), cp.getName());
|
||||
}
|
||||
cp.setControlTime(0);
|
||||
cp.setController(null);
|
||||
} else if (strength == cp.getMaxStrength() - 1) {
|
||||
if (cp.antiChatSpam()) {
|
||||
zone.broadcast("zone.capturepoint.contest", cp.getName(),
|
||||
team.getKind().getColor() + player.getName() + ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
cp.setStrength(strength);
|
||||
}
|
||||
|
||||
private static void incrementStrength(CapturePoint cp, Player player, Warzone zone, Team team) {
|
||||
int strength = cp.getStrength();
|
||||
if (strength > cp.getMaxStrength()) {
|
||||
// cap strength at CapturePoint.MAX_STRENGTH
|
||||
cp.setStrength(cp.getMaxStrength());
|
||||
return;
|
||||
} else if (strength == cp.getMaxStrength()) {
|
||||
// do nothing
|
||||
return;
|
||||
}
|
||||
strength += 1;
|
||||
if (strength == cp.getMaxStrength()) {
|
||||
if (cp.antiChatSpam()) {
|
||||
zone.broadcast("zone.capturepoint.capture", cp.getController().getFormattedName(), cp.getName());
|
||||
}
|
||||
team.addPoint();
|
||||
} else if (strength == 1) {
|
||||
if (cp.antiChatSpam()) {
|
||||
zone.broadcast("zone.capturepoint.fortify", team.getKind().getFormattedName(), cp.getName());
|
||||
}
|
||||
cp.setController(team.getKind());
|
||||
}
|
||||
cp.setStrength(strength);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
|
||||
import com.tommytony.war.utility.DeferredBlockReset;
|
||||
|
||||
public class DeferredBlockResetsJob implements Runnable {
|
||||
|
||||
List<BlockState> deferred = new ArrayList<BlockState>();
|
||||
|
||||
public DeferredBlockResetsJob() {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DeferredBlockResetsJob(World humor) {
|
||||
}
|
||||
|
||||
public void add(BlockState pleaseResetLater) {
|
||||
this.deferred.add(pleaseResetLater);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void add(DeferredBlockReset humor) {
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.deferred.isEmpty();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (BlockState reset : this.deferred) {
|
||||
reset.update(true, false);
|
||||
for (Entity ent : reset.getWorld().getEntities()) {
|
||||
if (ent instanceof Item
|
||||
&& ent.getLocation().distance(reset.getLocation()) < 2) {
|
||||
ent.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.tommytony.war.job;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the helmet again onto the players heads. Also limits the number of blocks being held.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class HelmetProtectionTask implements Runnable {
|
||||
|
||||
public void run() {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
for (Team team : zone.getTeams()) {
|
||||
for (Player player : team.getPlayers()) {
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
Material teamBlockMaterial;
|
||||
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
|
||||
teamBlockMaterial = team.getKind().getMaterial();
|
||||
// 1) Replace missing block head
|
||||
if (playerInv.getHelmet() == null || playerInv.getHelmet().getType() != Material.LEATHER_HELMET) {
|
||||
playerInv.setHelmet(team.getKind().getHat());
|
||||
}
|
||||
|
||||
// 2) Get rid of extra blocks in inventory: only keep one
|
||||
HashMap<Integer, ? extends ItemStack> blocks = playerInv.all(teamBlockMaterial);
|
||||
if (blocks.size() > 1 || (blocks.size() == 1 && blocks.get(blocks.keySet().iterator().next()).getAmount() > 1)) {
|
||||
int i = 0;
|
||||
int removed = 0;
|
||||
for (ItemStack item : playerInv.getContents()) {
|
||||
// remove only same colored wool
|
||||
if (item != null && item.getType() == teamBlockMaterial) {
|
||||
playerInv.clear(i);
|
||||
removed++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
int firstEmpty = playerInv.firstEmpty();
|
||||
if (firstEmpty > 0) {
|
||||
playerInv.setItem(firstEmpty, team.getKind().getBlockHead());
|
||||
}
|
||||
|
||||
if (removed > 1) {
|
||||
War.war.badMsg(player, "All that " + team.getName() + " wool must have been heavy!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check for thieves without their treasure in their hands
|
||||
if (zone.isFlagThief(player)) {
|
||||
Team victim = zone.getVictimTeamForFlagThief(player);
|
||||
player.getInventory().setItemInMainHand(null);
|
||||
player.getInventory().setItemInOffHand(null);
|
||||
player.getInventory().setHeldItemSlot(0);
|
||||
player.getInventory().addItem(new ItemStack(victim.getKind().getMaterial(), 2240));
|
||||
} else if (zone.isBombThief(player)) {
|
||||
player.getInventory().setItemInMainHand(null);
|
||||
player.getInventory().setItemInOffHand(null);
|
||||
player.getInventory().setHeldItemSlot(0);
|
||||
player.getInventory().addItem(new ItemStack(Material.TNT, 2240));
|
||||
} else if (zone.isCakeThief(player)) {
|
||||
player.getInventory().setItemInMainHand(null);
|
||||
player.getInventory().setItemInOffHand(null);
|
||||
player.getInventory().setHeldItemSlot(0);
|
||||
player.getInventory().addItem(new ItemStack(Material.CAKE, 2240));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.tommytony.war.jobs;
|
||||
package com.tommytony.war.job;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue