Compare commits
101 Commits
version2.1
...
version2.2
Author | SHA1 | Date | |
---|---|---|---|
54545a9ee1 | |||
560bbf0394 | |||
2150cc66d0 | |||
7673c3f674 | |||
577531db5e | |||
3739ee6c5a | |||
2d830b2f9f | |||
02fd7a4916 | |||
e21089d8c7 | |||
fc488e7f31 | |||
e8f23078f1 | |||
9ec2b91181 | |||
478095190a | |||
17942caa73 | |||
d0c23b581a | |||
6884f43e50 | |||
e84130a8fe | |||
8f54c0acc2 | |||
aeae14e2a0 | |||
36be95d0f5 | |||
ed4dd5711e | |||
437296262c | |||
ec2caaad97 | |||
81daa83f44 | |||
0695b3e202 | |||
6df27c14a0 | |||
a16d847234 | |||
d24f0b8fd1 | |||
ea52e4d87e | |||
f4495240a5 | |||
09b9c65ef6 | |||
afe693d491 | |||
d4f33a1885 | |||
b50a2b27d3 | |||
e88e03ed42 | |||
53e2be6be7 | |||
d29ad9a474 | |||
4f89e20e6f | |||
563bdfe2fd | |||
931cd1a520 | |||
b64f41ce0c | |||
1e9b9905a5 | |||
d28bedb78e | |||
e9c4583c3d | |||
7a8e61104a | |||
c764850ded | |||
f939e27464 | |||
ecd219fb2d | |||
99be2905be | |||
9e36cf189b | |||
78283a4f34 | |||
1d08c79cff | |||
cb0dec8b83 | |||
1968ccaaeb | |||
d23a9b7650 | |||
e5ef266f04 | |||
724e05e0a4 | |||
b18df58870 | |||
7119c185e7 | |||
c740a5b111 | |||
8bee74df89 | |||
b383ff89c6 | |||
fec999541e | |||
2ed611d995 | |||
faabb2f9db | |||
e6e6273147 | |||
093778f2fb | |||
a5b34458c4 | |||
30d15c141e | |||
3cac4e70cc | |||
95446f1371 | |||
8e860e90c6 | |||
d9194c7497 | |||
c3a24a940f | |||
c62fb32e90 | |||
580fda0273 | |||
252292819f | |||
79dcd259dc | |||
12fde472a2 | |||
be3c541845 | |||
6bd53a3fe6 | |||
a9be1eaa51 | |||
dd492a7327 | |||
0230314c7e | |||
768d385915 | |||
232305a871 | |||
00573c2763 | |||
f1d623df60 | |||
040377cb36 | |||
e9027900ce | |||
34b1c7e0ce | |||
987de39bf9 | |||
0e13f60122 | |||
f2bfe27eba | |||
67c8a15e46 | |||
a984f3a3ea | |||
f253dd4ccc | |||
71031d0578 | |||
e30b82b74f | |||
acf4c9002c | |||
4012a4ac15 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -28,3 +28,6 @@ profile
|
|||||||
|
|
||||||
# bukkit
|
# bukkit
|
||||||
bukkit/
|
bukkit/
|
||||||
|
|
||||||
|
# bukkit test-server
|
||||||
|
bukkit-testserver/
|
||||||
|
13
AUTHORS.txt
Normal file
13
AUTHORS.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
The following persons contributed to Craft Inc. Gates (previously named Ancient Gates):
|
||||||
|
|
||||||
|
CURRENT MAINTAINER
|
||||||
|
|
||||||
|
Tobias Ottenweller <mail@ottenweller.net>
|
||||||
|
Paul Schulze <info@paul-schulze.de>
|
||||||
|
|
||||||
|
|
||||||
|
FORMER CONTRIBUTOR (alphabetical order)
|
||||||
|
|
||||||
|
Jacob Brunson <jacob@dimensionsmachine.com>
|
||||||
|
locutus <bladedpenguin@gmail.com>
|
||||||
|
Olof Larsson <olof@sylt.nu>
|
130
README.md
130
README.md
@ -1,107 +1,93 @@
|
|||||||
# Craft Inc. Gates – Easily create portals with custom design
|
|
||||||
|
|
||||||
(previously known as __AncientGates__)
|
# Craft Inc. Gates #
|
||||||
|
|
||||||
With this plugin players can create gates that will teleport anyone who enter the gate to specific a location.
|
<Logo here>
|
||||||
The hightlights are: __It is so darn easy to use!__ and __The gates can look any way you like__
|
|
||||||
|
|
||||||
Try the ingame command: __/gate__
|
We are happy to finally announce __Craft Inc. Gates__.
|
||||||
|
|
||||||
Also have a look at the full __[userguide](http://www.craftinc.de/blog/?p=255)__.
|
This awesome plugin lets you _travel_ to far away places and worlds _faster than light_! Just create a gate at any location and set an exit somewhere else.
|
||||||
|
|
||||||
Check out our **[Craft Inc. Minecraft Server](http://www.craftinc.de)**! Everyone is welcome!
|
This has been made available by the hard work of the research and development department of the _Craft Inc. Corporation_. Under the lead of Professor Ddidderr Craftman scientists worked years to find a way to bend time and space inside the Minecraft universe to enable _ultra fast transportation_.
|
||||||
|
|
||||||
Thought first you should take a look at the demonstration oloflarsson and karibu6 created:
|
Now it is time for _you_ to try out this wonderful plugin. Simply install, create a gate and feel the funny tickle inside your brain while traveling.*
|
||||||
__[http://www.youtube.com/watch?v=L4hyqTpeEaA](http://www.youtube.com/watch?v=L4hyqTpeEaA)__
|
|
||||||
|
The key features of this are:
|
||||||
|
|
||||||
|
* Gates with and without frames
|
||||||
|
* Gates consisting of portal blocks and gates made of air (so called hidden gates)
|
||||||
|
* Gates with destinations in different worlds
|
||||||
|
* Gates with custom shapes (gates can look any way you want)
|
||||||
|
|
||||||
|
|
||||||
## FAQ
|
*The Craft Inc. Corporation won't take any responsibility for seasickness, memory loss and sudden suffocation in walls while traveling with one of our gates!
|
||||||
|
|
||||||
|
## FAQ ##
|
||||||
|
|
||||||
__Who can create a gate?__
|
__Who can create a gate?__
|
||||||
|
|
||||||
See the _Permissions_ section.
|
Have a look at the [_Permissions_](http://dev.bukkit.org/bukkit-plugins/craftinc-gates/pages/permissions/) page.
|
||||||
|
|
||||||
__Who can destroy a gate?__
|
__Who can destroy a gate?__
|
||||||
|
|
||||||
Anyone if you do not use a third-party protection plugin like Grief Prevention.
|
Anyone if you do not use a third-party protection plugin like Grief Prevention.
|
||||||
|
|
||||||
__Are there IConnomy integration, Features for user to dial other gates etc?__
|
__Is there a IConnomy integration? Features for user to dial other gates etc?__
|
||||||
|
|
||||||
Nope. This plugin is very minimalistic and plain. Server operators manage the portals players use them any time they are open.
|
Nope. We currently don't plan to integrate such features. If you really need such an integration please inform us. If there are a lot of people requesting such features we might change our mind.
|
||||||
|
|
||||||
## Usage
|
__Is there a list of all commands?__
|
||||||
|
|
||||||
__Note that the commands mentioned in this section will be made available with the upcoming 2.1 release of Craft Inc. Gates! Meanwhile type '/gate help' while playing to see the current set of commands.__
|
Sure, type _/gate help_ in-game or have a look at the [_Commands_](http://dev.bukkit.org/bukkit-plugins/craftinc-gates/pages/commands/) page.
|
||||||
|
|
||||||
With the __/gate__ plugin you can create gates which will teleport players anywhere you want. Just build a portal (like those nether portal). The gates can look any way you like.
|
__When I destroy the frame of a gate it stops working. Shouldn't it still work?__
|
||||||
|
|
||||||
To make the gate work place yourself in a newly created gate frame and type __/gate create [id]__. Afterwards walk to the destination of your portal and type __/gate exit [id]__ to set the destination. With __/gate open [id]__ you can get your newly created gate to work.
|
Yes and no. To make gates work without a frame you need to tweak the _checkForBrokenGateFrames_ setting. Have a look at the [_Configuration_](http://dev.bukkit.org/bukkit-plugins/craftinc-gates/pages/configuration/) page for more information.
|
||||||
|
|
||||||
To hide a gate simply call __/gate hide [id]__. Now that gate won’t have purple blocks when open. You can even remove the frame without stopping the hidden gate from working. But unhiding a gate without a frame is not possible!
|
|
||||||
|
|
||||||
|
|
||||||
Use the following commands to modify your gates even further:
|
## Usage ##
|
||||||
|
With this plugin you can create gates which will teleport players anywhere you want. The gates can look any way you like.
|
||||||
|
|
||||||
* __/gate close,c [id]__
|
To make the gate work place yourself inside a newly created gate frame and type __/gate new [id]__. Afterwards walk to the destination of your gate and type __/gate exit [id]__ to set the destination. With __/gate open [id]__ you can get your newly created gate to work.
|
||||||
Closes a gate to prevent players from using it.
|
|
||||||
|
|
||||||
* __/gate create,new [id]__
|
To hide a gate simply call __/gate hide [id]__. Now that gate won’t be made of purple portal blocks while open.
|
||||||
Creates a gate at your current location.
|
|
||||||
|
|
||||||
* __/gate delete,del,remove,rm [id]__
|
Have a look at the [_Commands_](http://dev.bukkit.org/bukkit-plugins/craftinc-gates/pages/commands/) page to find out how to modify gates even further.
|
||||||
Removes the gate from the game.
|
|
||||||
|
|
||||||
* __/gate exit,e [id]__
|
|
||||||
Changes the location where the gate will teleport players to your current location.
|
|
||||||
|
|
||||||
* __/gate help,h,? [page]__
|
|
||||||
Prints the help pages
|
|
||||||
|
|
||||||
* __/gate hide,h [id]__
|
|
||||||
Makes a gate NOT consist of gate blocks while open.
|
|
||||||
|
|
||||||
* __/gate info,details,i,d [id]__
|
|
||||||
Prints detailed informations about a certain gate.
|
|
||||||
|
|
||||||
* __/gate list,ls [page]__
|
|
||||||
Prints all availiable gates.
|
|
||||||
|
|
||||||
* __/gate location,l [id]__
|
|
||||||
Sets the entrance of the gate to your current location.
|
|
||||||
|
|
||||||
* __/gate open,o [id]__
|
|
||||||
Open a gate so players can use it.
|
|
||||||
|
|
||||||
* __/gate rename,changename,cn [current name] [new name]__
|
|
||||||
Changes the name/id of the gate.
|
|
||||||
|
|
||||||
* __/gate unhide,uh [id]__
|
|
||||||
Makes that gate visible.
|
|
||||||
|
|
||||||
|
|
||||||
|
## Installing ##
|
||||||
|
|
||||||
## Permissions
|
1. Download the latest release _[here](http://dev.bukkit.org/bukkit-plugins/craftinc-gates/files/)_
|
||||||
|
2. Extract the content of the zip file into the plugins folder of your Bukkit server.
|
||||||
* __craftincgates.info__
|
|
||||||
Gives access to info and list commands.
|
|
||||||
|
|
||||||
* __craftincgates.use__
|
|
||||||
Allows you to travel via gates.
|
|
||||||
|
|
||||||
* __craftincgates.manage__
|
|
||||||
Gives access to commands manipulating gates.
|
|
||||||
|
|
||||||
## Installing
|
|
||||||
|
|
||||||
1. Download the latest release: __[http://dev.bukkit.org/server-mods/craftinc-gates/files/](http://dev.bukkit.org/server-mods/craftinc-gates/files/)__
|
|
||||||
2. Put the downloaded _CraftIncGates.jar_ in the plugins folder.
|
|
||||||
3. Start or reload the server.
|
3. Start or reload the server.
|
||||||
|
|
||||||
## Bugs and other Problems
|
## Craft Inc. ##
|
||||||
|
Check out our __[Craft Inc. Minecraft Server](http://www.craftinc.de)__. Everyone is welcome!
|
||||||
|
|
||||||
Please use our [issue tracker](https://github.com/craftinc/craftinc-gates/issues?milestone=1&state=open) on github.
|
Also check out our other great plugins:
|
||||||
|
|
||||||
|
* [__Craft Inc. BorderProtection__](http://dev.bukkit.org/bukkit-mods/craftinc-borderprotection/)
|
||||||
|
protect your worlds with a border players cannot cross.
|
||||||
|
|
||||||
## License
|
* [__Craft Inc. Replicator__](http://dev.bukkit.org/bukkit-mods/craftinc-replicator/)
|
||||||
|
allows players to build a replicator to replicate blocks and other items. (still experimental)
|
||||||
|
|
||||||
This project has a LGPL license just like the Bukkit project.
|
* __Craft Inc. Scarecrow__
|
||||||
|
coming soon!
|
||||||
|
|
||||||
|
## Roadmap ##
|
||||||
|
* __Version 2.3__
|
||||||
|
* Info-Tools for gates. (Get the name of a gate you standing next to.)
|
||||||
|
* Search command for nearby gates. (Visually highlight nearby gates. Especially useful for hidden gates!)
|
||||||
|
* __Future__
|
||||||
|
* Optionally allow animals and mobs to travel via gates.
|
||||||
|
* Allow players to use gates while sitting inside a minecart or boat
|
||||||
|
* Dynmap integration.
|
||||||
|
* Per player permissions for using and managing gates.
|
||||||
|
* Horizontal gates.
|
||||||
|
|
||||||
|
## Bugs and other Problems ##
|
||||||
|
Please use our [_issue tracker_](https://github.com/craftinc/craftinc-gates/issues?state=open) on GitHub.
|
||||||
|
|
||||||
|
## Legal Information ##
|
||||||
|
This project is a fork of the original [_Ancient Gates_](https://github.com/bladedpenguin/minecraft-ancient-gates). It is licensed under the [_LGPL_](http://www.gnu.org/licenses/lgpl-3.0.txt) just like the Bukkit project. Thanks to all current and previous [_contributors_](https://github.com/craftinc/craftinc-gates/blob/development/AUTHORS.txt).
|
||||||
|
The font used for the Craft Inc. Gates logo is called [_MineCrafter 3_](http://www.minecraftforum.net/topic/892789-minecrafter-3-font-simply-easy/) and has been made available under the creative commons license. Thanks to Asherz08, MadPixel and Ashley Denham for this great font.
|
||||||
|
23
changelog.md
23
changelog.md
@ -1,10 +1,25 @@
|
|||||||
## 2.1.2
|
## 2.2.1 ##
|
||||||
|
* Changed priority of some event listeners to solve problems with WorldGuard and other protection plugins.
|
||||||
|
|
||||||
|
## 2.2.0 ##
|
||||||
|
* Improved gate commands and shortcuts (have a look at the bukkit-dev page for more information).
|
||||||
|
* Improved overall performance.
|
||||||
|
* Added a configuration file (have a look at the bukkit-dev page for more information).
|
||||||
|
* Resolved issues with (random) teleports to the nether.
|
||||||
|
* Made it possible to create non hidden gates without a frame. (Turned off by default!)
|
||||||
|
* Changed the behavior regarding portal blocks. Starting with this version no blocks will be set by the plugin. All portal blocks will only be visible on client side.
|
||||||
|
* Added checks preventing the plugin from overwriting the gate storage file on error.
|
||||||
|
* Added the ability to change and disable messages on teleport and insufficient permissions via a config file.
|
||||||
|
|
||||||
|
## 2.1.2 ##
|
||||||
* Fixed a bug where players got teleported one block beside the real portal.
|
* Fixed a bug where players got teleported one block beside the real portal.
|
||||||
* Fixed a bug where gates with no location caused multiply exceptions.
|
* Fixed a bug where gates with no location caused multiple exceptions.
|
||||||
## 2.1.1
|
|
||||||
|
## 2.1.1 ##
|
||||||
* Made the list command more reliable.
|
* Made the list command more reliable.
|
||||||
* Error messages will be displayed less frequent.
|
* Error messages will be displayed less frequent.
|
||||||
## 2.1.0
|
|
||||||
|
## 2.1.0 ##
|
||||||
* Command outputs are now colored.
|
* Command outputs are now colored.
|
||||||
* Fixed a bug where players in creative mode would not be teleported correctly.
|
* Fixed a bug where players in creative mode would not be teleported correctly.
|
||||||
* Made various commands available via the server console.
|
* Made various commands available via the server console.
|
||||||
|
35
doc/Commands.md
Normal file
35
doc/Commands.md
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
* __/gate close, c [id]__
|
||||||
|
Closes a gate to prevent players from using it.
|
||||||
|
|
||||||
|
* __/gate delete, del, remove [id]__
|
||||||
|
Removes the gate from the game.
|
||||||
|
|
||||||
|
* __/gate exit, e [id]__
|
||||||
|
Changes the location where the gate will teleport players to your current location.
|
||||||
|
|
||||||
|
* __/gate help, ? [page]__
|
||||||
|
Prints help pages.
|
||||||
|
|
||||||
|
* __/gate hide, h [id]__
|
||||||
|
Makes a gate NOT consist of gate blocks while open.
|
||||||
|
|
||||||
|
* __/gate info, i [id]__
|
||||||
|
Prints details about a certain gate.
|
||||||
|
|
||||||
|
* __/gate list, ls [page]__
|
||||||
|
Prints all available gates.
|
||||||
|
|
||||||
|
* __/gate location, lo [id]__
|
||||||
|
Sets the entrance of the gate to your current location.
|
||||||
|
|
||||||
|
* __/gate new, n [id]__
|
||||||
|
Creates a gate at your current location.
|
||||||
|
|
||||||
|
* __/gate open, o [id]__
|
||||||
|
Open a gate so players can use it.
|
||||||
|
|
||||||
|
* __/gate rename, rn [current name] [new name]__
|
||||||
|
Changes the name/id of the gate.
|
||||||
|
|
||||||
|
* __/gate unhide,uh [id]__
|
||||||
|
Makes that gate visible.
|
51
doc/Configuration.md
Normal file
51
doc/Configuration.md
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
Starting with version 2.2.0 some features are customizable via a configuration file.
|
||||||
|
|
||||||
|
The configuration file will be automatically created on the the first startup after
|
||||||
|
installing or updating the plugin.
|
||||||
|
|
||||||
|
|
||||||
|
The following keys and values are available:
|
||||||
|
|
||||||
|
|
||||||
|
* __maxGateBlocks__
|
||||||
|
A positive integer defining the maximum number of blocks a gate can consist of.
|
||||||
|
Note that increasing this value might slow down your server!
|
||||||
|
|
||||||
|
|
||||||
|
* __playerGateBlockUpdateRadius__
|
||||||
|
Defines the radius around a player where portal blocks are visible to that player.
|
||||||
|
Adjust this value when increasing or decreasing the view-distance on the server.
|
||||||
|
Only positive integer values are allowed.
|
||||||
|
|
||||||
|
|
||||||
|
* __checkForBrokenGateFrames__
|
||||||
|
Allowed values are _true_ and _false_ only. Setting this value to _false_ will disable
|
||||||
|
all checks for broken frames for non-hidden gates. Disabling frame block checks
|
||||||
|
might increase you server performance.
|
||||||
|
|
||||||
|
|
||||||
|
* __saveOnChanges__
|
||||||
|
Allowed values are _true_ and _false_ only. Disabling _save on changes_ might
|
||||||
|
increase server performance but gates will only be saved to disk when the plugin
|
||||||
|
gets disabled! This might lead to data loss on error.
|
||||||
|
|
||||||
|
|
||||||
|
* __gateTeleportMessage__
|
||||||
|
A string value going to displayed every time when a player travels using a gate. Will
|
||||||
|
only be displayed if _showTeleportMessage_ is set to _true_.
|
||||||
|
|
||||||
|
|
||||||
|
* __showTeleportMessage__
|
||||||
|
A boolean (_true_ or _false_) determining wether the _teleport message_ will
|
||||||
|
be displayed.
|
||||||
|
|
||||||
|
|
||||||
|
* __gateTeleportNoPermissionMessage__
|
||||||
|
A string value going to displayed every time when a player enters a gate and is not
|
||||||
|
allowed to use that gate. Will only be displayed if _showTeleportNoPermissionMessage_
|
||||||
|
is set to _true_.
|
||||||
|
|
||||||
|
|
||||||
|
* __showTeleportNoPermissionMessage__
|
||||||
|
A boolean (_true_ or _false_) determining wether the _no permission message_ will
|
||||||
|
be displayed.
|
12
doc/Permissions.md
Normal file
12
doc/Permissions.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
The following permissions are available: (Also have a look at the [Commands Page](http://dev.bukkit.org/bukkit-plugins/craftinc-gates/pages/commands/) to see if which commands can be executed with which permission set.)
|
||||||
|
|
||||||
|
* __craftincgates.info__
|
||||||
|
Gives access to info and list commands.
|
||||||
|
|
||||||
|
* __craftincgates.use__
|
||||||
|
Allows you to travel via gates.
|
||||||
|
|
||||||
|
* __craftincgates.manage__
|
||||||
|
Gives access to commands manipulating gates.
|
||||||
|
|
||||||
|
Craft Inc. Gates will use __[Vault](http://dev.bukkit.org/bukkit-mods/vault/)__'s permission system if Vault is installed on your server.
|
@ -1,10 +1,10 @@
|
|||||||
name: Craft Inc. Gates
|
name: ${project.name}
|
||||||
version: 2.1.2
|
version: ${project.version}
|
||||||
description: A plugin to create gates for fast traveling.
|
description: A plugin to create gates for fast traveling.
|
||||||
softdepend: [Vault]
|
softdepend: [Vault]
|
||||||
author: tomco, s1m0ne
|
author: tomco, s1m0ne
|
||||||
authors: [oloflarsson, locutus, DrAgonmoray, s1m0ne, tomco]
|
authors: [oloflarsson, locutus, DrAgonmoray, s1m0ne, tomco]
|
||||||
website: http://www.craftinc.de/craftinc-gates/
|
website: http://dev.bukkit.org/bukkit-plugins/craftinc-gates/
|
||||||
|
|
||||||
main: de.craftinc.gates.Plugin
|
main: de.craftinc.gates.Plugin
|
||||||
database: false
|
database: false
|
||||||
|
8
pom.xml
8
pom.xml
@ -4,14 +4,16 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.craftinc</groupId>
|
<groupId>de.craftinc</groupId>
|
||||||
<artifactId>CraftIncGates</artifactId>
|
<artifactId>CraftIncGates</artifactId>
|
||||||
|
<name>Craft Inc. Gates</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>2.1.2</version>
|
<version>2.2.1</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<finalName>${project.name} ${project.version}</finalName>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
@ -58,14 +60,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.5.2-R0.1</version>
|
<version>1.5.2-R1.0</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>craftbukkit</artifactId>
|
<artifactId>craftbukkit</artifactId>
|
||||||
<version>1.5.2-R0.1</version>
|
<version>1.5.2-R1.0</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
8
resources/config.yml
Normal file
8
resources/config.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
maxGateBlocks: 50
|
||||||
|
playerGateBlockUpdateRadius: 64
|
||||||
|
saveOnChanges: true
|
||||||
|
checkForBrokenGateFrames: true
|
||||||
|
gateTeleportMessage: "Thank you for traveling with Craft Inc. Gates."
|
||||||
|
showTeleportMessage: true
|
||||||
|
gateTeleportNoPermissionMessage: "You are not allowed to use this gate!"
|
||||||
|
showTeleportNoPermissionMessage: true
|
160
scripts/minecraft.sh
Executable file
160
scripts/minecraft.sh
Executable file
@ -0,0 +1,160 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(dirname "$0")
|
||||||
|
SERVICE='craftbukkit*.jar'
|
||||||
|
#USERNAME="minecraft"
|
||||||
|
CPU_COUNT=2
|
||||||
|
BUKKIT="$SCRIPT_DIR/../target/lib/$SERVICE"
|
||||||
|
INVOCATION="java -Xmx1000M -Xms300M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $BUKKIT nogui"
|
||||||
|
MCPATH="$SCRIPT_DIR/../bukkit-testserver"
|
||||||
|
|
||||||
|
if [ ! -d "$MCPATH" ]; then
|
||||||
|
mkdir -p "$MCPATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ME=$(whoami)
|
||||||
|
as_user() {
|
||||||
|
#if [ $ME == $USERNAME ] ; then
|
||||||
|
bash -c "$1"
|
||||||
|
#else
|
||||||
|
#su - $USERNAME -c "$1"
|
||||||
|
#fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mc_start() {
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "Tried to start but $SERVICE was already running!"
|
||||||
|
else
|
||||||
|
echo "$SERVICE was not running... starting."
|
||||||
|
cd "$MCPATH"
|
||||||
|
as_user "cd "$MCPATH" && screen -dmS minecraft $INVOCATION"
|
||||||
|
sleep 7
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "$SERVICE is now running."
|
||||||
|
else
|
||||||
|
echo "Could not start $SERVICE."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mc_stop() {
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "$SERVICE is running... stopping."
|
||||||
|
as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-all\"\015'"
|
||||||
|
sleep 2
|
||||||
|
as_user "screen -p 0 -S minecraft -X eval 'stuff \"stop\"\015'"
|
||||||
|
sleep 6
|
||||||
|
else
|
||||||
|
echo "$SERVICE was not running."
|
||||||
|
fi
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "$SERVICE could not be shut down... still running."
|
||||||
|
else
|
||||||
|
echo "$SERVICE is shut down."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mc_save() {
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "$SERVICE is running... saving."
|
||||||
|
as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-all\"\015'"
|
||||||
|
else
|
||||||
|
echo "$SERVICE was not running."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mc_reload() {
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "$SERVICE is running... reloading."
|
||||||
|
as_user "screen -p 0 -S minecraft -X eval 'stuff \"reload\"\015'"
|
||||||
|
else
|
||||||
|
echo "$SERVICE was not running."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mc_reload_or_start() {
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "$SERVICE was already running! Doing a reload now!"
|
||||||
|
mc_reload
|
||||||
|
else
|
||||||
|
echo "$SERVICE was not running... starting."
|
||||||
|
cd "$MCPATH"
|
||||||
|
as_user "cd \"$MCPATH\" && screen -dmS minecraft $INVOCATION"
|
||||||
|
sleep 7
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "$SERVICE is now running."
|
||||||
|
else
|
||||||
|
echo "Could not start $SERVICE."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mc_ddidderr_admin() {
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "$SERVICE is running... making ddidder to admin and reloading permissions."
|
||||||
|
as_user "screen -p 0 -S minecraft -X eval 'stuff \"pex user ddidderr group set admin\"\015'"
|
||||||
|
as_user "screen -p 0 -S minecraft -X eval 'stuff \"pex reload\"\015'"
|
||||||
|
else
|
||||||
|
echo "$SERVICE was not running."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
echo "Starting Minecraft..."
|
||||||
|
mc_start
|
||||||
|
echo "DONE"
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
echo "Stopping Minecraft..."
|
||||||
|
as_user "screen -p 0 -S minecraft -X eval 'stuff \"say SERVER SHUTTING DOWN!\"\015'"
|
||||||
|
mc_stop
|
||||||
|
echo "DONE"
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
as_user "screen -p 0 -S minecraft -X eval 'stuff \"say SERVER REBOOT IN 10 SECONDS.\"\015'"
|
||||||
|
$0 stop
|
||||||
|
sleep 1
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
reload)
|
||||||
|
mc_reload
|
||||||
|
;;
|
||||||
|
reload_or_start)
|
||||||
|
echo "Starting or reloading Minecraft..."
|
||||||
|
mc_reload_or_start
|
||||||
|
echo "DONE"
|
||||||
|
;;
|
||||||
|
ddidderr_admin)
|
||||||
|
mc_ddidderr_admin
|
||||||
|
;;
|
||||||
|
connected)
|
||||||
|
as_user "screen -p 0 -S minecraft -X eval 'stuff \"who\"\015'"
|
||||||
|
sleep 2s
|
||||||
|
tac "$MCPATH"/server.log | grep -m 1 "Connected"
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
if ps ax | grep -v grep | grep -v -i SCREEN | grep "craftbukkit" > /dev/null
|
||||||
|
then
|
||||||
|
echo "$SERVICE is running."
|
||||||
|
else
|
||||||
|
echo "$SERVICE is not running."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
save)
|
||||||
|
mc_save
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: /etc/init.d/minecraft {start|stop|restart|connected|status}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
29
scripts/test-deployment.sh
Executable file
29
scripts/test-deployment.sh
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(dirname "$0")"
|
||||||
|
|
||||||
|
DEVELOPER=$(whoami)
|
||||||
|
|
||||||
|
if [ $DEVELOPER = "tobi" ]; then
|
||||||
|
BUKKIT_DIR="$HOME/minecraft/testbuk"
|
||||||
|
PLUGIN_DIR="$HOME/minecraft/testbuk/plugins"
|
||||||
|
START_STOP_SCRIPT="$BUKKIT_DIR/../minecraft.sh"
|
||||||
|
else
|
||||||
|
BUKKIT_DIR="$SCRIPT_DIR/../bukkit-testserver"
|
||||||
|
PLUGIN_DIR="$SCRIPT_DIR/../bukkit-testserver/plugins"
|
||||||
|
START_STOP_SCRIPT="$SCRIPT_DIR/minecraft.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# TODO: This is a bad solution! Maven should write necessary information into an extra file.
|
||||||
|
ARTIFACT_ID="$(grep -C5 '<groupId>de.craftinc' "$SCRIPT_DIR/../pom.xml" | grep '<name>' | sed 's/[ \t]*<name>//g' | sed 's/<\/name>[ \t]*//g')"
|
||||||
|
|
||||||
|
# TODO: This is a bad solution! Maven should write necessary information into an extra file.
|
||||||
|
VERSION="$(grep -C5 '<groupId>de.craftinc' "$SCRIPT_DIR/../pom.xml" | grep '<version>' | sed 's/[ \t]*<version>//g' | sed 's/<\/version>[ \t]*//g')"
|
||||||
|
|
||||||
|
mkdir -p "$PLUGIN_DIR"
|
||||||
|
|
||||||
|
cp "$SCRIPT_DIR/../target/$ARTIFACT_ID $VERSION".jar "$PLUGIN_DIR/"
|
||||||
|
|
||||||
|
echo -e "ddidderr\nmice_on_drugs\nMochaccino\nbeuth_el_max" > "$BUKKIT_DIR/ops.txt"
|
||||||
|
|
||||||
|
$START_STOP_SCRIPT reload_or_start
|
@ -1,195 +0,0 @@
|
|||||||
package de.craftinc.gates;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
|
|
||||||
import de.craftinc.gates.util.FloodUtil;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class BaseGate
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* ATTRIBUTES
|
|
||||||
*/
|
|
||||||
protected Location location; /* saving both location and gateBlockLocations is redundant but makes it easy to allow players to reshape gates */
|
|
||||||
protected Set<Location> gateBlockLocations = new HashSet<Location>(); /* Locations of the blocks inside the gate */
|
|
||||||
|
|
||||||
protected Location exit;
|
|
||||||
|
|
||||||
protected boolean isHidden = false;
|
|
||||||
protected boolean isOpen = false;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* SETTER & GETTER
|
|
||||||
*/
|
|
||||||
|
|
||||||
public Location getLocation()
|
|
||||||
{
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setLocation(Location location) throws Exception
|
|
||||||
{
|
|
||||||
this.location = location;
|
|
||||||
|
|
||||||
if (isOpen) {
|
|
||||||
fillGate();
|
|
||||||
validate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Location getExit()
|
|
||||||
{
|
|
||||||
return exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setExit(Location exit) throws Exception
|
|
||||||
{
|
|
||||||
this.exit = exit;
|
|
||||||
validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean isHidden()
|
|
||||||
{
|
|
||||||
return isHidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setHidden(boolean isHidden) throws Exception
|
|
||||||
{
|
|
||||||
this.isHidden = isHidden;
|
|
||||||
|
|
||||||
if (isHidden == true) {
|
|
||||||
emptyGate();
|
|
||||||
}
|
|
||||||
else if (isOpen()) {
|
|
||||||
fillGate();
|
|
||||||
}
|
|
||||||
|
|
||||||
validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean isOpen()
|
|
||||||
{
|
|
||||||
return isOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setOpen(boolean isOpen) throws Exception
|
|
||||||
{
|
|
||||||
if (isOpen == true && this.isOpen == false) {
|
|
||||||
findPortalBlocks();
|
|
||||||
|
|
||||||
if (!isHidden) {
|
|
||||||
fillGate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (isOpen == false && this.isOpen == true) {
|
|
||||||
emptyGate();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isOpen = isOpen;
|
|
||||||
|
|
||||||
validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Set<Location> getGateBlockLocations()
|
|
||||||
{
|
|
||||||
return gateBlockLocations;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* GATE BLOCK HANDLING
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected void fillGate()
|
|
||||||
{
|
|
||||||
emptyGate();
|
|
||||||
findPortalBlocks();
|
|
||||||
|
|
||||||
// This is not to do an effect
|
|
||||||
// It is to stop portal blocks from destroying themself as they cant rely on non created blocks :P
|
|
||||||
for (Location l : gateBlockLocations) {
|
|
||||||
l.getBlock().setType(Material.GLOWSTONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Location l : gateBlockLocations) {
|
|
||||||
l.getBlock().setType(Material.PORTAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void emptyGate()
|
|
||||||
{
|
|
||||||
for (Location l : gateBlockLocations) {
|
|
||||||
if (l.getBlock().getType() == Material.PORTAL) {
|
|
||||||
l.getBlock().setType(Material.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void findPortalBlocks()
|
|
||||||
{
|
|
||||||
gateBlockLocations = new HashSet<Location>();
|
|
||||||
Set<Block> gateBlocks = FloodUtil.getGateFrameBlocks(location.getBlock());
|
|
||||||
|
|
||||||
if (gateBlocks != null) {
|
|
||||||
for (Block b : gateBlocks) {
|
|
||||||
gateBlockLocations.add(b.getLocation());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* VALIDATION
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if valus attributes do add up; will close gate on wrong values.
|
|
||||||
*/
|
|
||||||
public void validate() throws Exception
|
|
||||||
{
|
|
||||||
if (!isOpen) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location == null) {
|
|
||||||
setOpen(false);
|
|
||||||
throw new Exception("Gate got closed. It has no location.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exit == null) {
|
|
||||||
setOpen(false);
|
|
||||||
throw new Exception("Gate got closed. It has no exit.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gateBlockLocations == null || gateBlockLocations.size() == 0) {
|
|
||||||
setOpen(false);
|
|
||||||
throw new Exception("Gate got closed. The frame is missing or broken.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (isHidden == false) {
|
|
||||||
for (Location l : gateBlockLocations) {
|
|
||||||
if (l.getBlock().getType() == Material.AIR) {
|
|
||||||
setOpen(false);
|
|
||||||
throw new Exception("Gate got closed. The frame is missing or broken.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +1,256 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates;
|
package de.craftinc.gates;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import de.craftinc.gates.util.FloodUtil;
|
||||||
import java.util.Collection;
|
import de.craftinc.gates.persistence.LocationUtil;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
|
||||||
import de.craftinc.gates.util.LocationUtil;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class Gate implements ConfigurationSerializable
|
||||||
/**
|
|
||||||
* Adds persistence and serialization to the base gate class.
|
|
||||||
*/
|
|
||||||
public class Gate extends BaseGate implements ConfigurationSerializable
|
|
||||||
{
|
{
|
||||||
/*
|
protected Location location; /* saving both location and gateBlockLocations is redundant but makes it easy to allow players to reshape gates */
|
||||||
* ATTRIBUTES
|
protected Set<Location> gateBlockLocations = new HashSet<Location>(); /* Locations of the blocks inside the gate */
|
||||||
*/
|
protected Set<Block> gateFrameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
|
protected Location exit;
|
||||||
|
|
||||||
|
protected boolean isHidden = false;
|
||||||
|
protected boolean isOpen = false;
|
||||||
|
|
||||||
protected String id;
|
protected String id;
|
||||||
|
|
||||||
protected static Map<String, Gate> instances = new HashMap<String, Gate>();
|
/**
|
||||||
|
* You should never create two gates with the same 'id'. Also see 'setId(String id)'.
|
||||||
/*
|
* @param id This parameter must not be 'null'. An exception will be thrown otherwise!
|
||||||
* CONSTRUCTORS
|
|
||||||
*/
|
*/
|
||||||
|
public Gate(final String id)
|
||||||
public Gate(String id) throws Exception
|
|
||||||
{
|
{
|
||||||
setId(id);
|
setId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* SETTER & GETTER
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String getId()
|
|
||||||
{
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setId(String id) throws Exception
|
|
||||||
{
|
|
||||||
if (exists(id)) {
|
|
||||||
throw new Exception("A gate with '" + id + "' already exists");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return super.toString() + " " + this.getId();
|
return super.toString() + " " + this.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return This method might return a 'null' value.
|
||||||
|
*/
|
||||||
|
public Location getLocation()
|
||||||
|
{
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param location Supplying 'null' is permitted.
|
||||||
|
* @throws Exception Will throw an exception if the gate is open and an invalid (no gate frame) location is
|
||||||
|
* supplied. Note that the supplied 'location' will be set even if an exception is thrown. Note that this
|
||||||
|
* gate will be closed if an exception is thrown.
|
||||||
|
*/
|
||||||
|
public void setLocation(final Location location) throws Exception
|
||||||
|
{
|
||||||
|
this.location = location;
|
||||||
|
|
||||||
|
if (isOpen) {
|
||||||
|
findPortalBlocks();
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.gateBlockLocations = new HashSet<Location>();
|
||||||
|
this.gateFrameBlocks = new HashSet<Block>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return This method might return a 'null' value.
|
||||||
|
*/
|
||||||
|
public Location getExit()
|
||||||
|
{
|
||||||
|
return exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param exit Supplying 'null' is permitted.
|
||||||
|
* @throws Exception An exception will be thrown if 'null' value is supplied and this gate is open. Note that the
|
||||||
|
* supplied 'exit' will be set even if an exception is thrown. Note that this gate will be closed if an
|
||||||
|
* exception is thrown.
|
||||||
|
*/
|
||||||
|
public void setExit(final Location exit) throws Exception
|
||||||
|
{
|
||||||
|
this.exit = exit;
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return This method will never return 'null'.
|
||||||
|
*/
|
||||||
|
public String getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every gate should have an unique 'id'. You should therefore check if another gate with the same 'id' exists.
|
||||||
|
* Note that this method will not check if another gate with the same 'id' exists!
|
||||||
|
* @param id This parameter must not be 'null'. An exception will be thrown otherwise!
|
||||||
|
*/
|
||||||
|
public void setId(final String id)
|
||||||
|
{
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("gate 'id' cannot be 'null'");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.id = id.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isHidden()
|
||||||
|
{
|
||||||
|
return isHidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setHidden(boolean isHidden) throws Exception
|
||||||
|
{
|
||||||
|
this.isHidden = isHidden;
|
||||||
|
this.validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isOpen()
|
||||||
|
{
|
||||||
|
return isOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setOpen(boolean isOpen) throws Exception
|
||||||
|
{
|
||||||
|
if (isOpen && !this.isOpen) {
|
||||||
|
findPortalBlocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isOpen = isOpen;
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Will never return 'null' but might return an empty Set.
|
||||||
|
*/
|
||||||
|
public Set<Location> getGateBlockLocations()
|
||||||
|
{
|
||||||
|
return gateBlockLocations;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Will never return 'null' but might return an empty Set.
|
||||||
|
*/
|
||||||
|
public Set<Block> getGateFrameBlocks()
|
||||||
|
{
|
||||||
|
return gateFrameBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected void findPortalBlocks()
|
||||||
|
{
|
||||||
|
gateBlockLocations = new HashSet<Location>();
|
||||||
|
Set<Block> gateBlocks = FloodUtil.getGatePortalBlocks(location.getBlock());
|
||||||
|
|
||||||
|
if (gateBlocks != null) {
|
||||||
|
for (Block b : gateBlocks) {
|
||||||
|
gateBlockLocations.add(b.getLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gateFrameBlocks = FloodUtil.getFrame(gateBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if values attributes do add up; will close gate on wrong values.
|
||||||
|
*/
|
||||||
|
public void validate() throws Exception
|
||||||
|
{
|
||||||
|
if (!isOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location == null) {
|
||||||
|
isOpen = false;
|
||||||
|
this.gateBlockLocations = new HashSet<Location>();
|
||||||
|
this.gateFrameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
|
throw new Exception("Gate got closed. It has no location.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exit == null) {
|
||||||
|
isOpen = false;
|
||||||
|
this.gateBlockLocations = new HashSet<Location>();
|
||||||
|
this.gateFrameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
|
throw new Exception("Gate got closed. It has no exit.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gateBlockLocations.size() == 0) {
|
||||||
|
isOpen = false;
|
||||||
|
this.gateBlockLocations = new HashSet<Location>();
|
||||||
|
this.gateFrameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
|
throw new Exception("Gate got closed. The frame is missing or broken. (no gate blocks)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isHidden() && Plugin.getPlugin().getConfig().getBoolean(Plugin.confCheckForBrokenGateFramesKey)) {
|
||||||
|
|
||||||
|
for (Block b : gateFrameBlocks) {
|
||||||
|
|
||||||
|
if (b.getType() == Material.AIR) {
|
||||||
|
isOpen = false;
|
||||||
|
this.gateBlockLocations = new HashSet<Location>();
|
||||||
|
this.gateFrameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
|
throw new Exception("Gate got closed. The frame is missing or broken. (missing frame block(s))");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* INTERFACE: ConfigurationSerializable
|
* INTERFACE: ConfigurationSerializable
|
||||||
*/
|
*/
|
||||||
@ -83,7 +270,12 @@ public class Gate extends BaseGate implements ConfigurationSerializable
|
|||||||
public Gate(Map<String, Object> map)
|
public Gate(Map<String, Object> map)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
id = map.get(idKey).toString();
|
id = map.get(idKey).toString().toLowerCase();
|
||||||
|
|
||||||
|
if (id == null) {
|
||||||
|
throw new Exception("gates need to have an id");
|
||||||
|
}
|
||||||
|
|
||||||
isHidden = (Boolean)map.get(isHiddenKey);
|
isHidden = (Boolean)map.get(isHiddenKey);
|
||||||
isOpen = (Boolean)map.get(isOpenKey);
|
isOpen = (Boolean)map.get(isOpenKey);
|
||||||
|
|
||||||
@ -91,13 +283,13 @@ public class Gate extends BaseGate implements ConfigurationSerializable
|
|||||||
exit = LocationUtil.deserializeLocation((Map<String, Object>) map.get(exitKey));
|
exit = LocationUtil.deserializeLocation((Map<String, Object>) map.get(exitKey));
|
||||||
|
|
||||||
if (map.containsKey(exitPitchKey)) {
|
if (map.containsKey(exitPitchKey)) {
|
||||||
exit.setPitch(((Double)map.get(exitPitchKey)).floatValue());
|
exit.setPitch(((Number)map.get(exitPitchKey)).floatValue());
|
||||||
exit.setYaw(((Double)map.get(exitYawKey)).floatValue());
|
exit.setYaw(((Number)map.get(exitYawKey)).floatValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map.containsKey(locationPitchKey)) {
|
if (map.containsKey(locationPitchKey)) {
|
||||||
location.setPitch(((Double)map.get(locationPitchKey)).floatValue());
|
location.setPitch(((Number)map.get(locationPitchKey)).floatValue());
|
||||||
location.setYaw(((Double)map.get(locationYawKey)).floatValue());
|
location.setYaw(((Number)map.get(locationYawKey)).floatValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
gateBlockLocations = new HashSet<Location>();
|
gateBlockLocations = new HashSet<Location>();
|
||||||
@ -106,29 +298,27 @@ public class Gate extends BaseGate implements ConfigurationSerializable
|
|||||||
for (Map<String, Object> sgb : serializedGateBlocks) {
|
for (Map<String, Object> sgb : serializedGateBlocks) {
|
||||||
gateBlockLocations.add(LocationUtil.deserializeLocation(sgb));
|
gateBlockLocations.add(LocationUtil.deserializeLocation(sgb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gateFrameBlocks = FloodUtil.getFrameWithLocations(gateBlockLocations);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Plugin.log("ERROR: Failed to load gate '" + id + "'! (" + e.getMessage() + ")");
|
Plugin.log("ERROR: Failed to load gate '" + id + "'! (" + e.getMessage() + ")");
|
||||||
Plugin.log("NOTE: This gate will be removed from 'gates.yml' and added to 'invalid_gates.yml'!");
|
Plugin.log("NOTE: This gate will be removed from 'gates.yml' and added to 'invalid_gates.yml'!");
|
||||||
|
|
||||||
Plugin.instance.storeInvalidGate(map);
|
Plugin.getPlugin().getGatesManager().storeInvalidGate(map);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
instances.put(id, this);
|
try {
|
||||||
|
validate(); // make sure to not write invalid stuff to disk
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
Plugin.log("The loaded gate " + this.getId() + " seems to be not valid: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, Object> serialize()
|
public Map<String, Object> serialize()
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
validate(); // make sure to not write invalid stuff to disk
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
Plugin.log("Gate " + this.getId() + " seems to be not valid. It got closed before serializing!");
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> retVal = new HashMap<String, Object>();
|
Map<String, Object> retVal = new HashMap<String, Object>();
|
||||||
|
|
||||||
retVal.put(idKey, id);
|
retVal.put(idKey, id);
|
||||||
@ -157,58 +347,4 @@ public class Gate extends BaseGate implements ConfigurationSerializable
|
|||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ENTITY MANAGEMENT
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static Gate get(String id)
|
|
||||||
{
|
|
||||||
return instances.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean exists(String id)
|
|
||||||
{
|
|
||||||
return instances.containsKey(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Gate create(String id) throws Exception
|
|
||||||
{
|
|
||||||
Gate gate = new Gate(id);
|
|
||||||
|
|
||||||
instances.put(gate.id, gate);
|
|
||||||
return gate;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void rename(String oldId, String newId) throws Exception
|
|
||||||
{
|
|
||||||
Gate gate = get(oldId);
|
|
||||||
|
|
||||||
gate.setId(newId);
|
|
||||||
|
|
||||||
instances.remove(oldId);
|
|
||||||
instances.put(gate.id, gate);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void delete(String id)
|
|
||||||
{
|
|
||||||
Gate g = get(id);
|
|
||||||
|
|
||||||
if (g != null) {
|
|
||||||
g.emptyGate();
|
|
||||||
}
|
|
||||||
|
|
||||||
instances.remove(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Collection<Gate> getAll()
|
|
||||||
{
|
|
||||||
return instances.values();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
513
src/de/craftinc/gates/GatesManager.java
Normal file
513
src/de/craftinc/gates/GatesManager.java
Normal file
@ -0,0 +1,513 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import de.craftinc.gates.persistence.MigrationUtil;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.SimpleChunk;
|
||||||
|
import de.craftinc.gates.util.SimpleLocation;
|
||||||
|
|
||||||
|
|
||||||
|
public class GatesManager
|
||||||
|
{
|
||||||
|
protected File gatesConfigFile;
|
||||||
|
protected FileConfiguration gatesConfig;
|
||||||
|
protected static final String gatesPath = "gates"; // path to gates inside the yaml file
|
||||||
|
protected static final String storageVersionPath = "version";
|
||||||
|
protected static final int storageVersion = 1;
|
||||||
|
|
||||||
|
protected int chunkRadius;
|
||||||
|
|
||||||
|
protected Map<String, Gate> gatesById;
|
||||||
|
protected Map<SimpleChunk, Set<Gate>> gatesByChunk;
|
||||||
|
protected Map<SimpleLocation, Gate> gatesByLocation;
|
||||||
|
protected Map<SimpleLocation, Gate> gatesByFrameLocation;
|
||||||
|
|
||||||
|
protected List<Gate> gates;
|
||||||
|
|
||||||
|
protected boolean storageFileIsInvalid = false;
|
||||||
|
|
||||||
|
|
||||||
|
public Gate getGateWithId(final String id)
|
||||||
|
{
|
||||||
|
return gatesById.get(id.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Set<Gate> getNearbyGates(final Chunk chunk)
|
||||||
|
{
|
||||||
|
SimpleChunk simpleChunk = new SimpleChunk(chunk);
|
||||||
|
return gatesByChunk.get(simpleChunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Gate getGateAtLocation(final Location location)
|
||||||
|
{
|
||||||
|
SimpleLocation simpleLocation = new SimpleLocation(location);
|
||||||
|
return gatesByLocation.get(simpleLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Gate getGateAtFrameLocation(final Location location)
|
||||||
|
{
|
||||||
|
SimpleLocation simpleLocation = new SimpleLocation(location);
|
||||||
|
return gatesByFrameLocation.get(simpleLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void saveGatesToDisk()
|
||||||
|
{
|
||||||
|
if (storageFileIsInvalid) {
|
||||||
|
Plugin.log(Level.SEVERE, "ERROR: Not saving gates to disk. Storage file is invalid or corrupted!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gatesConfig.set(gatesPath, gates);
|
||||||
|
gatesConfig.set(storageVersionPath, storageVersion);
|
||||||
|
|
||||||
|
try {
|
||||||
|
gatesConfig.save(gatesConfigFile);
|
||||||
|
Plugin.log("Saved gates to disk.");
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
Plugin.log(Level.SEVERE, "ERROR: Could not save gates to disk.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public boolean loadGatesFromDisk()
|
||||||
|
{
|
||||||
|
this.gatesConfigFile = new File(Plugin.getPlugin().getDataFolder(), "gates.yml");
|
||||||
|
|
||||||
|
if(!this.gatesConfigFile.exists()) {
|
||||||
|
try {
|
||||||
|
boolean isNew = this.gatesConfigFile.createNewFile();
|
||||||
|
|
||||||
|
if (isNew) {
|
||||||
|
Plugin.log(Level.FINEST, "Created gate storage file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
this.storageFileIsInvalid = true;
|
||||||
|
Plugin.log(Level.SEVERE, "Cannot create gate storage file! No gates will be persisted.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.gatesConfig = new YamlConfiguration();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.gatesConfig.load(this.gatesConfigFile);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
this.storageFileIsInvalid = true;
|
||||||
|
Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded. Plugin will be disabled! (" + Arrays.toString(e.getStackTrace()) + ")");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.gates = (List<Gate>)gatesConfig.getList(gatesPath);
|
||||||
|
|
||||||
|
if (this.gates == null) {
|
||||||
|
this.gates = new ArrayList<Gate>();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object o : this.gates) {
|
||||||
|
|
||||||
|
if (!(o instanceof Gate)) {
|
||||||
|
this.storageFileIsInvalid = true;
|
||||||
|
Plugin.log(Level.SEVERE, "Gate file on disk is invalid. No gates loaded. Plugin will be disabled! (Invalid gate class detected)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Gate g : this.gates) {
|
||||||
|
try {
|
||||||
|
g.validate();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
try {
|
||||||
|
g.setOpen(false);
|
||||||
|
}
|
||||||
|
catch (Exception ignored) { }
|
||||||
|
|
||||||
|
Plugin.log(Level.FINER, "closed gate '" + g.getId() + "' reason: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fillGatesById();
|
||||||
|
fillGatesByChunk();
|
||||||
|
fillGatesByLocation();
|
||||||
|
fillGatesByFrameLocation();
|
||||||
|
|
||||||
|
Plugin.log("Loaded " + this.gates.size() + " gates.");
|
||||||
|
|
||||||
|
// migration
|
||||||
|
int fileStorageVersion = gatesConfig.getInt(storageVersionPath);
|
||||||
|
|
||||||
|
if (fileStorageVersion > storageVersion) {
|
||||||
|
this.storageFileIsInvalid = true;
|
||||||
|
Plugin.log(Level.SEVERE, "Unsupported storage version detected! Make sure you have the latest version of Craft Inc. Gates installed. Plugin will be disabled!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileStorageVersion < storageVersion && !this.gates.isEmpty()) {
|
||||||
|
Plugin.log("Outdated storage version detected. Performing data migration...");
|
||||||
|
boolean success = MigrationUtil.performMigration(fileStorageVersion, storageVersion, this.gates);
|
||||||
|
|
||||||
|
this.storageFileIsInvalid = !success;
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected int getChunkRadius()
|
||||||
|
{
|
||||||
|
if (this.chunkRadius == 0) {
|
||||||
|
this.chunkRadius = Plugin.getPlugin().getConfig().getInt(Plugin.confPlayerGateBlockUpdateRadiusKey);
|
||||||
|
this.chunkRadius = this.chunkRadius >> 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.chunkRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void fillGatesById()
|
||||||
|
{
|
||||||
|
gatesById = new HashMap<String, Gate>((int)(gates.size() * 1.25));
|
||||||
|
|
||||||
|
for (Gate g : gates) {
|
||||||
|
this.addGateWithId(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void fillGatesByChunk()
|
||||||
|
{
|
||||||
|
HashSet<SimpleChunk> chunksUsedByGates = new HashSet<SimpleChunk>();
|
||||||
|
|
||||||
|
for (Gate g : gates) {
|
||||||
|
|
||||||
|
if (g.getLocation() != null) {
|
||||||
|
|
||||||
|
Chunk c = g.getLocation().getChunk();
|
||||||
|
|
||||||
|
int x = c.getX();
|
||||||
|
int z = c.getZ();
|
||||||
|
|
||||||
|
for (int i = x-getChunkRadius(); i < x+getChunkRadius(); i++) {
|
||||||
|
|
||||||
|
for (int j = z-getChunkRadius(); j < z+getChunkRadius(); j++) {
|
||||||
|
|
||||||
|
chunksUsedByGates.add(new SimpleChunk(i, j, c.getWorld()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gatesByChunk = new HashMap<SimpleChunk, Set<Gate>>((int)(chunksUsedByGates.size() * 1.25));
|
||||||
|
|
||||||
|
for (Gate g : gates) {
|
||||||
|
this.addGateByChunk(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void fillGatesByLocation()
|
||||||
|
{
|
||||||
|
Set<Location> gateBlocks = new HashSet<Location>();
|
||||||
|
|
||||||
|
for (Gate g : gates) {
|
||||||
|
|
||||||
|
for (Location l : g.getGateBlockLocations()) {
|
||||||
|
gateBlocks.add(l);
|
||||||
|
|
||||||
|
Location headLocation = new Location(l.getWorld(),
|
||||||
|
l.getX(),
|
||||||
|
l.getY()+1,
|
||||||
|
l.getZ());
|
||||||
|
|
||||||
|
gateBlocks.add(headLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gatesByLocation = new HashMap<SimpleLocation, Gate>((int)(gateBlocks.size()*1.25));
|
||||||
|
|
||||||
|
for (Gate g : gates) {
|
||||||
|
this.addGateByLocations(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void fillGatesByFrameLocation()
|
||||||
|
{
|
||||||
|
int numFrameBlocks = 0;
|
||||||
|
|
||||||
|
for (Gate g : gates) {
|
||||||
|
numFrameBlocks += g.gateFrameBlocks.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
gatesByFrameLocation = new HashMap<SimpleLocation, Gate>((int)(numFrameBlocks*1.25));
|
||||||
|
|
||||||
|
for (Gate g : gates) {
|
||||||
|
this.addGateByFrameLocations(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void removeGateById(final String id)
|
||||||
|
{
|
||||||
|
gatesById.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void addGateWithId(final Gate g)
|
||||||
|
{
|
||||||
|
gatesById.put(g.getId(), g);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void removeGateByLocation(final Set<Location> gateBlocks)
|
||||||
|
{
|
||||||
|
if (gateBlocks != null) {
|
||||||
|
|
||||||
|
for (Location l : gateBlocks) {
|
||||||
|
|
||||||
|
SimpleLocation sl = new SimpleLocation(l);
|
||||||
|
gatesByLocation.remove(sl);
|
||||||
|
|
||||||
|
SimpleLocation headLocation = new SimpleLocation(l, true);
|
||||||
|
gatesByLocation.remove(headLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void removeGateByFrameLocation(final Set<Block> gateFrameBlocks)
|
||||||
|
{
|
||||||
|
if (gateFrameBlocks != null) {
|
||||||
|
|
||||||
|
for (Block block : gateFrameBlocks) {
|
||||||
|
SimpleLocation sl = new SimpleLocation(block.getLocation());
|
||||||
|
gatesByFrameLocation.remove(sl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void addGateByLocations(final Gate g)
|
||||||
|
{
|
||||||
|
for (Location l : g.getGateBlockLocations()) {
|
||||||
|
|
||||||
|
SimpleLocation sl = new SimpleLocation(l);
|
||||||
|
gatesByLocation.put(sl, g);
|
||||||
|
|
||||||
|
SimpleLocation headLocation = new SimpleLocation(l, true);
|
||||||
|
gatesByLocation.put(headLocation, g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void addGateByFrameLocations(final Gate g)
|
||||||
|
{
|
||||||
|
for (Block block : g.getGateFrameBlocks()) {
|
||||||
|
SimpleLocation sl = new SimpleLocation(block.getLocation());
|
||||||
|
gatesByFrameLocation.put(sl, g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void removeGateFromChunk(final Gate g, final Location l)
|
||||||
|
{
|
||||||
|
if (l != null) {
|
||||||
|
|
||||||
|
Chunk c = l.getChunk();
|
||||||
|
int x = c.getX();
|
||||||
|
int z = c.getZ();
|
||||||
|
|
||||||
|
for (int i = x-getChunkRadius(); i < x+getChunkRadius(); i++) {
|
||||||
|
|
||||||
|
for (int j = z-getChunkRadius(); j < z+getChunkRadius(); j++) {
|
||||||
|
|
||||||
|
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
|
||||||
|
Set<Gate> gatesInChunk = gatesByChunk.get(sc);
|
||||||
|
|
||||||
|
if (gatesInChunk != null) {
|
||||||
|
gatesInChunk.remove(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void addGateByChunk(final Gate g)
|
||||||
|
{
|
||||||
|
Location gateLocation = g.getLocation();
|
||||||
|
|
||||||
|
if (gateLocation != null) {
|
||||||
|
|
||||||
|
Chunk c = g.getLocation().getChunk();
|
||||||
|
int x = c.getX();
|
||||||
|
int z = c.getZ();
|
||||||
|
|
||||||
|
for (int i = x-getChunkRadius(); i < x+getChunkRadius(); i++) {
|
||||||
|
|
||||||
|
for (int j = z-getChunkRadius(); j < z+getChunkRadius(); j++) {
|
||||||
|
|
||||||
|
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
|
||||||
|
|
||||||
|
Set<Gate> gatesForC = gatesByChunk.get(sc);
|
||||||
|
|
||||||
|
if (gatesForC == null) {
|
||||||
|
gatesForC = new HashSet<Gate>(); // NOTE: not optimizing size here
|
||||||
|
gatesByChunk.put(sc, gatesForC);
|
||||||
|
}
|
||||||
|
|
||||||
|
gatesForC.add(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void storeInvalidGate(Map<String, Object> map)
|
||||||
|
{
|
||||||
|
File invalidGatesFile = new File(Plugin.getPlugin().getDataFolder(), "invalid_gates.yml");
|
||||||
|
Boolean invalidGatesFileExists = invalidGatesFile.exists();
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileWriter fileWriter = new FileWriter(invalidGatesFile, true);
|
||||||
|
|
||||||
|
if (!invalidGatesFileExists) {
|
||||||
|
fileWriter.write("gates:\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fileWriter.write("- ==: ");
|
||||||
|
fileWriter.write(map.get("==").toString() + "\n");
|
||||||
|
map.remove("==");
|
||||||
|
|
||||||
|
fileWriter.write("\topen: false\n");
|
||||||
|
map.remove("open");
|
||||||
|
|
||||||
|
fileWriter.write("\tgateBlocks: []\n");
|
||||||
|
map.remove("gateBlocks");
|
||||||
|
|
||||||
|
|
||||||
|
for (String key : map.keySet()) {
|
||||||
|
Object value = map.get(key);
|
||||||
|
|
||||||
|
fileWriter.write("\t" + key + ": ");
|
||||||
|
|
||||||
|
if (value instanceof Map) {
|
||||||
|
fileWriter.write("\n");
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> valueMap = (Map<String, Object>)value;
|
||||||
|
|
||||||
|
for (String k : valueMap.keySet()) {
|
||||||
|
Object v = valueMap.get(k);
|
||||||
|
|
||||||
|
fileWriter.write("\t\t" + k + ": " + v.toString() + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fileWriter.write(value.toString() + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileWriter.close();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
Plugin.log("ERROR: Could not save invalid gates to disk. Reason: \n" + Arrays.toString(e.getStackTrace()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void handleGateIdChange(final Gate g, final String oldId)
|
||||||
|
{
|
||||||
|
this.removeGateById(oldId);
|
||||||
|
this.addGateWithId(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void handleGateLocationChange(final Gate g,
|
||||||
|
final Location oldLocation,
|
||||||
|
final Set<Location> oldGateBlockLocations,
|
||||||
|
final Set<Block> oldGateFrameBlocks)
|
||||||
|
{
|
||||||
|
this.removeGateFromChunk(g, oldLocation);
|
||||||
|
this.addGateByChunk(g);
|
||||||
|
|
||||||
|
this.removeGateByLocation(oldGateBlockLocations);
|
||||||
|
this.addGateByLocations(g);
|
||||||
|
|
||||||
|
this.removeGateByFrameLocation(oldGateFrameBlocks);
|
||||||
|
this.addGateByFrameLocations(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void handleNewGate(final Gate g)
|
||||||
|
{
|
||||||
|
this.gates.add(g);
|
||||||
|
|
||||||
|
this.addGateByChunk(g);
|
||||||
|
this.addGateByLocations(g);
|
||||||
|
this.addGateWithId(g);
|
||||||
|
this.addGateByFrameLocations(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void handleDeletion(final Gate g)
|
||||||
|
{
|
||||||
|
this.gates.remove(g);
|
||||||
|
|
||||||
|
this.removeGateById(g.getId());
|
||||||
|
this.removeGateFromChunk(g, g.getLocation());
|
||||||
|
this.removeGateByLocation(g.getGateBlockLocations());
|
||||||
|
this.removeGateByFrameLocation(g.getGateFrameBlocks());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean gateExists(final String id)
|
||||||
|
{
|
||||||
|
return gatesById.containsKey(id.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Gate> allGates ()
|
||||||
|
{
|
||||||
|
return gates;
|
||||||
|
}
|
||||||
|
}
|
@ -1,57 +1,68 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates;
|
package de.craftinc.gates;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.*;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
import de.craftinc.gates.listeners.*;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import de.craftinc.gates.commands.*;
|
import de.craftinc.gates.commands.*;
|
||||||
import de.craftinc.gates.listeners.PluginBlockListener;
|
|
||||||
import de.craftinc.gates.listeners.PluginPlayerListener;
|
|
||||||
import de.craftinc.gates.listeners.PluginPortalListener;
|
|
||||||
|
|
||||||
|
|
||||||
public class Plugin extends JavaPlugin
|
public class Plugin extends JavaPlugin
|
||||||
{
|
{
|
||||||
public static Plugin instance;
|
|
||||||
|
|
||||||
public static final String permissionInfo = "craftincgates.info";
|
public static final String permissionInfo = "craftincgates.info";
|
||||||
public static final String permissionManage = "craftincgates.manage";
|
public static final String permissionManage = "craftincgates.manage";
|
||||||
// public static final String permissionAll = "craftincgates.*";
|
|
||||||
public static final String permissionUse = "craftincgates.use";
|
public static final String permissionUse = "craftincgates.use";
|
||||||
|
|
||||||
public static Permission permission = null;
|
public static final String confMaxGateBlocksKey = "maxGateBlocks";
|
||||||
|
public static final String confPlayerGateBlockUpdateRadiusKey = "playerGateBlockUpdateRadius";
|
||||||
|
public static final String confCheckForBrokenGateFramesKey = "checkForBrokenGateFrames";
|
||||||
|
public static final String confGateTeleportMessageKey = "gateTeleportMessage";
|
||||||
|
public static final String confShowTeleportMessageKey = "showTeleportMessage";
|
||||||
|
public static final String confGateTeleportNoPermissionMessageKey = "gateTeleportNoPermissionMessage";
|
||||||
|
public static final String confShowTeleportNoPermissionMessageKey = "showTeleportNoPermissionMessage";
|
||||||
|
public static final String confSaveOnChangesKey = "saveOnChanges";
|
||||||
|
|
||||||
public PluginPlayerListener playerListener = new PluginPlayerListener();
|
private static Plugin instance;
|
||||||
public PluginBlockListener blockListener = new PluginBlockListener();
|
private static Permission permission;
|
||||||
public PluginPortalListener portalListener = new PluginPortalListener();
|
|
||||||
|
|
||||||
private File gatesConfigFile;
|
protected String baseCommand;
|
||||||
private FileConfiguration gatesConfig;
|
protected List<BaseCommand> commands = new ArrayList<BaseCommand>();
|
||||||
|
protected GatesManager gatesManager = new GatesManager();
|
||||||
|
|
||||||
private String baseCommand;
|
protected PlayerMoveListener moveListener = new PlayerMoveListener();
|
||||||
|
protected PlayerTeleportListener teleportListener = new PlayerTeleportListener();
|
||||||
private String gatesPath = "gates";
|
protected PlayerRespawnListener respawnListener = new PlayerRespawnListener();
|
||||||
|
protected PlayerChangedWorldListener worldChangeListener = new PlayerChangedWorldListener();
|
||||||
|
protected PlayerJoinListener joinListener = new PlayerJoinListener();
|
||||||
// Commands
|
protected BlockBreakListener blockBreakListener = new BlockBreakListener();
|
||||||
public List<BaseCommand> commands = new ArrayList<BaseCommand>();
|
|
||||||
|
|
||||||
|
|
||||||
public Plugin()
|
public Plugin()
|
||||||
@ -60,6 +71,18 @@ public class Plugin extends JavaPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Plugin getPlugin()
|
||||||
|
{
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public GatesManager getGatesManager()
|
||||||
|
{
|
||||||
|
return gatesManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad()
|
public void onLoad()
|
||||||
{
|
{
|
||||||
@ -67,7 +90,7 @@ public class Plugin extends JavaPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setupPermissions()
|
protected void setupPermissions()
|
||||||
{
|
{
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
return;
|
return;
|
||||||
@ -91,7 +114,8 @@ public class Plugin extends JavaPlugin
|
|||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
// Save gates
|
// Save gates
|
||||||
saveGates();
|
gatesManager.saveGatesToDisk();
|
||||||
|
|
||||||
log("Disabled");
|
log("Disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,48 +123,57 @@ public class Plugin extends JavaPlugin
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
|
// Setup configuration
|
||||||
|
this.saveDefaultConfig();
|
||||||
|
|
||||||
// Setup permissions
|
// Setup permissions
|
||||||
setupPermissions();
|
setupPermissions();
|
||||||
|
|
||||||
// Add the commands
|
// Add the commands
|
||||||
commands.add(new CommandHelp());
|
commands.add(new CommandHelp());
|
||||||
commands.add(new CommandCreate());
|
commands.add(new CommandNew());
|
||||||
commands.add(new CommandDelete());
|
commands.add(new CommandRemove());
|
||||||
commands.add(new CommandSetLocation());
|
commands.add(new CommandLocation());
|
||||||
commands.add(new CommandSetExit());
|
commands.add(new CommandExit());
|
||||||
commands.add(new CommandOpen());
|
commands.add(new CommandOpen());
|
||||||
commands.add(new CommandRename());
|
commands.add(new CommandRename());
|
||||||
commands.add(new CommandClose());
|
commands.add(new CommandClose());
|
||||||
commands.add(new CommandList());
|
commands.add(new CommandList());
|
||||||
commands.add(new CommandInfo());
|
commands.add(new CommandInfo());
|
||||||
commands.add(new CommandSetHidden());
|
commands.add(new CommandHide());
|
||||||
commands.add(new CommandSetVisible());
|
commands.add(new CommandUnhide());
|
||||||
|
|
||||||
|
|
||||||
// Register events
|
// Register events
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
this.registerEventListeners();
|
||||||
pm.registerEvents(this.playerListener, this);
|
|
||||||
pm.registerEvents(this.blockListener, this);
|
|
||||||
pm.registerEvents(this.portalListener, this);
|
|
||||||
|
|
||||||
// Load gates
|
// Load gates
|
||||||
this.gatesConfigFile = new File(getDataFolder(), "gates.yml");
|
boolean success = gatesManager.loadGatesFromDisk();
|
||||||
|
|
||||||
if(!this.gatesConfigFile.exists())
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
this.gatesConfigFile.createNewFile();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log(Level.SEVERE, "Cannot create gate config file! No gates will be persisted.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.gatesConfig = YamlConfiguration.loadConfiguration(gatesConfigFile);
|
|
||||||
|
|
||||||
loadGates();
|
|
||||||
|
|
||||||
|
if (success) {
|
||||||
log("Enabled");
|
log("Enabled");
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
|
pm.disablePlugin(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void registerEventListeners()
|
||||||
|
{
|
||||||
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
|
|
||||||
|
pm.registerEvents(this.moveListener, this);
|
||||||
|
pm.registerEvents(this.teleportListener, this);
|
||||||
|
pm.registerEvents(this.respawnListener, this);
|
||||||
|
pm.registerEvents(this.worldChangeListener, this);
|
||||||
|
pm.registerEvents(this.joinListener, this);
|
||||||
|
|
||||||
|
if (getConfig().getBoolean(confCheckForBrokenGateFramesKey)) {
|
||||||
|
pm.registerEvents(this.blockBreakListener, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -189,7 +222,8 @@ public class Plugin extends JavaPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("Unknown gate-command \"" + commandName + "\". Try " + "/" + getBaseCommand() + " help");
|
sender.sendMessage(ChatColor.RED + "Unknown gate-command \"" + commandName + "\"." +
|
||||||
|
ChatColor.GREEN + " Try " + "/" + getBaseCommand() + " help");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -202,89 +236,13 @@ public class Plugin extends JavaPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void log(Level level, String msg) {
|
public static void log(Level level, String msg)
|
||||||
|
{
|
||||||
Logger.getLogger("Minecraft").log(level, "["+instance.getDescription().getFullName()+"] "+msg);
|
Logger.getLogger("Minecraft").log(level, "["+instance.getDescription().getFullName()+"] "+msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Saving and Loading Gates
|
|
||||||
*/
|
|
||||||
public void loadGates()
|
|
||||||
{
|
|
||||||
File gatesFile = new File(getDataFolder(), "gates.yml");
|
|
||||||
FileConfiguration gatesConfig = YamlConfiguration.loadConfiguration(gatesFile);
|
|
||||||
|
|
||||||
gatesConfig.getList(gatesPath); // this will create all the gates
|
public static Permission getPermission() {
|
||||||
}
|
return permission;
|
||||||
|
|
||||||
|
|
||||||
public void saveGates()
|
|
||||||
{
|
|
||||||
gatesConfig.set(gatesPath, new ArrayList<Object>(Gate.getAll()));
|
|
||||||
|
|
||||||
try {
|
|
||||||
gatesConfig.save(gatesConfigFile);
|
|
||||||
log("Saved gates to disk.");
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
log("ERROR: Could not save gates to disk.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void storeInvalidGate(Map<String, Object> map)
|
|
||||||
{
|
|
||||||
File invalidGatesFile = new File(getDataFolder(), "invalid_gates.yml");
|
|
||||||
Boolean invalidGatesFileExists = invalidGatesFile.exists();
|
|
||||||
|
|
||||||
try {
|
|
||||||
FileWriter fileWriter = new FileWriter(invalidGatesFile, true);
|
|
||||||
|
|
||||||
if (!invalidGatesFileExists) {
|
|
||||||
fileWriter.write("gates:\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fileWriter.write("- ==: ");
|
|
||||||
fileWriter.write(map.get("==").toString() + "\n");
|
|
||||||
map.remove("==");
|
|
||||||
|
|
||||||
fileWriter.write("\topen: false\n");
|
|
||||||
map.remove("open");
|
|
||||||
|
|
||||||
fileWriter.write("\tgateBlocks: []\n");
|
|
||||||
map.remove("gateBlocks");
|
|
||||||
|
|
||||||
|
|
||||||
for (String key : map.keySet()) {
|
|
||||||
Object value = map.get(key);
|
|
||||||
|
|
||||||
fileWriter.write("\t" + key + ": ");
|
|
||||||
|
|
||||||
if (value instanceof Map) {
|
|
||||||
fileWriter.write("\n");
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> valueMap = (Map<String, Object>)value;
|
|
||||||
|
|
||||||
for (String k : valueMap.keySet()) {
|
|
||||||
Object v = valueMap.get(k);
|
|
||||||
|
|
||||||
fileWriter.write("\t\t" + k + ": " + v.toString() + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fileWriter.write(value.toString() + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fileWriter.close();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
log("ERROR: Could not save invalid gates to disk.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -8,6 +24,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
import de.craftinc.gates.Gate;
|
||||||
|
import de.craftinc.gates.GatesManager;
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
import de.craftinc.gates.util.TextUtil;
|
import de.craftinc.gates.util.TextUtil;
|
||||||
|
|
||||||
@ -52,8 +69,8 @@ public abstract class BaseCommand
|
|||||||
|
|
||||||
this.perform();
|
this.perform();
|
||||||
|
|
||||||
if (this.shouldPersistToDisk) {
|
if (this.shouldPersistToDisk && Plugin.getPlugin().getConfig().getBoolean(Plugin.confSaveOnChangesKey)) {
|
||||||
Plugin.instance.saveGates();
|
Plugin.getPlugin().getGatesManager().saveGatesToDisk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,48 +92,36 @@ public abstract class BaseCommand
|
|||||||
|
|
||||||
protected boolean validateCall()
|
protected boolean validateCall()
|
||||||
{
|
{
|
||||||
boolean allParamtertersThere = parameters.size() >= requiredParameters.size();
|
boolean allParametersThere = parameters.size() >= requiredParameters.size();
|
||||||
boolean senderIsPlayer = this.sender instanceof Player;
|
boolean senderIsPlayer = this.sender instanceof Player;
|
||||||
boolean hasGateParameter = false;
|
boolean hasGateParameter = false;
|
||||||
|
|
||||||
if (this.hasGateParam == true && this.parameters.size() > 0 && this.setGateUsingParameter(this.parameters.get(0))) {
|
if (this.hasGateParam && this.parameters.size() > 0 && this.setGateUsingParameter(this.parameters.get(0))) {
|
||||||
hasGateParameter = true;
|
hasGateParameter = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean senderHasPermission = this.hasPermission();
|
boolean senderHasPermission = this.hasPermission();
|
||||||
|
boolean valid;
|
||||||
|
|
||||||
|
if (this.senderMustBePlayer && !senderIsPlayer) {
|
||||||
boolean valid = false;
|
|
||||||
|
|
||||||
if (this.senderMustBePlayer && !senderIsPlayer)
|
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + "This command can only be used by ingame players.");
|
sendMessage(ChatColor.RED + "This command can only be used by ingame players.");
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
else if (!allParamtertersThere)
|
else {
|
||||||
{
|
if (!allParametersThere) {
|
||||||
sendMessage(ChatColor.RED + "Some parameters are missing! " + ChatColor.AQUA + "Usage: " + this.getUseageTemplate(true));
|
sendMessage(ChatColor.RED + "Some parameters are missing! " + ChatColor.AQUA + "Usage: " + this.getUsageTemplate(true));
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
else if (!senderHasPermission && this.hasGateParam)
|
else if ((!senderHasPermission && this.hasGateParam) ||
|
||||||
{
|
(!senderHasPermission) ||
|
||||||
|
(this.hasGateParam && !hasGateParameter)) {
|
||||||
|
|
||||||
sendMessage(ChatColor.RED + "You either provided a invalid gate or do not have permission to " + this.helpDescription.toLowerCase());
|
sendMessage(ChatColor.RED + "You either provided a invalid gate or do not have permission to " + this.helpDescription.toLowerCase());
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
else if (!senderHasPermission)
|
else {
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + "You lack the permissions to " + this.helpDescription.toLowerCase());
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (this.hasGateParam && !hasGateParameter)
|
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + "There exists no gate with id " + this.parameters.get(0));
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
valid = true;
|
valid = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
@ -125,13 +130,13 @@ public abstract class BaseCommand
|
|||||||
|
|
||||||
protected boolean setGateUsingParameter(String param)
|
protected boolean setGateUsingParameter(String param)
|
||||||
{
|
{
|
||||||
if (!Gate.exists(param))
|
GatesManager gateManager = Plugin.getPlugin().getGatesManager();
|
||||||
{
|
|
||||||
|
if (!gateManager.gateExists(param)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
gate = gateManager.getGateWithId(param);
|
||||||
gate = Gate.get(param);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,55 +147,41 @@ public abstract class BaseCommand
|
|||||||
*/
|
*/
|
||||||
protected boolean hasPermission()
|
protected boolean hasPermission()
|
||||||
{
|
{
|
||||||
if (Plugin.permission == null) // fallback <EFBFBD> use the standard bukkit permission system
|
if (Plugin.getPermission() == null) { // fallback - use the standard bukkit permission system
|
||||||
{
|
|
||||||
return this.sender.hasPermission(this.requiredPermission);
|
return this.sender.hasPermission(this.requiredPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(this.sender instanceof Player)) {
|
||||||
Player p = null;
|
// sender is no player - there is no information about the senders locations
|
||||||
|
return Plugin.getPermission().has(this.sender, this.requiredPermission);
|
||||||
if (this.sender instanceof Player)
|
|
||||||
{
|
|
||||||
p = (Player) this.sender;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// sender is no player <20> there is no information about the senders locations
|
|
||||||
return Plugin.permission.has(this.sender, this.requiredPermission);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Player p = (Player) this.sender;
|
||||||
boolean hasPermission = false;
|
boolean hasPermission = false;
|
||||||
|
|
||||||
if (this.requiredPermission.equals(Plugin.permissionInfo))
|
if (this.requiredPermission.equals(Plugin.permissionInfo)) {
|
||||||
{
|
|
||||||
if (this.hasGateParam)
|
if (this.hasGateParam) {
|
||||||
{
|
|
||||||
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
hasPermission = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
||||||
hasPermission = Plugin.permission.has(p.getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (this.requiredPermission.equals(Plugin.permissionUse) )
|
else if (this.requiredPermission.equals(Plugin.permissionUse) ) {
|
||||||
{
|
|
||||||
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
||||||
}
|
}
|
||||||
else if (this.requiredPermission.equals(Plugin.permissionManage))
|
else if (this.requiredPermission.equals(Plugin.permissionManage)) {
|
||||||
{
|
|
||||||
if (this.needsPermissionAtCurrentLocation && this.hasGateParam)
|
if (this.needsPermissionAtCurrentLocation && this.hasGateParam) {
|
||||||
{
|
boolean hasPersmissionAtCurrentLocation = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
||||||
boolean hasPersmissionAtCurrentLocation = Plugin.permission.has(p.getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
hasPermission = hasPersmissionAtCurrentLocation && this.hasPermissionAtGateLocationAndExit(p);
|
hasPermission = hasPersmissionAtCurrentLocation && this.hasPermissionAtGateLocationAndExit(p);
|
||||||
}
|
}
|
||||||
else if (this.needsPermissionAtCurrentLocation)
|
else if (this.needsPermissionAtCurrentLocation) {
|
||||||
{
|
hasPermission = Plugin.getPermission().has(p.getWorld(), p.getName(), this.requiredPermission);
|
||||||
hasPermission = Plugin.permission.has(p.getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
hasPermission = this.hasPermissionAtGateLocationAndExit(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,29 +192,12 @@ public abstract class BaseCommand
|
|||||||
|
|
||||||
protected boolean hasPermissionAtGateLocationAndExit(Player p)
|
protected boolean hasPermissionAtGateLocationAndExit(Player p)
|
||||||
{
|
{
|
||||||
if (this.gate == null || p == null) // make sure we don't run into a nullpointer exception
|
if (this.gate == null || p == null) { // make sure we don't run into a nullpointer exception
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean permAtLocation;
|
boolean permAtLocation = this.gate.getLocation() == null || Plugin.getPermission().has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
||||||
|
boolean permAtExit = this.gate.getExit() == null || Plugin.getPermission().has(this.gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
||||||
if (this.gate.getLocation() == null) {
|
|
||||||
permAtLocation = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
permAtLocation = Plugin.permission.has(this.gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
boolean permAtExit;
|
|
||||||
|
|
||||||
if (this.gate.getExit() == null) {
|
|
||||||
permAtExit = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
permAtExit = Plugin.permission.has(this.gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
|
||||||
}
|
|
||||||
|
|
||||||
return permAtLocation & permAtExit;
|
return permAtLocation & permAtExit;
|
||||||
}
|
}
|
||||||
@ -232,14 +206,15 @@ public abstract class BaseCommand
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// Help and usage description
|
// Help and usage description
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
protected String getUsageTemplate(boolean withColor, boolean withDescription) {
|
protected String getUsageTemplate(boolean withColor, boolean withDescription)
|
||||||
|
{
|
||||||
String ret = "";
|
String ret = "";
|
||||||
|
|
||||||
if (withColor) {
|
if (withColor) {
|
||||||
ret += ChatColor.AQUA;
|
ret += ChatColor.AQUA;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += "/" + Plugin.instance.getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",")+" ";
|
ret += "/" + Plugin.getPlugin().getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",")+" ";
|
||||||
|
|
||||||
List<String> parts = new ArrayList<String>();
|
List<String> parts = new ArrayList<String>();
|
||||||
|
|
||||||
@ -269,11 +244,8 @@ public abstract class BaseCommand
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getUseageTemplate(boolean withColor) {
|
protected String getUsageTemplate(boolean withColor)
|
||||||
|
{
|
||||||
return getUsageTemplate(withColor, false);
|
return getUsageTemplate(withColor, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getUseageTemplate() {
|
|
||||||
return getUseageTemplate(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -10,7 +26,7 @@ public abstract class BaseLocationCommand extends BaseCommand
|
|||||||
protected Location getValidPlayerLocation()
|
protected Location getValidPlayerLocation()
|
||||||
{
|
{
|
||||||
// The player might stand in a half block or a sign or whatever
|
// The player might stand in a half block or a sign or whatever
|
||||||
// Therefore we load som extra locations and blocks
|
// Therefore we load some extra locations and blocks
|
||||||
Block playerBlock = player.getLocation().getBlock();
|
Block playerBlock = player.getLocation().getBlock();
|
||||||
Block upBlock = playerBlock.getRelative(BlockFace.UP);
|
Block upBlock = playerBlock.getRelative(BlockFace.UP);
|
||||||
|
|
||||||
|
@ -1,7 +1,24 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
@ -33,6 +50,7 @@ public class CommandClose extends BaseCommand
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
gate.setOpen(false);
|
gate.setOpen(false);
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
sendMessage(ChatColor.GREEN + "The gate was closed.");
|
sendMessage(ChatColor.GREEN + "The gate was closed.");
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
@ -41,8 +59,6 @@ public class CommandClose extends BaseCommand
|
|||||||
Plugin.log(Level.WARNING, e.getMessage());
|
Plugin.log(Level.WARNING, e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
package de.craftinc.gates.commands;
|
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
|
||||||
import de.craftinc.gates.Plugin;
|
|
||||||
|
|
||||||
|
|
||||||
public class CommandCreate extends BaseLocationCommand
|
|
||||||
{
|
|
||||||
public CommandCreate()
|
|
||||||
{
|
|
||||||
aliases.add("create");
|
|
||||||
aliases.add("new");
|
|
||||||
|
|
||||||
requiredParameters.add("id");
|
|
||||||
|
|
||||||
senderMustBePlayer = true;
|
|
||||||
hasGateParam = false;
|
|
||||||
|
|
||||||
helpDescription = "Create a gate at your current location.";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = true;
|
|
||||||
shouldPersistToDisk = true;
|
|
||||||
|
|
||||||
senderMustBePlayer = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
String id = parameters.get(0);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gate = Gate.create(id);
|
|
||||||
sendMessage(ChatColor.GREEN + "Gate with id '" + id + "' was created.");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + "Creating the gate failed!" + e.getMessage() + " See server log for more information");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Location playerLocation = getValidPlayerLocation();
|
|
||||||
|
|
||||||
Plugin.log("player location:" + playerLocation);
|
|
||||||
|
|
||||||
if (playerLocation != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gate.setLocation(playerLocation);
|
|
||||||
sendMessage(ChatColor.AQUA + "The gates location has been set to your current location.");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sendMessage("Now you should build a frame and execute:");
|
|
||||||
sendMessage(new CommandSetLocation().getUsageTemplate(true, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
|||||||
package de.craftinc.gates.commands;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
|
||||||
import de.craftinc.gates.Plugin;
|
|
||||||
|
|
||||||
|
|
||||||
public class CommandDelete extends BaseCommand
|
|
||||||
{
|
|
||||||
public CommandDelete()
|
|
||||||
{
|
|
||||||
aliases.add("delete");
|
|
||||||
aliases.add("del");
|
|
||||||
aliases.add("remove");
|
|
||||||
aliases.add("rm");
|
|
||||||
|
|
||||||
requiredParameters.add("id");
|
|
||||||
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
helpDescription = "Removes the gate from the game.";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
|
||||||
shouldPersistToDisk = true;
|
|
||||||
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
Gate.delete(gate.getId());
|
|
||||||
sendMessage(ChatColor.GREEN + "Gate with id '" + gate.getId() + "' was deleted.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
61
src/de/craftinc/gates/commands/CommandExit.java
Normal file
61
src/de/craftinc/gates/commands/CommandExit.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class CommandExit extends BaseCommand
|
||||||
|
{
|
||||||
|
public CommandExit()
|
||||||
|
{
|
||||||
|
aliases.add("exit");
|
||||||
|
aliases.add("e");
|
||||||
|
|
||||||
|
requiredParameters.add("id");
|
||||||
|
|
||||||
|
helpDescription = "Change exit of location.";
|
||||||
|
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
|
needsPermissionAtCurrentLocation = true;
|
||||||
|
shouldPersistToDisk = true;
|
||||||
|
senderMustBePlayer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gate.setExit(player.getLocation());
|
||||||
|
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
|
sendMessage(ChatColor.RED + "Setting the exit for the gate failed! See server log for more information");
|
||||||
|
Plugin.log(Level.WARNING, e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,28 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
import de.craftinc.gates.util.TextUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
|
||||||
import de.craftinc.gates.Plugin;
|
|
||||||
import de.craftinc.gates.util.TextUtil;
|
|
||||||
|
|
||||||
public class CommandHelp extends BaseCommand
|
public class CommandHelp extends BaseCommand
|
||||||
{
|
{
|
||||||
public static List<List<String>> helpPages;
|
public static List<List<String>> helpPages;
|
||||||
@ -20,17 +33,17 @@ public class CommandHelp extends BaseCommand
|
|||||||
List<String> allUsageStrings = new ArrayList<String>();
|
List<String> allUsageStrings = new ArrayList<String>();
|
||||||
|
|
||||||
allUsageStrings.add( new CommandHelp().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandHelp().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandCreate().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandNew().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandDelete().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandRemove().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandSetLocation().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandLocation().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandSetExit().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandExit().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandOpen().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandOpen().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandRename().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandRename().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandClose().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandClose().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandList().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandList().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandInfo().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandInfo().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandSetHidden().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandHide().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandSetVisible().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandUnhide().getUsageTemplate(true, true) );
|
||||||
|
|
||||||
Collections.sort(allUsageStrings);
|
Collections.sort(allUsageStrings);
|
||||||
|
|
||||||
@ -38,8 +51,7 @@ public class CommandHelp extends BaseCommand
|
|||||||
// put 5 commands on one page
|
// put 5 commands on one page
|
||||||
helpPages = new ArrayList<List<String>>();
|
helpPages = new ArrayList<List<String>>();
|
||||||
|
|
||||||
while (!allUsageStrings.isEmpty())
|
while (!allUsageStrings.isEmpty()) {
|
||||||
{
|
|
||||||
int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size();
|
int toIndex = allUsageStrings.size() >= 6 ? 5 : allUsageStrings.size();
|
||||||
List<String> currentHelpPage = new ArrayList<String>(allUsageStrings.subList(0, toIndex));
|
List<String> currentHelpPage = new ArrayList<String>(allUsageStrings.subList(0, toIndex));
|
||||||
helpPages.add(currentHelpPage);
|
helpPages.add(currentHelpPage);
|
||||||
@ -52,7 +64,6 @@ public class CommandHelp extends BaseCommand
|
|||||||
public CommandHelp()
|
public CommandHelp()
|
||||||
{
|
{
|
||||||
aliases.add("help");
|
aliases.add("help");
|
||||||
aliases.add("h");
|
|
||||||
aliases.add("?");
|
aliases.add("?");
|
||||||
|
|
||||||
optionalParameters.add("page");
|
optionalParameters.add("page");
|
||||||
@ -67,33 +78,27 @@ public class CommandHelp extends BaseCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean hasPermission(CommandSender sender, Gate gate)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
int page = 1;
|
int page;
|
||||||
|
|
||||||
if (parameters.size() > 0)
|
if (parameters.size() > 0) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
page = Integer.parseInt(parameters.get(0));
|
page = Integer.parseInt(parameters.get(0));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e) {
|
||||||
{
|
|
||||||
// wasn't an integer
|
// wasn't an integer
|
||||||
|
page = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
page = 1;
|
||||||
|
}
|
||||||
|
|
||||||
sendMessage(TextUtil.titleize("Craft Inc. Gates Help (" + page + "/" + helpPages.size() + ")"));
|
sendMessage(TextUtil.titleize("Craft Inc. Gates Help (" + page + "/" + helpPages.size() + ")"));
|
||||||
|
|
||||||
page -= 1;
|
page -= 1;
|
||||||
if (page < 0 || page >= helpPages.size())
|
if (page < 0 || page >= helpPages.size()) {
|
||||||
{
|
|
||||||
sendMessage("This page does not exist");
|
sendMessage("This page does not exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
59
src/de/craftinc/gates/commands/CommandHide.java
Normal file
59
src/de/craftinc/gates/commands/CommandHide.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class CommandHide extends BaseCommand
|
||||||
|
{
|
||||||
|
public CommandHide()
|
||||||
|
{
|
||||||
|
aliases.add("hide");
|
||||||
|
aliases.add("h");
|
||||||
|
|
||||||
|
requiredParameters.add("id");
|
||||||
|
|
||||||
|
helpDescription = "Makes a gate NOT consist of gate blocks while open.";
|
||||||
|
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
|
needsPermissionAtCurrentLocation = false;
|
||||||
|
shouldPersistToDisk = true;
|
||||||
|
senderMustBePlayer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
gate.setHidden(true);
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
|
sendMessage(ChatColor.GREEN + "The gate '" + gate.getId() + "' is now hidden.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
sendMessage(ChatColor.RED + "Hiding the gate failed! See server log for more information");
|
||||||
|
Plugin.log(Level.WARNING, e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,19 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
|
||||||
@ -12,13 +28,11 @@ public class CommandInfo extends BaseCommand
|
|||||||
public CommandInfo()
|
public CommandInfo()
|
||||||
{
|
{
|
||||||
aliases.add("info");
|
aliases.add("info");
|
||||||
aliases.add("details");
|
|
||||||
aliases.add("i");
|
aliases.add("i");
|
||||||
aliases.add("d");
|
|
||||||
|
|
||||||
requiredParameters.add("id");
|
requiredParameters.add("id");
|
||||||
|
|
||||||
helpDescription = "Print detailed informations about a certain gate.";
|
helpDescription = "Print detailed information about a certain gate.";
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionInfo;
|
requiredPermission = Plugin.permissionInfo;
|
||||||
|
|
||||||
@ -47,14 +61,17 @@ public class CommandInfo extends BaseCommand
|
|||||||
sendMessage(openHiddenMessage);
|
sendMessage(openHiddenMessage);
|
||||||
|
|
||||||
if (gate.getLocation() != null)
|
if (gate.getLocation() != null)
|
||||||
sendMessage(ChatColor.DARK_AQUA + "from: " + ChatColor.AQUA + "( " + gate.getLocation().getBlockX() + " | " + gate.getLocation().getBlockY() + " | " + gate.getLocation().getBlockZ() + " ) in " + gate.getLocation().getWorld().getName());
|
sendMessage(ChatColor.DARK_AQUA + "from: " + ChatColor.AQUA + "( " + (int)gate.getLocation().getX() +
|
||||||
|
" | " + (int)gate.getLocation().getY() + " | " + (int)gate.getLocation().getZ() + " ) in " +
|
||||||
|
gate.getLocation().getWorld().getName());
|
||||||
else
|
else
|
||||||
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no location");
|
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no location");
|
||||||
|
|
||||||
if (gate.getExit() != null)
|
if (gate.getExit() != null)
|
||||||
sendMessage(ChatColor.DARK_AQUA + "to: " + ChatColor.AQUA + "( " + gate.getExit().getBlockX() + " | " + gate.getExit().getBlockY() + " | " + gate.getExit().getBlockZ() + " ) in " + gate.getExit().getWorld().getName());
|
sendMessage(ChatColor.DARK_AQUA + "to: " + ChatColor.AQUA + "( " + (int)gate.getExit().getX() + " | "
|
||||||
|
+ (int)gate.getExit().getY() + " | " + (int)gate.getExit().getZ() + " ) in " +
|
||||||
|
gate.getExit().getWorld().getName());
|
||||||
else
|
else
|
||||||
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no exit");
|
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -134,9 +150,9 @@ public class CommandList extends BaseCommand
|
|||||||
*/
|
*/
|
||||||
protected Collection<Gate> getAllGates()
|
protected Collection<Gate> getAllGates()
|
||||||
{
|
{
|
||||||
Collection<Gate> gates = Gate.getAll();
|
Collection<Gate> gates = Plugin.getPlugin().getGatesManager().allGates();
|
||||||
|
|
||||||
if (this.sender instanceof Player && Plugin.permission != null) {
|
if (this.sender instanceof Player && Plugin.getPermission() != null) {
|
||||||
Player p = (Player)this.sender;
|
Player p = (Player)this.sender;
|
||||||
|
|
||||||
// create a copy since we cannot iterate over a collection while modifying it!
|
// create a copy since we cannot iterate over a collection while modifying it!
|
||||||
@ -145,7 +161,7 @@ public class CommandList extends BaseCommand
|
|||||||
for (Gate gate : gatesCopy) {
|
for (Gate gate : gatesCopy) {
|
||||||
|
|
||||||
if (gate.getLocation() != null) {
|
if (gate.getLocation() != null) {
|
||||||
boolean permissionAtGateLocation = Plugin.permission.has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
boolean permissionAtGateLocation = Plugin.getPermission().has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission);
|
||||||
if (!permissionAtGateLocation) {
|
if (!permissionAtGateLocation) {
|
||||||
gates.remove(gate);
|
gates.remove(gate);
|
||||||
continue;
|
continue;
|
||||||
@ -154,7 +170,7 @@ public class CommandList extends BaseCommand
|
|||||||
|
|
||||||
if (gate.getExit() != null) {
|
if (gate.getExit() != null) {
|
||||||
|
|
||||||
boolean permissionAtGateExit = Plugin.permission.has(gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
boolean permissionAtGateExit = Plugin.getPermission().has(gate.getExit().getWorld(), p.getName(), this.requiredPermission);
|
||||||
if (!permissionAtGateExit) {
|
if (!permissionAtGateExit) {
|
||||||
gates.remove(gate);
|
gates.remove(gate);
|
||||||
}
|
}
|
||||||
@ -282,13 +298,7 @@ public class CommandList extends BaseCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
if (linesNecessaryForCurrentGates < linesLeftOnPage) {
|
moreGatesOnLastPage = linesNecessaryForCurrentGates >= linesLeftOnPage;
|
||||||
moreGatesOnLastPage = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
moreGatesOnLastPage = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
linesLeftOnPage -= linesToFill;
|
linesLeftOnPage -= linesToFill;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,7 +320,7 @@ public class CommandList extends BaseCommand
|
|||||||
try {
|
try {
|
||||||
page = new Integer(parameters.get(0));
|
page = new Integer(parameters.get(0));
|
||||||
}
|
}
|
||||||
catch (Exception e) { }
|
catch (Exception ignored) { }
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
85
src/de/craftinc/gates/commands/CommandLocation.java
Normal file
85
src/de/craftinc/gates/commands/CommandLocation.java
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
|
||||||
|
public class CommandLocation extends BaseLocationCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
public CommandLocation()
|
||||||
|
{
|
||||||
|
aliases.add("location");
|
||||||
|
aliases.add("lo");
|
||||||
|
|
||||||
|
requiredParameters.add("id");
|
||||||
|
|
||||||
|
helpDescription = "Set the entrance of the gate to your current location.";
|
||||||
|
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
|
needsPermissionAtCurrentLocation = true;
|
||||||
|
shouldPersistToDisk = true;
|
||||||
|
senderMustBePlayer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
|
Location playerLocation = getValidPlayerLocation();
|
||||||
|
|
||||||
|
if (playerLocation == null)
|
||||||
|
{
|
||||||
|
sendMessage("There is not enough room for a gate to open here");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location oldLocation = gate.getLocation();
|
||||||
|
Set<Location> oldGateBlockLocations = gate.getGateBlockLocations();
|
||||||
|
Set<Block> oldFrameBlocks = gate.getGateFrameBlocks();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (gate.isOpen()) {
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
gate.setLocation(playerLocation);
|
||||||
|
|
||||||
|
sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location.");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
sendMessage(ChatColor.RED + "There seems to be no frame at your new location! The gate got closed!" + ChatColor.AQUA + " You should build a frame now and execute:");
|
||||||
|
sendMessage(new CommandOpen().getUsageTemplate(true, true));
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, oldLocation, oldGateBlockLocations, oldFrameBlocks);
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
83
src/de/craftinc/gates/commands/CommandNew.java
Normal file
83
src/de/craftinc/gates/commands/CommandNew.java
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Gate;
|
||||||
|
import de.craftinc.gates.GatesManager;
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class CommandNew extends BaseLocationCommand
|
||||||
|
{
|
||||||
|
public CommandNew()
|
||||||
|
{
|
||||||
|
aliases.add("new");
|
||||||
|
aliases.add("n");
|
||||||
|
|
||||||
|
requiredParameters.add("id");
|
||||||
|
|
||||||
|
senderMustBePlayer = true;
|
||||||
|
hasGateParam = false;
|
||||||
|
|
||||||
|
helpDescription = "Create a gate at your current location.";
|
||||||
|
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
|
needsPermissionAtCurrentLocation = true;
|
||||||
|
shouldPersistToDisk = true;
|
||||||
|
|
||||||
|
senderMustBePlayer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
|
String id = parameters.get(0);
|
||||||
|
GatesManager gatesManager = Plugin.getPlugin().getGatesManager();
|
||||||
|
|
||||||
|
if (gatesManager.gateExists(id)) {
|
||||||
|
sendMessage(ChatColor.RED + "Creating the gate failed! " + "A gate with the supplied id already exists!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gate = new Gate(id);
|
||||||
|
sendMessage(ChatColor.GREEN + "Gate with id '" + id + "' was created.");
|
||||||
|
|
||||||
|
|
||||||
|
Location playerLocation = getValidPlayerLocation();
|
||||||
|
|
||||||
|
if (playerLocation != null) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
gate.setLocation(playerLocation);
|
||||||
|
sendMessage(ChatColor.AQUA + "The gates location has been set to your current location.");
|
||||||
|
}
|
||||||
|
catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendMessage(ChatColor.RED + "Your location is invalid!" + ChatColor.AQUA + "Go somewhere else and execute:");
|
||||||
|
sendMessage(new CommandLocation().getUsageTemplate(true, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
gatesManager.handleNewGate(gate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,23 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
@ -28,13 +45,24 @@ public class CommandOpen extends BaseCommand
|
|||||||
|
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
try
|
try {
|
||||||
{
|
boolean needsGateManagerUpdate = false;
|
||||||
|
|
||||||
|
if (gate.getGateBlockLocations().isEmpty()) {
|
||||||
|
needsGateManagerUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
gate.setOpen(true);
|
gate.setOpen(true);
|
||||||
|
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
|
|
||||||
|
if (needsGateManagerUpdate) {
|
||||||
|
Plugin.getPlugin().getGatesManager().handleGateLocationChange(gate, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
sendMessage(ChatColor.GREEN + "The gate was opened.");
|
sendMessage(ChatColor.GREEN + "The gate was opened.");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e) {
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + e.getMessage());
|
sendMessage(ChatColor.RED + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
53
src/de/craftinc/gates/commands/CommandRemove.java
Normal file
53
src/de/craftinc/gates/commands/CommandRemove.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class CommandRemove extends BaseCommand
|
||||||
|
{
|
||||||
|
public CommandRemove()
|
||||||
|
{
|
||||||
|
aliases.add("delete");
|
||||||
|
aliases.add("del");
|
||||||
|
aliases.add("remove");
|
||||||
|
|
||||||
|
requiredParameters.add("id");
|
||||||
|
|
||||||
|
senderMustBePlayer = false;
|
||||||
|
helpDescription = "Removes the gate from the game.";
|
||||||
|
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
|
needsPermissionAtCurrentLocation = false;
|
||||||
|
shouldPersistToDisk = true;
|
||||||
|
|
||||||
|
senderMustBePlayer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
|
Plugin.getPlugin().getGatesManager().handleDeletion(gate);
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate, true);
|
||||||
|
sendMessage(ChatColor.GREEN + "Gate with id '" + gate.getId() + "' was deleted.");
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,24 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.commands;
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
import de.craftinc.gates.GatesManager;
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
@ -11,8 +27,7 @@ public class CommandRename extends BaseCommand
|
|||||||
public CommandRename()
|
public CommandRename()
|
||||||
{
|
{
|
||||||
aliases.add("rename");
|
aliases.add("rename");
|
||||||
aliases.add("changename");
|
aliases.add("rn");
|
||||||
aliases.add("cn");
|
|
||||||
|
|
||||||
hasGateParam = true;
|
hasGateParam = true;
|
||||||
senderMustBePlayer = false;
|
senderMustBePlayer = false;
|
||||||
@ -33,16 +48,19 @@ public class CommandRename extends BaseCommand
|
|||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
String newId = parameters.get(1);
|
String newId = parameters.get(1);
|
||||||
|
GatesManager gatesManager = Plugin.getPlugin().getGatesManager();
|
||||||
|
|
||||||
try
|
if (gatesManager.gateExists(newId)) {
|
||||||
{
|
|
||||||
Gate.rename(gate.getId(), newId);
|
|
||||||
sendMessage(ChatColor.GREEN + "Gate " + gate.getId() + " is now known as " + newId + ".");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + "Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
|
sendMessage(ChatColor.RED + "Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
String oldId = gate.getId();
|
||||||
|
|
||||||
|
gate.setId(newId);
|
||||||
|
gatesManager.handleGateIdChange(gate, oldId);
|
||||||
|
|
||||||
|
sendMessage(ChatColor.GREEN + "Gate " + gate.getId() + " is now known as " + newId + ".");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
package de.craftinc.gates.commands;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
|
||||||
|
|
||||||
|
|
||||||
public class CommandSetExit extends BaseCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
public CommandSetExit()
|
|
||||||
{
|
|
||||||
aliases.add("exit");
|
|
||||||
aliases.add("e");
|
|
||||||
|
|
||||||
requiredParameters.add("id");
|
|
||||||
|
|
||||||
helpDescription = "Change exit of location.";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = true;
|
|
||||||
shouldPersistToDisk = true;
|
|
||||||
senderMustBePlayer = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gate.setExit(player.getLocation());
|
|
||||||
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
sendMessage(ChatColor.RED + "Setting the exit for the gate failed! See server log for more information");
|
|
||||||
Plugin.log(Level.WARNING, e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
|||||||
package de.craftinc.gates.commands;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
|
||||||
|
|
||||||
|
|
||||||
public class CommandSetHidden extends BaseCommand
|
|
||||||
{
|
|
||||||
public CommandSetHidden()
|
|
||||||
{
|
|
||||||
aliases.add("hide");
|
|
||||||
aliases.add("h");
|
|
||||||
|
|
||||||
requiredParameters.add("id");
|
|
||||||
|
|
||||||
helpDescription = "Makes a gate NOT consist of gate blocks while open.";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
|
||||||
shouldPersistToDisk = true;
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gate.setHidden(true);
|
|
||||||
sendMessage(ChatColor.GREEN + "The gate '" + gate.getId() + "' is now hidden.");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + "Hiding the gate failed! See server log for more information");
|
|
||||||
Plugin.log(Level.WARNING, e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package de.craftinc.gates.commands;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
|
||||||
|
|
||||||
|
|
||||||
public class CommandSetLocation extends BaseLocationCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
public CommandSetLocation()
|
|
||||||
{
|
|
||||||
aliases.add("location");
|
|
||||||
aliases.add("l");
|
|
||||||
|
|
||||||
requiredParameters.add("id");
|
|
||||||
|
|
||||||
helpDescription = "Set the entrance of the gate to your current location.";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = true;
|
|
||||||
shouldPersistToDisk = true;
|
|
||||||
senderMustBePlayer = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
Location playerLocation = getValidPlayerLocation();
|
|
||||||
|
|
||||||
if (playerLocation == null)
|
|
||||||
{
|
|
||||||
sendMessage("There is not enough room for a gate to open here");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gate.setLocation(playerLocation);
|
|
||||||
sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location.");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
sendMessage(ChatColor.RED + "Setting the location for the gate failed! See server log for more information");
|
|
||||||
Plugin.log(Level.WARNING, e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
|||||||
package de.craftinc.gates.commands;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
|
||||||
|
|
||||||
|
|
||||||
public class CommandSetVisible extends BaseCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
public CommandSetVisible()
|
|
||||||
{
|
|
||||||
aliases.add("unhide");
|
|
||||||
aliases.add("uh");
|
|
||||||
|
|
||||||
requiredParameters.add("id");
|
|
||||||
|
|
||||||
helpDescription = "Make that gate visible";
|
|
||||||
|
|
||||||
requiredPermission = Plugin.permissionManage;
|
|
||||||
|
|
||||||
needsPermissionAtCurrentLocation = false;
|
|
||||||
shouldPersistToDisk = true;
|
|
||||||
senderMustBePlayer = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void perform()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gate.setHidden(false);
|
|
||||||
sendMessage(ChatColor.GREEN + "The gate " + gate.getId() + " is now visible.");
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
sendMessage(ChatColor.RED + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
58
src/de/craftinc/gates/commands/CommandUnhide.java
Normal file
58
src/de/craftinc/gates/commands/CommandUnhide.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.commands;
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class CommandUnhide extends BaseCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
public CommandUnhide()
|
||||||
|
{
|
||||||
|
aliases.add("unhide");
|
||||||
|
aliases.add("u");
|
||||||
|
|
||||||
|
requiredParameters.add("id");
|
||||||
|
|
||||||
|
helpDescription = "Make that gate visible";
|
||||||
|
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
|
|
||||||
|
needsPermissionAtCurrentLocation = false;
|
||||||
|
shouldPersistToDisk = true;
|
||||||
|
senderMustBePlayer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gate.setHidden(false);
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
|
sendMessage(ChatColor.GREEN + "The gate " + gate.getId() + " is now visible.");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
sendMessage(ChatColor.RED + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
48
src/de/craftinc/gates/listeners/BlockBreakListener.java
Normal file
48
src/de/craftinc/gates/listeners/BlockBreakListener.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.listeners;
|
||||||
|
|
||||||
|
|
||||||
|
import de.craftinc.gates.Gate;
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
|
||||||
|
public class BlockBreakListener implements Listener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onBlockBreak(BlockBreakEvent event)
|
||||||
|
{
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Gate gate = Plugin.getPlugin().getGatesManager().getGateAtFrameLocation(event.getBlock().getLocation());
|
||||||
|
|
||||||
|
if (gate != null && !gate.isHidden()) {
|
||||||
|
try {
|
||||||
|
gate.setOpen(false);
|
||||||
|
}
|
||||||
|
catch (Exception ignored) { }
|
||||||
|
|
||||||
|
GateBlockChangeSender.updateGateBlocks(gate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.listeners;
|
||||||
|
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class PlayerChangedWorldListener implements Listener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onPlayerChangeWorld(PlayerChangedWorldEvent event)
|
||||||
|
{
|
||||||
|
GateBlockChangeSender.updateGateBlocks(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
33
src/de/craftinc/gates/listeners/PlayerJoinListener.java
Normal file
33
src/de/craftinc/gates/listeners/PlayerJoinListener.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.listeners;
|
||||||
|
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
public class PlayerJoinListener implements Listener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
GateBlockChangeSender.updateGateBlocks(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
136
src/de/craftinc/gates/listeners/PlayerMoveListener.java
Normal file
136
src/de/craftinc/gates/listeners/PlayerMoveListener.java
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.listeners;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Gate;
|
||||||
|
import de.craftinc.gates.GatesManager;
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class PlayerMoveListener implements Listener
|
||||||
|
{
|
||||||
|
protected HashMap<String, Long> lastNoPermissionMessages = new HashMap<String, Long>();
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onPlayerMove(PlayerMoveEvent event)
|
||||||
|
{
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getFrom().getChunk() != event.getTo().getChunk()) {
|
||||||
|
GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getTo());
|
||||||
|
}
|
||||||
|
|
||||||
|
GatesManager gateManager = Plugin.getPlugin().getGatesManager();
|
||||||
|
Gate gateAtLocation = gateManager.getGateAtLocation(event.getTo());
|
||||||
|
|
||||||
|
if (gateAtLocation == null) {
|
||||||
|
// Location headTo = new Location(event.getTo().getWorld(),
|
||||||
|
// event.getTo().getX(),
|
||||||
|
// event.getTo().getY()+1.0,
|
||||||
|
// event.getTo().getZ());
|
||||||
|
//
|
||||||
|
// gateAtLocation = gateManager.getGateAtLocation(headTo);
|
||||||
|
|
||||||
|
// if (gateAtLocation == null) {
|
||||||
|
return;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gateAtLocation.isOpen()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for permission
|
||||||
|
if (!hasPermission(event.getPlayer(), gateAtLocation)
|
||||||
|
&& Plugin.getPlugin().getConfig().getBoolean(Plugin.confShowTeleportNoPermissionMessageKey)) {
|
||||||
|
|
||||||
|
String playerName = event.getPlayer().getName();
|
||||||
|
|
||||||
|
if (playerName == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the current time
|
||||||
|
Long now = Calendar.getInstance().getTimeInMillis();
|
||||||
|
|
||||||
|
// do not display messages more often than once per second
|
||||||
|
if (!this.lastNoPermissionMessages.containsKey(playerName) || this.lastNoPermissionMessages.get(playerName) < now - 10000L) {
|
||||||
|
|
||||||
|
String noPermissionString = Plugin.getPlugin().getConfig().getString(Plugin.confGateTeleportNoPermissionMessageKey);
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + noPermissionString);
|
||||||
|
this.lastNoPermissionMessages.put(playerName, now);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.teleportPlayer(event.getPlayer(), gateAtLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Teleports a player.
|
||||||
|
* @param p The player to teleport.
|
||||||
|
* @param g The gate to which exit the player will be teleported.
|
||||||
|
*/
|
||||||
|
private void teleportPlayer(Player p, Gate g)
|
||||||
|
{
|
||||||
|
Float newYaw = g.getExit().getYaw() - g.getLocation().getYaw() + p.getLocation().getYaw();
|
||||||
|
|
||||||
|
Location destLocation = new Location( g.getExit().getWorld(),
|
||||||
|
g.getExit().getX(),
|
||||||
|
g.getExit().getY(),
|
||||||
|
g.getExit().getZ(),
|
||||||
|
newYaw,
|
||||||
|
p.getLocation().getPitch()
|
||||||
|
);
|
||||||
|
|
||||||
|
p.teleport(destLocation);
|
||||||
|
|
||||||
|
if (Plugin.getPlugin().getConfig().getBoolean(Plugin.confShowTeleportMessageKey)) {
|
||||||
|
String teleporMessage = Plugin.getPlugin().getConfig().getString(Plugin.confGateTeleportMessageKey);
|
||||||
|
p.sendMessage(ChatColor.DARK_AQUA + teleporMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected boolean hasPermission(Player player, Gate gate)
|
||||||
|
{
|
||||||
|
if (Plugin.getPermission() == null) { // fallback: use the standard bukkit permission system
|
||||||
|
return player.hasPermission(Plugin.permissionUse);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
boolean permAtLocation = Plugin.getPermission().has(gate.getLocation().getWorld(), player.getName(), Plugin.permissionUse);
|
||||||
|
boolean permAtExit = Plugin.getPermission().has(gate.getExit().getWorld(), player.getName(), Plugin.permissionUse);
|
||||||
|
|
||||||
|
return permAtLocation && permAtExit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
src/de/craftinc/gates/listeners/PlayerRespawnListener.java
Normal file
34
src/de/craftinc/gates/listeners/PlayerRespawnListener.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.listeners;
|
||||||
|
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class PlayerRespawnListener implements Listener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onPlayerRespawn(PlayerRespawnEvent event)
|
||||||
|
{
|
||||||
|
GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getRespawnLocation(), true);
|
||||||
|
}
|
||||||
|
}
|
37
src/de/craftinc/gates/listeners/PlayerTeleportListener.java
Normal file
37
src/de/craftinc/gates/listeners/PlayerTeleportListener.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.listeners;
|
||||||
|
|
||||||
|
|
||||||
|
import de.craftinc.gates.util.GateBlockChangeSender;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
|
public class PlayerTeleportListener implements Listener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||||
|
{
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GateBlockChangeSender.updateGateBlocks(event.getPlayer(), event.getTo(), true);
|
||||||
|
}
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
package de.craftinc.gates.listeners;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class PluginBlockListener implements Listener
|
|
||||||
{
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
|
||||||
public void onBlockPhysics(BlockPhysicsEvent event)
|
|
||||||
{
|
|
||||||
if (event.isCancelled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event.getBlock().getType() != Material.PORTAL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isBlockInPortal(event.getBlock())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBlockInPortal(Block block)
|
|
||||||
{
|
|
||||||
if (block.getRelative(BlockFace.UP).getType() == Material.AIR) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( block.getRelative(BlockFace.NORTH).getType() != Material.AIR && block.getRelative(BlockFace.SOUTH).getType() != Material.AIR ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( block.getRelative(BlockFace.WEST).getType() != Material.AIR && block.getRelative(BlockFace.EAST).getType() != Material.AIR ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
package de.craftinc.gates.listeners;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
|
||||||
import de.craftinc.gates.Plugin;
|
|
||||||
import de.craftinc.gates.util.GateUtil;
|
|
||||||
|
|
||||||
|
|
||||||
public class PluginPlayerListener implements Listener
|
|
||||||
{
|
|
||||||
protected HashMap<String, Long> lastBorderMessage = new HashMap<String, Long>();
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
|
||||||
public void onPlayerMove(PlayerMoveEvent event)
|
|
||||||
{
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Find the gate at the current location.
|
|
||||||
Gate gateAtLocation = GateUtil.getGateAtPlayerLocation(event.getTo());
|
|
||||||
|
|
||||||
|
|
||||||
if (gateAtLocation == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for permission
|
|
||||||
if (!hasPermission(event.getPlayer(), gateAtLocation)) {
|
|
||||||
|
|
||||||
String playerName = event.getPlayer().getName();
|
|
||||||
|
|
||||||
if (playerName == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the current time
|
|
||||||
Long now = Calendar.getInstance().getTimeInMillis();
|
|
||||||
|
|
||||||
// do not display messages more often than once per second
|
|
||||||
if (!this.lastBorderMessage.containsKey(playerName) || this.lastBorderMessage.get(playerName) < now - 10000L) {
|
|
||||||
event.getPlayer().sendMessage(ChatColor.RED + "You are not allowed to use this gate!");
|
|
||||||
this.lastBorderMessage.put(playerName, now);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Teleport the player
|
|
||||||
checkChunkLoad(gateAtLocation.getLocation().getBlock());
|
|
||||||
|
|
||||||
Location gateExit = gateAtLocation.getExit();
|
|
||||||
Location gateLocation = gateAtLocation.getLocation();
|
|
||||||
Location playerLocation = event.getPlayer().getLocation();
|
|
||||||
|
|
||||||
Float newYaw = gateExit.getYaw() - gateLocation.getYaw() + playerLocation.getYaw();
|
|
||||||
|
|
||||||
Location teleportToLocation = new Location( gateExit.getWorld(),
|
|
||||||
gateExit.getX(),
|
|
||||||
gateExit.getY(),
|
|
||||||
gateExit.getZ(),
|
|
||||||
newYaw,
|
|
||||||
playerLocation.getPitch() );
|
|
||||||
|
|
||||||
event.getPlayer().teleport(teleportToLocation);
|
|
||||||
event.setTo(teleportToLocation);
|
|
||||||
|
|
||||||
event.getPlayer().sendMessage(ChatColor.DARK_AQUA + "Thank you for traveling with Craft Inc. Gates.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void checkChunkLoad(Block b)
|
|
||||||
{
|
|
||||||
World w = b.getWorld();
|
|
||||||
Chunk c = b.getChunk();
|
|
||||||
|
|
||||||
if (!w.isChunkLoaded(c))
|
|
||||||
{
|
|
||||||
Plugin.log(Level.FINE, "Loading chunk: " + c.toString() + " on: " + w.toString());
|
|
||||||
w.loadChunk(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected boolean hasPermission(Player player, Gate gate)
|
|
||||||
{
|
|
||||||
if (Plugin.permission == null) // fallback: use the standard bukkit permission system
|
|
||||||
{
|
|
||||||
return player.hasPermission(Plugin.permissionUse);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
boolean permAtLocation = Plugin.permission.has(gate.getLocation().getWorld(), player.getName(), Plugin.permissionUse);
|
|
||||||
boolean permAtExit = Plugin.permission.has(gate.getExit().getWorld(), player.getName(), Plugin.permissionUse);
|
|
||||||
|
|
||||||
return permAtLocation && permAtExit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
package de.craftinc.gates.listeners;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityPortalEnterEvent;
|
|
||||||
import org.bukkit.event.player.PlayerPortalEvent;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
|
||||||
import de.craftinc.gates.util.GateUtil;
|
|
||||||
|
|
||||||
|
|
||||||
public class PluginPortalListener implements Listener
|
|
||||||
{
|
|
||||||
private HashMap<Player, Gate> currentGateAtEvent = new HashMap<Player, Gate>();
|
|
||||||
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
|
||||||
public void onPlayerPortal(PlayerPortalEvent event)
|
|
||||||
{
|
|
||||||
if (event.isCancelled())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Location playerLocation = event.getPlayer().getLocation();
|
|
||||||
Gate gateAtLocation = GateUtil.getGateAtPlayerLocation(playerLocation);
|
|
||||||
|
|
||||||
|
|
||||||
// If the player's gamemode is creative no gate might be found!
|
|
||||||
// It seems like players get teleported on a move event when the 'to' location is
|
|
||||||
// inside a gate. This meens the location obtained earlier is NOT inside a gate.
|
|
||||||
if (gateAtLocation == null && event.getPlayer().getGameMode() == GameMode.CREATIVE)
|
|
||||||
{
|
|
||||||
gateAtLocation = this.currentGateAtEvent.get(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gateAtLocation != null)
|
|
||||||
{
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.currentGateAtEvent.put(event.getPlayer(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
|
||||||
public void onEntityPortalEnterEvent(EntityPortalEnterEvent event)
|
|
||||||
{
|
|
||||||
if (event.getEntity() instanceof Player)
|
|
||||||
{
|
|
||||||
Player player = (Player)event.getEntity();
|
|
||||||
|
|
||||||
if (player.getGameMode() == GameMode.CREATIVE)
|
|
||||||
{
|
|
||||||
if (this.currentGateAtEvent.get(player) != null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Location eventLocation = event.getLocation();
|
|
||||||
Gate closestGate = GateUtil.closestGate(eventLocation);
|
|
||||||
|
|
||||||
if (closestGate != null)
|
|
||||||
{
|
|
||||||
// Make sure gate and event locations are on the same height (y-value).
|
|
||||||
// Otherwise the distance will be messed up when players are flying.
|
|
||||||
// FIX ME: this could potentially let a nearby nether portal fail!
|
|
||||||
eventLocation.setY(closestGate.getLocation().getY());
|
|
||||||
|
|
||||||
double distToClosestGate = closestGate.getLocation().distance(eventLocation);
|
|
||||||
|
|
||||||
if (distToClosestGate < 2.0) {
|
|
||||||
this.currentGateAtEvent.put(player, closestGate);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.currentGateAtEvent.put(player, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
100
src/de/craftinc/gates/persistence/LocationUtil.java
Normal file
100
src/de/craftinc/gates/persistence/LocationUtil.java
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.persistence;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class LocationUtil
|
||||||
|
{
|
||||||
|
protected final static String worldKey = "world";
|
||||||
|
protected final static String xKey = "x";
|
||||||
|
protected final static String yKey = "y";
|
||||||
|
protected final static String zKey = "z";
|
||||||
|
|
||||||
|
|
||||||
|
protected static World getWorld(final String name) throws Exception
|
||||||
|
{
|
||||||
|
if (name == null) {
|
||||||
|
throw new IllegalArgumentException("The name of the world must not be 'null");
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = Plugin.getPlugin().getServer().getWorld(name);
|
||||||
|
|
||||||
|
if (world == null) {
|
||||||
|
throw new Exception("World '" + name + "' does not exists anymore! Cannot get instance!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializes a location. Helps storing locations inside yaml files. NOTE: We do not care about yaw
|
||||||
|
* and pitch for gate locations. So we won't serialize them.
|
||||||
|
*
|
||||||
|
* @param l The location to serialize. Supplying 'null' is ok..
|
||||||
|
* @return A Map object ready for storing inside a yaml file. Will return 'null' if 'l' is null.
|
||||||
|
*/
|
||||||
|
public static Map<String, Object> serializeLocation(final Location l)
|
||||||
|
{
|
||||||
|
if (l == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> serializedLocation = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
serializedLocation.put(worldKey, l.getWorld().getName());
|
||||||
|
serializedLocation.put(xKey, l.getX());
|
||||||
|
serializedLocation.put(yKey, l.getY());
|
||||||
|
serializedLocation.put(zKey, l.getZ());
|
||||||
|
|
||||||
|
return serializedLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param map A map generated with the 'serializeLocation' method. Supplying 'null' is ok.
|
||||||
|
* @return A deserialized location. This method will return 'null' if 'map' is null!
|
||||||
|
* @throws Exception This method will throw an exception if the world of the supplied serialized location
|
||||||
|
* does not exist or if 'map' does not contain all necessary keys!
|
||||||
|
*/
|
||||||
|
public static Location deserializeLocation(final Map<String, Object> map) throws Exception
|
||||||
|
{
|
||||||
|
if (map == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
World w = getWorld((String)map.get(worldKey));
|
||||||
|
|
||||||
|
Number x = (Number)map.get(xKey);
|
||||||
|
Number y = (Number)map.get(yKey);
|
||||||
|
Number z = (Number)map.get(zKey);
|
||||||
|
|
||||||
|
if (x == null || y == null || z == null) {
|
||||||
|
throw new IllegalArgumentException("Supplied map is invalid x, y or z coordinate was not supplied");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Location(w, x.doubleValue(), y.doubleValue(), z.doubleValue());
|
||||||
|
}
|
||||||
|
}
|
54
src/de/craftinc/gates/persistence/MigrationUtil.java
Normal file
54
src/de/craftinc/gates/persistence/MigrationUtil.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.persistence;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Gate;
|
||||||
|
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
|
||||||
|
public class MigrationUtil
|
||||||
|
{
|
||||||
|
public static boolean performMigration(int storageVersion, int currentVersion, List<Gate> gates)
|
||||||
|
{
|
||||||
|
if (currentVersion == 1 && storageVersion == 0) {
|
||||||
|
|
||||||
|
for (Gate g : gates) {
|
||||||
|
|
||||||
|
for (Location l : g.getGateBlockLocations()) {
|
||||||
|
Block b = l.getBlock();
|
||||||
|
|
||||||
|
if (b.getType() == Material.PORTAL) {
|
||||||
|
b.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Plugin.log(Level.SEVERE, "Supplied storage version is currently not supported! Make sure you have the latest version of Craft Inc. Gates installed. Plugin will be disabled!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,26 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.util;
|
package de.craftinc.gates.util;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -13,10 +30,8 @@ import de.craftinc.gates.Plugin;
|
|||||||
|
|
||||||
public class FloodUtil
|
public class FloodUtil
|
||||||
{
|
{
|
||||||
private final static int frameBlockSearchLimit = 40;
|
protected static final Set<BlockFace> exp1 = new HashSet<BlockFace>();
|
||||||
|
protected static final Set<BlockFace> exp2 = new HashSet<BlockFace>();
|
||||||
private static final Set<BlockFace> exp1 = new HashSet<BlockFace>();
|
|
||||||
private static final Set<BlockFace> exp2 = new HashSet<BlockFace>();
|
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
@ -32,29 +47,125 @@ public class FloodUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// For the same frame and location this set of blocks is deterministic
|
/**
|
||||||
public static Set<Block> getGateFrameBlocks(Block block)
|
* Returns the all frame blocks of an gate.
|
||||||
|
* @param blocks All blocks inside the gate.
|
||||||
|
* @return A Set containing all frame block. Will never return 'null'.
|
||||||
|
*/
|
||||||
|
public static Set<Block> getFrame(final Set<Block> blocks)
|
||||||
{
|
{
|
||||||
|
if (blocks == null || blocks.isEmpty()) {
|
||||||
|
return new HashSet<Block>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to find gate's direction (north-south or east-west)
|
||||||
|
Set<BlockFace> gateFrameSearchFaces = null;
|
||||||
|
|
||||||
|
for (Block b : blocks) {
|
||||||
|
|
||||||
|
if (blocks.contains(b.getRelative(BlockFace.EAST)) ||
|
||||||
|
blocks.contains(b.getRelative(BlockFace.WEST))) {
|
||||||
|
|
||||||
|
gateFrameSearchFaces = exp1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blocks.contains(b.getRelative(BlockFace.NORTH)) ||
|
||||||
|
blocks.contains(b.getRelative(BlockFace.SOUTH))) {
|
||||||
|
|
||||||
|
gateFrameSearchFaces = exp2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gateFrameSearchFaces != null) {
|
||||||
|
return _getFrame(blocks, gateFrameSearchFaces);
|
||||||
|
}
|
||||||
|
else { // no direction found (the gate might only consist of blocks one over another)
|
||||||
|
|
||||||
|
// Try one direction and check if the found blocks are not air.
|
||||||
|
// If air is found (frame broken or wrong direction) return the other direction
|
||||||
|
Set<Block> frameBlocks = _getFrame(blocks, exp1);
|
||||||
|
|
||||||
|
for (Block b : frameBlocks) {
|
||||||
|
|
||||||
|
if (b.getType() == Material.AIR) {
|
||||||
|
return _getFrame(blocks, exp2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return frameBlocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected static Set<Block> _getFrame(final Set<Block> blocks, final Set<BlockFace> searchDirections)
|
||||||
|
{
|
||||||
|
Set<Block> frameBlocks = new HashSet<Block>();
|
||||||
|
|
||||||
|
for (Block b : blocks) {
|
||||||
|
|
||||||
|
for (BlockFace bf : searchDirections) {
|
||||||
|
Block bb = b.getRelative(bf);
|
||||||
|
|
||||||
|
if (!blocks.contains(bb)) {
|
||||||
|
frameBlocks.add(bb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return frameBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the all frame blocks of an gate.
|
||||||
|
* @param locations All locations inside the gate.
|
||||||
|
* @return A Set containing all frame block. Will never return 'null'.
|
||||||
|
*/
|
||||||
|
public static Set<Block> getFrameWithLocations(final Set<Location> locations)
|
||||||
|
{
|
||||||
|
if (locations == null) {
|
||||||
|
throw new IllegalArgumentException("'locations' must not be 'null'");
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Block> blocks = new HashSet<Block>();
|
||||||
|
|
||||||
|
for (Location l : locations) {
|
||||||
|
blocks.add(l.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
return getFrame(blocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// For the same frame and location this set of blocks is deterministic
|
||||||
|
public static Set<Block> getGatePortalBlocks(final Block block)
|
||||||
|
{
|
||||||
|
if (block == null) {
|
||||||
|
throw new IllegalArgumentException("'block' must not be 'null'");
|
||||||
|
}
|
||||||
|
|
||||||
|
int frameBlockSearchLimit = Plugin.getPlugin().getConfig().getInt(Plugin.confMaxGateBlocksKey);
|
||||||
|
|
||||||
Set<Block> blocks1 = getAirFloodBlocks(block, new HashSet<Block>(), exp1, frameBlockSearchLimit);
|
Set<Block> blocks1 = getAirFloodBlocks(block, new HashSet<Block>(), exp1, frameBlockSearchLimit);
|
||||||
Set<Block> blocks2 = getAirFloodBlocks(block, new HashSet<Block>(), exp2, frameBlockSearchLimit);
|
Set<Block> blocks2 = getAirFloodBlocks(block, new HashSet<Block>(), exp2, frameBlockSearchLimit);
|
||||||
|
|
||||||
if (blocks1 == null && blocks2 == null)
|
if (blocks1 == null && blocks2 == null) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blocks1 == null)
|
if (blocks1 == null) {
|
||||||
{
|
|
||||||
return blocks2;
|
return blocks2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blocks2 == null)
|
if (blocks2 == null) {
|
||||||
{
|
|
||||||
return blocks1;
|
return blocks1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blocks1.size() > blocks2.size())
|
if (blocks1.size() > blocks2.size()) {
|
||||||
{
|
|
||||||
return blocks2;
|
return blocks2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,30 +173,30 @@ public class FloodUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Set<Block> getAirFloodBlocks(Block startBlock, Set<Block> foundBlocks, Set<BlockFace> expandFaces, int limit)
|
protected static Set<Block> getAirFloodBlocks(final Block startBlock,
|
||||||
{
|
Set<Block> foundBlocks,
|
||||||
if (foundBlocks == null)
|
final Set<BlockFace> expandFaces,
|
||||||
|
int limit)
|
||||||
{
|
{
|
||||||
|
if (foundBlocks == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundBlocks.size() > limit)
|
if (foundBlocks.size() > limit) {
|
||||||
{
|
|
||||||
Plugin.log(Level.ALL, "exceeding gate size limit.");
|
Plugin.log(Level.ALL, "exceeding gate size limit.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundBlocks.contains(startBlock))
|
if (foundBlocks.contains(startBlock)) {
|
||||||
return foundBlocks;
|
return foundBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
if (startBlock.getType() == Material.AIR || startBlock.getType() == Material.PORTAL)
|
if (startBlock.getType() == Material.AIR) {
|
||||||
{
|
|
||||||
// ... We found a block :D ...
|
// ... We found a block :D ...
|
||||||
foundBlocks.add(startBlock);
|
foundBlocks.add(startBlock);
|
||||||
|
|
||||||
// ... And flood away !
|
// ... And flood away !
|
||||||
for (BlockFace face : expandFaces)
|
for (BlockFace face : expandFaces) {
|
||||||
{
|
|
||||||
Block potentialBlock = startBlock.getRelative(face);
|
Block potentialBlock = startBlock.getRelative(face);
|
||||||
foundBlocks = getAirFloodBlocks(potentialBlock, foundBlocks, expandFaces, limit);
|
foundBlocks = getAirFloodBlocks(potentialBlock, foundBlocks, expandFaces, limit);
|
||||||
}
|
}
|
||||||
@ -93,5 +204,4 @@ public class FloodUtil
|
|||||||
|
|
||||||
return foundBlocks;
|
return foundBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
157
src/de/craftinc/gates/util/GateBlockChangeSender.java
Normal file
157
src/de/craftinc/gates/util/GateBlockChangeSender.java
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.util;
|
||||||
|
|
||||||
|
|
||||||
|
import de.craftinc.gates.Plugin;
|
||||||
|
import de.craftinc.gates.Gate;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
public class GateBlockChangeSender
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Sends gate blocks to player at a given location. Will send the updates either immediately or
|
||||||
|
* immediately and after a short delay.
|
||||||
|
* @param player A player to send block changes to. Must not be null!
|
||||||
|
* @param location The location to look for gates nearby. Must not be null!
|
||||||
|
* @param sendDelayed Set to 'true' if the block changes shall be send a second time after a one
|
||||||
|
* second delay.
|
||||||
|
*/
|
||||||
|
public static void updateGateBlocks(final Player player, final Location location, boolean sendDelayed)
|
||||||
|
{
|
||||||
|
if (player == null) {
|
||||||
|
throw new IllegalArgumentException("'player' must not be 'null'!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location == null) {
|
||||||
|
throw new IllegalArgumentException("'location' must not be 'null'!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Gate> gatesNearby = Plugin.getPlugin().getGatesManager().getNearbyGates(location.getChunk());
|
||||||
|
|
||||||
|
if (gatesNearby == null) {
|
||||||
|
return; // no gates nearby
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Gate g : gatesNearby) {
|
||||||
|
|
||||||
|
if (!g.isOpen() || g.isHidden()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Location l : g.getGateBlockLocations()) {
|
||||||
|
|
||||||
|
if (l.getBlock().getType() == Material.AIR) {
|
||||||
|
player.sendBlockChange(l, Material.PORTAL, (byte)0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendDelayed) {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.getPlugin(), new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
updateGateBlocks(player, location, false);
|
||||||
|
}
|
||||||
|
}, 20L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method calls: updateGateBlocks(player, location, false);
|
||||||
|
*/
|
||||||
|
public static void updateGateBlocks(final Player player, final Location location)
|
||||||
|
{
|
||||||
|
updateGateBlocks(player, location, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method calls: updateGateBlocks(player, player.getLocation(), false);
|
||||||
|
*/
|
||||||
|
public static void updateGateBlocks(final Player player)
|
||||||
|
{
|
||||||
|
if (player == null) {
|
||||||
|
throw new IllegalArgumentException("'player' must not be 'null'!");
|
||||||
|
}
|
||||||
|
|
||||||
|
updateGateBlocks(player, player.getLocation(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void updateGateBlocks(final Gate gate)
|
||||||
|
{
|
||||||
|
updateGateBlocks(gate, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends block changes to players near a given gate.
|
||||||
|
* @param gate Must not be 'null'!
|
||||||
|
* @param remove Set to true if all visible gate blocks shall be removed.
|
||||||
|
*/
|
||||||
|
public static void updateGateBlocks(final Gate gate, boolean remove)
|
||||||
|
{
|
||||||
|
if (gate == null) {
|
||||||
|
throw new IllegalArgumentException("'gate must not be 'null'!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Location gateLocation = gate.getLocation();
|
||||||
|
|
||||||
|
if (gate.getGateBlockLocations().isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Player> playersNearby = new ArrayList<Player>();
|
||||||
|
|
||||||
|
int searchRadius = Plugin.getPlugin().getConfig().getInt(Plugin.confPlayerGateBlockUpdateRadiusKey);
|
||||||
|
|
||||||
|
for (Player p : Plugin.getPlugin().getServer().getOnlinePlayers()) {
|
||||||
|
|
||||||
|
if (p.getWorld() == gateLocation.getWorld() && p.getLocation().distance(gateLocation) < searchRadius) {
|
||||||
|
playersNearby.add(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Material material;
|
||||||
|
|
||||||
|
if (gate.isOpen() && !gate.isHidden() && !remove) {
|
||||||
|
material = Material.PORTAL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
material = Material.AIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player p : playersNearby) {
|
||||||
|
|
||||||
|
for (Location l : gate.getGateBlockLocations()) {
|
||||||
|
|
||||||
|
if (l.getBlock().getType() == Material.AIR) { // on server-side a gate is always made out of AIR
|
||||||
|
p.sendBlockChange(l, material, (byte)0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,86 +0,0 @@
|
|||||||
package de.craftinc.gates.util;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Gate;
|
|
||||||
|
|
||||||
public class GateUtil
|
|
||||||
{
|
|
||||||
public static Gate closestGate(Location location)
|
|
||||||
{
|
|
||||||
Gate gate = null;
|
|
||||||
double minmalDist = Double.MAX_VALUE;
|
|
||||||
|
|
||||||
for (Gate g : Gate.getAll()) {
|
|
||||||
|
|
||||||
if (!g.getLocation().getWorld().equals(location.getWorld()))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
double tempDist = g.getLocation().distance(location);
|
|
||||||
|
|
||||||
if (tempDist < minmalDist)
|
|
||||||
{
|
|
||||||
gate = g;
|
|
||||||
minmalDist = tempDist;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return gate;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Gate getGateAtPlayerLocation(Location location)
|
|
||||||
{
|
|
||||||
Gate gate = null;
|
|
||||||
World playerWorld = location.getWorld();
|
|
||||||
|
|
||||||
// players are sometime stuck into the ground
|
|
||||||
Location locationUp = location.getBlock().getRelative(BlockFace.UP).getLocation();
|
|
||||||
|
|
||||||
for (Gate g : Gate.getAll())
|
|
||||||
{
|
|
||||||
if (gate != null)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the gate is open and useable
|
|
||||||
if (g.getLocation() == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
World gateWorld = g.getLocation().getWorld();
|
|
||||||
|
|
||||||
if (!g.isOpen() || !gateWorld.equals(playerWorld)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Check if the location matches
|
|
||||||
for (Location l: g.getGateBlockLocations()) {
|
|
||||||
|
|
||||||
if (LocationUtil.locationsAreAtSamePositions(l, location) || LocationUtil.locationsAreAtSamePositions(l, locationUp))
|
|
||||||
{
|
|
||||||
// Check if the gate is still valid
|
|
||||||
try {
|
|
||||||
g.validate();
|
|
||||||
|
|
||||||
gate = g;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
catch (Exception e2) {
|
|
||||||
break; // do nothing - gate got closed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return gate;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
package de.craftinc.gates.util;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NOTE: We do not care about yaw and pitch for gate locations. So we won't serialize them.
|
|
||||||
*/
|
|
||||||
public class LocationUtil
|
|
||||||
{
|
|
||||||
protected static String worldKey = "world";
|
|
||||||
protected static String xKey = "x";
|
|
||||||
protected static String yKey = "y";
|
|
||||||
protected static String zKey = "z";
|
|
||||||
|
|
||||||
|
|
||||||
protected static World getWorld(String name) throws Exception
|
|
||||||
{
|
|
||||||
World world = Plugin.instance.getServer().getWorld(name);
|
|
||||||
|
|
||||||
if (world == null) {
|
|
||||||
throw new Exception("World '" + name + "' does not exists anymore! Cannot get instance!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Map<String, Object> serializeLocation(Location l)
|
|
||||||
{
|
|
||||||
if (l == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> serializedLocation = new HashMap<String, Object>();
|
|
||||||
|
|
||||||
serializedLocation.put(worldKey, l.getWorld().getName());
|
|
||||||
serializedLocation.put(xKey, l.getX());
|
|
||||||
serializedLocation.put(yKey, l.getY());
|
|
||||||
serializedLocation.put(zKey, l.getZ());
|
|
||||||
|
|
||||||
return serializedLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Location deserializeLocation(Map<String, Object> map) throws Exception
|
|
||||||
{
|
|
||||||
if (map == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
World w = getWorld((String)map.get(worldKey));
|
|
||||||
|
|
||||||
|
|
||||||
// verbose loading of coordinates (they might be Double or Integer)
|
|
||||||
Object objX = map.get(xKey);
|
|
||||||
Object objY = map.get(yKey);
|
|
||||||
Object objZ = map.get(zKey);
|
|
||||||
|
|
||||||
double x,y,z;
|
|
||||||
|
|
||||||
if (objX instanceof Integer)
|
|
||||||
x = (double)(Integer)objX;
|
|
||||||
else
|
|
||||||
x = (Double)objX;
|
|
||||||
|
|
||||||
if (objY instanceof Integer)
|
|
||||||
y = (double)(Integer)objY;
|
|
||||||
else
|
|
||||||
y = (Double)objY;
|
|
||||||
|
|
||||||
if (objZ instanceof Integer)
|
|
||||||
z = (double)(Integer)objZ;
|
|
||||||
else
|
|
||||||
z = (Double)objZ;
|
|
||||||
|
|
||||||
|
|
||||||
return new Location(w, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean locationsAreAtSamePositions(final Location l1, final Location l2)
|
|
||||||
{
|
|
||||||
if (l1.getWorld() != l2.getWorld() && (l1.getWorld() == null || !l1.getWorld().equals(l2.getWorld()))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (l1.getBlockX() != l2.getBlockX()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (l1.getBlockY() != l2.getBlockY()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (l1.getBlockZ() != l2.getBlockZ()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
79
src/de/craftinc/gates/util/SimpleChunk.java
Normal file
79
src/de/craftinc/gates/util/SimpleChunk.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.util;
|
||||||
|
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
public class SimpleChunk
|
||||||
|
{
|
||||||
|
private int x;
|
||||||
|
private int z;
|
||||||
|
private String world;
|
||||||
|
|
||||||
|
public SimpleChunk(Chunk c)
|
||||||
|
{
|
||||||
|
this.x = c.getX();
|
||||||
|
this.z = c.getZ();
|
||||||
|
this.world = c.getWorld().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SimpleChunk(int x, int z, World w)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
|
this.z = z;
|
||||||
|
this.world = w.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (o instanceof SimpleChunk) {
|
||||||
|
SimpleChunk otherLocation = (SimpleChunk)o;
|
||||||
|
|
||||||
|
if (otherLocation.x == this.x
|
||||||
|
&& otherLocation.z == this.z
|
||||||
|
&& otherLocation.world.equals(this.world)) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int hash = 11;
|
||||||
|
hash = 29 * hash + x;
|
||||||
|
hash = 37 * hash + z;
|
||||||
|
hash = 29 * hash + world.hashCode();
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return this.getClass().toString() + " (x=" + this.x + " z=" + this.z + " world='" + this.world + "')";
|
||||||
|
}
|
||||||
|
}
|
95
src/de/craftinc/gates/util/SimpleLocation.java
Normal file
95
src/de/craftinc/gates/util/SimpleLocation.java
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.gates.util;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class SimpleLocation
|
||||||
|
{
|
||||||
|
private String world;
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private int z;
|
||||||
|
|
||||||
|
|
||||||
|
public SimpleLocation(Location l)
|
||||||
|
{
|
||||||
|
this.world = l.getWorld().getName();
|
||||||
|
|
||||||
|
// Using Block coordinates makes it possible to compare block locations with player locations.
|
||||||
|
// There might be an offset of 1 otherwise.
|
||||||
|
this.x = l.getBlockX();
|
||||||
|
this.y = l.getBlockY();
|
||||||
|
this.z = l.getBlockZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SimpleLocation(Location l, boolean isHeadPosition)
|
||||||
|
{
|
||||||
|
this.world = l.getWorld().getName();
|
||||||
|
|
||||||
|
// Using Block coordinates makes it possible to compare block locations with player locations.
|
||||||
|
// There might be an offset of 1 otherwise.
|
||||||
|
this.x = l.getBlockX();
|
||||||
|
this.y = l.getBlockY();
|
||||||
|
this.z = l.getBlockZ();
|
||||||
|
|
||||||
|
if (isHeadPosition) {
|
||||||
|
this.y--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return super.toString() + " x: " + x + " y: " + y + " z: " + z + " world: " + world;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object o)
|
||||||
|
{
|
||||||
|
if (o instanceof SimpleLocation) {
|
||||||
|
SimpleLocation otherLocation = (SimpleLocation)o;
|
||||||
|
|
||||||
|
if (otherLocation.x == this.x
|
||||||
|
&& otherLocation.y == this.y
|
||||||
|
&& otherLocation.z == this.z
|
||||||
|
&& otherLocation.world.equals(this.world)) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int hash = 13;
|
||||||
|
hash = 37 * hash + x;
|
||||||
|
hash = 31 * hash + y;
|
||||||
|
hash = 37 * hash + z;
|
||||||
|
hash = 31 * hash + world.hashCode();
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,24 @@
|
|||||||
|
/* Craft Inc. Gates
|
||||||
|
Copyright (C) 2011-2013 Craft Inc. Gates Team (see AUTHORS.txt)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program (LGPLv3). If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package de.craftinc.gates.util;
|
package de.craftinc.gates.util;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TextUtil
|
public class TextUtil
|
||||||
{
|
{
|
||||||
@ -29,7 +44,7 @@ public class TextUtil
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Joins all emements of list into a single string, sperating the original strings with glue.
|
* Joins all elements of list into a single string, separating the original strings with glue.
|
||||||
*/
|
*/
|
||||||
public static String implode(List<String> list, String glue)
|
public static String implode(List<String> list, String glue)
|
||||||
{
|
{
|
||||||
@ -45,24 +60,6 @@ public class TextUtil
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Joins all emements of list into a single string.
|
|
||||||
*/
|
|
||||||
public static String implode(List<String> list) {
|
|
||||||
return implode(list, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String getMaterialName(Material material)
|
|
||||||
{
|
|
||||||
String ret = material.toString();
|
|
||||||
ret = ret.replace('_', ' ');
|
|
||||||
ret = ret.toLowerCase();
|
|
||||||
|
|
||||||
return ret.substring(0, 1).toUpperCase() + ret.substring(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user